Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 33 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 34 | struct genl_info *info); |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 35 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
Marcel Holtmann | fb4e156 | 2013-04-28 16:22:06 -0700 | [diff] [blame] | 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 50 | /* multicast groups */ |
| 51 | enum nl80211_multicast_groups { |
| 52 | NL80211_MCGRP_CONFIG, |
| 53 | NL80211_MCGRP_SCAN, |
| 54 | NL80211_MCGRP_REGULATORY, |
| 55 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 56 | NL80211_MCGRP_VENDOR, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 57 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 58 | }; |
| 59 | |
| 60 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
| 61 | [NL80211_MCGRP_CONFIG] = { .name = "config", }, |
| 62 | [NL80211_MCGRP_SCAN] = { .name = "scan", }, |
| 63 | [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", }, |
| 64 | [NL80211_MCGRP_MLME] = { .name = "mlme", }, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 65 | [NL80211_MCGRP_VENDOR] = { .name = "vendor", }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 66 | #ifdef CONFIG_NL80211_TESTMODE |
| 67 | [NL80211_MCGRP_TESTMODE] = { .name = "testmode", } |
| 68 | #endif |
| 69 | }; |
| 70 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 71 | /* returns ERR_PTR values */ |
| 72 | static struct wireless_dev * |
| 73 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 74 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 75 | struct cfg80211_registered_device *rdev; |
| 76 | struct wireless_dev *result = NULL; |
| 77 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 78 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 79 | u64 wdev_id; |
| 80 | int wiphy_idx = -1; |
| 81 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 82 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 83 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 84 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 85 | if (!have_ifidx && !have_wdev_id) |
| 86 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 87 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 88 | if (have_ifidx) |
| 89 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 90 | if (have_wdev_id) { |
| 91 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 92 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 93 | } |
| 94 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 95 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 96 | struct wireless_dev *wdev; |
| 97 | |
| 98 | if (wiphy_net(&rdev->wiphy) != netns) |
| 99 | continue; |
| 100 | |
| 101 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 102 | continue; |
| 103 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 104 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 105 | if (have_ifidx && wdev->netdev && |
| 106 | wdev->netdev->ifindex == ifidx) { |
| 107 | result = wdev; |
| 108 | break; |
| 109 | } |
| 110 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 111 | result = wdev; |
| 112 | break; |
| 113 | } |
| 114 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 115 | |
| 116 | if (result) |
| 117 | break; |
| 118 | } |
| 119 | |
| 120 | if (result) |
| 121 | return result; |
| 122 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 123 | } |
| 124 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 125 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 126 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 127 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 128 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 129 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 130 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 131 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 132 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 133 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 134 | !attrs[NL80211_ATTR_IFINDEX] && |
| 135 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 136 | return ERR_PTR(-EINVAL); |
| 137 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 138 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 139 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 140 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 141 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 142 | if (attrs[NL80211_ATTR_WDEV]) { |
| 143 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 144 | struct wireless_dev *wdev; |
| 145 | bool found = false; |
| 146 | |
| 147 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 148 | if (tmp) { |
| 149 | /* make sure wdev exists */ |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 150 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 151 | if (wdev->identifier != (u32)wdev_id) |
| 152 | continue; |
| 153 | found = true; |
| 154 | break; |
| 155 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 156 | |
| 157 | if (!found) |
| 158 | tmp = NULL; |
| 159 | |
| 160 | if (rdev && tmp != rdev) |
| 161 | return ERR_PTR(-EINVAL); |
| 162 | rdev = tmp; |
| 163 | } |
| 164 | } |
| 165 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 166 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 167 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 168 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 169 | if (netdev) { |
| 170 | if (netdev->ieee80211_ptr) |
| 171 | tmp = wiphy_to_dev( |
| 172 | netdev->ieee80211_ptr->wiphy); |
| 173 | else |
| 174 | tmp = NULL; |
| 175 | |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 176 | /* not wireless device -- return error */ |
| 177 | if (!tmp) |
| 178 | return ERR_PTR(-EINVAL); |
| 179 | |
| 180 | /* mismatch -- return error */ |
| 181 | if (rdev && tmp != rdev) |
| 182 | return ERR_PTR(-EINVAL); |
| 183 | |
| 184 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 185 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 188 | if (!rdev) |
| 189 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 190 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 191 | if (netns != wiphy_net(&rdev->wiphy)) |
| 192 | return ERR_PTR(-ENODEV); |
| 193 | |
| 194 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* |
| 198 | * This function returns a pointer to the driver |
| 199 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 200 | * |
| 201 | * The result of this can be a PTR_ERR and hence must |
| 202 | * be checked with IS_ERR() for errors. |
| 203 | */ |
| 204 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 205 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 206 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 207 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 208 | } |
| 209 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 210 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 211 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 212 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 213 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 214 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 215 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 216 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 217 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 218 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 219 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 220 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 221 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 222 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 223 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 224 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 225 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 226 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 227 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 228 | |
| 229 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 230 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 232 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 233 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 234 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 235 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 236 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 237 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 238 | .len = WLAN_MAX_KEY_LEN }, |
| 239 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 240 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 242 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 243 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 244 | |
| 245 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 246 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 247 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 248 | .len = IEEE80211_MAX_DATA_LEN }, |
| 249 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 250 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 251 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 252 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 253 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 254 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 255 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 256 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 257 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 258 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 259 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 260 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 262 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 263 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 264 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 265 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 266 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 267 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 268 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 270 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 271 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 272 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 273 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 274 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 275 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 276 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 277 | |
| 278 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 279 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 280 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 281 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 282 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 283 | |
| 284 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 285 | .len = IEEE80211_MAX_SSID_LEN }, |
| 286 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 287 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 288 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 289 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 290 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 291 | [NL80211_ATTR_STA_FLAGS2] = { |
| 292 | .len = sizeof(struct nl80211_sta_flag_update), |
| 293 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 294 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 296 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 297 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 298 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 299 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 300 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 301 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 302 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 303 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 304 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 305 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 306 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 308 | .len = IEEE80211_MAX_DATA_LEN }, |
| 309 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 310 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 312 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 315 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 317 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 318 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 319 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 320 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 323 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 324 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 325 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 326 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 327 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 328 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 329 | .len = IEEE80211_MAX_DATA_LEN }, |
| 330 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 331 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 332 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 333 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 334 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 336 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 337 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 339 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 340 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 341 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 342 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 343 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 344 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 345 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 346 | .len = NL80211_HT_CAPABILITY_LEN |
| 347 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 348 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 349 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 350 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 351 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 352 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 353 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 354 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 355 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 356 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 357 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 358 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 359 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 360 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 361 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 362 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 363 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 364 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 365 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 366 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 367 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 368 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 369 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 370 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 371 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 372 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 373 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
| 374 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 }, |
| 375 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 376 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 377 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 378 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 379 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 380 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 381 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 382 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 383 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 384 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 385 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 386 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 387 | }; |
| 388 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 389 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 390 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 391 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 392 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 393 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 394 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 395 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 396 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 397 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 398 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 399 | }; |
| 400 | |
| 401 | /* policy for the key default flags */ |
| 402 | static const struct nla_policy |
| 403 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 404 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 405 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 406 | }; |
| 407 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 408 | /* policy for WoWLAN attributes */ |
| 409 | static const struct nla_policy |
| 410 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 411 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 412 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 413 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 414 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 415 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 416 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 417 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 418 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 419 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 420 | }; |
| 421 | |
| 422 | static const struct nla_policy |
| 423 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 424 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 425 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 426 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 427 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 428 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 429 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 430 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 431 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 432 | }, |
| 433 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 434 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 435 | }, |
| 436 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 437 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 438 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 439 | }; |
| 440 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 441 | /* policy for coalesce rule attributes */ |
| 442 | static const struct nla_policy |
| 443 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 444 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 445 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 446 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 447 | }; |
| 448 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 449 | /* policy for GTK rekey offload attributes */ |
| 450 | static const struct nla_policy |
| 451 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 452 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 453 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 454 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 455 | }; |
| 456 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 457 | static const struct nla_policy |
| 458 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 459 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 460 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 461 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 462 | }; |
| 463 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 464 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 465 | struct netlink_callback *cb, |
| 466 | struct cfg80211_registered_device **rdev, |
| 467 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 468 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 469 | int err; |
| 470 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 471 | rtnl_lock(); |
| 472 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 473 | if (!cb->args[0]) { |
| 474 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 475 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 476 | nl80211_policy); |
| 477 | if (err) |
| 478 | goto out_unlock; |
| 479 | |
| 480 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 481 | nl80211_fam.attrbuf); |
| 482 | if (IS_ERR(*wdev)) { |
| 483 | err = PTR_ERR(*wdev); |
| 484 | goto out_unlock; |
| 485 | } |
| 486 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 487 | /* 0 is the first index - add 1 to parse only once */ |
| 488 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 489 | cb->args[1] = (*wdev)->identifier; |
| 490 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 491 | /* subtract the 1 again here */ |
| 492 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 493 | struct wireless_dev *tmp; |
| 494 | |
| 495 | if (!wiphy) { |
| 496 | err = -ENODEV; |
| 497 | goto out_unlock; |
| 498 | } |
| 499 | *rdev = wiphy_to_dev(wiphy); |
| 500 | *wdev = NULL; |
| 501 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 502 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 503 | if (tmp->identifier == cb->args[1]) { |
| 504 | *wdev = tmp; |
| 505 | break; |
| 506 | } |
| 507 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 508 | |
| 509 | if (!*wdev) { |
| 510 | err = -ENODEV; |
| 511 | goto out_unlock; |
| 512 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 513 | } |
| 514 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 515 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 516 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 517 | rtnl_unlock(); |
| 518 | return err; |
| 519 | } |
| 520 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 521 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 522 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 523 | rtnl_unlock(); |
| 524 | } |
| 525 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 526 | /* IE validation */ |
| 527 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 528 | { |
| 529 | const u8 *pos; |
| 530 | int len; |
| 531 | |
| 532 | if (!attr) |
| 533 | return true; |
| 534 | |
| 535 | pos = nla_data(attr); |
| 536 | len = nla_len(attr); |
| 537 | |
| 538 | while (len) { |
| 539 | u8 elemlen; |
| 540 | |
| 541 | if (len < 2) |
| 542 | return false; |
| 543 | len -= 2; |
| 544 | |
| 545 | elemlen = pos[1]; |
| 546 | if (elemlen > len) |
| 547 | return false; |
| 548 | |
| 549 | len -= elemlen; |
| 550 | pos += 2 + elemlen; |
| 551 | } |
| 552 | |
| 553 | return true; |
| 554 | } |
| 555 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 556 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 557 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 558 | int flags, u8 cmd) |
| 559 | { |
| 560 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 561 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 562 | } |
| 563 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 564 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 565 | struct ieee80211_channel *chan, |
| 566 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 567 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 568 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 569 | chan->center_freq)) |
| 570 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 571 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 572 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 573 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 574 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 575 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 576 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 577 | goto nla_put_failure; |
| 578 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 579 | goto nla_put_failure; |
| 580 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 581 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 582 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 583 | goto nla_put_failure; |
| 584 | if (large) { |
| 585 | u32 time; |
| 586 | |
| 587 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 588 | |
| 589 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 590 | chan->dfs_state)) |
| 591 | goto nla_put_failure; |
| 592 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 593 | time)) |
| 594 | goto nla_put_failure; |
| 595 | } |
| 596 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 597 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 598 | if (large) { |
| 599 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 600 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 601 | goto nla_put_failure; |
| 602 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 603 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 604 | goto nla_put_failure; |
| 605 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 606 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 607 | goto nla_put_failure; |
| 608 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 609 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 610 | goto nla_put_failure; |
| 611 | } |
| 612 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 613 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 614 | DBM_TO_MBM(chan->max_power))) |
| 615 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 616 | |
| 617 | return 0; |
| 618 | |
| 619 | nla_put_failure: |
| 620 | return -ENOBUFS; |
| 621 | } |
| 622 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 623 | /* netlink command implementations */ |
| 624 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 625 | struct key_parse { |
| 626 | struct key_params p; |
| 627 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 628 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 629 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 630 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 631 | }; |
| 632 | |
| 633 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 634 | { |
| 635 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 636 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 637 | nl80211_key_policy); |
| 638 | if (err) |
| 639 | return err; |
| 640 | |
| 641 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 642 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 643 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 644 | if (k->def) { |
| 645 | k->def_uni = true; |
| 646 | k->def_multi = true; |
| 647 | } |
| 648 | if (k->defmgmt) |
| 649 | k->def_multi = true; |
| 650 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 651 | if (tb[NL80211_KEY_IDX]) |
| 652 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 653 | |
| 654 | if (tb[NL80211_KEY_DATA]) { |
| 655 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 656 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 657 | } |
| 658 | |
| 659 | if (tb[NL80211_KEY_SEQ]) { |
| 660 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 661 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 662 | } |
| 663 | |
| 664 | if (tb[NL80211_KEY_CIPHER]) |
| 665 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 666 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 667 | if (tb[NL80211_KEY_TYPE]) { |
| 668 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 669 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 670 | return -EINVAL; |
| 671 | } |
| 672 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 673 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 674 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 675 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 676 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 677 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 678 | if (err) |
| 679 | return err; |
| 680 | |
| 681 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 682 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 683 | } |
| 684 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 685 | return 0; |
| 686 | } |
| 687 | |
| 688 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 689 | { |
| 690 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 691 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 692 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 693 | } |
| 694 | |
| 695 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 696 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 697 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 698 | } |
| 699 | |
| 700 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 701 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 702 | |
| 703 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 704 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 705 | |
| 706 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 707 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 708 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 709 | if (k->def) { |
| 710 | k->def_uni = true; |
| 711 | k->def_multi = true; |
| 712 | } |
| 713 | if (k->defmgmt) |
| 714 | k->def_multi = true; |
| 715 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 716 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 717 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 718 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 719 | return -EINVAL; |
| 720 | } |
| 721 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 722 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 723 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 724 | int err = nla_parse_nested( |
| 725 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 726 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 727 | nl80211_key_default_policy); |
| 728 | if (err) |
| 729 | return err; |
| 730 | |
| 731 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 732 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 733 | } |
| 734 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 739 | { |
| 740 | int err; |
| 741 | |
| 742 | memset(k, 0, sizeof(*k)); |
| 743 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 744 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 745 | |
| 746 | if (info->attrs[NL80211_ATTR_KEY]) |
| 747 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 748 | else |
| 749 | err = nl80211_parse_key_old(info, k); |
| 750 | |
| 751 | if (err) |
| 752 | return err; |
| 753 | |
| 754 | if (k->def && k->defmgmt) |
| 755 | return -EINVAL; |
| 756 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 757 | if (k->defmgmt) { |
| 758 | if (k->def_uni || !k->def_multi) |
| 759 | return -EINVAL; |
| 760 | } |
| 761 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 762 | if (k->idx != -1) { |
| 763 | if (k->defmgmt) { |
| 764 | if (k->idx < 4 || k->idx > 5) |
| 765 | return -EINVAL; |
| 766 | } else if (k->def) { |
| 767 | if (k->idx < 0 || k->idx > 3) |
| 768 | return -EINVAL; |
| 769 | } else { |
| 770 | if (k->idx < 0 || k->idx > 5) |
| 771 | return -EINVAL; |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | return 0; |
| 776 | } |
| 777 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 778 | static struct cfg80211_cached_keys * |
| 779 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 780 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 781 | { |
| 782 | struct key_parse parse; |
| 783 | struct nlattr *key; |
| 784 | struct cfg80211_cached_keys *result; |
| 785 | int rem, err, def = 0; |
| 786 | |
| 787 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 788 | if (!result) |
| 789 | return ERR_PTR(-ENOMEM); |
| 790 | |
| 791 | result->def = -1; |
| 792 | result->defmgmt = -1; |
| 793 | |
| 794 | nla_for_each_nested(key, keys, rem) { |
| 795 | memset(&parse, 0, sizeof(parse)); |
| 796 | parse.idx = -1; |
| 797 | |
| 798 | err = nl80211_parse_key_new(key, &parse); |
| 799 | if (err) |
| 800 | goto error; |
| 801 | err = -EINVAL; |
| 802 | if (!parse.p.key) |
| 803 | goto error; |
| 804 | if (parse.idx < 0 || parse.idx > 4) |
| 805 | goto error; |
| 806 | if (parse.def) { |
| 807 | if (def) |
| 808 | goto error; |
| 809 | def = 1; |
| 810 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 811 | if (!parse.def_uni || !parse.def_multi) |
| 812 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 813 | } else if (parse.defmgmt) |
| 814 | goto error; |
| 815 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 816 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 817 | if (err) |
| 818 | goto error; |
| 819 | result->params[parse.idx].cipher = parse.p.cipher; |
| 820 | result->params[parse.idx].key_len = parse.p.key_len; |
| 821 | result->params[parse.idx].key = result->data[parse.idx]; |
| 822 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 823 | |
| 824 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 825 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 826 | if (no_ht) |
| 827 | *no_ht = true; |
| 828 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | return result; |
| 832 | error: |
| 833 | kfree(result); |
| 834 | return ERR_PTR(err); |
| 835 | } |
| 836 | |
| 837 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 838 | { |
| 839 | ASSERT_WDEV_LOCK(wdev); |
| 840 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 841 | switch (wdev->iftype) { |
| 842 | case NL80211_IFTYPE_AP: |
| 843 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 844 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 845 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 846 | break; |
| 847 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 848 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 849 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 850 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 851 | return -ENOLINK; |
| 852 | break; |
| 853 | default: |
| 854 | return -EINVAL; |
| 855 | } |
| 856 | |
| 857 | return 0; |
| 858 | } |
| 859 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 860 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 861 | struct nlattr *tb) |
| 862 | { |
| 863 | struct ieee80211_channel *chan; |
| 864 | |
| 865 | if (tb == NULL) |
| 866 | return NULL; |
| 867 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 868 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 869 | return NULL; |
| 870 | return chan; |
| 871 | } |
| 872 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 873 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 874 | { |
| 875 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 876 | int i; |
| 877 | |
| 878 | if (!nl_modes) |
| 879 | goto nla_put_failure; |
| 880 | |
| 881 | i = 0; |
| 882 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 883 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 884 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 885 | ifmodes >>= 1; |
| 886 | i++; |
| 887 | } |
| 888 | |
| 889 | nla_nest_end(msg, nl_modes); |
| 890 | return 0; |
| 891 | |
| 892 | nla_put_failure: |
| 893 | return -ENOBUFS; |
| 894 | } |
| 895 | |
| 896 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 897 | struct sk_buff *msg, |
| 898 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 899 | { |
| 900 | struct nlattr *nl_combis; |
| 901 | int i, j; |
| 902 | |
| 903 | nl_combis = nla_nest_start(msg, |
| 904 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 905 | if (!nl_combis) |
| 906 | goto nla_put_failure; |
| 907 | |
| 908 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 909 | const struct ieee80211_iface_combination *c; |
| 910 | struct nlattr *nl_combi, *nl_limits; |
| 911 | |
| 912 | c = &wiphy->iface_combinations[i]; |
| 913 | |
| 914 | nl_combi = nla_nest_start(msg, i + 1); |
| 915 | if (!nl_combi) |
| 916 | goto nla_put_failure; |
| 917 | |
| 918 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 919 | if (!nl_limits) |
| 920 | goto nla_put_failure; |
| 921 | |
| 922 | for (j = 0; j < c->n_limits; j++) { |
| 923 | struct nlattr *nl_limit; |
| 924 | |
| 925 | nl_limit = nla_nest_start(msg, j + 1); |
| 926 | if (!nl_limit) |
| 927 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 928 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 929 | c->limits[j].max)) |
| 930 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 931 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 932 | c->limits[j].types)) |
| 933 | goto nla_put_failure; |
| 934 | nla_nest_end(msg, nl_limit); |
| 935 | } |
| 936 | |
| 937 | nla_nest_end(msg, nl_limits); |
| 938 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 939 | if (c->beacon_int_infra_match && |
| 940 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 941 | goto nla_put_failure; |
| 942 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 943 | c->num_different_channels) || |
| 944 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 945 | c->max_interfaces)) |
| 946 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 947 | if (large && |
| 948 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 949 | c->radar_detect_widths)) |
| 950 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 951 | |
| 952 | nla_nest_end(msg, nl_combi); |
| 953 | } |
| 954 | |
| 955 | nla_nest_end(msg, nl_combis); |
| 956 | |
| 957 | return 0; |
| 958 | nla_put_failure: |
| 959 | return -ENOBUFS; |
| 960 | } |
| 961 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 962 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 963 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 964 | struct sk_buff *msg) |
| 965 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 966 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 967 | struct nlattr *nl_tcp; |
| 968 | |
| 969 | if (!tcp) |
| 970 | return 0; |
| 971 | |
| 972 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 973 | if (!nl_tcp) |
| 974 | return -ENOBUFS; |
| 975 | |
| 976 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 977 | tcp->data_payload_max)) |
| 978 | return -ENOBUFS; |
| 979 | |
| 980 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 981 | tcp->data_payload_max)) |
| 982 | return -ENOBUFS; |
| 983 | |
| 984 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 985 | return -ENOBUFS; |
| 986 | |
| 987 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 988 | sizeof(*tcp->tok), tcp->tok)) |
| 989 | return -ENOBUFS; |
| 990 | |
| 991 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 992 | tcp->data_interval_max)) |
| 993 | return -ENOBUFS; |
| 994 | |
| 995 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 996 | tcp->wake_payload_max)) |
| 997 | return -ENOBUFS; |
| 998 | |
| 999 | nla_nest_end(msg, nl_tcp); |
| 1000 | return 0; |
| 1001 | } |
| 1002 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1003 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1004 | struct cfg80211_registered_device *dev, |
| 1005 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1006 | { |
| 1007 | struct nlattr *nl_wowlan; |
| 1008 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1009 | if (!dev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1010 | return 0; |
| 1011 | |
| 1012 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1013 | if (!nl_wowlan) |
| 1014 | return -ENOBUFS; |
| 1015 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1016 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1017 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1018 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1019 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1020 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1021 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1022 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1023 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1024 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1025 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1026 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1027 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1028 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1029 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1030 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1031 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1032 | return -ENOBUFS; |
| 1033 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1034 | if (dev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1035 | struct nl80211_pattern_support pat = { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1036 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
| 1037 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, |
| 1038 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, |
| 1039 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1040 | }; |
| 1041 | |
| 1042 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1043 | sizeof(pat), &pat)) |
| 1044 | return -ENOBUFS; |
| 1045 | } |
| 1046 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1047 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1048 | return -ENOBUFS; |
| 1049 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1050 | nla_nest_end(msg, nl_wowlan); |
| 1051 | |
| 1052 | return 0; |
| 1053 | } |
| 1054 | #endif |
| 1055 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1056 | static int nl80211_send_coalesce(struct sk_buff *msg, |
| 1057 | struct cfg80211_registered_device *dev) |
| 1058 | { |
| 1059 | struct nl80211_coalesce_rule_support rule; |
| 1060 | |
| 1061 | if (!dev->wiphy.coalesce) |
| 1062 | return 0; |
| 1063 | |
| 1064 | rule.max_rules = dev->wiphy.coalesce->n_rules; |
| 1065 | rule.max_delay = dev->wiphy.coalesce->max_delay; |
| 1066 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; |
| 1067 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; |
| 1068 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; |
| 1069 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; |
| 1070 | |
| 1071 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1072 | return -ENOBUFS; |
| 1073 | |
| 1074 | return 0; |
| 1075 | } |
| 1076 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1077 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1078 | struct ieee80211_supported_band *sband) |
| 1079 | { |
| 1080 | struct nlattr *nl_rates, *nl_rate; |
| 1081 | struct ieee80211_rate *rate; |
| 1082 | int i; |
| 1083 | |
| 1084 | /* add HT info */ |
| 1085 | if (sband->ht_cap.ht_supported && |
| 1086 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1087 | sizeof(sband->ht_cap.mcs), |
| 1088 | &sband->ht_cap.mcs) || |
| 1089 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1090 | sband->ht_cap.cap) || |
| 1091 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1092 | sband->ht_cap.ampdu_factor) || |
| 1093 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1094 | sband->ht_cap.ampdu_density))) |
| 1095 | return -ENOBUFS; |
| 1096 | |
| 1097 | /* add VHT info */ |
| 1098 | if (sband->vht_cap.vht_supported && |
| 1099 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1100 | sizeof(sband->vht_cap.vht_mcs), |
| 1101 | &sband->vht_cap.vht_mcs) || |
| 1102 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1103 | sband->vht_cap.cap))) |
| 1104 | return -ENOBUFS; |
| 1105 | |
| 1106 | /* add bitrates */ |
| 1107 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1108 | if (!nl_rates) |
| 1109 | return -ENOBUFS; |
| 1110 | |
| 1111 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1112 | nl_rate = nla_nest_start(msg, i); |
| 1113 | if (!nl_rate) |
| 1114 | return -ENOBUFS; |
| 1115 | |
| 1116 | rate = &sband->bitrates[i]; |
| 1117 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1118 | rate->bitrate)) |
| 1119 | return -ENOBUFS; |
| 1120 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1121 | nla_put_flag(msg, |
| 1122 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1123 | return -ENOBUFS; |
| 1124 | |
| 1125 | nla_nest_end(msg, nl_rate); |
| 1126 | } |
| 1127 | |
| 1128 | nla_nest_end(msg, nl_rates); |
| 1129 | |
| 1130 | return 0; |
| 1131 | } |
| 1132 | |
| 1133 | static int |
| 1134 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1135 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1136 | { |
| 1137 | u16 stypes; |
| 1138 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1139 | enum nl80211_iftype ift; |
| 1140 | int i; |
| 1141 | |
| 1142 | if (!mgmt_stypes) |
| 1143 | return 0; |
| 1144 | |
| 1145 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1146 | if (!nl_ifs) |
| 1147 | return -ENOBUFS; |
| 1148 | |
| 1149 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1150 | nl_ftypes = nla_nest_start(msg, ift); |
| 1151 | if (!nl_ftypes) |
| 1152 | return -ENOBUFS; |
| 1153 | i = 0; |
| 1154 | stypes = mgmt_stypes[ift].tx; |
| 1155 | while (stypes) { |
| 1156 | if ((stypes & 1) && |
| 1157 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1158 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1159 | return -ENOBUFS; |
| 1160 | stypes >>= 1; |
| 1161 | i++; |
| 1162 | } |
| 1163 | nla_nest_end(msg, nl_ftypes); |
| 1164 | } |
| 1165 | |
| 1166 | nla_nest_end(msg, nl_ifs); |
| 1167 | |
| 1168 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1169 | if (!nl_ifs) |
| 1170 | return -ENOBUFS; |
| 1171 | |
| 1172 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1173 | nl_ftypes = nla_nest_start(msg, ift); |
| 1174 | if (!nl_ftypes) |
| 1175 | return -ENOBUFS; |
| 1176 | i = 0; |
| 1177 | stypes = mgmt_stypes[ift].rx; |
| 1178 | while (stypes) { |
| 1179 | if ((stypes & 1) && |
| 1180 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1181 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1182 | return -ENOBUFS; |
| 1183 | stypes >>= 1; |
| 1184 | i++; |
| 1185 | } |
| 1186 | nla_nest_end(msg, nl_ftypes); |
| 1187 | } |
| 1188 | nla_nest_end(msg, nl_ifs); |
| 1189 | |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1193 | struct nl80211_dump_wiphy_state { |
| 1194 | s64 filter_wiphy; |
| 1195 | long start; |
| 1196 | long split_start, band_start, chan_start; |
| 1197 | bool split; |
| 1198 | }; |
| 1199 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1200 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1201 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1202 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1203 | { |
| 1204 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1205 | struct nlattr *nl_bands, *nl_band; |
| 1206 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1207 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1208 | enum ieee80211_band band; |
| 1209 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1210 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1211 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1212 | dev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1213 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1214 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1215 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1216 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1217 | return -ENOBUFS; |
| 1218 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1219 | if (WARN_ON(!state)) |
| 1220 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1221 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1222 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1223 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1224 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1225 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1226 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1227 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1228 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1229 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1230 | case 0: |
| 1231 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1232 | dev->wiphy.retry_short) || |
| 1233 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1234 | dev->wiphy.retry_long) || |
| 1235 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1236 | dev->wiphy.frag_threshold) || |
| 1237 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1238 | dev->wiphy.rts_threshold) || |
| 1239 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1240 | dev->wiphy.coverage_class) || |
| 1241 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1242 | dev->wiphy.max_scan_ssids) || |
| 1243 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1244 | dev->wiphy.max_sched_scan_ssids) || |
| 1245 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1246 | dev->wiphy.max_scan_ie_len) || |
| 1247 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1248 | dev->wiphy.max_sched_scan_ie_len) || |
| 1249 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1250 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1251 | goto nla_put_failure; |
| 1252 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1253 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1254 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1255 | goto nla_put_failure; |
| 1256 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1257 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1258 | goto nla_put_failure; |
| 1259 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1260 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1261 | goto nla_put_failure; |
| 1262 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1263 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1264 | goto nla_put_failure; |
| 1265 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1266 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1267 | goto nla_put_failure; |
| 1268 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1269 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1270 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1271 | state->split_start++; |
| 1272 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1273 | break; |
| 1274 | case 1: |
| 1275 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1276 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1277 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1278 | goto nla_put_failure; |
| 1279 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1280 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1281 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1282 | goto nla_put_failure; |
| 1283 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1284 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1285 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1286 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1287 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1288 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1289 | dev->wiphy.available_antennas_tx) || |
| 1290 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1291 | dev->wiphy.available_antennas_rx)) |
| 1292 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1293 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1294 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1295 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1296 | dev->wiphy.probe_resp_offload)) |
| 1297 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1298 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1299 | if ((dev->wiphy.available_antennas_tx || |
| 1300 | dev->wiphy.available_antennas_rx) && |
| 1301 | dev->ops->get_antenna) { |
| 1302 | u32 tx_ant = 0, rx_ant = 0; |
| 1303 | int res; |
| 1304 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1305 | if (!res) { |
| 1306 | if (nla_put_u32(msg, |
| 1307 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1308 | tx_ant) || |
| 1309 | nla_put_u32(msg, |
| 1310 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1311 | rx_ant)) |
| 1312 | goto nla_put_failure; |
| 1313 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1314 | } |
| 1315 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1316 | state->split_start++; |
| 1317 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1318 | break; |
| 1319 | case 2: |
| 1320 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1321 | dev->wiphy.interface_modes)) |
| 1322 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1323 | state->split_start++; |
| 1324 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1325 | break; |
| 1326 | case 3: |
| 1327 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1328 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1329 | goto nla_put_failure; |
| 1330 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1331 | for (band = state->band_start; |
| 1332 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1333 | struct ieee80211_supported_band *sband; |
| 1334 | |
| 1335 | sband = dev->wiphy.bands[band]; |
| 1336 | |
| 1337 | if (!sband) |
| 1338 | continue; |
| 1339 | |
| 1340 | nl_band = nla_nest_start(msg, band); |
| 1341 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1342 | goto nla_put_failure; |
| 1343 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1344 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1345 | case 0: |
| 1346 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1347 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1348 | state->chan_start++; |
| 1349 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1350 | break; |
| 1351 | default: |
| 1352 | /* add frequencies */ |
| 1353 | nl_freqs = nla_nest_start( |
| 1354 | msg, NL80211_BAND_ATTR_FREQS); |
| 1355 | if (!nl_freqs) |
| 1356 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1357 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1358 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1359 | i < sband->n_channels; |
| 1360 | i++) { |
| 1361 | nl_freq = nla_nest_start(msg, i); |
| 1362 | if (!nl_freq) |
| 1363 | goto nla_put_failure; |
| 1364 | |
| 1365 | chan = &sband->channels[i]; |
| 1366 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1367 | if (nl80211_msg_put_channel( |
| 1368 | msg, chan, |
| 1369 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1370 | goto nla_put_failure; |
| 1371 | |
| 1372 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1373 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1374 | break; |
| 1375 | } |
| 1376 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1377 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1378 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1379 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1380 | nla_nest_end(msg, nl_freqs); |
| 1381 | } |
| 1382 | |
| 1383 | nla_nest_end(msg, nl_band); |
| 1384 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1385 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1386 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1387 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1388 | band--; |
| 1389 | break; |
| 1390 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1391 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1392 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1393 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1394 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1395 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1396 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1397 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1398 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1399 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1400 | if (state->band_start == 0 && state->chan_start == 0) |
| 1401 | state->split_start++; |
| 1402 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1403 | break; |
| 1404 | case 4: |
| 1405 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1406 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1407 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1408 | |
| 1409 | i = 0; |
| 1410 | #define CMD(op, n) \ |
| 1411 | do { \ |
| 1412 | if (dev->ops->op) { \ |
| 1413 | i++; \ |
| 1414 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1415 | goto nla_put_failure; \ |
| 1416 | } \ |
| 1417 | } while (0) |
| 1418 | |
| 1419 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1420 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1421 | CMD(add_key, NEW_KEY); |
| 1422 | CMD(start_ap, START_AP); |
| 1423 | CMD(add_station, NEW_STATION); |
| 1424 | CMD(add_mpath, NEW_MPATH); |
| 1425 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1426 | CMD(change_bss, SET_BSS); |
| 1427 | CMD(auth, AUTHENTICATE); |
| 1428 | CMD(assoc, ASSOCIATE); |
| 1429 | CMD(deauth, DEAUTHENTICATE); |
| 1430 | CMD(disassoc, DISASSOCIATE); |
| 1431 | CMD(join_ibss, JOIN_IBSS); |
| 1432 | CMD(join_mesh, JOIN_MESH); |
| 1433 | CMD(set_pmksa, SET_PMKSA); |
| 1434 | CMD(del_pmksa, DEL_PMKSA); |
| 1435 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1436 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1437 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1438 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1439 | CMD(mgmt_tx, FRAME); |
| 1440 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1441 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1442 | i++; |
| 1443 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1444 | goto nla_put_failure; |
| 1445 | } |
| 1446 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1447 | dev->ops->join_mesh) { |
| 1448 | i++; |
| 1449 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1450 | goto nla_put_failure; |
| 1451 | } |
| 1452 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1453 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1454 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1455 | CMD(tdls_oper, TDLS_OPER); |
| 1456 | } |
| 1457 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1458 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1459 | CMD(probe_client, PROBE_CLIENT); |
| 1460 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1461 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1462 | i++; |
| 1463 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1464 | goto nla_put_failure; |
| 1465 | } |
| 1466 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1467 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1468 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1469 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1470 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1471 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
| 1472 | CMD(channel_switch, CHANNEL_SWITCH); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1473 | } |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 1474 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1475 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1476 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1477 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1478 | #endif |
| 1479 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1480 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1481 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1482 | if (dev->ops->connect || dev->ops->auth) { |
| 1483 | i++; |
| 1484 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1485 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1486 | } |
| 1487 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1488 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1489 | i++; |
| 1490 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1491 | goto nla_put_failure; |
| 1492 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1493 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1494 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1495 | state->split_start++; |
| 1496 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1497 | break; |
| 1498 | case 5: |
| 1499 | if (dev->ops->remain_on_channel && |
| 1500 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1501 | nla_put_u32(msg, |
| 1502 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1503 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1504 | goto nla_put_failure; |
| 1505 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1506 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1507 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1508 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1509 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1510 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1511 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1512 | state->split_start++; |
| 1513 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1514 | break; |
| 1515 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1516 | #ifdef CONFIG_PM |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1517 | if (nl80211_send_wowlan(msg, dev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1518 | goto nla_put_failure; |
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 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1523 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1524 | #endif |
| 1525 | case 7: |
| 1526 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1527 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1528 | goto nla_put_failure; |
| 1529 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1530 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
| 1531 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1532 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1533 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1534 | state->split_start++; |
| 1535 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1536 | break; |
| 1537 | case 8: |
| 1538 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1539 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1540 | dev->wiphy.ap_sme_capa)) |
| 1541 | goto nla_put_failure; |
| 1542 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1543 | features = dev->wiphy.features; |
| 1544 | /* |
| 1545 | * We can only add the per-channel limit information if the |
| 1546 | * dump is split, otherwise it makes it too big. Therefore |
| 1547 | * only advertise it in that case. |
| 1548 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1549 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1550 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1551 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1552 | goto nla_put_failure; |
| 1553 | |
| 1554 | if (dev->wiphy.ht_capa_mod_mask && |
| 1555 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1556 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1557 | dev->wiphy.ht_capa_mod_mask)) |
| 1558 | goto nla_put_failure; |
| 1559 | |
| 1560 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1561 | dev->wiphy.max_acl_mac_addrs && |
| 1562 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1563 | dev->wiphy.max_acl_mac_addrs)) |
| 1564 | goto nla_put_failure; |
| 1565 | |
| 1566 | /* |
| 1567 | * Any information below this point is only available to |
| 1568 | * applications that can deal with it being split. This |
| 1569 | * helps ensure that newly added capabilities don't break |
| 1570 | * older tools by overrunning their buffers. |
| 1571 | * |
| 1572 | * We still increment split_start so that in the split |
| 1573 | * case we'll continue with more data in the next round, |
| 1574 | * but break unconditionally so unsplit data stops here. |
| 1575 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1576 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1577 | break; |
| 1578 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1579 | if (dev->wiphy.extended_capabilities && |
| 1580 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1581 | dev->wiphy.extended_capabilities_len, |
| 1582 | dev->wiphy.extended_capabilities) || |
| 1583 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1584 | dev->wiphy.extended_capabilities_len, |
| 1585 | dev->wiphy.extended_capabilities_mask))) |
| 1586 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1587 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1588 | if (dev->wiphy.vht_capa_mod_mask && |
| 1589 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1590 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1591 | dev->wiphy.vht_capa_mod_mask)) |
| 1592 | goto nla_put_failure; |
| 1593 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1594 | state->split_start++; |
| 1595 | break; |
| 1596 | case 10: |
| 1597 | if (nl80211_send_coalesce(msg, dev)) |
| 1598 | goto nla_put_failure; |
| 1599 | |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1600 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
| 1601 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1602 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1603 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1604 | |
| 1605 | if (dev->wiphy.max_ap_assoc_sta && |
| 1606 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
| 1607 | dev->wiphy.max_ap_assoc_sta)) |
| 1608 | goto nla_put_failure; |
| 1609 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1610 | state->split_start++; |
| 1611 | break; |
| 1612 | case 11: |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1613 | if (dev->wiphy.n_vendor_commands) { |
| 1614 | const struct nl80211_vendor_cmd_info *info; |
| 1615 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1616 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1617 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1618 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1619 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1620 | |
| 1621 | for (i = 0; i < dev->wiphy.n_vendor_commands; i++) { |
| 1622 | info = &dev->wiphy.vendor_commands[i].info; |
| 1623 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1624 | goto nla_put_failure; |
| 1625 | } |
| 1626 | nla_nest_end(msg, nested); |
| 1627 | } |
| 1628 | |
| 1629 | if (dev->wiphy.n_vendor_events) { |
| 1630 | const struct nl80211_vendor_cmd_info *info; |
| 1631 | struct nlattr *nested; |
| 1632 | |
| 1633 | nested = nla_nest_start(msg, |
| 1634 | NL80211_ATTR_VENDOR_EVENTS); |
| 1635 | if (!nested) |
| 1636 | goto nla_put_failure; |
| 1637 | |
| 1638 | for (i = 0; i < dev->wiphy.n_vendor_events; i++) { |
| 1639 | info = &dev->wiphy.vendor_events[i]; |
| 1640 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1641 | goto nla_put_failure; |
| 1642 | } |
| 1643 | nla_nest_end(msg, nested); |
| 1644 | } |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1645 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1646 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1647 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1648 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1649 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1650 | return genlmsg_end(msg, hdr); |
| 1651 | |
| 1652 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1653 | genlmsg_cancel(msg, hdr); |
| 1654 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1655 | } |
| 1656 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1657 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1658 | struct netlink_callback *cb, |
| 1659 | struct nl80211_dump_wiphy_state *state) |
| 1660 | { |
| 1661 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1662 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1663 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1664 | /* ignore parse errors for backward compatibility */ |
| 1665 | if (ret) |
| 1666 | return 0; |
| 1667 | |
| 1668 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1669 | if (tb[NL80211_ATTR_WIPHY]) |
| 1670 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1671 | if (tb[NL80211_ATTR_WDEV]) |
| 1672 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1673 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1674 | struct net_device *netdev; |
| 1675 | struct cfg80211_registered_device *rdev; |
| 1676 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1677 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1678 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1679 | if (!netdev) |
| 1680 | return -ENODEV; |
| 1681 | if (netdev->ieee80211_ptr) { |
| 1682 | rdev = wiphy_to_dev( |
| 1683 | netdev->ieee80211_ptr->wiphy); |
| 1684 | state->filter_wiphy = rdev->wiphy_idx; |
| 1685 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | return 0; |
| 1689 | } |
| 1690 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1691 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1692 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1693 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1694 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1695 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1696 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1697 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1698 | if (!state) { |
| 1699 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1700 | if (!state) { |
| 1701 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1702 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1703 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1704 | state->filter_wiphy = -1; |
| 1705 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1706 | if (ret) { |
| 1707 | kfree(state); |
| 1708 | rtnl_unlock(); |
| 1709 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1710 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1711 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1712 | } |
| 1713 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1714 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1715 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1716 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1717 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1718 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1719 | if (state->filter_wiphy != -1 && |
| 1720 | state->filter_wiphy != dev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1721 | continue; |
| 1722 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1723 | do { |
| 1724 | ret = nl80211_send_wiphy(dev, skb, |
| 1725 | NETLINK_CB(cb->skb).portid, |
| 1726 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1727 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1728 | if (ret < 0) { |
| 1729 | /* |
| 1730 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1731 | * or EMSGSIZE returned), this SKB is still |
| 1732 | * empty (so it's not too big because another |
| 1733 | * wiphy dataset is already in the skb) and |
| 1734 | * we've not tried to adjust the dump allocation |
| 1735 | * yet ... then adjust the alloc size to be |
| 1736 | * bigger, and return 1 but with the empty skb. |
| 1737 | * This results in an empty message being RX'ed |
| 1738 | * in userspace, but that is ignored. |
| 1739 | * |
| 1740 | * We can then retry with the larger buffer. |
| 1741 | */ |
| 1742 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1743 | !skb->len && |
| 1744 | cb->min_dump_alloc < 4096) { |
| 1745 | cb->min_dump_alloc = 4096; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1746 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1747 | return 1; |
| 1748 | } |
| 1749 | idx--; |
| 1750 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1751 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1752 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1753 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1754 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1755 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1756 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1757 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1758 | |
| 1759 | return skb->len; |
| 1760 | } |
| 1761 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1762 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1763 | { |
| 1764 | kfree((void *)cb->args[0]); |
| 1765 | return 0; |
| 1766 | } |
| 1767 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1768 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1769 | { |
| 1770 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1771 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1772 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1773 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1774 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1775 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1776 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1777 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1778 | 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] | 1779 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1780 | nlmsg_free(msg); |
| 1781 | return -ENOBUFS; |
| 1782 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1783 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1784 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1785 | } |
| 1786 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1787 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1788 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1789 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1790 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1791 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1792 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1793 | }; |
| 1794 | |
| 1795 | static int parse_txq_params(struct nlattr *tb[], |
| 1796 | struct ieee80211_txq_params *txq_params) |
| 1797 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1798 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1799 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1800 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1801 | return -EINVAL; |
| 1802 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1803 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1804 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1805 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1806 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1807 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1808 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1809 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1810 | return -EINVAL; |
| 1811 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1812 | return 0; |
| 1813 | } |
| 1814 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1815 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1816 | { |
| 1817 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1818 | * You can only set the channel explicitly for WDS interfaces, |
| 1819 | * all others have their channel managed via their respective |
| 1820 | * "establish a connection" command (connect, join, ...) |
| 1821 | * |
| 1822 | * For AP/GO and mesh mode, the channel can be set with the |
| 1823 | * channel userspace API, but is only stored and passed to the |
| 1824 | * low-level driver when the AP starts or the mesh is joined. |
| 1825 | * This is for backward compatibility, userspace can also give |
| 1826 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1827 | * |
| 1828 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1829 | * whatever else is going on, so they have their own special |
| 1830 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1831 | */ |
| 1832 | return !wdev || |
| 1833 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1834 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1835 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1836 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1837 | } |
| 1838 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1839 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1840 | struct genl_info *info, |
| 1841 | struct cfg80211_chan_def *chandef) |
| 1842 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1843 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1844 | |
| 1845 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1846 | return -EINVAL; |
| 1847 | |
| 1848 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1849 | |
| 1850 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1851 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1852 | chandef->center_freq1 = control_freq; |
| 1853 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1854 | |
| 1855 | /* Primary channel not allowed */ |
| 1856 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1857 | return -EINVAL; |
| 1858 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1859 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1860 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1861 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1862 | chantype = nla_get_u32( |
| 1863 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1864 | |
| 1865 | switch (chantype) { |
| 1866 | case NL80211_CHAN_NO_HT: |
| 1867 | case NL80211_CHAN_HT20: |
| 1868 | case NL80211_CHAN_HT40PLUS: |
| 1869 | case NL80211_CHAN_HT40MINUS: |
| 1870 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1871 | chantype); |
| 1872 | break; |
| 1873 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1874 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1875 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1876 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1877 | chandef->width = |
| 1878 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1879 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1880 | chandef->center_freq1 = |
| 1881 | nla_get_u32( |
| 1882 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1883 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1884 | chandef->center_freq2 = |
| 1885 | nla_get_u32( |
| 1886 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1887 | } |
| 1888 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1889 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1890 | return -EINVAL; |
| 1891 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1892 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1893 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1894 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1895 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1896 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1897 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1898 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1899 | return -EINVAL; |
| 1900 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1901 | return 0; |
| 1902 | } |
| 1903 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1904 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1905 | struct wireless_dev *wdev, |
| 1906 | struct genl_info *info) |
| 1907 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1908 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1909 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1910 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1911 | |
| 1912 | if (wdev) |
| 1913 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1914 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1915 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1916 | return -EOPNOTSUPP; |
| 1917 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1918 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1919 | if (result) |
| 1920 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1921 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1922 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1923 | case NL80211_IFTYPE_AP: |
| 1924 | case NL80211_IFTYPE_P2P_GO: |
| 1925 | if (wdev->beacon_interval) { |
| 1926 | result = -EBUSY; |
| 1927 | break; |
| 1928 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1929 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1930 | result = -EINVAL; |
| 1931 | break; |
| 1932 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1933 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1934 | result = 0; |
| 1935 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1936 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1937 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1938 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1939 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1940 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1941 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1942 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1943 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1944 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1945 | |
| 1946 | return result; |
| 1947 | } |
| 1948 | |
| 1949 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1950 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1951 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1952 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1953 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1954 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1955 | } |
| 1956 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1957 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1958 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1959 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1960 | struct net_device *dev = info->user_ptr[1]; |
| 1961 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1962 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1963 | |
| 1964 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1965 | return -EINVAL; |
| 1966 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1967 | if (netif_running(dev)) |
| 1968 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1969 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1970 | if (!rdev->ops->set_wds_peer) |
| 1971 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1972 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1973 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1974 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1975 | |
| 1976 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1977 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1981 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1982 | { |
| 1983 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1984 | struct net_device *netdev = NULL; |
| 1985 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1986 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1987 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1988 | u32 changed; |
| 1989 | u8 retry_short = 0, retry_long = 0; |
| 1990 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1991 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1992 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1993 | ASSERT_RTNL(); |
| 1994 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1995 | /* |
| 1996 | * Try to find the wiphy and netdev. Normally this |
| 1997 | * function shouldn't need the netdev, but this is |
| 1998 | * done for backward compatibility -- previously |
| 1999 | * setting the channel was done per wiphy, but now |
| 2000 | * it is per netdev. Previous userland like hostapd |
| 2001 | * also passed a netdev to set_wiphy, so that it is |
| 2002 | * possible to let that go to the right netdev! |
| 2003 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2004 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2005 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2006 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2007 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2008 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2009 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2010 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2011 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2012 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2013 | } |
| 2014 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2015 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2016 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2017 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2018 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2019 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2020 | wdev = NULL; |
| 2021 | netdev = NULL; |
| 2022 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2023 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2024 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2025 | |
| 2026 | /* |
| 2027 | * end workaround code, by now the rdev is available |
| 2028 | * and locked, and wdev may or may not be NULL. |
| 2029 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2030 | |
| 2031 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2032 | result = cfg80211_dev_rename( |
| 2033 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2034 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2035 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2036 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2037 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2038 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2039 | struct ieee80211_txq_params txq_params; |
| 2040 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2041 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2042 | if (!rdev->ops->set_txq_params) |
| 2043 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2044 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2045 | if (!netdev) |
| 2046 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2047 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2048 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2049 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2050 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2051 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2052 | if (!netif_running(netdev)) |
| 2053 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2054 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2055 | nla_for_each_nested(nl_txq_params, |
| 2056 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2057 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2058 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2059 | nla_data(nl_txq_params), |
| 2060 | nla_len(nl_txq_params), |
| 2061 | txq_params_policy); |
| 2062 | if (result) |
| 2063 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2064 | result = parse_txq_params(tb, &txq_params); |
| 2065 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2066 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2067 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2068 | result = rdev_set_txq_params(rdev, netdev, |
| 2069 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2070 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2071 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2072 | } |
| 2073 | } |
| 2074 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2075 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2076 | result = __nl80211_set_channel(rdev, |
| 2077 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 2078 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2079 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2080 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2081 | } |
| 2082 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2083 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2084 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2085 | enum nl80211_tx_power_setting type; |
| 2086 | int idx, mbm = 0; |
| 2087 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2088 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2089 | txp_wdev = NULL; |
| 2090 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2091 | if (!rdev->ops->set_tx_power) |
| 2092 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2093 | |
| 2094 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2095 | type = nla_get_u32(info->attrs[idx]); |
| 2096 | |
| 2097 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2098 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2099 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2100 | |
| 2101 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2102 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2103 | mbm = nla_get_u32(info->attrs[idx]); |
| 2104 | } |
| 2105 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2106 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2107 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2108 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2109 | } |
| 2110 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2111 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2112 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2113 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2114 | if ((!rdev->wiphy.available_antennas_tx && |
| 2115 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2116 | !rdev->ops->set_antenna) |
| 2117 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2118 | |
| 2119 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2120 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2121 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2122 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2123 | * available antenna masks, except for the "all" mask */ |
| 2124 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2125 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2126 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2127 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2128 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2129 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2130 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2131 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2132 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2133 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2134 | } |
| 2135 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2136 | changed = 0; |
| 2137 | |
| 2138 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2139 | retry_short = nla_get_u8( |
| 2140 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2141 | if (retry_short == 0) |
| 2142 | return -EINVAL; |
| 2143 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2144 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2145 | } |
| 2146 | |
| 2147 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2148 | retry_long = nla_get_u8( |
| 2149 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2150 | if (retry_long == 0) |
| 2151 | return -EINVAL; |
| 2152 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2153 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2154 | } |
| 2155 | |
| 2156 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2157 | frag_threshold = nla_get_u32( |
| 2158 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2159 | if (frag_threshold < 256) |
| 2160 | return -EINVAL; |
| 2161 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2162 | if (frag_threshold != (u32) -1) { |
| 2163 | /* |
| 2164 | * Fragments (apart from the last one) are required to |
| 2165 | * have even length. Make the fragmentation code |
| 2166 | * simpler by stripping LSB should someone try to use |
| 2167 | * odd threshold value. |
| 2168 | */ |
| 2169 | frag_threshold &= ~0x1; |
| 2170 | } |
| 2171 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2172 | } |
| 2173 | |
| 2174 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2175 | rts_threshold = nla_get_u32( |
| 2176 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2177 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2178 | } |
| 2179 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2180 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2181 | coverage_class = nla_get_u8( |
| 2182 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2183 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2184 | } |
| 2185 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2186 | if (changed) { |
| 2187 | u8 old_retry_short, old_retry_long; |
| 2188 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2189 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2190 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2191 | if (!rdev->ops->set_wiphy_params) |
| 2192 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2193 | |
| 2194 | old_retry_short = rdev->wiphy.retry_short; |
| 2195 | old_retry_long = rdev->wiphy.retry_long; |
| 2196 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2197 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2198 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2199 | |
| 2200 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2201 | rdev->wiphy.retry_short = retry_short; |
| 2202 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2203 | rdev->wiphy.retry_long = retry_long; |
| 2204 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2205 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2206 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2207 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2208 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2209 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2210 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2211 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2212 | if (result) { |
| 2213 | rdev->wiphy.retry_short = old_retry_short; |
| 2214 | rdev->wiphy.retry_long = old_retry_long; |
| 2215 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2216 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2217 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2218 | } |
| 2219 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2220 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2221 | } |
| 2222 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2223 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2224 | { |
| 2225 | return (u64)wdev->identifier | |
| 2226 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2227 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2228 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2229 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2230 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2231 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2232 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2233 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2234 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2235 | chandef->chan->center_freq)) |
| 2236 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2237 | switch (chandef->width) { |
| 2238 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2239 | case NL80211_CHAN_WIDTH_20: |
| 2240 | case NL80211_CHAN_WIDTH_40: |
| 2241 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2242 | cfg80211_get_chandef_type(chandef))) |
| 2243 | return -ENOBUFS; |
| 2244 | break; |
| 2245 | default: |
| 2246 | break; |
| 2247 | } |
| 2248 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2249 | return -ENOBUFS; |
| 2250 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2251 | return -ENOBUFS; |
| 2252 | if (chandef->center_freq2 && |
| 2253 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2254 | return -ENOBUFS; |
| 2255 | return 0; |
| 2256 | } |
| 2257 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2258 | 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] | 2259 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2260 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2261 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2262 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2263 | void *hdr; |
| 2264 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2265 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2266 | if (!hdr) |
| 2267 | return -1; |
| 2268 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2269 | if (dev && |
| 2270 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2271 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2272 | goto nla_put_failure; |
| 2273 | |
| 2274 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2275 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2276 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2277 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2278 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2279 | rdev->devlist_generation ^ |
| 2280 | (cfg80211_rdev_list_generation << 2))) |
| 2281 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2282 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2283 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2284 | int ret; |
| 2285 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2286 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2287 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2288 | if (ret == 0) { |
| 2289 | if (nl80211_send_chandef(msg, &chandef)) |
| 2290 | goto nla_put_failure; |
| 2291 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2292 | } |
| 2293 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2294 | if (wdev->ssid_len) { |
| 2295 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2296 | goto nla_put_failure; |
| 2297 | } |
| 2298 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2299 | return genlmsg_end(msg, hdr); |
| 2300 | |
| 2301 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2302 | genlmsg_cancel(msg, hdr); |
| 2303 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2307 | { |
| 2308 | int wp_idx = 0; |
| 2309 | int if_idx = 0; |
| 2310 | int wp_start = cb->args[0]; |
| 2311 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2312 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2313 | struct wireless_dev *wdev; |
| 2314 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2315 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2316 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2317 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2318 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2319 | if (wp_idx < wp_start) { |
| 2320 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2321 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2322 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2323 | if_idx = 0; |
| 2324 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2325 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2326 | if (if_idx < if_start) { |
| 2327 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2328 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2329 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2330 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2331 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2332 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2333 | goto out; |
| 2334 | } |
| 2335 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2336 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2337 | |
| 2338 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2339 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2340 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2341 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2342 | |
| 2343 | cb->args[0] = wp_idx; |
| 2344 | cb->args[1] = if_idx; |
| 2345 | |
| 2346 | return skb->len; |
| 2347 | } |
| 2348 | |
| 2349 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2350 | { |
| 2351 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2352 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2353 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2354 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2355 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2356 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2357 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2358 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2359 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2360 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2361 | nlmsg_free(msg); |
| 2362 | return -ENOBUFS; |
| 2363 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2364 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2365 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2366 | } |
| 2367 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2368 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2369 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2370 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2371 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2372 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2373 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2374 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2375 | }; |
| 2376 | |
| 2377 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2378 | { |
| 2379 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2380 | int flag; |
| 2381 | |
| 2382 | *mntrflags = 0; |
| 2383 | |
| 2384 | if (!nla) |
| 2385 | return -EINVAL; |
| 2386 | |
| 2387 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2388 | nla, mntr_flags_policy)) |
| 2389 | return -EINVAL; |
| 2390 | |
| 2391 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2392 | if (flags[flag]) |
| 2393 | *mntrflags |= (1<<flag); |
| 2394 | |
| 2395 | return 0; |
| 2396 | } |
| 2397 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2398 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2399 | struct net_device *netdev, u8 use_4addr, |
| 2400 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2401 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2402 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2403 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2404 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2405 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2406 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2407 | |
| 2408 | switch (iftype) { |
| 2409 | case NL80211_IFTYPE_AP_VLAN: |
| 2410 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2411 | return 0; |
| 2412 | break; |
| 2413 | case NL80211_IFTYPE_STATION: |
| 2414 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2415 | return 0; |
| 2416 | break; |
| 2417 | default: |
| 2418 | break; |
| 2419 | } |
| 2420 | |
| 2421 | return -EOPNOTSUPP; |
| 2422 | } |
| 2423 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2424 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2425 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2426 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2427 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2428 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2429 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2430 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2431 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2432 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2433 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2434 | memset(¶ms, 0, sizeof(params)); |
| 2435 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2436 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2437 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2438 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2439 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2440 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2441 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2442 | if (ntype > NL80211_IFTYPE_MAX) |
| 2443 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2444 | } |
| 2445 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2446 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2447 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2448 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2449 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2450 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2451 | if (netif_running(dev)) |
| 2452 | return -EBUSY; |
| 2453 | |
| 2454 | wdev_lock(wdev); |
| 2455 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2456 | IEEE80211_MAX_MESH_ID_LEN); |
| 2457 | wdev->mesh_id_up_len = |
| 2458 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2459 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2460 | wdev->mesh_id_up_len); |
| 2461 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2462 | } |
| 2463 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2464 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2465 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2466 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2467 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2468 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2469 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2470 | } else { |
| 2471 | params.use_4addr = -1; |
| 2472 | } |
| 2473 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2474 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2475 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2476 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2477 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2478 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2479 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2480 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2481 | |
| 2482 | flags = &_flags; |
| 2483 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2484 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2485 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2486 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2487 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2488 | return -EOPNOTSUPP; |
| 2489 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2490 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2491 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2492 | else |
| 2493 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2494 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2495 | if (!err && params.use_4addr != -1) |
| 2496 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2497 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2498 | return err; |
| 2499 | } |
| 2500 | |
| 2501 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2502 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2503 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2504 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2505 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2506 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2507 | int err; |
| 2508 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2509 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2510 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2511 | memset(¶ms, 0, sizeof(params)); |
| 2512 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2513 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2514 | return -EINVAL; |
| 2515 | |
| 2516 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2517 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2518 | if (type > NL80211_IFTYPE_MAX) |
| 2519 | return -EINVAL; |
| 2520 | } |
| 2521 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2522 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2523 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2524 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2525 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2526 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2527 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2528 | ETH_ALEN); |
| 2529 | if (!is_valid_ether_addr(params.macaddr)) |
| 2530 | return -EADDRNOTAVAIL; |
| 2531 | } |
| 2532 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2533 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2534 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2535 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2536 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2537 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2538 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2539 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2540 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2541 | if (!msg) |
| 2542 | return -ENOMEM; |
| 2543 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2544 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2545 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2546 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2547 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2548 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2549 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2550 | return -EOPNOTSUPP; |
| 2551 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2552 | wdev = rdev_add_virtual_intf(rdev, |
| 2553 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2554 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2555 | if (IS_ERR(wdev)) { |
| 2556 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2557 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2558 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2559 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2560 | switch (type) { |
| 2561 | case NL80211_IFTYPE_MESH_POINT: |
| 2562 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2563 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2564 | wdev_lock(wdev); |
| 2565 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2566 | IEEE80211_MAX_MESH_ID_LEN); |
| 2567 | wdev->mesh_id_up_len = |
| 2568 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2569 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2570 | wdev->mesh_id_up_len); |
| 2571 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2572 | break; |
| 2573 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2574 | /* |
| 2575 | * P2P Device doesn't have a netdev, so doesn't go |
| 2576 | * through the netdev notifier and must be added here |
| 2577 | */ |
| 2578 | mutex_init(&wdev->mtx); |
| 2579 | INIT_LIST_HEAD(&wdev->event_list); |
| 2580 | spin_lock_init(&wdev->event_lock); |
| 2581 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2582 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2583 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2584 | wdev->identifier = ++rdev->wdev_id; |
| 2585 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2586 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2587 | break; |
| 2588 | default: |
| 2589 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2590 | } |
| 2591 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2592 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2593 | rdev, wdev) < 0) { |
| 2594 | nlmsg_free(msg); |
| 2595 | return -ENOBUFS; |
| 2596 | } |
| 2597 | |
| 2598 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2602 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2603 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2604 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2605 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2606 | if (!rdev->ops->del_virtual_intf) |
| 2607 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2608 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2609 | /* |
| 2610 | * If we remove a wireless device without a netdev then clear |
| 2611 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2612 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2613 | * since the wdev has been freed, unlike with a netdev where |
| 2614 | * we need the dev_put() for the netdev to really be freed. |
| 2615 | */ |
| 2616 | if (!wdev->netdev) |
| 2617 | info->user_ptr[1] = NULL; |
| 2618 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2619 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2620 | } |
| 2621 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2622 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2623 | { |
| 2624 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2625 | struct net_device *dev = info->user_ptr[1]; |
| 2626 | u16 noack_map; |
| 2627 | |
| 2628 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2629 | return -EINVAL; |
| 2630 | |
| 2631 | if (!rdev->ops->set_noack_map) |
| 2632 | return -EOPNOTSUPP; |
| 2633 | |
| 2634 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2635 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2636 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2637 | } |
| 2638 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2639 | struct get_key_cookie { |
| 2640 | struct sk_buff *msg; |
| 2641 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2642 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2643 | }; |
| 2644 | |
| 2645 | static void get_key_callback(void *c, struct key_params *params) |
| 2646 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2647 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2648 | struct get_key_cookie *cookie = c; |
| 2649 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2650 | if ((params->key && |
| 2651 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2652 | params->key_len, params->key)) || |
| 2653 | (params->seq && |
| 2654 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2655 | params->seq_len, params->seq)) || |
| 2656 | (params->cipher && |
| 2657 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2658 | params->cipher))) |
| 2659 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2660 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2661 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2662 | if (!key) |
| 2663 | goto nla_put_failure; |
| 2664 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2665 | if ((params->key && |
| 2666 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2667 | params->key_len, params->key)) || |
| 2668 | (params->seq && |
| 2669 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2670 | params->seq_len, params->seq)) || |
| 2671 | (params->cipher && |
| 2672 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2673 | params->cipher))) |
| 2674 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2675 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2676 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2677 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2678 | |
| 2679 | nla_nest_end(cookie->msg, key); |
| 2680 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2681 | return; |
| 2682 | nla_put_failure: |
| 2683 | cookie->error = 1; |
| 2684 | } |
| 2685 | |
| 2686 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2687 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2689 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2690 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2691 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2692 | const u8 *mac_addr = NULL; |
| 2693 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2694 | struct get_key_cookie cookie = { |
| 2695 | .error = 0, |
| 2696 | }; |
| 2697 | void *hdr; |
| 2698 | struct sk_buff *msg; |
| 2699 | |
| 2700 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2701 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2702 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2703 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2704 | return -EINVAL; |
| 2705 | |
| 2706 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2707 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2708 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2709 | pairwise = !!mac_addr; |
| 2710 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2711 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2712 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2713 | return -EINVAL; |
| 2714 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2715 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2716 | return -EINVAL; |
| 2717 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2718 | } |
| 2719 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2720 | if (!rdev->ops->get_key) |
| 2721 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2722 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2723 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2724 | if (!msg) |
| 2725 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2726 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2727 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2728 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2729 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2730 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2731 | |
| 2732 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2733 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2734 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2735 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2736 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2737 | goto nla_put_failure; |
| 2738 | if (mac_addr && |
| 2739 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2740 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2741 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2742 | if (pairwise && mac_addr && |
| 2743 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2744 | return -ENOENT; |
| 2745 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2746 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2747 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2748 | |
| 2749 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2750 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2751 | |
| 2752 | if (cookie.error) |
| 2753 | goto nla_put_failure; |
| 2754 | |
| 2755 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2756 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2757 | |
| 2758 | nla_put_failure: |
| 2759 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2760 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2761 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2762 | return err; |
| 2763 | } |
| 2764 | |
| 2765 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2766 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2767 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2768 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2769 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2770 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2771 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2772 | err = nl80211_parse_key(info, &key); |
| 2773 | if (err) |
| 2774 | return err; |
| 2775 | |
| 2776 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2777 | return -EINVAL; |
| 2778 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2779 | /* only support setting default key */ |
| 2780 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2781 | return -EINVAL; |
| 2782 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2783 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2784 | |
| 2785 | if (key.def) { |
| 2786 | if (!rdev->ops->set_default_key) { |
| 2787 | err = -EOPNOTSUPP; |
| 2788 | goto out; |
| 2789 | } |
| 2790 | |
| 2791 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2792 | if (err) |
| 2793 | goto out; |
| 2794 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2795 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2796 | key.def_uni, key.def_multi); |
| 2797 | |
| 2798 | if (err) |
| 2799 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2800 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2801 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2802 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2803 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2804 | } else { |
| 2805 | if (key.def_uni || !key.def_multi) { |
| 2806 | err = -EINVAL; |
| 2807 | goto out; |
| 2808 | } |
| 2809 | |
| 2810 | if (!rdev->ops->set_default_mgmt_key) { |
| 2811 | err = -EOPNOTSUPP; |
| 2812 | goto out; |
| 2813 | } |
| 2814 | |
| 2815 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2816 | if (err) |
| 2817 | goto out; |
| 2818 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2819 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2820 | if (err) |
| 2821 | goto out; |
| 2822 | |
| 2823 | #ifdef CONFIG_CFG80211_WEXT |
| 2824 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2825 | #endif |
| 2826 | } |
| 2827 | |
| 2828 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2829 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2830 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2831 | return err; |
| 2832 | } |
| 2833 | |
| 2834 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2835 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2836 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2837 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2838 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2839 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2840 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2841 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2842 | err = nl80211_parse_key(info, &key); |
| 2843 | if (err) |
| 2844 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2845 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2846 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2847 | return -EINVAL; |
| 2848 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2849 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2850 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2851 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2852 | if (key.type == -1) { |
| 2853 | if (mac_addr) |
| 2854 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2855 | else |
| 2856 | key.type = NL80211_KEYTYPE_GROUP; |
| 2857 | } |
| 2858 | |
| 2859 | /* for now */ |
| 2860 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2861 | key.type != NL80211_KEYTYPE_GROUP) |
| 2862 | return -EINVAL; |
| 2863 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2864 | if (!rdev->ops->add_key) |
| 2865 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2866 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2867 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2868 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2869 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2870 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2871 | |
| 2872 | wdev_lock(dev->ieee80211_ptr); |
| 2873 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2874 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2875 | err = rdev_add_key(rdev, dev, key.idx, |
| 2876 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2877 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2878 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2879 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2880 | return err; |
| 2881 | } |
| 2882 | |
| 2883 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2884 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2885 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2886 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2887 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2888 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2889 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2890 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2891 | err = nl80211_parse_key(info, &key); |
| 2892 | if (err) |
| 2893 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2894 | |
| 2895 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2896 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2897 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2898 | if (key.type == -1) { |
| 2899 | if (mac_addr) |
| 2900 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2901 | else |
| 2902 | key.type = NL80211_KEYTYPE_GROUP; |
| 2903 | } |
| 2904 | |
| 2905 | /* for now */ |
| 2906 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2907 | key.type != NL80211_KEYTYPE_GROUP) |
| 2908 | return -EINVAL; |
| 2909 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2910 | if (!rdev->ops->del_key) |
| 2911 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2912 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2913 | wdev_lock(dev->ieee80211_ptr); |
| 2914 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2915 | |
| 2916 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2917 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2918 | err = -ENOENT; |
| 2919 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2920 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2921 | err = rdev_del_key(rdev, dev, key.idx, |
| 2922 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2923 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2924 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2925 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2926 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2927 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2928 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2929 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2930 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2931 | } |
| 2932 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2933 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2934 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2935 | return err; |
| 2936 | } |
| 2937 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2938 | /* This function returns an error or the number of nested attributes */ |
| 2939 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2940 | { |
| 2941 | struct nlattr *attr; |
| 2942 | int n_entries = 0, tmp; |
| 2943 | |
| 2944 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2945 | if (nla_len(attr) != ETH_ALEN) |
| 2946 | return -EINVAL; |
| 2947 | |
| 2948 | n_entries++; |
| 2949 | } |
| 2950 | |
| 2951 | return n_entries; |
| 2952 | } |
| 2953 | |
| 2954 | /* |
| 2955 | * This function parses ACL information and allocates memory for ACL data. |
| 2956 | * On successful return, the calling function is responsible to free the |
| 2957 | * ACL buffer returned by this function. |
| 2958 | */ |
| 2959 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2960 | struct genl_info *info) |
| 2961 | { |
| 2962 | enum nl80211_acl_policy acl_policy; |
| 2963 | struct nlattr *attr; |
| 2964 | struct cfg80211_acl_data *acl; |
| 2965 | int i = 0, n_entries, tmp; |
| 2966 | |
| 2967 | if (!wiphy->max_acl_mac_addrs) |
| 2968 | return ERR_PTR(-EOPNOTSUPP); |
| 2969 | |
| 2970 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2971 | return ERR_PTR(-EINVAL); |
| 2972 | |
| 2973 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2974 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2975 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2976 | return ERR_PTR(-EINVAL); |
| 2977 | |
| 2978 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2979 | return ERR_PTR(-EINVAL); |
| 2980 | |
| 2981 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2982 | if (n_entries < 0) |
| 2983 | return ERR_PTR(n_entries); |
| 2984 | |
| 2985 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2986 | return ERR_PTR(-ENOTSUPP); |
| 2987 | |
| 2988 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2989 | GFP_KERNEL); |
| 2990 | if (!acl) |
| 2991 | return ERR_PTR(-ENOMEM); |
| 2992 | |
| 2993 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2994 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2995 | i++; |
| 2996 | } |
| 2997 | |
| 2998 | acl->n_acl_entries = n_entries; |
| 2999 | acl->acl_policy = acl_policy; |
| 3000 | |
| 3001 | return acl; |
| 3002 | } |
| 3003 | |
| 3004 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3005 | { |
| 3006 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3007 | struct net_device *dev = info->user_ptr[1]; |
| 3008 | struct cfg80211_acl_data *acl; |
| 3009 | int err; |
| 3010 | |
| 3011 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3012 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3013 | return -EOPNOTSUPP; |
| 3014 | |
| 3015 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3016 | return -EINVAL; |
| 3017 | |
| 3018 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3019 | if (IS_ERR(acl)) |
| 3020 | return PTR_ERR(acl); |
| 3021 | |
| 3022 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3023 | |
| 3024 | kfree(acl); |
| 3025 | |
| 3026 | return err; |
| 3027 | } |
| 3028 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3029 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3030 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3031 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3032 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3033 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3034 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3035 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3036 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3037 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3038 | return -EINVAL; |
| 3039 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3040 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3041 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3042 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3043 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3044 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3045 | if (!bcn->head_len) |
| 3046 | return -EINVAL; |
| 3047 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3048 | } |
| 3049 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3050 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3051 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3052 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3053 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3054 | } |
| 3055 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3056 | if (!haveinfo) |
| 3057 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3058 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3059 | if (attrs[NL80211_ATTR_IE]) { |
| 3060 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3061 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3062 | } |
| 3063 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3064 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3065 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3066 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3067 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3068 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3069 | } |
| 3070 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3071 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3072 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3073 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3074 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3075 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3076 | } |
| 3077 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3078 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3079 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3080 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3081 | } |
| 3082 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3083 | return 0; |
| 3084 | } |
| 3085 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3086 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3087 | struct cfg80211_ap_settings *params) |
| 3088 | { |
| 3089 | struct wireless_dev *wdev; |
| 3090 | bool ret = false; |
| 3091 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3092 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3093 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3094 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3095 | continue; |
| 3096 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3097 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3098 | continue; |
| 3099 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3100 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3101 | ret = true; |
| 3102 | break; |
| 3103 | } |
| 3104 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3105 | return ret; |
| 3106 | } |
| 3107 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3108 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3109 | enum nl80211_auth_type auth_type, |
| 3110 | enum nl80211_commands cmd) |
| 3111 | { |
| 3112 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3113 | return false; |
| 3114 | |
| 3115 | switch (cmd) { |
| 3116 | case NL80211_CMD_AUTHENTICATE: |
| 3117 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3118 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3119 | return false; |
| 3120 | return true; |
| 3121 | case NL80211_CMD_CONNECT: |
| 3122 | case NL80211_CMD_START_AP: |
| 3123 | /* SAE not supported yet */ |
| 3124 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3125 | return false; |
| 3126 | return true; |
| 3127 | default: |
| 3128 | return false; |
| 3129 | } |
| 3130 | } |
| 3131 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3132 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3133 | { |
| 3134 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3135 | struct net_device *dev = info->user_ptr[1]; |
| 3136 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3137 | struct cfg80211_ap_settings params; |
| 3138 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3139 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3140 | |
| 3141 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3142 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3143 | return -EOPNOTSUPP; |
| 3144 | |
| 3145 | if (!rdev->ops->start_ap) |
| 3146 | return -EOPNOTSUPP; |
| 3147 | |
| 3148 | if (wdev->beacon_interval) |
| 3149 | return -EALREADY; |
| 3150 | |
| 3151 | memset(¶ms, 0, sizeof(params)); |
| 3152 | |
| 3153 | /* these are required for START_AP */ |
| 3154 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3155 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3156 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3157 | return -EINVAL; |
| 3158 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3159 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3160 | if (err) |
| 3161 | return err; |
| 3162 | |
| 3163 | params.beacon_interval = |
| 3164 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3165 | params.dtim_period = |
| 3166 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3167 | |
| 3168 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3169 | if (err) |
| 3170 | return err; |
| 3171 | |
| 3172 | /* |
| 3173 | * In theory, some of these attributes should be required here |
| 3174 | * but since they were not used when the command was originally |
| 3175 | * added, keep them optional for old user space programs to let |
| 3176 | * them continue to work with drivers that do not need the |
| 3177 | * additional information -- drivers must check! |
| 3178 | */ |
| 3179 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3180 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3181 | params.ssid_len = |
| 3182 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3183 | if (params.ssid_len == 0 || |
| 3184 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3185 | return -EINVAL; |
| 3186 | } |
| 3187 | |
| 3188 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3189 | params.hidden_ssid = nla_get_u32( |
| 3190 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3191 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3192 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3193 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3194 | return -EINVAL; |
| 3195 | } |
| 3196 | |
| 3197 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3198 | |
| 3199 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3200 | params.auth_type = nla_get_u32( |
| 3201 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3202 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3203 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3204 | return -EINVAL; |
| 3205 | } else |
| 3206 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3207 | |
| 3208 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3209 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3210 | if (err) |
| 3211 | return err; |
| 3212 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3213 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3214 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3215 | return -EOPNOTSUPP; |
| 3216 | params.inactivity_timeout = nla_get_u16( |
| 3217 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3218 | } |
| 3219 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3220 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3221 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3222 | return -EINVAL; |
| 3223 | params.p2p_ctwindow = |
| 3224 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3225 | if (params.p2p_ctwindow > 127) |
| 3226 | return -EINVAL; |
| 3227 | if (params.p2p_ctwindow != 0 && |
| 3228 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3229 | return -EINVAL; |
| 3230 | } |
| 3231 | |
| 3232 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3233 | u8 tmp; |
| 3234 | |
| 3235 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3236 | return -EINVAL; |
| 3237 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3238 | if (tmp > 1) |
| 3239 | return -EINVAL; |
| 3240 | params.p2p_opp_ps = tmp; |
| 3241 | if (params.p2p_opp_ps != 0 && |
| 3242 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3243 | return -EINVAL; |
| 3244 | } |
| 3245 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3246 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3247 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3248 | if (err) |
| 3249 | return err; |
| 3250 | } else if (wdev->preset_chandef.chan) { |
| 3251 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3252 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3253 | return -EINVAL; |
| 3254 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3255 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3256 | return -EINVAL; |
| 3257 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3258 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3259 | if (err < 0) |
| 3260 | return err; |
| 3261 | if (err) { |
| 3262 | radar_detect_width = BIT(params.chandef.width); |
| 3263 | params.radar_required = true; |
| 3264 | } |
| 3265 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3266 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3267 | params.chandef.chan, |
| 3268 | CHAN_MODE_SHARED, |
| 3269 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3270 | if (err) |
| 3271 | return err; |
| 3272 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3273 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3274 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3275 | if (IS_ERR(params.acl)) |
| 3276 | return PTR_ERR(params.acl); |
| 3277 | } |
| 3278 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3279 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3280 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3281 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3282 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3283 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3284 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3285 | wdev->ssid_len = params.ssid_len; |
| 3286 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3287 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3288 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3289 | |
| 3290 | kfree(params.acl); |
| 3291 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3292 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3293 | } |
| 3294 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3295 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3296 | { |
| 3297 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3298 | struct net_device *dev = info->user_ptr[1]; |
| 3299 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3300 | struct cfg80211_beacon_data params; |
| 3301 | int err; |
| 3302 | |
| 3303 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3304 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3305 | return -EOPNOTSUPP; |
| 3306 | |
| 3307 | if (!rdev->ops->change_beacon) |
| 3308 | return -EOPNOTSUPP; |
| 3309 | |
| 3310 | if (!wdev->beacon_interval) |
| 3311 | return -EINVAL; |
| 3312 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3313 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3314 | if (err) |
| 3315 | return err; |
| 3316 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3317 | wdev_lock(wdev); |
| 3318 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3319 | wdev_unlock(wdev); |
| 3320 | |
| 3321 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3322 | } |
| 3323 | |
| 3324 | 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] | 3325 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3326 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3327 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3328 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3329 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3330 | } |
| 3331 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3332 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3333 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3334 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3335 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3336 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3337 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3338 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3339 | }; |
| 3340 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3341 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3342 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3343 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3344 | { |
| 3345 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3346 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3347 | int flag; |
| 3348 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3349 | /* |
| 3350 | * Try parsing the new attribute first so userspace |
| 3351 | * can specify both for older kernels. |
| 3352 | */ |
| 3353 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3354 | if (nla) { |
| 3355 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3356 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3357 | sta_flags = nla_data(nla); |
| 3358 | params->sta_flags_mask = sta_flags->mask; |
| 3359 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3360 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3361 | if ((params->sta_flags_mask | |
| 3362 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3363 | return -EINVAL; |
| 3364 | return 0; |
| 3365 | } |
| 3366 | |
| 3367 | /* if present, parse the old attribute */ |
| 3368 | |
| 3369 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3370 | if (!nla) |
| 3371 | return 0; |
| 3372 | |
| 3373 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3374 | nla, sta_flags_policy)) |
| 3375 | return -EINVAL; |
| 3376 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3377 | /* |
| 3378 | * Only allow certain flags for interface types so that |
| 3379 | * other attributes are silently ignored. Remember that |
| 3380 | * this is backward compatibility code with old userspace |
| 3381 | * and shouldn't be hit in other cases anyway. |
| 3382 | */ |
| 3383 | switch (iftype) { |
| 3384 | case NL80211_IFTYPE_AP: |
| 3385 | case NL80211_IFTYPE_AP_VLAN: |
| 3386 | case NL80211_IFTYPE_P2P_GO: |
| 3387 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3388 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3389 | BIT(NL80211_STA_FLAG_WME) | |
| 3390 | BIT(NL80211_STA_FLAG_MFP); |
| 3391 | break; |
| 3392 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3393 | case NL80211_IFTYPE_STATION: |
| 3394 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3395 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3396 | break; |
| 3397 | case NL80211_IFTYPE_MESH_POINT: |
| 3398 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3399 | BIT(NL80211_STA_FLAG_MFP) | |
| 3400 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3401 | default: |
| 3402 | return -EINVAL; |
| 3403 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3404 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3405 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3406 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3407 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3408 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3409 | /* no longer support new API additions in old API */ |
| 3410 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3411 | return -EINVAL; |
| 3412 | } |
| 3413 | } |
| 3414 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3415 | return 0; |
| 3416 | } |
| 3417 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3418 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3419 | int attr) |
| 3420 | { |
| 3421 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3422 | u32 bitrate; |
| 3423 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3424 | |
| 3425 | rate = nla_nest_start(msg, attr); |
| 3426 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3427 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3428 | |
| 3429 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3430 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3431 | /* report 16-bit bitrate only if we can */ |
| 3432 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3433 | if (bitrate > 0 && |
| 3434 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3435 | return false; |
| 3436 | if (bitrate_compat > 0 && |
| 3437 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3438 | return false; |
| 3439 | |
| 3440 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3441 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3442 | return false; |
| 3443 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3444 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3445 | return false; |
| 3446 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3447 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3448 | return false; |
| 3449 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3450 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3451 | return false; |
| 3452 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3453 | return false; |
| 3454 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3455 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3456 | return false; |
| 3457 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3458 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3459 | return false; |
| 3460 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3461 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3462 | return false; |
| 3463 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3464 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3465 | return false; |
| 3466 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3467 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3468 | return false; |
| 3469 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3470 | |
| 3471 | nla_nest_end(msg, rate); |
| 3472 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3473 | } |
| 3474 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3475 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3476 | int id) |
| 3477 | { |
| 3478 | void *attr; |
| 3479 | int i = 0; |
| 3480 | |
| 3481 | if (!mask) |
| 3482 | return true; |
| 3483 | |
| 3484 | attr = nla_nest_start(msg, id); |
| 3485 | if (!attr) |
| 3486 | return false; |
| 3487 | |
| 3488 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3489 | if (!(mask & BIT(i))) |
| 3490 | continue; |
| 3491 | |
| 3492 | if (nla_put_u8(msg, i, signal[i])) |
| 3493 | return false; |
| 3494 | } |
| 3495 | |
| 3496 | nla_nest_end(msg, attr); |
| 3497 | |
| 3498 | return true; |
| 3499 | } |
| 3500 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3501 | 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] | 3502 | int flags, |
| 3503 | struct cfg80211_registered_device *rdev, |
| 3504 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3505 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3506 | { |
| 3507 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3508 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3509 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3510 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3511 | if (!hdr) |
| 3512 | return -1; |
| 3513 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3514 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3515 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3516 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3517 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3518 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3519 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3520 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3521 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3522 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3523 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3524 | sinfo->connected_time)) |
| 3525 | goto nla_put_failure; |
| 3526 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3527 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3528 | sinfo->inactive_time)) |
| 3529 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3530 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3531 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3532 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3533 | (u32)sinfo->rx_bytes)) |
| 3534 | goto nla_put_failure; |
| 3535 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3536 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3537 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3538 | (u32)sinfo->tx_bytes)) |
| 3539 | goto nla_put_failure; |
| 3540 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3541 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3542 | sinfo->rx_bytes)) |
| 3543 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3544 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3545 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3546 | sinfo->tx_bytes)) |
| 3547 | goto nla_put_failure; |
| 3548 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3549 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3550 | goto nla_put_failure; |
| 3551 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3552 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3553 | goto nla_put_failure; |
| 3554 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3555 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3556 | sinfo->plink_state)) |
| 3557 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3558 | switch (rdev->wiphy.signal_type) { |
| 3559 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3560 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3561 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3562 | sinfo->signal)) |
| 3563 | goto nla_put_failure; |
| 3564 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3565 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3566 | sinfo->signal_avg)) |
| 3567 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3568 | break; |
| 3569 | default: |
| 3570 | break; |
| 3571 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3572 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3573 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3574 | sinfo->chain_signal, |
| 3575 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3576 | goto nla_put_failure; |
| 3577 | } |
| 3578 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3579 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3580 | sinfo->chain_signal_avg, |
| 3581 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3582 | goto nla_put_failure; |
| 3583 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3584 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3585 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3586 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3587 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3588 | } |
| 3589 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3590 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3591 | NL80211_STA_INFO_RX_BITRATE)) |
| 3592 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3593 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3594 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3595 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3596 | sinfo->rx_packets)) |
| 3597 | goto nla_put_failure; |
| 3598 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3599 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3600 | sinfo->tx_packets)) |
| 3601 | goto nla_put_failure; |
| 3602 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3603 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3604 | sinfo->tx_retries)) |
| 3605 | goto nla_put_failure; |
| 3606 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3607 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3608 | sinfo->tx_failed)) |
| 3609 | goto nla_put_failure; |
| 3610 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3611 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3612 | sinfo->beacon_loss_count)) |
| 3613 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3614 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3615 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3616 | sinfo->local_pm)) |
| 3617 | goto nla_put_failure; |
| 3618 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3619 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3620 | sinfo->peer_pm)) |
| 3621 | goto nla_put_failure; |
| 3622 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3623 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3624 | sinfo->nonpeer_pm)) |
| 3625 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3626 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3627 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3628 | if (!bss_param) |
| 3629 | goto nla_put_failure; |
| 3630 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3631 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3632 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3633 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3634 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3635 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3636 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3637 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3638 | sinfo->bss_param.dtim_period) || |
| 3639 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3640 | sinfo->bss_param.beacon_interval)) |
| 3641 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3642 | |
| 3643 | nla_nest_end(msg, bss_param); |
| 3644 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3645 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3646 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3647 | sizeof(struct nl80211_sta_flag_update), |
| 3648 | &sinfo->sta_flags)) |
| 3649 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3650 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3651 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3652 | sinfo->t_offset)) |
| 3653 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3654 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3655 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3656 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3657 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3658 | sinfo->assoc_req_ies)) |
| 3659 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3660 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3661 | return genlmsg_end(msg, hdr); |
| 3662 | |
| 3663 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3664 | genlmsg_cancel(msg, hdr); |
| 3665 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3666 | } |
| 3667 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3668 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3669 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3670 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3671 | struct station_info sinfo; |
| 3672 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3673 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3674 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3675 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3676 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3677 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3678 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3679 | if (err) |
| 3680 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3681 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3682 | if (!wdev->netdev) { |
| 3683 | err = -EINVAL; |
| 3684 | goto out_err; |
| 3685 | } |
| 3686 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3687 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3688 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3689 | goto out_err; |
| 3690 | } |
| 3691 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3692 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3693 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3694 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3695 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3696 | if (err == -ENOENT) |
| 3697 | break; |
| 3698 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3699 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3700 | |
| 3701 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3702 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3703 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3704 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3705 | &sinfo) < 0) |
| 3706 | goto out; |
| 3707 | |
| 3708 | sta_idx++; |
| 3709 | } |
| 3710 | |
| 3711 | |
| 3712 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3713 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3714 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3715 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3716 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3717 | |
| 3718 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3719 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3720 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3721 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3722 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3723 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3724 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3725 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3726 | struct sk_buff *msg; |
| 3727 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3728 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3729 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3730 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3731 | |
| 3732 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3733 | return -EINVAL; |
| 3734 | |
| 3735 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3736 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3737 | if (!rdev->ops->get_station) |
| 3738 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3739 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3740 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3741 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3742 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3743 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3744 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3745 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3746 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3747 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3748 | 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] | 3749 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3750 | nlmsg_free(msg); |
| 3751 | return -ENOBUFS; |
| 3752 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3753 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3754 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3755 | } |
| 3756 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3757 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3758 | struct station_parameters *params, |
| 3759 | enum cfg80211_station_type statype) |
| 3760 | { |
| 3761 | if (params->listen_interval != -1) |
| 3762 | return -EINVAL; |
| 3763 | if (params->aid) |
| 3764 | return -EINVAL; |
| 3765 | |
| 3766 | /* When you run into this, adjust the code below for the new flag */ |
| 3767 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3768 | |
| 3769 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3770 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3771 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3772 | /* |
| 3773 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3774 | * code doesn't have the bug of including TDLS in the |
| 3775 | * mask everywhere. |
| 3776 | */ |
| 3777 | if (params->sta_flags_mask & |
| 3778 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3779 | BIT(NL80211_STA_FLAG_MFP) | |
| 3780 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3781 | return -EINVAL; |
| 3782 | break; |
| 3783 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3784 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3785 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3786 | return -EINVAL; |
| 3787 | /* ignore since it can't change */ |
| 3788 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3789 | break; |
| 3790 | default: |
| 3791 | /* disallow mesh-specific things */ |
| 3792 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3793 | return -EINVAL; |
| 3794 | if (params->local_pm) |
| 3795 | return -EINVAL; |
| 3796 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3797 | return -EINVAL; |
| 3798 | } |
| 3799 | |
| 3800 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3801 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3802 | /* TDLS can't be set, ... */ |
| 3803 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3804 | return -EINVAL; |
| 3805 | /* |
| 3806 | * ... but don't bother the driver with it. This works around |
| 3807 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3808 | * TLDS_PEER flag in the mask even for AP mode. |
| 3809 | */ |
| 3810 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3811 | } |
| 3812 | |
| 3813 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3814 | /* reject other things that can't change */ |
| 3815 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3816 | return -EINVAL; |
| 3817 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3818 | return -EINVAL; |
| 3819 | if (params->supported_rates) |
| 3820 | return -EINVAL; |
| 3821 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3822 | return -EINVAL; |
| 3823 | } |
| 3824 | |
| 3825 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3826 | if (params->vlan) |
| 3827 | return -EINVAL; |
| 3828 | } |
| 3829 | |
| 3830 | switch (statype) { |
| 3831 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3832 | /* Use this only for authorizing/unauthorizing a station */ |
| 3833 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3834 | return -EOPNOTSUPP; |
| 3835 | break; |
| 3836 | case CFG80211_STA_AP_CLIENT: |
| 3837 | /* accept only the listed bits */ |
| 3838 | if (params->sta_flags_mask & |
| 3839 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3840 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3841 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3842 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3843 | BIT(NL80211_STA_FLAG_WME) | |
| 3844 | BIT(NL80211_STA_FLAG_MFP))) |
| 3845 | return -EINVAL; |
| 3846 | |
| 3847 | /* but authenticated/associated only if driver handles it */ |
| 3848 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3849 | params->sta_flags_mask & |
| 3850 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3851 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3852 | return -EINVAL; |
| 3853 | break; |
| 3854 | case CFG80211_STA_IBSS: |
| 3855 | case CFG80211_STA_AP_STA: |
| 3856 | /* reject any changes other than AUTHORIZED */ |
| 3857 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3858 | return -EINVAL; |
| 3859 | break; |
| 3860 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3861 | /* reject any changes other than AUTHORIZED or WME */ |
| 3862 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3863 | BIT(NL80211_STA_FLAG_WME))) |
| 3864 | return -EINVAL; |
| 3865 | /* force (at least) rates when authorizing */ |
| 3866 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3867 | !params->supported_rates) |
| 3868 | return -EINVAL; |
| 3869 | break; |
| 3870 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3871 | /* reject any changes */ |
| 3872 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3873 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3874 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3875 | return -EINVAL; |
| 3876 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3877 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3878 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3879 | return -EINVAL; |
| 3880 | break; |
| 3881 | } |
| 3882 | |
| 3883 | return 0; |
| 3884 | } |
| 3885 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3886 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3887 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3888 | * 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] | 3889 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3890 | static struct net_device *get_vlan(struct genl_info *info, |
| 3891 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3892 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3893 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3894 | struct net_device *v; |
| 3895 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3896 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3897 | if (!vlanattr) |
| 3898 | return NULL; |
| 3899 | |
| 3900 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3901 | if (!v) |
| 3902 | return ERR_PTR(-ENODEV); |
| 3903 | |
| 3904 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3905 | ret = -EINVAL; |
| 3906 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3907 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3908 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3909 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3910 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3911 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3912 | ret = -EINVAL; |
| 3913 | goto error; |
| 3914 | } |
| 3915 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3916 | if (!netif_running(v)) { |
| 3917 | ret = -ENETDOWN; |
| 3918 | goto error; |
| 3919 | } |
| 3920 | |
| 3921 | return v; |
| 3922 | error: |
| 3923 | dev_put(v); |
| 3924 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3925 | } |
| 3926 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 3927 | static const struct nla_policy |
| 3928 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3929 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3930 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3931 | }; |
| 3932 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3933 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3934 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3935 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3936 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3937 | struct nlattr *nla; |
| 3938 | int err; |
| 3939 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3940 | /* parse WME attributes if present */ |
| 3941 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3942 | return 0; |
| 3943 | |
| 3944 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3945 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3946 | nl80211_sta_wme_policy); |
| 3947 | if (err) |
| 3948 | return err; |
| 3949 | |
| 3950 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3951 | params->uapsd_queues = nla_get_u8( |
| 3952 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3953 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3954 | return -EINVAL; |
| 3955 | |
| 3956 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3957 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3958 | |
| 3959 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3960 | return -EINVAL; |
| 3961 | |
| 3962 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3963 | |
| 3964 | return 0; |
| 3965 | } |
| 3966 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3967 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 3968 | struct station_parameters *params) |
| 3969 | { |
| 3970 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 3971 | params->supported_channels = |
| 3972 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3973 | params->supported_channels_len = |
| 3974 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3975 | /* |
| 3976 | * Need to include at least one (first channel, number of |
| 3977 | * channels) tuple for each subband, and must have proper |
| 3978 | * tuples for the rest of the data as well. |
| 3979 | */ |
| 3980 | if (params->supported_channels_len < 2) |
| 3981 | return -EINVAL; |
| 3982 | if (params->supported_channels_len % 2) |
| 3983 | return -EINVAL; |
| 3984 | } |
| 3985 | |
| 3986 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 3987 | params->supported_oper_classes = |
| 3988 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3989 | params->supported_oper_classes_len = |
| 3990 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3991 | /* |
| 3992 | * The value of the Length field of the Supported Operating |
| 3993 | * Classes element is between 2 and 253. |
| 3994 | */ |
| 3995 | if (params->supported_oper_classes_len < 2 || |
| 3996 | params->supported_oper_classes_len > 253) |
| 3997 | return -EINVAL; |
| 3998 | } |
| 3999 | return 0; |
| 4000 | } |
| 4001 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4002 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4003 | struct station_parameters *params) |
| 4004 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4005 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4006 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4007 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4008 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4009 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4010 | params->ht_capa = |
| 4011 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4012 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4013 | params->vht_capa = |
| 4014 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4015 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4016 | err = nl80211_parse_sta_channel_info(info, params); |
| 4017 | if (err) |
| 4018 | return err; |
| 4019 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4020 | return nl80211_parse_sta_wme(info, params); |
| 4021 | } |
| 4022 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4023 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4024 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4025 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4026 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4027 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4028 | u8 *mac_addr; |
| 4029 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4030 | |
| 4031 | memset(¶ms, 0, sizeof(params)); |
| 4032 | |
| 4033 | params.listen_interval = -1; |
| 4034 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4035 | if (!rdev->ops->change_station) |
| 4036 | return -EOPNOTSUPP; |
| 4037 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4038 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4039 | return -EINVAL; |
| 4040 | |
| 4041 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4042 | return -EINVAL; |
| 4043 | |
| 4044 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4045 | |
| 4046 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4047 | params.supported_rates = |
| 4048 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4049 | params.supported_rates_len = |
| 4050 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4051 | } |
| 4052 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4053 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4054 | params.capability = |
| 4055 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4056 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4057 | } |
| 4058 | |
| 4059 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4060 | params.ext_capab = |
| 4061 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4062 | params.ext_capab_len = |
| 4063 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4064 | } |
| 4065 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4066 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4067 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4068 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4069 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4070 | return -EINVAL; |
| 4071 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4072 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4073 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4074 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4075 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4076 | return -EINVAL; |
| 4077 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4078 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4079 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4080 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4081 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4082 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4083 | return -EINVAL; |
| 4084 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4085 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4086 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4087 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4088 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4089 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4090 | |
| 4091 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4092 | pm > NL80211_MESH_POWER_MAX) |
| 4093 | return -EINVAL; |
| 4094 | |
| 4095 | params.local_pm = pm; |
| 4096 | } |
| 4097 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4098 | /* Include parameters for TDLS peer (will check later) */ |
| 4099 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4100 | if (err) |
| 4101 | return err; |
| 4102 | |
| 4103 | params.vlan = get_vlan(info, rdev); |
| 4104 | if (IS_ERR(params.vlan)) |
| 4105 | return PTR_ERR(params.vlan); |
| 4106 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4107 | switch (dev->ieee80211_ptr->iftype) { |
| 4108 | case NL80211_IFTYPE_AP: |
| 4109 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4110 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4111 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4112 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4113 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4114 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4115 | break; |
| 4116 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4117 | err = -EOPNOTSUPP; |
| 4118 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4119 | } |
| 4120 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4121 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4122 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4123 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4124 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4125 | if (params.vlan) |
| 4126 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4127 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4128 | return err; |
| 4129 | } |
| 4130 | |
| 4131 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4132 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4133 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4134 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4135 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4136 | struct station_parameters params; |
| 4137 | u8 *mac_addr = NULL; |
| 4138 | |
| 4139 | memset(¶ms, 0, sizeof(params)); |
| 4140 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4141 | if (!rdev->ops->add_station) |
| 4142 | return -EOPNOTSUPP; |
| 4143 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4144 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4145 | return -EINVAL; |
| 4146 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4147 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4148 | return -EINVAL; |
| 4149 | |
| 4150 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4151 | return -EINVAL; |
| 4152 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4153 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4154 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4155 | return -EINVAL; |
| 4156 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4157 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4158 | params.supported_rates = |
| 4159 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4160 | params.supported_rates_len = |
| 4161 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4162 | params.listen_interval = |
| 4163 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4164 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4165 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4166 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4167 | else |
| 4168 | 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] | 4169 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4170 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4171 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4172 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4173 | params.capability = |
| 4174 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4175 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4176 | } |
| 4177 | |
| 4178 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4179 | params.ext_capab = |
| 4180 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4181 | params.ext_capab_len = |
| 4182 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4183 | } |
| 4184 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4185 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4186 | params.ht_capa = |
| 4187 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4188 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4189 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4190 | params.vht_capa = |
| 4191 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4192 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4193 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4194 | params.opmode_notif_used = true; |
| 4195 | params.opmode_notif = |
| 4196 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4197 | } |
| 4198 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4199 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4200 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4201 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4202 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4203 | return -EINVAL; |
| 4204 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4205 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4206 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4207 | if (err) |
| 4208 | return err; |
| 4209 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4210 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4211 | if (err) |
| 4212 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4213 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4214 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4215 | return -EINVAL; |
| 4216 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4217 | /* When you run into this, adjust the code below for the new flag */ |
| 4218 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4219 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4220 | switch (dev->ieee80211_ptr->iftype) { |
| 4221 | case NL80211_IFTYPE_AP: |
| 4222 | case NL80211_IFTYPE_AP_VLAN: |
| 4223 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4224 | /* ignore WME attributes if iface/sta is not capable */ |
| 4225 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4226 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4227 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4228 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4229 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4230 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4231 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4232 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4233 | /* but don't bother the driver with it */ |
| 4234 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4235 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4236 | /* allow authenticated/associated only if driver handles it */ |
| 4237 | if (!(rdev->wiphy.features & |
| 4238 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4239 | params.sta_flags_mask & |
| 4240 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4241 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4242 | return -EINVAL; |
| 4243 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4244 | /* must be last in here for error handling */ |
| 4245 | params.vlan = get_vlan(info, rdev); |
| 4246 | if (IS_ERR(params.vlan)) |
| 4247 | return PTR_ERR(params.vlan); |
| 4248 | break; |
| 4249 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4250 | /* ignore uAPSD data */ |
| 4251 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4252 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4253 | /* associated is disallowed */ |
| 4254 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4255 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4256 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4257 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4258 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4259 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4260 | break; |
| 4261 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4262 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4263 | /* ignore uAPSD data */ |
| 4264 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4265 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4266 | /* these are disallowed */ |
| 4267 | if (params.sta_flags_mask & |
| 4268 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4269 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4270 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4271 | /* Only TDLS peers can be added */ |
| 4272 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4273 | return -EINVAL; |
| 4274 | /* Can only add if TDLS ... */ |
| 4275 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4276 | return -EOPNOTSUPP; |
| 4277 | /* ... with external setup is supported */ |
| 4278 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4279 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4280 | /* |
| 4281 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4282 | * as authorized, but it shouldn't yet be. |
| 4283 | */ |
| 4284 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4285 | break; |
| 4286 | default: |
| 4287 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4288 | } |
| 4289 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4290 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4291 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4292 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4293 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4294 | if (params.vlan) |
| 4295 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4296 | return err; |
| 4297 | } |
| 4298 | |
| 4299 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4300 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4301 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4302 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4303 | u8 *mac_addr = NULL; |
| 4304 | |
| 4305 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4306 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4307 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4308 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4309 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4310 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4311 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4312 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4313 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4314 | if (!rdev->ops->del_station) |
| 4315 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4316 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4317 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4318 | } |
| 4319 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4320 | 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] | 4321 | int flags, struct net_device *dev, |
| 4322 | u8 *dst, u8 *next_hop, |
| 4323 | struct mpath_info *pinfo) |
| 4324 | { |
| 4325 | void *hdr; |
| 4326 | struct nlattr *pinfoattr; |
| 4327 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4328 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4329 | if (!hdr) |
| 4330 | return -1; |
| 4331 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4332 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4333 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4334 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4335 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4336 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4337 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4338 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4339 | if (!pinfoattr) |
| 4340 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4341 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4342 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4343 | pinfo->frame_qlen)) |
| 4344 | goto nla_put_failure; |
| 4345 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4346 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4347 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4348 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4349 | pinfo->metric)) || |
| 4350 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4351 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4352 | pinfo->exptime)) || |
| 4353 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4354 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4355 | pinfo->flags)) || |
| 4356 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4357 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4358 | pinfo->discovery_timeout)) || |
| 4359 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4360 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4361 | pinfo->discovery_retries))) |
| 4362 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4363 | |
| 4364 | nla_nest_end(msg, pinfoattr); |
| 4365 | |
| 4366 | return genlmsg_end(msg, hdr); |
| 4367 | |
| 4368 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4369 | genlmsg_cancel(msg, hdr); |
| 4370 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4371 | } |
| 4372 | |
| 4373 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4374 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4375 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4376 | struct mpath_info pinfo; |
| 4377 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4378 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4379 | u8 dst[ETH_ALEN]; |
| 4380 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4381 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4382 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4383 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4384 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4385 | if (err) |
| 4386 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4387 | |
| 4388 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4389 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4390 | goto out_err; |
| 4391 | } |
| 4392 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4393 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4394 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4395 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4396 | } |
| 4397 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4398 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4399 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4400 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4401 | if (err == -ENOENT) |
| 4402 | break; |
| 4403 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4404 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4405 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4406 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4407 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4408 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4409 | &pinfo) < 0) |
| 4410 | goto out; |
| 4411 | |
| 4412 | path_idx++; |
| 4413 | } |
| 4414 | |
| 4415 | |
| 4416 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4417 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4418 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4419 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4420 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4421 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4422 | } |
| 4423 | |
| 4424 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4425 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4426 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4427 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4428 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4429 | struct mpath_info pinfo; |
| 4430 | struct sk_buff *msg; |
| 4431 | u8 *dst = NULL; |
| 4432 | u8 next_hop[ETH_ALEN]; |
| 4433 | |
| 4434 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4435 | |
| 4436 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4437 | return -EINVAL; |
| 4438 | |
| 4439 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4440 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4441 | if (!rdev->ops->get_mpath) |
| 4442 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4443 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4444 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4445 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4446 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4447 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4448 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4449 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4450 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4451 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4452 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4453 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4454 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4455 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4456 | dev, dst, next_hop, &pinfo) < 0) { |
| 4457 | nlmsg_free(msg); |
| 4458 | return -ENOBUFS; |
| 4459 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4460 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4461 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4465 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4466 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4467 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4468 | u8 *dst = NULL; |
| 4469 | u8 *next_hop = NULL; |
| 4470 | |
| 4471 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4472 | return -EINVAL; |
| 4473 | |
| 4474 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4475 | return -EINVAL; |
| 4476 | |
| 4477 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4478 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4479 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4480 | if (!rdev->ops->change_mpath) |
| 4481 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4482 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4483 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4484 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4485 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4486 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4487 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4488 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4489 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4490 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4491 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4492 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4493 | u8 *dst = NULL; |
| 4494 | u8 *next_hop = NULL; |
| 4495 | |
| 4496 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4497 | return -EINVAL; |
| 4498 | |
| 4499 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4500 | return -EINVAL; |
| 4501 | |
| 4502 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4503 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4504 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4505 | if (!rdev->ops->add_mpath) |
| 4506 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4507 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4508 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4509 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4510 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4511 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4512 | } |
| 4513 | |
| 4514 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4515 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4516 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4517 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4518 | u8 *dst = NULL; |
| 4519 | |
| 4520 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4521 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4522 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4523 | if (!rdev->ops->del_mpath) |
| 4524 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4525 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4526 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4527 | } |
| 4528 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4529 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4530 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4531 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4532 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4533 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4534 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4535 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4536 | |
| 4537 | memset(¶ms, 0, sizeof(params)); |
| 4538 | /* default to not changing parameters */ |
| 4539 | params.use_cts_prot = -1; |
| 4540 | params.use_short_preamble = -1; |
| 4541 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4542 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4543 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4544 | params.p2p_ctwindow = -1; |
| 4545 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4546 | |
| 4547 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4548 | params.use_cts_prot = |
| 4549 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4550 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4551 | params.use_short_preamble = |
| 4552 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4553 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4554 | params.use_short_slot_time = |
| 4555 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4556 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4557 | params.basic_rates = |
| 4558 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4559 | params.basic_rates_len = |
| 4560 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4561 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4562 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4563 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4564 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4565 | params.ht_opmode = |
| 4566 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4567 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4568 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4569 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4570 | return -EINVAL; |
| 4571 | params.p2p_ctwindow = |
| 4572 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4573 | if (params.p2p_ctwindow < 0) |
| 4574 | return -EINVAL; |
| 4575 | if (params.p2p_ctwindow != 0 && |
| 4576 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4577 | return -EINVAL; |
| 4578 | } |
| 4579 | |
| 4580 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4581 | u8 tmp; |
| 4582 | |
| 4583 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4584 | return -EINVAL; |
| 4585 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4586 | if (tmp > 1) |
| 4587 | return -EINVAL; |
| 4588 | params.p2p_opp_ps = tmp; |
| 4589 | if (params.p2p_opp_ps && |
| 4590 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4591 | return -EINVAL; |
| 4592 | } |
| 4593 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4594 | if (!rdev->ops->change_bss) |
| 4595 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4596 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4597 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4598 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4599 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4600 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4601 | wdev_lock(wdev); |
| 4602 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4603 | wdev_unlock(wdev); |
| 4604 | |
| 4605 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4606 | } |
| 4607 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4608 | 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] | 4609 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4610 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4611 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4612 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4613 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4614 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4615 | }; |
| 4616 | |
| 4617 | static int parse_reg_rule(struct nlattr *tb[], |
| 4618 | struct ieee80211_reg_rule *reg_rule) |
| 4619 | { |
| 4620 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4621 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4622 | |
| 4623 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4624 | return -EINVAL; |
| 4625 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4626 | return -EINVAL; |
| 4627 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4628 | return -EINVAL; |
| 4629 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4630 | return -EINVAL; |
| 4631 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4632 | return -EINVAL; |
| 4633 | |
| 4634 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4635 | |
| 4636 | freq_range->start_freq_khz = |
| 4637 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4638 | freq_range->end_freq_khz = |
| 4639 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4640 | freq_range->max_bandwidth_khz = |
| 4641 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4642 | |
| 4643 | power_rule->max_eirp = |
| 4644 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4645 | |
| 4646 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4647 | power_rule->max_antenna_gain = |
| 4648 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4649 | |
| 4650 | return 0; |
| 4651 | } |
| 4652 | |
| 4653 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4654 | { |
| 4655 | int r; |
| 4656 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4657 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4658 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4659 | /* |
| 4660 | * You should only get this when cfg80211 hasn't yet initialized |
| 4661 | * completely when built-in to the kernel right between the time |
| 4662 | * window between nl80211_init() and regulatory_init(), if that is |
| 4663 | * even possible. |
| 4664 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4665 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4666 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4667 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4668 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4669 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4670 | |
| 4671 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4672 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4673 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4674 | user_reg_hint_type = |
| 4675 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4676 | else |
| 4677 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4678 | |
| 4679 | switch (user_reg_hint_type) { |
| 4680 | case NL80211_USER_REG_HINT_USER: |
| 4681 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4682 | break; |
| 4683 | default: |
| 4684 | return -EINVAL; |
| 4685 | } |
| 4686 | |
| 4687 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4688 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4689 | return r; |
| 4690 | } |
| 4691 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4692 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4693 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4694 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4695 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4696 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4697 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4698 | struct mesh_config cur_params; |
| 4699 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4700 | void *hdr; |
| 4701 | struct nlattr *pinfoattr; |
| 4702 | struct sk_buff *msg; |
| 4703 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4704 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4705 | return -EOPNOTSUPP; |
| 4706 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4707 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4708 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4709 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4710 | wdev_lock(wdev); |
| 4711 | /* If not connected, get default parameters */ |
| 4712 | if (!wdev->mesh_id_len) |
| 4713 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4714 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4715 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4716 | wdev_unlock(wdev); |
| 4717 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4718 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4719 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4720 | |
| 4721 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4722 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4723 | if (!msg) |
| 4724 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4725 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4726 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4727 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4728 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4729 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4730 | if (!pinfoattr) |
| 4731 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4732 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4733 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4734 | cur_params.dot11MeshRetryTimeout) || |
| 4735 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4736 | cur_params.dot11MeshConfirmTimeout) || |
| 4737 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4738 | cur_params.dot11MeshHoldingTimeout) || |
| 4739 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4740 | cur_params.dot11MeshMaxPeerLinks) || |
| 4741 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4742 | cur_params.dot11MeshMaxRetries) || |
| 4743 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4744 | cur_params.dot11MeshTTL) || |
| 4745 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4746 | cur_params.element_ttl) || |
| 4747 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4748 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4749 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4750 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4751 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4752 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4753 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4754 | cur_params.path_refresh_time) || |
| 4755 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4756 | cur_params.min_discovery_timeout) || |
| 4757 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4758 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4759 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4760 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4761 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4762 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4763 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4764 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4765 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4766 | cur_params.dot11MeshHWMPRootMode) || |
| 4767 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4768 | cur_params.dot11MeshHWMPRannInterval) || |
| 4769 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4770 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4771 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4772 | cur_params.dot11MeshForwarding) || |
| 4773 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4774 | cur_params.rssi_threshold) || |
| 4775 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4776 | cur_params.ht_opmode) || |
| 4777 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4778 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4779 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4780 | cur_params.dot11MeshHWMProotInterval) || |
| 4781 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4782 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4783 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4784 | cur_params.power_mode) || |
| 4785 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4786 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4787 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4788 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4789 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4790 | nla_nest_end(msg, pinfoattr); |
| 4791 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4792 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4793 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4794 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4795 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4796 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4797 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4798 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4799 | } |
| 4800 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4801 | 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] | 4802 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4803 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4804 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4805 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4806 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4807 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4808 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4809 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4810 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4811 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4812 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4813 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4814 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4815 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4816 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4817 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4818 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4819 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4820 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4821 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4822 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4823 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4824 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4825 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4826 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4827 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4828 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4829 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4830 | }; |
| 4831 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4832 | static const struct nla_policy |
| 4833 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4834 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4835 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4836 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4837 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4838 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4839 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4840 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4841 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4842 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4843 | }; |
| 4844 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4845 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4846 | struct mesh_config *cfg, |
| 4847 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4848 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4849 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4850 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4851 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4852 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4853 | do { \ |
| 4854 | if (tb[attr]) { \ |
| 4855 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4856 | return -EINVAL; \ |
| 4857 | cfg->param = fn(tb[attr]); \ |
| 4858 | mask |= (1 << (attr - 1)); \ |
| 4859 | } \ |
| 4860 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4861 | |
| 4862 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4863 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4864 | return -EINVAL; |
| 4865 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4866 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4867 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4868 | return -EINVAL; |
| 4869 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4870 | /* This makes sure that there aren't more than 32 mesh config |
| 4871 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4872 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4873 | |
| 4874 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4875 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4876 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4877 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4878 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4879 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4880 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4881 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4882 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4883 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4884 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4885 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4886 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4887 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4888 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4889 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4890 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4891 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4892 | 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] | 4893 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4894 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4895 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4896 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4897 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4898 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4899 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4900 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4901 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4902 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4903 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4904 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4905 | 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] | 4906 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4907 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4908 | 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] | 4909 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4910 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4911 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4912 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4913 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4914 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4915 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4916 | 1, 65535, mask, |
| 4917 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4918 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4919 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4920 | 1, 65535, mask, |
| 4921 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4922 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4923 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4924 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4925 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4926 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4927 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4928 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4929 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4930 | nla_get_u8); |
| 4931 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4932 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4933 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4934 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4935 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4936 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4937 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4938 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4939 | mask, NL80211_MESHCONF_FORWARDING, |
| 4940 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4941 | 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] | 4942 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4943 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4944 | 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] | 4945 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4946 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4947 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4948 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4949 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4950 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4951 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4952 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4953 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4954 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4955 | dot11MeshHWMPconfirmationInterval, |
| 4956 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4957 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4958 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4959 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4960 | NL80211_MESH_POWER_ACTIVE, |
| 4961 | NL80211_MESH_POWER_MAX, |
| 4962 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4963 | nla_get_u32); |
| 4964 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4965 | 0, 65535, mask, |
| 4966 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4967 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4968 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4969 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4970 | if (mask_out) |
| 4971 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4972 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4973 | return 0; |
| 4974 | |
| 4975 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4976 | } |
| 4977 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4978 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4979 | struct mesh_setup *setup) |
| 4980 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4981 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4982 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4983 | |
| 4984 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4985 | return -EINVAL; |
| 4986 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4987 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4988 | nl80211_mesh_setup_params_policy)) |
| 4989 | return -EINVAL; |
| 4990 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4991 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4992 | setup->sync_method = |
| 4993 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4994 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4995 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4996 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4997 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4998 | setup->path_sel_proto = |
| 4999 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5000 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5001 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5002 | |
| 5003 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5004 | setup->path_metric = |
| 5005 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5006 | IEEE80211_PATH_METRIC_VENDOR : |
| 5007 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5008 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5009 | |
| 5010 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5011 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5012 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5013 | if (!is_valid_ie_attr(ieattr)) |
| 5014 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5015 | setup->ie = nla_data(ieattr); |
| 5016 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5017 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5018 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5019 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5020 | return -EINVAL; |
| 5021 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5022 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5023 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5024 | if (setup->is_secure) |
| 5025 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5026 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5027 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5028 | if (!setup->user_mpm) |
| 5029 | return -EINVAL; |
| 5030 | setup->auth_id = |
| 5031 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5032 | } |
| 5033 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5034 | return 0; |
| 5035 | } |
| 5036 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5037 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5038 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5039 | { |
| 5040 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5041 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5042 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5043 | struct mesh_config cfg; |
| 5044 | u32 mask; |
| 5045 | int err; |
| 5046 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5047 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5048 | return -EOPNOTSUPP; |
| 5049 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5050 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5051 | return -EOPNOTSUPP; |
| 5052 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5053 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5054 | if (err) |
| 5055 | return err; |
| 5056 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5057 | wdev_lock(wdev); |
| 5058 | if (!wdev->mesh_id_len) |
| 5059 | err = -ENOLINK; |
| 5060 | |
| 5061 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5062 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5063 | |
| 5064 | wdev_unlock(wdev); |
| 5065 | |
| 5066 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5067 | } |
| 5068 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5069 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 5070 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5071 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5072 | struct sk_buff *msg; |
| 5073 | void *hdr = NULL; |
| 5074 | struct nlattr *nl_reg_rules; |
| 5075 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5076 | |
| 5077 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5078 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5079 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5080 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5081 | if (!msg) |
| 5082 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5083 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5084 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5085 | NL80211_CMD_GET_REG); |
| 5086 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5087 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5088 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5089 | if (reg_last_request_cell_base() && |
| 5090 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5091 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5092 | goto nla_put_failure; |
| 5093 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5094 | rcu_read_lock(); |
| 5095 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5096 | |
| 5097 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5098 | (regdom->dfs_region && |
| 5099 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5100 | goto nla_put_failure_rcu; |
| 5101 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5102 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5103 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5104 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5105 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5106 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5107 | struct nlattr *nl_reg_rule; |
| 5108 | const struct ieee80211_reg_rule *reg_rule; |
| 5109 | const struct ieee80211_freq_range *freq_range; |
| 5110 | const struct ieee80211_power_rule *power_rule; |
| 5111 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5112 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5113 | freq_range = ®_rule->freq_range; |
| 5114 | power_rule = ®_rule->power_rule; |
| 5115 | |
| 5116 | nl_reg_rule = nla_nest_start(msg, i); |
| 5117 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5118 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5119 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5120 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5121 | reg_rule->flags) || |
| 5122 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5123 | freq_range->start_freq_khz) || |
| 5124 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5125 | freq_range->end_freq_khz) || |
| 5126 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 5127 | freq_range->max_bandwidth_khz) || |
| 5128 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5129 | power_rule->max_antenna_gain) || |
| 5130 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 5131 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5132 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5133 | |
| 5134 | nla_nest_end(msg, nl_reg_rule); |
| 5135 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5136 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5137 | |
| 5138 | nla_nest_end(msg, nl_reg_rules); |
| 5139 | |
| 5140 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5141 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5142 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5143 | nla_put_failure_rcu: |
| 5144 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5145 | nla_put_failure: |
| 5146 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5147 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5148 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5149 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5150 | } |
| 5151 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5152 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5153 | { |
| 5154 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5155 | struct nlattr *nl_reg_rule; |
| 5156 | char *alpha2 = NULL; |
| 5157 | int rem_reg_rules = 0, r = 0; |
| 5158 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5159 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5160 | struct ieee80211_regdomain *rd = NULL; |
| 5161 | |
| 5162 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5163 | return -EINVAL; |
| 5164 | |
| 5165 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5166 | return -EINVAL; |
| 5167 | |
| 5168 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5169 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5170 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5171 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5172 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5173 | 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] | 5174 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5175 | num_rules++; |
| 5176 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5177 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5178 | } |
| 5179 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5180 | if (!reg_is_valid_request(alpha2)) |
| 5181 | return -EINVAL; |
| 5182 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5183 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5184 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5185 | |
| 5186 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5187 | if (!rd) |
| 5188 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5189 | |
| 5190 | rd->n_reg_rules = num_rules; |
| 5191 | rd->alpha2[0] = alpha2[0]; |
| 5192 | rd->alpha2[1] = alpha2[1]; |
| 5193 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5194 | /* |
| 5195 | * Disable DFS master mode if the DFS region was |
| 5196 | * not supported or known on this kernel. |
| 5197 | */ |
| 5198 | if (reg_supported_dfs_region(dfs_region)) |
| 5199 | rd->dfs_region = dfs_region; |
| 5200 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5201 | 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] | 5202 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5203 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5204 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5205 | reg_rule_policy); |
| 5206 | if (r) |
| 5207 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5208 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5209 | if (r) |
| 5210 | goto bad_reg; |
| 5211 | |
| 5212 | rule_idx++; |
| 5213 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5214 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5215 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5216 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5217 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5218 | } |
| 5219 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5220 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5221 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5222 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5223 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5224 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5225 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5226 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5227 | } |
| 5228 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5229 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5230 | { |
| 5231 | struct nlattr *attr1, *attr2; |
| 5232 | int n_channels = 0, tmp1, tmp2; |
| 5233 | |
| 5234 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5235 | n_channels++; |
| 5236 | /* |
| 5237 | * Some hardware has a limited channel list for |
| 5238 | * scanning, and it is pretty much nonsensical |
| 5239 | * to scan for a channel twice, so disallow that |
| 5240 | * and don't require drivers to check that the |
| 5241 | * channel list they get isn't longer than what |
| 5242 | * they can scan, as long as they can scan all |
| 5243 | * the channels they registered at once. |
| 5244 | */ |
| 5245 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5246 | if (attr1 != attr2 && |
| 5247 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5248 | return 0; |
| 5249 | } |
| 5250 | |
| 5251 | return n_channels; |
| 5252 | } |
| 5253 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5254 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5255 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5257 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5258 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5259 | struct nlattr *attr; |
| 5260 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5261 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5262 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5263 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5264 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5265 | return -EINVAL; |
| 5266 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5267 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5268 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5269 | if (!rdev->ops->scan) |
| 5270 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5271 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5272 | if (rdev->scan_req) { |
| 5273 | err = -EBUSY; |
| 5274 | goto unlock; |
| 5275 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5276 | |
| 5277 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5278 | n_channels = validate_scan_freqs( |
| 5279 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5280 | if (!n_channels) { |
| 5281 | err = -EINVAL; |
| 5282 | goto unlock; |
| 5283 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5284 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5285 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5286 | } |
| 5287 | |
| 5288 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5289 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5290 | n_ssids++; |
| 5291 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5292 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5293 | err = -EINVAL; |
| 5294 | goto unlock; |
| 5295 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5296 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5297 | if (info->attrs[NL80211_ATTR_IE]) |
| 5298 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5299 | else |
| 5300 | ie_len = 0; |
| 5301 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5302 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5303 | err = -EINVAL; |
| 5304 | goto unlock; |
| 5305 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5306 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5307 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5308 | + sizeof(*request->ssids) * n_ssids |
| 5309 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5310 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5311 | if (!request) { |
| 5312 | err = -ENOMEM; |
| 5313 | goto unlock; |
| 5314 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5315 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5316 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5317 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5318 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5319 | if (ie_len) { |
| 5320 | if (request->ssids) |
| 5321 | request->ie = (void *)(request->ssids + n_ssids); |
| 5322 | else |
| 5323 | request->ie = (void *)(request->channels + n_channels); |
| 5324 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5325 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5326 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5327 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5328 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5329 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5330 | struct ieee80211_channel *chan; |
| 5331 | |
| 5332 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5333 | |
| 5334 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5335 | err = -EINVAL; |
| 5336 | goto out_free; |
| 5337 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5338 | |
| 5339 | /* ignore disabled channels */ |
| 5340 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5341 | continue; |
| 5342 | |
| 5343 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5344 | i++; |
| 5345 | } |
| 5346 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5347 | enum ieee80211_band band; |
| 5348 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5349 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5350 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5351 | int j; |
| 5352 | if (!wiphy->bands[band]) |
| 5353 | continue; |
| 5354 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5355 | struct ieee80211_channel *chan; |
| 5356 | |
| 5357 | chan = &wiphy->bands[band]->channels[j]; |
| 5358 | |
| 5359 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5360 | continue; |
| 5361 | |
| 5362 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5363 | i++; |
| 5364 | } |
| 5365 | } |
| 5366 | } |
| 5367 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5368 | if (!i) { |
| 5369 | err = -EINVAL; |
| 5370 | goto out_free; |
| 5371 | } |
| 5372 | |
| 5373 | request->n_channels = i; |
| 5374 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5375 | i = 0; |
| 5376 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5377 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5378 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5379 | err = -EINVAL; |
| 5380 | goto out_free; |
| 5381 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5382 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5383 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5384 | i++; |
| 5385 | } |
| 5386 | } |
| 5387 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5388 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5389 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5390 | memcpy((void *)request->ie, |
| 5391 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5392 | request->ie_len); |
| 5393 | } |
| 5394 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5395 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5396 | if (wiphy->bands[i]) |
| 5397 | request->rates[i] = |
| 5398 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5399 | |
| 5400 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5401 | nla_for_each_nested(attr, |
| 5402 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5403 | tmp) { |
| 5404 | enum ieee80211_band band = nla_type(attr); |
| 5405 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5406 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5407 | err = -EINVAL; |
| 5408 | goto out_free; |
| 5409 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5410 | |
| 5411 | if (!wiphy->bands[band]) |
| 5412 | continue; |
| 5413 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5414 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5415 | nla_data(attr), |
| 5416 | nla_len(attr), |
| 5417 | &request->rates[band]); |
| 5418 | if (err) |
| 5419 | goto out_free; |
| 5420 | } |
| 5421 | } |
| 5422 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5423 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5424 | request->flags = nla_get_u32( |
| 5425 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5426 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5427 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5428 | err = -EOPNOTSUPP; |
| 5429 | goto out_free; |
| 5430 | } |
| 5431 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5432 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5433 | request->no_cck = |
| 5434 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5435 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5436 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5437 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5438 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5439 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5440 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5441 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5442 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5443 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5444 | nl80211_send_scan_start(rdev, wdev); |
| 5445 | if (wdev->netdev) |
| 5446 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5447 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5448 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5449 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5450 | kfree(request); |
| 5451 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5452 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5453 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5454 | return err; |
| 5455 | } |
| 5456 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5457 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5458 | struct genl_info *info) |
| 5459 | { |
| 5460 | struct cfg80211_sched_scan_request *request; |
| 5461 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5462 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5463 | struct nlattr *attr; |
| 5464 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5465 | 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] | 5466 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5467 | enum ieee80211_band band; |
| 5468 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5469 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5470 | |
| 5471 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5472 | !rdev->ops->sched_scan_start) |
| 5473 | return -EOPNOTSUPP; |
| 5474 | |
| 5475 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5476 | return -EINVAL; |
| 5477 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5478 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5479 | return -EINVAL; |
| 5480 | |
| 5481 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5482 | if (interval == 0) |
| 5483 | return -EINVAL; |
| 5484 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5485 | wiphy = &rdev->wiphy; |
| 5486 | |
| 5487 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5488 | n_channels = validate_scan_freqs( |
| 5489 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5490 | if (!n_channels) |
| 5491 | return -EINVAL; |
| 5492 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5493 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5494 | } |
| 5495 | |
| 5496 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5497 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5498 | tmp) |
| 5499 | n_ssids++; |
| 5500 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5501 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5502 | return -EINVAL; |
| 5503 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5504 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5505 | nla_for_each_nested(attr, |
| 5506 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5507 | tmp) |
| 5508 | n_match_sets++; |
| 5509 | |
| 5510 | if (n_match_sets > wiphy->max_match_sets) |
| 5511 | return -EINVAL; |
| 5512 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5513 | if (info->attrs[NL80211_ATTR_IE]) |
| 5514 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5515 | else |
| 5516 | ie_len = 0; |
| 5517 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5518 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5519 | return -EINVAL; |
| 5520 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5521 | if (rdev->sched_scan_req) { |
| 5522 | err = -EINPROGRESS; |
| 5523 | goto out; |
| 5524 | } |
| 5525 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5526 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5527 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5528 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5529 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5530 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5531 | if (!request) { |
| 5532 | err = -ENOMEM; |
| 5533 | goto out; |
| 5534 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5535 | |
| 5536 | if (n_ssids) |
| 5537 | request->ssids = (void *)&request->channels[n_channels]; |
| 5538 | request->n_ssids = n_ssids; |
| 5539 | if (ie_len) { |
| 5540 | if (request->ssids) |
| 5541 | request->ie = (void *)(request->ssids + n_ssids); |
| 5542 | else |
| 5543 | request->ie = (void *)(request->channels + n_channels); |
| 5544 | } |
| 5545 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5546 | if (n_match_sets) { |
| 5547 | if (request->ie) |
| 5548 | request->match_sets = (void *)(request->ie + ie_len); |
| 5549 | else if (request->ssids) |
| 5550 | request->match_sets = |
| 5551 | (void *)(request->ssids + n_ssids); |
| 5552 | else |
| 5553 | request->match_sets = |
| 5554 | (void *)(request->channels + n_channels); |
| 5555 | } |
| 5556 | request->n_match_sets = n_match_sets; |
| 5557 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5558 | i = 0; |
| 5559 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5560 | /* user specified, bail out if channel not found */ |
| 5561 | nla_for_each_nested(attr, |
| 5562 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5563 | tmp) { |
| 5564 | struct ieee80211_channel *chan; |
| 5565 | |
| 5566 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5567 | |
| 5568 | if (!chan) { |
| 5569 | err = -EINVAL; |
| 5570 | goto out_free; |
| 5571 | } |
| 5572 | |
| 5573 | /* ignore disabled channels */ |
| 5574 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5575 | continue; |
| 5576 | |
| 5577 | request->channels[i] = chan; |
| 5578 | i++; |
| 5579 | } |
| 5580 | } else { |
| 5581 | /* all channels */ |
| 5582 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5583 | int j; |
| 5584 | if (!wiphy->bands[band]) |
| 5585 | continue; |
| 5586 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5587 | struct ieee80211_channel *chan; |
| 5588 | |
| 5589 | chan = &wiphy->bands[band]->channels[j]; |
| 5590 | |
| 5591 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5592 | continue; |
| 5593 | |
| 5594 | request->channels[i] = chan; |
| 5595 | i++; |
| 5596 | } |
| 5597 | } |
| 5598 | } |
| 5599 | |
| 5600 | if (!i) { |
| 5601 | err = -EINVAL; |
| 5602 | goto out_free; |
| 5603 | } |
| 5604 | |
| 5605 | request->n_channels = i; |
| 5606 | |
| 5607 | i = 0; |
| 5608 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5609 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5610 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5611 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5612 | err = -EINVAL; |
| 5613 | goto out_free; |
| 5614 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5615 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5616 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5617 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5618 | i++; |
| 5619 | } |
| 5620 | } |
| 5621 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5622 | i = 0; |
| 5623 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5624 | nla_for_each_nested(attr, |
| 5625 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5626 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5627 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5628 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5629 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5630 | nla_data(attr), nla_len(attr), |
| 5631 | nl80211_match_policy); |
| 5632 | if (err) |
| 5633 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5634 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5635 | if (ssid) { |
| 5636 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5637 | err = -EINVAL; |
| 5638 | goto out_free; |
| 5639 | } |
| 5640 | memcpy(request->match_sets[i].ssid.ssid, |
| 5641 | nla_data(ssid), nla_len(ssid)); |
| 5642 | request->match_sets[i].ssid.ssid_len = |
| 5643 | nla_len(ssid); |
| 5644 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5645 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5646 | if (rssi) |
| 5647 | request->rssi_thold = nla_get_u32(rssi); |
| 5648 | else |
| 5649 | request->rssi_thold = |
| 5650 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5651 | i++; |
| 5652 | } |
| 5653 | } |
| 5654 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5655 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5656 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5657 | memcpy((void *)request->ie, |
| 5658 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5659 | request->ie_len); |
| 5660 | } |
| 5661 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5662 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5663 | request->flags = nla_get_u32( |
| 5664 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5665 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5666 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5667 | err = -EOPNOTSUPP; |
| 5668 | goto out_free; |
| 5669 | } |
| 5670 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5671 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5672 | request->dev = dev; |
| 5673 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5674 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5675 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5676 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5677 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5678 | if (!err) { |
| 5679 | rdev->sched_scan_req = request; |
| 5680 | nl80211_send_sched_scan(rdev, dev, |
| 5681 | NL80211_CMD_START_SCHED_SCAN); |
| 5682 | goto out; |
| 5683 | } |
| 5684 | |
| 5685 | out_free: |
| 5686 | kfree(request); |
| 5687 | out: |
| 5688 | return err; |
| 5689 | } |
| 5690 | |
| 5691 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5692 | struct genl_info *info) |
| 5693 | { |
| 5694 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5695 | |
| 5696 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5697 | !rdev->ops->sched_scan_stop) |
| 5698 | return -EOPNOTSUPP; |
| 5699 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5700 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5701 | } |
| 5702 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5703 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5704 | struct genl_info *info) |
| 5705 | { |
| 5706 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5707 | struct net_device *dev = info->user_ptr[1]; |
| 5708 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5709 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5710 | enum nl80211_dfs_regions dfs_region; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5711 | int err; |
| 5712 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5713 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 5714 | if (dfs_region == NL80211_DFS_UNSET) |
| 5715 | return -EINVAL; |
| 5716 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5717 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5718 | if (err) |
| 5719 | return err; |
| 5720 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5721 | if (netif_carrier_ok(dev)) |
| 5722 | return -EBUSY; |
| 5723 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5724 | if (wdev->cac_started) |
| 5725 | return -EBUSY; |
| 5726 | |
| 5727 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5728 | if (err < 0) |
| 5729 | return err; |
| 5730 | |
| 5731 | if (err == 0) |
| 5732 | return -EINVAL; |
| 5733 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 5734 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5735 | return -EINVAL; |
| 5736 | |
| 5737 | if (!rdev->ops->start_radar_detection) |
| 5738 | return -EOPNOTSUPP; |
| 5739 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5740 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5741 | chandef.chan, CHAN_MODE_SHARED, |
| 5742 | BIT(chandef.width)); |
| 5743 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5744 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5745 | |
| 5746 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5747 | if (!err) { |
| 5748 | wdev->channel = chandef.chan; |
| 5749 | wdev->cac_started = true; |
| 5750 | wdev->cac_start_time = jiffies; |
| 5751 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5752 | return err; |
| 5753 | } |
| 5754 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5755 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5756 | { |
| 5757 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5758 | struct net_device *dev = info->user_ptr[1]; |
| 5759 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5760 | struct cfg80211_csa_settings params; |
| 5761 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5762 | * function is called under RTNL lock, so this should not be a problem. |
| 5763 | */ |
| 5764 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5765 | u8 radar_detect_width = 0; |
| 5766 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5767 | bool need_new_beacon = false; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5768 | |
| 5769 | if (!rdev->ops->channel_switch || |
| 5770 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5771 | return -EOPNOTSUPP; |
| 5772 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5773 | switch (dev->ieee80211_ptr->iftype) { |
| 5774 | case NL80211_IFTYPE_AP: |
| 5775 | case NL80211_IFTYPE_P2P_GO: |
| 5776 | need_new_beacon = true; |
| 5777 | |
| 5778 | /* useless if AP is not running */ |
| 5779 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5780 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5781 | break; |
| 5782 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5783 | if (!wdev->ssid_len) |
| 5784 | return -ENOTCONN; |
| 5785 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 5786 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5787 | if (!wdev->mesh_id_len) |
| 5788 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5789 | break; |
| 5790 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5791 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5792 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5793 | |
| 5794 | memset(¶ms, 0, sizeof(params)); |
| 5795 | |
| 5796 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5797 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5798 | return -EINVAL; |
| 5799 | |
| 5800 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 5801 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5802 | return -EINVAL; |
| 5803 | |
| 5804 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5805 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5806 | if (!need_new_beacon) |
| 5807 | goto skip_beacons; |
| 5808 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5809 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5810 | if (err) |
| 5811 | return err; |
| 5812 | |
| 5813 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5814 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5815 | nl80211_policy); |
| 5816 | if (err) |
| 5817 | return err; |
| 5818 | |
| 5819 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5820 | if (err) |
| 5821 | return err; |
| 5822 | |
| 5823 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5824 | return -EINVAL; |
| 5825 | |
| 5826 | params.counter_offset_beacon = |
| 5827 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5828 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) |
| 5829 | return -EINVAL; |
| 5830 | |
| 5831 | /* sanity check - counters should be the same */ |
| 5832 | if (params.beacon_csa.tail[params.counter_offset_beacon] != |
| 5833 | params.count) |
| 5834 | return -EINVAL; |
| 5835 | |
| 5836 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
| 5837 | params.counter_offset_presp = |
| 5838 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5839 | if (params.counter_offset_presp >= |
| 5840 | params.beacon_csa.probe_resp_len) |
| 5841 | return -EINVAL; |
| 5842 | |
| 5843 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != |
| 5844 | params.count) |
| 5845 | return -EINVAL; |
| 5846 | } |
| 5847 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5848 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5849 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5850 | if (err) |
| 5851 | return err; |
| 5852 | |
| 5853 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
| 5854 | return -EINVAL; |
| 5855 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5856 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP || |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 5857 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO || |
| 5858 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) { |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5859 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 5860 | ¶ms.chandef); |
| 5861 | if (err < 0) { |
| 5862 | return err; |
| 5863 | } else if (err) { |
| 5864 | radar_detect_width = BIT(params.chandef.width); |
| 5865 | params.radar_required = true; |
| 5866 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5867 | } |
| 5868 | |
| 5869 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5870 | params.chandef.chan, |
| 5871 | CHAN_MODE_SHARED, |
| 5872 | radar_detect_width); |
| 5873 | if (err) |
| 5874 | return err; |
| 5875 | |
| 5876 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 5877 | params.block_tx = true; |
| 5878 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5879 | wdev_lock(wdev); |
| 5880 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 5881 | wdev_unlock(wdev); |
| 5882 | |
| 5883 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5884 | } |
| 5885 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5886 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5887 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5888 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5889 | struct wireless_dev *wdev, |
| 5890 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5891 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5892 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5893 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5894 | void *hdr; |
| 5895 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5896 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5897 | |
| 5898 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5899 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5900 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5901 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5902 | if (!hdr) |
| 5903 | return -1; |
| 5904 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5905 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5906 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5907 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5908 | goto nla_put_failure; |
| 5909 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5910 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5911 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5912 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5913 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5914 | |
| 5915 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5916 | if (!bss) |
| 5917 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5918 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5919 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5920 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5921 | |
| 5922 | rcu_read_lock(); |
| 5923 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5924 | if (ies) { |
| 5925 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5926 | goto fail_unlock_rcu; |
| 5927 | tsf = true; |
| 5928 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5929 | ies->len, ies->data)) |
| 5930 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5931 | } |
| 5932 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5933 | if (ies) { |
| 5934 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5935 | goto fail_unlock_rcu; |
| 5936 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5937 | ies->len, ies->data)) |
| 5938 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5939 | } |
| 5940 | rcu_read_unlock(); |
| 5941 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5942 | if (res->beacon_interval && |
| 5943 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5944 | goto nla_put_failure; |
| 5945 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5946 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 5947 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5948 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5949 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5950 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5951 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5952 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5953 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5954 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5955 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5956 | break; |
| 5957 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5958 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5959 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5960 | break; |
| 5961 | default: |
| 5962 | break; |
| 5963 | } |
| 5964 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5965 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5966 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5967 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5968 | if (intbss == wdev->current_bss && |
| 5969 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5970 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5971 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5972 | break; |
| 5973 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5974 | if (intbss == wdev->current_bss && |
| 5975 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5976 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5977 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5978 | break; |
| 5979 | default: |
| 5980 | break; |
| 5981 | } |
| 5982 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5983 | nla_nest_end(msg, bss); |
| 5984 | |
| 5985 | return genlmsg_end(msg, hdr); |
| 5986 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5987 | fail_unlock_rcu: |
| 5988 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5989 | nla_put_failure: |
| 5990 | genlmsg_cancel(msg, hdr); |
| 5991 | return -EMSGSIZE; |
| 5992 | } |
| 5993 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5994 | 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] | 5995 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5996 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5997 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5998 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5999 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6000 | int err; |
| 6001 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6002 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6003 | if (err) |
| 6004 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6005 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6006 | wdev_lock(wdev); |
| 6007 | spin_lock_bh(&rdev->bss_lock); |
| 6008 | cfg80211_bss_expire(rdev); |
| 6009 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6010 | cb->seq = rdev->bss_generation; |
| 6011 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6012 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6013 | if (++idx <= start) |
| 6014 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6015 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6016 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6017 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6018 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6019 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6020 | } |
| 6021 | } |
| 6022 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6023 | spin_unlock_bh(&rdev->bss_lock); |
| 6024 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6025 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6026 | cb->args[2] = idx; |
| 6027 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6028 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6029 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6030 | } |
| 6031 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6032 | 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] | 6033 | int flags, struct net_device *dev, |
| 6034 | struct survey_info *survey) |
| 6035 | { |
| 6036 | void *hdr; |
| 6037 | struct nlattr *infoattr; |
| 6038 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6039 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6040 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6041 | if (!hdr) |
| 6042 | return -ENOMEM; |
| 6043 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6044 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6045 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6046 | |
| 6047 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6048 | if (!infoattr) |
| 6049 | goto nla_put_failure; |
| 6050 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6051 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 6052 | survey->channel->center_freq)) |
| 6053 | goto nla_put_failure; |
| 6054 | |
| 6055 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6056 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6057 | goto nla_put_failure; |
| 6058 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6059 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6060 | goto nla_put_failure; |
| 6061 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6062 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6063 | survey->channel_time)) |
| 6064 | goto nla_put_failure; |
| 6065 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6066 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6067 | survey->channel_time_busy)) |
| 6068 | goto nla_put_failure; |
| 6069 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6070 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6071 | survey->channel_time_ext_busy)) |
| 6072 | goto nla_put_failure; |
| 6073 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6074 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6075 | survey->channel_time_rx)) |
| 6076 | goto nla_put_failure; |
| 6077 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6078 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6079 | survey->channel_time_tx)) |
| 6080 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6081 | |
| 6082 | nla_nest_end(msg, infoattr); |
| 6083 | |
| 6084 | return genlmsg_end(msg, hdr); |
| 6085 | |
| 6086 | nla_put_failure: |
| 6087 | genlmsg_cancel(msg, hdr); |
| 6088 | return -EMSGSIZE; |
| 6089 | } |
| 6090 | |
| 6091 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6092 | struct netlink_callback *cb) |
| 6093 | { |
| 6094 | struct survey_info survey; |
| 6095 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6096 | struct wireless_dev *wdev; |
| 6097 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6098 | int res; |
| 6099 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6100 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6101 | if (res) |
| 6102 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6103 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6104 | if (!wdev->netdev) { |
| 6105 | res = -EINVAL; |
| 6106 | goto out_err; |
| 6107 | } |
| 6108 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6109 | if (!dev->ops->dump_survey) { |
| 6110 | res = -EOPNOTSUPP; |
| 6111 | goto out_err; |
| 6112 | } |
| 6113 | |
| 6114 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6115 | struct ieee80211_channel *chan; |
| 6116 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6117 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6118 | if (res == -ENOENT) |
| 6119 | break; |
| 6120 | if (res) |
| 6121 | goto out_err; |
| 6122 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6123 | /* Survey without a channel doesn't make sense */ |
| 6124 | if (!survey.channel) { |
| 6125 | res = -EINVAL; |
| 6126 | goto out; |
| 6127 | } |
| 6128 | |
| 6129 | chan = ieee80211_get_channel(&dev->wiphy, |
| 6130 | survey.channel->center_freq); |
| 6131 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6132 | survey_idx++; |
| 6133 | continue; |
| 6134 | } |
| 6135 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6136 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6137 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6138 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6139 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6140 | goto out; |
| 6141 | survey_idx++; |
| 6142 | } |
| 6143 | |
| 6144 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6145 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6146 | res = skb->len; |
| 6147 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6148 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6149 | return res; |
| 6150 | } |
| 6151 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6152 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6153 | { |
| 6154 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6155 | NL80211_WPA_VERSION_2)); |
| 6156 | } |
| 6157 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6158 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6159 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6160 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6161 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6162 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6163 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6164 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6165 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6166 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6167 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6168 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6169 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6170 | return -EINVAL; |
| 6171 | |
| 6172 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6173 | return -EINVAL; |
| 6174 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6175 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6176 | return -EINVAL; |
| 6177 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6178 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6179 | return -EINVAL; |
| 6180 | |
| 6181 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6182 | return -EINVAL; |
| 6183 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6184 | err = nl80211_parse_key(info, &key); |
| 6185 | if (err) |
| 6186 | return err; |
| 6187 | |
| 6188 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6189 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6190 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6191 | if (!key.p.key || !key.p.key_len) |
| 6192 | return -EINVAL; |
| 6193 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6194 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6195 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6196 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6197 | return -EINVAL; |
| 6198 | if (key.idx > 4) |
| 6199 | return -EINVAL; |
| 6200 | } else { |
| 6201 | key.p.key_len = 0; |
| 6202 | key.p.key = NULL; |
| 6203 | } |
| 6204 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6205 | if (key.idx >= 0) { |
| 6206 | int i; |
| 6207 | bool ok = false; |
| 6208 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6209 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6210 | ok = true; |
| 6211 | break; |
| 6212 | } |
| 6213 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6214 | if (!ok) |
| 6215 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6216 | } |
| 6217 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6218 | if (!rdev->ops->auth) |
| 6219 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6220 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6221 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6222 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6223 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6224 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6225 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6226 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6227 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6228 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6229 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6230 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6231 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6232 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6233 | |
| 6234 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6235 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6236 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6237 | } |
| 6238 | |
| 6239 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6240 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6241 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6242 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6243 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6244 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6245 | return -EINVAL; |
| 6246 | |
| 6247 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6248 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6249 | return -EINVAL; |
| 6250 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6251 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6252 | /* need to include at least Auth Transaction and Status Code */ |
| 6253 | if (sae_data_len < 4) |
| 6254 | return -EINVAL; |
| 6255 | } |
| 6256 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6257 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6258 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6259 | /* |
| 6260 | * Since we no longer track auth state, ignore |
| 6261 | * requests to only change local state. |
| 6262 | */ |
| 6263 | if (local_state_change) |
| 6264 | return 0; |
| 6265 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6266 | wdev_lock(dev->ieee80211_ptr); |
| 6267 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6268 | ssid, ssid_len, ie, ie_len, |
| 6269 | key.p.key, key.p.key_len, key.idx, |
| 6270 | sae_data, sae_data_len); |
| 6271 | wdev_unlock(dev->ieee80211_ptr); |
| 6272 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6273 | } |
| 6274 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6275 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6276 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6277 | struct cfg80211_crypto_settings *settings, |
| 6278 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6279 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6280 | memset(settings, 0, sizeof(*settings)); |
| 6281 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6282 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6283 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6284 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6285 | u16 proto; |
| 6286 | proto = nla_get_u16( |
| 6287 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6288 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6289 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6290 | proto != ETH_P_PAE) |
| 6291 | return -EINVAL; |
| 6292 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6293 | settings->control_port_no_encrypt = true; |
| 6294 | } else |
| 6295 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6296 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6297 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6298 | void *data; |
| 6299 | int len, i; |
| 6300 | |
| 6301 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6302 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6303 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6304 | |
| 6305 | if (len % sizeof(u32)) |
| 6306 | return -EINVAL; |
| 6307 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6308 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6309 | return -EINVAL; |
| 6310 | |
| 6311 | memcpy(settings->ciphers_pairwise, data, len); |
| 6312 | |
| 6313 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6314 | if (!cfg80211_supported_cipher_suite( |
| 6315 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6316 | settings->ciphers_pairwise[i])) |
| 6317 | return -EINVAL; |
| 6318 | } |
| 6319 | |
| 6320 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6321 | settings->cipher_group = |
| 6322 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6323 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6324 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6325 | return -EINVAL; |
| 6326 | } |
| 6327 | |
| 6328 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6329 | settings->wpa_versions = |
| 6330 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6331 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6332 | return -EINVAL; |
| 6333 | } |
| 6334 | |
| 6335 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6336 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6337 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6338 | |
| 6339 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6340 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6341 | settings->n_akm_suites = len / sizeof(u32); |
| 6342 | |
| 6343 | if (len % sizeof(u32)) |
| 6344 | return -EINVAL; |
| 6345 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6346 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6347 | return -EINVAL; |
| 6348 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6349 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6350 | } |
| 6351 | |
| 6352 | return 0; |
| 6353 | } |
| 6354 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6355 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6356 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6357 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6358 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6359 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6360 | struct cfg80211_assoc_request req = {}; |
| 6361 | const u8 *bssid, *ssid; |
| 6362 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6363 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6364 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6365 | return -EINVAL; |
| 6366 | |
| 6367 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6368 | !info->attrs[NL80211_ATTR_SSID] || |
| 6369 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6370 | return -EINVAL; |
| 6371 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6372 | if (!rdev->ops->assoc) |
| 6373 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6374 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6375 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6376 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6377 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6378 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6379 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6380 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6381 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6382 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6383 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6384 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6385 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6386 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6387 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6388 | |
| 6389 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6390 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6391 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6392 | } |
| 6393 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6394 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6395 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6396 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6397 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6398 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6399 | else if (mfp != NL80211_MFP_NO) |
| 6400 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6401 | } |
| 6402 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6403 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6404 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6405 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6406 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6407 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6408 | |
| 6409 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6410 | memcpy(&req.ht_capa_mask, |
| 6411 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6412 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6413 | |
| 6414 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6415 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6416 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6417 | memcpy(&req.ht_capa, |
| 6418 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6419 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6420 | } |
| 6421 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6422 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6423 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6424 | |
| 6425 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6426 | memcpy(&req.vht_capa_mask, |
| 6427 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6428 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6429 | |
| 6430 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6431 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6432 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6433 | memcpy(&req.vht_capa, |
| 6434 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6435 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6436 | } |
| 6437 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6438 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6439 | if (!err) { |
| 6440 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6441 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6442 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6443 | wdev_unlock(dev->ieee80211_ptr); |
| 6444 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6445 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6446 | return err; |
| 6447 | } |
| 6448 | |
| 6449 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6450 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6451 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6452 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6453 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6454 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6455 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6456 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6457 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6458 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6459 | return -EINVAL; |
| 6460 | |
| 6461 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6462 | return -EINVAL; |
| 6463 | |
| 6464 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6465 | return -EINVAL; |
| 6466 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6467 | if (!rdev->ops->deauth) |
| 6468 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6469 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6470 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6471 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6472 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6473 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6474 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6475 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6476 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6477 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6478 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6479 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6480 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6481 | |
| 6482 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6483 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6484 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6485 | } |
| 6486 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6487 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6488 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6489 | wdev_lock(dev->ieee80211_ptr); |
| 6490 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6491 | local_state_change); |
| 6492 | wdev_unlock(dev->ieee80211_ptr); |
| 6493 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6494 | } |
| 6495 | |
| 6496 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6497 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6498 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6499 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6500 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6501 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6502 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6503 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6504 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6505 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6506 | return -EINVAL; |
| 6507 | |
| 6508 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6509 | return -EINVAL; |
| 6510 | |
| 6511 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6512 | return -EINVAL; |
| 6513 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6514 | if (!rdev->ops->disassoc) |
| 6515 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6516 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6517 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6518 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6519 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6520 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6521 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6522 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6523 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6524 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6525 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6526 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6527 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6528 | |
| 6529 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6530 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6531 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6532 | } |
| 6533 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6534 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6535 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6536 | wdev_lock(dev->ieee80211_ptr); |
| 6537 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6538 | local_state_change); |
| 6539 | wdev_unlock(dev->ieee80211_ptr); |
| 6540 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6541 | } |
| 6542 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6543 | static bool |
| 6544 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6545 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6546 | int rateval) |
| 6547 | { |
| 6548 | struct wiphy *wiphy = &rdev->wiphy; |
| 6549 | bool found = false; |
| 6550 | int band, i; |
| 6551 | |
| 6552 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6553 | struct ieee80211_supported_band *sband; |
| 6554 | |
| 6555 | sband = wiphy->bands[band]; |
| 6556 | if (!sband) |
| 6557 | continue; |
| 6558 | |
| 6559 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6560 | if (sband->bitrates[i].bitrate == rateval) { |
| 6561 | mcast_rate[band] = i + 1; |
| 6562 | found = true; |
| 6563 | break; |
| 6564 | } |
| 6565 | } |
| 6566 | } |
| 6567 | |
| 6568 | return found; |
| 6569 | } |
| 6570 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6571 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6572 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6573 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6574 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6575 | struct cfg80211_ibss_params ibss; |
| 6576 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6577 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6578 | int err; |
| 6579 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6580 | memset(&ibss, 0, sizeof(ibss)); |
| 6581 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6582 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6583 | return -EINVAL; |
| 6584 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6585 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6586 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6587 | return -EINVAL; |
| 6588 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6589 | ibss.beacon_interval = 100; |
| 6590 | |
| 6591 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6592 | ibss.beacon_interval = |
| 6593 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6594 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6595 | return -EINVAL; |
| 6596 | } |
| 6597 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6598 | if (!rdev->ops->join_ibss) |
| 6599 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6600 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6601 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6602 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6603 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6604 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6605 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6606 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6607 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6608 | |
| 6609 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6610 | return -EINVAL; |
| 6611 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6612 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6613 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6614 | |
| 6615 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6616 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6617 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6618 | } |
| 6619 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6620 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6621 | if (err) |
| 6622 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6623 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6624 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6625 | return -EINVAL; |
| 6626 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6627 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6628 | case NL80211_CHAN_WIDTH_5: |
| 6629 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6630 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6631 | break; |
| 6632 | case NL80211_CHAN_WIDTH_20: |
| 6633 | case NL80211_CHAN_WIDTH_40: |
| 6634 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6635 | break; |
| 6636 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6637 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6638 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6639 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6640 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6641 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6642 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6643 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6644 | u8 *rates = |
| 6645 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6646 | int n_rates = |
| 6647 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6648 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6649 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6650 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6651 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6652 | &ibss.basic_rates); |
| 6653 | if (err) |
| 6654 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6655 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6656 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6657 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6658 | memcpy(&ibss.ht_capa_mask, |
| 6659 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6660 | sizeof(ibss.ht_capa_mask)); |
| 6661 | |
| 6662 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6663 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6664 | return -EINVAL; |
| 6665 | memcpy(&ibss.ht_capa, |
| 6666 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6667 | sizeof(ibss.ht_capa)); |
| 6668 | } |
| 6669 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6670 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6671 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6672 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6673 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6674 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6675 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6676 | bool no_ht = false; |
| 6677 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6678 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6679 | info->attrs[NL80211_ATTR_KEYS], |
| 6680 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6681 | if (IS_ERR(connkeys)) |
| 6682 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6683 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6684 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6685 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6686 | kfree(connkeys); |
| 6687 | return -EINVAL; |
| 6688 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6689 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6690 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6691 | ibss.control_port = |
| 6692 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6693 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 6694 | ibss.userspace_handles_dfs = |
| 6695 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 6696 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6697 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6698 | if (err) |
| 6699 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6700 | return err; |
| 6701 | } |
| 6702 | |
| 6703 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6704 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6705 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6706 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6707 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6708 | if (!rdev->ops->leave_ibss) |
| 6709 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6710 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6711 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6712 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6713 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6714 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6715 | } |
| 6716 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6717 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6718 | { |
| 6719 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6720 | struct net_device *dev = info->user_ptr[1]; |
| 6721 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6722 | u32 nla_rate; |
| 6723 | int err; |
| 6724 | |
| 6725 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6726 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6727 | return -EOPNOTSUPP; |
| 6728 | |
| 6729 | if (!rdev->ops->set_mcast_rate) |
| 6730 | return -EOPNOTSUPP; |
| 6731 | |
| 6732 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6733 | |
| 6734 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6735 | return -EINVAL; |
| 6736 | |
| 6737 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6738 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6739 | return -EINVAL; |
| 6740 | |
| 6741 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6742 | |
| 6743 | return err; |
| 6744 | } |
| 6745 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6746 | static struct sk_buff * |
| 6747 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 6748 | int approxlen, u32 portid, u32 seq, |
| 6749 | enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6750 | enum nl80211_attrs attr, |
| 6751 | const struct nl80211_vendor_cmd_info *info, |
| 6752 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6753 | { |
| 6754 | struct sk_buff *skb; |
| 6755 | void *hdr; |
| 6756 | struct nlattr *data; |
| 6757 | |
| 6758 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6759 | if (!skb) |
| 6760 | return NULL; |
| 6761 | |
| 6762 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 6763 | if (!hdr) { |
| 6764 | kfree_skb(skb); |
| 6765 | return NULL; |
| 6766 | } |
| 6767 | |
| 6768 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6769 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6770 | |
| 6771 | if (info) { |
| 6772 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 6773 | info->vendor_id)) |
| 6774 | goto nla_put_failure; |
| 6775 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 6776 | info->subcmd)) |
| 6777 | goto nla_put_failure; |
| 6778 | } |
| 6779 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6780 | data = nla_nest_start(skb, attr); |
| 6781 | |
| 6782 | ((void **)skb->cb)[0] = rdev; |
| 6783 | ((void **)skb->cb)[1] = hdr; |
| 6784 | ((void **)skb->cb)[2] = data; |
| 6785 | |
| 6786 | return skb; |
| 6787 | |
| 6788 | nla_put_failure: |
| 6789 | kfree_skb(skb); |
| 6790 | return NULL; |
| 6791 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6792 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 6793 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
| 6794 | enum nl80211_commands cmd, |
| 6795 | enum nl80211_attrs attr, |
| 6796 | int vendor_event_idx, |
| 6797 | int approxlen, gfp_t gfp) |
| 6798 | { |
| 6799 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6800 | const struct nl80211_vendor_cmd_info *info; |
| 6801 | |
| 6802 | switch (cmd) { |
| 6803 | case NL80211_CMD_TESTMODE: |
| 6804 | if (WARN_ON(vendor_event_idx != -1)) |
| 6805 | return NULL; |
| 6806 | info = NULL; |
| 6807 | break; |
| 6808 | case NL80211_CMD_VENDOR: |
| 6809 | if (WARN_ON(vendor_event_idx < 0 || |
| 6810 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 6811 | return NULL; |
| 6812 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 6813 | break; |
| 6814 | default: |
| 6815 | WARN_ON(1); |
| 6816 | return NULL; |
| 6817 | } |
| 6818 | |
| 6819 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
| 6820 | cmd, attr, info, gfp); |
| 6821 | } |
| 6822 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 6823 | |
| 6824 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 6825 | { |
| 6826 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6827 | void *hdr = ((void **)skb->cb)[1]; |
| 6828 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6829 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 6830 | |
| 6831 | nla_nest_end(skb, data); |
| 6832 | genlmsg_end(skb, hdr); |
| 6833 | |
| 6834 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 6835 | mcgrp = NL80211_MCGRP_VENDOR; |
| 6836 | |
| 6837 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 6838 | mcgrp, gfp); |
| 6839 | } |
| 6840 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 6841 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6842 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6843 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6844 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6845 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6846 | struct wireless_dev *wdev = |
| 6847 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6848 | int err; |
| 6849 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6850 | if (!rdev->ops->testmode_cmd) |
| 6851 | return -EOPNOTSUPP; |
| 6852 | |
| 6853 | if (IS_ERR(wdev)) { |
| 6854 | err = PTR_ERR(wdev); |
| 6855 | if (err != -EINVAL) |
| 6856 | return err; |
| 6857 | wdev = NULL; |
| 6858 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 6859 | return -EINVAL; |
| 6860 | } |
| 6861 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6862 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6863 | return -EINVAL; |
| 6864 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6865 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6866 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6867 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6868 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6869 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6870 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6871 | return err; |
| 6872 | } |
| 6873 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6874 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6875 | struct netlink_callback *cb) |
| 6876 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6877 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6878 | int err; |
| 6879 | long phy_idx; |
| 6880 | void *data = NULL; |
| 6881 | int data_len = 0; |
| 6882 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6883 | rtnl_lock(); |
| 6884 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6885 | if (cb->args[0]) { |
| 6886 | /* |
| 6887 | * 0 is a valid index, but not valid for args[0], |
| 6888 | * so we need to offset by 1. |
| 6889 | */ |
| 6890 | phy_idx = cb->args[0] - 1; |
| 6891 | } else { |
| 6892 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6893 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6894 | nl80211_policy); |
| 6895 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6896 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6897 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6898 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6899 | nl80211_fam.attrbuf); |
| 6900 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6901 | err = PTR_ERR(rdev); |
| 6902 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6903 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6904 | phy_idx = rdev->wiphy_idx; |
| 6905 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6906 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6907 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6908 | cb->args[1] = |
| 6909 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6910 | } |
| 6911 | |
| 6912 | if (cb->args[1]) { |
| 6913 | data = nla_data((void *)cb->args[1]); |
| 6914 | data_len = nla_len((void *)cb->args[1]); |
| 6915 | } |
| 6916 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6917 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6918 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6919 | err = -ENOENT; |
| 6920 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6921 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6922 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6923 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6924 | err = -EOPNOTSUPP; |
| 6925 | goto out_err; |
| 6926 | } |
| 6927 | |
| 6928 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6929 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6930 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6931 | NL80211_CMD_TESTMODE); |
| 6932 | struct nlattr *tmdata; |
| 6933 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 6934 | if (!hdr) |
| 6935 | break; |
| 6936 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6937 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6938 | genlmsg_cancel(skb, hdr); |
| 6939 | break; |
| 6940 | } |
| 6941 | |
| 6942 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6943 | if (!tmdata) { |
| 6944 | genlmsg_cancel(skb, hdr); |
| 6945 | break; |
| 6946 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6947 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6948 | nla_nest_end(skb, tmdata); |
| 6949 | |
| 6950 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6951 | genlmsg_cancel(skb, hdr); |
| 6952 | break; |
| 6953 | } else if (err) { |
| 6954 | genlmsg_cancel(skb, hdr); |
| 6955 | goto out_err; |
| 6956 | } |
| 6957 | |
| 6958 | genlmsg_end(skb, hdr); |
| 6959 | } |
| 6960 | |
| 6961 | err = skb->len; |
| 6962 | /* see above */ |
| 6963 | cb->args[0] = phy_idx + 1; |
| 6964 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6965 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6966 | return err; |
| 6967 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6968 | #endif |
| 6969 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6970 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6971 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6972 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6973 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6974 | struct cfg80211_connect_params connect; |
| 6975 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6976 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6977 | int err; |
| 6978 | |
| 6979 | memset(&connect, 0, sizeof(connect)); |
| 6980 | |
| 6981 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6982 | return -EINVAL; |
| 6983 | |
| 6984 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6985 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6986 | return -EINVAL; |
| 6987 | |
| 6988 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6989 | connect.auth_type = |
| 6990 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6991 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6992 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6993 | return -EINVAL; |
| 6994 | } else |
| 6995 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6996 | |
| 6997 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6998 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6999 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7000 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7001 | if (err) |
| 7002 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7003 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7004 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7005 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7006 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7007 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7008 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7009 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7010 | connect.bg_scan_period = -1; |
| 7011 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 7012 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 7013 | connect.bg_scan_period = |
| 7014 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 7015 | } |
| 7016 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7017 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7018 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7019 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 7020 | connect.bssid_hint = |
| 7021 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7022 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7023 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7024 | |
| 7025 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7026 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7027 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7028 | } |
| 7029 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7030 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 7031 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 7032 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 7033 | connect.mfp != NL80211_MFP_NO) |
| 7034 | return -EINVAL; |
| 7035 | } else { |
| 7036 | connect.mfp = NL80211_MFP_NO; |
| 7037 | } |
| 7038 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7039 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7040 | connect.channel = nl80211_get_valid_chan( |
| 7041 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7042 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7043 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7044 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7045 | connect.channel_hint = nl80211_get_valid_chan( |
| 7046 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 7047 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7048 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7049 | } |
| 7050 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7051 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7052 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7053 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7054 | if (IS_ERR(connkeys)) |
| 7055 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7056 | } |
| 7057 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7058 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7059 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7060 | |
| 7061 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7062 | memcpy(&connect.ht_capa_mask, |
| 7063 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7064 | sizeof(connect.ht_capa_mask)); |
| 7065 | |
| 7066 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7067 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 7068 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7069 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7070 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7071 | memcpy(&connect.ht_capa, |
| 7072 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7073 | sizeof(connect.ht_capa)); |
| 7074 | } |
| 7075 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7076 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7077 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7078 | |
| 7079 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7080 | memcpy(&connect.vht_capa_mask, |
| 7081 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7082 | sizeof(connect.vht_capa_mask)); |
| 7083 | |
| 7084 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7085 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 7086 | kfree(connkeys); |
| 7087 | return -EINVAL; |
| 7088 | } |
| 7089 | memcpy(&connect.vht_capa, |
| 7090 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7091 | sizeof(connect.vht_capa)); |
| 7092 | } |
| 7093 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7094 | wdev_lock(dev->ieee80211_ptr); |
| 7095 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7096 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7097 | if (err) |
| 7098 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7099 | return err; |
| 7100 | } |
| 7101 | |
| 7102 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7103 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7104 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7105 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7106 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7107 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7108 | |
| 7109 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7110 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7111 | else |
| 7112 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7113 | |
| 7114 | if (reason == 0) |
| 7115 | return -EINVAL; |
| 7116 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7117 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7118 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7119 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7120 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7121 | wdev_lock(dev->ieee80211_ptr); |
| 7122 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7123 | wdev_unlock(dev->ieee80211_ptr); |
| 7124 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7125 | } |
| 7126 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7127 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7128 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7129 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7130 | struct net *net; |
| 7131 | int err; |
| 7132 | u32 pid; |
| 7133 | |
| 7134 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7135 | return -EINVAL; |
| 7136 | |
| 7137 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7138 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7139 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7140 | if (IS_ERR(net)) |
| 7141 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7142 | |
| 7143 | err = 0; |
| 7144 | |
| 7145 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7146 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7147 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7148 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7149 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7150 | return err; |
| 7151 | } |
| 7152 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7153 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7154 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7155 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7156 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7157 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7158 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7159 | struct cfg80211_pmksa pmksa; |
| 7160 | |
| 7161 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7162 | |
| 7163 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7164 | return -EINVAL; |
| 7165 | |
| 7166 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7167 | return -EINVAL; |
| 7168 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7169 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7170 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7171 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7172 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7173 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7174 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7175 | |
| 7176 | switch (info->genlhdr->cmd) { |
| 7177 | case NL80211_CMD_SET_PMKSA: |
| 7178 | rdev_ops = rdev->ops->set_pmksa; |
| 7179 | break; |
| 7180 | case NL80211_CMD_DEL_PMKSA: |
| 7181 | rdev_ops = rdev->ops->del_pmksa; |
| 7182 | break; |
| 7183 | default: |
| 7184 | WARN_ON(1); |
| 7185 | break; |
| 7186 | } |
| 7187 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7188 | if (!rdev_ops) |
| 7189 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7190 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7191 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7192 | } |
| 7193 | |
| 7194 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7195 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7196 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7197 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7198 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7199 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7200 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7201 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7202 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7203 | if (!rdev->ops->flush_pmksa) |
| 7204 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7205 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7206 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7207 | } |
| 7208 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7209 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7210 | { |
| 7211 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7212 | struct net_device *dev = info->user_ptr[1]; |
| 7213 | u8 action_code, dialog_token; |
| 7214 | u16 status_code; |
| 7215 | u8 *peer; |
| 7216 | |
| 7217 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7218 | !rdev->ops->tdls_mgmt) |
| 7219 | return -EOPNOTSUPP; |
| 7220 | |
| 7221 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7222 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7223 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7224 | !info->attrs[NL80211_ATTR_IE] || |
| 7225 | !info->attrs[NL80211_ATTR_MAC]) |
| 7226 | return -EINVAL; |
| 7227 | |
| 7228 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7229 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7230 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7231 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 7232 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7233 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 7234 | dialog_token, status_code, |
| 7235 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7236 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7237 | } |
| 7238 | |
| 7239 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7240 | { |
| 7241 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7242 | struct net_device *dev = info->user_ptr[1]; |
| 7243 | enum nl80211_tdls_operation operation; |
| 7244 | u8 *peer; |
| 7245 | |
| 7246 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7247 | !rdev->ops->tdls_oper) |
| 7248 | return -EOPNOTSUPP; |
| 7249 | |
| 7250 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7251 | !info->attrs[NL80211_ATTR_MAC]) |
| 7252 | return -EINVAL; |
| 7253 | |
| 7254 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7255 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7256 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7257 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7258 | } |
| 7259 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7260 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7261 | struct genl_info *info) |
| 7262 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7263 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7264 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7265 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7266 | struct sk_buff *msg; |
| 7267 | void *hdr; |
| 7268 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7269 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7270 | int err; |
| 7271 | |
| 7272 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7273 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7274 | return -EINVAL; |
| 7275 | |
| 7276 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7277 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7278 | if (!rdev->ops->remain_on_channel || |
| 7279 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7280 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7281 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7282 | /* |
| 7283 | * We should be on that channel for at least a minimum amount of |
| 7284 | * time (10ms) but no longer than the driver supports. |
| 7285 | */ |
| 7286 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7287 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7288 | return -EINVAL; |
| 7289 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7290 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7291 | if (err) |
| 7292 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7293 | |
| 7294 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7295 | if (!msg) |
| 7296 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7297 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7298 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7299 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7300 | if (!hdr) { |
| 7301 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7302 | goto free_msg; |
| 7303 | } |
| 7304 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7305 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7306 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7307 | |
| 7308 | if (err) |
| 7309 | goto free_msg; |
| 7310 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7311 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7312 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7313 | |
| 7314 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7315 | |
| 7316 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7317 | |
| 7318 | nla_put_failure: |
| 7319 | err = -ENOBUFS; |
| 7320 | free_msg: |
| 7321 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7322 | return err; |
| 7323 | } |
| 7324 | |
| 7325 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7326 | struct genl_info *info) |
| 7327 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7328 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7329 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7330 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7331 | |
| 7332 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7333 | return -EINVAL; |
| 7334 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7335 | if (!rdev->ops->cancel_remain_on_channel) |
| 7336 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7337 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7338 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7339 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7340 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7341 | } |
| 7342 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7343 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7344 | u8 *rates, u8 rates_len) |
| 7345 | { |
| 7346 | u8 i; |
| 7347 | u32 mask = 0; |
| 7348 | |
| 7349 | for (i = 0; i < rates_len; i++) { |
| 7350 | int rate = (rates[i] & 0x7f) * 5; |
| 7351 | int ridx; |
| 7352 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7353 | struct ieee80211_rate *srate = |
| 7354 | &sband->bitrates[ridx]; |
| 7355 | if (rate == srate->bitrate) { |
| 7356 | mask |= 1 << ridx; |
| 7357 | break; |
| 7358 | } |
| 7359 | } |
| 7360 | if (ridx == sband->n_bitrates) |
| 7361 | return 0; /* rate not found */ |
| 7362 | } |
| 7363 | |
| 7364 | return mask; |
| 7365 | } |
| 7366 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7367 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7368 | u8 *rates, u8 rates_len, |
| 7369 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7370 | { |
| 7371 | u8 i; |
| 7372 | |
| 7373 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7374 | |
| 7375 | for (i = 0; i < rates_len; i++) { |
| 7376 | int ridx, rbit; |
| 7377 | |
| 7378 | ridx = rates[i] / 8; |
| 7379 | rbit = BIT(rates[i] % 8); |
| 7380 | |
| 7381 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7382 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7383 | return false; |
| 7384 | |
| 7385 | /* check availability */ |
| 7386 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7387 | mcs[ridx] |= rbit; |
| 7388 | else |
| 7389 | return false; |
| 7390 | } |
| 7391 | |
| 7392 | return true; |
| 7393 | } |
| 7394 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7395 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 7396 | { |
| 7397 | u16 mcs_mask = 0; |
| 7398 | |
| 7399 | switch (vht_mcs_map) { |
| 7400 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 7401 | break; |
| 7402 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 7403 | mcs_mask = 0x00FF; |
| 7404 | break; |
| 7405 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 7406 | mcs_mask = 0x01FF; |
| 7407 | break; |
| 7408 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 7409 | mcs_mask = 0x03FF; |
| 7410 | break; |
| 7411 | default: |
| 7412 | break; |
| 7413 | } |
| 7414 | |
| 7415 | return mcs_mask; |
| 7416 | } |
| 7417 | |
| 7418 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 7419 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 7420 | { |
| 7421 | u8 nss; |
| 7422 | |
| 7423 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 7424 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 7425 | vht_mcs_map >>= 2; |
| 7426 | } |
| 7427 | } |
| 7428 | |
| 7429 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 7430 | struct nl80211_txrate_vht *txrate, |
| 7431 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 7432 | { |
| 7433 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7434 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 7435 | u8 i; |
| 7436 | |
| 7437 | if (!sband->vht_cap.vht_supported) |
| 7438 | return false; |
| 7439 | |
| 7440 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 7441 | |
| 7442 | /* Build vht_mcs_mask from VHT capabilities */ |
| 7443 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 7444 | |
| 7445 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 7446 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 7447 | mcs[i] = txrate->mcs[i]; |
| 7448 | else |
| 7449 | return false; |
| 7450 | } |
| 7451 | |
| 7452 | return true; |
| 7453 | } |
| 7454 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7455 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7456 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7457 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7458 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 7459 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7460 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7461 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7462 | }; |
| 7463 | |
| 7464 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7465 | struct genl_info *info) |
| 7466 | { |
| 7467 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7468 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7469 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7470 | int rem, i; |
| 7471 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7472 | struct nlattr *tx_rates; |
| 7473 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7474 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7475 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7476 | if (!rdev->ops->set_bitrate_mask) |
| 7477 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7478 | |
| 7479 | memset(&mask, 0, sizeof(mask)); |
| 7480 | /* Default to all rates enabled */ |
| 7481 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7482 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7483 | |
| 7484 | if (!sband) |
| 7485 | continue; |
| 7486 | |
| 7487 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7488 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7489 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7490 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7491 | |
| 7492 | if (!sband->vht_cap.vht_supported) |
| 7493 | continue; |
| 7494 | |
| 7495 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7496 | 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] | 7497 | } |
| 7498 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7499 | /* if no rates are given set it back to the defaults */ |
| 7500 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 7501 | goto out; |
| 7502 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7503 | /* |
| 7504 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7505 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7506 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7507 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7508 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7509 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7510 | int err; |
| 7511 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7512 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7513 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7514 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7515 | if (sband == NULL) |
| 7516 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7517 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7518 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7519 | if (err) |
| 7520 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7521 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7522 | mask.control[band].legacy = rateset_to_mask( |
| 7523 | sband, |
| 7524 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7525 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7526 | if ((mask.control[band].legacy == 0) && |
| 7527 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7528 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7529 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7530 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7531 | if (!ht_rateset_to_mask( |
| 7532 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7533 | nla_data(tb[NL80211_TXRATE_HT]), |
| 7534 | nla_len(tb[NL80211_TXRATE_HT]), |
| 7535 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7536 | return -EINVAL; |
| 7537 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7538 | if (tb[NL80211_TXRATE_VHT]) { |
| 7539 | if (!vht_set_mcs_mask( |
| 7540 | sband, |
| 7541 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 7542 | mask.control[band].vht_mcs)) |
| 7543 | return -EINVAL; |
| 7544 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7545 | if (tb[NL80211_TXRATE_GI]) { |
| 7546 | mask.control[band].gi = |
| 7547 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 7548 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 7549 | return -EINVAL; |
| 7550 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7551 | |
| 7552 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7553 | /* don't allow empty legacy rates if HT or VHT |
| 7554 | * are not even supported. |
| 7555 | */ |
| 7556 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 7557 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7558 | return -EINVAL; |
| 7559 | |
| 7560 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7561 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7562 | goto out; |
| 7563 | |
| 7564 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 7565 | if (mask.control[band].vht_mcs[i]) |
| 7566 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7567 | |
| 7568 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7569 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7570 | } |
| 7571 | } |
| 7572 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7573 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7574 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7575 | } |
| 7576 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7577 | 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] | 7578 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7579 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7580 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7581 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7582 | |
| 7583 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7584 | return -EINVAL; |
| 7585 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7586 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7587 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7588 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7589 | switch (wdev->iftype) { |
| 7590 | case NL80211_IFTYPE_STATION: |
| 7591 | case NL80211_IFTYPE_ADHOC: |
| 7592 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7593 | case NL80211_IFTYPE_AP: |
| 7594 | case NL80211_IFTYPE_AP_VLAN: |
| 7595 | case NL80211_IFTYPE_MESH_POINT: |
| 7596 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7597 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7598 | break; |
| 7599 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7600 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7601 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7602 | |
| 7603 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7604 | if (!rdev->ops->mgmt_tx) |
| 7605 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7606 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7607 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7608 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7609 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7610 | } |
| 7611 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7612 | 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] | 7613 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7614 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7615 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7616 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7617 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7618 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7619 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7620 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7621 | struct cfg80211_mgmt_tx_params params = { |
| 7622 | .dont_wait_for_ack = |
| 7623 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 7624 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7625 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7626 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7627 | return -EINVAL; |
| 7628 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7629 | if (!rdev->ops->mgmt_tx) |
| 7630 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7631 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7632 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7633 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7634 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7635 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7636 | case NL80211_IFTYPE_STATION: |
| 7637 | case NL80211_IFTYPE_ADHOC: |
| 7638 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7639 | case NL80211_IFTYPE_AP: |
| 7640 | case NL80211_IFTYPE_AP_VLAN: |
| 7641 | case NL80211_IFTYPE_MESH_POINT: |
| 7642 | case NL80211_IFTYPE_P2P_GO: |
| 7643 | break; |
| 7644 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7645 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7646 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7647 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7648 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7649 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7650 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7651 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7652 | |
| 7653 | /* |
| 7654 | * We should wait on the channel for at least a minimum amount |
| 7655 | * of time (10ms) but no longer than the driver supports. |
| 7656 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7657 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7658 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7659 | return -EINVAL; |
| 7660 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7661 | } |
| 7662 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7663 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7664 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7665 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7666 | return -EINVAL; |
| 7667 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7668 | 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] | 7669 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7670 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7671 | * the driver. The latter will use the current one |
| 7672 | */ |
| 7673 | chandef.chan = NULL; |
| 7674 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7675 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7676 | if (err) |
| 7677 | return err; |
| 7678 | } |
| 7679 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7680 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7681 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7682 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7683 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7684 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7685 | if (!msg) |
| 7686 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7687 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7688 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7689 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7690 | if (!hdr) { |
| 7691 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7692 | goto free_msg; |
| 7693 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7694 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7695 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7696 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 7697 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 7698 | params.chan = chandef.chan; |
| 7699 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7700 | if (err) |
| 7701 | goto free_msg; |
| 7702 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7703 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7704 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7705 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7706 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7707 | genlmsg_end(msg, hdr); |
| 7708 | return genlmsg_reply(msg, info); |
| 7709 | } |
| 7710 | |
| 7711 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7712 | |
| 7713 | nla_put_failure: |
| 7714 | err = -ENOBUFS; |
| 7715 | free_msg: |
| 7716 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7717 | return err; |
| 7718 | } |
| 7719 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7720 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7721 | { |
| 7722 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7723 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7724 | u64 cookie; |
| 7725 | |
| 7726 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7727 | return -EINVAL; |
| 7728 | |
| 7729 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7730 | return -EOPNOTSUPP; |
| 7731 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7732 | switch (wdev->iftype) { |
| 7733 | case NL80211_IFTYPE_STATION: |
| 7734 | case NL80211_IFTYPE_ADHOC: |
| 7735 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7736 | case NL80211_IFTYPE_AP: |
| 7737 | case NL80211_IFTYPE_AP_VLAN: |
| 7738 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7739 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7740 | break; |
| 7741 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7742 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7743 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7744 | |
| 7745 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7746 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7747 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7748 | } |
| 7749 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7750 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7751 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7752 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7753 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7754 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7755 | u8 ps_state; |
| 7756 | bool state; |
| 7757 | int err; |
| 7758 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7759 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7760 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7761 | |
| 7762 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7763 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7764 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7765 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7766 | |
| 7767 | wdev = dev->ieee80211_ptr; |
| 7768 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7769 | if (!rdev->ops->set_power_mgmt) |
| 7770 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7771 | |
| 7772 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7773 | |
| 7774 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7775 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7776 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7777 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7778 | if (!err) |
| 7779 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7780 | return err; |
| 7781 | } |
| 7782 | |
| 7783 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7784 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7785 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7786 | enum nl80211_ps_state ps_state; |
| 7787 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7788 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7789 | struct sk_buff *msg; |
| 7790 | void *hdr; |
| 7791 | int err; |
| 7792 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7793 | wdev = dev->ieee80211_ptr; |
| 7794 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7795 | if (!rdev->ops->set_power_mgmt) |
| 7796 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7797 | |
| 7798 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7799 | if (!msg) |
| 7800 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7801 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7802 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7803 | NL80211_CMD_GET_POWER_SAVE); |
| 7804 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7805 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7806 | goto free_msg; |
| 7807 | } |
| 7808 | |
| 7809 | if (wdev->ps) |
| 7810 | ps_state = NL80211_PS_ENABLED; |
| 7811 | else |
| 7812 | ps_state = NL80211_PS_DISABLED; |
| 7813 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7814 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7815 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7816 | |
| 7817 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7818 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7819 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7820 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7821 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7822 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7823 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7824 | return err; |
| 7825 | } |
| 7826 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 7827 | static const struct nla_policy |
| 7828 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7829 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7830 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7831 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7832 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7833 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7834 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7835 | }; |
| 7836 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7837 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7838 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7839 | { |
| 7840 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7841 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7842 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7843 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7844 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7845 | return -EINVAL; |
| 7846 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7847 | if (!rdev->ops->set_cqm_txe_config) |
| 7848 | return -EOPNOTSUPP; |
| 7849 | |
| 7850 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7851 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7852 | return -EOPNOTSUPP; |
| 7853 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7854 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7855 | } |
| 7856 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7857 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7858 | s32 threshold, u32 hysteresis) |
| 7859 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7860 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7861 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7862 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7863 | |
| 7864 | if (threshold > 0) |
| 7865 | return -EINVAL; |
| 7866 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7867 | /* disabling - hysteresis should also be zero then */ |
| 7868 | if (threshold == 0) |
| 7869 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7870 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7871 | if (!rdev->ops->set_cqm_rssi_config) |
| 7872 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7873 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7874 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7875 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7876 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7877 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7878 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7879 | } |
| 7880 | |
| 7881 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7882 | { |
| 7883 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7884 | struct nlattr *cqm; |
| 7885 | int err; |
| 7886 | |
| 7887 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7888 | if (!cqm) |
| 7889 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7890 | |
| 7891 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7892 | nl80211_attr_cqm_policy); |
| 7893 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7894 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7895 | |
| 7896 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7897 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7898 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7899 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7900 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7901 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 7902 | } |
| 7903 | |
| 7904 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7905 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7906 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7907 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7908 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7909 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7910 | |
| 7911 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 7912 | } |
| 7913 | |
| 7914 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7915 | } |
| 7916 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7917 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7918 | { |
| 7919 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7920 | struct net_device *dev = info->user_ptr[1]; |
| 7921 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7922 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7923 | int err; |
| 7924 | |
| 7925 | /* start with default */ |
| 7926 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7927 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7928 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7929 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7930 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7931 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7932 | if (err) |
| 7933 | return err; |
| 7934 | } |
| 7935 | |
| 7936 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7937 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7938 | return -EINVAL; |
| 7939 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7940 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7941 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7942 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7943 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7944 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7945 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7946 | return -EINVAL; |
| 7947 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7948 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7949 | setup.beacon_interval = |
| 7950 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7951 | if (setup.beacon_interval < 10 || |
| 7952 | setup.beacon_interval > 10000) |
| 7953 | return -EINVAL; |
| 7954 | } |
| 7955 | |
| 7956 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7957 | setup.dtim_period = |
| 7958 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7959 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7960 | return -EINVAL; |
| 7961 | } |
| 7962 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7963 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7964 | /* parse additional setup parameters if given */ |
| 7965 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7966 | if (err) |
| 7967 | return err; |
| 7968 | } |
| 7969 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7970 | if (setup.user_mpm) |
| 7971 | cfg.auto_open_plinks = false; |
| 7972 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7973 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7974 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7975 | if (err) |
| 7976 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7977 | } else { |
| 7978 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7979 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7980 | } |
| 7981 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 7982 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7983 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7984 | int n_rates = |
| 7985 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7986 | struct ieee80211_supported_band *sband; |
| 7987 | |
| 7988 | if (!setup.chandef.chan) |
| 7989 | return -EINVAL; |
| 7990 | |
| 7991 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 7992 | |
| 7993 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7994 | &setup.basic_rates); |
| 7995 | if (err) |
| 7996 | return err; |
| 7997 | } |
| 7998 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7999 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8000 | } |
| 8001 | |
| 8002 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8003 | { |
| 8004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8005 | struct net_device *dev = info->user_ptr[1]; |
| 8006 | |
| 8007 | return cfg80211_leave_mesh(rdev, dev); |
| 8008 | } |
| 8009 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8010 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8011 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 8012 | struct cfg80211_registered_device *rdev) |
| 8013 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8014 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8015 | struct nlattr *nl_pats, *nl_pat; |
| 8016 | int i, pat_len; |
| 8017 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8018 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8019 | return 0; |
| 8020 | |
| 8021 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 8022 | if (!nl_pats) |
| 8023 | return -ENOBUFS; |
| 8024 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8025 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8026 | nl_pat = nla_nest_start(msg, i + 1); |
| 8027 | if (!nl_pat) |
| 8028 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8029 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8030 | 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] | 8031 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8032 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8033 | wowlan->patterns[i].pattern) || |
| 8034 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8035 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8036 | return -ENOBUFS; |
| 8037 | nla_nest_end(msg, nl_pat); |
| 8038 | } |
| 8039 | nla_nest_end(msg, nl_pats); |
| 8040 | |
| 8041 | return 0; |
| 8042 | } |
| 8043 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8044 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 8045 | struct cfg80211_wowlan_tcp *tcp) |
| 8046 | { |
| 8047 | struct nlattr *nl_tcp; |
| 8048 | |
| 8049 | if (!tcp) |
| 8050 | return 0; |
| 8051 | |
| 8052 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8053 | if (!nl_tcp) |
| 8054 | return -ENOBUFS; |
| 8055 | |
| 8056 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8057 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 8058 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8059 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8060 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8061 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8062 | tcp->payload_len, tcp->payload) || |
| 8063 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8064 | tcp->data_interval) || |
| 8065 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8066 | tcp->wake_len, tcp->wake_data) || |
| 8067 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8068 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8069 | return -ENOBUFS; |
| 8070 | |
| 8071 | if (tcp->payload_seq.len && |
| 8072 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8073 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8074 | return -ENOBUFS; |
| 8075 | |
| 8076 | if (tcp->payload_tok.len && |
| 8077 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8078 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8079 | &tcp->payload_tok)) |
| 8080 | return -ENOBUFS; |
| 8081 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8082 | nla_nest_end(msg, nl_tcp); |
| 8083 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8084 | return 0; |
| 8085 | } |
| 8086 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8087 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8088 | { |
| 8089 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8090 | struct sk_buff *msg; |
| 8091 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8092 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8093 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8094 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8095 | return -EOPNOTSUPP; |
| 8096 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8097 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8098 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8099 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8100 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8101 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8102 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8103 | } |
| 8104 | |
| 8105 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8106 | if (!msg) |
| 8107 | return -ENOMEM; |
| 8108 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8109 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8110 | NL80211_CMD_GET_WOWLAN); |
| 8111 | if (!hdr) |
| 8112 | goto nla_put_failure; |
| 8113 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8114 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8115 | struct nlattr *nl_wowlan; |
| 8116 | |
| 8117 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8118 | if (!nl_wowlan) |
| 8119 | goto nla_put_failure; |
| 8120 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8121 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8122 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8123 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8124 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8125 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8126 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8127 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8128 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8129 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8130 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8131 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8132 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8133 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8134 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8135 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8136 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8137 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8138 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8139 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8140 | if (nl80211_send_wowlan_tcp(msg, |
| 8141 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8142 | goto nla_put_failure; |
| 8143 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8144 | nla_nest_end(msg, nl_wowlan); |
| 8145 | } |
| 8146 | |
| 8147 | genlmsg_end(msg, hdr); |
| 8148 | return genlmsg_reply(msg, info); |
| 8149 | |
| 8150 | nla_put_failure: |
| 8151 | nlmsg_free(msg); |
| 8152 | return -ENOBUFS; |
| 8153 | } |
| 8154 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8155 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8156 | struct nlattr *attr, |
| 8157 | struct cfg80211_wowlan *trig) |
| 8158 | { |
| 8159 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8160 | struct cfg80211_wowlan_tcp *cfg; |
| 8161 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8162 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8163 | u32 size; |
| 8164 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8165 | int err, port; |
| 8166 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8167 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8168 | return -EINVAL; |
| 8169 | |
| 8170 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8171 | nla_data(attr), nla_len(attr), |
| 8172 | nl80211_wowlan_tcp_policy); |
| 8173 | if (err) |
| 8174 | return err; |
| 8175 | |
| 8176 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8177 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8178 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8179 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8180 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8181 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8182 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8183 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8184 | return -EINVAL; |
| 8185 | |
| 8186 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8187 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8188 | return -EINVAL; |
| 8189 | |
| 8190 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8191 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8192 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8193 | return -EINVAL; |
| 8194 | |
| 8195 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8196 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8197 | return -EINVAL; |
| 8198 | |
| 8199 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8200 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8201 | return -EINVAL; |
| 8202 | |
| 8203 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8204 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8205 | |
| 8206 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8207 | tokens_size = tokln - sizeof(*tok); |
| 8208 | |
| 8209 | if (!tok->len || tokens_size % tok->len) |
| 8210 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8211 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8212 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8213 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8214 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8215 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8216 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8217 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8218 | return -EINVAL; |
| 8219 | if (tok->offset + tok->len > data_size) |
| 8220 | return -EINVAL; |
| 8221 | } |
| 8222 | |
| 8223 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8224 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8225 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8226 | return -EINVAL; |
| 8227 | if (seq->len == 0 || seq->len > 4) |
| 8228 | return -EINVAL; |
| 8229 | if (seq->len + seq->offset > data_size) |
| 8230 | return -EINVAL; |
| 8231 | } |
| 8232 | |
| 8233 | size = sizeof(*cfg); |
| 8234 | size += data_size; |
| 8235 | size += wake_size + wake_mask_size; |
| 8236 | size += tokens_size; |
| 8237 | |
| 8238 | cfg = kzalloc(size, GFP_KERNEL); |
| 8239 | if (!cfg) |
| 8240 | return -ENOMEM; |
| 8241 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8242 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8243 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8244 | ETH_ALEN); |
| 8245 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8246 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8247 | else |
| 8248 | port = 0; |
| 8249 | #ifdef CONFIG_INET |
| 8250 | /* allocate a socket and port for it and use it */ |
| 8251 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8252 | IPPROTO_TCP, &cfg->sock, 1); |
| 8253 | if (err) { |
| 8254 | kfree(cfg); |
| 8255 | return err; |
| 8256 | } |
| 8257 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8258 | sock_release(cfg->sock); |
| 8259 | kfree(cfg); |
| 8260 | return -EADDRINUSE; |
| 8261 | } |
| 8262 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8263 | #else |
| 8264 | if (!port) { |
| 8265 | kfree(cfg); |
| 8266 | return -EINVAL; |
| 8267 | } |
| 8268 | cfg->src_port = port; |
| 8269 | #endif |
| 8270 | |
| 8271 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8272 | cfg->payload_len = data_size; |
| 8273 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8274 | memcpy((void *)cfg->payload, |
| 8275 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8276 | data_size); |
| 8277 | if (seq) |
| 8278 | cfg->payload_seq = *seq; |
| 8279 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8280 | cfg->wake_len = wake_size; |
| 8281 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8282 | memcpy((void *)cfg->wake_data, |
| 8283 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8284 | wake_size); |
| 8285 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8286 | data_size + wake_size; |
| 8287 | memcpy((void *)cfg->wake_mask, |
| 8288 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8289 | wake_mask_size); |
| 8290 | if (tok) { |
| 8291 | cfg->tokens_size = tokens_size; |
| 8292 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8293 | } |
| 8294 | |
| 8295 | trig->tcp = cfg; |
| 8296 | |
| 8297 | return 0; |
| 8298 | } |
| 8299 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8300 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8301 | { |
| 8302 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8303 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8304 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8305 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8306 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8307 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8308 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8309 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8310 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8311 | return -EOPNOTSUPP; |
| 8312 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8313 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8314 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8315 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8316 | goto set_wakeup; |
| 8317 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8318 | |
| 8319 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8320 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8321 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8322 | nl80211_wowlan_policy); |
| 8323 | if (err) |
| 8324 | return err; |
| 8325 | |
| 8326 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8327 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8328 | return -EINVAL; |
| 8329 | new_triggers.any = true; |
| 8330 | } |
| 8331 | |
| 8332 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8333 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8334 | return -EINVAL; |
| 8335 | new_triggers.disconnect = true; |
| 8336 | } |
| 8337 | |
| 8338 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8339 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8340 | return -EINVAL; |
| 8341 | new_triggers.magic_pkt = true; |
| 8342 | } |
| 8343 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8344 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8345 | return -EINVAL; |
| 8346 | |
| 8347 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8348 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8349 | return -EINVAL; |
| 8350 | new_triggers.gtk_rekey_failure = true; |
| 8351 | } |
| 8352 | |
| 8353 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8354 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8355 | return -EINVAL; |
| 8356 | new_triggers.eap_identity_req = true; |
| 8357 | } |
| 8358 | |
| 8359 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8360 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8361 | return -EINVAL; |
| 8362 | new_triggers.four_way_handshake = true; |
| 8363 | } |
| 8364 | |
| 8365 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8366 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8367 | return -EINVAL; |
| 8368 | new_triggers.rfkill_release = true; |
| 8369 | } |
| 8370 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8371 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8372 | struct nlattr *pat; |
| 8373 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8374 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8375 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8376 | |
| 8377 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8378 | rem) |
| 8379 | n_patterns++; |
| 8380 | if (n_patterns > wowlan->n_patterns) |
| 8381 | return -EINVAL; |
| 8382 | |
| 8383 | new_triggers.patterns = kcalloc(n_patterns, |
| 8384 | sizeof(new_triggers.patterns[0]), |
| 8385 | GFP_KERNEL); |
| 8386 | if (!new_triggers.patterns) |
| 8387 | return -ENOMEM; |
| 8388 | |
| 8389 | new_triggers.n_patterns = n_patterns; |
| 8390 | i = 0; |
| 8391 | |
| 8392 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8393 | rem) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8394 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8395 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8396 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8397 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8398 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8399 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8400 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8401 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8402 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8403 | goto error; |
| 8404 | if (pat_len > wowlan->pattern_max_len || |
| 8405 | pat_len < wowlan->pattern_min_len) |
| 8406 | goto error; |
| 8407 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8408 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8409 | pkt_offset = 0; |
| 8410 | else |
| 8411 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8412 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8413 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8414 | goto error; |
| 8415 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8416 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8417 | new_triggers.patterns[i].mask = |
| 8418 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8419 | if (!new_triggers.patterns[i].mask) { |
| 8420 | err = -ENOMEM; |
| 8421 | goto error; |
| 8422 | } |
| 8423 | new_triggers.patterns[i].pattern = |
| 8424 | new_triggers.patterns[i].mask + mask_len; |
| 8425 | memcpy(new_triggers.patterns[i].mask, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8426 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8427 | mask_len); |
| 8428 | new_triggers.patterns[i].pattern_len = pat_len; |
| 8429 | memcpy(new_triggers.patterns[i].pattern, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8430 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8431 | pat_len); |
| 8432 | i++; |
| 8433 | } |
| 8434 | } |
| 8435 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8436 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8437 | err = nl80211_parse_wowlan_tcp( |
| 8438 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8439 | &new_triggers); |
| 8440 | if (err) |
| 8441 | goto error; |
| 8442 | } |
| 8443 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8444 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8445 | if (!ntrig) { |
| 8446 | err = -ENOMEM; |
| 8447 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8448 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8449 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8450 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8451 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8452 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8453 | if (rdev->ops->set_wakeup && |
| 8454 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8455 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8456 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8457 | return 0; |
| 8458 | error: |
| 8459 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8460 | kfree(new_triggers.patterns[i].mask); |
| 8461 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8462 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8463 | sock_release(new_triggers.tcp->sock); |
| 8464 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8465 | return err; |
| 8466 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8467 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8468 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8469 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8470 | struct cfg80211_registered_device *rdev) |
| 8471 | { |
| 8472 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8473 | int i, j, pat_len; |
| 8474 | struct cfg80211_coalesce_rules *rule; |
| 8475 | |
| 8476 | if (!rdev->coalesce->n_rules) |
| 8477 | return 0; |
| 8478 | |
| 8479 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8480 | if (!nl_rules) |
| 8481 | return -ENOBUFS; |
| 8482 | |
| 8483 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8484 | nl_rule = nla_nest_start(msg, i + 1); |
| 8485 | if (!nl_rule) |
| 8486 | return -ENOBUFS; |
| 8487 | |
| 8488 | rule = &rdev->coalesce->rules[i]; |
| 8489 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8490 | rule->delay)) |
| 8491 | return -ENOBUFS; |
| 8492 | |
| 8493 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8494 | rule->condition)) |
| 8495 | return -ENOBUFS; |
| 8496 | |
| 8497 | nl_pats = nla_nest_start(msg, |
| 8498 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8499 | if (!nl_pats) |
| 8500 | return -ENOBUFS; |
| 8501 | |
| 8502 | for (j = 0; j < rule->n_patterns; j++) { |
| 8503 | nl_pat = nla_nest_start(msg, j + 1); |
| 8504 | if (!nl_pat) |
| 8505 | return -ENOBUFS; |
| 8506 | pat_len = rule->patterns[j].pattern_len; |
| 8507 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8508 | DIV_ROUND_UP(pat_len, 8), |
| 8509 | rule->patterns[j].mask) || |
| 8510 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8511 | rule->patterns[j].pattern) || |
| 8512 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8513 | rule->patterns[j].pkt_offset)) |
| 8514 | return -ENOBUFS; |
| 8515 | nla_nest_end(msg, nl_pat); |
| 8516 | } |
| 8517 | nla_nest_end(msg, nl_pats); |
| 8518 | nla_nest_end(msg, nl_rule); |
| 8519 | } |
| 8520 | nla_nest_end(msg, nl_rules); |
| 8521 | |
| 8522 | return 0; |
| 8523 | } |
| 8524 | |
| 8525 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8526 | { |
| 8527 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8528 | struct sk_buff *msg; |
| 8529 | void *hdr; |
| 8530 | |
| 8531 | if (!rdev->wiphy.coalesce) |
| 8532 | return -EOPNOTSUPP; |
| 8533 | |
| 8534 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8535 | if (!msg) |
| 8536 | return -ENOMEM; |
| 8537 | |
| 8538 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8539 | NL80211_CMD_GET_COALESCE); |
| 8540 | if (!hdr) |
| 8541 | goto nla_put_failure; |
| 8542 | |
| 8543 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8544 | goto nla_put_failure; |
| 8545 | |
| 8546 | genlmsg_end(msg, hdr); |
| 8547 | return genlmsg_reply(msg, info); |
| 8548 | |
| 8549 | nla_put_failure: |
| 8550 | nlmsg_free(msg); |
| 8551 | return -ENOBUFS; |
| 8552 | } |
| 8553 | |
| 8554 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8555 | { |
| 8556 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8557 | int i, j; |
| 8558 | struct cfg80211_coalesce_rules *rule; |
| 8559 | |
| 8560 | if (!coalesce) |
| 8561 | return; |
| 8562 | |
| 8563 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8564 | rule = &coalesce->rules[i]; |
| 8565 | for (j = 0; j < rule->n_patterns; j++) |
| 8566 | kfree(rule->patterns[j].mask); |
| 8567 | kfree(rule->patterns); |
| 8568 | } |
| 8569 | kfree(coalesce->rules); |
| 8570 | kfree(coalesce); |
| 8571 | rdev->coalesce = NULL; |
| 8572 | } |
| 8573 | |
| 8574 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8575 | struct nlattr *rule, |
| 8576 | struct cfg80211_coalesce_rules *new_rule) |
| 8577 | { |
| 8578 | int err, i; |
| 8579 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8580 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8581 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8582 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8583 | |
| 8584 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8585 | nla_len(rule), nl80211_coalesce_policy); |
| 8586 | if (err) |
| 8587 | return err; |
| 8588 | |
| 8589 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8590 | new_rule->delay = |
| 8591 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8592 | if (new_rule->delay > coalesce->max_delay) |
| 8593 | return -EINVAL; |
| 8594 | |
| 8595 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8596 | new_rule->condition = |
| 8597 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8598 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8599 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8600 | return -EINVAL; |
| 8601 | |
| 8602 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8603 | return -EINVAL; |
| 8604 | |
| 8605 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8606 | rem) |
| 8607 | n_patterns++; |
| 8608 | if (n_patterns > coalesce->n_patterns) |
| 8609 | return -EINVAL; |
| 8610 | |
| 8611 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8612 | GFP_KERNEL); |
| 8613 | if (!new_rule->patterns) |
| 8614 | return -ENOMEM; |
| 8615 | |
| 8616 | new_rule->n_patterns = n_patterns; |
| 8617 | i = 0; |
| 8618 | |
| 8619 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8620 | rem) { |
| 8621 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8622 | nla_len(pat), NULL); |
| 8623 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8624 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8625 | return -EINVAL; |
| 8626 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8627 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8628 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8629 | return -EINVAL; |
| 8630 | if (pat_len > coalesce->pattern_max_len || |
| 8631 | pat_len < coalesce->pattern_min_len) |
| 8632 | return -EINVAL; |
| 8633 | |
| 8634 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8635 | pkt_offset = 0; |
| 8636 | else |
| 8637 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8638 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8639 | return -EINVAL; |
| 8640 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8641 | |
| 8642 | new_rule->patterns[i].mask = |
| 8643 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8644 | if (!new_rule->patterns[i].mask) |
| 8645 | return -ENOMEM; |
| 8646 | new_rule->patterns[i].pattern = |
| 8647 | new_rule->patterns[i].mask + mask_len; |
| 8648 | memcpy(new_rule->patterns[i].mask, |
| 8649 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); |
| 8650 | new_rule->patterns[i].pattern_len = pat_len; |
| 8651 | memcpy(new_rule->patterns[i].pattern, |
| 8652 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); |
| 8653 | i++; |
| 8654 | } |
| 8655 | |
| 8656 | return 0; |
| 8657 | } |
| 8658 | |
| 8659 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8660 | { |
| 8661 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8662 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8663 | struct cfg80211_coalesce new_coalesce = {}; |
| 8664 | struct cfg80211_coalesce *n_coalesce; |
| 8665 | int err, rem_rule, n_rules = 0, i, j; |
| 8666 | struct nlattr *rule; |
| 8667 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8668 | |
| 8669 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8670 | return -EOPNOTSUPP; |
| 8671 | |
| 8672 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8673 | cfg80211_rdev_free_coalesce(rdev); |
| 8674 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8675 | return 0; |
| 8676 | } |
| 8677 | |
| 8678 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8679 | rem_rule) |
| 8680 | n_rules++; |
| 8681 | if (n_rules > coalesce->n_rules) |
| 8682 | return -EINVAL; |
| 8683 | |
| 8684 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8685 | GFP_KERNEL); |
| 8686 | if (!new_coalesce.rules) |
| 8687 | return -ENOMEM; |
| 8688 | |
| 8689 | new_coalesce.n_rules = n_rules; |
| 8690 | i = 0; |
| 8691 | |
| 8692 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8693 | rem_rule) { |
| 8694 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8695 | &new_coalesce.rules[i]); |
| 8696 | if (err) |
| 8697 | goto error; |
| 8698 | |
| 8699 | i++; |
| 8700 | } |
| 8701 | |
| 8702 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8703 | if (err) |
| 8704 | goto error; |
| 8705 | |
| 8706 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8707 | if (!n_coalesce) { |
| 8708 | err = -ENOMEM; |
| 8709 | goto error; |
| 8710 | } |
| 8711 | cfg80211_rdev_free_coalesce(rdev); |
| 8712 | rdev->coalesce = n_coalesce; |
| 8713 | |
| 8714 | return 0; |
| 8715 | error: |
| 8716 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8717 | tmp_rule = &new_coalesce.rules[i]; |
| 8718 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8719 | kfree(tmp_rule->patterns[j].mask); |
| 8720 | kfree(tmp_rule->patterns); |
| 8721 | } |
| 8722 | kfree(new_coalesce.rules); |
| 8723 | |
| 8724 | return err; |
| 8725 | } |
| 8726 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8727 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8728 | { |
| 8729 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8730 | struct net_device *dev = info->user_ptr[1]; |
| 8731 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8732 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8733 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8734 | int err; |
| 8735 | |
| 8736 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8737 | return -EINVAL; |
| 8738 | |
| 8739 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8740 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8741 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8742 | nl80211_rekey_policy); |
| 8743 | if (err) |
| 8744 | return err; |
| 8745 | |
| 8746 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8747 | return -ERANGE; |
| 8748 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8749 | return -ERANGE; |
| 8750 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8751 | return -ERANGE; |
| 8752 | |
| 8753 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8754 | NL80211_KEK_LEN); |
| 8755 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8756 | NL80211_KCK_LEN); |
| 8757 | memcpy(rekey_data.replay_ctr, |
| 8758 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8759 | NL80211_REPLAY_CTR_LEN); |
| 8760 | |
| 8761 | wdev_lock(wdev); |
| 8762 | if (!wdev->current_bss) { |
| 8763 | err = -ENOTCONN; |
| 8764 | goto out; |
| 8765 | } |
| 8766 | |
| 8767 | if (!rdev->ops->set_rekey_data) { |
| 8768 | err = -EOPNOTSUPP; |
| 8769 | goto out; |
| 8770 | } |
| 8771 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8772 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8773 | out: |
| 8774 | wdev_unlock(wdev); |
| 8775 | return err; |
| 8776 | } |
| 8777 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8778 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8779 | struct genl_info *info) |
| 8780 | { |
| 8781 | struct net_device *dev = info->user_ptr[1]; |
| 8782 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8783 | |
| 8784 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8785 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8786 | return -EINVAL; |
| 8787 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8788 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8789 | return -EBUSY; |
| 8790 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8791 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8792 | return 0; |
| 8793 | } |
| 8794 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8795 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8796 | struct genl_info *info) |
| 8797 | { |
| 8798 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8799 | struct net_device *dev = info->user_ptr[1]; |
| 8800 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8801 | struct sk_buff *msg; |
| 8802 | void *hdr; |
| 8803 | const u8 *addr; |
| 8804 | u64 cookie; |
| 8805 | int err; |
| 8806 | |
| 8807 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8808 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8809 | return -EOPNOTSUPP; |
| 8810 | |
| 8811 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8812 | return -EINVAL; |
| 8813 | |
| 8814 | if (!rdev->ops->probe_client) |
| 8815 | return -EOPNOTSUPP; |
| 8816 | |
| 8817 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8818 | if (!msg) |
| 8819 | return -ENOMEM; |
| 8820 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8821 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8822 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8823 | if (!hdr) { |
| 8824 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8825 | goto free_msg; |
| 8826 | } |
| 8827 | |
| 8828 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8829 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8830 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8831 | if (err) |
| 8832 | goto free_msg; |
| 8833 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8834 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8835 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8836 | |
| 8837 | genlmsg_end(msg, hdr); |
| 8838 | |
| 8839 | return genlmsg_reply(msg, info); |
| 8840 | |
| 8841 | nla_put_failure: |
| 8842 | err = -ENOBUFS; |
| 8843 | free_msg: |
| 8844 | nlmsg_free(msg); |
| 8845 | return err; |
| 8846 | } |
| 8847 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8848 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8849 | { |
| 8850 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8851 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8852 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8853 | |
| 8854 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8855 | return -EOPNOTSUPP; |
| 8856 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8857 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8858 | if (!nreg) |
| 8859 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8860 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8861 | /* First, check if already registered. */ |
| 8862 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8863 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8864 | if (reg->nlportid == info->snd_portid) { |
| 8865 | rv = -EALREADY; |
| 8866 | goto out_err; |
| 8867 | } |
| 8868 | } |
| 8869 | /* Add it to the list */ |
| 8870 | nreg->nlportid = info->snd_portid; |
| 8871 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8872 | |
| 8873 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8874 | |
| 8875 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8876 | out_err: |
| 8877 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8878 | kfree(nreg); |
| 8879 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8880 | } |
| 8881 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8882 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8883 | { |
| 8884 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8885 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8886 | int err; |
| 8887 | |
| 8888 | if (!rdev->ops->start_p2p_device) |
| 8889 | return -EOPNOTSUPP; |
| 8890 | |
| 8891 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8892 | return -EOPNOTSUPP; |
| 8893 | |
| 8894 | if (wdev->p2p_started) |
| 8895 | return 0; |
| 8896 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8897 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8898 | if (err) |
| 8899 | return err; |
| 8900 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8901 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8902 | if (err) |
| 8903 | return err; |
| 8904 | |
| 8905 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8906 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8907 | |
| 8908 | return 0; |
| 8909 | } |
| 8910 | |
| 8911 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8912 | { |
| 8913 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8914 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8915 | |
| 8916 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8917 | return -EOPNOTSUPP; |
| 8918 | |
| 8919 | if (!rdev->ops->stop_p2p_device) |
| 8920 | return -EOPNOTSUPP; |
| 8921 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8922 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8923 | |
| 8924 | return 0; |
| 8925 | } |
| 8926 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8927 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8928 | struct genl_info *info) |
| 8929 | { |
| 8930 | void *hdr; |
| 8931 | struct sk_buff *msg; |
| 8932 | |
| 8933 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8934 | if (!msg) |
| 8935 | return -ENOMEM; |
| 8936 | |
| 8937 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8938 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8939 | if (!hdr) |
| 8940 | goto nla_put_failure; |
| 8941 | |
| 8942 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8943 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8944 | goto nla_put_failure; |
| 8945 | |
| 8946 | genlmsg_end(msg, hdr); |
| 8947 | return genlmsg_reply(msg, info); |
| 8948 | |
| 8949 | nla_put_failure: |
| 8950 | kfree_skb(msg); |
| 8951 | return -ENOBUFS; |
| 8952 | } |
| 8953 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8954 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8955 | { |
| 8956 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8957 | struct cfg80211_update_ft_ies_params ft_params; |
| 8958 | struct net_device *dev = info->user_ptr[1]; |
| 8959 | |
| 8960 | if (!rdev->ops->update_ft_ies) |
| 8961 | return -EOPNOTSUPP; |
| 8962 | |
| 8963 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8964 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8965 | return -EINVAL; |
| 8966 | |
| 8967 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8968 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8969 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8970 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8971 | |
| 8972 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8973 | } |
| 8974 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8975 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8976 | struct genl_info *info) |
| 8977 | { |
| 8978 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8979 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8980 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8981 | u16 duration; |
| 8982 | int ret; |
| 8983 | |
| 8984 | if (!rdev->ops->crit_proto_start) |
| 8985 | return -EOPNOTSUPP; |
| 8986 | |
| 8987 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8988 | return -EINVAL; |
| 8989 | |
| 8990 | if (rdev->crit_proto_nlportid) |
| 8991 | return -EBUSY; |
| 8992 | |
| 8993 | /* determine protocol if provided */ |
| 8994 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8995 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8996 | |
| 8997 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8998 | return -EINVAL; |
| 8999 | |
| 9000 | /* timeout must be provided */ |
| 9001 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 9002 | return -EINVAL; |
| 9003 | |
| 9004 | duration = |
| 9005 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 9006 | |
| 9007 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 9008 | return -ERANGE; |
| 9009 | |
| 9010 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 9011 | if (!ret) |
| 9012 | rdev->crit_proto_nlportid = info->snd_portid; |
| 9013 | |
| 9014 | return ret; |
| 9015 | } |
| 9016 | |
| 9017 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 9018 | struct genl_info *info) |
| 9019 | { |
| 9020 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9021 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9022 | |
| 9023 | if (!rdev->ops->crit_proto_stop) |
| 9024 | return -EOPNOTSUPP; |
| 9025 | |
| 9026 | if (rdev->crit_proto_nlportid) { |
| 9027 | rdev->crit_proto_nlportid = 0; |
| 9028 | rdev_crit_proto_stop(rdev, wdev); |
| 9029 | } |
| 9030 | return 0; |
| 9031 | } |
| 9032 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9033 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 9034 | { |
| 9035 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9036 | struct wireless_dev *wdev = |
| 9037 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 9038 | int i, err; |
| 9039 | u32 vid, subcmd; |
| 9040 | |
| 9041 | if (!rdev->wiphy.vendor_commands) |
| 9042 | return -EOPNOTSUPP; |
| 9043 | |
| 9044 | if (IS_ERR(wdev)) { |
| 9045 | err = PTR_ERR(wdev); |
| 9046 | if (err != -EINVAL) |
| 9047 | return err; |
| 9048 | wdev = NULL; |
| 9049 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9050 | return -EINVAL; |
| 9051 | } |
| 9052 | |
| 9053 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 9054 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 9055 | return -EINVAL; |
| 9056 | |
| 9057 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 9058 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 9059 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 9060 | const struct wiphy_vendor_command *vcmd; |
| 9061 | void *data = NULL; |
| 9062 | int len = 0; |
| 9063 | |
| 9064 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 9065 | |
| 9066 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 9067 | continue; |
| 9068 | |
| 9069 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 9070 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 9071 | if (!wdev) |
| 9072 | return -EINVAL; |
| 9073 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9074 | !wdev->netdev) |
| 9075 | return -EINVAL; |
| 9076 | |
| 9077 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9078 | if (wdev->netdev && |
| 9079 | !netif_running(wdev->netdev)) |
| 9080 | return -ENETDOWN; |
| 9081 | if (!wdev->netdev && !wdev->p2p_started) |
| 9082 | return -ENETDOWN; |
| 9083 | } |
| 9084 | } else { |
| 9085 | wdev = NULL; |
| 9086 | } |
| 9087 | |
| 9088 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9089 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9090 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9091 | } |
| 9092 | |
| 9093 | rdev->cur_cmd_info = info; |
| 9094 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9095 | data, len); |
| 9096 | rdev->cur_cmd_info = NULL; |
| 9097 | return err; |
| 9098 | } |
| 9099 | |
| 9100 | return -EOPNOTSUPP; |
| 9101 | } |
| 9102 | |
| 9103 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9104 | enum nl80211_commands cmd, |
| 9105 | enum nl80211_attrs attr, |
| 9106 | int approxlen) |
| 9107 | { |
| 9108 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9109 | |
| 9110 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9111 | return NULL; |
| 9112 | |
| 9113 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, |
| 9114 | rdev->cur_cmd_info->snd_portid, |
| 9115 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9116 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9117 | } |
| 9118 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9119 | |
| 9120 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9121 | { |
| 9122 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9123 | void *hdr = ((void **)skb->cb)[1]; |
| 9124 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9125 | |
| 9126 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9127 | kfree_skb(skb); |
| 9128 | return -EINVAL; |
| 9129 | } |
| 9130 | |
| 9131 | nla_nest_end(skb, data); |
| 9132 | genlmsg_end(skb, hdr); |
| 9133 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9134 | } |
| 9135 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9136 | |
| 9137 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9138 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 9139 | struct genl_info *info) |
| 9140 | { |
| 9141 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9142 | struct cfg80211_qos_map *qos_map = NULL; |
| 9143 | struct net_device *dev = info->user_ptr[1]; |
| 9144 | u8 *pos, len, num_des, des_len, des; |
| 9145 | int ret; |
| 9146 | |
| 9147 | if (!rdev->ops->set_qos_map) |
| 9148 | return -EOPNOTSUPP; |
| 9149 | |
| 9150 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 9151 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9152 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9153 | |
| 9154 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 9155 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 9156 | return -EINVAL; |
| 9157 | |
| 9158 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 9159 | if (!qos_map) |
| 9160 | return -ENOMEM; |
| 9161 | |
| 9162 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 9163 | if (num_des) { |
| 9164 | des_len = num_des * |
| 9165 | sizeof(struct cfg80211_dscp_exception); |
| 9166 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 9167 | qos_map->num_des = num_des; |
| 9168 | for (des = 0; des < num_des; des++) { |
| 9169 | if (qos_map->dscp_exception[des].up > 7) { |
| 9170 | kfree(qos_map); |
| 9171 | return -EINVAL; |
| 9172 | } |
| 9173 | } |
| 9174 | pos += des_len; |
| 9175 | } |
| 9176 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 9177 | } |
| 9178 | |
| 9179 | wdev_lock(dev->ieee80211_ptr); |
| 9180 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 9181 | if (!ret) |
| 9182 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 9183 | wdev_unlock(dev->ieee80211_ptr); |
| 9184 | |
| 9185 | kfree(qos_map); |
| 9186 | return ret; |
| 9187 | } |
| 9188 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9189 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 9190 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 9191 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9192 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 9193 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 9194 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9195 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9196 | /* 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] | 9197 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 9198 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9199 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9200 | 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] | 9201 | struct genl_info *info) |
| 9202 | { |
| 9203 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9204 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9205 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9206 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 9207 | |
| 9208 | if (rtnl) |
| 9209 | rtnl_lock(); |
| 9210 | |
| 9211 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 9212 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9213 | if (IS_ERR(rdev)) { |
| 9214 | if (rtnl) |
| 9215 | rtnl_unlock(); |
| 9216 | return PTR_ERR(rdev); |
| 9217 | } |
| 9218 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9219 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 9220 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9221 | ASSERT_RTNL(); |
| 9222 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9223 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 9224 | info->attrs); |
| 9225 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9226 | if (rtnl) |
| 9227 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9228 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9229 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9230 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9231 | dev = wdev->netdev; |
| 9232 | rdev = wiphy_to_dev(wdev->wiphy); |
| 9233 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9234 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 9235 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9236 | if (rtnl) |
| 9237 | rtnl_unlock(); |
| 9238 | return -EINVAL; |
| 9239 | } |
| 9240 | |
| 9241 | info->user_ptr[1] = dev; |
| 9242 | } else { |
| 9243 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9244 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9245 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9246 | if (dev) { |
| 9247 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 9248 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9249 | if (rtnl) |
| 9250 | rtnl_unlock(); |
| 9251 | return -ENETDOWN; |
| 9252 | } |
| 9253 | |
| 9254 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9255 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 9256 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9257 | if (rtnl) |
| 9258 | rtnl_unlock(); |
| 9259 | return -ENETDOWN; |
| 9260 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9261 | } |
| 9262 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9263 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9264 | } |
| 9265 | |
| 9266 | return 0; |
| 9267 | } |
| 9268 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9269 | 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] | 9270 | struct genl_info *info) |
| 9271 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9272 | if (info->user_ptr[1]) { |
| 9273 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 9274 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9275 | |
| 9276 | if (wdev->netdev) |
| 9277 | dev_put(wdev->netdev); |
| 9278 | } else { |
| 9279 | dev_put(info->user_ptr[1]); |
| 9280 | } |
| 9281 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9282 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 9283 | rtnl_unlock(); |
| 9284 | } |
| 9285 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 9286 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9287 | { |
| 9288 | .cmd = NL80211_CMD_GET_WIPHY, |
| 9289 | .doit = nl80211_get_wiphy, |
| 9290 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9291 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9292 | .policy = nl80211_policy, |
| 9293 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9294 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9295 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9296 | }, |
| 9297 | { |
| 9298 | .cmd = NL80211_CMD_SET_WIPHY, |
| 9299 | .doit = nl80211_set_wiphy, |
| 9300 | .policy = nl80211_policy, |
| 9301 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9302 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9303 | }, |
| 9304 | { |
| 9305 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 9306 | .doit = nl80211_get_interface, |
| 9307 | .dumpit = nl80211_dump_interface, |
| 9308 | .policy = nl80211_policy, |
| 9309 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9310 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9311 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9312 | }, |
| 9313 | { |
| 9314 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 9315 | .doit = nl80211_set_interface, |
| 9316 | .policy = nl80211_policy, |
| 9317 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9318 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9319 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9320 | }, |
| 9321 | { |
| 9322 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 9323 | .doit = nl80211_new_interface, |
| 9324 | .policy = nl80211_policy, |
| 9325 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9326 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9327 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9328 | }, |
| 9329 | { |
| 9330 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 9331 | .doit = nl80211_del_interface, |
| 9332 | .policy = nl80211_policy, |
| 9333 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 9334 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9335 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9336 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9337 | { |
| 9338 | .cmd = NL80211_CMD_GET_KEY, |
| 9339 | .doit = nl80211_get_key, |
| 9340 | .policy = nl80211_policy, |
| 9341 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9342 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9343 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9344 | }, |
| 9345 | { |
| 9346 | .cmd = NL80211_CMD_SET_KEY, |
| 9347 | .doit = nl80211_set_key, |
| 9348 | .policy = nl80211_policy, |
| 9349 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9350 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9351 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9352 | }, |
| 9353 | { |
| 9354 | .cmd = NL80211_CMD_NEW_KEY, |
| 9355 | .doit = nl80211_new_key, |
| 9356 | .policy = nl80211_policy, |
| 9357 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9358 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9359 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9360 | }, |
| 9361 | { |
| 9362 | .cmd = NL80211_CMD_DEL_KEY, |
| 9363 | .doit = nl80211_del_key, |
| 9364 | .policy = nl80211_policy, |
| 9365 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9366 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9367 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9368 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9369 | { |
| 9370 | .cmd = NL80211_CMD_SET_BEACON, |
| 9371 | .policy = nl80211_policy, |
| 9372 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9373 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9374 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9375 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9376 | }, |
| 9377 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9378 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9379 | .policy = nl80211_policy, |
| 9380 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9381 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9382 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9383 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9384 | }, |
| 9385 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9386 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9387 | .policy = nl80211_policy, |
| 9388 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9389 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9390 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9391 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9392 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9393 | { |
| 9394 | .cmd = NL80211_CMD_GET_STATION, |
| 9395 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9396 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9397 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9398 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9399 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9400 | }, |
| 9401 | { |
| 9402 | .cmd = NL80211_CMD_SET_STATION, |
| 9403 | .doit = nl80211_set_station, |
| 9404 | .policy = nl80211_policy, |
| 9405 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9406 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9407 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9408 | }, |
| 9409 | { |
| 9410 | .cmd = NL80211_CMD_NEW_STATION, |
| 9411 | .doit = nl80211_new_station, |
| 9412 | .policy = nl80211_policy, |
| 9413 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9414 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9415 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9416 | }, |
| 9417 | { |
| 9418 | .cmd = NL80211_CMD_DEL_STATION, |
| 9419 | .doit = nl80211_del_station, |
| 9420 | .policy = nl80211_policy, |
| 9421 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9422 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9423 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9424 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9425 | { |
| 9426 | .cmd = NL80211_CMD_GET_MPATH, |
| 9427 | .doit = nl80211_get_mpath, |
| 9428 | .dumpit = nl80211_dump_mpath, |
| 9429 | .policy = nl80211_policy, |
| 9430 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9431 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9432 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9433 | }, |
| 9434 | { |
| 9435 | .cmd = NL80211_CMD_SET_MPATH, |
| 9436 | .doit = nl80211_set_mpath, |
| 9437 | .policy = nl80211_policy, |
| 9438 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9439 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9440 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9441 | }, |
| 9442 | { |
| 9443 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9444 | .doit = nl80211_new_mpath, |
| 9445 | .policy = nl80211_policy, |
| 9446 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9447 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9448 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9449 | }, |
| 9450 | { |
| 9451 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9452 | .doit = nl80211_del_mpath, |
| 9453 | .policy = nl80211_policy, |
| 9454 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9455 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9456 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9457 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9458 | { |
| 9459 | .cmd = NL80211_CMD_SET_BSS, |
| 9460 | .doit = nl80211_set_bss, |
| 9461 | .policy = nl80211_policy, |
| 9462 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9463 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9464 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9465 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9466 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9467 | .cmd = NL80211_CMD_GET_REG, |
| 9468 | .doit = nl80211_get_reg, |
| 9469 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9470 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9471 | /* can be retrieved by unprivileged users */ |
| 9472 | }, |
| 9473 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9474 | .cmd = NL80211_CMD_SET_REG, |
| 9475 | .doit = nl80211_set_reg, |
| 9476 | .policy = nl80211_policy, |
| 9477 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9478 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9479 | }, |
| 9480 | { |
| 9481 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9482 | .doit = nl80211_req_set_reg, |
| 9483 | .policy = nl80211_policy, |
| 9484 | .flags = GENL_ADMIN_PERM, |
| 9485 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9486 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9487 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9488 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9489 | .policy = nl80211_policy, |
| 9490 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9491 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9492 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9493 | }, |
| 9494 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9495 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9496 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9497 | .policy = nl80211_policy, |
| 9498 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9499 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9500 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9501 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9502 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9503 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9504 | .doit = nl80211_trigger_scan, |
| 9505 | .policy = nl80211_policy, |
| 9506 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9507 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9508 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9509 | }, |
| 9510 | { |
| 9511 | .cmd = NL80211_CMD_GET_SCAN, |
| 9512 | .policy = nl80211_policy, |
| 9513 | .dumpit = nl80211_dump_scan, |
| 9514 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9515 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9516 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9517 | .doit = nl80211_start_sched_scan, |
| 9518 | .policy = nl80211_policy, |
| 9519 | .flags = GENL_ADMIN_PERM, |
| 9520 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9521 | NL80211_FLAG_NEED_RTNL, |
| 9522 | }, |
| 9523 | { |
| 9524 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9525 | .doit = nl80211_stop_sched_scan, |
| 9526 | .policy = nl80211_policy, |
| 9527 | .flags = GENL_ADMIN_PERM, |
| 9528 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9529 | NL80211_FLAG_NEED_RTNL, |
| 9530 | }, |
| 9531 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9532 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9533 | .doit = nl80211_authenticate, |
| 9534 | .policy = nl80211_policy, |
| 9535 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9536 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9537 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9538 | }, |
| 9539 | { |
| 9540 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9541 | .doit = nl80211_associate, |
| 9542 | .policy = nl80211_policy, |
| 9543 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9544 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9545 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9546 | }, |
| 9547 | { |
| 9548 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9549 | .doit = nl80211_deauthenticate, |
| 9550 | .policy = nl80211_policy, |
| 9551 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9552 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9553 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9554 | }, |
| 9555 | { |
| 9556 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9557 | .doit = nl80211_disassociate, |
| 9558 | .policy = nl80211_policy, |
| 9559 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9560 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9561 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9562 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9563 | { |
| 9564 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9565 | .doit = nl80211_join_ibss, |
| 9566 | .policy = nl80211_policy, |
| 9567 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9568 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9569 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9570 | }, |
| 9571 | { |
| 9572 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9573 | .doit = nl80211_leave_ibss, |
| 9574 | .policy = nl80211_policy, |
| 9575 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9576 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9577 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9578 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9579 | #ifdef CONFIG_NL80211_TESTMODE |
| 9580 | { |
| 9581 | .cmd = NL80211_CMD_TESTMODE, |
| 9582 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9583 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9584 | .policy = nl80211_policy, |
| 9585 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9586 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9587 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9588 | }, |
| 9589 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9590 | { |
| 9591 | .cmd = NL80211_CMD_CONNECT, |
| 9592 | .doit = nl80211_connect, |
| 9593 | .policy = nl80211_policy, |
| 9594 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9595 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9596 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9597 | }, |
| 9598 | { |
| 9599 | .cmd = NL80211_CMD_DISCONNECT, |
| 9600 | .doit = nl80211_disconnect, |
| 9601 | .policy = nl80211_policy, |
| 9602 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9603 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9604 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9605 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9606 | { |
| 9607 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9608 | .doit = nl80211_wiphy_netns, |
| 9609 | .policy = nl80211_policy, |
| 9610 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9611 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9612 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9613 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9614 | { |
| 9615 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9616 | .policy = nl80211_policy, |
| 9617 | .dumpit = nl80211_dump_survey, |
| 9618 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9619 | { |
| 9620 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9621 | .doit = nl80211_setdel_pmksa, |
| 9622 | .policy = nl80211_policy, |
| 9623 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9624 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9625 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9626 | }, |
| 9627 | { |
| 9628 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9629 | .doit = nl80211_setdel_pmksa, |
| 9630 | .policy = nl80211_policy, |
| 9631 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9632 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9633 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9634 | }, |
| 9635 | { |
| 9636 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9637 | .doit = nl80211_flush_pmksa, |
| 9638 | .policy = nl80211_policy, |
| 9639 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9640 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9641 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9642 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9643 | { |
| 9644 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9645 | .doit = nl80211_remain_on_channel, |
| 9646 | .policy = nl80211_policy, |
| 9647 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9648 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9649 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9650 | }, |
| 9651 | { |
| 9652 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9653 | .doit = nl80211_cancel_remain_on_channel, |
| 9654 | .policy = nl80211_policy, |
| 9655 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9656 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9657 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9658 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9659 | { |
| 9660 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9661 | .doit = nl80211_set_tx_bitrate_mask, |
| 9662 | .policy = nl80211_policy, |
| 9663 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9664 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9665 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9666 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9667 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9668 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9669 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9670 | .policy = nl80211_policy, |
| 9671 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9672 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9673 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9674 | }, |
| 9675 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9676 | .cmd = NL80211_CMD_FRAME, |
| 9677 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9678 | .policy = nl80211_policy, |
| 9679 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9680 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9681 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9682 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9683 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9684 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9685 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9686 | .policy = nl80211_policy, |
| 9687 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9688 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9689 | NL80211_FLAG_NEED_RTNL, |
| 9690 | }, |
| 9691 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9692 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9693 | .doit = nl80211_set_power_save, |
| 9694 | .policy = nl80211_policy, |
| 9695 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9696 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9697 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9698 | }, |
| 9699 | { |
| 9700 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9701 | .doit = nl80211_get_power_save, |
| 9702 | .policy = nl80211_policy, |
| 9703 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9704 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9705 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9706 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9707 | { |
| 9708 | .cmd = NL80211_CMD_SET_CQM, |
| 9709 | .doit = nl80211_set_cqm, |
| 9710 | .policy = nl80211_policy, |
| 9711 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9712 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9713 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9714 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9715 | { |
| 9716 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9717 | .doit = nl80211_set_channel, |
| 9718 | .policy = nl80211_policy, |
| 9719 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9720 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9721 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9722 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9723 | { |
| 9724 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9725 | .doit = nl80211_set_wds_peer, |
| 9726 | .policy = nl80211_policy, |
| 9727 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9728 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9729 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9730 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9731 | { |
| 9732 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9733 | .doit = nl80211_join_mesh, |
| 9734 | .policy = nl80211_policy, |
| 9735 | .flags = GENL_ADMIN_PERM, |
| 9736 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9737 | NL80211_FLAG_NEED_RTNL, |
| 9738 | }, |
| 9739 | { |
| 9740 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9741 | .doit = nl80211_leave_mesh, |
| 9742 | .policy = nl80211_policy, |
| 9743 | .flags = GENL_ADMIN_PERM, |
| 9744 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9745 | NL80211_FLAG_NEED_RTNL, |
| 9746 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9747 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9748 | { |
| 9749 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9750 | .doit = nl80211_get_wowlan, |
| 9751 | .policy = nl80211_policy, |
| 9752 | /* can be retrieved by unprivileged users */ |
| 9753 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9754 | NL80211_FLAG_NEED_RTNL, |
| 9755 | }, |
| 9756 | { |
| 9757 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9758 | .doit = nl80211_set_wowlan, |
| 9759 | .policy = nl80211_policy, |
| 9760 | .flags = GENL_ADMIN_PERM, |
| 9761 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9762 | NL80211_FLAG_NEED_RTNL, |
| 9763 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9764 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9765 | { |
| 9766 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9767 | .doit = nl80211_set_rekey_data, |
| 9768 | .policy = nl80211_policy, |
| 9769 | .flags = GENL_ADMIN_PERM, |
| 9770 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9771 | NL80211_FLAG_NEED_RTNL, |
| 9772 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9773 | { |
| 9774 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9775 | .doit = nl80211_tdls_mgmt, |
| 9776 | .policy = nl80211_policy, |
| 9777 | .flags = GENL_ADMIN_PERM, |
| 9778 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9779 | NL80211_FLAG_NEED_RTNL, |
| 9780 | }, |
| 9781 | { |
| 9782 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9783 | .doit = nl80211_tdls_oper, |
| 9784 | .policy = nl80211_policy, |
| 9785 | .flags = GENL_ADMIN_PERM, |
| 9786 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9787 | NL80211_FLAG_NEED_RTNL, |
| 9788 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9789 | { |
| 9790 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9791 | .doit = nl80211_register_unexpected_frame, |
| 9792 | .policy = nl80211_policy, |
| 9793 | .flags = GENL_ADMIN_PERM, |
| 9794 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9795 | NL80211_FLAG_NEED_RTNL, |
| 9796 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9797 | { |
| 9798 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9799 | .doit = nl80211_probe_client, |
| 9800 | .policy = nl80211_policy, |
| 9801 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9802 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9803 | NL80211_FLAG_NEED_RTNL, |
| 9804 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9805 | { |
| 9806 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9807 | .doit = nl80211_register_beacons, |
| 9808 | .policy = nl80211_policy, |
| 9809 | .flags = GENL_ADMIN_PERM, |
| 9810 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9811 | NL80211_FLAG_NEED_RTNL, |
| 9812 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9813 | { |
| 9814 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9815 | .doit = nl80211_set_noack_map, |
| 9816 | .policy = nl80211_policy, |
| 9817 | .flags = GENL_ADMIN_PERM, |
| 9818 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9819 | NL80211_FLAG_NEED_RTNL, |
| 9820 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9821 | { |
| 9822 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 9823 | .doit = nl80211_start_p2p_device, |
| 9824 | .policy = nl80211_policy, |
| 9825 | .flags = GENL_ADMIN_PERM, |
| 9826 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9827 | NL80211_FLAG_NEED_RTNL, |
| 9828 | }, |
| 9829 | { |
| 9830 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 9831 | .doit = nl80211_stop_p2p_device, |
| 9832 | .policy = nl80211_policy, |
| 9833 | .flags = GENL_ADMIN_PERM, |
| 9834 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9835 | NL80211_FLAG_NEED_RTNL, |
| 9836 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9837 | { |
| 9838 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 9839 | .doit = nl80211_set_mcast_rate, |
| 9840 | .policy = nl80211_policy, |
| 9841 | .flags = GENL_ADMIN_PERM, |
| 9842 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9843 | NL80211_FLAG_NEED_RTNL, |
| 9844 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 9845 | { |
| 9846 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 9847 | .doit = nl80211_set_mac_acl, |
| 9848 | .policy = nl80211_policy, |
| 9849 | .flags = GENL_ADMIN_PERM, |
| 9850 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9851 | NL80211_FLAG_NEED_RTNL, |
| 9852 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9853 | { |
| 9854 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 9855 | .doit = nl80211_start_radar_detection, |
| 9856 | .policy = nl80211_policy, |
| 9857 | .flags = GENL_ADMIN_PERM, |
| 9858 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9859 | NL80211_FLAG_NEED_RTNL, |
| 9860 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9861 | { |
| 9862 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 9863 | .doit = nl80211_get_protocol_features, |
| 9864 | .policy = nl80211_policy, |
| 9865 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9866 | { |
| 9867 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9868 | .doit = nl80211_update_ft_ies, |
| 9869 | .policy = nl80211_policy, |
| 9870 | .flags = GENL_ADMIN_PERM, |
| 9871 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9872 | NL80211_FLAG_NEED_RTNL, |
| 9873 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9874 | { |
| 9875 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9876 | .doit = nl80211_crit_protocol_start, |
| 9877 | .policy = nl80211_policy, |
| 9878 | .flags = GENL_ADMIN_PERM, |
| 9879 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9880 | NL80211_FLAG_NEED_RTNL, |
| 9881 | }, |
| 9882 | { |
| 9883 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9884 | .doit = nl80211_crit_protocol_stop, |
| 9885 | .policy = nl80211_policy, |
| 9886 | .flags = GENL_ADMIN_PERM, |
| 9887 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9888 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9889 | }, |
| 9890 | { |
| 9891 | .cmd = NL80211_CMD_GET_COALESCE, |
| 9892 | .doit = nl80211_get_coalesce, |
| 9893 | .policy = nl80211_policy, |
| 9894 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9895 | NL80211_FLAG_NEED_RTNL, |
| 9896 | }, |
| 9897 | { |
| 9898 | .cmd = NL80211_CMD_SET_COALESCE, |
| 9899 | .doit = nl80211_set_coalesce, |
| 9900 | .policy = nl80211_policy, |
| 9901 | .flags = GENL_ADMIN_PERM, |
| 9902 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9903 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9904 | }, |
| 9905 | { |
| 9906 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 9907 | .doit = nl80211_channel_switch, |
| 9908 | .policy = nl80211_policy, |
| 9909 | .flags = GENL_ADMIN_PERM, |
| 9910 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9911 | NL80211_FLAG_NEED_RTNL, |
| 9912 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9913 | { |
| 9914 | .cmd = NL80211_CMD_VENDOR, |
| 9915 | .doit = nl80211_vendor_cmd, |
| 9916 | .policy = nl80211_policy, |
| 9917 | .flags = GENL_ADMIN_PERM, |
| 9918 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9919 | NL80211_FLAG_NEED_RTNL, |
| 9920 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9921 | { |
| 9922 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 9923 | .doit = nl80211_set_qos_map, |
| 9924 | .policy = nl80211_policy, |
| 9925 | .flags = GENL_ADMIN_PERM, |
| 9926 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9927 | NL80211_FLAG_NEED_RTNL, |
| 9928 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9929 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9930 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9931 | /* notification functions */ |
| 9932 | |
| 9933 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 9934 | { |
| 9935 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9936 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9937 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9938 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9939 | if (!msg) |
| 9940 | return; |
| 9941 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9942 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9943 | nlmsg_free(msg); |
| 9944 | return; |
| 9945 | } |
| 9946 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9947 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 9948 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9949 | } |
| 9950 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9951 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9952 | struct cfg80211_registered_device *rdev) |
| 9953 | { |
| 9954 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9955 | struct nlattr *nest; |
| 9956 | int i; |
| 9957 | |
| 9958 | if (WARN_ON(!req)) |
| 9959 | return 0; |
| 9960 | |
| 9961 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9962 | if (!nest) |
| 9963 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9964 | for (i = 0; i < req->n_ssids; i++) { |
| 9965 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9966 | goto nla_put_failure; |
| 9967 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9968 | nla_nest_end(msg, nest); |
| 9969 | |
| 9970 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9971 | if (!nest) |
| 9972 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9973 | for (i = 0; i < req->n_channels; i++) { |
| 9974 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9975 | goto nla_put_failure; |
| 9976 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9977 | nla_nest_end(msg, nest); |
| 9978 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9979 | if (req->ie && |
| 9980 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9981 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9982 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 9983 | if (req->flags && |
| 9984 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 9985 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9986 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9987 | return 0; |
| 9988 | nla_put_failure: |
| 9989 | return -ENOBUFS; |
| 9990 | } |
| 9991 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9992 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9993 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9994 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9995 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9996 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9997 | { |
| 9998 | void *hdr; |
| 9999 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10000 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10001 | if (!hdr) |
| 10002 | return -1; |
| 10003 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10004 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10005 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10006 | wdev->netdev->ifindex)) || |
| 10007 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10008 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10009 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10010 | /* ignore errors and send incomplete event anyway */ |
| 10011 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10012 | |
| 10013 | return genlmsg_end(msg, hdr); |
| 10014 | |
| 10015 | nla_put_failure: |
| 10016 | genlmsg_cancel(msg, hdr); |
| 10017 | return -EMSGSIZE; |
| 10018 | } |
| 10019 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10020 | static int |
| 10021 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 10022 | struct cfg80211_registered_device *rdev, |
| 10023 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10024 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10025 | { |
| 10026 | void *hdr; |
| 10027 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10028 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10029 | if (!hdr) |
| 10030 | return -1; |
| 10031 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10032 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10033 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10034 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10035 | |
| 10036 | return genlmsg_end(msg, hdr); |
| 10037 | |
| 10038 | nla_put_failure: |
| 10039 | genlmsg_cancel(msg, hdr); |
| 10040 | return -EMSGSIZE; |
| 10041 | } |
| 10042 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10043 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10044 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10045 | { |
| 10046 | struct sk_buff *msg; |
| 10047 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10048 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10049 | if (!msg) |
| 10050 | return; |
| 10051 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10052 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10053 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 10054 | nlmsg_free(msg); |
| 10055 | return; |
| 10056 | } |
| 10057 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10058 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10059 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10060 | } |
| 10061 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10062 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10063 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10064 | { |
| 10065 | struct sk_buff *msg; |
| 10066 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10067 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10068 | if (!msg) |
| 10069 | return; |
| 10070 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10071 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10072 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 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); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10079 | } |
| 10080 | |
| 10081 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10082 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10083 | { |
| 10084 | struct sk_buff *msg; |
| 10085 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10086 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10087 | if (!msg) |
| 10088 | return; |
| 10089 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10090 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10091 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10092 | nlmsg_free(msg); |
| 10093 | return; |
| 10094 | } |
| 10095 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10096 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10097 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10098 | } |
| 10099 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10100 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 10101 | struct net_device *netdev) |
| 10102 | { |
| 10103 | struct sk_buff *msg; |
| 10104 | |
| 10105 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10106 | if (!msg) |
| 10107 | return; |
| 10108 | |
| 10109 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 10110 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 10111 | nlmsg_free(msg); |
| 10112 | return; |
| 10113 | } |
| 10114 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10115 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10116 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10117 | } |
| 10118 | |
| 10119 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 10120 | struct net_device *netdev, u32 cmd) |
| 10121 | { |
| 10122 | struct sk_buff *msg; |
| 10123 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10124 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10125 | if (!msg) |
| 10126 | return; |
| 10127 | |
| 10128 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 10129 | nlmsg_free(msg); |
| 10130 | return; |
| 10131 | } |
| 10132 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10133 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10134 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10135 | } |
| 10136 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10137 | /* |
| 10138 | * This can happen on global regulatory changes or device specific settings |
| 10139 | * based on custom world regulatory domains. |
| 10140 | */ |
| 10141 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 10142 | { |
| 10143 | struct sk_buff *msg; |
| 10144 | void *hdr; |
| 10145 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10146 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10147 | if (!msg) |
| 10148 | return; |
| 10149 | |
| 10150 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 10151 | if (!hdr) { |
| 10152 | nlmsg_free(msg); |
| 10153 | return; |
| 10154 | } |
| 10155 | |
| 10156 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10157 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 10158 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10159 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10160 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 10161 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10162 | NL80211_REGDOM_TYPE_WORLD)) |
| 10163 | goto nla_put_failure; |
| 10164 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 10165 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10166 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 10167 | goto nla_put_failure; |
| 10168 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 10169 | request->intersect) { |
| 10170 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10171 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 10172 | goto nla_put_failure; |
| 10173 | } else { |
| 10174 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10175 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 10176 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 10177 | request->alpha2)) |
| 10178 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10179 | } |
| 10180 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 10181 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10182 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 10183 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10184 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10185 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10186 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10187 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10188 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10189 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10190 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10191 | |
| 10192 | return; |
| 10193 | |
| 10194 | nla_put_failure: |
| 10195 | genlmsg_cancel(msg, hdr); |
| 10196 | nlmsg_free(msg); |
| 10197 | } |
| 10198 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10199 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 10200 | struct net_device *netdev, |
| 10201 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10202 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10203 | { |
| 10204 | struct sk_buff *msg; |
| 10205 | void *hdr; |
| 10206 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10207 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10208 | if (!msg) |
| 10209 | return; |
| 10210 | |
| 10211 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10212 | if (!hdr) { |
| 10213 | nlmsg_free(msg); |
| 10214 | return; |
| 10215 | } |
| 10216 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10217 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10218 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10219 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10220 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10221 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10222 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10223 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10224 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10225 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10226 | return; |
| 10227 | |
| 10228 | nla_put_failure: |
| 10229 | genlmsg_cancel(msg, hdr); |
| 10230 | nlmsg_free(msg); |
| 10231 | } |
| 10232 | |
| 10233 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10234 | struct net_device *netdev, const u8 *buf, |
| 10235 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10236 | { |
| 10237 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10238 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10239 | } |
| 10240 | |
| 10241 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 10242 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10243 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10244 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10245 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 10246 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10247 | } |
| 10248 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10249 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10250 | struct net_device *netdev, const u8 *buf, |
| 10251 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10252 | { |
| 10253 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10254 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10255 | } |
| 10256 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10257 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 10258 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10259 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10260 | { |
| 10261 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10262 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10263 | } |
| 10264 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10265 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 10266 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10267 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10268 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10269 | struct wiphy *wiphy = wdev->wiphy; |
| 10270 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10271 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 10272 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10273 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10274 | if (WARN_ON(len < 2)) |
| 10275 | return; |
| 10276 | |
| 10277 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 10278 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 10279 | else |
| 10280 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 10281 | |
| 10282 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 10283 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10284 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10285 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10286 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 10287 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 10288 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10289 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10290 | { |
| 10291 | struct sk_buff *msg; |
| 10292 | void *hdr; |
| 10293 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10294 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10295 | if (!msg) |
| 10296 | return; |
| 10297 | |
| 10298 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10299 | if (!hdr) { |
| 10300 | nlmsg_free(msg); |
| 10301 | return; |
| 10302 | } |
| 10303 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10304 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10305 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10306 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 10307 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10308 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10309 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10310 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [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); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10314 | return; |
| 10315 | |
| 10316 | nla_put_failure: |
| 10317 | genlmsg_cancel(msg, hdr); |
| 10318 | nlmsg_free(msg); |
| 10319 | } |
| 10320 | |
| 10321 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10322 | struct net_device *netdev, const u8 *addr, |
| 10323 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10324 | { |
| 10325 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10326 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10327 | } |
| 10328 | |
| 10329 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10330 | struct net_device *netdev, const u8 *addr, |
| 10331 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10332 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10333 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 10334 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10335 | } |
| 10336 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10337 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 10338 | struct net_device *netdev, const u8 *bssid, |
| 10339 | const u8 *req_ie, size_t req_ie_len, |
| 10340 | const u8 *resp_ie, size_t resp_ie_len, |
| 10341 | u16 status, gfp_t gfp) |
| 10342 | { |
| 10343 | struct sk_buff *msg; |
| 10344 | void *hdr; |
| 10345 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10346 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10347 | if (!msg) |
| 10348 | return; |
| 10349 | |
| 10350 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10351 | if (!hdr) { |
| 10352 | nlmsg_free(msg); |
| 10353 | return; |
| 10354 | } |
| 10355 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10356 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10357 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10358 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10359 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10360 | (req_ie && |
| 10361 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10362 | (resp_ie && |
| 10363 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10364 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10365 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10366 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10367 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10368 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10369 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10370 | return; |
| 10371 | |
| 10372 | nla_put_failure: |
| 10373 | genlmsg_cancel(msg, hdr); |
| 10374 | nlmsg_free(msg); |
| 10375 | |
| 10376 | } |
| 10377 | |
| 10378 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10379 | struct net_device *netdev, const u8 *bssid, |
| 10380 | const u8 *req_ie, size_t req_ie_len, |
| 10381 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10382 | { |
| 10383 | struct sk_buff *msg; |
| 10384 | void *hdr; |
| 10385 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10386 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10387 | if (!msg) |
| 10388 | return; |
| 10389 | |
| 10390 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10391 | if (!hdr) { |
| 10392 | nlmsg_free(msg); |
| 10393 | return; |
| 10394 | } |
| 10395 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10396 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10397 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10398 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10399 | (req_ie && |
| 10400 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10401 | (resp_ie && |
| 10402 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10403 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10404 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10405 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10406 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10407 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10408 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10409 | return; |
| 10410 | |
| 10411 | nla_put_failure: |
| 10412 | genlmsg_cancel(msg, hdr); |
| 10413 | nlmsg_free(msg); |
| 10414 | |
| 10415 | } |
| 10416 | |
| 10417 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10418 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10419 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10420 | { |
| 10421 | struct sk_buff *msg; |
| 10422 | void *hdr; |
| 10423 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10424 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10425 | if (!msg) |
| 10426 | return; |
| 10427 | |
| 10428 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10429 | if (!hdr) { |
| 10430 | nlmsg_free(msg); |
| 10431 | return; |
| 10432 | } |
| 10433 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10434 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10435 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10436 | (from_ap && reason && |
| 10437 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10438 | (from_ap && |
| 10439 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10440 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10441 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10442 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10443 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10444 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10445 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10446 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10447 | return; |
| 10448 | |
| 10449 | nla_put_failure: |
| 10450 | genlmsg_cancel(msg, hdr); |
| 10451 | nlmsg_free(msg); |
| 10452 | |
| 10453 | } |
| 10454 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10455 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10456 | struct net_device *netdev, const u8 *bssid, |
| 10457 | gfp_t gfp) |
| 10458 | { |
| 10459 | struct sk_buff *msg; |
| 10460 | void *hdr; |
| 10461 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10462 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10463 | if (!msg) |
| 10464 | return; |
| 10465 | |
| 10466 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10467 | if (!hdr) { |
| 10468 | nlmsg_free(msg); |
| 10469 | return; |
| 10470 | } |
| 10471 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10472 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10473 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10474 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10475 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10476 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10477 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10478 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10479 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10480 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10481 | return; |
| 10482 | |
| 10483 | nla_put_failure: |
| 10484 | genlmsg_cancel(msg, hdr); |
| 10485 | nlmsg_free(msg); |
| 10486 | } |
| 10487 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10488 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10489 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10490 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10491 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10492 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10493 | struct sk_buff *msg; |
| 10494 | void *hdr; |
| 10495 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10496 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10497 | return; |
| 10498 | |
| 10499 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10500 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10501 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10502 | if (!msg) |
| 10503 | return; |
| 10504 | |
| 10505 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10506 | if (!hdr) { |
| 10507 | nlmsg_free(msg); |
| 10508 | return; |
| 10509 | } |
| 10510 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10511 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10512 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10513 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10514 | (ie_len && ie && |
| 10515 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10516 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10517 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10518 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10519 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10520 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10521 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10522 | return; |
| 10523 | |
| 10524 | nla_put_failure: |
| 10525 | genlmsg_cancel(msg, hdr); |
| 10526 | nlmsg_free(msg); |
| 10527 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10528 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10529 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10530 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10531 | struct net_device *netdev, const u8 *addr, |
| 10532 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10533 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10534 | { |
| 10535 | struct sk_buff *msg; |
| 10536 | void *hdr; |
| 10537 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10538 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10539 | if (!msg) |
| 10540 | return; |
| 10541 | |
| 10542 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10543 | if (!hdr) { |
| 10544 | nlmsg_free(msg); |
| 10545 | return; |
| 10546 | } |
| 10547 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10548 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10549 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10550 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10551 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10552 | (key_id != -1 && |
| 10553 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10554 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10555 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10556 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10557 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10558 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10559 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10560 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10561 | return; |
| 10562 | |
| 10563 | nla_put_failure: |
| 10564 | genlmsg_cancel(msg, hdr); |
| 10565 | nlmsg_free(msg); |
| 10566 | } |
| 10567 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10568 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10569 | struct ieee80211_channel *channel_before, |
| 10570 | struct ieee80211_channel *channel_after) |
| 10571 | { |
| 10572 | struct sk_buff *msg; |
| 10573 | void *hdr; |
| 10574 | struct nlattr *nl_freq; |
| 10575 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10576 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10577 | if (!msg) |
| 10578 | return; |
| 10579 | |
| 10580 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10581 | if (!hdr) { |
| 10582 | nlmsg_free(msg); |
| 10583 | return; |
| 10584 | } |
| 10585 | |
| 10586 | /* |
| 10587 | * Since we are applying the beacon hint to a wiphy we know its |
| 10588 | * wiphy_idx is valid |
| 10589 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10590 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10591 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10592 | |
| 10593 | /* Before */ |
| 10594 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10595 | if (!nl_freq) |
| 10596 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10597 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10598 | goto nla_put_failure; |
| 10599 | nla_nest_end(msg, nl_freq); |
| 10600 | |
| 10601 | /* After */ |
| 10602 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10603 | if (!nl_freq) |
| 10604 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10605 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10606 | goto nla_put_failure; |
| 10607 | nla_nest_end(msg, nl_freq); |
| 10608 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10609 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10610 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10611 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10612 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10613 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10614 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10615 | |
| 10616 | return; |
| 10617 | |
| 10618 | nla_put_failure: |
| 10619 | genlmsg_cancel(msg, hdr); |
| 10620 | nlmsg_free(msg); |
| 10621 | } |
| 10622 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10623 | static void nl80211_send_remain_on_chan_event( |
| 10624 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10625 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10626 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10627 | unsigned int duration, gfp_t gfp) |
| 10628 | { |
| 10629 | struct sk_buff *msg; |
| 10630 | void *hdr; |
| 10631 | |
| 10632 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10633 | if (!msg) |
| 10634 | return; |
| 10635 | |
| 10636 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10637 | if (!hdr) { |
| 10638 | nlmsg_free(msg); |
| 10639 | return; |
| 10640 | } |
| 10641 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10642 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10643 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10644 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10645 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10646 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10647 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10648 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10649 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10650 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10651 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10652 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10653 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10654 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10655 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10656 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10657 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10658 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10659 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10660 | return; |
| 10661 | |
| 10662 | nla_put_failure: |
| 10663 | genlmsg_cancel(msg, hdr); |
| 10664 | nlmsg_free(msg); |
| 10665 | } |
| 10666 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10667 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10668 | struct ieee80211_channel *chan, |
| 10669 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10670 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10671 | struct wiphy *wiphy = wdev->wiphy; |
| 10672 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10673 | |
| 10674 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10675 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10676 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10677 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10678 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10679 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10680 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10681 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10682 | struct ieee80211_channel *chan, |
| 10683 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10684 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10685 | struct wiphy *wiphy = wdev->wiphy; |
| 10686 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10687 | |
| 10688 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10689 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10690 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10691 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10692 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10693 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10694 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10695 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10696 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10697 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10698 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10699 | struct sk_buff *msg; |
| 10700 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10701 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10702 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10703 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10704 | if (!msg) |
| 10705 | return; |
| 10706 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10707 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10708 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10709 | nlmsg_free(msg); |
| 10710 | return; |
| 10711 | } |
| 10712 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10713 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10714 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10715 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10716 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10717 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10718 | 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] | 10719 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10720 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10721 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10722 | struct sk_buff *msg; |
| 10723 | void *hdr; |
| 10724 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10725 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10726 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10727 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10728 | if (!msg) |
| 10729 | return; |
| 10730 | |
| 10731 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10732 | if (!hdr) { |
| 10733 | nlmsg_free(msg); |
| 10734 | return; |
| 10735 | } |
| 10736 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10737 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10738 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10739 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10740 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10741 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10742 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10743 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10744 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10745 | return; |
| 10746 | |
| 10747 | nla_put_failure: |
| 10748 | genlmsg_cancel(msg, hdr); |
| 10749 | nlmsg_free(msg); |
| 10750 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10751 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10752 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10753 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10754 | enum nl80211_connect_failed_reason reason, |
| 10755 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10756 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10757 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10758 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10759 | struct sk_buff *msg; |
| 10760 | void *hdr; |
| 10761 | |
| 10762 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10763 | if (!msg) |
| 10764 | return; |
| 10765 | |
| 10766 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10767 | if (!hdr) { |
| 10768 | nlmsg_free(msg); |
| 10769 | return; |
| 10770 | } |
| 10771 | |
| 10772 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10773 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10774 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10775 | goto nla_put_failure; |
| 10776 | |
| 10777 | genlmsg_end(msg, hdr); |
| 10778 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10779 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10780 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10781 | return; |
| 10782 | |
| 10783 | nla_put_failure: |
| 10784 | genlmsg_cancel(msg, hdr); |
| 10785 | nlmsg_free(msg); |
| 10786 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10787 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10788 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10789 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10790 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10791 | { |
| 10792 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10793 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10794 | struct sk_buff *msg; |
| 10795 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10796 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10797 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10798 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10799 | return false; |
| 10800 | |
| 10801 | msg = nlmsg_new(100, gfp); |
| 10802 | if (!msg) |
| 10803 | return true; |
| 10804 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10805 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10806 | if (!hdr) { |
| 10807 | nlmsg_free(msg); |
| 10808 | return true; |
| 10809 | } |
| 10810 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10811 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10812 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10813 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10814 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10815 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10816 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10817 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10818 | return true; |
| 10819 | |
| 10820 | nla_put_failure: |
| 10821 | genlmsg_cancel(msg, hdr); |
| 10822 | nlmsg_free(msg); |
| 10823 | return true; |
| 10824 | } |
| 10825 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10826 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 10827 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10828 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10829 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10830 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10831 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10832 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 10833 | |
| 10834 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10835 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 10836 | trace_cfg80211_return_bool(false); |
| 10837 | return false; |
| 10838 | } |
| 10839 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 10840 | addr, gfp); |
| 10841 | trace_cfg80211_return_bool(ret); |
| 10842 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10843 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10844 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 10845 | |
| 10846 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 10847 | const u8 *addr, gfp_t gfp) |
| 10848 | { |
| 10849 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10850 | bool ret; |
| 10851 | |
| 10852 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 10853 | |
| 10854 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10855 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 10856 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 10857 | trace_cfg80211_return_bool(false); |
| 10858 | return false; |
| 10859 | } |
| 10860 | ret = __nl80211_unexpected_frame(dev, |
| 10861 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 10862 | addr, gfp); |
| 10863 | trace_cfg80211_return_bool(ret); |
| 10864 | return ret; |
| 10865 | } |
| 10866 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10867 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10868 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10869 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 10870 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10871 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10872 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10873 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10874 | struct sk_buff *msg; |
| 10875 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10876 | |
| 10877 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10878 | if (!msg) |
| 10879 | return -ENOMEM; |
| 10880 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10881 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10882 | if (!hdr) { |
| 10883 | nlmsg_free(msg); |
| 10884 | return -ENOMEM; |
| 10885 | } |
| 10886 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10887 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10888 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10889 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10890 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10891 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10892 | (sig_dbm && |
| 10893 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10894 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10895 | (flags && |
| 10896 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10897 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10898 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10899 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10900 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10901 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10902 | |
| 10903 | nla_put_failure: |
| 10904 | genlmsg_cancel(msg, hdr); |
| 10905 | nlmsg_free(msg); |
| 10906 | return -ENOBUFS; |
| 10907 | } |
| 10908 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10909 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10910 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10911 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10912 | struct wiphy *wiphy = wdev->wiphy; |
| 10913 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10914 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10915 | struct sk_buff *msg; |
| 10916 | void *hdr; |
| 10917 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10918 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10919 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10920 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10921 | if (!msg) |
| 10922 | return; |
| 10923 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10924 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10925 | if (!hdr) { |
| 10926 | nlmsg_free(msg); |
| 10927 | return; |
| 10928 | } |
| 10929 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10930 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10931 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10932 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10933 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10934 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10935 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10936 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10937 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10938 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10939 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10940 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10941 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10942 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10943 | return; |
| 10944 | |
| 10945 | nla_put_failure: |
| 10946 | genlmsg_cancel(msg, hdr); |
| 10947 | nlmsg_free(msg); |
| 10948 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10949 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10950 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10951 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10952 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10953 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10954 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10955 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10956 | struct wiphy *wiphy = wdev->wiphy; |
| 10957 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10958 | struct sk_buff *msg; |
| 10959 | struct nlattr *pinfoattr; |
| 10960 | void *hdr; |
| 10961 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10962 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10963 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10964 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10965 | if (!msg) |
| 10966 | return; |
| 10967 | |
| 10968 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10969 | if (!hdr) { |
| 10970 | nlmsg_free(msg); |
| 10971 | return; |
| 10972 | } |
| 10973 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10974 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10975 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10976 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10977 | |
| 10978 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10979 | if (!pinfoattr) |
| 10980 | goto nla_put_failure; |
| 10981 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10982 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10983 | rssi_event)) |
| 10984 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10985 | |
| 10986 | nla_nest_end(msg, pinfoattr); |
| 10987 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10988 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10989 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10990 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10991 | NL80211_MCGRP_MLME, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10992 | return; |
| 10993 | |
| 10994 | nla_put_failure: |
| 10995 | genlmsg_cancel(msg, hdr); |
| 10996 | nlmsg_free(msg); |
| 10997 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10998 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10999 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11000 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 11001 | struct net_device *netdev, const u8 *bssid, |
| 11002 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11003 | { |
| 11004 | struct sk_buff *msg; |
| 11005 | struct nlattr *rekey_attr; |
| 11006 | void *hdr; |
| 11007 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11008 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11009 | if (!msg) |
| 11010 | return; |
| 11011 | |
| 11012 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 11013 | if (!hdr) { |
| 11014 | nlmsg_free(msg); |
| 11015 | return; |
| 11016 | } |
| 11017 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11018 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11019 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11020 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 11021 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11022 | |
| 11023 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 11024 | if (!rekey_attr) |
| 11025 | goto nla_put_failure; |
| 11026 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11027 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 11028 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 11029 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11030 | |
| 11031 | nla_nest_end(msg, rekey_attr); |
| 11032 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11033 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11034 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11035 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11036 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11037 | return; |
| 11038 | |
| 11039 | nla_put_failure: |
| 11040 | genlmsg_cancel(msg, hdr); |
| 11041 | nlmsg_free(msg); |
| 11042 | } |
| 11043 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11044 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 11045 | const u8 *replay_ctr, gfp_t gfp) |
| 11046 | { |
| 11047 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11048 | struct wiphy *wiphy = wdev->wiphy; |
| 11049 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11050 | |
| 11051 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 11052 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 11053 | } |
| 11054 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 11055 | |
| 11056 | static void |
| 11057 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 11058 | struct net_device *netdev, int index, |
| 11059 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11060 | { |
| 11061 | struct sk_buff *msg; |
| 11062 | struct nlattr *attr; |
| 11063 | void *hdr; |
| 11064 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11065 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11066 | if (!msg) |
| 11067 | return; |
| 11068 | |
| 11069 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 11070 | if (!hdr) { |
| 11071 | nlmsg_free(msg); |
| 11072 | return; |
| 11073 | } |
| 11074 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11075 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11076 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11077 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11078 | |
| 11079 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 11080 | if (!attr) |
| 11081 | goto nla_put_failure; |
| 11082 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11083 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 11084 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 11085 | (preauth && |
| 11086 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 11087 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11088 | |
| 11089 | nla_nest_end(msg, attr); |
| 11090 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11091 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11092 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11093 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11094 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11095 | return; |
| 11096 | |
| 11097 | nla_put_failure: |
| 11098 | genlmsg_cancel(msg, hdr); |
| 11099 | nlmsg_free(msg); |
| 11100 | } |
| 11101 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11102 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 11103 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 11104 | { |
| 11105 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11106 | struct wiphy *wiphy = wdev->wiphy; |
| 11107 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11108 | |
| 11109 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 11110 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 11111 | } |
| 11112 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 11113 | |
| 11114 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 11115 | struct net_device *netdev, |
| 11116 | struct cfg80211_chan_def *chandef, |
| 11117 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11118 | { |
| 11119 | struct sk_buff *msg; |
| 11120 | void *hdr; |
| 11121 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11122 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11123 | if (!msg) |
| 11124 | return; |
| 11125 | |
| 11126 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 11127 | if (!hdr) { |
| 11128 | nlmsg_free(msg); |
| 11129 | return; |
| 11130 | } |
| 11131 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11132 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11133 | goto nla_put_failure; |
| 11134 | |
| 11135 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 11136 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11137 | |
| 11138 | genlmsg_end(msg, hdr); |
| 11139 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11140 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11141 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11142 | return; |
| 11143 | |
| 11144 | nla_put_failure: |
| 11145 | genlmsg_cancel(msg, hdr); |
| 11146 | nlmsg_free(msg); |
| 11147 | } |
| 11148 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11149 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 11150 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11151 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11152 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11153 | struct wiphy *wiphy = wdev->wiphy; |
| 11154 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11155 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11156 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11157 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11158 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11159 | |
| 11160 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 11161 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 11162 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 11163 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11164 | return; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11165 | |
| 11166 | wdev->channel = chandef->chan; |
| 11167 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11168 | } |
| 11169 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 11170 | |
| 11171 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 11172 | const u8 *peer, u32 num_packets, |
| 11173 | u32 rate, u32 intvl, gfp_t gfp) |
| 11174 | { |
| 11175 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11176 | struct wiphy *wiphy = wdev->wiphy; |
| 11177 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11178 | struct sk_buff *msg; |
| 11179 | struct nlattr *pinfoattr; |
| 11180 | void *hdr; |
| 11181 | |
| 11182 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11183 | if (!msg) |
| 11184 | return; |
| 11185 | |
| 11186 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11187 | if (!hdr) { |
| 11188 | nlmsg_free(msg); |
| 11189 | return; |
| 11190 | } |
| 11191 | |
| 11192 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11193 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11194 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11195 | goto nla_put_failure; |
| 11196 | |
| 11197 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11198 | if (!pinfoattr) |
| 11199 | goto nla_put_failure; |
| 11200 | |
| 11201 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 11202 | goto nla_put_failure; |
| 11203 | |
| 11204 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 11205 | goto nla_put_failure; |
| 11206 | |
| 11207 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 11208 | goto nla_put_failure; |
| 11209 | |
| 11210 | nla_nest_end(msg, pinfoattr); |
| 11211 | |
| 11212 | genlmsg_end(msg, hdr); |
| 11213 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11214 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11215 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11216 | return; |
| 11217 | |
| 11218 | nla_put_failure: |
| 11219 | genlmsg_cancel(msg, hdr); |
| 11220 | nlmsg_free(msg); |
| 11221 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11222 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11223 | |
| 11224 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11225 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 11226 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11227 | enum nl80211_radar_event event, |
| 11228 | struct net_device *netdev, gfp_t gfp) |
| 11229 | { |
| 11230 | struct sk_buff *msg; |
| 11231 | void *hdr; |
| 11232 | |
| 11233 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11234 | if (!msg) |
| 11235 | return; |
| 11236 | |
| 11237 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 11238 | if (!hdr) { |
| 11239 | nlmsg_free(msg); |
| 11240 | return; |
| 11241 | } |
| 11242 | |
| 11243 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 11244 | goto nla_put_failure; |
| 11245 | |
| 11246 | /* NOP and radar events don't need a netdev parameter */ |
| 11247 | if (netdev) { |
| 11248 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 11249 | |
| 11250 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11251 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11252 | goto nla_put_failure; |
| 11253 | } |
| 11254 | |
| 11255 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 11256 | goto nla_put_failure; |
| 11257 | |
| 11258 | if (nl80211_send_chandef(msg, chandef)) |
| 11259 | goto nla_put_failure; |
| 11260 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11261 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11262 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11263 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11264 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11265 | return; |
| 11266 | |
| 11267 | nla_put_failure: |
| 11268 | genlmsg_cancel(msg, hdr); |
| 11269 | nlmsg_free(msg); |
| 11270 | } |
| 11271 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11272 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 11273 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11274 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11275 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11276 | struct wiphy *wiphy = wdev->wiphy; |
| 11277 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11278 | struct sk_buff *msg; |
| 11279 | struct nlattr *pinfoattr; |
| 11280 | void *hdr; |
| 11281 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11282 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 11283 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11284 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11285 | if (!msg) |
| 11286 | return; |
| 11287 | |
| 11288 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11289 | if (!hdr) { |
| 11290 | nlmsg_free(msg); |
| 11291 | return; |
| 11292 | } |
| 11293 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11294 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11295 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11296 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11297 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11298 | |
| 11299 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11300 | if (!pinfoattr) |
| 11301 | goto nla_put_failure; |
| 11302 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11303 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 11304 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11305 | |
| 11306 | nla_nest_end(msg, pinfoattr); |
| 11307 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11308 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11309 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11310 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11311 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11312 | return; |
| 11313 | |
| 11314 | nla_put_failure: |
| 11315 | genlmsg_cancel(msg, hdr); |
| 11316 | nlmsg_free(msg); |
| 11317 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11318 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11319 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11320 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 11321 | u64 cookie, bool acked, gfp_t gfp) |
| 11322 | { |
| 11323 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11324 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11325 | struct sk_buff *msg; |
| 11326 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11327 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11328 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 11329 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11330 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11331 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11332 | if (!msg) |
| 11333 | return; |
| 11334 | |
| 11335 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 11336 | if (!hdr) { |
| 11337 | nlmsg_free(msg); |
| 11338 | return; |
| 11339 | } |
| 11340 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11341 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11342 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11343 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11344 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11345 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11346 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11347 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11348 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11349 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11350 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11351 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11352 | return; |
| 11353 | |
| 11354 | nla_put_failure: |
| 11355 | genlmsg_cancel(msg, hdr); |
| 11356 | nlmsg_free(msg); |
| 11357 | } |
| 11358 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11359 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11360 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11361 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11362 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11363 | { |
| 11364 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11365 | struct sk_buff *msg; |
| 11366 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11367 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11368 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11369 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11370 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11371 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11372 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11373 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11374 | if (!msg) { |
| 11375 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11376 | return; |
| 11377 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11378 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11379 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11380 | if (!hdr) |
| 11381 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11382 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11383 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11384 | (freq && |
| 11385 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11386 | (sig_dbm && |
| 11387 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11388 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11389 | goto nla_put_failure; |
| 11390 | |
| 11391 | genlmsg_end(msg, hdr); |
| 11392 | |
| 11393 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11394 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11395 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11396 | return; |
| 11397 | |
| 11398 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11399 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11400 | if (hdr) |
| 11401 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11402 | nlmsg_free(msg); |
| 11403 | } |
| 11404 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11405 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11406 | #ifdef CONFIG_PM |
| 11407 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11408 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11409 | gfp_t gfp) |
| 11410 | { |
| 11411 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11412 | struct sk_buff *msg; |
| 11413 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11414 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11415 | |
| 11416 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11417 | |
| 11418 | if (wakeup) |
| 11419 | size += wakeup->packet_present_len; |
| 11420 | |
| 11421 | msg = nlmsg_new(size, gfp); |
| 11422 | if (!msg) |
| 11423 | return; |
| 11424 | |
| 11425 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11426 | if (!hdr) |
| 11427 | goto free_msg; |
| 11428 | |
| 11429 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11430 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11431 | goto free_msg; |
| 11432 | |
| 11433 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11434 | wdev->netdev->ifindex)) |
| 11435 | goto free_msg; |
| 11436 | |
| 11437 | if (wakeup) { |
| 11438 | struct nlattr *reasons; |
| 11439 | |
| 11440 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 11441 | if (!reasons) |
| 11442 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11443 | |
| 11444 | if (wakeup->disconnect && |
| 11445 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11446 | goto free_msg; |
| 11447 | if (wakeup->magic_pkt && |
| 11448 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11449 | goto free_msg; |
| 11450 | if (wakeup->gtk_rekey_failure && |
| 11451 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11452 | goto free_msg; |
| 11453 | if (wakeup->eap_identity_req && |
| 11454 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11455 | goto free_msg; |
| 11456 | if (wakeup->four_way_handshake && |
| 11457 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11458 | goto free_msg; |
| 11459 | if (wakeup->rfkill_release && |
| 11460 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11461 | goto free_msg; |
| 11462 | |
| 11463 | if (wakeup->pattern_idx >= 0 && |
| 11464 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11465 | wakeup->pattern_idx)) |
| 11466 | goto free_msg; |
| 11467 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11468 | if (wakeup->tcp_match && |
| 11469 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 11470 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11471 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11472 | if (wakeup->tcp_connlost && |
| 11473 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 11474 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11475 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11476 | if (wakeup->tcp_nomoretokens && |
| 11477 | nla_put_flag(msg, |
| 11478 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 11479 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11480 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11481 | if (wakeup->packet) { |
| 11482 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11483 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11484 | |
| 11485 | if (!wakeup->packet_80211) { |
| 11486 | pkt_attr = |
| 11487 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11488 | len_attr = |
| 11489 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11490 | } |
| 11491 | |
| 11492 | if (wakeup->packet_len && |
| 11493 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11494 | goto free_msg; |
| 11495 | |
| 11496 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11497 | wakeup->packet)) |
| 11498 | goto free_msg; |
| 11499 | } |
| 11500 | |
| 11501 | nla_nest_end(msg, reasons); |
| 11502 | } |
| 11503 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11504 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11505 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11506 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11507 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11508 | return; |
| 11509 | |
| 11510 | free_msg: |
| 11511 | nlmsg_free(msg); |
| 11512 | } |
| 11513 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11514 | #endif |
| 11515 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11516 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11517 | enum nl80211_tdls_operation oper, |
| 11518 | u16 reason_code, gfp_t gfp) |
| 11519 | { |
| 11520 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11521 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11522 | struct sk_buff *msg; |
| 11523 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11524 | |
| 11525 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11526 | reason_code); |
| 11527 | |
| 11528 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11529 | if (!msg) |
| 11530 | return; |
| 11531 | |
| 11532 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11533 | if (!hdr) { |
| 11534 | nlmsg_free(msg); |
| 11535 | return; |
| 11536 | } |
| 11537 | |
| 11538 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11539 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11540 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11541 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11542 | (reason_code > 0 && |
| 11543 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11544 | goto nla_put_failure; |
| 11545 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11546 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11547 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11548 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11549 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11550 | return; |
| 11551 | |
| 11552 | nla_put_failure: |
| 11553 | genlmsg_cancel(msg, hdr); |
| 11554 | nlmsg_free(msg); |
| 11555 | } |
| 11556 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11557 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11558 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11559 | unsigned long state, |
| 11560 | void *_notify) |
| 11561 | { |
| 11562 | struct netlink_notify *notify = _notify; |
| 11563 | struct cfg80211_registered_device *rdev; |
| 11564 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11565 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11566 | |
| 11567 | if (state != NETLINK_URELEASE) |
| 11568 | return NOTIFY_DONE; |
| 11569 | |
| 11570 | rcu_read_lock(); |
| 11571 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11572 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11573 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11574 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11575 | |
| 11576 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11577 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11578 | list) { |
| 11579 | if (reg->nlportid == notify->portid) { |
| 11580 | list_del(®->list); |
| 11581 | kfree(reg); |
| 11582 | break; |
| 11583 | } |
| 11584 | } |
| 11585 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11586 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11587 | |
| 11588 | rcu_read_unlock(); |
| 11589 | |
| 11590 | return NOTIFY_DONE; |
| 11591 | } |
| 11592 | |
| 11593 | static struct notifier_block nl80211_netlink_notifier = { |
| 11594 | .notifier_call = nl80211_netlink_notify, |
| 11595 | }; |
| 11596 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11597 | void cfg80211_ft_event(struct net_device *netdev, |
| 11598 | struct cfg80211_ft_event_params *ft_event) |
| 11599 | { |
| 11600 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 11601 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11602 | struct sk_buff *msg; |
| 11603 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11604 | |
| 11605 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11606 | |
| 11607 | if (!ft_event->target_ap) |
| 11608 | return; |
| 11609 | |
| 11610 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11611 | if (!msg) |
| 11612 | return; |
| 11613 | |
| 11614 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11615 | if (!hdr) |
| 11616 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11617 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11618 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11619 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11620 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 11621 | goto out; |
| 11622 | |
| 11623 | if (ft_event->ies && |
| 11624 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 11625 | goto out; |
| 11626 | if (ft_event->ric_ies && |
| 11627 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11628 | ft_event->ric_ies)) |
| 11629 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11630 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11631 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11632 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11633 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11634 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11635 | return; |
| 11636 | out: |
| 11637 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11638 | } |
| 11639 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11640 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11641 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11642 | { |
| 11643 | struct cfg80211_registered_device *rdev; |
| 11644 | struct sk_buff *msg; |
| 11645 | void *hdr; |
| 11646 | u32 nlportid; |
| 11647 | |
| 11648 | rdev = wiphy_to_dev(wdev->wiphy); |
| 11649 | if (!rdev->crit_proto_nlportid) |
| 11650 | return; |
| 11651 | |
| 11652 | nlportid = rdev->crit_proto_nlportid; |
| 11653 | rdev->crit_proto_nlportid = 0; |
| 11654 | |
| 11655 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11656 | if (!msg) |
| 11657 | return; |
| 11658 | |
| 11659 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11660 | if (!hdr) |
| 11661 | goto nla_put_failure; |
| 11662 | |
| 11663 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11664 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11665 | goto nla_put_failure; |
| 11666 | |
| 11667 | genlmsg_end(msg, hdr); |
| 11668 | |
| 11669 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11670 | return; |
| 11671 | |
| 11672 | nla_put_failure: |
| 11673 | if (hdr) |
| 11674 | genlmsg_cancel(msg, hdr); |
| 11675 | nlmsg_free(msg); |
| 11676 | |
| 11677 | } |
| 11678 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11679 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11680 | /* initialisation/exit functions */ |
| 11681 | |
| 11682 | int nl80211_init(void) |
| 11683 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11684 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11685 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11686 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 11687 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11688 | if (err) |
| 11689 | return err; |
| 11690 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11691 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11692 | if (err) |
| 11693 | goto err_out; |
| 11694 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11695 | return 0; |
| 11696 | err_out: |
| 11697 | genl_unregister_family(&nl80211_fam); |
| 11698 | return err; |
| 11699 | } |
| 11700 | |
| 11701 | void nl80211_exit(void) |
| 11702 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11703 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11704 | genl_unregister_family(&nl80211_fam); |
| 11705 | } |