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) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1722 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1723 | cb->min_dump_alloc < 4096) { |
| 1724 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1725 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1726 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1727 | return 1; |
| 1728 | } |
| 1729 | idx--; |
| 1730 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1731 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1732 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1733 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1734 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1735 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1736 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1737 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1738 | |
| 1739 | return skb->len; |
| 1740 | } |
| 1741 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1742 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1743 | { |
| 1744 | kfree((void *)cb->args[0]); |
| 1745 | return 0; |
| 1746 | } |
| 1747 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1748 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1749 | { |
| 1750 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1751 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1752 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1753 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1754 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1755 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1756 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1757 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1758 | 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] | 1759 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1760 | nlmsg_free(msg); |
| 1761 | return -ENOBUFS; |
| 1762 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1763 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1764 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1765 | } |
| 1766 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1767 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1768 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1769 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1770 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1771 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1772 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1773 | }; |
| 1774 | |
| 1775 | static int parse_txq_params(struct nlattr *tb[], |
| 1776 | struct ieee80211_txq_params *txq_params) |
| 1777 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1778 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1779 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1780 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1781 | return -EINVAL; |
| 1782 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1783 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1784 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1785 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1786 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1787 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1788 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1789 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1790 | return -EINVAL; |
| 1791 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1792 | return 0; |
| 1793 | } |
| 1794 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1795 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1796 | { |
| 1797 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1798 | * You can only set the channel explicitly for WDS interfaces, |
| 1799 | * all others have their channel managed via their respective |
| 1800 | * "establish a connection" command (connect, join, ...) |
| 1801 | * |
| 1802 | * For AP/GO and mesh mode, the channel can be set with the |
| 1803 | * channel userspace API, but is only stored and passed to the |
| 1804 | * low-level driver when the AP starts or the mesh is joined. |
| 1805 | * This is for backward compatibility, userspace can also give |
| 1806 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1807 | * |
| 1808 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1809 | * whatever else is going on, so they have their own special |
| 1810 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1811 | */ |
| 1812 | return !wdev || |
| 1813 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1814 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1815 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1816 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1817 | } |
| 1818 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1819 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1820 | struct genl_info *info, |
| 1821 | struct cfg80211_chan_def *chandef) |
| 1822 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1823 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1824 | |
| 1825 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1826 | return -EINVAL; |
| 1827 | |
| 1828 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1829 | |
| 1830 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1831 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1832 | chandef->center_freq1 = control_freq; |
| 1833 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1834 | |
| 1835 | /* Primary channel not allowed */ |
| 1836 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1837 | return -EINVAL; |
| 1838 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1839 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1840 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1841 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1842 | chantype = nla_get_u32( |
| 1843 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1844 | |
| 1845 | switch (chantype) { |
| 1846 | case NL80211_CHAN_NO_HT: |
| 1847 | case NL80211_CHAN_HT20: |
| 1848 | case NL80211_CHAN_HT40PLUS: |
| 1849 | case NL80211_CHAN_HT40MINUS: |
| 1850 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1851 | chantype); |
| 1852 | break; |
| 1853 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1854 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1855 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1856 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1857 | chandef->width = |
| 1858 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1859 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1860 | chandef->center_freq1 = |
| 1861 | nla_get_u32( |
| 1862 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1863 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1864 | chandef->center_freq2 = |
| 1865 | nla_get_u32( |
| 1866 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1867 | } |
| 1868 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1869 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1870 | return -EINVAL; |
| 1871 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1872 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1873 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1874 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1875 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1876 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1877 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1878 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1879 | return -EINVAL; |
| 1880 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1881 | return 0; |
| 1882 | } |
| 1883 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1884 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1885 | struct wireless_dev *wdev, |
| 1886 | struct genl_info *info) |
| 1887 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1888 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1889 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1890 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1891 | |
| 1892 | if (wdev) |
| 1893 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1894 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1895 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1896 | return -EOPNOTSUPP; |
| 1897 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1898 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1899 | if (result) |
| 1900 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1901 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1902 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1903 | case NL80211_IFTYPE_AP: |
| 1904 | case NL80211_IFTYPE_P2P_GO: |
| 1905 | if (wdev->beacon_interval) { |
| 1906 | result = -EBUSY; |
| 1907 | break; |
| 1908 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1909 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1910 | result = -EINVAL; |
| 1911 | break; |
| 1912 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1913 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1914 | result = 0; |
| 1915 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1916 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1917 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1918 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1919 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1920 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1921 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1922 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1923 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1924 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1925 | |
| 1926 | return result; |
| 1927 | } |
| 1928 | |
| 1929 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1930 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1931 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1932 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1933 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1934 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1935 | } |
| 1936 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1937 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1938 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1939 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1940 | struct net_device *dev = info->user_ptr[1]; |
| 1941 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1942 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1943 | |
| 1944 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1945 | return -EINVAL; |
| 1946 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1947 | if (netif_running(dev)) |
| 1948 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1949 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1950 | if (!rdev->ops->set_wds_peer) |
| 1951 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1952 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1953 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1954 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1955 | |
| 1956 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1957 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1961 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1962 | { |
| 1963 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1964 | struct net_device *netdev = NULL; |
| 1965 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1966 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1967 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1968 | u32 changed; |
| 1969 | u8 retry_short = 0, retry_long = 0; |
| 1970 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1971 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1972 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1973 | ASSERT_RTNL(); |
| 1974 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1975 | /* |
| 1976 | * Try to find the wiphy and netdev. Normally this |
| 1977 | * function shouldn't need the netdev, but this is |
| 1978 | * done for backward compatibility -- previously |
| 1979 | * setting the channel was done per wiphy, but now |
| 1980 | * it is per netdev. Previous userland like hostapd |
| 1981 | * also passed a netdev to set_wiphy, so that it is |
| 1982 | * possible to let that go to the right netdev! |
| 1983 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1984 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1985 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1986 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1987 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1988 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1989 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1990 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1991 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1992 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1993 | } |
| 1994 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1995 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1996 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1997 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1998 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1999 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2000 | wdev = NULL; |
| 2001 | netdev = NULL; |
| 2002 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2003 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2004 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2005 | |
| 2006 | /* |
| 2007 | * end workaround code, by now the rdev is available |
| 2008 | * and locked, and wdev may or may not be NULL. |
| 2009 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2010 | |
| 2011 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2012 | result = cfg80211_dev_rename( |
| 2013 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2014 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2015 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2016 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2017 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2018 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2019 | struct ieee80211_txq_params txq_params; |
| 2020 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2021 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2022 | if (!rdev->ops->set_txq_params) |
| 2023 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2024 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2025 | if (!netdev) |
| 2026 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2027 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2028 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2029 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2030 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2031 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2032 | if (!netif_running(netdev)) |
| 2033 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2034 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2035 | nla_for_each_nested(nl_txq_params, |
| 2036 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2037 | rem_txq_params) { |
| 2038 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2039 | nla_data(nl_txq_params), |
| 2040 | nla_len(nl_txq_params), |
| 2041 | txq_params_policy); |
| 2042 | result = parse_txq_params(tb, &txq_params); |
| 2043 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2044 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2045 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2046 | result = rdev_set_txq_params(rdev, netdev, |
| 2047 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2048 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2049 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2050 | } |
| 2051 | } |
| 2052 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2053 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2054 | result = __nl80211_set_channel(rdev, |
| 2055 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 2056 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2057 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2058 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2059 | } |
| 2060 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2061 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2062 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2063 | enum nl80211_tx_power_setting type; |
| 2064 | int idx, mbm = 0; |
| 2065 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2066 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2067 | txp_wdev = NULL; |
| 2068 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2069 | if (!rdev->ops->set_tx_power) |
| 2070 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2071 | |
| 2072 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2073 | type = nla_get_u32(info->attrs[idx]); |
| 2074 | |
| 2075 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2076 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2077 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2078 | |
| 2079 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2080 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2081 | mbm = nla_get_u32(info->attrs[idx]); |
| 2082 | } |
| 2083 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2084 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2085 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2086 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2087 | } |
| 2088 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2089 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2090 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2091 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2092 | if ((!rdev->wiphy.available_antennas_tx && |
| 2093 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2094 | !rdev->ops->set_antenna) |
| 2095 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2096 | |
| 2097 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2098 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2099 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2100 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2101 | * available antenna masks, except for the "all" mask */ |
| 2102 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2103 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2104 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2105 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2106 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2107 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2108 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2109 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2110 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2111 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2112 | } |
| 2113 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2114 | changed = 0; |
| 2115 | |
| 2116 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2117 | retry_short = nla_get_u8( |
| 2118 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2119 | if (retry_short == 0) |
| 2120 | return -EINVAL; |
| 2121 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2122 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2123 | } |
| 2124 | |
| 2125 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2126 | retry_long = nla_get_u8( |
| 2127 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2128 | if (retry_long == 0) |
| 2129 | return -EINVAL; |
| 2130 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2131 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2132 | } |
| 2133 | |
| 2134 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2135 | frag_threshold = nla_get_u32( |
| 2136 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2137 | if (frag_threshold < 256) |
| 2138 | return -EINVAL; |
| 2139 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2140 | if (frag_threshold != (u32) -1) { |
| 2141 | /* |
| 2142 | * Fragments (apart from the last one) are required to |
| 2143 | * have even length. Make the fragmentation code |
| 2144 | * simpler by stripping LSB should someone try to use |
| 2145 | * odd threshold value. |
| 2146 | */ |
| 2147 | frag_threshold &= ~0x1; |
| 2148 | } |
| 2149 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2150 | } |
| 2151 | |
| 2152 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2153 | rts_threshold = nla_get_u32( |
| 2154 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2155 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2156 | } |
| 2157 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2158 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2159 | coverage_class = nla_get_u8( |
| 2160 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2161 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2162 | } |
| 2163 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2164 | if (changed) { |
| 2165 | u8 old_retry_short, old_retry_long; |
| 2166 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2167 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2168 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2169 | if (!rdev->ops->set_wiphy_params) |
| 2170 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2171 | |
| 2172 | old_retry_short = rdev->wiphy.retry_short; |
| 2173 | old_retry_long = rdev->wiphy.retry_long; |
| 2174 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2175 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2176 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2177 | |
| 2178 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2179 | rdev->wiphy.retry_short = retry_short; |
| 2180 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2181 | rdev->wiphy.retry_long = retry_long; |
| 2182 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2183 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2184 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2185 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2186 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2187 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2188 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2189 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2190 | if (result) { |
| 2191 | rdev->wiphy.retry_short = old_retry_short; |
| 2192 | rdev->wiphy.retry_long = old_retry_long; |
| 2193 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2194 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2195 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2196 | } |
| 2197 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2198 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2199 | } |
| 2200 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2201 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2202 | { |
| 2203 | return (u64)wdev->identifier | |
| 2204 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2205 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2206 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2207 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2208 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2209 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2210 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2211 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2212 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2213 | chandef->chan->center_freq)) |
| 2214 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2215 | switch (chandef->width) { |
| 2216 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2217 | case NL80211_CHAN_WIDTH_20: |
| 2218 | case NL80211_CHAN_WIDTH_40: |
| 2219 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2220 | cfg80211_get_chandef_type(chandef))) |
| 2221 | return -ENOBUFS; |
| 2222 | break; |
| 2223 | default: |
| 2224 | break; |
| 2225 | } |
| 2226 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2227 | return -ENOBUFS; |
| 2228 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2229 | return -ENOBUFS; |
| 2230 | if (chandef->center_freq2 && |
| 2231 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2232 | return -ENOBUFS; |
| 2233 | return 0; |
| 2234 | } |
| 2235 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2236 | 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] | 2237 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2238 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2239 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2240 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2241 | void *hdr; |
| 2242 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2243 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2244 | if (!hdr) |
| 2245 | return -1; |
| 2246 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2247 | if (dev && |
| 2248 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2249 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2250 | goto nla_put_failure; |
| 2251 | |
| 2252 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2253 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2254 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2255 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2256 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2257 | rdev->devlist_generation ^ |
| 2258 | (cfg80211_rdev_list_generation << 2))) |
| 2259 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2260 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2261 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2262 | int ret; |
| 2263 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2264 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2265 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2266 | if (ret == 0) { |
| 2267 | if (nl80211_send_chandef(msg, &chandef)) |
| 2268 | goto nla_put_failure; |
| 2269 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2270 | } |
| 2271 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2272 | if (wdev->ssid_len) { |
| 2273 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2274 | goto nla_put_failure; |
| 2275 | } |
| 2276 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2277 | return genlmsg_end(msg, hdr); |
| 2278 | |
| 2279 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2280 | genlmsg_cancel(msg, hdr); |
| 2281 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2285 | { |
| 2286 | int wp_idx = 0; |
| 2287 | int if_idx = 0; |
| 2288 | int wp_start = cb->args[0]; |
| 2289 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2290 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2291 | struct wireless_dev *wdev; |
| 2292 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2293 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2294 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2295 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2296 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2297 | if (wp_idx < wp_start) { |
| 2298 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2299 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2300 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2301 | if_idx = 0; |
| 2302 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2303 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2304 | if (if_idx < if_start) { |
| 2305 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2306 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2307 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2308 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2309 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2310 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2311 | goto out; |
| 2312 | } |
| 2313 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2314 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2315 | |
| 2316 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2317 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2318 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2319 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2320 | |
| 2321 | cb->args[0] = wp_idx; |
| 2322 | cb->args[1] = if_idx; |
| 2323 | |
| 2324 | return skb->len; |
| 2325 | } |
| 2326 | |
| 2327 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2328 | { |
| 2329 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2330 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2331 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2332 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2333 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2334 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2335 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2336 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2337 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2338 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2339 | nlmsg_free(msg); |
| 2340 | return -ENOBUFS; |
| 2341 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2342 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2343 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2344 | } |
| 2345 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2346 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2347 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2348 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2349 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2350 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2351 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2352 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2353 | }; |
| 2354 | |
| 2355 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2356 | { |
| 2357 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2358 | int flag; |
| 2359 | |
| 2360 | *mntrflags = 0; |
| 2361 | |
| 2362 | if (!nla) |
| 2363 | return -EINVAL; |
| 2364 | |
| 2365 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2366 | nla, mntr_flags_policy)) |
| 2367 | return -EINVAL; |
| 2368 | |
| 2369 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2370 | if (flags[flag]) |
| 2371 | *mntrflags |= (1<<flag); |
| 2372 | |
| 2373 | return 0; |
| 2374 | } |
| 2375 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2376 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2377 | struct net_device *netdev, u8 use_4addr, |
| 2378 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2379 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2380 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2381 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2382 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2383 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2384 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2385 | |
| 2386 | switch (iftype) { |
| 2387 | case NL80211_IFTYPE_AP_VLAN: |
| 2388 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2389 | return 0; |
| 2390 | break; |
| 2391 | case NL80211_IFTYPE_STATION: |
| 2392 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2393 | return 0; |
| 2394 | break; |
| 2395 | default: |
| 2396 | break; |
| 2397 | } |
| 2398 | |
| 2399 | return -EOPNOTSUPP; |
| 2400 | } |
| 2401 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2402 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2403 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2404 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2405 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2406 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2407 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2408 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2409 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2410 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2411 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2412 | memset(¶ms, 0, sizeof(params)); |
| 2413 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2414 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2415 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2416 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2417 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2418 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2419 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2420 | if (ntype > NL80211_IFTYPE_MAX) |
| 2421 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2422 | } |
| 2423 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2424 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2425 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2426 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2427 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2428 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2429 | if (netif_running(dev)) |
| 2430 | return -EBUSY; |
| 2431 | |
| 2432 | wdev_lock(wdev); |
| 2433 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2434 | IEEE80211_MAX_MESH_ID_LEN); |
| 2435 | wdev->mesh_id_up_len = |
| 2436 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2437 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2438 | wdev->mesh_id_up_len); |
| 2439 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2440 | } |
| 2441 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2442 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2443 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2444 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2445 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2446 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2447 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2448 | } else { |
| 2449 | params.use_4addr = -1; |
| 2450 | } |
| 2451 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2452 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2453 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2454 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2455 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2456 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2457 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2458 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2459 | |
| 2460 | flags = &_flags; |
| 2461 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2462 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2463 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2464 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2465 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2466 | return -EOPNOTSUPP; |
| 2467 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2468 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2469 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2470 | else |
| 2471 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2472 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2473 | if (!err && params.use_4addr != -1) |
| 2474 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2475 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2476 | return err; |
| 2477 | } |
| 2478 | |
| 2479 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2480 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2481 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2482 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2483 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2484 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2485 | int err; |
| 2486 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2487 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2488 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2489 | memset(¶ms, 0, sizeof(params)); |
| 2490 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2491 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2492 | return -EINVAL; |
| 2493 | |
| 2494 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2495 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2496 | if (type > NL80211_IFTYPE_MAX) |
| 2497 | return -EINVAL; |
| 2498 | } |
| 2499 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2500 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2501 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2502 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2503 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2504 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2505 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2506 | ETH_ALEN); |
| 2507 | if (!is_valid_ether_addr(params.macaddr)) |
| 2508 | return -EADDRNOTAVAIL; |
| 2509 | } |
| 2510 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2511 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2512 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2513 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2514 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2515 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2516 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2517 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2518 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2519 | if (!msg) |
| 2520 | return -ENOMEM; |
| 2521 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2522 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2523 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2524 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2525 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2526 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2527 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2528 | return -EOPNOTSUPP; |
| 2529 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2530 | wdev = rdev_add_virtual_intf(rdev, |
| 2531 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2532 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2533 | if (IS_ERR(wdev)) { |
| 2534 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2535 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2536 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2537 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2538 | switch (type) { |
| 2539 | case NL80211_IFTYPE_MESH_POINT: |
| 2540 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2541 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2542 | wdev_lock(wdev); |
| 2543 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2544 | IEEE80211_MAX_MESH_ID_LEN); |
| 2545 | wdev->mesh_id_up_len = |
| 2546 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2547 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2548 | wdev->mesh_id_up_len); |
| 2549 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2550 | break; |
| 2551 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2552 | /* |
| 2553 | * P2P Device doesn't have a netdev, so doesn't go |
| 2554 | * through the netdev notifier and must be added here |
| 2555 | */ |
| 2556 | mutex_init(&wdev->mtx); |
| 2557 | INIT_LIST_HEAD(&wdev->event_list); |
| 2558 | spin_lock_init(&wdev->event_lock); |
| 2559 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2560 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2561 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2562 | wdev->identifier = ++rdev->wdev_id; |
| 2563 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2564 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2565 | break; |
| 2566 | default: |
| 2567 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2568 | } |
| 2569 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2570 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2571 | rdev, wdev) < 0) { |
| 2572 | nlmsg_free(msg); |
| 2573 | return -ENOBUFS; |
| 2574 | } |
| 2575 | |
| 2576 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2577 | } |
| 2578 | |
| 2579 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2580 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2581 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2582 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2583 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2584 | if (!rdev->ops->del_virtual_intf) |
| 2585 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2586 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2587 | /* |
| 2588 | * If we remove a wireless device without a netdev then clear |
| 2589 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2590 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2591 | * since the wdev has been freed, unlike with a netdev where |
| 2592 | * we need the dev_put() for the netdev to really be freed. |
| 2593 | */ |
| 2594 | if (!wdev->netdev) |
| 2595 | info->user_ptr[1] = NULL; |
| 2596 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2597 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2598 | } |
| 2599 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2600 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2601 | { |
| 2602 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2603 | struct net_device *dev = info->user_ptr[1]; |
| 2604 | u16 noack_map; |
| 2605 | |
| 2606 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2607 | return -EINVAL; |
| 2608 | |
| 2609 | if (!rdev->ops->set_noack_map) |
| 2610 | return -EOPNOTSUPP; |
| 2611 | |
| 2612 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2613 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2614 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2615 | } |
| 2616 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2617 | struct get_key_cookie { |
| 2618 | struct sk_buff *msg; |
| 2619 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2620 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2621 | }; |
| 2622 | |
| 2623 | static void get_key_callback(void *c, struct key_params *params) |
| 2624 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2625 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2626 | struct get_key_cookie *cookie = c; |
| 2627 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2628 | if ((params->key && |
| 2629 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2630 | params->key_len, params->key)) || |
| 2631 | (params->seq && |
| 2632 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2633 | params->seq_len, params->seq)) || |
| 2634 | (params->cipher && |
| 2635 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2636 | params->cipher))) |
| 2637 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2638 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2639 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2640 | if (!key) |
| 2641 | goto nla_put_failure; |
| 2642 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2643 | if ((params->key && |
| 2644 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2645 | params->key_len, params->key)) || |
| 2646 | (params->seq && |
| 2647 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2648 | params->seq_len, params->seq)) || |
| 2649 | (params->cipher && |
| 2650 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2651 | params->cipher))) |
| 2652 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2653 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2654 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2655 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2656 | |
| 2657 | nla_nest_end(cookie->msg, key); |
| 2658 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2659 | return; |
| 2660 | nla_put_failure: |
| 2661 | cookie->error = 1; |
| 2662 | } |
| 2663 | |
| 2664 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2665 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2666 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2667 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2668 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2669 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2670 | const u8 *mac_addr = NULL; |
| 2671 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2672 | struct get_key_cookie cookie = { |
| 2673 | .error = 0, |
| 2674 | }; |
| 2675 | void *hdr; |
| 2676 | struct sk_buff *msg; |
| 2677 | |
| 2678 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2679 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2680 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2681 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2682 | return -EINVAL; |
| 2683 | |
| 2684 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2685 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2686 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2687 | pairwise = !!mac_addr; |
| 2688 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2689 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2690 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2691 | return -EINVAL; |
| 2692 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2693 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2694 | return -EINVAL; |
| 2695 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2696 | } |
| 2697 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2698 | if (!rdev->ops->get_key) |
| 2699 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2700 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2701 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2702 | if (!msg) |
| 2703 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2704 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2705 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2706 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2707 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2708 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2709 | |
| 2710 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2711 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2712 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2713 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2714 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2715 | goto nla_put_failure; |
| 2716 | if (mac_addr && |
| 2717 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2718 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2719 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2720 | if (pairwise && mac_addr && |
| 2721 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2722 | return -ENOENT; |
| 2723 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2724 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2725 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2726 | |
| 2727 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2728 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2729 | |
| 2730 | if (cookie.error) |
| 2731 | goto nla_put_failure; |
| 2732 | |
| 2733 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2734 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2735 | |
| 2736 | nla_put_failure: |
| 2737 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2738 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2739 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2740 | return err; |
| 2741 | } |
| 2742 | |
| 2743 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2744 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2745 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2746 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2747 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2748 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2749 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2750 | err = nl80211_parse_key(info, &key); |
| 2751 | if (err) |
| 2752 | return err; |
| 2753 | |
| 2754 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2755 | return -EINVAL; |
| 2756 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2757 | /* only support setting default key */ |
| 2758 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2759 | return -EINVAL; |
| 2760 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2761 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2762 | |
| 2763 | if (key.def) { |
| 2764 | if (!rdev->ops->set_default_key) { |
| 2765 | err = -EOPNOTSUPP; |
| 2766 | goto out; |
| 2767 | } |
| 2768 | |
| 2769 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2770 | if (err) |
| 2771 | goto out; |
| 2772 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2773 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2774 | key.def_uni, key.def_multi); |
| 2775 | |
| 2776 | if (err) |
| 2777 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2778 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2779 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2780 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2781 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2782 | } else { |
| 2783 | if (key.def_uni || !key.def_multi) { |
| 2784 | err = -EINVAL; |
| 2785 | goto out; |
| 2786 | } |
| 2787 | |
| 2788 | if (!rdev->ops->set_default_mgmt_key) { |
| 2789 | err = -EOPNOTSUPP; |
| 2790 | goto out; |
| 2791 | } |
| 2792 | |
| 2793 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2794 | if (err) |
| 2795 | goto out; |
| 2796 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2797 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2798 | if (err) |
| 2799 | goto out; |
| 2800 | |
| 2801 | #ifdef CONFIG_CFG80211_WEXT |
| 2802 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2803 | #endif |
| 2804 | } |
| 2805 | |
| 2806 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2807 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2808 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2809 | return err; |
| 2810 | } |
| 2811 | |
| 2812 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2813 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2814 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2815 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2816 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2817 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2818 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2819 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2820 | err = nl80211_parse_key(info, &key); |
| 2821 | if (err) |
| 2822 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2823 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2824 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2825 | return -EINVAL; |
| 2826 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2827 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2828 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2829 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2830 | if (key.type == -1) { |
| 2831 | if (mac_addr) |
| 2832 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2833 | else |
| 2834 | key.type = NL80211_KEYTYPE_GROUP; |
| 2835 | } |
| 2836 | |
| 2837 | /* for now */ |
| 2838 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2839 | key.type != NL80211_KEYTYPE_GROUP) |
| 2840 | return -EINVAL; |
| 2841 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2842 | if (!rdev->ops->add_key) |
| 2843 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2844 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2845 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2846 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2847 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2848 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2849 | |
| 2850 | wdev_lock(dev->ieee80211_ptr); |
| 2851 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2852 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2853 | err = rdev_add_key(rdev, dev, key.idx, |
| 2854 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2855 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2856 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2857 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2858 | return err; |
| 2859 | } |
| 2860 | |
| 2861 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2862 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2863 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2864 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2865 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2866 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2867 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2868 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2869 | err = nl80211_parse_key(info, &key); |
| 2870 | if (err) |
| 2871 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2872 | |
| 2873 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2874 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2875 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2876 | if (key.type == -1) { |
| 2877 | if (mac_addr) |
| 2878 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2879 | else |
| 2880 | key.type = NL80211_KEYTYPE_GROUP; |
| 2881 | } |
| 2882 | |
| 2883 | /* for now */ |
| 2884 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2885 | key.type != NL80211_KEYTYPE_GROUP) |
| 2886 | return -EINVAL; |
| 2887 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2888 | if (!rdev->ops->del_key) |
| 2889 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2890 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2891 | wdev_lock(dev->ieee80211_ptr); |
| 2892 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2893 | |
| 2894 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2895 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2896 | err = -ENOENT; |
| 2897 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2898 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2899 | err = rdev_del_key(rdev, dev, key.idx, |
| 2900 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2901 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2902 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2903 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2904 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2905 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2906 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2907 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2908 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2909 | } |
| 2910 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2911 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2912 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2913 | return err; |
| 2914 | } |
| 2915 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2916 | /* This function returns an error or the number of nested attributes */ |
| 2917 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2918 | { |
| 2919 | struct nlattr *attr; |
| 2920 | int n_entries = 0, tmp; |
| 2921 | |
| 2922 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2923 | if (nla_len(attr) != ETH_ALEN) |
| 2924 | return -EINVAL; |
| 2925 | |
| 2926 | n_entries++; |
| 2927 | } |
| 2928 | |
| 2929 | return n_entries; |
| 2930 | } |
| 2931 | |
| 2932 | /* |
| 2933 | * This function parses ACL information and allocates memory for ACL data. |
| 2934 | * On successful return, the calling function is responsible to free the |
| 2935 | * ACL buffer returned by this function. |
| 2936 | */ |
| 2937 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2938 | struct genl_info *info) |
| 2939 | { |
| 2940 | enum nl80211_acl_policy acl_policy; |
| 2941 | struct nlattr *attr; |
| 2942 | struct cfg80211_acl_data *acl; |
| 2943 | int i = 0, n_entries, tmp; |
| 2944 | |
| 2945 | if (!wiphy->max_acl_mac_addrs) |
| 2946 | return ERR_PTR(-EOPNOTSUPP); |
| 2947 | |
| 2948 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2949 | return ERR_PTR(-EINVAL); |
| 2950 | |
| 2951 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2952 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2953 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2954 | return ERR_PTR(-EINVAL); |
| 2955 | |
| 2956 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2957 | return ERR_PTR(-EINVAL); |
| 2958 | |
| 2959 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2960 | if (n_entries < 0) |
| 2961 | return ERR_PTR(n_entries); |
| 2962 | |
| 2963 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2964 | return ERR_PTR(-ENOTSUPP); |
| 2965 | |
| 2966 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2967 | GFP_KERNEL); |
| 2968 | if (!acl) |
| 2969 | return ERR_PTR(-ENOMEM); |
| 2970 | |
| 2971 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2972 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2973 | i++; |
| 2974 | } |
| 2975 | |
| 2976 | acl->n_acl_entries = n_entries; |
| 2977 | acl->acl_policy = acl_policy; |
| 2978 | |
| 2979 | return acl; |
| 2980 | } |
| 2981 | |
| 2982 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2983 | { |
| 2984 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2985 | struct net_device *dev = info->user_ptr[1]; |
| 2986 | struct cfg80211_acl_data *acl; |
| 2987 | int err; |
| 2988 | |
| 2989 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2990 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2991 | return -EOPNOTSUPP; |
| 2992 | |
| 2993 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2994 | return -EINVAL; |
| 2995 | |
| 2996 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2997 | if (IS_ERR(acl)) |
| 2998 | return PTR_ERR(acl); |
| 2999 | |
| 3000 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3001 | |
| 3002 | kfree(acl); |
| 3003 | |
| 3004 | return err; |
| 3005 | } |
| 3006 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3007 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3008 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3009 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3010 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3011 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3012 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3013 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3014 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3015 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3016 | return -EINVAL; |
| 3017 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3018 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3019 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3020 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3021 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3022 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3023 | if (!bcn->head_len) |
| 3024 | return -EINVAL; |
| 3025 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3026 | } |
| 3027 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3028 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3029 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3030 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3031 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3032 | } |
| 3033 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3034 | if (!haveinfo) |
| 3035 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3036 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3037 | if (attrs[NL80211_ATTR_IE]) { |
| 3038 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3039 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3040 | } |
| 3041 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3042 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3043 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3044 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3045 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3046 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3047 | } |
| 3048 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3049 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3050 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3051 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3052 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3053 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3054 | } |
| 3055 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3056 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3057 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3058 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3059 | } |
| 3060 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3061 | return 0; |
| 3062 | } |
| 3063 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3064 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3065 | struct cfg80211_ap_settings *params) |
| 3066 | { |
| 3067 | struct wireless_dev *wdev; |
| 3068 | bool ret = false; |
| 3069 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3070 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3071 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3072 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3073 | continue; |
| 3074 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3075 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3076 | continue; |
| 3077 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3078 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3079 | ret = true; |
| 3080 | break; |
| 3081 | } |
| 3082 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3083 | return ret; |
| 3084 | } |
| 3085 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3086 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3087 | enum nl80211_auth_type auth_type, |
| 3088 | enum nl80211_commands cmd) |
| 3089 | { |
| 3090 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3091 | return false; |
| 3092 | |
| 3093 | switch (cmd) { |
| 3094 | case NL80211_CMD_AUTHENTICATE: |
| 3095 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3096 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3097 | return false; |
| 3098 | return true; |
| 3099 | case NL80211_CMD_CONNECT: |
| 3100 | case NL80211_CMD_START_AP: |
| 3101 | /* SAE not supported yet */ |
| 3102 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3103 | return false; |
| 3104 | return true; |
| 3105 | default: |
| 3106 | return false; |
| 3107 | } |
| 3108 | } |
| 3109 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3110 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3111 | { |
| 3112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3113 | struct net_device *dev = info->user_ptr[1]; |
| 3114 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3115 | struct cfg80211_ap_settings params; |
| 3116 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3117 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3118 | |
| 3119 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3120 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3121 | return -EOPNOTSUPP; |
| 3122 | |
| 3123 | if (!rdev->ops->start_ap) |
| 3124 | return -EOPNOTSUPP; |
| 3125 | |
| 3126 | if (wdev->beacon_interval) |
| 3127 | return -EALREADY; |
| 3128 | |
| 3129 | memset(¶ms, 0, sizeof(params)); |
| 3130 | |
| 3131 | /* these are required for START_AP */ |
| 3132 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3133 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3134 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3135 | return -EINVAL; |
| 3136 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3137 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3138 | if (err) |
| 3139 | return err; |
| 3140 | |
| 3141 | params.beacon_interval = |
| 3142 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3143 | params.dtim_period = |
| 3144 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3145 | |
| 3146 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3147 | if (err) |
| 3148 | return err; |
| 3149 | |
| 3150 | /* |
| 3151 | * In theory, some of these attributes should be required here |
| 3152 | * but since they were not used when the command was originally |
| 3153 | * added, keep them optional for old user space programs to let |
| 3154 | * them continue to work with drivers that do not need the |
| 3155 | * additional information -- drivers must check! |
| 3156 | */ |
| 3157 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3158 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3159 | params.ssid_len = |
| 3160 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3161 | if (params.ssid_len == 0 || |
| 3162 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3163 | return -EINVAL; |
| 3164 | } |
| 3165 | |
| 3166 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3167 | params.hidden_ssid = nla_get_u32( |
| 3168 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3169 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3170 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3171 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3172 | return -EINVAL; |
| 3173 | } |
| 3174 | |
| 3175 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3176 | |
| 3177 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3178 | params.auth_type = nla_get_u32( |
| 3179 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3180 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3181 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3182 | return -EINVAL; |
| 3183 | } else |
| 3184 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3185 | |
| 3186 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3187 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3188 | if (err) |
| 3189 | return err; |
| 3190 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3191 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3192 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3193 | return -EOPNOTSUPP; |
| 3194 | params.inactivity_timeout = nla_get_u16( |
| 3195 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3196 | } |
| 3197 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3198 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3199 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3200 | return -EINVAL; |
| 3201 | params.p2p_ctwindow = |
| 3202 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3203 | if (params.p2p_ctwindow > 127) |
| 3204 | return -EINVAL; |
| 3205 | if (params.p2p_ctwindow != 0 && |
| 3206 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3207 | return -EINVAL; |
| 3208 | } |
| 3209 | |
| 3210 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3211 | u8 tmp; |
| 3212 | |
| 3213 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3214 | return -EINVAL; |
| 3215 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3216 | if (tmp > 1) |
| 3217 | return -EINVAL; |
| 3218 | params.p2p_opp_ps = tmp; |
| 3219 | if (params.p2p_opp_ps != 0 && |
| 3220 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3221 | return -EINVAL; |
| 3222 | } |
| 3223 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3224 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3225 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3226 | if (err) |
| 3227 | return err; |
| 3228 | } else if (wdev->preset_chandef.chan) { |
| 3229 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3230 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3231 | return -EINVAL; |
| 3232 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3233 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3234 | return -EINVAL; |
| 3235 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3236 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3237 | if (err < 0) |
| 3238 | return err; |
| 3239 | if (err) { |
| 3240 | radar_detect_width = BIT(params.chandef.width); |
| 3241 | params.radar_required = true; |
| 3242 | } |
| 3243 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3244 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3245 | params.chandef.chan, |
| 3246 | CHAN_MODE_SHARED, |
| 3247 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3248 | if (err) |
| 3249 | return err; |
| 3250 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3251 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3252 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3253 | if (IS_ERR(params.acl)) |
| 3254 | return PTR_ERR(params.acl); |
| 3255 | } |
| 3256 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3257 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3258 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3259 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3260 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3261 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3262 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3263 | wdev->ssid_len = params.ssid_len; |
| 3264 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3265 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3266 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3267 | |
| 3268 | kfree(params.acl); |
| 3269 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3270 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3271 | } |
| 3272 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3273 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3274 | { |
| 3275 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3276 | struct net_device *dev = info->user_ptr[1]; |
| 3277 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3278 | struct cfg80211_beacon_data params; |
| 3279 | int err; |
| 3280 | |
| 3281 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3282 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3283 | return -EOPNOTSUPP; |
| 3284 | |
| 3285 | if (!rdev->ops->change_beacon) |
| 3286 | return -EOPNOTSUPP; |
| 3287 | |
| 3288 | if (!wdev->beacon_interval) |
| 3289 | return -EINVAL; |
| 3290 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3291 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3292 | if (err) |
| 3293 | return err; |
| 3294 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3295 | wdev_lock(wdev); |
| 3296 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3297 | wdev_unlock(wdev); |
| 3298 | |
| 3299 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3300 | } |
| 3301 | |
| 3302 | 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] | 3303 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3304 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3305 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3306 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3307 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3308 | } |
| 3309 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3310 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3311 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3312 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3313 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3314 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3315 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3316 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3317 | }; |
| 3318 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3319 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3320 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3321 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3322 | { |
| 3323 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3324 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3325 | int flag; |
| 3326 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3327 | /* |
| 3328 | * Try parsing the new attribute first so userspace |
| 3329 | * can specify both for older kernels. |
| 3330 | */ |
| 3331 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3332 | if (nla) { |
| 3333 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3334 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3335 | sta_flags = nla_data(nla); |
| 3336 | params->sta_flags_mask = sta_flags->mask; |
| 3337 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3338 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3339 | if ((params->sta_flags_mask | |
| 3340 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3341 | return -EINVAL; |
| 3342 | return 0; |
| 3343 | } |
| 3344 | |
| 3345 | /* if present, parse the old attribute */ |
| 3346 | |
| 3347 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3348 | if (!nla) |
| 3349 | return 0; |
| 3350 | |
| 3351 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3352 | nla, sta_flags_policy)) |
| 3353 | return -EINVAL; |
| 3354 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3355 | /* |
| 3356 | * Only allow certain flags for interface types so that |
| 3357 | * other attributes are silently ignored. Remember that |
| 3358 | * this is backward compatibility code with old userspace |
| 3359 | * and shouldn't be hit in other cases anyway. |
| 3360 | */ |
| 3361 | switch (iftype) { |
| 3362 | case NL80211_IFTYPE_AP: |
| 3363 | case NL80211_IFTYPE_AP_VLAN: |
| 3364 | case NL80211_IFTYPE_P2P_GO: |
| 3365 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3366 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3367 | BIT(NL80211_STA_FLAG_WME) | |
| 3368 | BIT(NL80211_STA_FLAG_MFP); |
| 3369 | break; |
| 3370 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3371 | case NL80211_IFTYPE_STATION: |
| 3372 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3373 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3374 | break; |
| 3375 | case NL80211_IFTYPE_MESH_POINT: |
| 3376 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3377 | BIT(NL80211_STA_FLAG_MFP) | |
| 3378 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3379 | default: |
| 3380 | return -EINVAL; |
| 3381 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3382 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3383 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3384 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3385 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3386 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3387 | /* no longer support new API additions in old API */ |
| 3388 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3389 | return -EINVAL; |
| 3390 | } |
| 3391 | } |
| 3392 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3393 | return 0; |
| 3394 | } |
| 3395 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3396 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3397 | int attr) |
| 3398 | { |
| 3399 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3400 | u32 bitrate; |
| 3401 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3402 | |
| 3403 | rate = nla_nest_start(msg, attr); |
| 3404 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3405 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3406 | |
| 3407 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3408 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3409 | /* report 16-bit bitrate only if we can */ |
| 3410 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3411 | if (bitrate > 0 && |
| 3412 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3413 | return false; |
| 3414 | if (bitrate_compat > 0 && |
| 3415 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3416 | return false; |
| 3417 | |
| 3418 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3419 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3420 | return false; |
| 3421 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3422 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3423 | return false; |
| 3424 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3425 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3426 | return false; |
| 3427 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3428 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3429 | return false; |
| 3430 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3431 | return false; |
| 3432 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3433 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3434 | return false; |
| 3435 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3436 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3437 | return false; |
| 3438 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3439 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3440 | return false; |
| 3441 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3442 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3443 | return false; |
| 3444 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3445 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3446 | return false; |
| 3447 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3448 | |
| 3449 | nla_nest_end(msg, rate); |
| 3450 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3451 | } |
| 3452 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3453 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3454 | int id) |
| 3455 | { |
| 3456 | void *attr; |
| 3457 | int i = 0; |
| 3458 | |
| 3459 | if (!mask) |
| 3460 | return true; |
| 3461 | |
| 3462 | attr = nla_nest_start(msg, id); |
| 3463 | if (!attr) |
| 3464 | return false; |
| 3465 | |
| 3466 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3467 | if (!(mask & BIT(i))) |
| 3468 | continue; |
| 3469 | |
| 3470 | if (nla_put_u8(msg, i, signal[i])) |
| 3471 | return false; |
| 3472 | } |
| 3473 | |
| 3474 | nla_nest_end(msg, attr); |
| 3475 | |
| 3476 | return true; |
| 3477 | } |
| 3478 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3479 | 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] | 3480 | int flags, |
| 3481 | struct cfg80211_registered_device *rdev, |
| 3482 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3483 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3484 | { |
| 3485 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3486 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3487 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3488 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3489 | if (!hdr) |
| 3490 | return -1; |
| 3491 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3492 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3493 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3494 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3495 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3496 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3497 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3498 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3499 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3500 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3501 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3502 | sinfo->connected_time)) |
| 3503 | goto nla_put_failure; |
| 3504 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3505 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3506 | sinfo->inactive_time)) |
| 3507 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3508 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3509 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3510 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3511 | (u32)sinfo->rx_bytes)) |
| 3512 | goto nla_put_failure; |
| 3513 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3514 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3515 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3516 | (u32)sinfo->tx_bytes)) |
| 3517 | goto nla_put_failure; |
| 3518 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3519 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3520 | sinfo->rx_bytes)) |
| 3521 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3522 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3523 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3524 | sinfo->tx_bytes)) |
| 3525 | goto nla_put_failure; |
| 3526 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3527 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3528 | goto nla_put_failure; |
| 3529 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3530 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3531 | goto nla_put_failure; |
| 3532 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3533 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3534 | sinfo->plink_state)) |
| 3535 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3536 | switch (rdev->wiphy.signal_type) { |
| 3537 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3538 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3539 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3540 | sinfo->signal)) |
| 3541 | goto nla_put_failure; |
| 3542 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3543 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3544 | sinfo->signal_avg)) |
| 3545 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3546 | break; |
| 3547 | default: |
| 3548 | break; |
| 3549 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3550 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3551 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3552 | sinfo->chain_signal, |
| 3553 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3554 | goto nla_put_failure; |
| 3555 | } |
| 3556 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3557 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3558 | sinfo->chain_signal_avg, |
| 3559 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3560 | goto nla_put_failure; |
| 3561 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3562 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3563 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3564 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3565 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3566 | } |
| 3567 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3568 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3569 | NL80211_STA_INFO_RX_BITRATE)) |
| 3570 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3571 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3572 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3573 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3574 | sinfo->rx_packets)) |
| 3575 | goto nla_put_failure; |
| 3576 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3577 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3578 | sinfo->tx_packets)) |
| 3579 | goto nla_put_failure; |
| 3580 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3581 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3582 | sinfo->tx_retries)) |
| 3583 | goto nla_put_failure; |
| 3584 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3585 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3586 | sinfo->tx_failed)) |
| 3587 | goto nla_put_failure; |
| 3588 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3589 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3590 | sinfo->beacon_loss_count)) |
| 3591 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3592 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3593 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3594 | sinfo->local_pm)) |
| 3595 | goto nla_put_failure; |
| 3596 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3597 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3598 | sinfo->peer_pm)) |
| 3599 | goto nla_put_failure; |
| 3600 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3601 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3602 | sinfo->nonpeer_pm)) |
| 3603 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3604 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3605 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3606 | if (!bss_param) |
| 3607 | goto nla_put_failure; |
| 3608 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3609 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3610 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3611 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3612 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3613 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3614 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3615 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3616 | sinfo->bss_param.dtim_period) || |
| 3617 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3618 | sinfo->bss_param.beacon_interval)) |
| 3619 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3620 | |
| 3621 | nla_nest_end(msg, bss_param); |
| 3622 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3623 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3624 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3625 | sizeof(struct nl80211_sta_flag_update), |
| 3626 | &sinfo->sta_flags)) |
| 3627 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3628 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3629 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3630 | sinfo->t_offset)) |
| 3631 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3632 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3633 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3634 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3635 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3636 | sinfo->assoc_req_ies)) |
| 3637 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3638 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3639 | return genlmsg_end(msg, hdr); |
| 3640 | |
| 3641 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3642 | genlmsg_cancel(msg, hdr); |
| 3643 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3644 | } |
| 3645 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3646 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3647 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3648 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3649 | struct station_info sinfo; |
| 3650 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3651 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3652 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3653 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3654 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3655 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3656 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3657 | if (err) |
| 3658 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3659 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3660 | if (!wdev->netdev) { |
| 3661 | err = -EINVAL; |
| 3662 | goto out_err; |
| 3663 | } |
| 3664 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3665 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3666 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3667 | goto out_err; |
| 3668 | } |
| 3669 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3670 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3671 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3672 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3673 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3674 | if (err == -ENOENT) |
| 3675 | break; |
| 3676 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3677 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3678 | |
| 3679 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3680 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3681 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3682 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3683 | &sinfo) < 0) |
| 3684 | goto out; |
| 3685 | |
| 3686 | sta_idx++; |
| 3687 | } |
| 3688 | |
| 3689 | |
| 3690 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3691 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3692 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3693 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3694 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3695 | |
| 3696 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3697 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3698 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3699 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3700 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3701 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3702 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3703 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3704 | struct sk_buff *msg; |
| 3705 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3706 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3707 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3708 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3709 | |
| 3710 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3711 | return -EINVAL; |
| 3712 | |
| 3713 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3714 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3715 | if (!rdev->ops->get_station) |
| 3716 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3717 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3718 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3719 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3720 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3721 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3722 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3723 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3724 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3725 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3726 | 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] | 3727 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3728 | nlmsg_free(msg); |
| 3729 | return -ENOBUFS; |
| 3730 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3731 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3732 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3733 | } |
| 3734 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3735 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3736 | struct station_parameters *params, |
| 3737 | enum cfg80211_station_type statype) |
| 3738 | { |
| 3739 | if (params->listen_interval != -1) |
| 3740 | return -EINVAL; |
| 3741 | if (params->aid) |
| 3742 | return -EINVAL; |
| 3743 | |
| 3744 | /* When you run into this, adjust the code below for the new flag */ |
| 3745 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3746 | |
| 3747 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3748 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3749 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3750 | /* |
| 3751 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3752 | * code doesn't have the bug of including TDLS in the |
| 3753 | * mask everywhere. |
| 3754 | */ |
| 3755 | if (params->sta_flags_mask & |
| 3756 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3757 | BIT(NL80211_STA_FLAG_MFP) | |
| 3758 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3759 | return -EINVAL; |
| 3760 | break; |
| 3761 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3762 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3763 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3764 | return -EINVAL; |
| 3765 | /* ignore since it can't change */ |
| 3766 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3767 | break; |
| 3768 | default: |
| 3769 | /* disallow mesh-specific things */ |
| 3770 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3771 | return -EINVAL; |
| 3772 | if (params->local_pm) |
| 3773 | return -EINVAL; |
| 3774 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3775 | return -EINVAL; |
| 3776 | } |
| 3777 | |
| 3778 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3779 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3780 | /* TDLS can't be set, ... */ |
| 3781 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3782 | return -EINVAL; |
| 3783 | /* |
| 3784 | * ... but don't bother the driver with it. This works around |
| 3785 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3786 | * TLDS_PEER flag in the mask even for AP mode. |
| 3787 | */ |
| 3788 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3789 | } |
| 3790 | |
| 3791 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3792 | /* reject other things that can't change */ |
| 3793 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3794 | return -EINVAL; |
| 3795 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3796 | return -EINVAL; |
| 3797 | if (params->supported_rates) |
| 3798 | return -EINVAL; |
| 3799 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3800 | return -EINVAL; |
| 3801 | } |
| 3802 | |
| 3803 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3804 | if (params->vlan) |
| 3805 | return -EINVAL; |
| 3806 | } |
| 3807 | |
| 3808 | switch (statype) { |
| 3809 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3810 | /* Use this only for authorizing/unauthorizing a station */ |
| 3811 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3812 | return -EOPNOTSUPP; |
| 3813 | break; |
| 3814 | case CFG80211_STA_AP_CLIENT: |
| 3815 | /* accept only the listed bits */ |
| 3816 | if (params->sta_flags_mask & |
| 3817 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3818 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3819 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3820 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3821 | BIT(NL80211_STA_FLAG_WME) | |
| 3822 | BIT(NL80211_STA_FLAG_MFP))) |
| 3823 | return -EINVAL; |
| 3824 | |
| 3825 | /* but authenticated/associated only if driver handles it */ |
| 3826 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3827 | params->sta_flags_mask & |
| 3828 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3829 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3830 | return -EINVAL; |
| 3831 | break; |
| 3832 | case CFG80211_STA_IBSS: |
| 3833 | case CFG80211_STA_AP_STA: |
| 3834 | /* reject any changes other than AUTHORIZED */ |
| 3835 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3836 | return -EINVAL; |
| 3837 | break; |
| 3838 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3839 | /* reject any changes other than AUTHORIZED or WME */ |
| 3840 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3841 | BIT(NL80211_STA_FLAG_WME))) |
| 3842 | return -EINVAL; |
| 3843 | /* force (at least) rates when authorizing */ |
| 3844 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3845 | !params->supported_rates) |
| 3846 | return -EINVAL; |
| 3847 | break; |
| 3848 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3849 | /* reject any changes */ |
| 3850 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3851 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3852 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3853 | return -EINVAL; |
| 3854 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3855 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3856 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3857 | return -EINVAL; |
| 3858 | break; |
| 3859 | } |
| 3860 | |
| 3861 | return 0; |
| 3862 | } |
| 3863 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3864 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3865 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3866 | * 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] | 3867 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3868 | static struct net_device *get_vlan(struct genl_info *info, |
| 3869 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3870 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3871 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3872 | struct net_device *v; |
| 3873 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3874 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3875 | if (!vlanattr) |
| 3876 | return NULL; |
| 3877 | |
| 3878 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3879 | if (!v) |
| 3880 | return ERR_PTR(-ENODEV); |
| 3881 | |
| 3882 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3883 | ret = -EINVAL; |
| 3884 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3885 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3886 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3887 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3888 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3889 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3890 | ret = -EINVAL; |
| 3891 | goto error; |
| 3892 | } |
| 3893 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3894 | if (!netif_running(v)) { |
| 3895 | ret = -ENETDOWN; |
| 3896 | goto error; |
| 3897 | } |
| 3898 | |
| 3899 | return v; |
| 3900 | error: |
| 3901 | dev_put(v); |
| 3902 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3903 | } |
| 3904 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3905 | static struct nla_policy |
| 3906 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3907 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3908 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3909 | }; |
| 3910 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3911 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3912 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3913 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3914 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3915 | struct nlattr *nla; |
| 3916 | int err; |
| 3917 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3918 | /* parse WME attributes if present */ |
| 3919 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3920 | return 0; |
| 3921 | |
| 3922 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3923 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3924 | nl80211_sta_wme_policy); |
| 3925 | if (err) |
| 3926 | return err; |
| 3927 | |
| 3928 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3929 | params->uapsd_queues = nla_get_u8( |
| 3930 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3931 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3932 | return -EINVAL; |
| 3933 | |
| 3934 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3935 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3936 | |
| 3937 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3938 | return -EINVAL; |
| 3939 | |
| 3940 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3941 | |
| 3942 | return 0; |
| 3943 | } |
| 3944 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3945 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 3946 | struct station_parameters *params) |
| 3947 | { |
| 3948 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 3949 | params->supported_channels = |
| 3950 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3951 | params->supported_channels_len = |
| 3952 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3953 | /* |
| 3954 | * Need to include at least one (first channel, number of |
| 3955 | * channels) tuple for each subband, and must have proper |
| 3956 | * tuples for the rest of the data as well. |
| 3957 | */ |
| 3958 | if (params->supported_channels_len < 2) |
| 3959 | return -EINVAL; |
| 3960 | if (params->supported_channels_len % 2) |
| 3961 | return -EINVAL; |
| 3962 | } |
| 3963 | |
| 3964 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 3965 | params->supported_oper_classes = |
| 3966 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3967 | params->supported_oper_classes_len = |
| 3968 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3969 | /* |
| 3970 | * The value of the Length field of the Supported Operating |
| 3971 | * Classes element is between 2 and 253. |
| 3972 | */ |
| 3973 | if (params->supported_oper_classes_len < 2 || |
| 3974 | params->supported_oper_classes_len > 253) |
| 3975 | return -EINVAL; |
| 3976 | } |
| 3977 | return 0; |
| 3978 | } |
| 3979 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3980 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3981 | struct station_parameters *params) |
| 3982 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3983 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3984 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3985 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 3986 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3987 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3988 | params->ht_capa = |
| 3989 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3990 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3991 | params->vht_capa = |
| 3992 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3993 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3994 | err = nl80211_parse_sta_channel_info(info, params); |
| 3995 | if (err) |
| 3996 | return err; |
| 3997 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3998 | return nl80211_parse_sta_wme(info, params); |
| 3999 | } |
| 4000 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4001 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4002 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4003 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4004 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4005 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4006 | u8 *mac_addr; |
| 4007 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4008 | |
| 4009 | memset(¶ms, 0, sizeof(params)); |
| 4010 | |
| 4011 | params.listen_interval = -1; |
| 4012 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4013 | if (!rdev->ops->change_station) |
| 4014 | return -EOPNOTSUPP; |
| 4015 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4016 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4017 | return -EINVAL; |
| 4018 | |
| 4019 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4020 | return -EINVAL; |
| 4021 | |
| 4022 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4023 | |
| 4024 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4025 | params.supported_rates = |
| 4026 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4027 | params.supported_rates_len = |
| 4028 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4029 | } |
| 4030 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4031 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4032 | params.capability = |
| 4033 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4034 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4035 | } |
| 4036 | |
| 4037 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4038 | params.ext_capab = |
| 4039 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4040 | params.ext_capab_len = |
| 4041 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4042 | } |
| 4043 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4044 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4045 | return -EINVAL; |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4046 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4047 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4048 | return -EINVAL; |
| 4049 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4050 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4051 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4052 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4053 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4054 | return -EINVAL; |
| 4055 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4056 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4057 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4058 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4059 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4060 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4061 | return -EINVAL; |
| 4062 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4063 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4064 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4065 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4066 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4067 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4068 | |
| 4069 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4070 | pm > NL80211_MESH_POWER_MAX) |
| 4071 | return -EINVAL; |
| 4072 | |
| 4073 | params.local_pm = pm; |
| 4074 | } |
| 4075 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4076 | /* Include parameters for TDLS peer (will check later) */ |
| 4077 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4078 | if (err) |
| 4079 | return err; |
| 4080 | |
| 4081 | params.vlan = get_vlan(info, rdev); |
| 4082 | if (IS_ERR(params.vlan)) |
| 4083 | return PTR_ERR(params.vlan); |
| 4084 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4085 | switch (dev->ieee80211_ptr->iftype) { |
| 4086 | case NL80211_IFTYPE_AP: |
| 4087 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4088 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4089 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4090 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4091 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4092 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4093 | break; |
| 4094 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4095 | err = -EOPNOTSUPP; |
| 4096 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4097 | } |
| 4098 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4099 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4100 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4101 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4102 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4103 | if (params.vlan) |
| 4104 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4105 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4106 | return err; |
| 4107 | } |
| 4108 | |
| 4109 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4110 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4111 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4112 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4113 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4114 | struct station_parameters params; |
| 4115 | u8 *mac_addr = NULL; |
| 4116 | |
| 4117 | memset(¶ms, 0, sizeof(params)); |
| 4118 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4119 | if (!rdev->ops->add_station) |
| 4120 | return -EOPNOTSUPP; |
| 4121 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4122 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4123 | return -EINVAL; |
| 4124 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4125 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4126 | return -EINVAL; |
| 4127 | |
| 4128 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4129 | return -EINVAL; |
| 4130 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4131 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4132 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4133 | return -EINVAL; |
| 4134 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4135 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4136 | params.supported_rates = |
| 4137 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4138 | params.supported_rates_len = |
| 4139 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4140 | params.listen_interval = |
| 4141 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4142 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4143 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4144 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4145 | else |
| 4146 | 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] | 4147 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4148 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4149 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4150 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4151 | params.capability = |
| 4152 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4153 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4154 | } |
| 4155 | |
| 4156 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4157 | params.ext_capab = |
| 4158 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4159 | params.ext_capab_len = |
| 4160 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4161 | } |
| 4162 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4163 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4164 | params.ht_capa = |
| 4165 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4166 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4167 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4168 | params.vht_capa = |
| 4169 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4170 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4171 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4172 | params.opmode_notif_used = true; |
| 4173 | params.opmode_notif = |
| 4174 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4175 | } |
| 4176 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4177 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4178 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4179 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4180 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4181 | return -EINVAL; |
| 4182 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4183 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4184 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4185 | if (err) |
| 4186 | return err; |
| 4187 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4188 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4189 | if (err) |
| 4190 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4191 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4192 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4193 | return -EINVAL; |
| 4194 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4195 | /* When you run into this, adjust the code below for the new flag */ |
| 4196 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4197 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4198 | switch (dev->ieee80211_ptr->iftype) { |
| 4199 | case NL80211_IFTYPE_AP: |
| 4200 | case NL80211_IFTYPE_AP_VLAN: |
| 4201 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4202 | /* ignore WME attributes if iface/sta is not capable */ |
| 4203 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4204 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4205 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4206 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4207 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4208 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4209 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4210 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4211 | /* but don't bother the driver with it */ |
| 4212 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4213 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4214 | /* allow authenticated/associated only if driver handles it */ |
| 4215 | if (!(rdev->wiphy.features & |
| 4216 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4217 | params.sta_flags_mask & |
| 4218 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4219 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4220 | return -EINVAL; |
| 4221 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4222 | /* must be last in here for error handling */ |
| 4223 | params.vlan = get_vlan(info, rdev); |
| 4224 | if (IS_ERR(params.vlan)) |
| 4225 | return PTR_ERR(params.vlan); |
| 4226 | break; |
| 4227 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4228 | /* ignore uAPSD data */ |
| 4229 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4230 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4231 | /* associated is disallowed */ |
| 4232 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4233 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4234 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4235 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4236 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4237 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4238 | break; |
| 4239 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4240 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4241 | /* ignore uAPSD data */ |
| 4242 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4243 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4244 | /* these are disallowed */ |
| 4245 | if (params.sta_flags_mask & |
| 4246 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4247 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4248 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4249 | /* Only TDLS peers can be added */ |
| 4250 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4251 | return -EINVAL; |
| 4252 | /* Can only add if TDLS ... */ |
| 4253 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4254 | return -EOPNOTSUPP; |
| 4255 | /* ... with external setup is supported */ |
| 4256 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4257 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4258 | /* |
| 4259 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4260 | * as authorized, but it shouldn't yet be. |
| 4261 | */ |
| 4262 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4263 | break; |
| 4264 | default: |
| 4265 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4266 | } |
| 4267 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4268 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4269 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4270 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4271 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4272 | if (params.vlan) |
| 4273 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4274 | return err; |
| 4275 | } |
| 4276 | |
| 4277 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4278 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4279 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4280 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4281 | u8 *mac_addr = NULL; |
| 4282 | |
| 4283 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4284 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4285 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4286 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4287 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4288 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4289 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4290 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4291 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4292 | if (!rdev->ops->del_station) |
| 4293 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4294 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4295 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4296 | } |
| 4297 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4298 | 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] | 4299 | int flags, struct net_device *dev, |
| 4300 | u8 *dst, u8 *next_hop, |
| 4301 | struct mpath_info *pinfo) |
| 4302 | { |
| 4303 | void *hdr; |
| 4304 | struct nlattr *pinfoattr; |
| 4305 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4306 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4307 | if (!hdr) |
| 4308 | return -1; |
| 4309 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4310 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4311 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4312 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4313 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4314 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4315 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4316 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4317 | if (!pinfoattr) |
| 4318 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4319 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4320 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4321 | pinfo->frame_qlen)) |
| 4322 | goto nla_put_failure; |
| 4323 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4324 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4325 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4326 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4327 | pinfo->metric)) || |
| 4328 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4329 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4330 | pinfo->exptime)) || |
| 4331 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4332 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4333 | pinfo->flags)) || |
| 4334 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4335 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4336 | pinfo->discovery_timeout)) || |
| 4337 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4338 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4339 | pinfo->discovery_retries))) |
| 4340 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4341 | |
| 4342 | nla_nest_end(msg, pinfoattr); |
| 4343 | |
| 4344 | return genlmsg_end(msg, hdr); |
| 4345 | |
| 4346 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4347 | genlmsg_cancel(msg, hdr); |
| 4348 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4352 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4353 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4354 | struct mpath_info pinfo; |
| 4355 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4356 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4357 | u8 dst[ETH_ALEN]; |
| 4358 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4359 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4360 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4361 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4362 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4363 | if (err) |
| 4364 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4365 | |
| 4366 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4367 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4368 | goto out_err; |
| 4369 | } |
| 4370 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4371 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4372 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4373 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4374 | } |
| 4375 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4376 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4377 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4378 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4379 | if (err == -ENOENT) |
| 4380 | break; |
| 4381 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4382 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4383 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4384 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4385 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4386 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4387 | &pinfo) < 0) |
| 4388 | goto out; |
| 4389 | |
| 4390 | path_idx++; |
| 4391 | } |
| 4392 | |
| 4393 | |
| 4394 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4395 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4396 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4397 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4398 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4399 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4400 | } |
| 4401 | |
| 4402 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4403 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4404 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4405 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4406 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4407 | struct mpath_info pinfo; |
| 4408 | struct sk_buff *msg; |
| 4409 | u8 *dst = NULL; |
| 4410 | u8 next_hop[ETH_ALEN]; |
| 4411 | |
| 4412 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4413 | |
| 4414 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4415 | return -EINVAL; |
| 4416 | |
| 4417 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4418 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4419 | if (!rdev->ops->get_mpath) |
| 4420 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4421 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4422 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4423 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4424 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4425 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4426 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4427 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4428 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4429 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4430 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4431 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4432 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4433 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4434 | dev, dst, next_hop, &pinfo) < 0) { |
| 4435 | nlmsg_free(msg); |
| 4436 | return -ENOBUFS; |
| 4437 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4438 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4439 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4443 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4444 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4445 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4446 | u8 *dst = NULL; |
| 4447 | u8 *next_hop = NULL; |
| 4448 | |
| 4449 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4450 | return -EINVAL; |
| 4451 | |
| 4452 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4453 | return -EINVAL; |
| 4454 | |
| 4455 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4456 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4457 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4458 | if (!rdev->ops->change_mpath) |
| 4459 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4460 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4461 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4462 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4463 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4464 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4465 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4466 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4467 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4468 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4469 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4470 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4471 | u8 *dst = NULL; |
| 4472 | u8 *next_hop = NULL; |
| 4473 | |
| 4474 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4475 | return -EINVAL; |
| 4476 | |
| 4477 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4478 | return -EINVAL; |
| 4479 | |
| 4480 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4481 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4482 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4483 | if (!rdev->ops->add_mpath) |
| 4484 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4485 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4486 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4487 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4488 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4489 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4490 | } |
| 4491 | |
| 4492 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4493 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4494 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4495 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4496 | u8 *dst = NULL; |
| 4497 | |
| 4498 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4499 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4500 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4501 | if (!rdev->ops->del_mpath) |
| 4502 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4503 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4504 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4505 | } |
| 4506 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4507 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4508 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4509 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4510 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4511 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4512 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4513 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4514 | |
| 4515 | memset(¶ms, 0, sizeof(params)); |
| 4516 | /* default to not changing parameters */ |
| 4517 | params.use_cts_prot = -1; |
| 4518 | params.use_short_preamble = -1; |
| 4519 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4520 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4521 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4522 | params.p2p_ctwindow = -1; |
| 4523 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4524 | |
| 4525 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4526 | params.use_cts_prot = |
| 4527 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4528 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4529 | params.use_short_preamble = |
| 4530 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4531 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4532 | params.use_short_slot_time = |
| 4533 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4534 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4535 | params.basic_rates = |
| 4536 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4537 | params.basic_rates_len = |
| 4538 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4539 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4540 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4541 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4542 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4543 | params.ht_opmode = |
| 4544 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4545 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4546 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4547 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4548 | return -EINVAL; |
| 4549 | params.p2p_ctwindow = |
| 4550 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4551 | if (params.p2p_ctwindow < 0) |
| 4552 | return -EINVAL; |
| 4553 | if (params.p2p_ctwindow != 0 && |
| 4554 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4555 | return -EINVAL; |
| 4556 | } |
| 4557 | |
| 4558 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4559 | u8 tmp; |
| 4560 | |
| 4561 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4562 | return -EINVAL; |
| 4563 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4564 | if (tmp > 1) |
| 4565 | return -EINVAL; |
| 4566 | params.p2p_opp_ps = tmp; |
| 4567 | if (params.p2p_opp_ps && |
| 4568 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4569 | return -EINVAL; |
| 4570 | } |
| 4571 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4572 | if (!rdev->ops->change_bss) |
| 4573 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4574 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4575 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4576 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4577 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4578 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4579 | wdev_lock(wdev); |
| 4580 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4581 | wdev_unlock(wdev); |
| 4582 | |
| 4583 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4584 | } |
| 4585 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4586 | 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] | 4587 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4588 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4589 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4590 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4591 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4592 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4593 | }; |
| 4594 | |
| 4595 | static int parse_reg_rule(struct nlattr *tb[], |
| 4596 | struct ieee80211_reg_rule *reg_rule) |
| 4597 | { |
| 4598 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4599 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4600 | |
| 4601 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4602 | return -EINVAL; |
| 4603 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4604 | return -EINVAL; |
| 4605 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4606 | return -EINVAL; |
| 4607 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4608 | return -EINVAL; |
| 4609 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4610 | return -EINVAL; |
| 4611 | |
| 4612 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4613 | |
| 4614 | freq_range->start_freq_khz = |
| 4615 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4616 | freq_range->end_freq_khz = |
| 4617 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4618 | freq_range->max_bandwidth_khz = |
| 4619 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4620 | |
| 4621 | power_rule->max_eirp = |
| 4622 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4623 | |
| 4624 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4625 | power_rule->max_antenna_gain = |
| 4626 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4627 | |
| 4628 | return 0; |
| 4629 | } |
| 4630 | |
| 4631 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4632 | { |
| 4633 | int r; |
| 4634 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4635 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4636 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4637 | /* |
| 4638 | * You should only get this when cfg80211 hasn't yet initialized |
| 4639 | * completely when built-in to the kernel right between the time |
| 4640 | * window between nl80211_init() and regulatory_init(), if that is |
| 4641 | * even possible. |
| 4642 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4643 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4644 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4645 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4646 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4647 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4648 | |
| 4649 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4650 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4651 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4652 | user_reg_hint_type = |
| 4653 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4654 | else |
| 4655 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4656 | |
| 4657 | switch (user_reg_hint_type) { |
| 4658 | case NL80211_USER_REG_HINT_USER: |
| 4659 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4660 | break; |
| 4661 | default: |
| 4662 | return -EINVAL; |
| 4663 | } |
| 4664 | |
| 4665 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4666 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4667 | return r; |
| 4668 | } |
| 4669 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4670 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4671 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4672 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4673 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4674 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4675 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4676 | struct mesh_config cur_params; |
| 4677 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4678 | void *hdr; |
| 4679 | struct nlattr *pinfoattr; |
| 4680 | struct sk_buff *msg; |
| 4681 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4682 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4683 | return -EOPNOTSUPP; |
| 4684 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4685 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4686 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4687 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4688 | wdev_lock(wdev); |
| 4689 | /* If not connected, get default parameters */ |
| 4690 | if (!wdev->mesh_id_len) |
| 4691 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4692 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4693 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4694 | wdev_unlock(wdev); |
| 4695 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4696 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4697 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4698 | |
| 4699 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4700 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4701 | if (!msg) |
| 4702 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4703 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4704 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4705 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4706 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4707 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4708 | if (!pinfoattr) |
| 4709 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4710 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4711 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4712 | cur_params.dot11MeshRetryTimeout) || |
| 4713 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4714 | cur_params.dot11MeshConfirmTimeout) || |
| 4715 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4716 | cur_params.dot11MeshHoldingTimeout) || |
| 4717 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4718 | cur_params.dot11MeshMaxPeerLinks) || |
| 4719 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4720 | cur_params.dot11MeshMaxRetries) || |
| 4721 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4722 | cur_params.dot11MeshTTL) || |
| 4723 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4724 | cur_params.element_ttl) || |
| 4725 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4726 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4727 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4728 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4729 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4730 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4731 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4732 | cur_params.path_refresh_time) || |
| 4733 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4734 | cur_params.min_discovery_timeout) || |
| 4735 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4736 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4737 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4738 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4739 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4740 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4741 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4742 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4743 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4744 | cur_params.dot11MeshHWMPRootMode) || |
| 4745 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4746 | cur_params.dot11MeshHWMPRannInterval) || |
| 4747 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4748 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4749 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4750 | cur_params.dot11MeshForwarding) || |
| 4751 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4752 | cur_params.rssi_threshold) || |
| 4753 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4754 | cur_params.ht_opmode) || |
| 4755 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4756 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4757 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4758 | cur_params.dot11MeshHWMProotInterval) || |
| 4759 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4760 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4761 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4762 | cur_params.power_mode) || |
| 4763 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4764 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4765 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4766 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4767 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4768 | nla_nest_end(msg, pinfoattr); |
| 4769 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4770 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4771 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4772 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4773 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4774 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4775 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4776 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4777 | } |
| 4778 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4779 | 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] | 4780 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4781 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4782 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4783 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4784 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4785 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4786 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4787 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4788 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4789 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4790 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4791 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4792 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4793 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4794 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4795 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4796 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4797 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4798 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4799 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4800 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4801 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4802 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4803 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4804 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4805 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4806 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4807 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4808 | }; |
| 4809 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4810 | static const struct nla_policy |
| 4811 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4812 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4813 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4814 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4815 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4816 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4817 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4818 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4819 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4820 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4821 | }; |
| 4822 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4823 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4824 | struct mesh_config *cfg, |
| 4825 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4826 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4827 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4828 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4829 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4830 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4831 | do { \ |
| 4832 | if (tb[attr]) { \ |
| 4833 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4834 | return -EINVAL; \ |
| 4835 | cfg->param = fn(tb[attr]); \ |
| 4836 | mask |= (1 << (attr - 1)); \ |
| 4837 | } \ |
| 4838 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4839 | |
| 4840 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4841 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4842 | return -EINVAL; |
| 4843 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4844 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4845 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4846 | return -EINVAL; |
| 4847 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4848 | /* This makes sure that there aren't more than 32 mesh config |
| 4849 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4850 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4851 | |
| 4852 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4853 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4854 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4855 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4856 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4857 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4858 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4859 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4860 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4861 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4862 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4863 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4864 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4865 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4866 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4867 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4868 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4869 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4870 | 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] | 4871 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4872 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4873 | 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] | 4874 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4875 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4876 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4877 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4878 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4879 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4880 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4881 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4882 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4883 | 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] | 4884 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4885 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4886 | 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] | 4887 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4888 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4889 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4890 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4891 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4892 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4893 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4894 | 1, 65535, mask, |
| 4895 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4896 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4897 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4898 | 1, 65535, mask, |
| 4899 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4900 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4901 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4902 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4903 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4904 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4905 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4906 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4907 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4908 | nla_get_u8); |
| 4909 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4910 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4911 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4912 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4913 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4914 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4915 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4916 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4917 | mask, NL80211_MESHCONF_FORWARDING, |
| 4918 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4919 | 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] | 4920 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4921 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4922 | 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] | 4923 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4924 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4925 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4926 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4927 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4928 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4929 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4930 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4931 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4932 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4933 | dot11MeshHWMPconfirmationInterval, |
| 4934 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4935 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4936 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4937 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4938 | NL80211_MESH_POWER_ACTIVE, |
| 4939 | NL80211_MESH_POWER_MAX, |
| 4940 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4941 | nla_get_u32); |
| 4942 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4943 | 0, 65535, mask, |
| 4944 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4945 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4946 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4947 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4948 | if (mask_out) |
| 4949 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4950 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4951 | return 0; |
| 4952 | |
| 4953 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4954 | } |
| 4955 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4956 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4957 | struct mesh_setup *setup) |
| 4958 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4959 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4960 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4961 | |
| 4962 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4963 | return -EINVAL; |
| 4964 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4965 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4966 | nl80211_mesh_setup_params_policy)) |
| 4967 | return -EINVAL; |
| 4968 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4969 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4970 | setup->sync_method = |
| 4971 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4972 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4973 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4974 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4975 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4976 | setup->path_sel_proto = |
| 4977 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4978 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4979 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4980 | |
| 4981 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4982 | setup->path_metric = |
| 4983 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4984 | IEEE80211_PATH_METRIC_VENDOR : |
| 4985 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4986 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4987 | |
| 4988 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4989 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4990 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4991 | if (!is_valid_ie_attr(ieattr)) |
| 4992 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4993 | setup->ie = nla_data(ieattr); |
| 4994 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4995 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4996 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4997 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4998 | return -EINVAL; |
| 4999 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5000 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5001 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5002 | if (setup->is_secure) |
| 5003 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5004 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5005 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5006 | if (!setup->user_mpm) |
| 5007 | return -EINVAL; |
| 5008 | setup->auth_id = |
| 5009 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5010 | } |
| 5011 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5012 | return 0; |
| 5013 | } |
| 5014 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5015 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5016 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5017 | { |
| 5018 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5019 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5020 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5021 | struct mesh_config cfg; |
| 5022 | u32 mask; |
| 5023 | int err; |
| 5024 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5025 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5026 | return -EOPNOTSUPP; |
| 5027 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5028 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5029 | return -EOPNOTSUPP; |
| 5030 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5031 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5032 | if (err) |
| 5033 | return err; |
| 5034 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5035 | wdev_lock(wdev); |
| 5036 | if (!wdev->mesh_id_len) |
| 5037 | err = -ENOLINK; |
| 5038 | |
| 5039 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5040 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5041 | |
| 5042 | wdev_unlock(wdev); |
| 5043 | |
| 5044 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5045 | } |
| 5046 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5047 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 5048 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5049 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5050 | struct sk_buff *msg; |
| 5051 | void *hdr = NULL; |
| 5052 | struct nlattr *nl_reg_rules; |
| 5053 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5054 | |
| 5055 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5056 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5057 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5058 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5059 | if (!msg) |
| 5060 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5061 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5062 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5063 | NL80211_CMD_GET_REG); |
| 5064 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5065 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5066 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5067 | if (reg_last_request_cell_base() && |
| 5068 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5069 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5070 | goto nla_put_failure; |
| 5071 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5072 | rcu_read_lock(); |
| 5073 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5074 | |
| 5075 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5076 | (regdom->dfs_region && |
| 5077 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5078 | goto nla_put_failure_rcu; |
| 5079 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5080 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5081 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5082 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5083 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5084 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5085 | struct nlattr *nl_reg_rule; |
| 5086 | const struct ieee80211_reg_rule *reg_rule; |
| 5087 | const struct ieee80211_freq_range *freq_range; |
| 5088 | const struct ieee80211_power_rule *power_rule; |
| 5089 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5090 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5091 | freq_range = ®_rule->freq_range; |
| 5092 | power_rule = ®_rule->power_rule; |
| 5093 | |
| 5094 | nl_reg_rule = nla_nest_start(msg, i); |
| 5095 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5096 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5097 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5098 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5099 | reg_rule->flags) || |
| 5100 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5101 | freq_range->start_freq_khz) || |
| 5102 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5103 | freq_range->end_freq_khz) || |
| 5104 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 5105 | freq_range->max_bandwidth_khz) || |
| 5106 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5107 | power_rule->max_antenna_gain) || |
| 5108 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 5109 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5110 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5111 | |
| 5112 | nla_nest_end(msg, nl_reg_rule); |
| 5113 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5114 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5115 | |
| 5116 | nla_nest_end(msg, nl_reg_rules); |
| 5117 | |
| 5118 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5119 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5120 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5121 | nla_put_failure_rcu: |
| 5122 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5123 | nla_put_failure: |
| 5124 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5125 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5126 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5127 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5128 | } |
| 5129 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5130 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5131 | { |
| 5132 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5133 | struct nlattr *nl_reg_rule; |
| 5134 | char *alpha2 = NULL; |
| 5135 | int rem_reg_rules = 0, r = 0; |
| 5136 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5137 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5138 | struct ieee80211_regdomain *rd = NULL; |
| 5139 | |
| 5140 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5141 | return -EINVAL; |
| 5142 | |
| 5143 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5144 | return -EINVAL; |
| 5145 | |
| 5146 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5147 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5148 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5149 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5150 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5151 | 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] | 5152 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5153 | num_rules++; |
| 5154 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5155 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5156 | } |
| 5157 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5158 | if (!reg_is_valid_request(alpha2)) |
| 5159 | return -EINVAL; |
| 5160 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5161 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5162 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5163 | |
| 5164 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5165 | if (!rd) |
| 5166 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5167 | |
| 5168 | rd->n_reg_rules = num_rules; |
| 5169 | rd->alpha2[0] = alpha2[0]; |
| 5170 | rd->alpha2[1] = alpha2[1]; |
| 5171 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5172 | /* |
| 5173 | * Disable DFS master mode if the DFS region was |
| 5174 | * not supported or known on this kernel. |
| 5175 | */ |
| 5176 | if (reg_supported_dfs_region(dfs_region)) |
| 5177 | rd->dfs_region = dfs_region; |
| 5178 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5179 | 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] | 5180 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5181 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5182 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5183 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5184 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5185 | if (r) |
| 5186 | goto bad_reg; |
| 5187 | |
| 5188 | rule_idx++; |
| 5189 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5190 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5191 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5192 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5193 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5194 | } |
| 5195 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5196 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5197 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5198 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5199 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5200 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5201 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5202 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5203 | } |
| 5204 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5205 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5206 | { |
| 5207 | struct nlattr *attr1, *attr2; |
| 5208 | int n_channels = 0, tmp1, tmp2; |
| 5209 | |
| 5210 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5211 | n_channels++; |
| 5212 | /* |
| 5213 | * Some hardware has a limited channel list for |
| 5214 | * scanning, and it is pretty much nonsensical |
| 5215 | * to scan for a channel twice, so disallow that |
| 5216 | * and don't require drivers to check that the |
| 5217 | * channel list they get isn't longer than what |
| 5218 | * they can scan, as long as they can scan all |
| 5219 | * the channels they registered at once. |
| 5220 | */ |
| 5221 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5222 | if (attr1 != attr2 && |
| 5223 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5224 | return 0; |
| 5225 | } |
| 5226 | |
| 5227 | return n_channels; |
| 5228 | } |
| 5229 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5230 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5231 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5232 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5233 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5234 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5235 | struct nlattr *attr; |
| 5236 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5237 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5238 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5239 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5240 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5241 | return -EINVAL; |
| 5242 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5243 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5244 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5245 | if (!rdev->ops->scan) |
| 5246 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5247 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 5248 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5249 | err = -EBUSY; |
| 5250 | goto unlock; |
| 5251 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5252 | |
| 5253 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5254 | n_channels = validate_scan_freqs( |
| 5255 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5256 | if (!n_channels) { |
| 5257 | err = -EINVAL; |
| 5258 | goto unlock; |
| 5259 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5260 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5261 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5262 | } |
| 5263 | |
| 5264 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5265 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5266 | n_ssids++; |
| 5267 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5268 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5269 | err = -EINVAL; |
| 5270 | goto unlock; |
| 5271 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5272 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5273 | if (info->attrs[NL80211_ATTR_IE]) |
| 5274 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5275 | else |
| 5276 | ie_len = 0; |
| 5277 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5278 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5279 | err = -EINVAL; |
| 5280 | goto unlock; |
| 5281 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5282 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5283 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5284 | + sizeof(*request->ssids) * n_ssids |
| 5285 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5286 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5287 | if (!request) { |
| 5288 | err = -ENOMEM; |
| 5289 | goto unlock; |
| 5290 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5291 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5292 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5293 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5294 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5295 | if (ie_len) { |
| 5296 | if (request->ssids) |
| 5297 | request->ie = (void *)(request->ssids + n_ssids); |
| 5298 | else |
| 5299 | request->ie = (void *)(request->channels + n_channels); |
| 5300 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5301 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5302 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5303 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5304 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5305 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5306 | struct ieee80211_channel *chan; |
| 5307 | |
| 5308 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5309 | |
| 5310 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5311 | err = -EINVAL; |
| 5312 | goto out_free; |
| 5313 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5314 | |
| 5315 | /* ignore disabled channels */ |
| 5316 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5317 | continue; |
| 5318 | |
| 5319 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5320 | i++; |
| 5321 | } |
| 5322 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5323 | enum ieee80211_band band; |
| 5324 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5325 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5326 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5327 | int j; |
| 5328 | if (!wiphy->bands[band]) |
| 5329 | continue; |
| 5330 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5331 | struct ieee80211_channel *chan; |
| 5332 | |
| 5333 | chan = &wiphy->bands[band]->channels[j]; |
| 5334 | |
| 5335 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5336 | continue; |
| 5337 | |
| 5338 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5339 | i++; |
| 5340 | } |
| 5341 | } |
| 5342 | } |
| 5343 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5344 | if (!i) { |
| 5345 | err = -EINVAL; |
| 5346 | goto out_free; |
| 5347 | } |
| 5348 | |
| 5349 | request->n_channels = i; |
| 5350 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5351 | i = 0; |
| 5352 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5353 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5354 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5355 | err = -EINVAL; |
| 5356 | goto out_free; |
| 5357 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5358 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5359 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5360 | i++; |
| 5361 | } |
| 5362 | } |
| 5363 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5364 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5365 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5366 | memcpy((void *)request->ie, |
| 5367 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5368 | request->ie_len); |
| 5369 | } |
| 5370 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5371 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5372 | if (wiphy->bands[i]) |
| 5373 | request->rates[i] = |
| 5374 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5375 | |
| 5376 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5377 | nla_for_each_nested(attr, |
| 5378 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5379 | tmp) { |
| 5380 | enum ieee80211_band band = nla_type(attr); |
| 5381 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5382 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5383 | err = -EINVAL; |
| 5384 | goto out_free; |
| 5385 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5386 | |
| 5387 | if (!wiphy->bands[band]) |
| 5388 | continue; |
| 5389 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5390 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5391 | nla_data(attr), |
| 5392 | nla_len(attr), |
| 5393 | &request->rates[band]); |
| 5394 | if (err) |
| 5395 | goto out_free; |
| 5396 | } |
| 5397 | } |
| 5398 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5399 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5400 | request->flags = nla_get_u32( |
| 5401 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5402 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5403 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5404 | err = -EOPNOTSUPP; |
| 5405 | goto out_free; |
| 5406 | } |
| 5407 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5408 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5409 | request->no_cck = |
| 5410 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5411 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5412 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5413 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5414 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5415 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5416 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5417 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5418 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5419 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5420 | nl80211_send_scan_start(rdev, wdev); |
| 5421 | if (wdev->netdev) |
| 5422 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5423 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5424 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5425 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5426 | kfree(request); |
| 5427 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5428 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5429 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5430 | return err; |
| 5431 | } |
| 5432 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5433 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5434 | struct genl_info *info) |
| 5435 | { |
| 5436 | struct cfg80211_sched_scan_request *request; |
| 5437 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5438 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5439 | struct nlattr *attr; |
| 5440 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5441 | 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] | 5442 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5443 | enum ieee80211_band band; |
| 5444 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5445 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5446 | |
| 5447 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5448 | !rdev->ops->sched_scan_start) |
| 5449 | return -EOPNOTSUPP; |
| 5450 | |
| 5451 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5452 | return -EINVAL; |
| 5453 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5454 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5455 | return -EINVAL; |
| 5456 | |
| 5457 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5458 | if (interval == 0) |
| 5459 | return -EINVAL; |
| 5460 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5461 | wiphy = &rdev->wiphy; |
| 5462 | |
| 5463 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5464 | n_channels = validate_scan_freqs( |
| 5465 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5466 | if (!n_channels) |
| 5467 | return -EINVAL; |
| 5468 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5469 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5470 | } |
| 5471 | |
| 5472 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5473 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5474 | tmp) |
| 5475 | n_ssids++; |
| 5476 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5477 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5478 | return -EINVAL; |
| 5479 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5480 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5481 | nla_for_each_nested(attr, |
| 5482 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5483 | tmp) |
| 5484 | n_match_sets++; |
| 5485 | |
| 5486 | if (n_match_sets > wiphy->max_match_sets) |
| 5487 | return -EINVAL; |
| 5488 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5489 | if (info->attrs[NL80211_ATTR_IE]) |
| 5490 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5491 | else |
| 5492 | ie_len = 0; |
| 5493 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5494 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5495 | return -EINVAL; |
| 5496 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5497 | if (rdev->sched_scan_req) { |
| 5498 | err = -EINPROGRESS; |
| 5499 | goto out; |
| 5500 | } |
| 5501 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5502 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5503 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5504 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5505 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5506 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5507 | if (!request) { |
| 5508 | err = -ENOMEM; |
| 5509 | goto out; |
| 5510 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5511 | |
| 5512 | if (n_ssids) |
| 5513 | request->ssids = (void *)&request->channels[n_channels]; |
| 5514 | request->n_ssids = n_ssids; |
| 5515 | if (ie_len) { |
| 5516 | if (request->ssids) |
| 5517 | request->ie = (void *)(request->ssids + n_ssids); |
| 5518 | else |
| 5519 | request->ie = (void *)(request->channels + n_channels); |
| 5520 | } |
| 5521 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5522 | if (n_match_sets) { |
| 5523 | if (request->ie) |
| 5524 | request->match_sets = (void *)(request->ie + ie_len); |
| 5525 | else if (request->ssids) |
| 5526 | request->match_sets = |
| 5527 | (void *)(request->ssids + n_ssids); |
| 5528 | else |
| 5529 | request->match_sets = |
| 5530 | (void *)(request->channels + n_channels); |
| 5531 | } |
| 5532 | request->n_match_sets = n_match_sets; |
| 5533 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5534 | i = 0; |
| 5535 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5536 | /* user specified, bail out if channel not found */ |
| 5537 | nla_for_each_nested(attr, |
| 5538 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5539 | tmp) { |
| 5540 | struct ieee80211_channel *chan; |
| 5541 | |
| 5542 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5543 | |
| 5544 | if (!chan) { |
| 5545 | err = -EINVAL; |
| 5546 | goto out_free; |
| 5547 | } |
| 5548 | |
| 5549 | /* ignore disabled channels */ |
| 5550 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5551 | continue; |
| 5552 | |
| 5553 | request->channels[i] = chan; |
| 5554 | i++; |
| 5555 | } |
| 5556 | } else { |
| 5557 | /* all channels */ |
| 5558 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5559 | int j; |
| 5560 | if (!wiphy->bands[band]) |
| 5561 | continue; |
| 5562 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5563 | struct ieee80211_channel *chan; |
| 5564 | |
| 5565 | chan = &wiphy->bands[band]->channels[j]; |
| 5566 | |
| 5567 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5568 | continue; |
| 5569 | |
| 5570 | request->channels[i] = chan; |
| 5571 | i++; |
| 5572 | } |
| 5573 | } |
| 5574 | } |
| 5575 | |
| 5576 | if (!i) { |
| 5577 | err = -EINVAL; |
| 5578 | goto out_free; |
| 5579 | } |
| 5580 | |
| 5581 | request->n_channels = i; |
| 5582 | |
| 5583 | i = 0; |
| 5584 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5585 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5586 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5587 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5588 | err = -EINVAL; |
| 5589 | goto out_free; |
| 5590 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5591 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5592 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5593 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5594 | i++; |
| 5595 | } |
| 5596 | } |
| 5597 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5598 | i = 0; |
| 5599 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5600 | nla_for_each_nested(attr, |
| 5601 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5602 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5603 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5604 | |
| 5605 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5606 | nla_data(attr), nla_len(attr), |
| 5607 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5608 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5609 | if (ssid) { |
| 5610 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5611 | err = -EINVAL; |
| 5612 | goto out_free; |
| 5613 | } |
| 5614 | memcpy(request->match_sets[i].ssid.ssid, |
| 5615 | nla_data(ssid), nla_len(ssid)); |
| 5616 | request->match_sets[i].ssid.ssid_len = |
| 5617 | nla_len(ssid); |
| 5618 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5619 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5620 | if (rssi) |
| 5621 | request->rssi_thold = nla_get_u32(rssi); |
| 5622 | else |
| 5623 | request->rssi_thold = |
| 5624 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5625 | i++; |
| 5626 | } |
| 5627 | } |
| 5628 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5629 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5630 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5631 | memcpy((void *)request->ie, |
| 5632 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5633 | request->ie_len); |
| 5634 | } |
| 5635 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5636 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5637 | request->flags = nla_get_u32( |
| 5638 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5639 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5640 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5641 | err = -EOPNOTSUPP; |
| 5642 | goto out_free; |
| 5643 | } |
| 5644 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5645 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5646 | request->dev = dev; |
| 5647 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5648 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5649 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5650 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5651 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5652 | if (!err) { |
| 5653 | rdev->sched_scan_req = request; |
| 5654 | nl80211_send_sched_scan(rdev, dev, |
| 5655 | NL80211_CMD_START_SCHED_SCAN); |
| 5656 | goto out; |
| 5657 | } |
| 5658 | |
| 5659 | out_free: |
| 5660 | kfree(request); |
| 5661 | out: |
| 5662 | return err; |
| 5663 | } |
| 5664 | |
| 5665 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5666 | struct genl_info *info) |
| 5667 | { |
| 5668 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5669 | |
| 5670 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5671 | !rdev->ops->sched_scan_stop) |
| 5672 | return -EOPNOTSUPP; |
| 5673 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5674 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5675 | } |
| 5676 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5677 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5678 | struct genl_info *info) |
| 5679 | { |
| 5680 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5681 | struct net_device *dev = info->user_ptr[1]; |
| 5682 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5683 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5684 | enum nl80211_dfs_regions dfs_region; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5685 | int err; |
| 5686 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5687 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 5688 | if (dfs_region == NL80211_DFS_UNSET) |
| 5689 | return -EINVAL; |
| 5690 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5691 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5692 | if (err) |
| 5693 | return err; |
| 5694 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5695 | if (netif_carrier_ok(dev)) |
| 5696 | return -EBUSY; |
| 5697 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5698 | if (wdev->cac_started) |
| 5699 | return -EBUSY; |
| 5700 | |
| 5701 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5702 | if (err < 0) |
| 5703 | return err; |
| 5704 | |
| 5705 | if (err == 0) |
| 5706 | return -EINVAL; |
| 5707 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 5708 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5709 | return -EINVAL; |
| 5710 | |
| 5711 | if (!rdev->ops->start_radar_detection) |
| 5712 | return -EOPNOTSUPP; |
| 5713 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5714 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5715 | chandef.chan, CHAN_MODE_SHARED, |
| 5716 | BIT(chandef.width)); |
| 5717 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5718 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5719 | |
| 5720 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5721 | if (!err) { |
| 5722 | wdev->channel = chandef.chan; |
| 5723 | wdev->cac_started = true; |
| 5724 | wdev->cac_start_time = jiffies; |
| 5725 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5726 | return err; |
| 5727 | } |
| 5728 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5729 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5730 | { |
| 5731 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5732 | struct net_device *dev = info->user_ptr[1]; |
| 5733 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5734 | struct cfg80211_csa_settings params; |
| 5735 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5736 | * function is called under RTNL lock, so this should not be a problem. |
| 5737 | */ |
| 5738 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5739 | u8 radar_detect_width = 0; |
| 5740 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5741 | bool need_new_beacon = false; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5742 | |
| 5743 | if (!rdev->ops->channel_switch || |
| 5744 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5745 | return -EOPNOTSUPP; |
| 5746 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5747 | switch (dev->ieee80211_ptr->iftype) { |
| 5748 | case NL80211_IFTYPE_AP: |
| 5749 | case NL80211_IFTYPE_P2P_GO: |
| 5750 | need_new_beacon = true; |
| 5751 | |
| 5752 | /* useless if AP is not running */ |
| 5753 | if (!wdev->beacon_interval) |
| 5754 | return -EINVAL; |
| 5755 | break; |
| 5756 | case NL80211_IFTYPE_ADHOC: |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 5757 | case NL80211_IFTYPE_MESH_POINT: |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5758 | break; |
| 5759 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5760 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5761 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5762 | |
| 5763 | memset(¶ms, 0, sizeof(params)); |
| 5764 | |
| 5765 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5766 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5767 | return -EINVAL; |
| 5768 | |
| 5769 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 5770 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5771 | return -EINVAL; |
| 5772 | |
| 5773 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5774 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5775 | if (!need_new_beacon) |
| 5776 | goto skip_beacons; |
| 5777 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5778 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5779 | if (err) |
| 5780 | return err; |
| 5781 | |
| 5782 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5783 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5784 | nl80211_policy); |
| 5785 | if (err) |
| 5786 | return err; |
| 5787 | |
| 5788 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5789 | if (err) |
| 5790 | return err; |
| 5791 | |
| 5792 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5793 | return -EINVAL; |
| 5794 | |
| 5795 | params.counter_offset_beacon = |
| 5796 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5797 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) |
| 5798 | return -EINVAL; |
| 5799 | |
| 5800 | /* sanity check - counters should be the same */ |
| 5801 | if (params.beacon_csa.tail[params.counter_offset_beacon] != |
| 5802 | params.count) |
| 5803 | return -EINVAL; |
| 5804 | |
| 5805 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
| 5806 | params.counter_offset_presp = |
| 5807 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5808 | if (params.counter_offset_presp >= |
| 5809 | params.beacon_csa.probe_resp_len) |
| 5810 | return -EINVAL; |
| 5811 | |
| 5812 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != |
| 5813 | params.count) |
| 5814 | return -EINVAL; |
| 5815 | } |
| 5816 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5817 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5818 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5819 | if (err) |
| 5820 | return err; |
| 5821 | |
| 5822 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
| 5823 | return -EINVAL; |
| 5824 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5825 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP || |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 5826 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO || |
| 5827 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) { |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5828 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 5829 | ¶ms.chandef); |
| 5830 | if (err < 0) { |
| 5831 | return err; |
| 5832 | } else if (err) { |
| 5833 | radar_detect_width = BIT(params.chandef.width); |
| 5834 | params.radar_required = true; |
| 5835 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5836 | } |
| 5837 | |
| 5838 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5839 | params.chandef.chan, |
| 5840 | CHAN_MODE_SHARED, |
| 5841 | radar_detect_width); |
| 5842 | if (err) |
| 5843 | return err; |
| 5844 | |
| 5845 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 5846 | params.block_tx = true; |
| 5847 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5848 | wdev_lock(wdev); |
| 5849 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 5850 | wdev_unlock(wdev); |
| 5851 | |
| 5852 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5853 | } |
| 5854 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5855 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5856 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5857 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5858 | struct wireless_dev *wdev, |
| 5859 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5860 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5861 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5862 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5863 | void *hdr; |
| 5864 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5865 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5866 | |
| 5867 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5868 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5869 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5870 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5871 | if (!hdr) |
| 5872 | return -1; |
| 5873 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5874 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5875 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5876 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5877 | goto nla_put_failure; |
| 5878 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5879 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5880 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5881 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5882 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5883 | |
| 5884 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5885 | if (!bss) |
| 5886 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5887 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5888 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5889 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5890 | |
| 5891 | rcu_read_lock(); |
| 5892 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5893 | if (ies) { |
| 5894 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5895 | goto fail_unlock_rcu; |
| 5896 | tsf = true; |
| 5897 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5898 | ies->len, ies->data)) |
| 5899 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5900 | } |
| 5901 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5902 | if (ies) { |
| 5903 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5904 | goto fail_unlock_rcu; |
| 5905 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5906 | ies->len, ies->data)) |
| 5907 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5908 | } |
| 5909 | rcu_read_unlock(); |
| 5910 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5911 | if (res->beacon_interval && |
| 5912 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5913 | goto nla_put_failure; |
| 5914 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5915 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 5916 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5917 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5918 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5919 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5920 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5921 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5922 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5923 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5924 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5925 | break; |
| 5926 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5927 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5928 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5929 | break; |
| 5930 | default: |
| 5931 | break; |
| 5932 | } |
| 5933 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5934 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5935 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5936 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5937 | if (intbss == wdev->current_bss && |
| 5938 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5939 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5940 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5941 | break; |
| 5942 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5943 | if (intbss == wdev->current_bss && |
| 5944 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5945 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5946 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5947 | break; |
| 5948 | default: |
| 5949 | break; |
| 5950 | } |
| 5951 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5952 | nla_nest_end(msg, bss); |
| 5953 | |
| 5954 | return genlmsg_end(msg, hdr); |
| 5955 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5956 | fail_unlock_rcu: |
| 5957 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5958 | nla_put_failure: |
| 5959 | genlmsg_cancel(msg, hdr); |
| 5960 | return -EMSGSIZE; |
| 5961 | } |
| 5962 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5963 | 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] | 5964 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5965 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5966 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5967 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5968 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5969 | int err; |
| 5970 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5971 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5972 | if (err) |
| 5973 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5974 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5975 | wdev_lock(wdev); |
| 5976 | spin_lock_bh(&rdev->bss_lock); |
| 5977 | cfg80211_bss_expire(rdev); |
| 5978 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5979 | cb->seq = rdev->bss_generation; |
| 5980 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5981 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5982 | if (++idx <= start) |
| 5983 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5984 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5985 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5986 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5987 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5988 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5989 | } |
| 5990 | } |
| 5991 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5992 | spin_unlock_bh(&rdev->bss_lock); |
| 5993 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5994 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5995 | cb->args[2] = idx; |
| 5996 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5997 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5998 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5999 | } |
| 6000 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6001 | 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] | 6002 | int flags, struct net_device *dev, |
| 6003 | struct survey_info *survey) |
| 6004 | { |
| 6005 | void *hdr; |
| 6006 | struct nlattr *infoattr; |
| 6007 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6008 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6009 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6010 | if (!hdr) |
| 6011 | return -ENOMEM; |
| 6012 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6013 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6014 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6015 | |
| 6016 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6017 | if (!infoattr) |
| 6018 | goto nla_put_failure; |
| 6019 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6020 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 6021 | survey->channel->center_freq)) |
| 6022 | goto nla_put_failure; |
| 6023 | |
| 6024 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6025 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6026 | goto nla_put_failure; |
| 6027 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6028 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6029 | goto nla_put_failure; |
| 6030 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6031 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6032 | survey->channel_time)) |
| 6033 | goto nla_put_failure; |
| 6034 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6035 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6036 | survey->channel_time_busy)) |
| 6037 | goto nla_put_failure; |
| 6038 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6039 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6040 | survey->channel_time_ext_busy)) |
| 6041 | goto nla_put_failure; |
| 6042 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6043 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6044 | survey->channel_time_rx)) |
| 6045 | goto nla_put_failure; |
| 6046 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6047 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6048 | survey->channel_time_tx)) |
| 6049 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6050 | |
| 6051 | nla_nest_end(msg, infoattr); |
| 6052 | |
| 6053 | return genlmsg_end(msg, hdr); |
| 6054 | |
| 6055 | nla_put_failure: |
| 6056 | genlmsg_cancel(msg, hdr); |
| 6057 | return -EMSGSIZE; |
| 6058 | } |
| 6059 | |
| 6060 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6061 | struct netlink_callback *cb) |
| 6062 | { |
| 6063 | struct survey_info survey; |
| 6064 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6065 | struct wireless_dev *wdev; |
| 6066 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6067 | int res; |
| 6068 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6069 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6070 | if (res) |
| 6071 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6072 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6073 | if (!wdev->netdev) { |
| 6074 | res = -EINVAL; |
| 6075 | goto out_err; |
| 6076 | } |
| 6077 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6078 | if (!dev->ops->dump_survey) { |
| 6079 | res = -EOPNOTSUPP; |
| 6080 | goto out_err; |
| 6081 | } |
| 6082 | |
| 6083 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6084 | struct ieee80211_channel *chan; |
| 6085 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6086 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6087 | if (res == -ENOENT) |
| 6088 | break; |
| 6089 | if (res) |
| 6090 | goto out_err; |
| 6091 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6092 | /* Survey without a channel doesn't make sense */ |
| 6093 | if (!survey.channel) { |
| 6094 | res = -EINVAL; |
| 6095 | goto out; |
| 6096 | } |
| 6097 | |
| 6098 | chan = ieee80211_get_channel(&dev->wiphy, |
| 6099 | survey.channel->center_freq); |
| 6100 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6101 | survey_idx++; |
| 6102 | continue; |
| 6103 | } |
| 6104 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6105 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6106 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6107 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6108 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6109 | goto out; |
| 6110 | survey_idx++; |
| 6111 | } |
| 6112 | |
| 6113 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6114 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6115 | res = skb->len; |
| 6116 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6117 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6118 | return res; |
| 6119 | } |
| 6120 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6121 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6122 | { |
| 6123 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6124 | NL80211_WPA_VERSION_2)); |
| 6125 | } |
| 6126 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6127 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6128 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6129 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6130 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6131 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6132 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6133 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6134 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6135 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6136 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6137 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6138 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6139 | return -EINVAL; |
| 6140 | |
| 6141 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6142 | return -EINVAL; |
| 6143 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6144 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6145 | return -EINVAL; |
| 6146 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6147 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6148 | return -EINVAL; |
| 6149 | |
| 6150 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6151 | return -EINVAL; |
| 6152 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6153 | err = nl80211_parse_key(info, &key); |
| 6154 | if (err) |
| 6155 | return err; |
| 6156 | |
| 6157 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6158 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6159 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6160 | if (!key.p.key || !key.p.key_len) |
| 6161 | return -EINVAL; |
| 6162 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6163 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6164 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6165 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6166 | return -EINVAL; |
| 6167 | if (key.idx > 4) |
| 6168 | return -EINVAL; |
| 6169 | } else { |
| 6170 | key.p.key_len = 0; |
| 6171 | key.p.key = NULL; |
| 6172 | } |
| 6173 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6174 | if (key.idx >= 0) { |
| 6175 | int i; |
| 6176 | bool ok = false; |
| 6177 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6178 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6179 | ok = true; |
| 6180 | break; |
| 6181 | } |
| 6182 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6183 | if (!ok) |
| 6184 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6185 | } |
| 6186 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6187 | if (!rdev->ops->auth) |
| 6188 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6189 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6190 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6191 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6192 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6193 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6194 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6195 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6196 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6197 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6198 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6199 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6200 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6201 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6202 | |
| 6203 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6204 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6205 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6206 | } |
| 6207 | |
| 6208 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6209 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6210 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6211 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6212 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6213 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6214 | return -EINVAL; |
| 6215 | |
| 6216 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6217 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6218 | return -EINVAL; |
| 6219 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6220 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6221 | /* need to include at least Auth Transaction and Status Code */ |
| 6222 | if (sae_data_len < 4) |
| 6223 | return -EINVAL; |
| 6224 | } |
| 6225 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6226 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6227 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6228 | /* |
| 6229 | * Since we no longer track auth state, ignore |
| 6230 | * requests to only change local state. |
| 6231 | */ |
| 6232 | if (local_state_change) |
| 6233 | return 0; |
| 6234 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6235 | wdev_lock(dev->ieee80211_ptr); |
| 6236 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6237 | ssid, ssid_len, ie, ie_len, |
| 6238 | key.p.key, key.p.key_len, key.idx, |
| 6239 | sae_data, sae_data_len); |
| 6240 | wdev_unlock(dev->ieee80211_ptr); |
| 6241 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6242 | } |
| 6243 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6244 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6245 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6246 | struct cfg80211_crypto_settings *settings, |
| 6247 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6248 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6249 | memset(settings, 0, sizeof(*settings)); |
| 6250 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6251 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6252 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6253 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6254 | u16 proto; |
| 6255 | proto = nla_get_u16( |
| 6256 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6257 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6258 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6259 | proto != ETH_P_PAE) |
| 6260 | return -EINVAL; |
| 6261 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6262 | settings->control_port_no_encrypt = true; |
| 6263 | } else |
| 6264 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6265 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6266 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6267 | void *data; |
| 6268 | int len, i; |
| 6269 | |
| 6270 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6271 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6272 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6273 | |
| 6274 | if (len % sizeof(u32)) |
| 6275 | return -EINVAL; |
| 6276 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6277 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6278 | return -EINVAL; |
| 6279 | |
| 6280 | memcpy(settings->ciphers_pairwise, data, len); |
| 6281 | |
| 6282 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6283 | if (!cfg80211_supported_cipher_suite( |
| 6284 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6285 | settings->ciphers_pairwise[i])) |
| 6286 | return -EINVAL; |
| 6287 | } |
| 6288 | |
| 6289 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6290 | settings->cipher_group = |
| 6291 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6292 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6293 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6294 | return -EINVAL; |
| 6295 | } |
| 6296 | |
| 6297 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6298 | settings->wpa_versions = |
| 6299 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6300 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6301 | return -EINVAL; |
| 6302 | } |
| 6303 | |
| 6304 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6305 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6306 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6307 | |
| 6308 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6309 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6310 | settings->n_akm_suites = len / sizeof(u32); |
| 6311 | |
| 6312 | if (len % sizeof(u32)) |
| 6313 | return -EINVAL; |
| 6314 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6315 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6316 | return -EINVAL; |
| 6317 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6318 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6319 | } |
| 6320 | |
| 6321 | return 0; |
| 6322 | } |
| 6323 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6324 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6325 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6326 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6327 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6328 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6329 | struct cfg80211_assoc_request req = {}; |
| 6330 | const u8 *bssid, *ssid; |
| 6331 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6332 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6333 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6334 | return -EINVAL; |
| 6335 | |
| 6336 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6337 | !info->attrs[NL80211_ATTR_SSID] || |
| 6338 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6339 | return -EINVAL; |
| 6340 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6341 | if (!rdev->ops->assoc) |
| 6342 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6343 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6344 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6345 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6346 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6347 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6348 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6349 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6350 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6351 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6352 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6353 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6354 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6355 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6356 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6357 | |
| 6358 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6359 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6360 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6361 | } |
| 6362 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6363 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6364 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6365 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6366 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6367 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6368 | else if (mfp != NL80211_MFP_NO) |
| 6369 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6370 | } |
| 6371 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6372 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6373 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6374 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6375 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6376 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6377 | |
| 6378 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6379 | memcpy(&req.ht_capa_mask, |
| 6380 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6381 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6382 | |
| 6383 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6384 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6385 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6386 | memcpy(&req.ht_capa, |
| 6387 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6388 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6389 | } |
| 6390 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6391 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6392 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6393 | |
| 6394 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6395 | memcpy(&req.vht_capa_mask, |
| 6396 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6397 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6398 | |
| 6399 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6400 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6401 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6402 | memcpy(&req.vht_capa, |
| 6403 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6404 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6405 | } |
| 6406 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6407 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6408 | if (!err) { |
| 6409 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6410 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6411 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6412 | wdev_unlock(dev->ieee80211_ptr); |
| 6413 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6414 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6415 | return err; |
| 6416 | } |
| 6417 | |
| 6418 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6419 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6420 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6421 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6422 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6423 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6424 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6425 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6426 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6427 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6428 | return -EINVAL; |
| 6429 | |
| 6430 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6431 | return -EINVAL; |
| 6432 | |
| 6433 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6434 | return -EINVAL; |
| 6435 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6436 | if (!rdev->ops->deauth) |
| 6437 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6438 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6439 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6440 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6441 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6442 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6443 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6444 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6445 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6446 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6447 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6448 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6449 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6450 | |
| 6451 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6452 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6453 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6454 | } |
| 6455 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6456 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6457 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6458 | wdev_lock(dev->ieee80211_ptr); |
| 6459 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6460 | local_state_change); |
| 6461 | wdev_unlock(dev->ieee80211_ptr); |
| 6462 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6463 | } |
| 6464 | |
| 6465 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6466 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6467 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6468 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6469 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6470 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6471 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6472 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6473 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6474 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6475 | return -EINVAL; |
| 6476 | |
| 6477 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6478 | return -EINVAL; |
| 6479 | |
| 6480 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6481 | return -EINVAL; |
| 6482 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6483 | if (!rdev->ops->disassoc) |
| 6484 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6485 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6486 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6487 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6488 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6489 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6490 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6491 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6492 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6493 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6494 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6495 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6496 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6497 | |
| 6498 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6499 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6500 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6501 | } |
| 6502 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6503 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6504 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6505 | wdev_lock(dev->ieee80211_ptr); |
| 6506 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6507 | local_state_change); |
| 6508 | wdev_unlock(dev->ieee80211_ptr); |
| 6509 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6510 | } |
| 6511 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6512 | static bool |
| 6513 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6514 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6515 | int rateval) |
| 6516 | { |
| 6517 | struct wiphy *wiphy = &rdev->wiphy; |
| 6518 | bool found = false; |
| 6519 | int band, i; |
| 6520 | |
| 6521 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6522 | struct ieee80211_supported_band *sband; |
| 6523 | |
| 6524 | sband = wiphy->bands[band]; |
| 6525 | if (!sband) |
| 6526 | continue; |
| 6527 | |
| 6528 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6529 | if (sband->bitrates[i].bitrate == rateval) { |
| 6530 | mcast_rate[band] = i + 1; |
| 6531 | found = true; |
| 6532 | break; |
| 6533 | } |
| 6534 | } |
| 6535 | } |
| 6536 | |
| 6537 | return found; |
| 6538 | } |
| 6539 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6540 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6541 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6542 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6543 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6544 | struct cfg80211_ibss_params ibss; |
| 6545 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6546 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6547 | int err; |
| 6548 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6549 | memset(&ibss, 0, sizeof(ibss)); |
| 6550 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6551 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6552 | return -EINVAL; |
| 6553 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6554 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6555 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6556 | return -EINVAL; |
| 6557 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6558 | ibss.beacon_interval = 100; |
| 6559 | |
| 6560 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6561 | ibss.beacon_interval = |
| 6562 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6563 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6564 | return -EINVAL; |
| 6565 | } |
| 6566 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6567 | if (!rdev->ops->join_ibss) |
| 6568 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6569 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6570 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6571 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6572 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6573 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6574 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6575 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6576 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6577 | |
| 6578 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6579 | return -EINVAL; |
| 6580 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6581 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6582 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6583 | |
| 6584 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6585 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6586 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6587 | } |
| 6588 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6589 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6590 | if (err) |
| 6591 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6592 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6593 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6594 | return -EINVAL; |
| 6595 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6596 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6597 | case NL80211_CHAN_WIDTH_5: |
| 6598 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6599 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6600 | break; |
| 6601 | case NL80211_CHAN_WIDTH_20: |
| 6602 | case NL80211_CHAN_WIDTH_40: |
| 6603 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6604 | break; |
| 6605 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6606 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6607 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6608 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6609 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6610 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6611 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6612 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6613 | u8 *rates = |
| 6614 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6615 | int n_rates = |
| 6616 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6617 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6618 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6619 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6620 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6621 | &ibss.basic_rates); |
| 6622 | if (err) |
| 6623 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6624 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6625 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6626 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6627 | memcpy(&ibss.ht_capa_mask, |
| 6628 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6629 | sizeof(ibss.ht_capa_mask)); |
| 6630 | |
| 6631 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6632 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6633 | return -EINVAL; |
| 6634 | memcpy(&ibss.ht_capa, |
| 6635 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6636 | sizeof(ibss.ht_capa)); |
| 6637 | } |
| 6638 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6639 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6640 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6641 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6642 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6643 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6644 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6645 | bool no_ht = false; |
| 6646 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6647 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6648 | info->attrs[NL80211_ATTR_KEYS], |
| 6649 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6650 | if (IS_ERR(connkeys)) |
| 6651 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6652 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6653 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6654 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6655 | kfree(connkeys); |
| 6656 | return -EINVAL; |
| 6657 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6658 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6659 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6660 | ibss.control_port = |
| 6661 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6662 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 6663 | ibss.userspace_handles_dfs = |
| 6664 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 6665 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6666 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6667 | if (err) |
| 6668 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6669 | return err; |
| 6670 | } |
| 6671 | |
| 6672 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6673 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6674 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6675 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6676 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6677 | if (!rdev->ops->leave_ibss) |
| 6678 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6679 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6680 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6681 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6682 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6683 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6684 | } |
| 6685 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6686 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6687 | { |
| 6688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6689 | struct net_device *dev = info->user_ptr[1]; |
| 6690 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6691 | u32 nla_rate; |
| 6692 | int err; |
| 6693 | |
| 6694 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6695 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6696 | return -EOPNOTSUPP; |
| 6697 | |
| 6698 | if (!rdev->ops->set_mcast_rate) |
| 6699 | return -EOPNOTSUPP; |
| 6700 | |
| 6701 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6702 | |
| 6703 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6704 | return -EINVAL; |
| 6705 | |
| 6706 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6707 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6708 | return -EINVAL; |
| 6709 | |
| 6710 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6711 | |
| 6712 | return err; |
| 6713 | } |
| 6714 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6715 | static struct sk_buff * |
| 6716 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 6717 | int approxlen, u32 portid, u32 seq, |
| 6718 | enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6719 | enum nl80211_attrs attr, |
| 6720 | const struct nl80211_vendor_cmd_info *info, |
| 6721 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6722 | { |
| 6723 | struct sk_buff *skb; |
| 6724 | void *hdr; |
| 6725 | struct nlattr *data; |
| 6726 | |
| 6727 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6728 | if (!skb) |
| 6729 | return NULL; |
| 6730 | |
| 6731 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 6732 | if (!hdr) { |
| 6733 | kfree_skb(skb); |
| 6734 | return NULL; |
| 6735 | } |
| 6736 | |
| 6737 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6738 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6739 | |
| 6740 | if (info) { |
| 6741 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 6742 | info->vendor_id)) |
| 6743 | goto nla_put_failure; |
| 6744 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 6745 | info->subcmd)) |
| 6746 | goto nla_put_failure; |
| 6747 | } |
| 6748 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6749 | data = nla_nest_start(skb, attr); |
| 6750 | |
| 6751 | ((void **)skb->cb)[0] = rdev; |
| 6752 | ((void **)skb->cb)[1] = hdr; |
| 6753 | ((void **)skb->cb)[2] = data; |
| 6754 | |
| 6755 | return skb; |
| 6756 | |
| 6757 | nla_put_failure: |
| 6758 | kfree_skb(skb); |
| 6759 | return NULL; |
| 6760 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6761 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 6762 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
| 6763 | enum nl80211_commands cmd, |
| 6764 | enum nl80211_attrs attr, |
| 6765 | int vendor_event_idx, |
| 6766 | int approxlen, gfp_t gfp) |
| 6767 | { |
| 6768 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6769 | const struct nl80211_vendor_cmd_info *info; |
| 6770 | |
| 6771 | switch (cmd) { |
| 6772 | case NL80211_CMD_TESTMODE: |
| 6773 | if (WARN_ON(vendor_event_idx != -1)) |
| 6774 | return NULL; |
| 6775 | info = NULL; |
| 6776 | break; |
| 6777 | case NL80211_CMD_VENDOR: |
| 6778 | if (WARN_ON(vendor_event_idx < 0 || |
| 6779 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 6780 | return NULL; |
| 6781 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 6782 | break; |
| 6783 | default: |
| 6784 | WARN_ON(1); |
| 6785 | return NULL; |
| 6786 | } |
| 6787 | |
| 6788 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
| 6789 | cmd, attr, info, gfp); |
| 6790 | } |
| 6791 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 6792 | |
| 6793 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 6794 | { |
| 6795 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6796 | void *hdr = ((void **)skb->cb)[1]; |
| 6797 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6798 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 6799 | |
| 6800 | nla_nest_end(skb, data); |
| 6801 | genlmsg_end(skb, hdr); |
| 6802 | |
| 6803 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 6804 | mcgrp = NL80211_MCGRP_VENDOR; |
| 6805 | |
| 6806 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 6807 | mcgrp, gfp); |
| 6808 | } |
| 6809 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 6810 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6811 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6812 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6813 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6814 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6815 | struct wireless_dev *wdev = |
| 6816 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6817 | int err; |
| 6818 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6819 | if (!rdev->ops->testmode_cmd) |
| 6820 | return -EOPNOTSUPP; |
| 6821 | |
| 6822 | if (IS_ERR(wdev)) { |
| 6823 | err = PTR_ERR(wdev); |
| 6824 | if (err != -EINVAL) |
| 6825 | return err; |
| 6826 | wdev = NULL; |
| 6827 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 6828 | return -EINVAL; |
| 6829 | } |
| 6830 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6831 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6832 | return -EINVAL; |
| 6833 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6834 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6835 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6836 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6837 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6838 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6839 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6840 | return err; |
| 6841 | } |
| 6842 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6843 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6844 | struct netlink_callback *cb) |
| 6845 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6846 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6847 | int err; |
| 6848 | long phy_idx; |
| 6849 | void *data = NULL; |
| 6850 | int data_len = 0; |
| 6851 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6852 | rtnl_lock(); |
| 6853 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6854 | if (cb->args[0]) { |
| 6855 | /* |
| 6856 | * 0 is a valid index, but not valid for args[0], |
| 6857 | * so we need to offset by 1. |
| 6858 | */ |
| 6859 | phy_idx = cb->args[0] - 1; |
| 6860 | } else { |
| 6861 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6862 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6863 | nl80211_policy); |
| 6864 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6865 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6866 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6867 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6868 | nl80211_fam.attrbuf); |
| 6869 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6870 | err = PTR_ERR(rdev); |
| 6871 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6872 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6873 | phy_idx = rdev->wiphy_idx; |
| 6874 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6875 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6876 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6877 | cb->args[1] = |
| 6878 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6879 | } |
| 6880 | |
| 6881 | if (cb->args[1]) { |
| 6882 | data = nla_data((void *)cb->args[1]); |
| 6883 | data_len = nla_len((void *)cb->args[1]); |
| 6884 | } |
| 6885 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6886 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6887 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6888 | err = -ENOENT; |
| 6889 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6890 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6891 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6892 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6893 | err = -EOPNOTSUPP; |
| 6894 | goto out_err; |
| 6895 | } |
| 6896 | |
| 6897 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6898 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6899 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6900 | NL80211_CMD_TESTMODE); |
| 6901 | struct nlattr *tmdata; |
| 6902 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 6903 | if (!hdr) |
| 6904 | break; |
| 6905 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6906 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6907 | genlmsg_cancel(skb, hdr); |
| 6908 | break; |
| 6909 | } |
| 6910 | |
| 6911 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6912 | if (!tmdata) { |
| 6913 | genlmsg_cancel(skb, hdr); |
| 6914 | break; |
| 6915 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6916 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6917 | nla_nest_end(skb, tmdata); |
| 6918 | |
| 6919 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6920 | genlmsg_cancel(skb, hdr); |
| 6921 | break; |
| 6922 | } else if (err) { |
| 6923 | genlmsg_cancel(skb, hdr); |
| 6924 | goto out_err; |
| 6925 | } |
| 6926 | |
| 6927 | genlmsg_end(skb, hdr); |
| 6928 | } |
| 6929 | |
| 6930 | err = skb->len; |
| 6931 | /* see above */ |
| 6932 | cb->args[0] = phy_idx + 1; |
| 6933 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6934 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6935 | return err; |
| 6936 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6937 | #endif |
| 6938 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6939 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6940 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6942 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6943 | struct cfg80211_connect_params connect; |
| 6944 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6945 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6946 | int err; |
| 6947 | |
| 6948 | memset(&connect, 0, sizeof(connect)); |
| 6949 | |
| 6950 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6951 | return -EINVAL; |
| 6952 | |
| 6953 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6954 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6955 | return -EINVAL; |
| 6956 | |
| 6957 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6958 | connect.auth_type = |
| 6959 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6960 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6961 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6962 | return -EINVAL; |
| 6963 | } else |
| 6964 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6965 | |
| 6966 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6967 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6968 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6969 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6970 | if (err) |
| 6971 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6972 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6973 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6974 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6975 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6976 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6977 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6978 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6979 | connect.bg_scan_period = -1; |
| 6980 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6981 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6982 | connect.bg_scan_period = |
| 6983 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6984 | } |
| 6985 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6986 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6987 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6988 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6989 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6990 | |
| 6991 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6992 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6993 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6994 | } |
| 6995 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6996 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6997 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6998 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6999 | connect.mfp != NL80211_MFP_NO) |
| 7000 | return -EINVAL; |
| 7001 | } else { |
| 7002 | connect.mfp = NL80211_MFP_NO; |
| 7003 | } |
| 7004 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7005 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7006 | connect.channel = |
| 7007 | ieee80211_get_channel(wiphy, |
| 7008 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 7009 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7010 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 7011 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7012 | } |
| 7013 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7014 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7015 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7016 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7017 | if (IS_ERR(connkeys)) |
| 7018 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7019 | } |
| 7020 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7021 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7022 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7023 | |
| 7024 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7025 | memcpy(&connect.ht_capa_mask, |
| 7026 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7027 | sizeof(connect.ht_capa_mask)); |
| 7028 | |
| 7029 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7030 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 7031 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7032 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7033 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7034 | memcpy(&connect.ht_capa, |
| 7035 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7036 | sizeof(connect.ht_capa)); |
| 7037 | } |
| 7038 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7039 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7040 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7041 | |
| 7042 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7043 | memcpy(&connect.vht_capa_mask, |
| 7044 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7045 | sizeof(connect.vht_capa_mask)); |
| 7046 | |
| 7047 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7048 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 7049 | kfree(connkeys); |
| 7050 | return -EINVAL; |
| 7051 | } |
| 7052 | memcpy(&connect.vht_capa, |
| 7053 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7054 | sizeof(connect.vht_capa)); |
| 7055 | } |
| 7056 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7057 | wdev_lock(dev->ieee80211_ptr); |
| 7058 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7059 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7060 | if (err) |
| 7061 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7062 | return err; |
| 7063 | } |
| 7064 | |
| 7065 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7066 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7067 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7068 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7069 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7070 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7071 | |
| 7072 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7073 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7074 | else |
| 7075 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7076 | |
| 7077 | if (reason == 0) |
| 7078 | return -EINVAL; |
| 7079 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7080 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7081 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7082 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7083 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7084 | wdev_lock(dev->ieee80211_ptr); |
| 7085 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7086 | wdev_unlock(dev->ieee80211_ptr); |
| 7087 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7088 | } |
| 7089 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7090 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7091 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7092 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7093 | struct net *net; |
| 7094 | int err; |
| 7095 | u32 pid; |
| 7096 | |
| 7097 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7098 | return -EINVAL; |
| 7099 | |
| 7100 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7101 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7102 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7103 | if (IS_ERR(net)) |
| 7104 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7105 | |
| 7106 | err = 0; |
| 7107 | |
| 7108 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7109 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7110 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7111 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7112 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7113 | return err; |
| 7114 | } |
| 7115 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7116 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7117 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7118 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7119 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7120 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7121 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7122 | struct cfg80211_pmksa pmksa; |
| 7123 | |
| 7124 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7125 | |
| 7126 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7127 | return -EINVAL; |
| 7128 | |
| 7129 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7130 | return -EINVAL; |
| 7131 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7132 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7133 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7134 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7135 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7136 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7137 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7138 | |
| 7139 | switch (info->genlhdr->cmd) { |
| 7140 | case NL80211_CMD_SET_PMKSA: |
| 7141 | rdev_ops = rdev->ops->set_pmksa; |
| 7142 | break; |
| 7143 | case NL80211_CMD_DEL_PMKSA: |
| 7144 | rdev_ops = rdev->ops->del_pmksa; |
| 7145 | break; |
| 7146 | default: |
| 7147 | WARN_ON(1); |
| 7148 | break; |
| 7149 | } |
| 7150 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7151 | if (!rdev_ops) |
| 7152 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7153 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7154 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7155 | } |
| 7156 | |
| 7157 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7158 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7159 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7160 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7161 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7162 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7163 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7164 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7165 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7166 | if (!rdev->ops->flush_pmksa) |
| 7167 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7168 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7169 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7170 | } |
| 7171 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7172 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7173 | { |
| 7174 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7175 | struct net_device *dev = info->user_ptr[1]; |
| 7176 | u8 action_code, dialog_token; |
| 7177 | u16 status_code; |
| 7178 | u8 *peer; |
| 7179 | |
| 7180 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7181 | !rdev->ops->tdls_mgmt) |
| 7182 | return -EOPNOTSUPP; |
| 7183 | |
| 7184 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7185 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7186 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7187 | !info->attrs[NL80211_ATTR_IE] || |
| 7188 | !info->attrs[NL80211_ATTR_MAC]) |
| 7189 | return -EINVAL; |
| 7190 | |
| 7191 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7192 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7193 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7194 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 7195 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7196 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 7197 | dialog_token, status_code, |
| 7198 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7199 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7200 | } |
| 7201 | |
| 7202 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7203 | { |
| 7204 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7205 | struct net_device *dev = info->user_ptr[1]; |
| 7206 | enum nl80211_tdls_operation operation; |
| 7207 | u8 *peer; |
| 7208 | |
| 7209 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7210 | !rdev->ops->tdls_oper) |
| 7211 | return -EOPNOTSUPP; |
| 7212 | |
| 7213 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7214 | !info->attrs[NL80211_ATTR_MAC]) |
| 7215 | return -EINVAL; |
| 7216 | |
| 7217 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7218 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7219 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7220 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7221 | } |
| 7222 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7223 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7224 | struct genl_info *info) |
| 7225 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7226 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7227 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7228 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7229 | struct sk_buff *msg; |
| 7230 | void *hdr; |
| 7231 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7232 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7233 | int err; |
| 7234 | |
| 7235 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7236 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7237 | return -EINVAL; |
| 7238 | |
| 7239 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7240 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7241 | if (!rdev->ops->remain_on_channel || |
| 7242 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7243 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7244 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7245 | /* |
| 7246 | * We should be on that channel for at least a minimum amount of |
| 7247 | * time (10ms) but no longer than the driver supports. |
| 7248 | */ |
| 7249 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7250 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7251 | return -EINVAL; |
| 7252 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7253 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7254 | if (err) |
| 7255 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7256 | |
| 7257 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7258 | if (!msg) |
| 7259 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7260 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7261 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7262 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7263 | if (!hdr) { |
| 7264 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7265 | goto free_msg; |
| 7266 | } |
| 7267 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7268 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7269 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7270 | |
| 7271 | if (err) |
| 7272 | goto free_msg; |
| 7273 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7274 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7275 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7276 | |
| 7277 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7278 | |
| 7279 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7280 | |
| 7281 | nla_put_failure: |
| 7282 | err = -ENOBUFS; |
| 7283 | free_msg: |
| 7284 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7285 | return err; |
| 7286 | } |
| 7287 | |
| 7288 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7289 | struct genl_info *info) |
| 7290 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7291 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7292 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7293 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7294 | |
| 7295 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7296 | return -EINVAL; |
| 7297 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7298 | if (!rdev->ops->cancel_remain_on_channel) |
| 7299 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7300 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7301 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7302 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7303 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7304 | } |
| 7305 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7306 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7307 | u8 *rates, u8 rates_len) |
| 7308 | { |
| 7309 | u8 i; |
| 7310 | u32 mask = 0; |
| 7311 | |
| 7312 | for (i = 0; i < rates_len; i++) { |
| 7313 | int rate = (rates[i] & 0x7f) * 5; |
| 7314 | int ridx; |
| 7315 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7316 | struct ieee80211_rate *srate = |
| 7317 | &sband->bitrates[ridx]; |
| 7318 | if (rate == srate->bitrate) { |
| 7319 | mask |= 1 << ridx; |
| 7320 | break; |
| 7321 | } |
| 7322 | } |
| 7323 | if (ridx == sband->n_bitrates) |
| 7324 | return 0; /* rate not found */ |
| 7325 | } |
| 7326 | |
| 7327 | return mask; |
| 7328 | } |
| 7329 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7330 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7331 | u8 *rates, u8 rates_len, |
| 7332 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7333 | { |
| 7334 | u8 i; |
| 7335 | |
| 7336 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7337 | |
| 7338 | for (i = 0; i < rates_len; i++) { |
| 7339 | int ridx, rbit; |
| 7340 | |
| 7341 | ridx = rates[i] / 8; |
| 7342 | rbit = BIT(rates[i] % 8); |
| 7343 | |
| 7344 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7345 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7346 | return false; |
| 7347 | |
| 7348 | /* check availability */ |
| 7349 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7350 | mcs[ridx] |= rbit; |
| 7351 | else |
| 7352 | return false; |
| 7353 | } |
| 7354 | |
| 7355 | return true; |
| 7356 | } |
| 7357 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7358 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 7359 | { |
| 7360 | u16 mcs_mask = 0; |
| 7361 | |
| 7362 | switch (vht_mcs_map) { |
| 7363 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 7364 | break; |
| 7365 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 7366 | mcs_mask = 0x00FF; |
| 7367 | break; |
| 7368 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 7369 | mcs_mask = 0x01FF; |
| 7370 | break; |
| 7371 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 7372 | mcs_mask = 0x03FF; |
| 7373 | break; |
| 7374 | default: |
| 7375 | break; |
| 7376 | } |
| 7377 | |
| 7378 | return mcs_mask; |
| 7379 | } |
| 7380 | |
| 7381 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 7382 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 7383 | { |
| 7384 | u8 nss; |
| 7385 | |
| 7386 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 7387 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 7388 | vht_mcs_map >>= 2; |
| 7389 | } |
| 7390 | } |
| 7391 | |
| 7392 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 7393 | struct nl80211_txrate_vht *txrate, |
| 7394 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 7395 | { |
| 7396 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7397 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 7398 | u8 i; |
| 7399 | |
| 7400 | if (!sband->vht_cap.vht_supported) |
| 7401 | return false; |
| 7402 | |
| 7403 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 7404 | |
| 7405 | /* Build vht_mcs_mask from VHT capabilities */ |
| 7406 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 7407 | |
| 7408 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 7409 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 7410 | mcs[i] = txrate->mcs[i]; |
| 7411 | else |
| 7412 | return false; |
| 7413 | } |
| 7414 | |
| 7415 | return true; |
| 7416 | } |
| 7417 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7418 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7419 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7420 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7421 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 7422 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7423 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7424 | }; |
| 7425 | |
| 7426 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7427 | struct genl_info *info) |
| 7428 | { |
| 7429 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7430 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7431 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7432 | int rem, i; |
| 7433 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7434 | struct nlattr *tx_rates; |
| 7435 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7436 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7437 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7438 | if (!rdev->ops->set_bitrate_mask) |
| 7439 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7440 | |
| 7441 | memset(&mask, 0, sizeof(mask)); |
| 7442 | /* Default to all rates enabled */ |
| 7443 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7444 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7445 | |
| 7446 | if (!sband) |
| 7447 | continue; |
| 7448 | |
| 7449 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7450 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7451 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7452 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7453 | |
| 7454 | if (!sband->vht_cap.vht_supported) |
| 7455 | continue; |
| 7456 | |
| 7457 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7458 | 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] | 7459 | } |
| 7460 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7461 | /* if no rates are given set it back to the defaults */ |
| 7462 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 7463 | goto out; |
| 7464 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7465 | /* |
| 7466 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7467 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7468 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7469 | 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] | 7470 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7471 | { |
| 7472 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7473 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7474 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7475 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7476 | if (sband == NULL) |
| 7477 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7478 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7479 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7480 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7481 | mask.control[band].legacy = rateset_to_mask( |
| 7482 | sband, |
| 7483 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7484 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7485 | if ((mask.control[band].legacy == 0) && |
| 7486 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7487 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7488 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7489 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7490 | if (!ht_rateset_to_mask( |
| 7491 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7492 | nla_data(tb[NL80211_TXRATE_HT]), |
| 7493 | nla_len(tb[NL80211_TXRATE_HT]), |
| 7494 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7495 | return -EINVAL; |
| 7496 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7497 | if (tb[NL80211_TXRATE_VHT]) { |
| 7498 | if (!vht_set_mcs_mask( |
| 7499 | sband, |
| 7500 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 7501 | mask.control[band].vht_mcs)) |
| 7502 | return -EINVAL; |
| 7503 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7504 | |
| 7505 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7506 | /* don't allow empty legacy rates if HT or VHT |
| 7507 | * are not even supported. |
| 7508 | */ |
| 7509 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 7510 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7511 | return -EINVAL; |
| 7512 | |
| 7513 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7514 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7515 | goto out; |
| 7516 | |
| 7517 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 7518 | if (mask.control[band].vht_mcs[i]) |
| 7519 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7520 | |
| 7521 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7522 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7523 | } |
| 7524 | } |
| 7525 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7526 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7527 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7528 | } |
| 7529 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7530 | 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] | 7531 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7532 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7533 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7534 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7535 | |
| 7536 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7537 | return -EINVAL; |
| 7538 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7539 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7540 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7541 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7542 | switch (wdev->iftype) { |
| 7543 | case NL80211_IFTYPE_STATION: |
| 7544 | case NL80211_IFTYPE_ADHOC: |
| 7545 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7546 | case NL80211_IFTYPE_AP: |
| 7547 | case NL80211_IFTYPE_AP_VLAN: |
| 7548 | case NL80211_IFTYPE_MESH_POINT: |
| 7549 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7550 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7551 | break; |
| 7552 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7553 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7554 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7555 | |
| 7556 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7557 | if (!rdev->ops->mgmt_tx) |
| 7558 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7559 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7560 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7561 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7562 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7563 | } |
| 7564 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7565 | 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] | 7566 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7567 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7568 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7569 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7570 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7571 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7572 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7573 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7574 | struct cfg80211_mgmt_tx_params params = { |
| 7575 | .dont_wait_for_ack = |
| 7576 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 7577 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7578 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7579 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7580 | return -EINVAL; |
| 7581 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7582 | if (!rdev->ops->mgmt_tx) |
| 7583 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7584 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7585 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7586 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7587 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7588 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7589 | case NL80211_IFTYPE_STATION: |
| 7590 | case NL80211_IFTYPE_ADHOC: |
| 7591 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7592 | case NL80211_IFTYPE_AP: |
| 7593 | case NL80211_IFTYPE_AP_VLAN: |
| 7594 | case NL80211_IFTYPE_MESH_POINT: |
| 7595 | case NL80211_IFTYPE_P2P_GO: |
| 7596 | break; |
| 7597 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7598 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7599 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7600 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7601 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7602 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7603 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7604 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7605 | |
| 7606 | /* |
| 7607 | * We should wait on the channel for at least a minimum amount |
| 7608 | * of time (10ms) but no longer than the driver supports. |
| 7609 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7610 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7611 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7612 | return -EINVAL; |
| 7613 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7614 | } |
| 7615 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7616 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7617 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7618 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7619 | return -EINVAL; |
| 7620 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7621 | 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] | 7622 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7623 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7624 | * the driver. The latter will use the current one |
| 7625 | */ |
| 7626 | chandef.chan = NULL; |
| 7627 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7628 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7629 | if (err) |
| 7630 | return err; |
| 7631 | } |
| 7632 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7633 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7634 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7635 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7636 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7637 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7638 | if (!msg) |
| 7639 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7640 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7641 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7642 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7643 | if (!hdr) { |
| 7644 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7645 | goto free_msg; |
| 7646 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7647 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7648 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7649 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 7650 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 7651 | params.chan = chandef.chan; |
| 7652 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7653 | if (err) |
| 7654 | goto free_msg; |
| 7655 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7656 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7657 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7658 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7659 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7660 | genlmsg_end(msg, hdr); |
| 7661 | return genlmsg_reply(msg, info); |
| 7662 | } |
| 7663 | |
| 7664 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7665 | |
| 7666 | nla_put_failure: |
| 7667 | err = -ENOBUFS; |
| 7668 | free_msg: |
| 7669 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7670 | return err; |
| 7671 | } |
| 7672 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7673 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7674 | { |
| 7675 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7676 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7677 | u64 cookie; |
| 7678 | |
| 7679 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7680 | return -EINVAL; |
| 7681 | |
| 7682 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7683 | return -EOPNOTSUPP; |
| 7684 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7685 | switch (wdev->iftype) { |
| 7686 | case NL80211_IFTYPE_STATION: |
| 7687 | case NL80211_IFTYPE_ADHOC: |
| 7688 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7689 | case NL80211_IFTYPE_AP: |
| 7690 | case NL80211_IFTYPE_AP_VLAN: |
| 7691 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7692 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7693 | break; |
| 7694 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7695 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7696 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7697 | |
| 7698 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7699 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7700 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7701 | } |
| 7702 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7703 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7704 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7705 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7706 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7707 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7708 | u8 ps_state; |
| 7709 | bool state; |
| 7710 | int err; |
| 7711 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7712 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7713 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7714 | |
| 7715 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7716 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7717 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7718 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7719 | |
| 7720 | wdev = dev->ieee80211_ptr; |
| 7721 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7722 | if (!rdev->ops->set_power_mgmt) |
| 7723 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7724 | |
| 7725 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7726 | |
| 7727 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7728 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7729 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7730 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7731 | if (!err) |
| 7732 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7733 | return err; |
| 7734 | } |
| 7735 | |
| 7736 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7737 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7738 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7739 | enum nl80211_ps_state ps_state; |
| 7740 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7741 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7742 | struct sk_buff *msg; |
| 7743 | void *hdr; |
| 7744 | int err; |
| 7745 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7746 | wdev = dev->ieee80211_ptr; |
| 7747 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7748 | if (!rdev->ops->set_power_mgmt) |
| 7749 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7750 | |
| 7751 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7752 | if (!msg) |
| 7753 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7754 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7755 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7756 | NL80211_CMD_GET_POWER_SAVE); |
| 7757 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7758 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7759 | goto free_msg; |
| 7760 | } |
| 7761 | |
| 7762 | if (wdev->ps) |
| 7763 | ps_state = NL80211_PS_ENABLED; |
| 7764 | else |
| 7765 | ps_state = NL80211_PS_DISABLED; |
| 7766 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7767 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7768 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7769 | |
| 7770 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7771 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7772 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7773 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7774 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7775 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7776 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7777 | return err; |
| 7778 | } |
| 7779 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7780 | static struct nla_policy |
| 7781 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7782 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7783 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7784 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7785 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7786 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7787 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7788 | }; |
| 7789 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7790 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7791 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7792 | { |
| 7793 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7794 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7795 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7796 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7797 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7798 | return -EINVAL; |
| 7799 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7800 | if (!rdev->ops->set_cqm_txe_config) |
| 7801 | return -EOPNOTSUPP; |
| 7802 | |
| 7803 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7804 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7805 | return -EOPNOTSUPP; |
| 7806 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7807 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7808 | } |
| 7809 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7810 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7811 | s32 threshold, u32 hysteresis) |
| 7812 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7813 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7814 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7815 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7816 | |
| 7817 | if (threshold > 0) |
| 7818 | return -EINVAL; |
| 7819 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7820 | /* disabling - hysteresis should also be zero then */ |
| 7821 | if (threshold == 0) |
| 7822 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7823 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7824 | if (!rdev->ops->set_cqm_rssi_config) |
| 7825 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7826 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7827 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7828 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7829 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7830 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7831 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7832 | } |
| 7833 | |
| 7834 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7835 | { |
| 7836 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7837 | struct nlattr *cqm; |
| 7838 | int err; |
| 7839 | |
| 7840 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7841 | if (!cqm) |
| 7842 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7843 | |
| 7844 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7845 | nl80211_attr_cqm_policy); |
| 7846 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7847 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7848 | |
| 7849 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7850 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7851 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7852 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7853 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7854 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 7855 | } |
| 7856 | |
| 7857 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7858 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7859 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7860 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7861 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7862 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7863 | |
| 7864 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 7865 | } |
| 7866 | |
| 7867 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7868 | } |
| 7869 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7870 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7871 | { |
| 7872 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7873 | struct net_device *dev = info->user_ptr[1]; |
| 7874 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7875 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7876 | int err; |
| 7877 | |
| 7878 | /* start with default */ |
| 7879 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7880 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7881 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7882 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7883 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7884 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7885 | if (err) |
| 7886 | return err; |
| 7887 | } |
| 7888 | |
| 7889 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7890 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7891 | return -EINVAL; |
| 7892 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7893 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7894 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7895 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7896 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7897 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7898 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7899 | return -EINVAL; |
| 7900 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7901 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7902 | setup.beacon_interval = |
| 7903 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7904 | if (setup.beacon_interval < 10 || |
| 7905 | setup.beacon_interval > 10000) |
| 7906 | return -EINVAL; |
| 7907 | } |
| 7908 | |
| 7909 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7910 | setup.dtim_period = |
| 7911 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7912 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7913 | return -EINVAL; |
| 7914 | } |
| 7915 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7916 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7917 | /* parse additional setup parameters if given */ |
| 7918 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7919 | if (err) |
| 7920 | return err; |
| 7921 | } |
| 7922 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7923 | if (setup.user_mpm) |
| 7924 | cfg.auto_open_plinks = false; |
| 7925 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7926 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7927 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7928 | if (err) |
| 7929 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7930 | } else { |
| 7931 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7932 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7933 | } |
| 7934 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 7935 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7936 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7937 | int n_rates = |
| 7938 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7939 | struct ieee80211_supported_band *sband; |
| 7940 | |
| 7941 | if (!setup.chandef.chan) |
| 7942 | return -EINVAL; |
| 7943 | |
| 7944 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 7945 | |
| 7946 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7947 | &setup.basic_rates); |
| 7948 | if (err) |
| 7949 | return err; |
| 7950 | } |
| 7951 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7952 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7953 | } |
| 7954 | |
| 7955 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7956 | { |
| 7957 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7958 | struct net_device *dev = info->user_ptr[1]; |
| 7959 | |
| 7960 | return cfg80211_leave_mesh(rdev, dev); |
| 7961 | } |
| 7962 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7963 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7964 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7965 | struct cfg80211_registered_device *rdev) |
| 7966 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7967 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7968 | struct nlattr *nl_pats, *nl_pat; |
| 7969 | int i, pat_len; |
| 7970 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7971 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7972 | return 0; |
| 7973 | |
| 7974 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7975 | if (!nl_pats) |
| 7976 | return -ENOBUFS; |
| 7977 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7978 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7979 | nl_pat = nla_nest_start(msg, i + 1); |
| 7980 | if (!nl_pat) |
| 7981 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7982 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7983 | 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] | 7984 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7985 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 7986 | wowlan->patterns[i].pattern) || |
| 7987 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7988 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7989 | return -ENOBUFS; |
| 7990 | nla_nest_end(msg, nl_pat); |
| 7991 | } |
| 7992 | nla_nest_end(msg, nl_pats); |
| 7993 | |
| 7994 | return 0; |
| 7995 | } |
| 7996 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7997 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7998 | struct cfg80211_wowlan_tcp *tcp) |
| 7999 | { |
| 8000 | struct nlattr *nl_tcp; |
| 8001 | |
| 8002 | if (!tcp) |
| 8003 | return 0; |
| 8004 | |
| 8005 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8006 | if (!nl_tcp) |
| 8007 | return -ENOBUFS; |
| 8008 | |
| 8009 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8010 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 8011 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8012 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8013 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8014 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8015 | tcp->payload_len, tcp->payload) || |
| 8016 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8017 | tcp->data_interval) || |
| 8018 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8019 | tcp->wake_len, tcp->wake_data) || |
| 8020 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8021 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8022 | return -ENOBUFS; |
| 8023 | |
| 8024 | if (tcp->payload_seq.len && |
| 8025 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8026 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8027 | return -ENOBUFS; |
| 8028 | |
| 8029 | if (tcp->payload_tok.len && |
| 8030 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8031 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8032 | &tcp->payload_tok)) |
| 8033 | return -ENOBUFS; |
| 8034 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8035 | nla_nest_end(msg, nl_tcp); |
| 8036 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8037 | return 0; |
| 8038 | } |
| 8039 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8040 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8041 | { |
| 8042 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8043 | struct sk_buff *msg; |
| 8044 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8045 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8046 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8047 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8048 | return -EOPNOTSUPP; |
| 8049 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8050 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8051 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8052 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8053 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8054 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8055 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8056 | } |
| 8057 | |
| 8058 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8059 | if (!msg) |
| 8060 | return -ENOMEM; |
| 8061 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8062 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8063 | NL80211_CMD_GET_WOWLAN); |
| 8064 | if (!hdr) |
| 8065 | goto nla_put_failure; |
| 8066 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8067 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8068 | struct nlattr *nl_wowlan; |
| 8069 | |
| 8070 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8071 | if (!nl_wowlan) |
| 8072 | goto nla_put_failure; |
| 8073 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8074 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8075 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8076 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8077 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8078 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8079 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8080 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8081 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8082 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8083 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8084 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8085 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8086 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8087 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8088 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8089 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8090 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8091 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8092 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8093 | if (nl80211_send_wowlan_tcp(msg, |
| 8094 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8095 | goto nla_put_failure; |
| 8096 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8097 | nla_nest_end(msg, nl_wowlan); |
| 8098 | } |
| 8099 | |
| 8100 | genlmsg_end(msg, hdr); |
| 8101 | return genlmsg_reply(msg, info); |
| 8102 | |
| 8103 | nla_put_failure: |
| 8104 | nlmsg_free(msg); |
| 8105 | return -ENOBUFS; |
| 8106 | } |
| 8107 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8108 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8109 | struct nlattr *attr, |
| 8110 | struct cfg80211_wowlan *trig) |
| 8111 | { |
| 8112 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8113 | struct cfg80211_wowlan_tcp *cfg; |
| 8114 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8115 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8116 | u32 size; |
| 8117 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8118 | int err, port; |
| 8119 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8120 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8121 | return -EINVAL; |
| 8122 | |
| 8123 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8124 | nla_data(attr), nla_len(attr), |
| 8125 | nl80211_wowlan_tcp_policy); |
| 8126 | if (err) |
| 8127 | return err; |
| 8128 | |
| 8129 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8130 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8131 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8132 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8133 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8134 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8135 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8136 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8137 | return -EINVAL; |
| 8138 | |
| 8139 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8140 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8141 | return -EINVAL; |
| 8142 | |
| 8143 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8144 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8145 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8146 | return -EINVAL; |
| 8147 | |
| 8148 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8149 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8150 | return -EINVAL; |
| 8151 | |
| 8152 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8153 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8154 | return -EINVAL; |
| 8155 | |
| 8156 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8157 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8158 | |
| 8159 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8160 | tokens_size = tokln - sizeof(*tok); |
| 8161 | |
| 8162 | if (!tok->len || tokens_size % tok->len) |
| 8163 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8164 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8165 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8166 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8167 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8168 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8169 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8170 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8171 | return -EINVAL; |
| 8172 | if (tok->offset + tok->len > data_size) |
| 8173 | return -EINVAL; |
| 8174 | } |
| 8175 | |
| 8176 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8177 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8178 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8179 | return -EINVAL; |
| 8180 | if (seq->len == 0 || seq->len > 4) |
| 8181 | return -EINVAL; |
| 8182 | if (seq->len + seq->offset > data_size) |
| 8183 | return -EINVAL; |
| 8184 | } |
| 8185 | |
| 8186 | size = sizeof(*cfg); |
| 8187 | size += data_size; |
| 8188 | size += wake_size + wake_mask_size; |
| 8189 | size += tokens_size; |
| 8190 | |
| 8191 | cfg = kzalloc(size, GFP_KERNEL); |
| 8192 | if (!cfg) |
| 8193 | return -ENOMEM; |
| 8194 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8195 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8196 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8197 | ETH_ALEN); |
| 8198 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8199 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8200 | else |
| 8201 | port = 0; |
| 8202 | #ifdef CONFIG_INET |
| 8203 | /* allocate a socket and port for it and use it */ |
| 8204 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8205 | IPPROTO_TCP, &cfg->sock, 1); |
| 8206 | if (err) { |
| 8207 | kfree(cfg); |
| 8208 | return err; |
| 8209 | } |
| 8210 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8211 | sock_release(cfg->sock); |
| 8212 | kfree(cfg); |
| 8213 | return -EADDRINUSE; |
| 8214 | } |
| 8215 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8216 | #else |
| 8217 | if (!port) { |
| 8218 | kfree(cfg); |
| 8219 | return -EINVAL; |
| 8220 | } |
| 8221 | cfg->src_port = port; |
| 8222 | #endif |
| 8223 | |
| 8224 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8225 | cfg->payload_len = data_size; |
| 8226 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8227 | memcpy((void *)cfg->payload, |
| 8228 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8229 | data_size); |
| 8230 | if (seq) |
| 8231 | cfg->payload_seq = *seq; |
| 8232 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8233 | cfg->wake_len = wake_size; |
| 8234 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8235 | memcpy((void *)cfg->wake_data, |
| 8236 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8237 | wake_size); |
| 8238 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8239 | data_size + wake_size; |
| 8240 | memcpy((void *)cfg->wake_mask, |
| 8241 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8242 | wake_mask_size); |
| 8243 | if (tok) { |
| 8244 | cfg->tokens_size = tokens_size; |
| 8245 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8246 | } |
| 8247 | |
| 8248 | trig->tcp = cfg; |
| 8249 | |
| 8250 | return 0; |
| 8251 | } |
| 8252 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8253 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8254 | { |
| 8255 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8256 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8257 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8258 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8259 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8260 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8261 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8262 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8263 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8264 | return -EOPNOTSUPP; |
| 8265 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8266 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8267 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8268 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8269 | goto set_wakeup; |
| 8270 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8271 | |
| 8272 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8273 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8274 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8275 | nl80211_wowlan_policy); |
| 8276 | if (err) |
| 8277 | return err; |
| 8278 | |
| 8279 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8280 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8281 | return -EINVAL; |
| 8282 | new_triggers.any = true; |
| 8283 | } |
| 8284 | |
| 8285 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8286 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8287 | return -EINVAL; |
| 8288 | new_triggers.disconnect = true; |
| 8289 | } |
| 8290 | |
| 8291 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8292 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8293 | return -EINVAL; |
| 8294 | new_triggers.magic_pkt = true; |
| 8295 | } |
| 8296 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8297 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8298 | return -EINVAL; |
| 8299 | |
| 8300 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8301 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8302 | return -EINVAL; |
| 8303 | new_triggers.gtk_rekey_failure = true; |
| 8304 | } |
| 8305 | |
| 8306 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8307 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8308 | return -EINVAL; |
| 8309 | new_triggers.eap_identity_req = true; |
| 8310 | } |
| 8311 | |
| 8312 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8313 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8314 | return -EINVAL; |
| 8315 | new_triggers.four_way_handshake = true; |
| 8316 | } |
| 8317 | |
| 8318 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8319 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8320 | return -EINVAL; |
| 8321 | new_triggers.rfkill_release = true; |
| 8322 | } |
| 8323 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8324 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8325 | struct nlattr *pat; |
| 8326 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8327 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8328 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8329 | |
| 8330 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8331 | rem) |
| 8332 | n_patterns++; |
| 8333 | if (n_patterns > wowlan->n_patterns) |
| 8334 | return -EINVAL; |
| 8335 | |
| 8336 | new_triggers.patterns = kcalloc(n_patterns, |
| 8337 | sizeof(new_triggers.patterns[0]), |
| 8338 | GFP_KERNEL); |
| 8339 | if (!new_triggers.patterns) |
| 8340 | return -ENOMEM; |
| 8341 | |
| 8342 | new_triggers.n_patterns = n_patterns; |
| 8343 | i = 0; |
| 8344 | |
| 8345 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8346 | rem) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8347 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8348 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8349 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8350 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8351 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8352 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8353 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8354 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8355 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8356 | goto error; |
| 8357 | if (pat_len > wowlan->pattern_max_len || |
| 8358 | pat_len < wowlan->pattern_min_len) |
| 8359 | goto error; |
| 8360 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8361 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8362 | pkt_offset = 0; |
| 8363 | else |
| 8364 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8365 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8366 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8367 | goto error; |
| 8368 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8369 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8370 | new_triggers.patterns[i].mask = |
| 8371 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8372 | if (!new_triggers.patterns[i].mask) { |
| 8373 | err = -ENOMEM; |
| 8374 | goto error; |
| 8375 | } |
| 8376 | new_triggers.patterns[i].pattern = |
| 8377 | new_triggers.patterns[i].mask + mask_len; |
| 8378 | memcpy(new_triggers.patterns[i].mask, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8379 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8380 | mask_len); |
| 8381 | new_triggers.patterns[i].pattern_len = pat_len; |
| 8382 | memcpy(new_triggers.patterns[i].pattern, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8383 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8384 | pat_len); |
| 8385 | i++; |
| 8386 | } |
| 8387 | } |
| 8388 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8389 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8390 | err = nl80211_parse_wowlan_tcp( |
| 8391 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8392 | &new_triggers); |
| 8393 | if (err) |
| 8394 | goto error; |
| 8395 | } |
| 8396 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8397 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8398 | if (!ntrig) { |
| 8399 | err = -ENOMEM; |
| 8400 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8401 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8402 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8403 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8404 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8405 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8406 | if (rdev->ops->set_wakeup && |
| 8407 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8408 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8409 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8410 | return 0; |
| 8411 | error: |
| 8412 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8413 | kfree(new_triggers.patterns[i].mask); |
| 8414 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8415 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8416 | sock_release(new_triggers.tcp->sock); |
| 8417 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8418 | return err; |
| 8419 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8420 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8421 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8422 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8423 | struct cfg80211_registered_device *rdev) |
| 8424 | { |
| 8425 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8426 | int i, j, pat_len; |
| 8427 | struct cfg80211_coalesce_rules *rule; |
| 8428 | |
| 8429 | if (!rdev->coalesce->n_rules) |
| 8430 | return 0; |
| 8431 | |
| 8432 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8433 | if (!nl_rules) |
| 8434 | return -ENOBUFS; |
| 8435 | |
| 8436 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8437 | nl_rule = nla_nest_start(msg, i + 1); |
| 8438 | if (!nl_rule) |
| 8439 | return -ENOBUFS; |
| 8440 | |
| 8441 | rule = &rdev->coalesce->rules[i]; |
| 8442 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8443 | rule->delay)) |
| 8444 | return -ENOBUFS; |
| 8445 | |
| 8446 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8447 | rule->condition)) |
| 8448 | return -ENOBUFS; |
| 8449 | |
| 8450 | nl_pats = nla_nest_start(msg, |
| 8451 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8452 | if (!nl_pats) |
| 8453 | return -ENOBUFS; |
| 8454 | |
| 8455 | for (j = 0; j < rule->n_patterns; j++) { |
| 8456 | nl_pat = nla_nest_start(msg, j + 1); |
| 8457 | if (!nl_pat) |
| 8458 | return -ENOBUFS; |
| 8459 | pat_len = rule->patterns[j].pattern_len; |
| 8460 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8461 | DIV_ROUND_UP(pat_len, 8), |
| 8462 | rule->patterns[j].mask) || |
| 8463 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8464 | rule->patterns[j].pattern) || |
| 8465 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8466 | rule->patterns[j].pkt_offset)) |
| 8467 | return -ENOBUFS; |
| 8468 | nla_nest_end(msg, nl_pat); |
| 8469 | } |
| 8470 | nla_nest_end(msg, nl_pats); |
| 8471 | nla_nest_end(msg, nl_rule); |
| 8472 | } |
| 8473 | nla_nest_end(msg, nl_rules); |
| 8474 | |
| 8475 | return 0; |
| 8476 | } |
| 8477 | |
| 8478 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8479 | { |
| 8480 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8481 | struct sk_buff *msg; |
| 8482 | void *hdr; |
| 8483 | |
| 8484 | if (!rdev->wiphy.coalesce) |
| 8485 | return -EOPNOTSUPP; |
| 8486 | |
| 8487 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8488 | if (!msg) |
| 8489 | return -ENOMEM; |
| 8490 | |
| 8491 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8492 | NL80211_CMD_GET_COALESCE); |
| 8493 | if (!hdr) |
| 8494 | goto nla_put_failure; |
| 8495 | |
| 8496 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8497 | goto nla_put_failure; |
| 8498 | |
| 8499 | genlmsg_end(msg, hdr); |
| 8500 | return genlmsg_reply(msg, info); |
| 8501 | |
| 8502 | nla_put_failure: |
| 8503 | nlmsg_free(msg); |
| 8504 | return -ENOBUFS; |
| 8505 | } |
| 8506 | |
| 8507 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8508 | { |
| 8509 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8510 | int i, j; |
| 8511 | struct cfg80211_coalesce_rules *rule; |
| 8512 | |
| 8513 | if (!coalesce) |
| 8514 | return; |
| 8515 | |
| 8516 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8517 | rule = &coalesce->rules[i]; |
| 8518 | for (j = 0; j < rule->n_patterns; j++) |
| 8519 | kfree(rule->patterns[j].mask); |
| 8520 | kfree(rule->patterns); |
| 8521 | } |
| 8522 | kfree(coalesce->rules); |
| 8523 | kfree(coalesce); |
| 8524 | rdev->coalesce = NULL; |
| 8525 | } |
| 8526 | |
| 8527 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8528 | struct nlattr *rule, |
| 8529 | struct cfg80211_coalesce_rules *new_rule) |
| 8530 | { |
| 8531 | int err, i; |
| 8532 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8533 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8534 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8535 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8536 | |
| 8537 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8538 | nla_len(rule), nl80211_coalesce_policy); |
| 8539 | if (err) |
| 8540 | return err; |
| 8541 | |
| 8542 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8543 | new_rule->delay = |
| 8544 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8545 | if (new_rule->delay > coalesce->max_delay) |
| 8546 | return -EINVAL; |
| 8547 | |
| 8548 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8549 | new_rule->condition = |
| 8550 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8551 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8552 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8553 | return -EINVAL; |
| 8554 | |
| 8555 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8556 | return -EINVAL; |
| 8557 | |
| 8558 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8559 | rem) |
| 8560 | n_patterns++; |
| 8561 | if (n_patterns > coalesce->n_patterns) |
| 8562 | return -EINVAL; |
| 8563 | |
| 8564 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8565 | GFP_KERNEL); |
| 8566 | if (!new_rule->patterns) |
| 8567 | return -ENOMEM; |
| 8568 | |
| 8569 | new_rule->n_patterns = n_patterns; |
| 8570 | i = 0; |
| 8571 | |
| 8572 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8573 | rem) { |
| 8574 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8575 | nla_len(pat), NULL); |
| 8576 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8577 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8578 | return -EINVAL; |
| 8579 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8580 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8581 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8582 | return -EINVAL; |
| 8583 | if (pat_len > coalesce->pattern_max_len || |
| 8584 | pat_len < coalesce->pattern_min_len) |
| 8585 | return -EINVAL; |
| 8586 | |
| 8587 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8588 | pkt_offset = 0; |
| 8589 | else |
| 8590 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8591 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8592 | return -EINVAL; |
| 8593 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8594 | |
| 8595 | new_rule->patterns[i].mask = |
| 8596 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8597 | if (!new_rule->patterns[i].mask) |
| 8598 | return -ENOMEM; |
| 8599 | new_rule->patterns[i].pattern = |
| 8600 | new_rule->patterns[i].mask + mask_len; |
| 8601 | memcpy(new_rule->patterns[i].mask, |
| 8602 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); |
| 8603 | new_rule->patterns[i].pattern_len = pat_len; |
| 8604 | memcpy(new_rule->patterns[i].pattern, |
| 8605 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); |
| 8606 | i++; |
| 8607 | } |
| 8608 | |
| 8609 | return 0; |
| 8610 | } |
| 8611 | |
| 8612 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8613 | { |
| 8614 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8615 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8616 | struct cfg80211_coalesce new_coalesce = {}; |
| 8617 | struct cfg80211_coalesce *n_coalesce; |
| 8618 | int err, rem_rule, n_rules = 0, i, j; |
| 8619 | struct nlattr *rule; |
| 8620 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8621 | |
| 8622 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8623 | return -EOPNOTSUPP; |
| 8624 | |
| 8625 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8626 | cfg80211_rdev_free_coalesce(rdev); |
| 8627 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8628 | return 0; |
| 8629 | } |
| 8630 | |
| 8631 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8632 | rem_rule) |
| 8633 | n_rules++; |
| 8634 | if (n_rules > coalesce->n_rules) |
| 8635 | return -EINVAL; |
| 8636 | |
| 8637 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8638 | GFP_KERNEL); |
| 8639 | if (!new_coalesce.rules) |
| 8640 | return -ENOMEM; |
| 8641 | |
| 8642 | new_coalesce.n_rules = n_rules; |
| 8643 | i = 0; |
| 8644 | |
| 8645 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8646 | rem_rule) { |
| 8647 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8648 | &new_coalesce.rules[i]); |
| 8649 | if (err) |
| 8650 | goto error; |
| 8651 | |
| 8652 | i++; |
| 8653 | } |
| 8654 | |
| 8655 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8656 | if (err) |
| 8657 | goto error; |
| 8658 | |
| 8659 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8660 | if (!n_coalesce) { |
| 8661 | err = -ENOMEM; |
| 8662 | goto error; |
| 8663 | } |
| 8664 | cfg80211_rdev_free_coalesce(rdev); |
| 8665 | rdev->coalesce = n_coalesce; |
| 8666 | |
| 8667 | return 0; |
| 8668 | error: |
| 8669 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8670 | tmp_rule = &new_coalesce.rules[i]; |
| 8671 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8672 | kfree(tmp_rule->patterns[j].mask); |
| 8673 | kfree(tmp_rule->patterns); |
| 8674 | } |
| 8675 | kfree(new_coalesce.rules); |
| 8676 | |
| 8677 | return err; |
| 8678 | } |
| 8679 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8680 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8681 | { |
| 8682 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8683 | struct net_device *dev = info->user_ptr[1]; |
| 8684 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8685 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8686 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8687 | int err; |
| 8688 | |
| 8689 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8690 | return -EINVAL; |
| 8691 | |
| 8692 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8693 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8694 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8695 | nl80211_rekey_policy); |
| 8696 | if (err) |
| 8697 | return err; |
| 8698 | |
| 8699 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8700 | return -ERANGE; |
| 8701 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8702 | return -ERANGE; |
| 8703 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8704 | return -ERANGE; |
| 8705 | |
| 8706 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8707 | NL80211_KEK_LEN); |
| 8708 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8709 | NL80211_KCK_LEN); |
| 8710 | memcpy(rekey_data.replay_ctr, |
| 8711 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8712 | NL80211_REPLAY_CTR_LEN); |
| 8713 | |
| 8714 | wdev_lock(wdev); |
| 8715 | if (!wdev->current_bss) { |
| 8716 | err = -ENOTCONN; |
| 8717 | goto out; |
| 8718 | } |
| 8719 | |
| 8720 | if (!rdev->ops->set_rekey_data) { |
| 8721 | err = -EOPNOTSUPP; |
| 8722 | goto out; |
| 8723 | } |
| 8724 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8725 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8726 | out: |
| 8727 | wdev_unlock(wdev); |
| 8728 | return err; |
| 8729 | } |
| 8730 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8731 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8732 | struct genl_info *info) |
| 8733 | { |
| 8734 | struct net_device *dev = info->user_ptr[1]; |
| 8735 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8736 | |
| 8737 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8738 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8739 | return -EINVAL; |
| 8740 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8741 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8742 | return -EBUSY; |
| 8743 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8744 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8745 | return 0; |
| 8746 | } |
| 8747 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8748 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8749 | struct genl_info *info) |
| 8750 | { |
| 8751 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8752 | struct net_device *dev = info->user_ptr[1]; |
| 8753 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8754 | struct sk_buff *msg; |
| 8755 | void *hdr; |
| 8756 | const u8 *addr; |
| 8757 | u64 cookie; |
| 8758 | int err; |
| 8759 | |
| 8760 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8761 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8762 | return -EOPNOTSUPP; |
| 8763 | |
| 8764 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8765 | return -EINVAL; |
| 8766 | |
| 8767 | if (!rdev->ops->probe_client) |
| 8768 | return -EOPNOTSUPP; |
| 8769 | |
| 8770 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8771 | if (!msg) |
| 8772 | return -ENOMEM; |
| 8773 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8774 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8775 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8776 | if (!hdr) { |
| 8777 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8778 | goto free_msg; |
| 8779 | } |
| 8780 | |
| 8781 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8782 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8783 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8784 | if (err) |
| 8785 | goto free_msg; |
| 8786 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8787 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8788 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8789 | |
| 8790 | genlmsg_end(msg, hdr); |
| 8791 | |
| 8792 | return genlmsg_reply(msg, info); |
| 8793 | |
| 8794 | nla_put_failure: |
| 8795 | err = -ENOBUFS; |
| 8796 | free_msg: |
| 8797 | nlmsg_free(msg); |
| 8798 | return err; |
| 8799 | } |
| 8800 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8801 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8802 | { |
| 8803 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8804 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8805 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8806 | |
| 8807 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8808 | return -EOPNOTSUPP; |
| 8809 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8810 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8811 | if (!nreg) |
| 8812 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8813 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8814 | /* First, check if already registered. */ |
| 8815 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8816 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8817 | if (reg->nlportid == info->snd_portid) { |
| 8818 | rv = -EALREADY; |
| 8819 | goto out_err; |
| 8820 | } |
| 8821 | } |
| 8822 | /* Add it to the list */ |
| 8823 | nreg->nlportid = info->snd_portid; |
| 8824 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8825 | |
| 8826 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8827 | |
| 8828 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8829 | out_err: |
| 8830 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8831 | kfree(nreg); |
| 8832 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8833 | } |
| 8834 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8835 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8836 | { |
| 8837 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8838 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8839 | int err; |
| 8840 | |
| 8841 | if (!rdev->ops->start_p2p_device) |
| 8842 | return -EOPNOTSUPP; |
| 8843 | |
| 8844 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8845 | return -EOPNOTSUPP; |
| 8846 | |
| 8847 | if (wdev->p2p_started) |
| 8848 | return 0; |
| 8849 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8850 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8851 | if (err) |
| 8852 | return err; |
| 8853 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8854 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8855 | if (err) |
| 8856 | return err; |
| 8857 | |
| 8858 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8859 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8860 | |
| 8861 | return 0; |
| 8862 | } |
| 8863 | |
| 8864 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8865 | { |
| 8866 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8867 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8868 | |
| 8869 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8870 | return -EOPNOTSUPP; |
| 8871 | |
| 8872 | if (!rdev->ops->stop_p2p_device) |
| 8873 | return -EOPNOTSUPP; |
| 8874 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8875 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8876 | |
| 8877 | return 0; |
| 8878 | } |
| 8879 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8880 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8881 | struct genl_info *info) |
| 8882 | { |
| 8883 | void *hdr; |
| 8884 | struct sk_buff *msg; |
| 8885 | |
| 8886 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8887 | if (!msg) |
| 8888 | return -ENOMEM; |
| 8889 | |
| 8890 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8891 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8892 | if (!hdr) |
| 8893 | goto nla_put_failure; |
| 8894 | |
| 8895 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8896 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8897 | goto nla_put_failure; |
| 8898 | |
| 8899 | genlmsg_end(msg, hdr); |
| 8900 | return genlmsg_reply(msg, info); |
| 8901 | |
| 8902 | nla_put_failure: |
| 8903 | kfree_skb(msg); |
| 8904 | return -ENOBUFS; |
| 8905 | } |
| 8906 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8907 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8908 | { |
| 8909 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8910 | struct cfg80211_update_ft_ies_params ft_params; |
| 8911 | struct net_device *dev = info->user_ptr[1]; |
| 8912 | |
| 8913 | if (!rdev->ops->update_ft_ies) |
| 8914 | return -EOPNOTSUPP; |
| 8915 | |
| 8916 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8917 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8918 | return -EINVAL; |
| 8919 | |
| 8920 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8921 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8922 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8923 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8924 | |
| 8925 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8926 | } |
| 8927 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8928 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8929 | struct genl_info *info) |
| 8930 | { |
| 8931 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8932 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8933 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8934 | u16 duration; |
| 8935 | int ret; |
| 8936 | |
| 8937 | if (!rdev->ops->crit_proto_start) |
| 8938 | return -EOPNOTSUPP; |
| 8939 | |
| 8940 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8941 | return -EINVAL; |
| 8942 | |
| 8943 | if (rdev->crit_proto_nlportid) |
| 8944 | return -EBUSY; |
| 8945 | |
| 8946 | /* determine protocol if provided */ |
| 8947 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8948 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8949 | |
| 8950 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8951 | return -EINVAL; |
| 8952 | |
| 8953 | /* timeout must be provided */ |
| 8954 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8955 | return -EINVAL; |
| 8956 | |
| 8957 | duration = |
| 8958 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8959 | |
| 8960 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8961 | return -ERANGE; |
| 8962 | |
| 8963 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 8964 | if (!ret) |
| 8965 | rdev->crit_proto_nlportid = info->snd_portid; |
| 8966 | |
| 8967 | return ret; |
| 8968 | } |
| 8969 | |
| 8970 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 8971 | struct genl_info *info) |
| 8972 | { |
| 8973 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8974 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8975 | |
| 8976 | if (!rdev->ops->crit_proto_stop) |
| 8977 | return -EOPNOTSUPP; |
| 8978 | |
| 8979 | if (rdev->crit_proto_nlportid) { |
| 8980 | rdev->crit_proto_nlportid = 0; |
| 8981 | rdev_crit_proto_stop(rdev, wdev); |
| 8982 | } |
| 8983 | return 0; |
| 8984 | } |
| 8985 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8986 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 8987 | { |
| 8988 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8989 | struct wireless_dev *wdev = |
| 8990 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 8991 | int i, err; |
| 8992 | u32 vid, subcmd; |
| 8993 | |
| 8994 | if (!rdev->wiphy.vendor_commands) |
| 8995 | return -EOPNOTSUPP; |
| 8996 | |
| 8997 | if (IS_ERR(wdev)) { |
| 8998 | err = PTR_ERR(wdev); |
| 8999 | if (err != -EINVAL) |
| 9000 | return err; |
| 9001 | wdev = NULL; |
| 9002 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9003 | return -EINVAL; |
| 9004 | } |
| 9005 | |
| 9006 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 9007 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 9008 | return -EINVAL; |
| 9009 | |
| 9010 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 9011 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 9012 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 9013 | const struct wiphy_vendor_command *vcmd; |
| 9014 | void *data = NULL; |
| 9015 | int len = 0; |
| 9016 | |
| 9017 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 9018 | |
| 9019 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 9020 | continue; |
| 9021 | |
| 9022 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 9023 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 9024 | if (!wdev) |
| 9025 | return -EINVAL; |
| 9026 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9027 | !wdev->netdev) |
| 9028 | return -EINVAL; |
| 9029 | |
| 9030 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9031 | if (wdev->netdev && |
| 9032 | !netif_running(wdev->netdev)) |
| 9033 | return -ENETDOWN; |
| 9034 | if (!wdev->netdev && !wdev->p2p_started) |
| 9035 | return -ENETDOWN; |
| 9036 | } |
| 9037 | } else { |
| 9038 | wdev = NULL; |
| 9039 | } |
| 9040 | |
| 9041 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9042 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9043 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9044 | } |
| 9045 | |
| 9046 | rdev->cur_cmd_info = info; |
| 9047 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9048 | data, len); |
| 9049 | rdev->cur_cmd_info = NULL; |
| 9050 | return err; |
| 9051 | } |
| 9052 | |
| 9053 | return -EOPNOTSUPP; |
| 9054 | } |
| 9055 | |
| 9056 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9057 | enum nl80211_commands cmd, |
| 9058 | enum nl80211_attrs attr, |
| 9059 | int approxlen) |
| 9060 | { |
| 9061 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9062 | |
| 9063 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9064 | return NULL; |
| 9065 | |
| 9066 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, |
| 9067 | rdev->cur_cmd_info->snd_portid, |
| 9068 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9069 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9070 | } |
| 9071 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9072 | |
| 9073 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9074 | { |
| 9075 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9076 | void *hdr = ((void **)skb->cb)[1]; |
| 9077 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9078 | |
| 9079 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9080 | kfree_skb(skb); |
| 9081 | return -EINVAL; |
| 9082 | } |
| 9083 | |
| 9084 | nla_nest_end(skb, data); |
| 9085 | genlmsg_end(skb, hdr); |
| 9086 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9087 | } |
| 9088 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9089 | |
| 9090 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9091 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 9092 | struct genl_info *info) |
| 9093 | { |
| 9094 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9095 | struct cfg80211_qos_map *qos_map = NULL; |
| 9096 | struct net_device *dev = info->user_ptr[1]; |
| 9097 | u8 *pos, len, num_des, des_len, des; |
| 9098 | int ret; |
| 9099 | |
| 9100 | if (!rdev->ops->set_qos_map) |
| 9101 | return -EOPNOTSUPP; |
| 9102 | |
| 9103 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 9104 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9105 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9106 | |
| 9107 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 9108 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 9109 | return -EINVAL; |
| 9110 | |
| 9111 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 9112 | if (!qos_map) |
| 9113 | return -ENOMEM; |
| 9114 | |
| 9115 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 9116 | if (num_des) { |
| 9117 | des_len = num_des * |
| 9118 | sizeof(struct cfg80211_dscp_exception); |
| 9119 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 9120 | qos_map->num_des = num_des; |
| 9121 | for (des = 0; des < num_des; des++) { |
| 9122 | if (qos_map->dscp_exception[des].up > 7) { |
| 9123 | kfree(qos_map); |
| 9124 | return -EINVAL; |
| 9125 | } |
| 9126 | } |
| 9127 | pos += des_len; |
| 9128 | } |
| 9129 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 9130 | } |
| 9131 | |
| 9132 | wdev_lock(dev->ieee80211_ptr); |
| 9133 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 9134 | if (!ret) |
| 9135 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 9136 | wdev_unlock(dev->ieee80211_ptr); |
| 9137 | |
| 9138 | kfree(qos_map); |
| 9139 | return ret; |
| 9140 | } |
| 9141 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9142 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 9143 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 9144 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9145 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 9146 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 9147 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9148 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9149 | /* 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] | 9150 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 9151 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9152 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9153 | 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] | 9154 | struct genl_info *info) |
| 9155 | { |
| 9156 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9157 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9158 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9159 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 9160 | |
| 9161 | if (rtnl) |
| 9162 | rtnl_lock(); |
| 9163 | |
| 9164 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 9165 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9166 | if (IS_ERR(rdev)) { |
| 9167 | if (rtnl) |
| 9168 | rtnl_unlock(); |
| 9169 | return PTR_ERR(rdev); |
| 9170 | } |
| 9171 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9172 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 9173 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9174 | ASSERT_RTNL(); |
| 9175 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9176 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 9177 | info->attrs); |
| 9178 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9179 | if (rtnl) |
| 9180 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9181 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9182 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9183 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9184 | dev = wdev->netdev; |
| 9185 | rdev = wiphy_to_dev(wdev->wiphy); |
| 9186 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9187 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 9188 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9189 | if (rtnl) |
| 9190 | rtnl_unlock(); |
| 9191 | return -EINVAL; |
| 9192 | } |
| 9193 | |
| 9194 | info->user_ptr[1] = dev; |
| 9195 | } else { |
| 9196 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9197 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9198 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9199 | if (dev) { |
| 9200 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 9201 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9202 | if (rtnl) |
| 9203 | rtnl_unlock(); |
| 9204 | return -ENETDOWN; |
| 9205 | } |
| 9206 | |
| 9207 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9208 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 9209 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9210 | if (rtnl) |
| 9211 | rtnl_unlock(); |
| 9212 | return -ENETDOWN; |
| 9213 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9214 | } |
| 9215 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9216 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9217 | } |
| 9218 | |
| 9219 | return 0; |
| 9220 | } |
| 9221 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9222 | 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] | 9223 | struct genl_info *info) |
| 9224 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9225 | if (info->user_ptr[1]) { |
| 9226 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 9227 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9228 | |
| 9229 | if (wdev->netdev) |
| 9230 | dev_put(wdev->netdev); |
| 9231 | } else { |
| 9232 | dev_put(info->user_ptr[1]); |
| 9233 | } |
| 9234 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9235 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 9236 | rtnl_unlock(); |
| 9237 | } |
| 9238 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 9239 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9240 | { |
| 9241 | .cmd = NL80211_CMD_GET_WIPHY, |
| 9242 | .doit = nl80211_get_wiphy, |
| 9243 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9244 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9245 | .policy = nl80211_policy, |
| 9246 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9247 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9248 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9249 | }, |
| 9250 | { |
| 9251 | .cmd = NL80211_CMD_SET_WIPHY, |
| 9252 | .doit = nl80211_set_wiphy, |
| 9253 | .policy = nl80211_policy, |
| 9254 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9255 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9256 | }, |
| 9257 | { |
| 9258 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 9259 | .doit = nl80211_get_interface, |
| 9260 | .dumpit = nl80211_dump_interface, |
| 9261 | .policy = nl80211_policy, |
| 9262 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9263 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9264 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9265 | }, |
| 9266 | { |
| 9267 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 9268 | .doit = nl80211_set_interface, |
| 9269 | .policy = nl80211_policy, |
| 9270 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9271 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9272 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9273 | }, |
| 9274 | { |
| 9275 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 9276 | .doit = nl80211_new_interface, |
| 9277 | .policy = nl80211_policy, |
| 9278 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9279 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9280 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9281 | }, |
| 9282 | { |
| 9283 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 9284 | .doit = nl80211_del_interface, |
| 9285 | .policy = nl80211_policy, |
| 9286 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 9287 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9288 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9289 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9290 | { |
| 9291 | .cmd = NL80211_CMD_GET_KEY, |
| 9292 | .doit = nl80211_get_key, |
| 9293 | .policy = nl80211_policy, |
| 9294 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9295 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9296 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9297 | }, |
| 9298 | { |
| 9299 | .cmd = NL80211_CMD_SET_KEY, |
| 9300 | .doit = nl80211_set_key, |
| 9301 | .policy = nl80211_policy, |
| 9302 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9303 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9304 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9305 | }, |
| 9306 | { |
| 9307 | .cmd = NL80211_CMD_NEW_KEY, |
| 9308 | .doit = nl80211_new_key, |
| 9309 | .policy = nl80211_policy, |
| 9310 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9311 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9312 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9313 | }, |
| 9314 | { |
| 9315 | .cmd = NL80211_CMD_DEL_KEY, |
| 9316 | .doit = nl80211_del_key, |
| 9317 | .policy = nl80211_policy, |
| 9318 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9319 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9320 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9321 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9322 | { |
| 9323 | .cmd = NL80211_CMD_SET_BEACON, |
| 9324 | .policy = nl80211_policy, |
| 9325 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9326 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9327 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9328 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9329 | }, |
| 9330 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9331 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9332 | .policy = nl80211_policy, |
| 9333 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9334 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9335 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9336 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9337 | }, |
| 9338 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9339 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9340 | .policy = nl80211_policy, |
| 9341 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9342 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9343 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9344 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9345 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9346 | { |
| 9347 | .cmd = NL80211_CMD_GET_STATION, |
| 9348 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9349 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9350 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9351 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9352 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9353 | }, |
| 9354 | { |
| 9355 | .cmd = NL80211_CMD_SET_STATION, |
| 9356 | .doit = nl80211_set_station, |
| 9357 | .policy = nl80211_policy, |
| 9358 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9359 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9360 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9361 | }, |
| 9362 | { |
| 9363 | .cmd = NL80211_CMD_NEW_STATION, |
| 9364 | .doit = nl80211_new_station, |
| 9365 | .policy = nl80211_policy, |
| 9366 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9367 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9368 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9369 | }, |
| 9370 | { |
| 9371 | .cmd = NL80211_CMD_DEL_STATION, |
| 9372 | .doit = nl80211_del_station, |
| 9373 | .policy = nl80211_policy, |
| 9374 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9375 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9376 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9377 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9378 | { |
| 9379 | .cmd = NL80211_CMD_GET_MPATH, |
| 9380 | .doit = nl80211_get_mpath, |
| 9381 | .dumpit = nl80211_dump_mpath, |
| 9382 | .policy = nl80211_policy, |
| 9383 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9384 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9385 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9386 | }, |
| 9387 | { |
| 9388 | .cmd = NL80211_CMD_SET_MPATH, |
| 9389 | .doit = nl80211_set_mpath, |
| 9390 | .policy = nl80211_policy, |
| 9391 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9392 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9393 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9394 | }, |
| 9395 | { |
| 9396 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9397 | .doit = nl80211_new_mpath, |
| 9398 | .policy = nl80211_policy, |
| 9399 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9400 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9401 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9402 | }, |
| 9403 | { |
| 9404 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9405 | .doit = nl80211_del_mpath, |
| 9406 | .policy = nl80211_policy, |
| 9407 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9408 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9409 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9410 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9411 | { |
| 9412 | .cmd = NL80211_CMD_SET_BSS, |
| 9413 | .doit = nl80211_set_bss, |
| 9414 | .policy = nl80211_policy, |
| 9415 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9416 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9417 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9418 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9419 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9420 | .cmd = NL80211_CMD_GET_REG, |
| 9421 | .doit = nl80211_get_reg, |
| 9422 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9423 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9424 | /* can be retrieved by unprivileged users */ |
| 9425 | }, |
| 9426 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9427 | .cmd = NL80211_CMD_SET_REG, |
| 9428 | .doit = nl80211_set_reg, |
| 9429 | .policy = nl80211_policy, |
| 9430 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9431 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9432 | }, |
| 9433 | { |
| 9434 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9435 | .doit = nl80211_req_set_reg, |
| 9436 | .policy = nl80211_policy, |
| 9437 | .flags = GENL_ADMIN_PERM, |
| 9438 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9439 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9440 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9441 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9442 | .policy = nl80211_policy, |
| 9443 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9444 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9445 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9446 | }, |
| 9447 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9448 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9449 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9450 | .policy = nl80211_policy, |
| 9451 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9452 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9453 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9454 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9455 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9456 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9457 | .doit = nl80211_trigger_scan, |
| 9458 | .policy = nl80211_policy, |
| 9459 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9460 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9461 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9462 | }, |
| 9463 | { |
| 9464 | .cmd = NL80211_CMD_GET_SCAN, |
| 9465 | .policy = nl80211_policy, |
| 9466 | .dumpit = nl80211_dump_scan, |
| 9467 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9468 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9469 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9470 | .doit = nl80211_start_sched_scan, |
| 9471 | .policy = nl80211_policy, |
| 9472 | .flags = GENL_ADMIN_PERM, |
| 9473 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9474 | NL80211_FLAG_NEED_RTNL, |
| 9475 | }, |
| 9476 | { |
| 9477 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9478 | .doit = nl80211_stop_sched_scan, |
| 9479 | .policy = nl80211_policy, |
| 9480 | .flags = GENL_ADMIN_PERM, |
| 9481 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9482 | NL80211_FLAG_NEED_RTNL, |
| 9483 | }, |
| 9484 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9485 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9486 | .doit = nl80211_authenticate, |
| 9487 | .policy = nl80211_policy, |
| 9488 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9489 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9490 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9491 | }, |
| 9492 | { |
| 9493 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9494 | .doit = nl80211_associate, |
| 9495 | .policy = nl80211_policy, |
| 9496 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9497 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9498 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9499 | }, |
| 9500 | { |
| 9501 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9502 | .doit = nl80211_deauthenticate, |
| 9503 | .policy = nl80211_policy, |
| 9504 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9505 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9506 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9507 | }, |
| 9508 | { |
| 9509 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9510 | .doit = nl80211_disassociate, |
| 9511 | .policy = nl80211_policy, |
| 9512 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9513 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9514 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9515 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9516 | { |
| 9517 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9518 | .doit = nl80211_join_ibss, |
| 9519 | .policy = nl80211_policy, |
| 9520 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9521 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9522 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9523 | }, |
| 9524 | { |
| 9525 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9526 | .doit = nl80211_leave_ibss, |
| 9527 | .policy = nl80211_policy, |
| 9528 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9529 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9530 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9531 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9532 | #ifdef CONFIG_NL80211_TESTMODE |
| 9533 | { |
| 9534 | .cmd = NL80211_CMD_TESTMODE, |
| 9535 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9536 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9537 | .policy = nl80211_policy, |
| 9538 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9539 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9540 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9541 | }, |
| 9542 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9543 | { |
| 9544 | .cmd = NL80211_CMD_CONNECT, |
| 9545 | .doit = nl80211_connect, |
| 9546 | .policy = nl80211_policy, |
| 9547 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9548 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9549 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9550 | }, |
| 9551 | { |
| 9552 | .cmd = NL80211_CMD_DISCONNECT, |
| 9553 | .doit = nl80211_disconnect, |
| 9554 | .policy = nl80211_policy, |
| 9555 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9556 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9557 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9558 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9559 | { |
| 9560 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9561 | .doit = nl80211_wiphy_netns, |
| 9562 | .policy = nl80211_policy, |
| 9563 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9564 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9565 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9566 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9567 | { |
| 9568 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9569 | .policy = nl80211_policy, |
| 9570 | .dumpit = nl80211_dump_survey, |
| 9571 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9572 | { |
| 9573 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9574 | .doit = nl80211_setdel_pmksa, |
| 9575 | .policy = nl80211_policy, |
| 9576 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9577 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9578 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9579 | }, |
| 9580 | { |
| 9581 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9582 | .doit = nl80211_setdel_pmksa, |
| 9583 | .policy = nl80211_policy, |
| 9584 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9585 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9586 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9587 | }, |
| 9588 | { |
| 9589 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9590 | .doit = nl80211_flush_pmksa, |
| 9591 | .policy = nl80211_policy, |
| 9592 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9593 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9594 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9595 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9596 | { |
| 9597 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9598 | .doit = nl80211_remain_on_channel, |
| 9599 | .policy = nl80211_policy, |
| 9600 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9601 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9602 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9603 | }, |
| 9604 | { |
| 9605 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9606 | .doit = nl80211_cancel_remain_on_channel, |
| 9607 | .policy = nl80211_policy, |
| 9608 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9609 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9610 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9611 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9612 | { |
| 9613 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9614 | .doit = nl80211_set_tx_bitrate_mask, |
| 9615 | .policy = nl80211_policy, |
| 9616 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9617 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9618 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9619 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9620 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9621 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9622 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9623 | .policy = nl80211_policy, |
| 9624 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9625 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9626 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9627 | }, |
| 9628 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9629 | .cmd = NL80211_CMD_FRAME, |
| 9630 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9631 | .policy = nl80211_policy, |
| 9632 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9633 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9634 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9635 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9636 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9637 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9638 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9639 | .policy = nl80211_policy, |
| 9640 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9641 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9642 | NL80211_FLAG_NEED_RTNL, |
| 9643 | }, |
| 9644 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9645 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9646 | .doit = nl80211_set_power_save, |
| 9647 | .policy = nl80211_policy, |
| 9648 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9649 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9650 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9651 | }, |
| 9652 | { |
| 9653 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9654 | .doit = nl80211_get_power_save, |
| 9655 | .policy = nl80211_policy, |
| 9656 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9657 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9658 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9659 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9660 | { |
| 9661 | .cmd = NL80211_CMD_SET_CQM, |
| 9662 | .doit = nl80211_set_cqm, |
| 9663 | .policy = nl80211_policy, |
| 9664 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9665 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9666 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9667 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9668 | { |
| 9669 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9670 | .doit = nl80211_set_channel, |
| 9671 | .policy = nl80211_policy, |
| 9672 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9673 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9674 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9675 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9676 | { |
| 9677 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9678 | .doit = nl80211_set_wds_peer, |
| 9679 | .policy = nl80211_policy, |
| 9680 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9681 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9682 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9683 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9684 | { |
| 9685 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9686 | .doit = nl80211_join_mesh, |
| 9687 | .policy = nl80211_policy, |
| 9688 | .flags = GENL_ADMIN_PERM, |
| 9689 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9690 | NL80211_FLAG_NEED_RTNL, |
| 9691 | }, |
| 9692 | { |
| 9693 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9694 | .doit = nl80211_leave_mesh, |
| 9695 | .policy = nl80211_policy, |
| 9696 | .flags = GENL_ADMIN_PERM, |
| 9697 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9698 | NL80211_FLAG_NEED_RTNL, |
| 9699 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9700 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9701 | { |
| 9702 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9703 | .doit = nl80211_get_wowlan, |
| 9704 | .policy = nl80211_policy, |
| 9705 | /* can be retrieved by unprivileged users */ |
| 9706 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9707 | NL80211_FLAG_NEED_RTNL, |
| 9708 | }, |
| 9709 | { |
| 9710 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9711 | .doit = nl80211_set_wowlan, |
| 9712 | .policy = nl80211_policy, |
| 9713 | .flags = GENL_ADMIN_PERM, |
| 9714 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9715 | NL80211_FLAG_NEED_RTNL, |
| 9716 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9717 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9718 | { |
| 9719 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9720 | .doit = nl80211_set_rekey_data, |
| 9721 | .policy = nl80211_policy, |
| 9722 | .flags = GENL_ADMIN_PERM, |
| 9723 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9724 | NL80211_FLAG_NEED_RTNL, |
| 9725 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9726 | { |
| 9727 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9728 | .doit = nl80211_tdls_mgmt, |
| 9729 | .policy = nl80211_policy, |
| 9730 | .flags = GENL_ADMIN_PERM, |
| 9731 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9732 | NL80211_FLAG_NEED_RTNL, |
| 9733 | }, |
| 9734 | { |
| 9735 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9736 | .doit = nl80211_tdls_oper, |
| 9737 | .policy = nl80211_policy, |
| 9738 | .flags = GENL_ADMIN_PERM, |
| 9739 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9740 | NL80211_FLAG_NEED_RTNL, |
| 9741 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9742 | { |
| 9743 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9744 | .doit = nl80211_register_unexpected_frame, |
| 9745 | .policy = nl80211_policy, |
| 9746 | .flags = GENL_ADMIN_PERM, |
| 9747 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9748 | NL80211_FLAG_NEED_RTNL, |
| 9749 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9750 | { |
| 9751 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9752 | .doit = nl80211_probe_client, |
| 9753 | .policy = nl80211_policy, |
| 9754 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9755 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9756 | NL80211_FLAG_NEED_RTNL, |
| 9757 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9758 | { |
| 9759 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9760 | .doit = nl80211_register_beacons, |
| 9761 | .policy = nl80211_policy, |
| 9762 | .flags = GENL_ADMIN_PERM, |
| 9763 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9764 | NL80211_FLAG_NEED_RTNL, |
| 9765 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9766 | { |
| 9767 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9768 | .doit = nl80211_set_noack_map, |
| 9769 | .policy = nl80211_policy, |
| 9770 | .flags = GENL_ADMIN_PERM, |
| 9771 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9772 | NL80211_FLAG_NEED_RTNL, |
| 9773 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9774 | { |
| 9775 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 9776 | .doit = nl80211_start_p2p_device, |
| 9777 | .policy = nl80211_policy, |
| 9778 | .flags = GENL_ADMIN_PERM, |
| 9779 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9780 | NL80211_FLAG_NEED_RTNL, |
| 9781 | }, |
| 9782 | { |
| 9783 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 9784 | .doit = nl80211_stop_p2p_device, |
| 9785 | .policy = nl80211_policy, |
| 9786 | .flags = GENL_ADMIN_PERM, |
| 9787 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9788 | NL80211_FLAG_NEED_RTNL, |
| 9789 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9790 | { |
| 9791 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 9792 | .doit = nl80211_set_mcast_rate, |
| 9793 | .policy = nl80211_policy, |
| 9794 | .flags = GENL_ADMIN_PERM, |
| 9795 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9796 | NL80211_FLAG_NEED_RTNL, |
| 9797 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 9798 | { |
| 9799 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 9800 | .doit = nl80211_set_mac_acl, |
| 9801 | .policy = nl80211_policy, |
| 9802 | .flags = GENL_ADMIN_PERM, |
| 9803 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9804 | NL80211_FLAG_NEED_RTNL, |
| 9805 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9806 | { |
| 9807 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 9808 | .doit = nl80211_start_radar_detection, |
| 9809 | .policy = nl80211_policy, |
| 9810 | .flags = GENL_ADMIN_PERM, |
| 9811 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9812 | NL80211_FLAG_NEED_RTNL, |
| 9813 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9814 | { |
| 9815 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 9816 | .doit = nl80211_get_protocol_features, |
| 9817 | .policy = nl80211_policy, |
| 9818 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9819 | { |
| 9820 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9821 | .doit = nl80211_update_ft_ies, |
| 9822 | .policy = nl80211_policy, |
| 9823 | .flags = GENL_ADMIN_PERM, |
| 9824 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9825 | NL80211_FLAG_NEED_RTNL, |
| 9826 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9827 | { |
| 9828 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9829 | .doit = nl80211_crit_protocol_start, |
| 9830 | .policy = nl80211_policy, |
| 9831 | .flags = GENL_ADMIN_PERM, |
| 9832 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9833 | NL80211_FLAG_NEED_RTNL, |
| 9834 | }, |
| 9835 | { |
| 9836 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9837 | .doit = nl80211_crit_protocol_stop, |
| 9838 | .policy = nl80211_policy, |
| 9839 | .flags = GENL_ADMIN_PERM, |
| 9840 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9841 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9842 | }, |
| 9843 | { |
| 9844 | .cmd = NL80211_CMD_GET_COALESCE, |
| 9845 | .doit = nl80211_get_coalesce, |
| 9846 | .policy = nl80211_policy, |
| 9847 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9848 | NL80211_FLAG_NEED_RTNL, |
| 9849 | }, |
| 9850 | { |
| 9851 | .cmd = NL80211_CMD_SET_COALESCE, |
| 9852 | .doit = nl80211_set_coalesce, |
| 9853 | .policy = nl80211_policy, |
| 9854 | .flags = GENL_ADMIN_PERM, |
| 9855 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9856 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9857 | }, |
| 9858 | { |
| 9859 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 9860 | .doit = nl80211_channel_switch, |
| 9861 | .policy = nl80211_policy, |
| 9862 | .flags = GENL_ADMIN_PERM, |
| 9863 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9864 | NL80211_FLAG_NEED_RTNL, |
| 9865 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9866 | { |
| 9867 | .cmd = NL80211_CMD_VENDOR, |
| 9868 | .doit = nl80211_vendor_cmd, |
| 9869 | .policy = nl80211_policy, |
| 9870 | .flags = GENL_ADMIN_PERM, |
| 9871 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9872 | NL80211_FLAG_NEED_RTNL, |
| 9873 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9874 | { |
| 9875 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 9876 | .doit = nl80211_set_qos_map, |
| 9877 | .policy = nl80211_policy, |
| 9878 | .flags = GENL_ADMIN_PERM, |
| 9879 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9880 | NL80211_FLAG_NEED_RTNL, |
| 9881 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9882 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9883 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9884 | /* notification functions */ |
| 9885 | |
| 9886 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 9887 | { |
| 9888 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9889 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9890 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9891 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9892 | if (!msg) |
| 9893 | return; |
| 9894 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9895 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9896 | nlmsg_free(msg); |
| 9897 | return; |
| 9898 | } |
| 9899 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9900 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 9901 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9902 | } |
| 9903 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9904 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9905 | struct cfg80211_registered_device *rdev) |
| 9906 | { |
| 9907 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9908 | struct nlattr *nest; |
| 9909 | int i; |
| 9910 | |
| 9911 | if (WARN_ON(!req)) |
| 9912 | return 0; |
| 9913 | |
| 9914 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9915 | if (!nest) |
| 9916 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9917 | for (i = 0; i < req->n_ssids; i++) { |
| 9918 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9919 | goto nla_put_failure; |
| 9920 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9921 | nla_nest_end(msg, nest); |
| 9922 | |
| 9923 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9924 | if (!nest) |
| 9925 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9926 | for (i = 0; i < req->n_channels; i++) { |
| 9927 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9928 | goto nla_put_failure; |
| 9929 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9930 | nla_nest_end(msg, nest); |
| 9931 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9932 | if (req->ie && |
| 9933 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9934 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9935 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 9936 | if (req->flags && |
| 9937 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 9938 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9939 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9940 | return 0; |
| 9941 | nla_put_failure: |
| 9942 | return -ENOBUFS; |
| 9943 | } |
| 9944 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9945 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9946 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9947 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9948 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9949 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9950 | { |
| 9951 | void *hdr; |
| 9952 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9953 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9954 | if (!hdr) |
| 9955 | return -1; |
| 9956 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9957 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9958 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9959 | wdev->netdev->ifindex)) || |
| 9960 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9961 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9962 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9963 | /* ignore errors and send incomplete event anyway */ |
| 9964 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9965 | |
| 9966 | return genlmsg_end(msg, hdr); |
| 9967 | |
| 9968 | nla_put_failure: |
| 9969 | genlmsg_cancel(msg, hdr); |
| 9970 | return -EMSGSIZE; |
| 9971 | } |
| 9972 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9973 | static int |
| 9974 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9975 | struct cfg80211_registered_device *rdev, |
| 9976 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9977 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9978 | { |
| 9979 | void *hdr; |
| 9980 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9981 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9982 | if (!hdr) |
| 9983 | return -1; |
| 9984 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9985 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9986 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9987 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9988 | |
| 9989 | return genlmsg_end(msg, hdr); |
| 9990 | |
| 9991 | nla_put_failure: |
| 9992 | genlmsg_cancel(msg, hdr); |
| 9993 | return -EMSGSIZE; |
| 9994 | } |
| 9995 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9996 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9997 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9998 | { |
| 9999 | struct sk_buff *msg; |
| 10000 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10001 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10002 | if (!msg) |
| 10003 | return; |
| 10004 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10005 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10006 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 10007 | nlmsg_free(msg); |
| 10008 | return; |
| 10009 | } |
| 10010 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10011 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10012 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10013 | } |
| 10014 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10015 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 10016 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10017 | { |
| 10018 | struct sk_buff *msg; |
| 10019 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10020 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10021 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10022 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10023 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10024 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10025 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 10026 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10027 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10028 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10029 | } |
| 10030 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10031 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10032 | } |
| 10033 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10034 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 10035 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10036 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10037 | if (!msg) |
| 10038 | return; |
| 10039 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10040 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10041 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10042 | } |
| 10043 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10044 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 10045 | struct net_device *netdev) |
| 10046 | { |
| 10047 | struct sk_buff *msg; |
| 10048 | |
| 10049 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10050 | if (!msg) |
| 10051 | return; |
| 10052 | |
| 10053 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 10054 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 10055 | nlmsg_free(msg); |
| 10056 | return; |
| 10057 | } |
| 10058 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10059 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10060 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10061 | } |
| 10062 | |
| 10063 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 10064 | struct net_device *netdev, u32 cmd) |
| 10065 | { |
| 10066 | struct sk_buff *msg; |
| 10067 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10068 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10069 | if (!msg) |
| 10070 | return; |
| 10071 | |
| 10072 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 10073 | nlmsg_free(msg); |
| 10074 | return; |
| 10075 | } |
| 10076 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10077 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10078 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10079 | } |
| 10080 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10081 | /* |
| 10082 | * This can happen on global regulatory changes or device specific settings |
| 10083 | * based on custom world regulatory domains. |
| 10084 | */ |
| 10085 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 10086 | { |
| 10087 | struct sk_buff *msg; |
| 10088 | void *hdr; |
| 10089 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10090 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10091 | if (!msg) |
| 10092 | return; |
| 10093 | |
| 10094 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 10095 | if (!hdr) { |
| 10096 | nlmsg_free(msg); |
| 10097 | return; |
| 10098 | } |
| 10099 | |
| 10100 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10101 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 10102 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10103 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10104 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 10105 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10106 | NL80211_REGDOM_TYPE_WORLD)) |
| 10107 | goto nla_put_failure; |
| 10108 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 10109 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10110 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 10111 | goto nla_put_failure; |
| 10112 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 10113 | request->intersect) { |
| 10114 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10115 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 10116 | goto nla_put_failure; |
| 10117 | } else { |
| 10118 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10119 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 10120 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 10121 | request->alpha2)) |
| 10122 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10123 | } |
| 10124 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 10125 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10126 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 10127 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10128 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10129 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10130 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10131 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10132 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10133 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10134 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10135 | |
| 10136 | return; |
| 10137 | |
| 10138 | nla_put_failure: |
| 10139 | genlmsg_cancel(msg, hdr); |
| 10140 | nlmsg_free(msg); |
| 10141 | } |
| 10142 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10143 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 10144 | struct net_device *netdev, |
| 10145 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10146 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10147 | { |
| 10148 | struct sk_buff *msg; |
| 10149 | void *hdr; |
| 10150 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10151 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10152 | if (!msg) |
| 10153 | return; |
| 10154 | |
| 10155 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10156 | if (!hdr) { |
| 10157 | nlmsg_free(msg); |
| 10158 | return; |
| 10159 | } |
| 10160 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10161 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10162 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10163 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10164 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10165 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10166 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10167 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10168 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10169 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10170 | return; |
| 10171 | |
| 10172 | nla_put_failure: |
| 10173 | genlmsg_cancel(msg, hdr); |
| 10174 | nlmsg_free(msg); |
| 10175 | } |
| 10176 | |
| 10177 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10178 | struct net_device *netdev, const u8 *buf, |
| 10179 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10180 | { |
| 10181 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10182 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10183 | } |
| 10184 | |
| 10185 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 10186 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10187 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10188 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10189 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 10190 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10191 | } |
| 10192 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10193 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10194 | struct net_device *netdev, const u8 *buf, |
| 10195 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10196 | { |
| 10197 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10198 | NL80211_CMD_DEAUTHENTICATE, 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_disassoc(struct cfg80211_registered_device *rdev, |
| 10202 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 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_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10207 | } |
| 10208 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10209 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 10210 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10211 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10212 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10213 | struct wiphy *wiphy = wdev->wiphy; |
| 10214 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10215 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 10216 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10217 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10218 | if (WARN_ON(len < 2)) |
| 10219 | return; |
| 10220 | |
| 10221 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 10222 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 10223 | else |
| 10224 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 10225 | |
| 10226 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 10227 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10228 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10229 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10230 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 10231 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 10232 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10233 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10234 | { |
| 10235 | struct sk_buff *msg; |
| 10236 | void *hdr; |
| 10237 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10238 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10239 | if (!msg) |
| 10240 | return; |
| 10241 | |
| 10242 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10243 | if (!hdr) { |
| 10244 | nlmsg_free(msg); |
| 10245 | return; |
| 10246 | } |
| 10247 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10248 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10249 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10250 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 10251 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10252 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10253 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10254 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10255 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10256 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10257 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10258 | return; |
| 10259 | |
| 10260 | nla_put_failure: |
| 10261 | genlmsg_cancel(msg, hdr); |
| 10262 | nlmsg_free(msg); |
| 10263 | } |
| 10264 | |
| 10265 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10266 | struct net_device *netdev, const u8 *addr, |
| 10267 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10268 | { |
| 10269 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10270 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10271 | } |
| 10272 | |
| 10273 | void nl80211_send_assoc_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 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10277 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 10278 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10279 | } |
| 10280 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10281 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 10282 | struct net_device *netdev, const u8 *bssid, |
| 10283 | const u8 *req_ie, size_t req_ie_len, |
| 10284 | const u8 *resp_ie, size_t resp_ie_len, |
| 10285 | u16 status, gfp_t gfp) |
| 10286 | { |
| 10287 | struct sk_buff *msg; |
| 10288 | void *hdr; |
| 10289 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10290 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10291 | if (!msg) |
| 10292 | return; |
| 10293 | |
| 10294 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10295 | if (!hdr) { |
| 10296 | nlmsg_free(msg); |
| 10297 | return; |
| 10298 | } |
| 10299 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10300 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10301 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10302 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10303 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10304 | (req_ie && |
| 10305 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10306 | (resp_ie && |
| 10307 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10308 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10309 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10310 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10311 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10312 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10313 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10314 | return; |
| 10315 | |
| 10316 | nla_put_failure: |
| 10317 | genlmsg_cancel(msg, hdr); |
| 10318 | nlmsg_free(msg); |
| 10319 | |
| 10320 | } |
| 10321 | |
| 10322 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10323 | struct net_device *netdev, const u8 *bssid, |
| 10324 | const u8 *req_ie, size_t req_ie_len, |
| 10325 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10326 | { |
| 10327 | struct sk_buff *msg; |
| 10328 | void *hdr; |
| 10329 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10330 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10331 | if (!msg) |
| 10332 | return; |
| 10333 | |
| 10334 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10335 | if (!hdr) { |
| 10336 | nlmsg_free(msg); |
| 10337 | return; |
| 10338 | } |
| 10339 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10340 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10341 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10342 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10343 | (req_ie && |
| 10344 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10345 | (resp_ie && |
| 10346 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10347 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10348 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10349 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10350 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10351 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10352 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10353 | return; |
| 10354 | |
| 10355 | nla_put_failure: |
| 10356 | genlmsg_cancel(msg, hdr); |
| 10357 | nlmsg_free(msg); |
| 10358 | |
| 10359 | } |
| 10360 | |
| 10361 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10362 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10363 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10364 | { |
| 10365 | struct sk_buff *msg; |
| 10366 | void *hdr; |
| 10367 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10368 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10369 | if (!msg) |
| 10370 | return; |
| 10371 | |
| 10372 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10373 | if (!hdr) { |
| 10374 | nlmsg_free(msg); |
| 10375 | return; |
| 10376 | } |
| 10377 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10378 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10379 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10380 | (from_ap && reason && |
| 10381 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10382 | (from_ap && |
| 10383 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10384 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10385 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10386 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10387 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10388 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10389 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10390 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10391 | return; |
| 10392 | |
| 10393 | nla_put_failure: |
| 10394 | genlmsg_cancel(msg, hdr); |
| 10395 | nlmsg_free(msg); |
| 10396 | |
| 10397 | } |
| 10398 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10399 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10400 | struct net_device *netdev, const u8 *bssid, |
| 10401 | gfp_t gfp) |
| 10402 | { |
| 10403 | struct sk_buff *msg; |
| 10404 | void *hdr; |
| 10405 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10406 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10407 | if (!msg) |
| 10408 | return; |
| 10409 | |
| 10410 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10411 | if (!hdr) { |
| 10412 | nlmsg_free(msg); |
| 10413 | return; |
| 10414 | } |
| 10415 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10416 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10417 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10418 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10419 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10420 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10421 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10422 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10423 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10424 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10425 | return; |
| 10426 | |
| 10427 | nla_put_failure: |
| 10428 | genlmsg_cancel(msg, hdr); |
| 10429 | nlmsg_free(msg); |
| 10430 | } |
| 10431 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10432 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10433 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10434 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10435 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10436 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10437 | struct sk_buff *msg; |
| 10438 | void *hdr; |
| 10439 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10440 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10441 | return; |
| 10442 | |
| 10443 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10444 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10445 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10446 | if (!msg) |
| 10447 | return; |
| 10448 | |
| 10449 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10450 | if (!hdr) { |
| 10451 | nlmsg_free(msg); |
| 10452 | return; |
| 10453 | } |
| 10454 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10455 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10456 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10457 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10458 | (ie_len && ie && |
| 10459 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10460 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10461 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10462 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10463 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10464 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10465 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10466 | return; |
| 10467 | |
| 10468 | nla_put_failure: |
| 10469 | genlmsg_cancel(msg, hdr); |
| 10470 | nlmsg_free(msg); |
| 10471 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10472 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10473 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10474 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10475 | struct net_device *netdev, const u8 *addr, |
| 10476 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10477 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10478 | { |
| 10479 | struct sk_buff *msg; |
| 10480 | void *hdr; |
| 10481 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10482 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10483 | if (!msg) |
| 10484 | return; |
| 10485 | |
| 10486 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10487 | if (!hdr) { |
| 10488 | nlmsg_free(msg); |
| 10489 | return; |
| 10490 | } |
| 10491 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10492 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10493 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10494 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10495 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10496 | (key_id != -1 && |
| 10497 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10498 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10499 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10500 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10501 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10502 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10503 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10504 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10505 | return; |
| 10506 | |
| 10507 | nla_put_failure: |
| 10508 | genlmsg_cancel(msg, hdr); |
| 10509 | nlmsg_free(msg); |
| 10510 | } |
| 10511 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10512 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10513 | struct ieee80211_channel *channel_before, |
| 10514 | struct ieee80211_channel *channel_after) |
| 10515 | { |
| 10516 | struct sk_buff *msg; |
| 10517 | void *hdr; |
| 10518 | struct nlattr *nl_freq; |
| 10519 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10520 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10521 | if (!msg) |
| 10522 | return; |
| 10523 | |
| 10524 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10525 | if (!hdr) { |
| 10526 | nlmsg_free(msg); |
| 10527 | return; |
| 10528 | } |
| 10529 | |
| 10530 | /* |
| 10531 | * Since we are applying the beacon hint to a wiphy we know its |
| 10532 | * wiphy_idx is valid |
| 10533 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10534 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10535 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10536 | |
| 10537 | /* Before */ |
| 10538 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10539 | if (!nl_freq) |
| 10540 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10541 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10542 | goto nla_put_failure; |
| 10543 | nla_nest_end(msg, nl_freq); |
| 10544 | |
| 10545 | /* After */ |
| 10546 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 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_after, 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 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10553 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10554 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10555 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10556 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10557 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10558 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10559 | |
| 10560 | return; |
| 10561 | |
| 10562 | nla_put_failure: |
| 10563 | genlmsg_cancel(msg, hdr); |
| 10564 | nlmsg_free(msg); |
| 10565 | } |
| 10566 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10567 | static void nl80211_send_remain_on_chan_event( |
| 10568 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10569 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10570 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10571 | unsigned int duration, gfp_t gfp) |
| 10572 | { |
| 10573 | struct sk_buff *msg; |
| 10574 | void *hdr; |
| 10575 | |
| 10576 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10577 | if (!msg) |
| 10578 | return; |
| 10579 | |
| 10580 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10581 | if (!hdr) { |
| 10582 | nlmsg_free(msg); |
| 10583 | return; |
| 10584 | } |
| 10585 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10586 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10587 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10588 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10589 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10590 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10591 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10592 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10593 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10594 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10595 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10596 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10597 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10598 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10599 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10600 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10601 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10602 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10603 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10604 | return; |
| 10605 | |
| 10606 | nla_put_failure: |
| 10607 | genlmsg_cancel(msg, hdr); |
| 10608 | nlmsg_free(msg); |
| 10609 | } |
| 10610 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10611 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10612 | struct ieee80211_channel *chan, |
| 10613 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10614 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10615 | struct wiphy *wiphy = wdev->wiphy; |
| 10616 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10617 | |
| 10618 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10619 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10620 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10621 | duration, 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 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10624 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10625 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10626 | struct ieee80211_channel *chan, |
| 10627 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10628 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10629 | struct wiphy *wiphy = wdev->wiphy; |
| 10630 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10631 | |
| 10632 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10633 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10634 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10635 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10636 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10637 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10638 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10639 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10640 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10641 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10642 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10643 | struct sk_buff *msg; |
| 10644 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10645 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10646 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10647 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10648 | if (!msg) |
| 10649 | return; |
| 10650 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10651 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10652 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10653 | nlmsg_free(msg); |
| 10654 | return; |
| 10655 | } |
| 10656 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10657 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10658 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10659 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10660 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10661 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10662 | 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] | 10663 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10664 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10665 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10666 | struct sk_buff *msg; |
| 10667 | void *hdr; |
| 10668 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10669 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10670 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10671 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10672 | if (!msg) |
| 10673 | return; |
| 10674 | |
| 10675 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10676 | if (!hdr) { |
| 10677 | nlmsg_free(msg); |
| 10678 | return; |
| 10679 | } |
| 10680 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10681 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10682 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10683 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10684 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10685 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10686 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10687 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10688 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10689 | return; |
| 10690 | |
| 10691 | nla_put_failure: |
| 10692 | genlmsg_cancel(msg, hdr); |
| 10693 | nlmsg_free(msg); |
| 10694 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10695 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10696 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10697 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10698 | enum nl80211_connect_failed_reason reason, |
| 10699 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10700 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10701 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10702 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10703 | struct sk_buff *msg; |
| 10704 | void *hdr; |
| 10705 | |
| 10706 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10707 | if (!msg) |
| 10708 | return; |
| 10709 | |
| 10710 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10711 | if (!hdr) { |
| 10712 | nlmsg_free(msg); |
| 10713 | return; |
| 10714 | } |
| 10715 | |
| 10716 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10717 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10718 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10719 | goto nla_put_failure; |
| 10720 | |
| 10721 | genlmsg_end(msg, hdr); |
| 10722 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10723 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10724 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10725 | return; |
| 10726 | |
| 10727 | nla_put_failure: |
| 10728 | genlmsg_cancel(msg, hdr); |
| 10729 | nlmsg_free(msg); |
| 10730 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10731 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10732 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10733 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10734 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10735 | { |
| 10736 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10737 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10738 | struct sk_buff *msg; |
| 10739 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10740 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10741 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10742 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10743 | return false; |
| 10744 | |
| 10745 | msg = nlmsg_new(100, gfp); |
| 10746 | if (!msg) |
| 10747 | return true; |
| 10748 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10749 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10750 | if (!hdr) { |
| 10751 | nlmsg_free(msg); |
| 10752 | return true; |
| 10753 | } |
| 10754 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10755 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10756 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10757 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10758 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10759 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10760 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10761 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10762 | return true; |
| 10763 | |
| 10764 | nla_put_failure: |
| 10765 | genlmsg_cancel(msg, hdr); |
| 10766 | nlmsg_free(msg); |
| 10767 | return true; |
| 10768 | } |
| 10769 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10770 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 10771 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10772 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10773 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10774 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10775 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10776 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 10777 | |
| 10778 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10779 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 10780 | trace_cfg80211_return_bool(false); |
| 10781 | return false; |
| 10782 | } |
| 10783 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 10784 | addr, gfp); |
| 10785 | trace_cfg80211_return_bool(ret); |
| 10786 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10787 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10788 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 10789 | |
| 10790 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 10791 | const u8 *addr, gfp_t gfp) |
| 10792 | { |
| 10793 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10794 | bool ret; |
| 10795 | |
| 10796 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 10797 | |
| 10798 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10799 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 10800 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 10801 | trace_cfg80211_return_bool(false); |
| 10802 | return false; |
| 10803 | } |
| 10804 | ret = __nl80211_unexpected_frame(dev, |
| 10805 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 10806 | addr, gfp); |
| 10807 | trace_cfg80211_return_bool(ret); |
| 10808 | return ret; |
| 10809 | } |
| 10810 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10811 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10812 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10813 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 10814 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10815 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10816 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10817 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10818 | struct sk_buff *msg; |
| 10819 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10820 | |
| 10821 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10822 | if (!msg) |
| 10823 | return -ENOMEM; |
| 10824 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10825 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10826 | if (!hdr) { |
| 10827 | nlmsg_free(msg); |
| 10828 | return -ENOMEM; |
| 10829 | } |
| 10830 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10831 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10832 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10833 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10834 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10835 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10836 | (sig_dbm && |
| 10837 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10838 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10839 | (flags && |
| 10840 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10841 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10842 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10843 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10844 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10845 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10846 | |
| 10847 | nla_put_failure: |
| 10848 | genlmsg_cancel(msg, hdr); |
| 10849 | nlmsg_free(msg); |
| 10850 | return -ENOBUFS; |
| 10851 | } |
| 10852 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10853 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10854 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10855 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10856 | struct wiphy *wiphy = wdev->wiphy; |
| 10857 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10858 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10859 | struct sk_buff *msg; |
| 10860 | void *hdr; |
| 10861 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10862 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10863 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10864 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10865 | if (!msg) |
| 10866 | return; |
| 10867 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10868 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10869 | if (!hdr) { |
| 10870 | nlmsg_free(msg); |
| 10871 | return; |
| 10872 | } |
| 10873 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10874 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10875 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10876 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10877 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10878 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10879 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10880 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10881 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10882 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10883 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10884 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10885 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10886 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10887 | return; |
| 10888 | |
| 10889 | nla_put_failure: |
| 10890 | genlmsg_cancel(msg, hdr); |
| 10891 | nlmsg_free(msg); |
| 10892 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10893 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10894 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10895 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10896 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10897 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10898 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10899 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10900 | struct wiphy *wiphy = wdev->wiphy; |
| 10901 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10902 | struct sk_buff *msg; |
| 10903 | struct nlattr *pinfoattr; |
| 10904 | void *hdr; |
| 10905 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10906 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10907 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10908 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10909 | if (!msg) |
| 10910 | return; |
| 10911 | |
| 10912 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10913 | if (!hdr) { |
| 10914 | nlmsg_free(msg); |
| 10915 | return; |
| 10916 | } |
| 10917 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10918 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10919 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10920 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10921 | |
| 10922 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10923 | if (!pinfoattr) |
| 10924 | goto nla_put_failure; |
| 10925 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10926 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10927 | rssi_event)) |
| 10928 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10929 | |
| 10930 | nla_nest_end(msg, pinfoattr); |
| 10931 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10932 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10933 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10934 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10935 | NL80211_MCGRP_MLME, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10936 | return; |
| 10937 | |
| 10938 | nla_put_failure: |
| 10939 | genlmsg_cancel(msg, hdr); |
| 10940 | nlmsg_free(msg); |
| 10941 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10942 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10943 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10944 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10945 | struct net_device *netdev, const u8 *bssid, |
| 10946 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10947 | { |
| 10948 | struct sk_buff *msg; |
| 10949 | struct nlattr *rekey_attr; |
| 10950 | void *hdr; |
| 10951 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10952 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10953 | if (!msg) |
| 10954 | return; |
| 10955 | |
| 10956 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10957 | if (!hdr) { |
| 10958 | nlmsg_free(msg); |
| 10959 | return; |
| 10960 | } |
| 10961 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10962 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10963 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10964 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10965 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10966 | |
| 10967 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10968 | if (!rekey_attr) |
| 10969 | goto nla_put_failure; |
| 10970 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10971 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10972 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10973 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10974 | |
| 10975 | nla_nest_end(msg, rekey_attr); |
| 10976 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10977 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10978 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10979 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10980 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10981 | return; |
| 10982 | |
| 10983 | nla_put_failure: |
| 10984 | genlmsg_cancel(msg, hdr); |
| 10985 | nlmsg_free(msg); |
| 10986 | } |
| 10987 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10988 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10989 | const u8 *replay_ctr, gfp_t gfp) |
| 10990 | { |
| 10991 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10992 | struct wiphy *wiphy = wdev->wiphy; |
| 10993 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10994 | |
| 10995 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10996 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10997 | } |
| 10998 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10999 | |
| 11000 | static void |
| 11001 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 11002 | struct net_device *netdev, int index, |
| 11003 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11004 | { |
| 11005 | struct sk_buff *msg; |
| 11006 | struct nlattr *attr; |
| 11007 | void *hdr; |
| 11008 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11009 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11010 | if (!msg) |
| 11011 | return; |
| 11012 | |
| 11013 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 11014 | if (!hdr) { |
| 11015 | nlmsg_free(msg); |
| 11016 | return; |
| 11017 | } |
| 11018 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11019 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11020 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11021 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11022 | |
| 11023 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 11024 | if (!attr) |
| 11025 | goto nla_put_failure; |
| 11026 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11027 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 11028 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 11029 | (preauth && |
| 11030 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 11031 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11032 | |
| 11033 | nla_nest_end(msg, attr); |
| 11034 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11035 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11036 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11037 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11038 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11039 | return; |
| 11040 | |
| 11041 | nla_put_failure: |
| 11042 | genlmsg_cancel(msg, hdr); |
| 11043 | nlmsg_free(msg); |
| 11044 | } |
| 11045 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11046 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 11047 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 11048 | { |
| 11049 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11050 | struct wiphy *wiphy = wdev->wiphy; |
| 11051 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11052 | |
| 11053 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 11054 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 11055 | } |
| 11056 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 11057 | |
| 11058 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 11059 | struct net_device *netdev, |
| 11060 | struct cfg80211_chan_def *chandef, |
| 11061 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11062 | { |
| 11063 | struct sk_buff *msg; |
| 11064 | void *hdr; |
| 11065 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11066 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11067 | if (!msg) |
| 11068 | return; |
| 11069 | |
| 11070 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 11071 | if (!hdr) { |
| 11072 | nlmsg_free(msg); |
| 11073 | return; |
| 11074 | } |
| 11075 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11076 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11077 | goto nla_put_failure; |
| 11078 | |
| 11079 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 11080 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11081 | |
| 11082 | genlmsg_end(msg, hdr); |
| 11083 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11084 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11085 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11086 | return; |
| 11087 | |
| 11088 | nla_put_failure: |
| 11089 | genlmsg_cancel(msg, hdr); |
| 11090 | nlmsg_free(msg); |
| 11091 | } |
| 11092 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11093 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 11094 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11095 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11096 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11097 | struct wiphy *wiphy = wdev->wiphy; |
| 11098 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11099 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11100 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11101 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11102 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11103 | |
| 11104 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 11105 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 11106 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 11107 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11108 | return; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11109 | |
| 11110 | wdev->channel = chandef->chan; |
| 11111 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11112 | } |
| 11113 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 11114 | |
| 11115 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 11116 | const u8 *peer, u32 num_packets, |
| 11117 | u32 rate, u32 intvl, gfp_t gfp) |
| 11118 | { |
| 11119 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11120 | struct wiphy *wiphy = wdev->wiphy; |
| 11121 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11122 | struct sk_buff *msg; |
| 11123 | struct nlattr *pinfoattr; |
| 11124 | void *hdr; |
| 11125 | |
| 11126 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11127 | if (!msg) |
| 11128 | return; |
| 11129 | |
| 11130 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11131 | if (!hdr) { |
| 11132 | nlmsg_free(msg); |
| 11133 | return; |
| 11134 | } |
| 11135 | |
| 11136 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11137 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11138 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11139 | goto nla_put_failure; |
| 11140 | |
| 11141 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11142 | if (!pinfoattr) |
| 11143 | goto nla_put_failure; |
| 11144 | |
| 11145 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 11146 | goto nla_put_failure; |
| 11147 | |
| 11148 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 11149 | goto nla_put_failure; |
| 11150 | |
| 11151 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 11152 | goto nla_put_failure; |
| 11153 | |
| 11154 | nla_nest_end(msg, pinfoattr); |
| 11155 | |
| 11156 | genlmsg_end(msg, hdr); |
| 11157 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11158 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11159 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11160 | return; |
| 11161 | |
| 11162 | nla_put_failure: |
| 11163 | genlmsg_cancel(msg, hdr); |
| 11164 | nlmsg_free(msg); |
| 11165 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11166 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11167 | |
| 11168 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11169 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 11170 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11171 | enum nl80211_radar_event event, |
| 11172 | struct net_device *netdev, gfp_t gfp) |
| 11173 | { |
| 11174 | struct sk_buff *msg; |
| 11175 | void *hdr; |
| 11176 | |
| 11177 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11178 | if (!msg) |
| 11179 | return; |
| 11180 | |
| 11181 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 11182 | if (!hdr) { |
| 11183 | nlmsg_free(msg); |
| 11184 | return; |
| 11185 | } |
| 11186 | |
| 11187 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 11188 | goto nla_put_failure; |
| 11189 | |
| 11190 | /* NOP and radar events don't need a netdev parameter */ |
| 11191 | if (netdev) { |
| 11192 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 11193 | |
| 11194 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11195 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11196 | goto nla_put_failure; |
| 11197 | } |
| 11198 | |
| 11199 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 11200 | goto nla_put_failure; |
| 11201 | |
| 11202 | if (nl80211_send_chandef(msg, chandef)) |
| 11203 | goto nla_put_failure; |
| 11204 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11205 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11206 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11207 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11208 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11209 | return; |
| 11210 | |
| 11211 | nla_put_failure: |
| 11212 | genlmsg_cancel(msg, hdr); |
| 11213 | nlmsg_free(msg); |
| 11214 | } |
| 11215 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11216 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 11217 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11218 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11219 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11220 | struct wiphy *wiphy = wdev->wiphy; |
| 11221 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11222 | struct sk_buff *msg; |
| 11223 | struct nlattr *pinfoattr; |
| 11224 | void *hdr; |
| 11225 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11226 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 11227 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11228 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11229 | if (!msg) |
| 11230 | return; |
| 11231 | |
| 11232 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11233 | if (!hdr) { |
| 11234 | nlmsg_free(msg); |
| 11235 | return; |
| 11236 | } |
| 11237 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11238 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11239 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11240 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11241 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11242 | |
| 11243 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11244 | if (!pinfoattr) |
| 11245 | goto nla_put_failure; |
| 11246 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11247 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 11248 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11249 | |
| 11250 | nla_nest_end(msg, pinfoattr); |
| 11251 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11252 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11253 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11254 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11255 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11256 | return; |
| 11257 | |
| 11258 | nla_put_failure: |
| 11259 | genlmsg_cancel(msg, hdr); |
| 11260 | nlmsg_free(msg); |
| 11261 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11262 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11263 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11264 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 11265 | u64 cookie, bool acked, gfp_t gfp) |
| 11266 | { |
| 11267 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11268 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11269 | struct sk_buff *msg; |
| 11270 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11271 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11272 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 11273 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11274 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11275 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11276 | if (!msg) |
| 11277 | return; |
| 11278 | |
| 11279 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 11280 | if (!hdr) { |
| 11281 | nlmsg_free(msg); |
| 11282 | return; |
| 11283 | } |
| 11284 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11285 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11286 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11287 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11288 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11289 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11290 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11291 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11292 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11293 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11294 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11295 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11296 | return; |
| 11297 | |
| 11298 | nla_put_failure: |
| 11299 | genlmsg_cancel(msg, hdr); |
| 11300 | nlmsg_free(msg); |
| 11301 | } |
| 11302 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11303 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11304 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11305 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11306 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11307 | { |
| 11308 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11309 | struct sk_buff *msg; |
| 11310 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11311 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11312 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11313 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11314 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11315 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11316 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11317 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11318 | if (!msg) { |
| 11319 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11320 | return; |
| 11321 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11322 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11323 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11324 | if (!hdr) |
| 11325 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11326 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11327 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11328 | (freq && |
| 11329 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11330 | (sig_dbm && |
| 11331 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11332 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11333 | goto nla_put_failure; |
| 11334 | |
| 11335 | genlmsg_end(msg, hdr); |
| 11336 | |
| 11337 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11338 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11339 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11340 | return; |
| 11341 | |
| 11342 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11343 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11344 | if (hdr) |
| 11345 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11346 | nlmsg_free(msg); |
| 11347 | } |
| 11348 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11349 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11350 | #ifdef CONFIG_PM |
| 11351 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11352 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11353 | gfp_t gfp) |
| 11354 | { |
| 11355 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11356 | struct sk_buff *msg; |
| 11357 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11358 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11359 | |
| 11360 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11361 | |
| 11362 | if (wakeup) |
| 11363 | size += wakeup->packet_present_len; |
| 11364 | |
| 11365 | msg = nlmsg_new(size, gfp); |
| 11366 | if (!msg) |
| 11367 | return; |
| 11368 | |
| 11369 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11370 | if (!hdr) |
| 11371 | goto free_msg; |
| 11372 | |
| 11373 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11374 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11375 | goto free_msg; |
| 11376 | |
| 11377 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11378 | wdev->netdev->ifindex)) |
| 11379 | goto free_msg; |
| 11380 | |
| 11381 | if (wakeup) { |
| 11382 | struct nlattr *reasons; |
| 11383 | |
| 11384 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 11385 | if (!reasons) |
| 11386 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11387 | |
| 11388 | if (wakeup->disconnect && |
| 11389 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11390 | goto free_msg; |
| 11391 | if (wakeup->magic_pkt && |
| 11392 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11393 | goto free_msg; |
| 11394 | if (wakeup->gtk_rekey_failure && |
| 11395 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11396 | goto free_msg; |
| 11397 | if (wakeup->eap_identity_req && |
| 11398 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11399 | goto free_msg; |
| 11400 | if (wakeup->four_way_handshake && |
| 11401 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11402 | goto free_msg; |
| 11403 | if (wakeup->rfkill_release && |
| 11404 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11405 | goto free_msg; |
| 11406 | |
| 11407 | if (wakeup->pattern_idx >= 0 && |
| 11408 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11409 | wakeup->pattern_idx)) |
| 11410 | goto free_msg; |
| 11411 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11412 | if (wakeup->tcp_match && |
| 11413 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 11414 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11415 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11416 | if (wakeup->tcp_connlost && |
| 11417 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 11418 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11419 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11420 | if (wakeup->tcp_nomoretokens && |
| 11421 | nla_put_flag(msg, |
| 11422 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 11423 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11424 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11425 | if (wakeup->packet) { |
| 11426 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11427 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11428 | |
| 11429 | if (!wakeup->packet_80211) { |
| 11430 | pkt_attr = |
| 11431 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11432 | len_attr = |
| 11433 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11434 | } |
| 11435 | |
| 11436 | if (wakeup->packet_len && |
| 11437 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11438 | goto free_msg; |
| 11439 | |
| 11440 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11441 | wakeup->packet)) |
| 11442 | goto free_msg; |
| 11443 | } |
| 11444 | |
| 11445 | nla_nest_end(msg, reasons); |
| 11446 | } |
| 11447 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11448 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11449 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11450 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11451 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11452 | return; |
| 11453 | |
| 11454 | free_msg: |
| 11455 | nlmsg_free(msg); |
| 11456 | } |
| 11457 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11458 | #endif |
| 11459 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11460 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11461 | enum nl80211_tdls_operation oper, |
| 11462 | u16 reason_code, gfp_t gfp) |
| 11463 | { |
| 11464 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11465 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11466 | struct sk_buff *msg; |
| 11467 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11468 | |
| 11469 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11470 | reason_code); |
| 11471 | |
| 11472 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11473 | if (!msg) |
| 11474 | return; |
| 11475 | |
| 11476 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11477 | if (!hdr) { |
| 11478 | nlmsg_free(msg); |
| 11479 | return; |
| 11480 | } |
| 11481 | |
| 11482 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11483 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11484 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11485 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11486 | (reason_code > 0 && |
| 11487 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11488 | goto nla_put_failure; |
| 11489 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11490 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11491 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11492 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11493 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11494 | return; |
| 11495 | |
| 11496 | nla_put_failure: |
| 11497 | genlmsg_cancel(msg, hdr); |
| 11498 | nlmsg_free(msg); |
| 11499 | } |
| 11500 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11501 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11502 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11503 | unsigned long state, |
| 11504 | void *_notify) |
| 11505 | { |
| 11506 | struct netlink_notify *notify = _notify; |
| 11507 | struct cfg80211_registered_device *rdev; |
| 11508 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11509 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11510 | |
| 11511 | if (state != NETLINK_URELEASE) |
| 11512 | return NOTIFY_DONE; |
| 11513 | |
| 11514 | rcu_read_lock(); |
| 11515 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11516 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11517 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11518 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11519 | |
| 11520 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11521 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11522 | list) { |
| 11523 | if (reg->nlportid == notify->portid) { |
| 11524 | list_del(®->list); |
| 11525 | kfree(reg); |
| 11526 | break; |
| 11527 | } |
| 11528 | } |
| 11529 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11530 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11531 | |
| 11532 | rcu_read_unlock(); |
| 11533 | |
| 11534 | return NOTIFY_DONE; |
| 11535 | } |
| 11536 | |
| 11537 | static struct notifier_block nl80211_netlink_notifier = { |
| 11538 | .notifier_call = nl80211_netlink_notify, |
| 11539 | }; |
| 11540 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11541 | void cfg80211_ft_event(struct net_device *netdev, |
| 11542 | struct cfg80211_ft_event_params *ft_event) |
| 11543 | { |
| 11544 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 11545 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11546 | struct sk_buff *msg; |
| 11547 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11548 | |
| 11549 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11550 | |
| 11551 | if (!ft_event->target_ap) |
| 11552 | return; |
| 11553 | |
| 11554 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11555 | if (!msg) |
| 11556 | return; |
| 11557 | |
| 11558 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11559 | if (!hdr) |
| 11560 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11561 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11562 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11563 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11564 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 11565 | goto out; |
| 11566 | |
| 11567 | if (ft_event->ies && |
| 11568 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 11569 | goto out; |
| 11570 | if (ft_event->ric_ies && |
| 11571 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11572 | ft_event->ric_ies)) |
| 11573 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11574 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11575 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11576 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11577 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11578 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11579 | return; |
| 11580 | out: |
| 11581 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11582 | } |
| 11583 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11584 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11585 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11586 | { |
| 11587 | struct cfg80211_registered_device *rdev; |
| 11588 | struct sk_buff *msg; |
| 11589 | void *hdr; |
| 11590 | u32 nlportid; |
| 11591 | |
| 11592 | rdev = wiphy_to_dev(wdev->wiphy); |
| 11593 | if (!rdev->crit_proto_nlportid) |
| 11594 | return; |
| 11595 | |
| 11596 | nlportid = rdev->crit_proto_nlportid; |
| 11597 | rdev->crit_proto_nlportid = 0; |
| 11598 | |
| 11599 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11600 | if (!msg) |
| 11601 | return; |
| 11602 | |
| 11603 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11604 | if (!hdr) |
| 11605 | goto nla_put_failure; |
| 11606 | |
| 11607 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11608 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11609 | goto nla_put_failure; |
| 11610 | |
| 11611 | genlmsg_end(msg, hdr); |
| 11612 | |
| 11613 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11614 | return; |
| 11615 | |
| 11616 | nla_put_failure: |
| 11617 | if (hdr) |
| 11618 | genlmsg_cancel(msg, hdr); |
| 11619 | nlmsg_free(msg); |
| 11620 | |
| 11621 | } |
| 11622 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11623 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11624 | /* initialisation/exit functions */ |
| 11625 | |
| 11626 | int nl80211_init(void) |
| 11627 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11628 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11629 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11630 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 11631 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11632 | if (err) |
| 11633 | return err; |
| 11634 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11635 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11636 | if (err) |
| 11637 | goto err_out; |
| 11638 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11639 | return 0; |
| 11640 | err_out: |
| 11641 | genl_unregister_family(&nl80211_fam); |
| 11642 | return err; |
| 11643 | } |
| 11644 | |
| 11645 | void nl80211_exit(void) |
| 11646 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11647 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11648 | genl_unregister_family(&nl80211_fam); |
| 11649 | } |