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, |
| 56 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 57 | }; |
| 58 | |
| 59 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
| 60 | [NL80211_MCGRP_CONFIG] = { .name = "config", }, |
| 61 | [NL80211_MCGRP_SCAN] = { .name = "scan", }, |
| 62 | [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", }, |
| 63 | [NL80211_MCGRP_MLME] = { .name = "mlme", }, |
| 64 | #ifdef CONFIG_NL80211_TESTMODE |
| 65 | [NL80211_MCGRP_TESTMODE] = { .name = "testmode", } |
| 66 | #endif |
| 67 | }; |
| 68 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 69 | /* returns ERR_PTR values */ |
| 70 | static struct wireless_dev * |
| 71 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 73 | struct cfg80211_registered_device *rdev; |
| 74 | struct wireless_dev *result = NULL; |
| 75 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 76 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 77 | u64 wdev_id; |
| 78 | int wiphy_idx = -1; |
| 79 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 80 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 81 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 82 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 83 | if (!have_ifidx && !have_wdev_id) |
| 84 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 85 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 86 | if (have_ifidx) |
| 87 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 88 | if (have_wdev_id) { |
| 89 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 90 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 91 | } |
| 92 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 93 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 94 | struct wireless_dev *wdev; |
| 95 | |
| 96 | if (wiphy_net(&rdev->wiphy) != netns) |
| 97 | continue; |
| 98 | |
| 99 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 100 | continue; |
| 101 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 102 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 103 | if (have_ifidx && wdev->netdev && |
| 104 | wdev->netdev->ifindex == ifidx) { |
| 105 | result = wdev; |
| 106 | break; |
| 107 | } |
| 108 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 109 | result = wdev; |
| 110 | break; |
| 111 | } |
| 112 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 113 | |
| 114 | if (result) |
| 115 | break; |
| 116 | } |
| 117 | |
| 118 | if (result) |
| 119 | return result; |
| 120 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 121 | } |
| 122 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 123 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 124 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 125 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 126 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 127 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 128 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 129 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 130 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 131 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 132 | !attrs[NL80211_ATTR_IFINDEX] && |
| 133 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 134 | return ERR_PTR(-EINVAL); |
| 135 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 136 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 137 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 138 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 139 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 140 | if (attrs[NL80211_ATTR_WDEV]) { |
| 141 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 142 | struct wireless_dev *wdev; |
| 143 | bool found = false; |
| 144 | |
| 145 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 146 | if (tmp) { |
| 147 | /* make sure wdev exists */ |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 148 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 149 | if (wdev->identifier != (u32)wdev_id) |
| 150 | continue; |
| 151 | found = true; |
| 152 | break; |
| 153 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 154 | |
| 155 | if (!found) |
| 156 | tmp = NULL; |
| 157 | |
| 158 | if (rdev && tmp != rdev) |
| 159 | return ERR_PTR(-EINVAL); |
| 160 | rdev = tmp; |
| 161 | } |
| 162 | } |
| 163 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 164 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 165 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 166 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 167 | if (netdev) { |
| 168 | if (netdev->ieee80211_ptr) |
| 169 | tmp = wiphy_to_dev( |
| 170 | netdev->ieee80211_ptr->wiphy); |
| 171 | else |
| 172 | tmp = NULL; |
| 173 | |
| 174 | dev_put(netdev); |
| 175 | |
| 176 | /* not wireless device -- return error */ |
| 177 | if (!tmp) |
| 178 | return ERR_PTR(-EINVAL); |
| 179 | |
| 180 | /* mismatch -- return error */ |
| 181 | if (rdev && tmp != rdev) |
| 182 | return ERR_PTR(-EINVAL); |
| 183 | |
| 184 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 185 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 188 | if (!rdev) |
| 189 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 190 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 191 | if (netns != wiphy_net(&rdev->wiphy)) |
| 192 | return ERR_PTR(-ENODEV); |
| 193 | |
| 194 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* |
| 198 | * This function returns a pointer to the driver |
| 199 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 200 | * |
| 201 | * The result of this can be a PTR_ERR and hence must |
| 202 | * be checked with IS_ERR() for errors. |
| 203 | */ |
| 204 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 205 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 206 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 207 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 208 | } |
| 209 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 210 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 211 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 212 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 213 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 214 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 215 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 216 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 217 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 218 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 219 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 220 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 221 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 222 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 223 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 224 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 225 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 226 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 227 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 228 | |
| 229 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 230 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 232 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 233 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 234 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 235 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 236 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 237 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 238 | .len = WLAN_MAX_KEY_LEN }, |
| 239 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 240 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 242 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 243 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 244 | |
| 245 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 246 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 247 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 248 | .len = IEEE80211_MAX_DATA_LEN }, |
| 249 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 250 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 251 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 252 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 253 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 254 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 255 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 256 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 257 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 258 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 259 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 260 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 262 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 263 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 264 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 265 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 266 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 267 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 268 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 270 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 271 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 272 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 273 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 274 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 275 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 276 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 277 | |
| 278 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 279 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 280 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 281 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 282 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 283 | |
| 284 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 285 | .len = IEEE80211_MAX_SSID_LEN }, |
| 286 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 287 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 288 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 289 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 290 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 291 | [NL80211_ATTR_STA_FLAGS2] = { |
| 292 | .len = sizeof(struct nl80211_sta_flag_update), |
| 293 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 294 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 296 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 297 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 298 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 299 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 300 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 301 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 302 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 303 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 304 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 305 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 306 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 308 | .len = IEEE80211_MAX_DATA_LEN }, |
| 309 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 310 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 312 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 315 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 317 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 318 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 319 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 320 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 323 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 324 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 325 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 326 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 327 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 328 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 329 | .len = IEEE80211_MAX_DATA_LEN }, |
| 330 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 331 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 332 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 333 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 334 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 336 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 337 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 339 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 340 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 341 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 342 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 343 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 344 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 345 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 346 | .len = NL80211_HT_CAPABILITY_LEN |
| 347 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 348 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 349 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 350 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 351 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 352 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 353 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 354 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 355 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 356 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 357 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 358 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 359 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 360 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 361 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 362 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 363 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 364 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 365 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 366 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 367 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 368 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 369 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 370 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 371 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 372 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 373 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
| 374 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 }, |
| 375 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 376 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 377 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 378 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 379 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 380 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 381 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 382 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 383 | }; |
| 384 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 385 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 386 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 387 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 388 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 389 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 390 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 391 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 392 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 393 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 394 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 395 | }; |
| 396 | |
| 397 | /* policy for the key default flags */ |
| 398 | static const struct nla_policy |
| 399 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 400 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 401 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 402 | }; |
| 403 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 404 | /* policy for WoWLAN attributes */ |
| 405 | static const struct nla_policy |
| 406 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 407 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 408 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 409 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 410 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 411 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 412 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 413 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 414 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 415 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 416 | }; |
| 417 | |
| 418 | static const struct nla_policy |
| 419 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 420 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 421 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 422 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 423 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 424 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 425 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 426 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 427 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 428 | }, |
| 429 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 430 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 431 | }, |
| 432 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 433 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 434 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 435 | }; |
| 436 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 437 | /* policy for coalesce rule attributes */ |
| 438 | static const struct nla_policy |
| 439 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 440 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 441 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 442 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 443 | }; |
| 444 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 445 | /* policy for GTK rekey offload attributes */ |
| 446 | static const struct nla_policy |
| 447 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 448 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 449 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 450 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 451 | }; |
| 452 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 453 | static const struct nla_policy |
| 454 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 455 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 456 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 457 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 458 | }; |
| 459 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 460 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 461 | struct netlink_callback *cb, |
| 462 | struct cfg80211_registered_device **rdev, |
| 463 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 464 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 465 | int err; |
| 466 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 467 | rtnl_lock(); |
| 468 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 469 | if (!cb->args[0]) { |
| 470 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 471 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 472 | nl80211_policy); |
| 473 | if (err) |
| 474 | goto out_unlock; |
| 475 | |
| 476 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 477 | nl80211_fam.attrbuf); |
| 478 | if (IS_ERR(*wdev)) { |
| 479 | err = PTR_ERR(*wdev); |
| 480 | goto out_unlock; |
| 481 | } |
| 482 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 483 | /* 0 is the first index - add 1 to parse only once */ |
| 484 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 485 | cb->args[1] = (*wdev)->identifier; |
| 486 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 487 | /* subtract the 1 again here */ |
| 488 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 489 | struct wireless_dev *tmp; |
| 490 | |
| 491 | if (!wiphy) { |
| 492 | err = -ENODEV; |
| 493 | goto out_unlock; |
| 494 | } |
| 495 | *rdev = wiphy_to_dev(wiphy); |
| 496 | *wdev = NULL; |
| 497 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 498 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 499 | if (tmp->identifier == cb->args[1]) { |
| 500 | *wdev = tmp; |
| 501 | break; |
| 502 | } |
| 503 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 504 | |
| 505 | if (!*wdev) { |
| 506 | err = -ENODEV; |
| 507 | goto out_unlock; |
| 508 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 509 | } |
| 510 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 511 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 512 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 513 | rtnl_unlock(); |
| 514 | return err; |
| 515 | } |
| 516 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 517 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 518 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 519 | rtnl_unlock(); |
| 520 | } |
| 521 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 522 | /* IE validation */ |
| 523 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 524 | { |
| 525 | const u8 *pos; |
| 526 | int len; |
| 527 | |
| 528 | if (!attr) |
| 529 | return true; |
| 530 | |
| 531 | pos = nla_data(attr); |
| 532 | len = nla_len(attr); |
| 533 | |
| 534 | while (len) { |
| 535 | u8 elemlen; |
| 536 | |
| 537 | if (len < 2) |
| 538 | return false; |
| 539 | len -= 2; |
| 540 | |
| 541 | elemlen = pos[1]; |
| 542 | if (elemlen > len) |
| 543 | return false; |
| 544 | |
| 545 | len -= elemlen; |
| 546 | pos += 2 + elemlen; |
| 547 | } |
| 548 | |
| 549 | return true; |
| 550 | } |
| 551 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 552 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 553 | 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] | 554 | int flags, u8 cmd) |
| 555 | { |
| 556 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 557 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 558 | } |
| 559 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 560 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 561 | struct ieee80211_channel *chan, |
| 562 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 563 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 564 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 565 | chan->center_freq)) |
| 566 | goto nla_put_failure; |
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 ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 569 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 570 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 571 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 572 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 573 | goto nla_put_failure; |
| 574 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 575 | goto nla_put_failure; |
| 576 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 577 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 578 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 579 | goto nla_put_failure; |
| 580 | if (large) { |
| 581 | u32 time; |
| 582 | |
| 583 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 584 | |
| 585 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 586 | chan->dfs_state)) |
| 587 | goto nla_put_failure; |
| 588 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 589 | time)) |
| 590 | goto nla_put_failure; |
| 591 | } |
| 592 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 593 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 594 | if (large) { |
| 595 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 596 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 597 | goto nla_put_failure; |
| 598 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 599 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 600 | goto nla_put_failure; |
| 601 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 602 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 603 | goto nla_put_failure; |
| 604 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 605 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 606 | goto nla_put_failure; |
| 607 | } |
| 608 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 609 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 610 | DBM_TO_MBM(chan->max_power))) |
| 611 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 612 | |
| 613 | return 0; |
| 614 | |
| 615 | nla_put_failure: |
| 616 | return -ENOBUFS; |
| 617 | } |
| 618 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 619 | /* netlink command implementations */ |
| 620 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 621 | struct key_parse { |
| 622 | struct key_params p; |
| 623 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 624 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 625 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 626 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 627 | }; |
| 628 | |
| 629 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 630 | { |
| 631 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 632 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 633 | nl80211_key_policy); |
| 634 | if (err) |
| 635 | return err; |
| 636 | |
| 637 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 638 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 639 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 640 | if (k->def) { |
| 641 | k->def_uni = true; |
| 642 | k->def_multi = true; |
| 643 | } |
| 644 | if (k->defmgmt) |
| 645 | k->def_multi = true; |
| 646 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 647 | if (tb[NL80211_KEY_IDX]) |
| 648 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 649 | |
| 650 | if (tb[NL80211_KEY_DATA]) { |
| 651 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 652 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 653 | } |
| 654 | |
| 655 | if (tb[NL80211_KEY_SEQ]) { |
| 656 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 657 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 658 | } |
| 659 | |
| 660 | if (tb[NL80211_KEY_CIPHER]) |
| 661 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 662 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 663 | if (tb[NL80211_KEY_TYPE]) { |
| 664 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 665 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 666 | return -EINVAL; |
| 667 | } |
| 668 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 669 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 670 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 671 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 672 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 673 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 674 | if (err) |
| 675 | return err; |
| 676 | |
| 677 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 678 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 679 | } |
| 680 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 681 | return 0; |
| 682 | } |
| 683 | |
| 684 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 685 | { |
| 686 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 687 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 688 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 689 | } |
| 690 | |
| 691 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 692 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 693 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 694 | } |
| 695 | |
| 696 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 697 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 698 | |
| 699 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 700 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 701 | |
| 702 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 703 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 704 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 705 | if (k->def) { |
| 706 | k->def_uni = true; |
| 707 | k->def_multi = true; |
| 708 | } |
| 709 | if (k->defmgmt) |
| 710 | k->def_multi = true; |
| 711 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 712 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 713 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 714 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 715 | return -EINVAL; |
| 716 | } |
| 717 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 718 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 719 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 720 | int err = nla_parse_nested( |
| 721 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 722 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 723 | nl80211_key_default_policy); |
| 724 | if (err) |
| 725 | return err; |
| 726 | |
| 727 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 728 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 729 | } |
| 730 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 731 | return 0; |
| 732 | } |
| 733 | |
| 734 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 735 | { |
| 736 | int err; |
| 737 | |
| 738 | memset(k, 0, sizeof(*k)); |
| 739 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 740 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 741 | |
| 742 | if (info->attrs[NL80211_ATTR_KEY]) |
| 743 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 744 | else |
| 745 | err = nl80211_parse_key_old(info, k); |
| 746 | |
| 747 | if (err) |
| 748 | return err; |
| 749 | |
| 750 | if (k->def && k->defmgmt) |
| 751 | return -EINVAL; |
| 752 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 753 | if (k->defmgmt) { |
| 754 | if (k->def_uni || !k->def_multi) |
| 755 | return -EINVAL; |
| 756 | } |
| 757 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 758 | if (k->idx != -1) { |
| 759 | if (k->defmgmt) { |
| 760 | if (k->idx < 4 || k->idx > 5) |
| 761 | return -EINVAL; |
| 762 | } else if (k->def) { |
| 763 | if (k->idx < 0 || k->idx > 3) |
| 764 | return -EINVAL; |
| 765 | } else { |
| 766 | if (k->idx < 0 || k->idx > 5) |
| 767 | return -EINVAL; |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | return 0; |
| 772 | } |
| 773 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 774 | static struct cfg80211_cached_keys * |
| 775 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 776 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 777 | { |
| 778 | struct key_parse parse; |
| 779 | struct nlattr *key; |
| 780 | struct cfg80211_cached_keys *result; |
| 781 | int rem, err, def = 0; |
| 782 | |
| 783 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 784 | if (!result) |
| 785 | return ERR_PTR(-ENOMEM); |
| 786 | |
| 787 | result->def = -1; |
| 788 | result->defmgmt = -1; |
| 789 | |
| 790 | nla_for_each_nested(key, keys, rem) { |
| 791 | memset(&parse, 0, sizeof(parse)); |
| 792 | parse.idx = -1; |
| 793 | |
| 794 | err = nl80211_parse_key_new(key, &parse); |
| 795 | if (err) |
| 796 | goto error; |
| 797 | err = -EINVAL; |
| 798 | if (!parse.p.key) |
| 799 | goto error; |
| 800 | if (parse.idx < 0 || parse.idx > 4) |
| 801 | goto error; |
| 802 | if (parse.def) { |
| 803 | if (def) |
| 804 | goto error; |
| 805 | def = 1; |
| 806 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 807 | if (!parse.def_uni || !parse.def_multi) |
| 808 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 809 | } else if (parse.defmgmt) |
| 810 | goto error; |
| 811 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 812 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 813 | if (err) |
| 814 | goto error; |
| 815 | result->params[parse.idx].cipher = parse.p.cipher; |
| 816 | result->params[parse.idx].key_len = parse.p.key_len; |
| 817 | result->params[parse.idx].key = result->data[parse.idx]; |
| 818 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 819 | |
| 820 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 821 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 822 | if (no_ht) |
| 823 | *no_ht = true; |
| 824 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | return result; |
| 828 | error: |
| 829 | kfree(result); |
| 830 | return ERR_PTR(err); |
| 831 | } |
| 832 | |
| 833 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 834 | { |
| 835 | ASSERT_WDEV_LOCK(wdev); |
| 836 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 837 | switch (wdev->iftype) { |
| 838 | case NL80211_IFTYPE_AP: |
| 839 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 840 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 841 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 842 | break; |
| 843 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 844 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 845 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 846 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 847 | return -ENOLINK; |
| 848 | break; |
| 849 | default: |
| 850 | return -EINVAL; |
| 851 | } |
| 852 | |
| 853 | return 0; |
| 854 | } |
| 855 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 856 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 857 | { |
| 858 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 859 | int i; |
| 860 | |
| 861 | if (!nl_modes) |
| 862 | goto nla_put_failure; |
| 863 | |
| 864 | i = 0; |
| 865 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 866 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 867 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 868 | ifmodes >>= 1; |
| 869 | i++; |
| 870 | } |
| 871 | |
| 872 | nla_nest_end(msg, nl_modes); |
| 873 | return 0; |
| 874 | |
| 875 | nla_put_failure: |
| 876 | return -ENOBUFS; |
| 877 | } |
| 878 | |
| 879 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 880 | struct sk_buff *msg, |
| 881 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 882 | { |
| 883 | struct nlattr *nl_combis; |
| 884 | int i, j; |
| 885 | |
| 886 | nl_combis = nla_nest_start(msg, |
| 887 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 888 | if (!nl_combis) |
| 889 | goto nla_put_failure; |
| 890 | |
| 891 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 892 | const struct ieee80211_iface_combination *c; |
| 893 | struct nlattr *nl_combi, *nl_limits; |
| 894 | |
| 895 | c = &wiphy->iface_combinations[i]; |
| 896 | |
| 897 | nl_combi = nla_nest_start(msg, i + 1); |
| 898 | if (!nl_combi) |
| 899 | goto nla_put_failure; |
| 900 | |
| 901 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 902 | if (!nl_limits) |
| 903 | goto nla_put_failure; |
| 904 | |
| 905 | for (j = 0; j < c->n_limits; j++) { |
| 906 | struct nlattr *nl_limit; |
| 907 | |
| 908 | nl_limit = nla_nest_start(msg, j + 1); |
| 909 | if (!nl_limit) |
| 910 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 911 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 912 | c->limits[j].max)) |
| 913 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 914 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 915 | c->limits[j].types)) |
| 916 | goto nla_put_failure; |
| 917 | nla_nest_end(msg, nl_limit); |
| 918 | } |
| 919 | |
| 920 | nla_nest_end(msg, nl_limits); |
| 921 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 922 | if (c->beacon_int_infra_match && |
| 923 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 924 | goto nla_put_failure; |
| 925 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 926 | c->num_different_channels) || |
| 927 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 928 | c->max_interfaces)) |
| 929 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 930 | if (large && |
| 931 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 932 | c->radar_detect_widths)) |
| 933 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 934 | |
| 935 | nla_nest_end(msg, nl_combi); |
| 936 | } |
| 937 | |
| 938 | nla_nest_end(msg, nl_combis); |
| 939 | |
| 940 | return 0; |
| 941 | nla_put_failure: |
| 942 | return -ENOBUFS; |
| 943 | } |
| 944 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 945 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 946 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 947 | struct sk_buff *msg) |
| 948 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 949 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 950 | struct nlattr *nl_tcp; |
| 951 | |
| 952 | if (!tcp) |
| 953 | return 0; |
| 954 | |
| 955 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 956 | if (!nl_tcp) |
| 957 | return -ENOBUFS; |
| 958 | |
| 959 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 960 | tcp->data_payload_max)) |
| 961 | return -ENOBUFS; |
| 962 | |
| 963 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 964 | tcp->data_payload_max)) |
| 965 | return -ENOBUFS; |
| 966 | |
| 967 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 968 | return -ENOBUFS; |
| 969 | |
| 970 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 971 | sizeof(*tcp->tok), tcp->tok)) |
| 972 | return -ENOBUFS; |
| 973 | |
| 974 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 975 | tcp->data_interval_max)) |
| 976 | return -ENOBUFS; |
| 977 | |
| 978 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 979 | tcp->wake_payload_max)) |
| 980 | return -ENOBUFS; |
| 981 | |
| 982 | nla_nest_end(msg, nl_tcp); |
| 983 | return 0; |
| 984 | } |
| 985 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 986 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 987 | struct cfg80211_registered_device *dev, |
| 988 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 989 | { |
| 990 | struct nlattr *nl_wowlan; |
| 991 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 992 | if (!dev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 993 | return 0; |
| 994 | |
| 995 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 996 | if (!nl_wowlan) |
| 997 | return -ENOBUFS; |
| 998 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 999 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1000 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1001 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1002 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1003 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1004 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1005 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1006 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1007 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1008 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1009 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1010 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1011 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1012 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1013 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1014 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1015 | return -ENOBUFS; |
| 1016 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1017 | if (dev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1018 | struct nl80211_pattern_support pat = { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1019 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
| 1020 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, |
| 1021 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, |
| 1022 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1023 | }; |
| 1024 | |
| 1025 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1026 | sizeof(pat), &pat)) |
| 1027 | return -ENOBUFS; |
| 1028 | } |
| 1029 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1030 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1031 | return -ENOBUFS; |
| 1032 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1033 | nla_nest_end(msg, nl_wowlan); |
| 1034 | |
| 1035 | return 0; |
| 1036 | } |
| 1037 | #endif |
| 1038 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1039 | static int nl80211_send_coalesce(struct sk_buff *msg, |
| 1040 | struct cfg80211_registered_device *dev) |
| 1041 | { |
| 1042 | struct nl80211_coalesce_rule_support rule; |
| 1043 | |
| 1044 | if (!dev->wiphy.coalesce) |
| 1045 | return 0; |
| 1046 | |
| 1047 | rule.max_rules = dev->wiphy.coalesce->n_rules; |
| 1048 | rule.max_delay = dev->wiphy.coalesce->max_delay; |
| 1049 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; |
| 1050 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; |
| 1051 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; |
| 1052 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; |
| 1053 | |
| 1054 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1055 | return -ENOBUFS; |
| 1056 | |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1060 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1061 | struct ieee80211_supported_band *sband) |
| 1062 | { |
| 1063 | struct nlattr *nl_rates, *nl_rate; |
| 1064 | struct ieee80211_rate *rate; |
| 1065 | int i; |
| 1066 | |
| 1067 | /* add HT info */ |
| 1068 | if (sband->ht_cap.ht_supported && |
| 1069 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1070 | sizeof(sband->ht_cap.mcs), |
| 1071 | &sband->ht_cap.mcs) || |
| 1072 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1073 | sband->ht_cap.cap) || |
| 1074 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1075 | sband->ht_cap.ampdu_factor) || |
| 1076 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1077 | sband->ht_cap.ampdu_density))) |
| 1078 | return -ENOBUFS; |
| 1079 | |
| 1080 | /* add VHT info */ |
| 1081 | if (sband->vht_cap.vht_supported && |
| 1082 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1083 | sizeof(sband->vht_cap.vht_mcs), |
| 1084 | &sband->vht_cap.vht_mcs) || |
| 1085 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1086 | sband->vht_cap.cap))) |
| 1087 | return -ENOBUFS; |
| 1088 | |
| 1089 | /* add bitrates */ |
| 1090 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1091 | if (!nl_rates) |
| 1092 | return -ENOBUFS; |
| 1093 | |
| 1094 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1095 | nl_rate = nla_nest_start(msg, i); |
| 1096 | if (!nl_rate) |
| 1097 | return -ENOBUFS; |
| 1098 | |
| 1099 | rate = &sband->bitrates[i]; |
| 1100 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1101 | rate->bitrate)) |
| 1102 | return -ENOBUFS; |
| 1103 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1104 | nla_put_flag(msg, |
| 1105 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1106 | return -ENOBUFS; |
| 1107 | |
| 1108 | nla_nest_end(msg, nl_rate); |
| 1109 | } |
| 1110 | |
| 1111 | nla_nest_end(msg, nl_rates); |
| 1112 | |
| 1113 | return 0; |
| 1114 | } |
| 1115 | |
| 1116 | static int |
| 1117 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1118 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1119 | { |
| 1120 | u16 stypes; |
| 1121 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1122 | enum nl80211_iftype ift; |
| 1123 | int i; |
| 1124 | |
| 1125 | if (!mgmt_stypes) |
| 1126 | return 0; |
| 1127 | |
| 1128 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1129 | if (!nl_ifs) |
| 1130 | return -ENOBUFS; |
| 1131 | |
| 1132 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1133 | nl_ftypes = nla_nest_start(msg, ift); |
| 1134 | if (!nl_ftypes) |
| 1135 | return -ENOBUFS; |
| 1136 | i = 0; |
| 1137 | stypes = mgmt_stypes[ift].tx; |
| 1138 | while (stypes) { |
| 1139 | if ((stypes & 1) && |
| 1140 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1141 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1142 | return -ENOBUFS; |
| 1143 | stypes >>= 1; |
| 1144 | i++; |
| 1145 | } |
| 1146 | nla_nest_end(msg, nl_ftypes); |
| 1147 | } |
| 1148 | |
| 1149 | nla_nest_end(msg, nl_ifs); |
| 1150 | |
| 1151 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1152 | if (!nl_ifs) |
| 1153 | return -ENOBUFS; |
| 1154 | |
| 1155 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1156 | nl_ftypes = nla_nest_start(msg, ift); |
| 1157 | if (!nl_ftypes) |
| 1158 | return -ENOBUFS; |
| 1159 | i = 0; |
| 1160 | stypes = mgmt_stypes[ift].rx; |
| 1161 | while (stypes) { |
| 1162 | if ((stypes & 1) && |
| 1163 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1164 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1165 | return -ENOBUFS; |
| 1166 | stypes >>= 1; |
| 1167 | i++; |
| 1168 | } |
| 1169 | nla_nest_end(msg, nl_ftypes); |
| 1170 | } |
| 1171 | nla_nest_end(msg, nl_ifs); |
| 1172 | |
| 1173 | return 0; |
| 1174 | } |
| 1175 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1176 | struct nl80211_dump_wiphy_state { |
| 1177 | s64 filter_wiphy; |
| 1178 | long start; |
| 1179 | long split_start, band_start, chan_start; |
| 1180 | bool split; |
| 1181 | }; |
| 1182 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1183 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1184 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1185 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1186 | { |
| 1187 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1188 | struct nlattr *nl_bands, *nl_band; |
| 1189 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1190 | struct nlattr *nl_cmds; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1191 | struct nlattr *nl_vendor_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1192 | enum ieee80211_band band; |
| 1193 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1194 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1195 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1196 | dev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1197 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1198 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1199 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1200 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1201 | return -ENOBUFS; |
| 1202 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1203 | if (WARN_ON(!state)) |
| 1204 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1205 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1206 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1207 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1208 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1209 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1210 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1211 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1212 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1213 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1214 | case 0: |
| 1215 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1216 | dev->wiphy.retry_short) || |
| 1217 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1218 | dev->wiphy.retry_long) || |
| 1219 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1220 | dev->wiphy.frag_threshold) || |
| 1221 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1222 | dev->wiphy.rts_threshold) || |
| 1223 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1224 | dev->wiphy.coverage_class) || |
| 1225 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1226 | dev->wiphy.max_scan_ssids) || |
| 1227 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1228 | dev->wiphy.max_sched_scan_ssids) || |
| 1229 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1230 | dev->wiphy.max_scan_ie_len) || |
| 1231 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1232 | dev->wiphy.max_sched_scan_ie_len) || |
| 1233 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1234 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1235 | goto nla_put_failure; |
| 1236 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1237 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1238 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1239 | goto nla_put_failure; |
| 1240 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1241 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1242 | goto nla_put_failure; |
| 1243 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1244 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1245 | goto nla_put_failure; |
| 1246 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1247 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1248 | goto nla_put_failure; |
| 1249 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1250 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1251 | goto nla_put_failure; |
| 1252 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1253 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1254 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1255 | state->split_start++; |
| 1256 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1257 | break; |
| 1258 | case 1: |
| 1259 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1260 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1261 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1262 | goto nla_put_failure; |
| 1263 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1264 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1265 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1266 | goto nla_put_failure; |
| 1267 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1268 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1269 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1270 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1271 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1272 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1273 | dev->wiphy.available_antennas_tx) || |
| 1274 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1275 | dev->wiphy.available_antennas_rx)) |
| 1276 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1277 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1278 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1279 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1280 | dev->wiphy.probe_resp_offload)) |
| 1281 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1282 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1283 | if ((dev->wiphy.available_antennas_tx || |
| 1284 | dev->wiphy.available_antennas_rx) && |
| 1285 | dev->ops->get_antenna) { |
| 1286 | u32 tx_ant = 0, rx_ant = 0; |
| 1287 | int res; |
| 1288 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1289 | if (!res) { |
| 1290 | if (nla_put_u32(msg, |
| 1291 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1292 | tx_ant) || |
| 1293 | nla_put_u32(msg, |
| 1294 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1295 | rx_ant)) |
| 1296 | goto nla_put_failure; |
| 1297 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1298 | } |
| 1299 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1300 | state->split_start++; |
| 1301 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1302 | break; |
| 1303 | case 2: |
| 1304 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1305 | dev->wiphy.interface_modes)) |
| 1306 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1307 | state->split_start++; |
| 1308 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1309 | break; |
| 1310 | case 3: |
| 1311 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1312 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1313 | goto nla_put_failure; |
| 1314 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1315 | for (band = state->band_start; |
| 1316 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1317 | struct ieee80211_supported_band *sband; |
| 1318 | |
| 1319 | sband = dev->wiphy.bands[band]; |
| 1320 | |
| 1321 | if (!sband) |
| 1322 | continue; |
| 1323 | |
| 1324 | nl_band = nla_nest_start(msg, band); |
| 1325 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1326 | goto nla_put_failure; |
| 1327 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1328 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1329 | case 0: |
| 1330 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1331 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1332 | state->chan_start++; |
| 1333 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1334 | break; |
| 1335 | default: |
| 1336 | /* add frequencies */ |
| 1337 | nl_freqs = nla_nest_start( |
| 1338 | msg, NL80211_BAND_ATTR_FREQS); |
| 1339 | if (!nl_freqs) |
| 1340 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1341 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1342 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1343 | i < sband->n_channels; |
| 1344 | i++) { |
| 1345 | nl_freq = nla_nest_start(msg, i); |
| 1346 | if (!nl_freq) |
| 1347 | goto nla_put_failure; |
| 1348 | |
| 1349 | chan = &sband->channels[i]; |
| 1350 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1351 | if (nl80211_msg_put_channel( |
| 1352 | msg, chan, |
| 1353 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1354 | goto nla_put_failure; |
| 1355 | |
| 1356 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1357 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1358 | break; |
| 1359 | } |
| 1360 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1361 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1362 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1363 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1364 | nla_nest_end(msg, nl_freqs); |
| 1365 | } |
| 1366 | |
| 1367 | nla_nest_end(msg, nl_band); |
| 1368 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1369 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1370 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1371 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1372 | band--; |
| 1373 | break; |
| 1374 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1375 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1376 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1377 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1378 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1379 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1380 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1381 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1382 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1383 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1384 | if (state->band_start == 0 && state->chan_start == 0) |
| 1385 | state->split_start++; |
| 1386 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1387 | break; |
| 1388 | case 4: |
| 1389 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1390 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1391 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1392 | |
| 1393 | i = 0; |
| 1394 | #define CMD(op, n) \ |
| 1395 | do { \ |
| 1396 | if (dev->ops->op) { \ |
| 1397 | i++; \ |
| 1398 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1399 | goto nla_put_failure; \ |
| 1400 | } \ |
| 1401 | } while (0) |
| 1402 | |
| 1403 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1404 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1405 | CMD(add_key, NEW_KEY); |
| 1406 | CMD(start_ap, START_AP); |
| 1407 | CMD(add_station, NEW_STATION); |
| 1408 | CMD(add_mpath, NEW_MPATH); |
| 1409 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1410 | CMD(change_bss, SET_BSS); |
| 1411 | CMD(auth, AUTHENTICATE); |
| 1412 | CMD(assoc, ASSOCIATE); |
| 1413 | CMD(deauth, DEAUTHENTICATE); |
| 1414 | CMD(disassoc, DISASSOCIATE); |
| 1415 | CMD(join_ibss, JOIN_IBSS); |
| 1416 | CMD(join_mesh, JOIN_MESH); |
| 1417 | CMD(set_pmksa, SET_PMKSA); |
| 1418 | CMD(del_pmksa, DEL_PMKSA); |
| 1419 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1420 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1421 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1422 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1423 | CMD(mgmt_tx, FRAME); |
| 1424 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1425 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1426 | i++; |
| 1427 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1428 | goto nla_put_failure; |
| 1429 | } |
| 1430 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1431 | dev->ops->join_mesh) { |
| 1432 | i++; |
| 1433 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1434 | goto nla_put_failure; |
| 1435 | } |
| 1436 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1437 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1438 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1439 | CMD(tdls_oper, TDLS_OPER); |
| 1440 | } |
| 1441 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1442 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1443 | CMD(probe_client, PROBE_CLIENT); |
| 1444 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1445 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1446 | i++; |
| 1447 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1448 | goto nla_put_failure; |
| 1449 | } |
| 1450 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1451 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1452 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1453 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1454 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1455 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
| 1456 | CMD(channel_switch, CHANNEL_SWITCH); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1457 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1458 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1459 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1460 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1461 | #endif |
| 1462 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1463 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1464 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1465 | if (dev->ops->connect || dev->ops->auth) { |
| 1466 | i++; |
| 1467 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1468 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1469 | } |
| 1470 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1471 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1472 | i++; |
| 1473 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1474 | goto nla_put_failure; |
| 1475 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1476 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1477 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1478 | state->split_start++; |
| 1479 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1480 | break; |
| 1481 | case 5: |
| 1482 | if (dev->ops->remain_on_channel && |
| 1483 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1484 | nla_put_u32(msg, |
| 1485 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1486 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1487 | goto nla_put_failure; |
| 1488 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1489 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1490 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1491 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1492 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1493 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1494 | goto nla_put_failure; |
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 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1499 | #ifdef CONFIG_PM |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1500 | if (nl80211_send_wowlan(msg, dev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1501 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1502 | state->split_start++; |
| 1503 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1504 | break; |
| 1505 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1506 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1507 | #endif |
| 1508 | case 7: |
| 1509 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1510 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1511 | goto nla_put_failure; |
| 1512 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1513 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
| 1514 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1515 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1516 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1517 | state->split_start++; |
| 1518 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1519 | break; |
| 1520 | case 8: |
| 1521 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1522 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1523 | dev->wiphy.ap_sme_capa)) |
| 1524 | goto nla_put_failure; |
| 1525 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1526 | features = dev->wiphy.features; |
| 1527 | /* |
| 1528 | * We can only add the per-channel limit information if the |
| 1529 | * dump is split, otherwise it makes it too big. Therefore |
| 1530 | * only advertise it in that case. |
| 1531 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1532 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1533 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1534 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1535 | goto nla_put_failure; |
| 1536 | |
| 1537 | if (dev->wiphy.ht_capa_mod_mask && |
| 1538 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1539 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1540 | dev->wiphy.ht_capa_mod_mask)) |
| 1541 | goto nla_put_failure; |
| 1542 | |
| 1543 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1544 | dev->wiphy.max_acl_mac_addrs && |
| 1545 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1546 | dev->wiphy.max_acl_mac_addrs)) |
| 1547 | goto nla_put_failure; |
| 1548 | |
| 1549 | /* |
| 1550 | * Any information below this point is only available to |
| 1551 | * applications that can deal with it being split. This |
| 1552 | * helps ensure that newly added capabilities don't break |
| 1553 | * older tools by overrunning their buffers. |
| 1554 | * |
| 1555 | * We still increment split_start so that in the split |
| 1556 | * case we'll continue with more data in the next round, |
| 1557 | * but break unconditionally so unsplit data stops here. |
| 1558 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1559 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1560 | break; |
| 1561 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1562 | if (dev->wiphy.extended_capabilities && |
| 1563 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1564 | dev->wiphy.extended_capabilities_len, |
| 1565 | dev->wiphy.extended_capabilities) || |
| 1566 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1567 | dev->wiphy.extended_capabilities_len, |
| 1568 | dev->wiphy.extended_capabilities_mask))) |
| 1569 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1570 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1571 | if (dev->wiphy.vht_capa_mod_mask && |
| 1572 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1573 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1574 | dev->wiphy.vht_capa_mod_mask)) |
| 1575 | goto nla_put_failure; |
| 1576 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1577 | state->split_start++; |
| 1578 | break; |
| 1579 | case 10: |
| 1580 | if (nl80211_send_coalesce(msg, dev)) |
| 1581 | goto nla_put_failure; |
| 1582 | |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1583 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
| 1584 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1585 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1586 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1587 | state->split_start++; |
| 1588 | break; |
| 1589 | case 11: |
| 1590 | nl_vendor_cmds = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1591 | if (!nl_vendor_cmds) |
| 1592 | goto nla_put_failure; |
| 1593 | |
| 1594 | for (i = 0; i < dev->wiphy.n_vendor_commands; i++) |
| 1595 | if (nla_put(msg, i + 1, |
| 1596 | sizeof(struct nl80211_vendor_cmd_info), |
| 1597 | &dev->wiphy.vendor_commands[i].info)) |
| 1598 | goto nla_put_failure; |
| 1599 | nla_nest_end(msg, nl_vendor_cmds); |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1600 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1601 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1602 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1603 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1604 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1605 | return genlmsg_end(msg, hdr); |
| 1606 | |
| 1607 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1608 | genlmsg_cancel(msg, hdr); |
| 1609 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1610 | } |
| 1611 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1612 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1613 | struct netlink_callback *cb, |
| 1614 | struct nl80211_dump_wiphy_state *state) |
| 1615 | { |
| 1616 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1617 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1618 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1619 | /* ignore parse errors for backward compatibility */ |
| 1620 | if (ret) |
| 1621 | return 0; |
| 1622 | |
| 1623 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1624 | if (tb[NL80211_ATTR_WIPHY]) |
| 1625 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1626 | if (tb[NL80211_ATTR_WDEV]) |
| 1627 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1628 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1629 | struct net_device *netdev; |
| 1630 | struct cfg80211_registered_device *rdev; |
| 1631 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1632 | |
| 1633 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
| 1634 | if (!netdev) |
| 1635 | return -ENODEV; |
| 1636 | if (netdev->ieee80211_ptr) { |
| 1637 | rdev = wiphy_to_dev( |
| 1638 | netdev->ieee80211_ptr->wiphy); |
| 1639 | state->filter_wiphy = rdev->wiphy_idx; |
| 1640 | } |
| 1641 | dev_put(netdev); |
| 1642 | } |
| 1643 | |
| 1644 | return 0; |
| 1645 | } |
| 1646 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1647 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1648 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1649 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1650 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1651 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1652 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1653 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1654 | if (!state) { |
| 1655 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1656 | if (!state) { |
| 1657 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1658 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1659 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1660 | state->filter_wiphy = -1; |
| 1661 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1662 | if (ret) { |
| 1663 | kfree(state); |
| 1664 | rtnl_unlock(); |
| 1665 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1666 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1667 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1668 | } |
| 1669 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1670 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1671 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1672 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1673 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1674 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1675 | if (state->filter_wiphy != -1 && |
| 1676 | state->filter_wiphy != dev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1677 | continue; |
| 1678 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1679 | do { |
| 1680 | ret = nl80211_send_wiphy(dev, skb, |
| 1681 | NETLINK_CB(cb->skb).portid, |
| 1682 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1683 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1684 | if (ret < 0) { |
| 1685 | /* |
| 1686 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1687 | * or EMSGSIZE returned), this SKB is still |
| 1688 | * empty (so it's not too big because another |
| 1689 | * wiphy dataset is already in the skb) and |
| 1690 | * we've not tried to adjust the dump allocation |
| 1691 | * yet ... then adjust the alloc size to be |
| 1692 | * bigger, and return 1 but with the empty skb. |
| 1693 | * This results in an empty message being RX'ed |
| 1694 | * in userspace, but that is ignored. |
| 1695 | * |
| 1696 | * We can then retry with the larger buffer. |
| 1697 | */ |
| 1698 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1699 | !skb->len && |
| 1700 | cb->min_dump_alloc < 4096) { |
| 1701 | cb->min_dump_alloc = 4096; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1702 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1703 | return 1; |
| 1704 | } |
| 1705 | idx--; |
| 1706 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1707 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1708 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1709 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1710 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1711 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1712 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1713 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1714 | |
| 1715 | return skb->len; |
| 1716 | } |
| 1717 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1718 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1719 | { |
| 1720 | kfree((void *)cb->args[0]); |
| 1721 | return 0; |
| 1722 | } |
| 1723 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1724 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1725 | { |
| 1726 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1727 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1728 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1729 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1730 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1731 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1732 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1733 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1734 | 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] | 1735 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1736 | nlmsg_free(msg); |
| 1737 | return -ENOBUFS; |
| 1738 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1739 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1740 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1741 | } |
| 1742 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1743 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1744 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1745 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1746 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1747 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1748 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1749 | }; |
| 1750 | |
| 1751 | static int parse_txq_params(struct nlattr *tb[], |
| 1752 | struct ieee80211_txq_params *txq_params) |
| 1753 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1754 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1755 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1756 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1757 | return -EINVAL; |
| 1758 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1759 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1760 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1761 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1762 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1763 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1764 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1765 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1766 | return -EINVAL; |
| 1767 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1768 | return 0; |
| 1769 | } |
| 1770 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1771 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1772 | { |
| 1773 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1774 | * You can only set the channel explicitly for WDS interfaces, |
| 1775 | * all others have their channel managed via their respective |
| 1776 | * "establish a connection" command (connect, join, ...) |
| 1777 | * |
| 1778 | * For AP/GO and mesh mode, the channel can be set with the |
| 1779 | * channel userspace API, but is only stored and passed to the |
| 1780 | * low-level driver when the AP starts or the mesh is joined. |
| 1781 | * This is for backward compatibility, userspace can also give |
| 1782 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1783 | * |
| 1784 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1785 | * whatever else is going on, so they have their own special |
| 1786 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1787 | */ |
| 1788 | return !wdev || |
| 1789 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1790 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1791 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1792 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1793 | } |
| 1794 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1795 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1796 | struct genl_info *info, |
| 1797 | struct cfg80211_chan_def *chandef) |
| 1798 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1799 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1800 | |
| 1801 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1802 | return -EINVAL; |
| 1803 | |
| 1804 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1805 | |
| 1806 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1807 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1808 | chandef->center_freq1 = control_freq; |
| 1809 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1810 | |
| 1811 | /* Primary channel not allowed */ |
| 1812 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1813 | return -EINVAL; |
| 1814 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1815 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1816 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1817 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1818 | chantype = nla_get_u32( |
| 1819 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1820 | |
| 1821 | switch (chantype) { |
| 1822 | case NL80211_CHAN_NO_HT: |
| 1823 | case NL80211_CHAN_HT20: |
| 1824 | case NL80211_CHAN_HT40PLUS: |
| 1825 | case NL80211_CHAN_HT40MINUS: |
| 1826 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1827 | chantype); |
| 1828 | break; |
| 1829 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1830 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1831 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1832 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1833 | chandef->width = |
| 1834 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1835 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1836 | chandef->center_freq1 = |
| 1837 | nla_get_u32( |
| 1838 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1839 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1840 | chandef->center_freq2 = |
| 1841 | nla_get_u32( |
| 1842 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1843 | } |
| 1844 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1845 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1846 | return -EINVAL; |
| 1847 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1848 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1849 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1850 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1851 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1852 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1853 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1854 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1855 | return -EINVAL; |
| 1856 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1857 | return 0; |
| 1858 | } |
| 1859 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1860 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1861 | struct wireless_dev *wdev, |
| 1862 | struct genl_info *info) |
| 1863 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1864 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1865 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1866 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1867 | |
| 1868 | if (wdev) |
| 1869 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1870 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1871 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1872 | return -EOPNOTSUPP; |
| 1873 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1874 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1875 | if (result) |
| 1876 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1877 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1878 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1879 | case NL80211_IFTYPE_AP: |
| 1880 | case NL80211_IFTYPE_P2P_GO: |
| 1881 | if (wdev->beacon_interval) { |
| 1882 | result = -EBUSY; |
| 1883 | break; |
| 1884 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1885 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1886 | result = -EINVAL; |
| 1887 | break; |
| 1888 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1889 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1890 | result = 0; |
| 1891 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1892 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1893 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1894 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1895 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1896 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1897 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1898 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1899 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1900 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1901 | |
| 1902 | return result; |
| 1903 | } |
| 1904 | |
| 1905 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1906 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1907 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1908 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1909 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1910 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1911 | } |
| 1912 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1913 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1914 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1915 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1916 | struct net_device *dev = info->user_ptr[1]; |
| 1917 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1918 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1919 | |
| 1920 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1921 | return -EINVAL; |
| 1922 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1923 | if (netif_running(dev)) |
| 1924 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1925 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1926 | if (!rdev->ops->set_wds_peer) |
| 1927 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1928 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1929 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1930 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1931 | |
| 1932 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1933 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1937 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1938 | { |
| 1939 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1940 | struct net_device *netdev = NULL; |
| 1941 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1942 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1943 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1944 | u32 changed; |
| 1945 | u8 retry_short = 0, retry_long = 0; |
| 1946 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1947 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1948 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1949 | ASSERT_RTNL(); |
| 1950 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1951 | /* |
| 1952 | * Try to find the wiphy and netdev. Normally this |
| 1953 | * function shouldn't need the netdev, but this is |
| 1954 | * done for backward compatibility -- previously |
| 1955 | * setting the channel was done per wiphy, but now |
| 1956 | * it is per netdev. Previous userland like hostapd |
| 1957 | * also passed a netdev to set_wiphy, so that it is |
| 1958 | * possible to let that go to the right netdev! |
| 1959 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1960 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1961 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1962 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1963 | |
| 1964 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1965 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1966 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1967 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1968 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1969 | } |
| 1970 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1971 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1972 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1973 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1974 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1975 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1976 | wdev = NULL; |
| 1977 | netdev = NULL; |
| 1978 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1979 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1980 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1981 | |
| 1982 | /* |
| 1983 | * end workaround code, by now the rdev is available |
| 1984 | * and locked, and wdev may or may not be NULL. |
| 1985 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1986 | |
| 1987 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1988 | result = cfg80211_dev_rename( |
| 1989 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1990 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1991 | if (result) |
| 1992 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1993 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1994 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1995 | struct ieee80211_txq_params txq_params; |
| 1996 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1997 | |
| 1998 | if (!rdev->ops->set_txq_params) { |
| 1999 | result = -EOPNOTSUPP; |
| 2000 | goto bad_res; |
| 2001 | } |
| 2002 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2003 | if (!netdev) { |
| 2004 | result = -EINVAL; |
| 2005 | goto bad_res; |
| 2006 | } |
| 2007 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2008 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2009 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 2010 | result = -EINVAL; |
| 2011 | goto bad_res; |
| 2012 | } |
| 2013 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2014 | if (!netif_running(netdev)) { |
| 2015 | result = -ENETDOWN; |
| 2016 | goto bad_res; |
| 2017 | } |
| 2018 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2019 | nla_for_each_nested(nl_txq_params, |
| 2020 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2021 | rem_txq_params) { |
| 2022 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2023 | nla_data(nl_txq_params), |
| 2024 | nla_len(nl_txq_params), |
| 2025 | txq_params_policy); |
| 2026 | result = parse_txq_params(tb, &txq_params); |
| 2027 | if (result) |
| 2028 | goto bad_res; |
| 2029 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2030 | result = rdev_set_txq_params(rdev, netdev, |
| 2031 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2032 | if (result) |
| 2033 | goto bad_res; |
| 2034 | } |
| 2035 | } |
| 2036 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2037 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2038 | result = __nl80211_set_channel(rdev, |
| 2039 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 2040 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2041 | if (result) |
| 2042 | goto bad_res; |
| 2043 | } |
| 2044 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2045 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2046 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2047 | enum nl80211_tx_power_setting type; |
| 2048 | int idx, mbm = 0; |
| 2049 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2050 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2051 | txp_wdev = NULL; |
| 2052 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2053 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 2054 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2055 | goto bad_res; |
| 2056 | } |
| 2057 | |
| 2058 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2059 | type = nla_get_u32(info->attrs[idx]); |
| 2060 | |
| 2061 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 2062 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 2063 | result = -EINVAL; |
| 2064 | goto bad_res; |
| 2065 | } |
| 2066 | |
| 2067 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2068 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2069 | mbm = nla_get_u32(info->attrs[idx]); |
| 2070 | } |
| 2071 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2072 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2073 | if (result) |
| 2074 | goto bad_res; |
| 2075 | } |
| 2076 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2077 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2078 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2079 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2080 | if ((!rdev->wiphy.available_antennas_tx && |
| 2081 | !rdev->wiphy.available_antennas_rx) || |
| 2082 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2083 | result = -EOPNOTSUPP; |
| 2084 | goto bad_res; |
| 2085 | } |
| 2086 | |
| 2087 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2088 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2089 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2090 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2091 | * available antenna masks, except for the "all" mask */ |
| 2092 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 2093 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2094 | result = -EINVAL; |
| 2095 | goto bad_res; |
| 2096 | } |
| 2097 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2098 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2099 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2100 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2101 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2102 | if (result) |
| 2103 | goto bad_res; |
| 2104 | } |
| 2105 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2106 | changed = 0; |
| 2107 | |
| 2108 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2109 | retry_short = nla_get_u8( |
| 2110 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 2111 | if (retry_short == 0) { |
| 2112 | result = -EINVAL; |
| 2113 | goto bad_res; |
| 2114 | } |
| 2115 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2116 | } |
| 2117 | |
| 2118 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2119 | retry_long = nla_get_u8( |
| 2120 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 2121 | if (retry_long == 0) { |
| 2122 | result = -EINVAL; |
| 2123 | goto bad_res; |
| 2124 | } |
| 2125 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2126 | } |
| 2127 | |
| 2128 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2129 | frag_threshold = nla_get_u32( |
| 2130 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2131 | if (frag_threshold < 256) { |
| 2132 | result = -EINVAL; |
| 2133 | goto bad_res; |
| 2134 | } |
| 2135 | if (frag_threshold != (u32) -1) { |
| 2136 | /* |
| 2137 | * Fragments (apart from the last one) are required to |
| 2138 | * have even length. Make the fragmentation code |
| 2139 | * simpler by stripping LSB should someone try to use |
| 2140 | * odd threshold value. |
| 2141 | */ |
| 2142 | frag_threshold &= ~0x1; |
| 2143 | } |
| 2144 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2145 | } |
| 2146 | |
| 2147 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2148 | rts_threshold = nla_get_u32( |
| 2149 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2150 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2151 | } |
| 2152 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2153 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2154 | coverage_class = nla_get_u8( |
| 2155 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2156 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2157 | } |
| 2158 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2159 | if (changed) { |
| 2160 | u8 old_retry_short, old_retry_long; |
| 2161 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2162 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2163 | |
| 2164 | if (!rdev->ops->set_wiphy_params) { |
| 2165 | result = -EOPNOTSUPP; |
| 2166 | goto bad_res; |
| 2167 | } |
| 2168 | |
| 2169 | old_retry_short = rdev->wiphy.retry_short; |
| 2170 | old_retry_long = rdev->wiphy.retry_long; |
| 2171 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2172 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2173 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2174 | |
| 2175 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2176 | rdev->wiphy.retry_short = retry_short; |
| 2177 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2178 | rdev->wiphy.retry_long = retry_long; |
| 2179 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2180 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2181 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2182 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2183 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2184 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2185 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2186 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2187 | if (result) { |
| 2188 | rdev->wiphy.retry_short = old_retry_short; |
| 2189 | rdev->wiphy.retry_long = old_retry_long; |
| 2190 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2191 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2192 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2193 | } |
| 2194 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2195 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2196 | bad_res: |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2197 | if (netdev) |
| 2198 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2199 | return result; |
| 2200 | } |
| 2201 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2202 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2203 | { |
| 2204 | return (u64)wdev->identifier | |
| 2205 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2206 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2207 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2208 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2209 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2210 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2211 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2212 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2213 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2214 | chandef->chan->center_freq)) |
| 2215 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2216 | switch (chandef->width) { |
| 2217 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2218 | case NL80211_CHAN_WIDTH_20: |
| 2219 | case NL80211_CHAN_WIDTH_40: |
| 2220 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2221 | cfg80211_get_chandef_type(chandef))) |
| 2222 | return -ENOBUFS; |
| 2223 | break; |
| 2224 | default: |
| 2225 | break; |
| 2226 | } |
| 2227 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2228 | return -ENOBUFS; |
| 2229 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2230 | return -ENOBUFS; |
| 2231 | if (chandef->center_freq2 && |
| 2232 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2233 | return -ENOBUFS; |
| 2234 | return 0; |
| 2235 | } |
| 2236 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2237 | 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] | 2238 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2239 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2240 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2241 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2242 | void *hdr; |
| 2243 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2244 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2245 | if (!hdr) |
| 2246 | return -1; |
| 2247 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2248 | if (dev && |
| 2249 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2250 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2251 | goto nla_put_failure; |
| 2252 | |
| 2253 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2254 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2255 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2256 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2257 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2258 | rdev->devlist_generation ^ |
| 2259 | (cfg80211_rdev_list_generation << 2))) |
| 2260 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2261 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2262 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2263 | int ret; |
| 2264 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2265 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2266 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2267 | if (ret == 0) { |
| 2268 | if (nl80211_send_chandef(msg, &chandef)) |
| 2269 | goto nla_put_failure; |
| 2270 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2271 | } |
| 2272 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2273 | if (wdev->ssid_len) { |
| 2274 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2275 | goto nla_put_failure; |
| 2276 | } |
| 2277 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2278 | return genlmsg_end(msg, hdr); |
| 2279 | |
| 2280 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2281 | genlmsg_cancel(msg, hdr); |
| 2282 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2286 | { |
| 2287 | int wp_idx = 0; |
| 2288 | int if_idx = 0; |
| 2289 | int wp_start = cb->args[0]; |
| 2290 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2291 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2292 | struct wireless_dev *wdev; |
| 2293 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2294 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2295 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2296 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2297 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2298 | if (wp_idx < wp_start) { |
| 2299 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2300 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2301 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2302 | if_idx = 0; |
| 2303 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2304 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2305 | if (if_idx < if_start) { |
| 2306 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2307 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2308 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2309 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2310 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2311 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2312 | goto out; |
| 2313 | } |
| 2314 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2315 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2316 | |
| 2317 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2318 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2319 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2320 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2321 | |
| 2322 | cb->args[0] = wp_idx; |
| 2323 | cb->args[1] = if_idx; |
| 2324 | |
| 2325 | return skb->len; |
| 2326 | } |
| 2327 | |
| 2328 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2329 | { |
| 2330 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2331 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2332 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2333 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2334 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2335 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2336 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2337 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2338 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2339 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2340 | nlmsg_free(msg); |
| 2341 | return -ENOBUFS; |
| 2342 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2343 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2344 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2345 | } |
| 2346 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2347 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2348 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2349 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2350 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2351 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2352 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2353 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2354 | }; |
| 2355 | |
| 2356 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2357 | { |
| 2358 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2359 | int flag; |
| 2360 | |
| 2361 | *mntrflags = 0; |
| 2362 | |
| 2363 | if (!nla) |
| 2364 | return -EINVAL; |
| 2365 | |
| 2366 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2367 | nla, mntr_flags_policy)) |
| 2368 | return -EINVAL; |
| 2369 | |
| 2370 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2371 | if (flags[flag]) |
| 2372 | *mntrflags |= (1<<flag); |
| 2373 | |
| 2374 | return 0; |
| 2375 | } |
| 2376 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2377 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2378 | struct net_device *netdev, u8 use_4addr, |
| 2379 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2380 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2381 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2382 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2383 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2384 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2385 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2386 | |
| 2387 | switch (iftype) { |
| 2388 | case NL80211_IFTYPE_AP_VLAN: |
| 2389 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2390 | return 0; |
| 2391 | break; |
| 2392 | case NL80211_IFTYPE_STATION: |
| 2393 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2394 | return 0; |
| 2395 | break; |
| 2396 | default: |
| 2397 | break; |
| 2398 | } |
| 2399 | |
| 2400 | return -EOPNOTSUPP; |
| 2401 | } |
| 2402 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2403 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2404 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2405 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2406 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2407 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2408 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2409 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2410 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2411 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2412 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2413 | memset(¶ms, 0, sizeof(params)); |
| 2414 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2415 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2416 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2417 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2418 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2419 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2420 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2421 | if (ntype > NL80211_IFTYPE_MAX) |
| 2422 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2423 | } |
| 2424 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2425 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2426 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2427 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2428 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2429 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2430 | if (netif_running(dev)) |
| 2431 | return -EBUSY; |
| 2432 | |
| 2433 | wdev_lock(wdev); |
| 2434 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2435 | IEEE80211_MAX_MESH_ID_LEN); |
| 2436 | wdev->mesh_id_up_len = |
| 2437 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2438 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2439 | wdev->mesh_id_up_len); |
| 2440 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2441 | } |
| 2442 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2443 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2444 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2445 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2446 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2447 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2448 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2449 | } else { |
| 2450 | params.use_4addr = -1; |
| 2451 | } |
| 2452 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2453 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2454 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2455 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2456 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2457 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2458 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2459 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2460 | |
| 2461 | flags = &_flags; |
| 2462 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2463 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2464 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2465 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2466 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2467 | return -EOPNOTSUPP; |
| 2468 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2469 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2470 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2471 | else |
| 2472 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2473 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2474 | if (!err && params.use_4addr != -1) |
| 2475 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2476 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2477 | return err; |
| 2478 | } |
| 2479 | |
| 2480 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2481 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2482 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2483 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2484 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2485 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2486 | int err; |
| 2487 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2488 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2489 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2490 | memset(¶ms, 0, sizeof(params)); |
| 2491 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2492 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2493 | return -EINVAL; |
| 2494 | |
| 2495 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2496 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2497 | if (type > NL80211_IFTYPE_MAX) |
| 2498 | return -EINVAL; |
| 2499 | } |
| 2500 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2501 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2502 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2503 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2504 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2505 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2506 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2507 | ETH_ALEN); |
| 2508 | if (!is_valid_ether_addr(params.macaddr)) |
| 2509 | return -EADDRNOTAVAIL; |
| 2510 | } |
| 2511 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2512 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2513 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2514 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2515 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2516 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2517 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2518 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2519 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2520 | if (!msg) |
| 2521 | return -ENOMEM; |
| 2522 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2523 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2524 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2525 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2526 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2527 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2528 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2529 | return -EOPNOTSUPP; |
| 2530 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2531 | wdev = rdev_add_virtual_intf(rdev, |
| 2532 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2533 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2534 | if (IS_ERR(wdev)) { |
| 2535 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2536 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2537 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2538 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2539 | switch (type) { |
| 2540 | case NL80211_IFTYPE_MESH_POINT: |
| 2541 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2542 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2543 | wdev_lock(wdev); |
| 2544 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2545 | IEEE80211_MAX_MESH_ID_LEN); |
| 2546 | wdev->mesh_id_up_len = |
| 2547 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2548 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2549 | wdev->mesh_id_up_len); |
| 2550 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2551 | break; |
| 2552 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2553 | /* |
| 2554 | * P2P Device doesn't have a netdev, so doesn't go |
| 2555 | * through the netdev notifier and must be added here |
| 2556 | */ |
| 2557 | mutex_init(&wdev->mtx); |
| 2558 | INIT_LIST_HEAD(&wdev->event_list); |
| 2559 | spin_lock_init(&wdev->event_lock); |
| 2560 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2561 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2562 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2563 | wdev->identifier = ++rdev->wdev_id; |
| 2564 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2565 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2566 | break; |
| 2567 | default: |
| 2568 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2569 | } |
| 2570 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2571 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2572 | rdev, wdev) < 0) { |
| 2573 | nlmsg_free(msg); |
| 2574 | return -ENOBUFS; |
| 2575 | } |
| 2576 | |
| 2577 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2581 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2582 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2583 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2584 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2585 | if (!rdev->ops->del_virtual_intf) |
| 2586 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2587 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2588 | /* |
| 2589 | * If we remove a wireless device without a netdev then clear |
| 2590 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2591 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2592 | * since the wdev has been freed, unlike with a netdev where |
| 2593 | * we need the dev_put() for the netdev to really be freed. |
| 2594 | */ |
| 2595 | if (!wdev->netdev) |
| 2596 | info->user_ptr[1] = NULL; |
| 2597 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2598 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2599 | } |
| 2600 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2601 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2602 | { |
| 2603 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2604 | struct net_device *dev = info->user_ptr[1]; |
| 2605 | u16 noack_map; |
| 2606 | |
| 2607 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2608 | return -EINVAL; |
| 2609 | |
| 2610 | if (!rdev->ops->set_noack_map) |
| 2611 | return -EOPNOTSUPP; |
| 2612 | |
| 2613 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2614 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2615 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2616 | } |
| 2617 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2618 | struct get_key_cookie { |
| 2619 | struct sk_buff *msg; |
| 2620 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2621 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2622 | }; |
| 2623 | |
| 2624 | static void get_key_callback(void *c, struct key_params *params) |
| 2625 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2626 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2627 | struct get_key_cookie *cookie = c; |
| 2628 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2629 | if ((params->key && |
| 2630 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2631 | params->key_len, params->key)) || |
| 2632 | (params->seq && |
| 2633 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2634 | params->seq_len, params->seq)) || |
| 2635 | (params->cipher && |
| 2636 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2637 | params->cipher))) |
| 2638 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2639 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2640 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2641 | if (!key) |
| 2642 | goto nla_put_failure; |
| 2643 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2644 | if ((params->key && |
| 2645 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2646 | params->key_len, params->key)) || |
| 2647 | (params->seq && |
| 2648 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2649 | params->seq_len, params->seq)) || |
| 2650 | (params->cipher && |
| 2651 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2652 | params->cipher))) |
| 2653 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2654 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2655 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2656 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2657 | |
| 2658 | nla_nest_end(cookie->msg, key); |
| 2659 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2660 | return; |
| 2661 | nla_put_failure: |
| 2662 | cookie->error = 1; |
| 2663 | } |
| 2664 | |
| 2665 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2666 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2667 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2668 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2669 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2670 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2671 | const u8 *mac_addr = NULL; |
| 2672 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2673 | struct get_key_cookie cookie = { |
| 2674 | .error = 0, |
| 2675 | }; |
| 2676 | void *hdr; |
| 2677 | struct sk_buff *msg; |
| 2678 | |
| 2679 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2680 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2681 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2682 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2683 | return -EINVAL; |
| 2684 | |
| 2685 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2686 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2687 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2688 | pairwise = !!mac_addr; |
| 2689 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2690 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2691 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2692 | return -EINVAL; |
| 2693 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2694 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2695 | return -EINVAL; |
| 2696 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2697 | } |
| 2698 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2699 | if (!rdev->ops->get_key) |
| 2700 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2701 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2702 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2703 | if (!msg) |
| 2704 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2705 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2706 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2707 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2708 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2709 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2710 | |
| 2711 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2712 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2713 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2714 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2715 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2716 | goto nla_put_failure; |
| 2717 | if (mac_addr && |
| 2718 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2719 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2720 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2721 | if (pairwise && mac_addr && |
| 2722 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2723 | return -ENOENT; |
| 2724 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2725 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2726 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2727 | |
| 2728 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2729 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2730 | |
| 2731 | if (cookie.error) |
| 2732 | goto nla_put_failure; |
| 2733 | |
| 2734 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2735 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2736 | |
| 2737 | nla_put_failure: |
| 2738 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2739 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2740 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2741 | return err; |
| 2742 | } |
| 2743 | |
| 2744 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2745 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2746 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2747 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2748 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2749 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2750 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2751 | err = nl80211_parse_key(info, &key); |
| 2752 | if (err) |
| 2753 | return err; |
| 2754 | |
| 2755 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2756 | return -EINVAL; |
| 2757 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2758 | /* only support setting default key */ |
| 2759 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2760 | return -EINVAL; |
| 2761 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2762 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2763 | |
| 2764 | if (key.def) { |
| 2765 | if (!rdev->ops->set_default_key) { |
| 2766 | err = -EOPNOTSUPP; |
| 2767 | goto out; |
| 2768 | } |
| 2769 | |
| 2770 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2771 | if (err) |
| 2772 | goto out; |
| 2773 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2774 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2775 | key.def_uni, key.def_multi); |
| 2776 | |
| 2777 | if (err) |
| 2778 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2779 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2780 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2781 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2782 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2783 | } else { |
| 2784 | if (key.def_uni || !key.def_multi) { |
| 2785 | err = -EINVAL; |
| 2786 | goto out; |
| 2787 | } |
| 2788 | |
| 2789 | if (!rdev->ops->set_default_mgmt_key) { |
| 2790 | err = -EOPNOTSUPP; |
| 2791 | goto out; |
| 2792 | } |
| 2793 | |
| 2794 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2795 | if (err) |
| 2796 | goto out; |
| 2797 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2798 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2799 | if (err) |
| 2800 | goto out; |
| 2801 | |
| 2802 | #ifdef CONFIG_CFG80211_WEXT |
| 2803 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2804 | #endif |
| 2805 | } |
| 2806 | |
| 2807 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2808 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2809 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2810 | return err; |
| 2811 | } |
| 2812 | |
| 2813 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2814 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2815 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2816 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2817 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2818 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2819 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2820 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2821 | err = nl80211_parse_key(info, &key); |
| 2822 | if (err) |
| 2823 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2824 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2825 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2826 | return -EINVAL; |
| 2827 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2828 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2829 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2830 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2831 | if (key.type == -1) { |
| 2832 | if (mac_addr) |
| 2833 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2834 | else |
| 2835 | key.type = NL80211_KEYTYPE_GROUP; |
| 2836 | } |
| 2837 | |
| 2838 | /* for now */ |
| 2839 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2840 | key.type != NL80211_KEYTYPE_GROUP) |
| 2841 | return -EINVAL; |
| 2842 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2843 | if (!rdev->ops->add_key) |
| 2844 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2845 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2846 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2847 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2848 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2849 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2850 | |
| 2851 | wdev_lock(dev->ieee80211_ptr); |
| 2852 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2853 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2854 | err = rdev_add_key(rdev, dev, key.idx, |
| 2855 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2856 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2857 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2858 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2859 | return err; |
| 2860 | } |
| 2861 | |
| 2862 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2863 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2864 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2865 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2866 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2867 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2868 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2869 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2870 | err = nl80211_parse_key(info, &key); |
| 2871 | if (err) |
| 2872 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2873 | |
| 2874 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2875 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2876 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2877 | if (key.type == -1) { |
| 2878 | if (mac_addr) |
| 2879 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2880 | else |
| 2881 | key.type = NL80211_KEYTYPE_GROUP; |
| 2882 | } |
| 2883 | |
| 2884 | /* for now */ |
| 2885 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2886 | key.type != NL80211_KEYTYPE_GROUP) |
| 2887 | return -EINVAL; |
| 2888 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2889 | if (!rdev->ops->del_key) |
| 2890 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2891 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2892 | wdev_lock(dev->ieee80211_ptr); |
| 2893 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2894 | |
| 2895 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2896 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2897 | err = -ENOENT; |
| 2898 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2899 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2900 | err = rdev_del_key(rdev, dev, key.idx, |
| 2901 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2902 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2903 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2904 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2905 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2906 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2907 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2908 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2909 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2910 | } |
| 2911 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2912 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2913 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2914 | return err; |
| 2915 | } |
| 2916 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2917 | /* This function returns an error or the number of nested attributes */ |
| 2918 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2919 | { |
| 2920 | struct nlattr *attr; |
| 2921 | int n_entries = 0, tmp; |
| 2922 | |
| 2923 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2924 | if (nla_len(attr) != ETH_ALEN) |
| 2925 | return -EINVAL; |
| 2926 | |
| 2927 | n_entries++; |
| 2928 | } |
| 2929 | |
| 2930 | return n_entries; |
| 2931 | } |
| 2932 | |
| 2933 | /* |
| 2934 | * This function parses ACL information and allocates memory for ACL data. |
| 2935 | * On successful return, the calling function is responsible to free the |
| 2936 | * ACL buffer returned by this function. |
| 2937 | */ |
| 2938 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2939 | struct genl_info *info) |
| 2940 | { |
| 2941 | enum nl80211_acl_policy acl_policy; |
| 2942 | struct nlattr *attr; |
| 2943 | struct cfg80211_acl_data *acl; |
| 2944 | int i = 0, n_entries, tmp; |
| 2945 | |
| 2946 | if (!wiphy->max_acl_mac_addrs) |
| 2947 | return ERR_PTR(-EOPNOTSUPP); |
| 2948 | |
| 2949 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2950 | return ERR_PTR(-EINVAL); |
| 2951 | |
| 2952 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2953 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2954 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2955 | return ERR_PTR(-EINVAL); |
| 2956 | |
| 2957 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2958 | return ERR_PTR(-EINVAL); |
| 2959 | |
| 2960 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2961 | if (n_entries < 0) |
| 2962 | return ERR_PTR(n_entries); |
| 2963 | |
| 2964 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2965 | return ERR_PTR(-ENOTSUPP); |
| 2966 | |
| 2967 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2968 | GFP_KERNEL); |
| 2969 | if (!acl) |
| 2970 | return ERR_PTR(-ENOMEM); |
| 2971 | |
| 2972 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2973 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2974 | i++; |
| 2975 | } |
| 2976 | |
| 2977 | acl->n_acl_entries = n_entries; |
| 2978 | acl->acl_policy = acl_policy; |
| 2979 | |
| 2980 | return acl; |
| 2981 | } |
| 2982 | |
| 2983 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2984 | { |
| 2985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2986 | struct net_device *dev = info->user_ptr[1]; |
| 2987 | struct cfg80211_acl_data *acl; |
| 2988 | int err; |
| 2989 | |
| 2990 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2991 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2992 | return -EOPNOTSUPP; |
| 2993 | |
| 2994 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2995 | return -EINVAL; |
| 2996 | |
| 2997 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2998 | if (IS_ERR(acl)) |
| 2999 | return PTR_ERR(acl); |
| 3000 | |
| 3001 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3002 | |
| 3003 | kfree(acl); |
| 3004 | |
| 3005 | return err; |
| 3006 | } |
| 3007 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3008 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3009 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3010 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3011 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3012 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3013 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3014 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3015 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3016 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3017 | return -EINVAL; |
| 3018 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3019 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3020 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3021 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3022 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3023 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3024 | if (!bcn->head_len) |
| 3025 | return -EINVAL; |
| 3026 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3027 | } |
| 3028 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3029 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3030 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3031 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3032 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3033 | } |
| 3034 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3035 | if (!haveinfo) |
| 3036 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3037 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3038 | if (attrs[NL80211_ATTR_IE]) { |
| 3039 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3040 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3041 | } |
| 3042 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3043 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3044 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3045 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3046 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3047 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3048 | } |
| 3049 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3050 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3051 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3052 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3053 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3054 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3055 | } |
| 3056 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3057 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3058 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3059 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3060 | } |
| 3061 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3062 | return 0; |
| 3063 | } |
| 3064 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3065 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3066 | struct cfg80211_ap_settings *params) |
| 3067 | { |
| 3068 | struct wireless_dev *wdev; |
| 3069 | bool ret = false; |
| 3070 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3071 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3072 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3073 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3074 | continue; |
| 3075 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3076 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3077 | continue; |
| 3078 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3079 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3080 | ret = true; |
| 3081 | break; |
| 3082 | } |
| 3083 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3084 | return ret; |
| 3085 | } |
| 3086 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3087 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3088 | enum nl80211_auth_type auth_type, |
| 3089 | enum nl80211_commands cmd) |
| 3090 | { |
| 3091 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3092 | return false; |
| 3093 | |
| 3094 | switch (cmd) { |
| 3095 | case NL80211_CMD_AUTHENTICATE: |
| 3096 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3097 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3098 | return false; |
| 3099 | return true; |
| 3100 | case NL80211_CMD_CONNECT: |
| 3101 | case NL80211_CMD_START_AP: |
| 3102 | /* SAE not supported yet */ |
| 3103 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3104 | return false; |
| 3105 | return true; |
| 3106 | default: |
| 3107 | return false; |
| 3108 | } |
| 3109 | } |
| 3110 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3111 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3112 | { |
| 3113 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3114 | struct net_device *dev = info->user_ptr[1]; |
| 3115 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3116 | struct cfg80211_ap_settings params; |
| 3117 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3118 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3119 | |
| 3120 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3121 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3122 | return -EOPNOTSUPP; |
| 3123 | |
| 3124 | if (!rdev->ops->start_ap) |
| 3125 | return -EOPNOTSUPP; |
| 3126 | |
| 3127 | if (wdev->beacon_interval) |
| 3128 | return -EALREADY; |
| 3129 | |
| 3130 | memset(¶ms, 0, sizeof(params)); |
| 3131 | |
| 3132 | /* these are required for START_AP */ |
| 3133 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3134 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3135 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3136 | return -EINVAL; |
| 3137 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3138 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3139 | if (err) |
| 3140 | return err; |
| 3141 | |
| 3142 | params.beacon_interval = |
| 3143 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3144 | params.dtim_period = |
| 3145 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3146 | |
| 3147 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3148 | if (err) |
| 3149 | return err; |
| 3150 | |
| 3151 | /* |
| 3152 | * In theory, some of these attributes should be required here |
| 3153 | * but since they were not used when the command was originally |
| 3154 | * added, keep them optional for old user space programs to let |
| 3155 | * them continue to work with drivers that do not need the |
| 3156 | * additional information -- drivers must check! |
| 3157 | */ |
| 3158 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3159 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3160 | params.ssid_len = |
| 3161 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3162 | if (params.ssid_len == 0 || |
| 3163 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3164 | return -EINVAL; |
| 3165 | } |
| 3166 | |
| 3167 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3168 | params.hidden_ssid = nla_get_u32( |
| 3169 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3170 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3171 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3172 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3173 | return -EINVAL; |
| 3174 | } |
| 3175 | |
| 3176 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3177 | |
| 3178 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3179 | params.auth_type = nla_get_u32( |
| 3180 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3181 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3182 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3183 | return -EINVAL; |
| 3184 | } else |
| 3185 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3186 | |
| 3187 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3188 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3189 | if (err) |
| 3190 | return err; |
| 3191 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3192 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3193 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3194 | return -EOPNOTSUPP; |
| 3195 | params.inactivity_timeout = nla_get_u16( |
| 3196 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3197 | } |
| 3198 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3199 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3200 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3201 | return -EINVAL; |
| 3202 | params.p2p_ctwindow = |
| 3203 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3204 | if (params.p2p_ctwindow > 127) |
| 3205 | return -EINVAL; |
| 3206 | if (params.p2p_ctwindow != 0 && |
| 3207 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3208 | return -EINVAL; |
| 3209 | } |
| 3210 | |
| 3211 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3212 | u8 tmp; |
| 3213 | |
| 3214 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3215 | return -EINVAL; |
| 3216 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3217 | if (tmp > 1) |
| 3218 | return -EINVAL; |
| 3219 | params.p2p_opp_ps = tmp; |
| 3220 | if (params.p2p_opp_ps != 0 && |
| 3221 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3222 | return -EINVAL; |
| 3223 | } |
| 3224 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3225 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3226 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3227 | if (err) |
| 3228 | return err; |
| 3229 | } else if (wdev->preset_chandef.chan) { |
| 3230 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3231 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3232 | return -EINVAL; |
| 3233 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3234 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3235 | return -EINVAL; |
| 3236 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3237 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3238 | if (err < 0) |
| 3239 | return err; |
| 3240 | if (err) { |
| 3241 | radar_detect_width = BIT(params.chandef.width); |
| 3242 | params.radar_required = true; |
| 3243 | } |
| 3244 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3245 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3246 | params.chandef.chan, |
| 3247 | CHAN_MODE_SHARED, |
| 3248 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3249 | if (err) |
| 3250 | return err; |
| 3251 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3252 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3253 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3254 | if (IS_ERR(params.acl)) |
| 3255 | return PTR_ERR(params.acl); |
| 3256 | } |
| 3257 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3258 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3259 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3260 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3261 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3262 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3263 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3264 | wdev->ssid_len = params.ssid_len; |
| 3265 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3266 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3267 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3268 | |
| 3269 | kfree(params.acl); |
| 3270 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3271 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3272 | } |
| 3273 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3274 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3275 | { |
| 3276 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3277 | struct net_device *dev = info->user_ptr[1]; |
| 3278 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3279 | struct cfg80211_beacon_data params; |
| 3280 | int err; |
| 3281 | |
| 3282 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3283 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3284 | return -EOPNOTSUPP; |
| 3285 | |
| 3286 | if (!rdev->ops->change_beacon) |
| 3287 | return -EOPNOTSUPP; |
| 3288 | |
| 3289 | if (!wdev->beacon_interval) |
| 3290 | return -EINVAL; |
| 3291 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3292 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3293 | if (err) |
| 3294 | return err; |
| 3295 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3296 | wdev_lock(wdev); |
| 3297 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3298 | wdev_unlock(wdev); |
| 3299 | |
| 3300 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3301 | } |
| 3302 | |
| 3303 | 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] | 3304 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3305 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3306 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3307 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3308 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3309 | } |
| 3310 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3311 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3312 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3313 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3314 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3315 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3316 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3317 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3318 | }; |
| 3319 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3320 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3321 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3322 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3323 | { |
| 3324 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3325 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3326 | int flag; |
| 3327 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3328 | /* |
| 3329 | * Try parsing the new attribute first so userspace |
| 3330 | * can specify both for older kernels. |
| 3331 | */ |
| 3332 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3333 | if (nla) { |
| 3334 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3335 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3336 | sta_flags = nla_data(nla); |
| 3337 | params->sta_flags_mask = sta_flags->mask; |
| 3338 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3339 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3340 | if ((params->sta_flags_mask | |
| 3341 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3342 | return -EINVAL; |
| 3343 | return 0; |
| 3344 | } |
| 3345 | |
| 3346 | /* if present, parse the old attribute */ |
| 3347 | |
| 3348 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3349 | if (!nla) |
| 3350 | return 0; |
| 3351 | |
| 3352 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3353 | nla, sta_flags_policy)) |
| 3354 | return -EINVAL; |
| 3355 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3356 | /* |
| 3357 | * Only allow certain flags for interface types so that |
| 3358 | * other attributes are silently ignored. Remember that |
| 3359 | * this is backward compatibility code with old userspace |
| 3360 | * and shouldn't be hit in other cases anyway. |
| 3361 | */ |
| 3362 | switch (iftype) { |
| 3363 | case NL80211_IFTYPE_AP: |
| 3364 | case NL80211_IFTYPE_AP_VLAN: |
| 3365 | case NL80211_IFTYPE_P2P_GO: |
| 3366 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3367 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3368 | BIT(NL80211_STA_FLAG_WME) | |
| 3369 | BIT(NL80211_STA_FLAG_MFP); |
| 3370 | break; |
| 3371 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3372 | case NL80211_IFTYPE_STATION: |
| 3373 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3374 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3375 | break; |
| 3376 | case NL80211_IFTYPE_MESH_POINT: |
| 3377 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3378 | BIT(NL80211_STA_FLAG_MFP) | |
| 3379 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3380 | default: |
| 3381 | return -EINVAL; |
| 3382 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3383 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3384 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3385 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3386 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3387 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3388 | /* no longer support new API additions in old API */ |
| 3389 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3390 | return -EINVAL; |
| 3391 | } |
| 3392 | } |
| 3393 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3394 | return 0; |
| 3395 | } |
| 3396 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3397 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3398 | int attr) |
| 3399 | { |
| 3400 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3401 | u32 bitrate; |
| 3402 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3403 | |
| 3404 | rate = nla_nest_start(msg, attr); |
| 3405 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3406 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3407 | |
| 3408 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3409 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3410 | /* report 16-bit bitrate only if we can */ |
| 3411 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3412 | if (bitrate > 0 && |
| 3413 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3414 | return false; |
| 3415 | if (bitrate_compat > 0 && |
| 3416 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3417 | return false; |
| 3418 | |
| 3419 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3420 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3421 | return false; |
| 3422 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3423 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3424 | return false; |
| 3425 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3426 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3427 | return false; |
| 3428 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3429 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3430 | return false; |
| 3431 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3432 | return false; |
| 3433 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3434 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3435 | return false; |
| 3436 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3437 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3438 | return false; |
| 3439 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3440 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3441 | return false; |
| 3442 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3443 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3444 | return false; |
| 3445 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3446 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3447 | return false; |
| 3448 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3449 | |
| 3450 | nla_nest_end(msg, rate); |
| 3451 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3452 | } |
| 3453 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3454 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3455 | int id) |
| 3456 | { |
| 3457 | void *attr; |
| 3458 | int i = 0; |
| 3459 | |
| 3460 | if (!mask) |
| 3461 | return true; |
| 3462 | |
| 3463 | attr = nla_nest_start(msg, id); |
| 3464 | if (!attr) |
| 3465 | return false; |
| 3466 | |
| 3467 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3468 | if (!(mask & BIT(i))) |
| 3469 | continue; |
| 3470 | |
| 3471 | if (nla_put_u8(msg, i, signal[i])) |
| 3472 | return false; |
| 3473 | } |
| 3474 | |
| 3475 | nla_nest_end(msg, attr); |
| 3476 | |
| 3477 | return true; |
| 3478 | } |
| 3479 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3480 | 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] | 3481 | int flags, |
| 3482 | struct cfg80211_registered_device *rdev, |
| 3483 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3484 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3485 | { |
| 3486 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3487 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3488 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3489 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3490 | if (!hdr) |
| 3491 | return -1; |
| 3492 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3493 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3494 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3495 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3496 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3497 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3498 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3499 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3500 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3501 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3502 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3503 | sinfo->connected_time)) |
| 3504 | goto nla_put_failure; |
| 3505 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3506 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3507 | sinfo->inactive_time)) |
| 3508 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3509 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3510 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3511 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3512 | (u32)sinfo->rx_bytes)) |
| 3513 | goto nla_put_failure; |
| 3514 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3515 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3516 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3517 | (u32)sinfo->tx_bytes)) |
| 3518 | goto nla_put_failure; |
| 3519 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3520 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3521 | sinfo->rx_bytes)) |
| 3522 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3523 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3524 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3525 | sinfo->tx_bytes)) |
| 3526 | goto nla_put_failure; |
| 3527 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3528 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3529 | goto nla_put_failure; |
| 3530 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3531 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3532 | goto nla_put_failure; |
| 3533 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3534 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3535 | sinfo->plink_state)) |
| 3536 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3537 | switch (rdev->wiphy.signal_type) { |
| 3538 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3539 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3540 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3541 | sinfo->signal)) |
| 3542 | goto nla_put_failure; |
| 3543 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3544 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3545 | sinfo->signal_avg)) |
| 3546 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3547 | break; |
| 3548 | default: |
| 3549 | break; |
| 3550 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3551 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3552 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3553 | sinfo->chain_signal, |
| 3554 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3555 | goto nla_put_failure; |
| 3556 | } |
| 3557 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3558 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3559 | sinfo->chain_signal_avg, |
| 3560 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3561 | goto nla_put_failure; |
| 3562 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3563 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3564 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3565 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3566 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3567 | } |
| 3568 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3569 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3570 | NL80211_STA_INFO_RX_BITRATE)) |
| 3571 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3572 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3573 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3574 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3575 | sinfo->rx_packets)) |
| 3576 | goto nla_put_failure; |
| 3577 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3578 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3579 | sinfo->tx_packets)) |
| 3580 | goto nla_put_failure; |
| 3581 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3582 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3583 | sinfo->tx_retries)) |
| 3584 | goto nla_put_failure; |
| 3585 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3586 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3587 | sinfo->tx_failed)) |
| 3588 | goto nla_put_failure; |
| 3589 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3590 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3591 | sinfo->beacon_loss_count)) |
| 3592 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3593 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3594 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3595 | sinfo->local_pm)) |
| 3596 | goto nla_put_failure; |
| 3597 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3598 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3599 | sinfo->peer_pm)) |
| 3600 | goto nla_put_failure; |
| 3601 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3602 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3603 | sinfo->nonpeer_pm)) |
| 3604 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3605 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3606 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3607 | if (!bss_param) |
| 3608 | goto nla_put_failure; |
| 3609 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3610 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3611 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3612 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3613 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3614 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3615 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3616 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3617 | sinfo->bss_param.dtim_period) || |
| 3618 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3619 | sinfo->bss_param.beacon_interval)) |
| 3620 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3621 | |
| 3622 | nla_nest_end(msg, bss_param); |
| 3623 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3624 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3625 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3626 | sizeof(struct nl80211_sta_flag_update), |
| 3627 | &sinfo->sta_flags)) |
| 3628 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3629 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3630 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3631 | sinfo->t_offset)) |
| 3632 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3633 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3634 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3635 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3636 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3637 | sinfo->assoc_req_ies)) |
| 3638 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3639 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3640 | return genlmsg_end(msg, hdr); |
| 3641 | |
| 3642 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3643 | genlmsg_cancel(msg, hdr); |
| 3644 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3645 | } |
| 3646 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3647 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3648 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3649 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3650 | struct station_info sinfo; |
| 3651 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3652 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3653 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3654 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3655 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3656 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3657 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3658 | if (err) |
| 3659 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3660 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3661 | if (!wdev->netdev) { |
| 3662 | err = -EINVAL; |
| 3663 | goto out_err; |
| 3664 | } |
| 3665 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3666 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3667 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3668 | goto out_err; |
| 3669 | } |
| 3670 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3671 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3672 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3673 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3674 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3675 | if (err == -ENOENT) |
| 3676 | break; |
| 3677 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3678 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3679 | |
| 3680 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3681 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3682 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3683 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3684 | &sinfo) < 0) |
| 3685 | goto out; |
| 3686 | |
| 3687 | sta_idx++; |
| 3688 | } |
| 3689 | |
| 3690 | |
| 3691 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3692 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3693 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3694 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3695 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3696 | |
| 3697 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3698 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3699 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3700 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3701 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3702 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3703 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3704 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3705 | struct sk_buff *msg; |
| 3706 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3707 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3708 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3709 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3710 | |
| 3711 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3712 | return -EINVAL; |
| 3713 | |
| 3714 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3715 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3716 | if (!rdev->ops->get_station) |
| 3717 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3718 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3719 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3720 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3721 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3722 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3723 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3724 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3725 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3726 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3727 | 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] | 3728 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3729 | nlmsg_free(msg); |
| 3730 | return -ENOBUFS; |
| 3731 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3732 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3733 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3734 | } |
| 3735 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3736 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3737 | struct station_parameters *params, |
| 3738 | enum cfg80211_station_type statype) |
| 3739 | { |
| 3740 | if (params->listen_interval != -1) |
| 3741 | return -EINVAL; |
| 3742 | if (params->aid) |
| 3743 | return -EINVAL; |
| 3744 | |
| 3745 | /* When you run into this, adjust the code below for the new flag */ |
| 3746 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3747 | |
| 3748 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3749 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3750 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3751 | /* |
| 3752 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3753 | * code doesn't have the bug of including TDLS in the |
| 3754 | * mask everywhere. |
| 3755 | */ |
| 3756 | if (params->sta_flags_mask & |
| 3757 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3758 | BIT(NL80211_STA_FLAG_MFP) | |
| 3759 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3760 | return -EINVAL; |
| 3761 | break; |
| 3762 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3763 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3764 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3765 | return -EINVAL; |
| 3766 | /* ignore since it can't change */ |
| 3767 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3768 | break; |
| 3769 | default: |
| 3770 | /* disallow mesh-specific things */ |
| 3771 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3772 | return -EINVAL; |
| 3773 | if (params->local_pm) |
| 3774 | return -EINVAL; |
| 3775 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3776 | return -EINVAL; |
| 3777 | } |
| 3778 | |
| 3779 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3780 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3781 | /* TDLS can't be set, ... */ |
| 3782 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3783 | return -EINVAL; |
| 3784 | /* |
| 3785 | * ... but don't bother the driver with it. This works around |
| 3786 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3787 | * TLDS_PEER flag in the mask even for AP mode. |
| 3788 | */ |
| 3789 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3790 | } |
| 3791 | |
| 3792 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3793 | /* reject other things that can't change */ |
| 3794 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3795 | return -EINVAL; |
| 3796 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3797 | return -EINVAL; |
| 3798 | if (params->supported_rates) |
| 3799 | return -EINVAL; |
| 3800 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3801 | return -EINVAL; |
| 3802 | } |
| 3803 | |
| 3804 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3805 | if (params->vlan) |
| 3806 | return -EINVAL; |
| 3807 | } |
| 3808 | |
| 3809 | switch (statype) { |
| 3810 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3811 | /* Use this only for authorizing/unauthorizing a station */ |
| 3812 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3813 | return -EOPNOTSUPP; |
| 3814 | break; |
| 3815 | case CFG80211_STA_AP_CLIENT: |
| 3816 | /* accept only the listed bits */ |
| 3817 | if (params->sta_flags_mask & |
| 3818 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3819 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3820 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3821 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3822 | BIT(NL80211_STA_FLAG_WME) | |
| 3823 | BIT(NL80211_STA_FLAG_MFP))) |
| 3824 | return -EINVAL; |
| 3825 | |
| 3826 | /* but authenticated/associated only if driver handles it */ |
| 3827 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3828 | params->sta_flags_mask & |
| 3829 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3830 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3831 | return -EINVAL; |
| 3832 | break; |
| 3833 | case CFG80211_STA_IBSS: |
| 3834 | case CFG80211_STA_AP_STA: |
| 3835 | /* reject any changes other than AUTHORIZED */ |
| 3836 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3837 | return -EINVAL; |
| 3838 | break; |
| 3839 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3840 | /* reject any changes other than AUTHORIZED or WME */ |
| 3841 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3842 | BIT(NL80211_STA_FLAG_WME))) |
| 3843 | return -EINVAL; |
| 3844 | /* force (at least) rates when authorizing */ |
| 3845 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3846 | !params->supported_rates) |
| 3847 | return -EINVAL; |
| 3848 | break; |
| 3849 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3850 | /* reject any changes */ |
| 3851 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3852 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3853 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3854 | return -EINVAL; |
| 3855 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3856 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3857 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3858 | return -EINVAL; |
| 3859 | break; |
| 3860 | } |
| 3861 | |
| 3862 | return 0; |
| 3863 | } |
| 3864 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3865 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3866 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3867 | * 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] | 3868 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3869 | static struct net_device *get_vlan(struct genl_info *info, |
| 3870 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3871 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3872 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3873 | struct net_device *v; |
| 3874 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3875 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3876 | if (!vlanattr) |
| 3877 | return NULL; |
| 3878 | |
| 3879 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3880 | if (!v) |
| 3881 | return ERR_PTR(-ENODEV); |
| 3882 | |
| 3883 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3884 | ret = -EINVAL; |
| 3885 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3886 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3887 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3888 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3889 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3890 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3891 | ret = -EINVAL; |
| 3892 | goto error; |
| 3893 | } |
| 3894 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3895 | if (!netif_running(v)) { |
| 3896 | ret = -ENETDOWN; |
| 3897 | goto error; |
| 3898 | } |
| 3899 | |
| 3900 | return v; |
| 3901 | error: |
| 3902 | dev_put(v); |
| 3903 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3904 | } |
| 3905 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3906 | static struct nla_policy |
| 3907 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3908 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3909 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3910 | }; |
| 3911 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3912 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3913 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3914 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3915 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3916 | struct nlattr *nla; |
| 3917 | int err; |
| 3918 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3919 | /* parse WME attributes if present */ |
| 3920 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3921 | return 0; |
| 3922 | |
| 3923 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3924 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3925 | nl80211_sta_wme_policy); |
| 3926 | if (err) |
| 3927 | return err; |
| 3928 | |
| 3929 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3930 | params->uapsd_queues = nla_get_u8( |
| 3931 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3932 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3933 | return -EINVAL; |
| 3934 | |
| 3935 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3936 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3937 | |
| 3938 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3939 | return -EINVAL; |
| 3940 | |
| 3941 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3942 | |
| 3943 | return 0; |
| 3944 | } |
| 3945 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3946 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 3947 | struct station_parameters *params) |
| 3948 | { |
| 3949 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 3950 | params->supported_channels = |
| 3951 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3952 | params->supported_channels_len = |
| 3953 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3954 | /* |
| 3955 | * Need to include at least one (first channel, number of |
| 3956 | * channels) tuple for each subband, and must have proper |
| 3957 | * tuples for the rest of the data as well. |
| 3958 | */ |
| 3959 | if (params->supported_channels_len < 2) |
| 3960 | return -EINVAL; |
| 3961 | if (params->supported_channels_len % 2) |
| 3962 | return -EINVAL; |
| 3963 | } |
| 3964 | |
| 3965 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 3966 | params->supported_oper_classes = |
| 3967 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3968 | params->supported_oper_classes_len = |
| 3969 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3970 | /* |
| 3971 | * The value of the Length field of the Supported Operating |
| 3972 | * Classes element is between 2 and 253. |
| 3973 | */ |
| 3974 | if (params->supported_oper_classes_len < 2 || |
| 3975 | params->supported_oper_classes_len > 253) |
| 3976 | return -EINVAL; |
| 3977 | } |
| 3978 | return 0; |
| 3979 | } |
| 3980 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3981 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3982 | struct station_parameters *params) |
| 3983 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3984 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3985 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3986 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 3987 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3988 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3989 | params->ht_capa = |
| 3990 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3991 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3992 | params->vht_capa = |
| 3993 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3994 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3995 | err = nl80211_parse_sta_channel_info(info, params); |
| 3996 | if (err) |
| 3997 | return err; |
| 3998 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3999 | return nl80211_parse_sta_wme(info, params); |
| 4000 | } |
| 4001 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4002 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4003 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4005 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4006 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4007 | u8 *mac_addr; |
| 4008 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4009 | |
| 4010 | memset(¶ms, 0, sizeof(params)); |
| 4011 | |
| 4012 | params.listen_interval = -1; |
| 4013 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4014 | if (!rdev->ops->change_station) |
| 4015 | return -EOPNOTSUPP; |
| 4016 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4017 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4018 | return -EINVAL; |
| 4019 | |
| 4020 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4021 | return -EINVAL; |
| 4022 | |
| 4023 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4024 | |
| 4025 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4026 | params.supported_rates = |
| 4027 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4028 | params.supported_rates_len = |
| 4029 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4030 | } |
| 4031 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4032 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4033 | params.capability = |
| 4034 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4035 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4036 | } |
| 4037 | |
| 4038 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4039 | params.ext_capab = |
| 4040 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4041 | params.ext_capab_len = |
| 4042 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4043 | } |
| 4044 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4045 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4046 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4047 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4048 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4049 | return -EINVAL; |
| 4050 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4051 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4052 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4053 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4054 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4055 | return -EINVAL; |
| 4056 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4057 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4058 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4059 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4060 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4061 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4062 | return -EINVAL; |
| 4063 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4064 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4065 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4066 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4067 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4068 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4069 | |
| 4070 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4071 | pm > NL80211_MESH_POWER_MAX) |
| 4072 | return -EINVAL; |
| 4073 | |
| 4074 | params.local_pm = pm; |
| 4075 | } |
| 4076 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4077 | /* Include parameters for TDLS peer (will check later) */ |
| 4078 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4079 | if (err) |
| 4080 | return err; |
| 4081 | |
| 4082 | params.vlan = get_vlan(info, rdev); |
| 4083 | if (IS_ERR(params.vlan)) |
| 4084 | return PTR_ERR(params.vlan); |
| 4085 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4086 | switch (dev->ieee80211_ptr->iftype) { |
| 4087 | case NL80211_IFTYPE_AP: |
| 4088 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4089 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4090 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4091 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4092 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4093 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4094 | break; |
| 4095 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4096 | err = -EOPNOTSUPP; |
| 4097 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4098 | } |
| 4099 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4100 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4101 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4102 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4103 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4104 | if (params.vlan) |
| 4105 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4106 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4107 | return err; |
| 4108 | } |
| 4109 | |
| 4110 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4111 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4113 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4114 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4115 | struct station_parameters params; |
| 4116 | u8 *mac_addr = NULL; |
| 4117 | |
| 4118 | memset(¶ms, 0, sizeof(params)); |
| 4119 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4120 | if (!rdev->ops->add_station) |
| 4121 | return -EOPNOTSUPP; |
| 4122 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4123 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4124 | return -EINVAL; |
| 4125 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4126 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4127 | return -EINVAL; |
| 4128 | |
| 4129 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4130 | return -EINVAL; |
| 4131 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4132 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4133 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4134 | return -EINVAL; |
| 4135 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4136 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4137 | params.supported_rates = |
| 4138 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4139 | params.supported_rates_len = |
| 4140 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4141 | params.listen_interval = |
| 4142 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4143 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4144 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4145 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4146 | else |
| 4147 | 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] | 4148 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4149 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4150 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4151 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4152 | params.capability = |
| 4153 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4154 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4155 | } |
| 4156 | |
| 4157 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4158 | params.ext_capab = |
| 4159 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4160 | params.ext_capab_len = |
| 4161 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4162 | } |
| 4163 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4164 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4165 | params.ht_capa = |
| 4166 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4167 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4168 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4169 | params.vht_capa = |
| 4170 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4171 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4172 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4173 | params.opmode_notif_used = true; |
| 4174 | params.opmode_notif = |
| 4175 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4176 | } |
| 4177 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4178 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4179 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4180 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4181 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4182 | return -EINVAL; |
| 4183 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4184 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4185 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4186 | if (err) |
| 4187 | return err; |
| 4188 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4189 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4190 | if (err) |
| 4191 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4192 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4193 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4194 | return -EINVAL; |
| 4195 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4196 | /* When you run into this, adjust the code below for the new flag */ |
| 4197 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4198 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4199 | switch (dev->ieee80211_ptr->iftype) { |
| 4200 | case NL80211_IFTYPE_AP: |
| 4201 | case NL80211_IFTYPE_AP_VLAN: |
| 4202 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4203 | /* ignore WME attributes if iface/sta is not capable */ |
| 4204 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4205 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4206 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4207 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4208 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4209 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4210 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4211 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4212 | /* but don't bother the driver with it */ |
| 4213 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4214 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4215 | /* allow authenticated/associated only if driver handles it */ |
| 4216 | if (!(rdev->wiphy.features & |
| 4217 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4218 | params.sta_flags_mask & |
| 4219 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4220 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4221 | return -EINVAL; |
| 4222 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4223 | /* must be last in here for error handling */ |
| 4224 | params.vlan = get_vlan(info, rdev); |
| 4225 | if (IS_ERR(params.vlan)) |
| 4226 | return PTR_ERR(params.vlan); |
| 4227 | break; |
| 4228 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4229 | /* ignore uAPSD data */ |
| 4230 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4231 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4232 | /* associated is disallowed */ |
| 4233 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4234 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4235 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4236 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4237 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4238 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4239 | break; |
| 4240 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4241 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4242 | /* ignore uAPSD data */ |
| 4243 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4244 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4245 | /* these are disallowed */ |
| 4246 | if (params.sta_flags_mask & |
| 4247 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4248 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4249 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4250 | /* Only TDLS peers can be added */ |
| 4251 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4252 | return -EINVAL; |
| 4253 | /* Can only add if TDLS ... */ |
| 4254 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4255 | return -EOPNOTSUPP; |
| 4256 | /* ... with external setup is supported */ |
| 4257 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4258 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4259 | /* |
| 4260 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4261 | * as authorized, but it shouldn't yet be. |
| 4262 | */ |
| 4263 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4264 | break; |
| 4265 | default: |
| 4266 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4267 | } |
| 4268 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4269 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4270 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4271 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4272 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4273 | if (params.vlan) |
| 4274 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4275 | return err; |
| 4276 | } |
| 4277 | |
| 4278 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4279 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4280 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4281 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4282 | u8 *mac_addr = NULL; |
| 4283 | |
| 4284 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4285 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4286 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4287 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4288 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4289 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4290 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4291 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4292 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4293 | if (!rdev->ops->del_station) |
| 4294 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4295 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4296 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4297 | } |
| 4298 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4299 | 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] | 4300 | int flags, struct net_device *dev, |
| 4301 | u8 *dst, u8 *next_hop, |
| 4302 | struct mpath_info *pinfo) |
| 4303 | { |
| 4304 | void *hdr; |
| 4305 | struct nlattr *pinfoattr; |
| 4306 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4307 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4308 | if (!hdr) |
| 4309 | return -1; |
| 4310 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4311 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4312 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4313 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4314 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4315 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4316 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4317 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4318 | if (!pinfoattr) |
| 4319 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4320 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4321 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4322 | pinfo->frame_qlen)) |
| 4323 | goto nla_put_failure; |
| 4324 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4325 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4326 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4327 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4328 | pinfo->metric)) || |
| 4329 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4330 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4331 | pinfo->exptime)) || |
| 4332 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4333 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4334 | pinfo->flags)) || |
| 4335 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4336 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4337 | pinfo->discovery_timeout)) || |
| 4338 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4339 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4340 | pinfo->discovery_retries))) |
| 4341 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4342 | |
| 4343 | nla_nest_end(msg, pinfoattr); |
| 4344 | |
| 4345 | return genlmsg_end(msg, hdr); |
| 4346 | |
| 4347 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4348 | genlmsg_cancel(msg, hdr); |
| 4349 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4353 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4354 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4355 | struct mpath_info pinfo; |
| 4356 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4357 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4358 | u8 dst[ETH_ALEN]; |
| 4359 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4360 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4361 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4362 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4363 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4364 | if (err) |
| 4365 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4366 | |
| 4367 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4368 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4369 | goto out_err; |
| 4370 | } |
| 4371 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4372 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4373 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4374 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4375 | } |
| 4376 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4377 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4378 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4379 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4380 | if (err == -ENOENT) |
| 4381 | break; |
| 4382 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4383 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4384 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4385 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4386 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4387 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4388 | &pinfo) < 0) |
| 4389 | goto out; |
| 4390 | |
| 4391 | path_idx++; |
| 4392 | } |
| 4393 | |
| 4394 | |
| 4395 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4396 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4397 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4398 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4399 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4400 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4401 | } |
| 4402 | |
| 4403 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4404 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4405 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4406 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4407 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4408 | struct mpath_info pinfo; |
| 4409 | struct sk_buff *msg; |
| 4410 | u8 *dst = NULL; |
| 4411 | u8 next_hop[ETH_ALEN]; |
| 4412 | |
| 4413 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4414 | |
| 4415 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4416 | return -EINVAL; |
| 4417 | |
| 4418 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4419 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4420 | if (!rdev->ops->get_mpath) |
| 4421 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4422 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4423 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4424 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4425 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4426 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4427 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4428 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4429 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4430 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4431 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4432 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4433 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4434 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4435 | dev, dst, next_hop, &pinfo) < 0) { |
| 4436 | nlmsg_free(msg); |
| 4437 | return -ENOBUFS; |
| 4438 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4439 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4440 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4441 | } |
| 4442 | |
| 4443 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4444 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4445 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4446 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4447 | u8 *dst = NULL; |
| 4448 | u8 *next_hop = NULL; |
| 4449 | |
| 4450 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4451 | return -EINVAL; |
| 4452 | |
| 4453 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4454 | return -EINVAL; |
| 4455 | |
| 4456 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4457 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4458 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4459 | if (!rdev->ops->change_mpath) |
| 4460 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4461 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4462 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4463 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4464 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4465 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4466 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4467 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4468 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4469 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4470 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4471 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4472 | u8 *dst = NULL; |
| 4473 | u8 *next_hop = NULL; |
| 4474 | |
| 4475 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4476 | return -EINVAL; |
| 4477 | |
| 4478 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4479 | return -EINVAL; |
| 4480 | |
| 4481 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4482 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4483 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4484 | if (!rdev->ops->add_mpath) |
| 4485 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4486 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4487 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4488 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4489 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4490 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4491 | } |
| 4492 | |
| 4493 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4494 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4495 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4496 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4497 | u8 *dst = NULL; |
| 4498 | |
| 4499 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4500 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4501 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4502 | if (!rdev->ops->del_mpath) |
| 4503 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4504 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4505 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4506 | } |
| 4507 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4508 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4509 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4510 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4511 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4512 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4513 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4514 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4515 | |
| 4516 | memset(¶ms, 0, sizeof(params)); |
| 4517 | /* default to not changing parameters */ |
| 4518 | params.use_cts_prot = -1; |
| 4519 | params.use_short_preamble = -1; |
| 4520 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4521 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4522 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4523 | params.p2p_ctwindow = -1; |
| 4524 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4525 | |
| 4526 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4527 | params.use_cts_prot = |
| 4528 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4529 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4530 | params.use_short_preamble = |
| 4531 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4532 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4533 | params.use_short_slot_time = |
| 4534 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4535 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4536 | params.basic_rates = |
| 4537 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4538 | params.basic_rates_len = |
| 4539 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4540 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4541 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4542 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4543 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4544 | params.ht_opmode = |
| 4545 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4546 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4547 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4548 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4549 | return -EINVAL; |
| 4550 | params.p2p_ctwindow = |
| 4551 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4552 | if (params.p2p_ctwindow < 0) |
| 4553 | return -EINVAL; |
| 4554 | if (params.p2p_ctwindow != 0 && |
| 4555 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4556 | return -EINVAL; |
| 4557 | } |
| 4558 | |
| 4559 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4560 | u8 tmp; |
| 4561 | |
| 4562 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4563 | return -EINVAL; |
| 4564 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4565 | if (tmp > 1) |
| 4566 | return -EINVAL; |
| 4567 | params.p2p_opp_ps = tmp; |
| 4568 | if (params.p2p_opp_ps && |
| 4569 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4570 | return -EINVAL; |
| 4571 | } |
| 4572 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4573 | if (!rdev->ops->change_bss) |
| 4574 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4575 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4576 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4577 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4578 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4579 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4580 | wdev_lock(wdev); |
| 4581 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4582 | wdev_unlock(wdev); |
| 4583 | |
| 4584 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4585 | } |
| 4586 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4587 | 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] | 4588 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4589 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4590 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4591 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4592 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4593 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4594 | }; |
| 4595 | |
| 4596 | static int parse_reg_rule(struct nlattr *tb[], |
| 4597 | struct ieee80211_reg_rule *reg_rule) |
| 4598 | { |
| 4599 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4600 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4601 | |
| 4602 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4603 | return -EINVAL; |
| 4604 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4605 | return -EINVAL; |
| 4606 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4607 | return -EINVAL; |
| 4608 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4609 | return -EINVAL; |
| 4610 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4611 | return -EINVAL; |
| 4612 | |
| 4613 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4614 | |
| 4615 | freq_range->start_freq_khz = |
| 4616 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4617 | freq_range->end_freq_khz = |
| 4618 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4619 | freq_range->max_bandwidth_khz = |
| 4620 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4621 | |
| 4622 | power_rule->max_eirp = |
| 4623 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4624 | |
| 4625 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4626 | power_rule->max_antenna_gain = |
| 4627 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4628 | |
| 4629 | return 0; |
| 4630 | } |
| 4631 | |
| 4632 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4633 | { |
| 4634 | int r; |
| 4635 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4636 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4637 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4638 | /* |
| 4639 | * You should only get this when cfg80211 hasn't yet initialized |
| 4640 | * completely when built-in to the kernel right between the time |
| 4641 | * window between nl80211_init() and regulatory_init(), if that is |
| 4642 | * even possible. |
| 4643 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4644 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4645 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4646 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4647 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4648 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4649 | |
| 4650 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4651 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4652 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4653 | user_reg_hint_type = |
| 4654 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4655 | else |
| 4656 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4657 | |
| 4658 | switch (user_reg_hint_type) { |
| 4659 | case NL80211_USER_REG_HINT_USER: |
| 4660 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4661 | break; |
| 4662 | default: |
| 4663 | return -EINVAL; |
| 4664 | } |
| 4665 | |
| 4666 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4667 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4668 | return r; |
| 4669 | } |
| 4670 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4671 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4672 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4673 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4674 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4675 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4676 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4677 | struct mesh_config cur_params; |
| 4678 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4679 | void *hdr; |
| 4680 | struct nlattr *pinfoattr; |
| 4681 | struct sk_buff *msg; |
| 4682 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4683 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4684 | return -EOPNOTSUPP; |
| 4685 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4686 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4687 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4688 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4689 | wdev_lock(wdev); |
| 4690 | /* If not connected, get default parameters */ |
| 4691 | if (!wdev->mesh_id_len) |
| 4692 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4693 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4694 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4695 | wdev_unlock(wdev); |
| 4696 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4697 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4698 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4699 | |
| 4700 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4701 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4702 | if (!msg) |
| 4703 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4704 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4705 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4706 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4707 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4708 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4709 | if (!pinfoattr) |
| 4710 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4711 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4712 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4713 | cur_params.dot11MeshRetryTimeout) || |
| 4714 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4715 | cur_params.dot11MeshConfirmTimeout) || |
| 4716 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4717 | cur_params.dot11MeshHoldingTimeout) || |
| 4718 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4719 | cur_params.dot11MeshMaxPeerLinks) || |
| 4720 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4721 | cur_params.dot11MeshMaxRetries) || |
| 4722 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4723 | cur_params.dot11MeshTTL) || |
| 4724 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4725 | cur_params.element_ttl) || |
| 4726 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4727 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4728 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4729 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4730 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4731 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4732 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4733 | cur_params.path_refresh_time) || |
| 4734 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4735 | cur_params.min_discovery_timeout) || |
| 4736 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4737 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4738 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4739 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4740 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4741 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4742 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4743 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4744 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4745 | cur_params.dot11MeshHWMPRootMode) || |
| 4746 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4747 | cur_params.dot11MeshHWMPRannInterval) || |
| 4748 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4749 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4750 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4751 | cur_params.dot11MeshForwarding) || |
| 4752 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4753 | cur_params.rssi_threshold) || |
| 4754 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4755 | cur_params.ht_opmode) || |
| 4756 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4757 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4758 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4759 | cur_params.dot11MeshHWMProotInterval) || |
| 4760 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4761 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4762 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4763 | cur_params.power_mode) || |
| 4764 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4765 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4766 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4767 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4768 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4769 | nla_nest_end(msg, pinfoattr); |
| 4770 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4771 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4772 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4773 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4774 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4775 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4776 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4777 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4778 | } |
| 4779 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4780 | 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] | 4781 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4782 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4783 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4784 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4785 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4786 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4787 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4788 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4789 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4790 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4791 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4792 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4793 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4794 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4795 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4796 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4797 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4798 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4799 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4800 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4801 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4802 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4803 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4804 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4805 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4806 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4807 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4808 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4809 | }; |
| 4810 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4811 | static const struct nla_policy |
| 4812 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4813 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4814 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4815 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4816 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4817 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4818 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4819 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4820 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4821 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4822 | }; |
| 4823 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4824 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4825 | struct mesh_config *cfg, |
| 4826 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4827 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4828 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4829 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4830 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4831 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4832 | do { \ |
| 4833 | if (tb[attr]) { \ |
| 4834 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4835 | return -EINVAL; \ |
| 4836 | cfg->param = fn(tb[attr]); \ |
| 4837 | mask |= (1 << (attr - 1)); \ |
| 4838 | } \ |
| 4839 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4840 | |
| 4841 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4842 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4843 | return -EINVAL; |
| 4844 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4845 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4846 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4847 | return -EINVAL; |
| 4848 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4849 | /* This makes sure that there aren't more than 32 mesh config |
| 4850 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4851 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4852 | |
| 4853 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4854 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4855 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4856 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4857 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4858 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4859 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4860 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4861 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4862 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4863 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4864 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4865 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4866 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4867 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4868 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4869 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4870 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4871 | 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] | 4872 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4873 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4874 | 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] | 4875 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4876 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4877 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4878 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4879 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4880 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4881 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4882 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4883 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4884 | 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] | 4885 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4886 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4887 | 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] | 4888 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4889 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4890 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4891 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4892 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4893 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4894 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4895 | 1, 65535, mask, |
| 4896 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4897 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4898 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4899 | 1, 65535, mask, |
| 4900 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4901 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4902 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4903 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4904 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4905 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4906 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4907 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4908 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4909 | nla_get_u8); |
| 4910 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4911 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4912 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4913 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4914 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4915 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4916 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4917 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4918 | mask, NL80211_MESHCONF_FORWARDING, |
| 4919 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4920 | 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] | 4921 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4922 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4923 | 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] | 4924 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4925 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4926 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4927 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4928 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4929 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4930 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4931 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4932 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4933 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4934 | dot11MeshHWMPconfirmationInterval, |
| 4935 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4936 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4937 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4938 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4939 | NL80211_MESH_POWER_ACTIVE, |
| 4940 | NL80211_MESH_POWER_MAX, |
| 4941 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4942 | nla_get_u32); |
| 4943 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4944 | 0, 65535, mask, |
| 4945 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4946 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4947 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4948 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4949 | if (mask_out) |
| 4950 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4951 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4952 | return 0; |
| 4953 | |
| 4954 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4955 | } |
| 4956 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4957 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4958 | struct mesh_setup *setup) |
| 4959 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4960 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4961 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4962 | |
| 4963 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4964 | return -EINVAL; |
| 4965 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4966 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4967 | nl80211_mesh_setup_params_policy)) |
| 4968 | return -EINVAL; |
| 4969 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4970 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4971 | setup->sync_method = |
| 4972 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4973 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4974 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4975 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4976 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4977 | setup->path_sel_proto = |
| 4978 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4979 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4980 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4981 | |
| 4982 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4983 | setup->path_metric = |
| 4984 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4985 | IEEE80211_PATH_METRIC_VENDOR : |
| 4986 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4987 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4988 | |
| 4989 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4990 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4991 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4992 | if (!is_valid_ie_attr(ieattr)) |
| 4993 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4994 | setup->ie = nla_data(ieattr); |
| 4995 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4996 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4997 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4998 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4999 | return -EINVAL; |
| 5000 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5001 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5002 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5003 | if (setup->is_secure) |
| 5004 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5005 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5006 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5007 | if (!setup->user_mpm) |
| 5008 | return -EINVAL; |
| 5009 | setup->auth_id = |
| 5010 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5011 | } |
| 5012 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5013 | return 0; |
| 5014 | } |
| 5015 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5016 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5017 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5018 | { |
| 5019 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5020 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5021 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5022 | struct mesh_config cfg; |
| 5023 | u32 mask; |
| 5024 | int err; |
| 5025 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5026 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5027 | return -EOPNOTSUPP; |
| 5028 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5029 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5030 | return -EOPNOTSUPP; |
| 5031 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5032 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5033 | if (err) |
| 5034 | return err; |
| 5035 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5036 | wdev_lock(wdev); |
| 5037 | if (!wdev->mesh_id_len) |
| 5038 | err = -ENOLINK; |
| 5039 | |
| 5040 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5041 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5042 | |
| 5043 | wdev_unlock(wdev); |
| 5044 | |
| 5045 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5046 | } |
| 5047 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5048 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 5049 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5050 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5051 | struct sk_buff *msg; |
| 5052 | void *hdr = NULL; |
| 5053 | struct nlattr *nl_reg_rules; |
| 5054 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5055 | |
| 5056 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5057 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5058 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5059 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5060 | if (!msg) |
| 5061 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5062 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5063 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5064 | NL80211_CMD_GET_REG); |
| 5065 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5066 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5067 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5068 | if (reg_last_request_cell_base() && |
| 5069 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5070 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5071 | goto nla_put_failure; |
| 5072 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5073 | rcu_read_lock(); |
| 5074 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5075 | |
| 5076 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5077 | (regdom->dfs_region && |
| 5078 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5079 | goto nla_put_failure_rcu; |
| 5080 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5081 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5082 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5083 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5084 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5085 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5086 | struct nlattr *nl_reg_rule; |
| 5087 | const struct ieee80211_reg_rule *reg_rule; |
| 5088 | const struct ieee80211_freq_range *freq_range; |
| 5089 | const struct ieee80211_power_rule *power_rule; |
| 5090 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5091 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5092 | freq_range = ®_rule->freq_range; |
| 5093 | power_rule = ®_rule->power_rule; |
| 5094 | |
| 5095 | nl_reg_rule = nla_nest_start(msg, i); |
| 5096 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5097 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5098 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5099 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5100 | reg_rule->flags) || |
| 5101 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5102 | freq_range->start_freq_khz) || |
| 5103 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5104 | freq_range->end_freq_khz) || |
| 5105 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 5106 | freq_range->max_bandwidth_khz) || |
| 5107 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5108 | power_rule->max_antenna_gain) || |
| 5109 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 5110 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5111 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5112 | |
| 5113 | nla_nest_end(msg, nl_reg_rule); |
| 5114 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5115 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5116 | |
| 5117 | nla_nest_end(msg, nl_reg_rules); |
| 5118 | |
| 5119 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5120 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5121 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5122 | nla_put_failure_rcu: |
| 5123 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5124 | nla_put_failure: |
| 5125 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5126 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5127 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5128 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5129 | } |
| 5130 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5131 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5132 | { |
| 5133 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5134 | struct nlattr *nl_reg_rule; |
| 5135 | char *alpha2 = NULL; |
| 5136 | int rem_reg_rules = 0, r = 0; |
| 5137 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5138 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5139 | struct ieee80211_regdomain *rd = NULL; |
| 5140 | |
| 5141 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5142 | return -EINVAL; |
| 5143 | |
| 5144 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5145 | return -EINVAL; |
| 5146 | |
| 5147 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5148 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5149 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5150 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5151 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5152 | 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] | 5153 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5154 | num_rules++; |
| 5155 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5156 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5157 | } |
| 5158 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5159 | if (!reg_is_valid_request(alpha2)) |
| 5160 | return -EINVAL; |
| 5161 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5162 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5163 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5164 | |
| 5165 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5166 | if (!rd) |
| 5167 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5168 | |
| 5169 | rd->n_reg_rules = num_rules; |
| 5170 | rd->alpha2[0] = alpha2[0]; |
| 5171 | rd->alpha2[1] = alpha2[1]; |
| 5172 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5173 | /* |
| 5174 | * Disable DFS master mode if the DFS region was |
| 5175 | * not supported or known on this kernel. |
| 5176 | */ |
| 5177 | if (reg_supported_dfs_region(dfs_region)) |
| 5178 | rd->dfs_region = dfs_region; |
| 5179 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5180 | 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] | 5181 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5182 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5183 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5184 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5185 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5186 | if (r) |
| 5187 | goto bad_reg; |
| 5188 | |
| 5189 | rule_idx++; |
| 5190 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5191 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5192 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5193 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5194 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5195 | } |
| 5196 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5197 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5198 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5199 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5200 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5201 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5202 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5203 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5204 | } |
| 5205 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5206 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5207 | { |
| 5208 | struct nlattr *attr1, *attr2; |
| 5209 | int n_channels = 0, tmp1, tmp2; |
| 5210 | |
| 5211 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5212 | n_channels++; |
| 5213 | /* |
| 5214 | * Some hardware has a limited channel list for |
| 5215 | * scanning, and it is pretty much nonsensical |
| 5216 | * to scan for a channel twice, so disallow that |
| 5217 | * and don't require drivers to check that the |
| 5218 | * channel list they get isn't longer than what |
| 5219 | * they can scan, as long as they can scan all |
| 5220 | * the channels they registered at once. |
| 5221 | */ |
| 5222 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5223 | if (attr1 != attr2 && |
| 5224 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5225 | return 0; |
| 5226 | } |
| 5227 | |
| 5228 | return n_channels; |
| 5229 | } |
| 5230 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5231 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5232 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5233 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5234 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5235 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5236 | struct nlattr *attr; |
| 5237 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5238 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5239 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5240 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5241 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5242 | return -EINVAL; |
| 5243 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5244 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5245 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5246 | if (!rdev->ops->scan) |
| 5247 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5248 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5249 | if (rdev->scan_req) { |
| 5250 | err = -EBUSY; |
| 5251 | goto unlock; |
| 5252 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5253 | |
| 5254 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5255 | n_channels = validate_scan_freqs( |
| 5256 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5257 | if (!n_channels) { |
| 5258 | err = -EINVAL; |
| 5259 | goto unlock; |
| 5260 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5261 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5262 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5263 | n_channels = 0; |
| 5264 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5265 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5266 | if (wiphy->bands[band]) |
| 5267 | n_channels += wiphy->bands[band]->n_channels; |
| 5268 | } |
| 5269 | |
| 5270 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5271 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5272 | n_ssids++; |
| 5273 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5274 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5275 | err = -EINVAL; |
| 5276 | goto unlock; |
| 5277 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5278 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5279 | if (info->attrs[NL80211_ATTR_IE]) |
| 5280 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5281 | else |
| 5282 | ie_len = 0; |
| 5283 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5284 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5285 | err = -EINVAL; |
| 5286 | goto unlock; |
| 5287 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5288 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5289 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5290 | + sizeof(*request->ssids) * n_ssids |
| 5291 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5292 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5293 | if (!request) { |
| 5294 | err = -ENOMEM; |
| 5295 | goto unlock; |
| 5296 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5297 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5298 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5299 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5300 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5301 | if (ie_len) { |
| 5302 | if (request->ssids) |
| 5303 | request->ie = (void *)(request->ssids + n_ssids); |
| 5304 | else |
| 5305 | request->ie = (void *)(request->channels + n_channels); |
| 5306 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5307 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5308 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5309 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5310 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5311 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5312 | struct ieee80211_channel *chan; |
| 5313 | |
| 5314 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5315 | |
| 5316 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5317 | err = -EINVAL; |
| 5318 | goto out_free; |
| 5319 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5320 | |
| 5321 | /* ignore disabled channels */ |
| 5322 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5323 | continue; |
| 5324 | |
| 5325 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5326 | i++; |
| 5327 | } |
| 5328 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5329 | enum ieee80211_band band; |
| 5330 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5331 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5332 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5333 | int j; |
| 5334 | if (!wiphy->bands[band]) |
| 5335 | continue; |
| 5336 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5337 | struct ieee80211_channel *chan; |
| 5338 | |
| 5339 | chan = &wiphy->bands[band]->channels[j]; |
| 5340 | |
| 5341 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5342 | continue; |
| 5343 | |
| 5344 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5345 | i++; |
| 5346 | } |
| 5347 | } |
| 5348 | } |
| 5349 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5350 | if (!i) { |
| 5351 | err = -EINVAL; |
| 5352 | goto out_free; |
| 5353 | } |
| 5354 | |
| 5355 | request->n_channels = i; |
| 5356 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5357 | i = 0; |
| 5358 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5359 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5360 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5361 | err = -EINVAL; |
| 5362 | goto out_free; |
| 5363 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5364 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5365 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5366 | i++; |
| 5367 | } |
| 5368 | } |
| 5369 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5370 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5371 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5372 | memcpy((void *)request->ie, |
| 5373 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5374 | request->ie_len); |
| 5375 | } |
| 5376 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5377 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5378 | if (wiphy->bands[i]) |
| 5379 | request->rates[i] = |
| 5380 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5381 | |
| 5382 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5383 | nla_for_each_nested(attr, |
| 5384 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5385 | tmp) { |
| 5386 | enum ieee80211_band band = nla_type(attr); |
| 5387 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5388 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5389 | err = -EINVAL; |
| 5390 | goto out_free; |
| 5391 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5392 | |
| 5393 | if (!wiphy->bands[band]) |
| 5394 | continue; |
| 5395 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5396 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5397 | nla_data(attr), |
| 5398 | nla_len(attr), |
| 5399 | &request->rates[band]); |
| 5400 | if (err) |
| 5401 | goto out_free; |
| 5402 | } |
| 5403 | } |
| 5404 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5405 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5406 | request->flags = nla_get_u32( |
| 5407 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5408 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5409 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5410 | err = -EOPNOTSUPP; |
| 5411 | goto out_free; |
| 5412 | } |
| 5413 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5414 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5415 | request->no_cck = |
| 5416 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5417 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5418 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5419 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5420 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5421 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5422 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5423 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5424 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5425 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5426 | nl80211_send_scan_start(rdev, wdev); |
| 5427 | if (wdev->netdev) |
| 5428 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5429 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5430 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5431 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5432 | kfree(request); |
| 5433 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5434 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5435 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5436 | return err; |
| 5437 | } |
| 5438 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5439 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5440 | struct genl_info *info) |
| 5441 | { |
| 5442 | struct cfg80211_sched_scan_request *request; |
| 5443 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5444 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5445 | struct nlattr *attr; |
| 5446 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5447 | 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] | 5448 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5449 | enum ieee80211_band band; |
| 5450 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5451 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5452 | |
| 5453 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5454 | !rdev->ops->sched_scan_start) |
| 5455 | return -EOPNOTSUPP; |
| 5456 | |
| 5457 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5458 | return -EINVAL; |
| 5459 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5460 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5461 | return -EINVAL; |
| 5462 | |
| 5463 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5464 | if (interval == 0) |
| 5465 | return -EINVAL; |
| 5466 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5467 | wiphy = &rdev->wiphy; |
| 5468 | |
| 5469 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5470 | n_channels = validate_scan_freqs( |
| 5471 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5472 | if (!n_channels) |
| 5473 | return -EINVAL; |
| 5474 | } else { |
| 5475 | n_channels = 0; |
| 5476 | |
| 5477 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5478 | if (wiphy->bands[band]) |
| 5479 | n_channels += wiphy->bands[band]->n_channels; |
| 5480 | } |
| 5481 | |
| 5482 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5483 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5484 | tmp) |
| 5485 | n_ssids++; |
| 5486 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5487 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5488 | return -EINVAL; |
| 5489 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5490 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5491 | nla_for_each_nested(attr, |
| 5492 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5493 | tmp) |
| 5494 | n_match_sets++; |
| 5495 | |
| 5496 | if (n_match_sets > wiphy->max_match_sets) |
| 5497 | return -EINVAL; |
| 5498 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5499 | if (info->attrs[NL80211_ATTR_IE]) |
| 5500 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5501 | else |
| 5502 | ie_len = 0; |
| 5503 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5504 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5505 | return -EINVAL; |
| 5506 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5507 | if (rdev->sched_scan_req) { |
| 5508 | err = -EINPROGRESS; |
| 5509 | goto out; |
| 5510 | } |
| 5511 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5512 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5513 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5514 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5515 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5516 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5517 | if (!request) { |
| 5518 | err = -ENOMEM; |
| 5519 | goto out; |
| 5520 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5521 | |
| 5522 | if (n_ssids) |
| 5523 | request->ssids = (void *)&request->channels[n_channels]; |
| 5524 | request->n_ssids = n_ssids; |
| 5525 | if (ie_len) { |
| 5526 | if (request->ssids) |
| 5527 | request->ie = (void *)(request->ssids + n_ssids); |
| 5528 | else |
| 5529 | request->ie = (void *)(request->channels + n_channels); |
| 5530 | } |
| 5531 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5532 | if (n_match_sets) { |
| 5533 | if (request->ie) |
| 5534 | request->match_sets = (void *)(request->ie + ie_len); |
| 5535 | else if (request->ssids) |
| 5536 | request->match_sets = |
| 5537 | (void *)(request->ssids + n_ssids); |
| 5538 | else |
| 5539 | request->match_sets = |
| 5540 | (void *)(request->channels + n_channels); |
| 5541 | } |
| 5542 | request->n_match_sets = n_match_sets; |
| 5543 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5544 | i = 0; |
| 5545 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5546 | /* user specified, bail out if channel not found */ |
| 5547 | nla_for_each_nested(attr, |
| 5548 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5549 | tmp) { |
| 5550 | struct ieee80211_channel *chan; |
| 5551 | |
| 5552 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5553 | |
| 5554 | if (!chan) { |
| 5555 | err = -EINVAL; |
| 5556 | goto out_free; |
| 5557 | } |
| 5558 | |
| 5559 | /* ignore disabled channels */ |
| 5560 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5561 | continue; |
| 5562 | |
| 5563 | request->channels[i] = chan; |
| 5564 | i++; |
| 5565 | } |
| 5566 | } else { |
| 5567 | /* all channels */ |
| 5568 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5569 | int j; |
| 5570 | if (!wiphy->bands[band]) |
| 5571 | continue; |
| 5572 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5573 | struct ieee80211_channel *chan; |
| 5574 | |
| 5575 | chan = &wiphy->bands[band]->channels[j]; |
| 5576 | |
| 5577 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5578 | continue; |
| 5579 | |
| 5580 | request->channels[i] = chan; |
| 5581 | i++; |
| 5582 | } |
| 5583 | } |
| 5584 | } |
| 5585 | |
| 5586 | if (!i) { |
| 5587 | err = -EINVAL; |
| 5588 | goto out_free; |
| 5589 | } |
| 5590 | |
| 5591 | request->n_channels = i; |
| 5592 | |
| 5593 | i = 0; |
| 5594 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5595 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5596 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5597 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5598 | err = -EINVAL; |
| 5599 | goto out_free; |
| 5600 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5601 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5602 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5603 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5604 | i++; |
| 5605 | } |
| 5606 | } |
| 5607 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5608 | i = 0; |
| 5609 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5610 | nla_for_each_nested(attr, |
| 5611 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5612 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5613 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5614 | |
| 5615 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5616 | nla_data(attr), nla_len(attr), |
| 5617 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5618 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5619 | if (ssid) { |
| 5620 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5621 | err = -EINVAL; |
| 5622 | goto out_free; |
| 5623 | } |
| 5624 | memcpy(request->match_sets[i].ssid.ssid, |
| 5625 | nla_data(ssid), nla_len(ssid)); |
| 5626 | request->match_sets[i].ssid.ssid_len = |
| 5627 | nla_len(ssid); |
| 5628 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5629 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5630 | if (rssi) |
| 5631 | request->rssi_thold = nla_get_u32(rssi); |
| 5632 | else |
| 5633 | request->rssi_thold = |
| 5634 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5635 | i++; |
| 5636 | } |
| 5637 | } |
| 5638 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5639 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5640 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5641 | memcpy((void *)request->ie, |
| 5642 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5643 | request->ie_len); |
| 5644 | } |
| 5645 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5646 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5647 | request->flags = nla_get_u32( |
| 5648 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5649 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5650 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5651 | err = -EOPNOTSUPP; |
| 5652 | goto out_free; |
| 5653 | } |
| 5654 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5655 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5656 | request->dev = dev; |
| 5657 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5658 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5659 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5660 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5661 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5662 | if (!err) { |
| 5663 | rdev->sched_scan_req = request; |
| 5664 | nl80211_send_sched_scan(rdev, dev, |
| 5665 | NL80211_CMD_START_SCHED_SCAN); |
| 5666 | goto out; |
| 5667 | } |
| 5668 | |
| 5669 | out_free: |
| 5670 | kfree(request); |
| 5671 | out: |
| 5672 | return err; |
| 5673 | } |
| 5674 | |
| 5675 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5676 | struct genl_info *info) |
| 5677 | { |
| 5678 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5679 | |
| 5680 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5681 | !rdev->ops->sched_scan_stop) |
| 5682 | return -EOPNOTSUPP; |
| 5683 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5684 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5685 | } |
| 5686 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5687 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5688 | struct genl_info *info) |
| 5689 | { |
| 5690 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5691 | struct net_device *dev = info->user_ptr[1]; |
| 5692 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5693 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5694 | enum nl80211_dfs_regions dfs_region; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5695 | int err; |
| 5696 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5697 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 5698 | if (dfs_region == NL80211_DFS_UNSET) |
| 5699 | return -EINVAL; |
| 5700 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5701 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5702 | if (err) |
| 5703 | return err; |
| 5704 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5705 | if (netif_carrier_ok(dev)) |
| 5706 | return -EBUSY; |
| 5707 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5708 | if (wdev->cac_started) |
| 5709 | return -EBUSY; |
| 5710 | |
| 5711 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5712 | if (err < 0) |
| 5713 | return err; |
| 5714 | |
| 5715 | if (err == 0) |
| 5716 | return -EINVAL; |
| 5717 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 5718 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5719 | return -EINVAL; |
| 5720 | |
| 5721 | if (!rdev->ops->start_radar_detection) |
| 5722 | return -EOPNOTSUPP; |
| 5723 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5724 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5725 | chandef.chan, CHAN_MODE_SHARED, |
| 5726 | BIT(chandef.width)); |
| 5727 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5728 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5729 | |
| 5730 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5731 | if (!err) { |
| 5732 | wdev->channel = chandef.chan; |
| 5733 | wdev->cac_started = true; |
| 5734 | wdev->cac_start_time = jiffies; |
| 5735 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5736 | return err; |
| 5737 | } |
| 5738 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5739 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5740 | { |
| 5741 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5742 | struct net_device *dev = info->user_ptr[1]; |
| 5743 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5744 | struct cfg80211_csa_settings params; |
| 5745 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5746 | * function is called under RTNL lock, so this should not be a problem. |
| 5747 | */ |
| 5748 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5749 | u8 radar_detect_width = 0; |
| 5750 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5751 | bool need_new_beacon = false; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5752 | |
| 5753 | if (!rdev->ops->channel_switch || |
| 5754 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5755 | return -EOPNOTSUPP; |
| 5756 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5757 | switch (dev->ieee80211_ptr->iftype) { |
| 5758 | case NL80211_IFTYPE_AP: |
| 5759 | case NL80211_IFTYPE_P2P_GO: |
| 5760 | need_new_beacon = true; |
| 5761 | |
| 5762 | /* useless if AP is not running */ |
| 5763 | if (!wdev->beacon_interval) |
| 5764 | return -EINVAL; |
| 5765 | break; |
| 5766 | case NL80211_IFTYPE_ADHOC: |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 5767 | case NL80211_IFTYPE_MESH_POINT: |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5768 | break; |
| 5769 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5770 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5771 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5772 | |
| 5773 | memset(¶ms, 0, sizeof(params)); |
| 5774 | |
| 5775 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5776 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5777 | return -EINVAL; |
| 5778 | |
| 5779 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 5780 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5781 | return -EINVAL; |
| 5782 | |
| 5783 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5784 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5785 | if (!need_new_beacon) |
| 5786 | goto skip_beacons; |
| 5787 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5788 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5789 | if (err) |
| 5790 | return err; |
| 5791 | |
| 5792 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5793 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5794 | nl80211_policy); |
| 5795 | if (err) |
| 5796 | return err; |
| 5797 | |
| 5798 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5799 | if (err) |
| 5800 | return err; |
| 5801 | |
| 5802 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5803 | return -EINVAL; |
| 5804 | |
| 5805 | params.counter_offset_beacon = |
| 5806 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5807 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) |
| 5808 | return -EINVAL; |
| 5809 | |
| 5810 | /* sanity check - counters should be the same */ |
| 5811 | if (params.beacon_csa.tail[params.counter_offset_beacon] != |
| 5812 | params.count) |
| 5813 | return -EINVAL; |
| 5814 | |
| 5815 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
| 5816 | params.counter_offset_presp = |
| 5817 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5818 | if (params.counter_offset_presp >= |
| 5819 | params.beacon_csa.probe_resp_len) |
| 5820 | return -EINVAL; |
| 5821 | |
| 5822 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != |
| 5823 | params.count) |
| 5824 | return -EINVAL; |
| 5825 | } |
| 5826 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5827 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5828 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5829 | if (err) |
| 5830 | return err; |
| 5831 | |
| 5832 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
| 5833 | return -EINVAL; |
| 5834 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5835 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP || |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 5836 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO || |
| 5837 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) { |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5838 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 5839 | ¶ms.chandef); |
| 5840 | if (err < 0) { |
| 5841 | return err; |
| 5842 | } else if (err) { |
| 5843 | radar_detect_width = BIT(params.chandef.width); |
| 5844 | params.radar_required = true; |
| 5845 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5846 | } |
| 5847 | |
| 5848 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5849 | params.chandef.chan, |
| 5850 | CHAN_MODE_SHARED, |
| 5851 | radar_detect_width); |
| 5852 | if (err) |
| 5853 | return err; |
| 5854 | |
| 5855 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 5856 | params.block_tx = true; |
| 5857 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5858 | wdev_lock(wdev); |
| 5859 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 5860 | wdev_unlock(wdev); |
| 5861 | |
| 5862 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5863 | } |
| 5864 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5865 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5866 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5867 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5868 | struct wireless_dev *wdev, |
| 5869 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5870 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5871 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5872 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5873 | void *hdr; |
| 5874 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5875 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5876 | |
| 5877 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5878 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5879 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5880 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5881 | if (!hdr) |
| 5882 | return -1; |
| 5883 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5884 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5885 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5886 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5887 | goto nla_put_failure; |
| 5888 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5889 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5890 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5891 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5892 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5893 | |
| 5894 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5895 | if (!bss) |
| 5896 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5897 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5898 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5899 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5900 | |
| 5901 | rcu_read_lock(); |
| 5902 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5903 | if (ies) { |
| 5904 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5905 | goto fail_unlock_rcu; |
| 5906 | tsf = true; |
| 5907 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5908 | ies->len, ies->data)) |
| 5909 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5910 | } |
| 5911 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5912 | if (ies) { |
| 5913 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5914 | goto fail_unlock_rcu; |
| 5915 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5916 | ies->len, ies->data)) |
| 5917 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5918 | } |
| 5919 | rcu_read_unlock(); |
| 5920 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5921 | if (res->beacon_interval && |
| 5922 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5923 | goto nla_put_failure; |
| 5924 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5925 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 5926 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5927 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5928 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5929 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5930 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5931 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5932 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5933 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5934 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5935 | break; |
| 5936 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5937 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5938 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5939 | break; |
| 5940 | default: |
| 5941 | break; |
| 5942 | } |
| 5943 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5944 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5945 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5946 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5947 | if (intbss == wdev->current_bss && |
| 5948 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5949 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5950 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5951 | break; |
| 5952 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5953 | if (intbss == wdev->current_bss && |
| 5954 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5955 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5956 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5957 | break; |
| 5958 | default: |
| 5959 | break; |
| 5960 | } |
| 5961 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5962 | nla_nest_end(msg, bss); |
| 5963 | |
| 5964 | return genlmsg_end(msg, hdr); |
| 5965 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5966 | fail_unlock_rcu: |
| 5967 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5968 | nla_put_failure: |
| 5969 | genlmsg_cancel(msg, hdr); |
| 5970 | return -EMSGSIZE; |
| 5971 | } |
| 5972 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5973 | 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] | 5974 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5975 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5976 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5977 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5978 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5979 | int err; |
| 5980 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5981 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5982 | if (err) |
| 5983 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5984 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5985 | wdev_lock(wdev); |
| 5986 | spin_lock_bh(&rdev->bss_lock); |
| 5987 | cfg80211_bss_expire(rdev); |
| 5988 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5989 | cb->seq = rdev->bss_generation; |
| 5990 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5991 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5992 | if (++idx <= start) |
| 5993 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5994 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5995 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5996 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5997 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5998 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5999 | } |
| 6000 | } |
| 6001 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6002 | spin_unlock_bh(&rdev->bss_lock); |
| 6003 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6004 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6005 | cb->args[2] = idx; |
| 6006 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6007 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6008 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6009 | } |
| 6010 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6011 | 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] | 6012 | int flags, struct net_device *dev, |
| 6013 | struct survey_info *survey) |
| 6014 | { |
| 6015 | void *hdr; |
| 6016 | struct nlattr *infoattr; |
| 6017 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6018 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6019 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6020 | if (!hdr) |
| 6021 | return -ENOMEM; |
| 6022 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6023 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6024 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6025 | |
| 6026 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6027 | if (!infoattr) |
| 6028 | goto nla_put_failure; |
| 6029 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6030 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 6031 | survey->channel->center_freq)) |
| 6032 | goto nla_put_failure; |
| 6033 | |
| 6034 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6035 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6036 | goto nla_put_failure; |
| 6037 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6038 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6039 | goto nla_put_failure; |
| 6040 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6041 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6042 | survey->channel_time)) |
| 6043 | goto nla_put_failure; |
| 6044 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6045 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6046 | survey->channel_time_busy)) |
| 6047 | goto nla_put_failure; |
| 6048 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6049 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6050 | survey->channel_time_ext_busy)) |
| 6051 | goto nla_put_failure; |
| 6052 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6053 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6054 | survey->channel_time_rx)) |
| 6055 | goto nla_put_failure; |
| 6056 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6057 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6058 | survey->channel_time_tx)) |
| 6059 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6060 | |
| 6061 | nla_nest_end(msg, infoattr); |
| 6062 | |
| 6063 | return genlmsg_end(msg, hdr); |
| 6064 | |
| 6065 | nla_put_failure: |
| 6066 | genlmsg_cancel(msg, hdr); |
| 6067 | return -EMSGSIZE; |
| 6068 | } |
| 6069 | |
| 6070 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6071 | struct netlink_callback *cb) |
| 6072 | { |
| 6073 | struct survey_info survey; |
| 6074 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6075 | struct wireless_dev *wdev; |
| 6076 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6077 | int res; |
| 6078 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6079 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6080 | if (res) |
| 6081 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6082 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6083 | if (!wdev->netdev) { |
| 6084 | res = -EINVAL; |
| 6085 | goto out_err; |
| 6086 | } |
| 6087 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6088 | if (!dev->ops->dump_survey) { |
| 6089 | res = -EOPNOTSUPP; |
| 6090 | goto out_err; |
| 6091 | } |
| 6092 | |
| 6093 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6094 | struct ieee80211_channel *chan; |
| 6095 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6096 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6097 | if (res == -ENOENT) |
| 6098 | break; |
| 6099 | if (res) |
| 6100 | goto out_err; |
| 6101 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6102 | /* Survey without a channel doesn't make sense */ |
| 6103 | if (!survey.channel) { |
| 6104 | res = -EINVAL; |
| 6105 | goto out; |
| 6106 | } |
| 6107 | |
| 6108 | chan = ieee80211_get_channel(&dev->wiphy, |
| 6109 | survey.channel->center_freq); |
| 6110 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6111 | survey_idx++; |
| 6112 | continue; |
| 6113 | } |
| 6114 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6115 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6116 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6117 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6118 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6119 | goto out; |
| 6120 | survey_idx++; |
| 6121 | } |
| 6122 | |
| 6123 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6124 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6125 | res = skb->len; |
| 6126 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6127 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6128 | return res; |
| 6129 | } |
| 6130 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6131 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6132 | { |
| 6133 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6134 | NL80211_WPA_VERSION_2)); |
| 6135 | } |
| 6136 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6137 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6138 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6139 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6140 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6141 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6142 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6143 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6144 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6145 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6146 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6147 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6148 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6149 | return -EINVAL; |
| 6150 | |
| 6151 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6152 | return -EINVAL; |
| 6153 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6154 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6155 | return -EINVAL; |
| 6156 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6157 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6158 | return -EINVAL; |
| 6159 | |
| 6160 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6161 | return -EINVAL; |
| 6162 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6163 | err = nl80211_parse_key(info, &key); |
| 6164 | if (err) |
| 6165 | return err; |
| 6166 | |
| 6167 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6168 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6169 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6170 | if (!key.p.key || !key.p.key_len) |
| 6171 | return -EINVAL; |
| 6172 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6173 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6174 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6175 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6176 | return -EINVAL; |
| 6177 | if (key.idx > 4) |
| 6178 | return -EINVAL; |
| 6179 | } else { |
| 6180 | key.p.key_len = 0; |
| 6181 | key.p.key = NULL; |
| 6182 | } |
| 6183 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6184 | if (key.idx >= 0) { |
| 6185 | int i; |
| 6186 | bool ok = false; |
| 6187 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6188 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6189 | ok = true; |
| 6190 | break; |
| 6191 | } |
| 6192 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6193 | if (!ok) |
| 6194 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6195 | } |
| 6196 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6197 | if (!rdev->ops->auth) |
| 6198 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6199 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6200 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6201 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6202 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6203 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6204 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6205 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6206 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6207 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6208 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6209 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6210 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6211 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6212 | |
| 6213 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6214 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6215 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6216 | } |
| 6217 | |
| 6218 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6219 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6220 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6221 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6222 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6223 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6224 | return -EINVAL; |
| 6225 | |
| 6226 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6227 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6228 | return -EINVAL; |
| 6229 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6230 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6231 | /* need to include at least Auth Transaction and Status Code */ |
| 6232 | if (sae_data_len < 4) |
| 6233 | return -EINVAL; |
| 6234 | } |
| 6235 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6236 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6237 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6238 | /* |
| 6239 | * Since we no longer track auth state, ignore |
| 6240 | * requests to only change local state. |
| 6241 | */ |
| 6242 | if (local_state_change) |
| 6243 | return 0; |
| 6244 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6245 | wdev_lock(dev->ieee80211_ptr); |
| 6246 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6247 | ssid, ssid_len, ie, ie_len, |
| 6248 | key.p.key, key.p.key_len, key.idx, |
| 6249 | sae_data, sae_data_len); |
| 6250 | wdev_unlock(dev->ieee80211_ptr); |
| 6251 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6252 | } |
| 6253 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6254 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6255 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6256 | struct cfg80211_crypto_settings *settings, |
| 6257 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6258 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6259 | memset(settings, 0, sizeof(*settings)); |
| 6260 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6261 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6262 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6263 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6264 | u16 proto; |
| 6265 | proto = nla_get_u16( |
| 6266 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6267 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6268 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6269 | proto != ETH_P_PAE) |
| 6270 | return -EINVAL; |
| 6271 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6272 | settings->control_port_no_encrypt = true; |
| 6273 | } else |
| 6274 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6275 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6276 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6277 | void *data; |
| 6278 | int len, i; |
| 6279 | |
| 6280 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6281 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6282 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6283 | |
| 6284 | if (len % sizeof(u32)) |
| 6285 | return -EINVAL; |
| 6286 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6287 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6288 | return -EINVAL; |
| 6289 | |
| 6290 | memcpy(settings->ciphers_pairwise, data, len); |
| 6291 | |
| 6292 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6293 | if (!cfg80211_supported_cipher_suite( |
| 6294 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6295 | settings->ciphers_pairwise[i])) |
| 6296 | return -EINVAL; |
| 6297 | } |
| 6298 | |
| 6299 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6300 | settings->cipher_group = |
| 6301 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6302 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6303 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6304 | return -EINVAL; |
| 6305 | } |
| 6306 | |
| 6307 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6308 | settings->wpa_versions = |
| 6309 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6310 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6311 | return -EINVAL; |
| 6312 | } |
| 6313 | |
| 6314 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6315 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6316 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6317 | |
| 6318 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6319 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6320 | settings->n_akm_suites = len / sizeof(u32); |
| 6321 | |
| 6322 | if (len % sizeof(u32)) |
| 6323 | return -EINVAL; |
| 6324 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6325 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6326 | return -EINVAL; |
| 6327 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6328 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6329 | } |
| 6330 | |
| 6331 | return 0; |
| 6332 | } |
| 6333 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6334 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6335 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6336 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6337 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6338 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6339 | struct cfg80211_assoc_request req = {}; |
| 6340 | const u8 *bssid, *ssid; |
| 6341 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6342 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6343 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6344 | return -EINVAL; |
| 6345 | |
| 6346 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6347 | !info->attrs[NL80211_ATTR_SSID] || |
| 6348 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6349 | return -EINVAL; |
| 6350 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6351 | if (!rdev->ops->assoc) |
| 6352 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6353 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6354 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6355 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6356 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6357 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6358 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6359 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6360 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6361 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6362 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6363 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6364 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6365 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6366 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6367 | |
| 6368 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6369 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6370 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6371 | } |
| 6372 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6373 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6374 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6375 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6376 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6377 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6378 | else if (mfp != NL80211_MFP_NO) |
| 6379 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6380 | } |
| 6381 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6382 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6383 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6384 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6385 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6386 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6387 | |
| 6388 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6389 | memcpy(&req.ht_capa_mask, |
| 6390 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6391 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6392 | |
| 6393 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6394 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6395 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6396 | memcpy(&req.ht_capa, |
| 6397 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6398 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6399 | } |
| 6400 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6401 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6402 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6403 | |
| 6404 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6405 | memcpy(&req.vht_capa_mask, |
| 6406 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6407 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6408 | |
| 6409 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6410 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6411 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6412 | memcpy(&req.vht_capa, |
| 6413 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6414 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6415 | } |
| 6416 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6417 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6418 | if (!err) { |
| 6419 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6420 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6421 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6422 | wdev_unlock(dev->ieee80211_ptr); |
| 6423 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6424 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6425 | return err; |
| 6426 | } |
| 6427 | |
| 6428 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6429 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6430 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6431 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6432 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6433 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6434 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6435 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6436 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6437 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6438 | return -EINVAL; |
| 6439 | |
| 6440 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6441 | return -EINVAL; |
| 6442 | |
| 6443 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6444 | return -EINVAL; |
| 6445 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6446 | if (!rdev->ops->deauth) |
| 6447 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6448 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6449 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6450 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6451 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6452 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6453 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6454 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6455 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6456 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6457 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6458 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6459 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6460 | |
| 6461 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6462 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6463 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6464 | } |
| 6465 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6466 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6467 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6468 | wdev_lock(dev->ieee80211_ptr); |
| 6469 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6470 | local_state_change); |
| 6471 | wdev_unlock(dev->ieee80211_ptr); |
| 6472 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6473 | } |
| 6474 | |
| 6475 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6476 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6477 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6478 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6479 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6480 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6481 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6482 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6483 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6484 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6485 | return -EINVAL; |
| 6486 | |
| 6487 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6488 | return -EINVAL; |
| 6489 | |
| 6490 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6491 | return -EINVAL; |
| 6492 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6493 | if (!rdev->ops->disassoc) |
| 6494 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6495 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6496 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6497 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6498 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6499 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6500 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6501 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6502 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6503 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6504 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6505 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6506 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6507 | |
| 6508 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6509 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6510 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6511 | } |
| 6512 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6513 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6514 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6515 | wdev_lock(dev->ieee80211_ptr); |
| 6516 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6517 | local_state_change); |
| 6518 | wdev_unlock(dev->ieee80211_ptr); |
| 6519 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6520 | } |
| 6521 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6522 | static bool |
| 6523 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6524 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6525 | int rateval) |
| 6526 | { |
| 6527 | struct wiphy *wiphy = &rdev->wiphy; |
| 6528 | bool found = false; |
| 6529 | int band, i; |
| 6530 | |
| 6531 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6532 | struct ieee80211_supported_band *sband; |
| 6533 | |
| 6534 | sband = wiphy->bands[band]; |
| 6535 | if (!sband) |
| 6536 | continue; |
| 6537 | |
| 6538 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6539 | if (sband->bitrates[i].bitrate == rateval) { |
| 6540 | mcast_rate[band] = i + 1; |
| 6541 | found = true; |
| 6542 | break; |
| 6543 | } |
| 6544 | } |
| 6545 | } |
| 6546 | |
| 6547 | return found; |
| 6548 | } |
| 6549 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6550 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6551 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6552 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6553 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6554 | struct cfg80211_ibss_params ibss; |
| 6555 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6556 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6557 | int err; |
| 6558 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6559 | memset(&ibss, 0, sizeof(ibss)); |
| 6560 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6561 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6562 | return -EINVAL; |
| 6563 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6564 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6565 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6566 | return -EINVAL; |
| 6567 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6568 | ibss.beacon_interval = 100; |
| 6569 | |
| 6570 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6571 | ibss.beacon_interval = |
| 6572 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6573 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6574 | return -EINVAL; |
| 6575 | } |
| 6576 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6577 | if (!rdev->ops->join_ibss) |
| 6578 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6579 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6580 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6581 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6582 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6583 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6584 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6585 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6586 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6587 | |
| 6588 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6589 | return -EINVAL; |
| 6590 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6591 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6592 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6593 | |
| 6594 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6595 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6596 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6597 | } |
| 6598 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6599 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6600 | if (err) |
| 6601 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6602 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6603 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6604 | return -EINVAL; |
| 6605 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6606 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6607 | case NL80211_CHAN_WIDTH_5: |
| 6608 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6609 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6610 | break; |
| 6611 | case NL80211_CHAN_WIDTH_20: |
| 6612 | case NL80211_CHAN_WIDTH_40: |
| 6613 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6614 | break; |
| 6615 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6616 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6617 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6618 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6619 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6620 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6621 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6622 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6623 | u8 *rates = |
| 6624 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6625 | int n_rates = |
| 6626 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6627 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6628 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6629 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6630 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6631 | &ibss.basic_rates); |
| 6632 | if (err) |
| 6633 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6634 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6635 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6636 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6637 | memcpy(&ibss.ht_capa_mask, |
| 6638 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6639 | sizeof(ibss.ht_capa_mask)); |
| 6640 | |
| 6641 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6642 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6643 | return -EINVAL; |
| 6644 | memcpy(&ibss.ht_capa, |
| 6645 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6646 | sizeof(ibss.ht_capa)); |
| 6647 | } |
| 6648 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6649 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6650 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6651 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6652 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6653 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6654 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6655 | bool no_ht = false; |
| 6656 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6657 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6658 | info->attrs[NL80211_ATTR_KEYS], |
| 6659 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6660 | if (IS_ERR(connkeys)) |
| 6661 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6662 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6663 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6664 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6665 | kfree(connkeys); |
| 6666 | return -EINVAL; |
| 6667 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6668 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6669 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6670 | ibss.control_port = |
| 6671 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6672 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 6673 | ibss.userspace_handles_dfs = |
| 6674 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 6675 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6676 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6677 | if (err) |
| 6678 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6679 | return err; |
| 6680 | } |
| 6681 | |
| 6682 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6683 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6684 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6685 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6686 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6687 | if (!rdev->ops->leave_ibss) |
| 6688 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6689 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6690 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6691 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6692 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6693 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6694 | } |
| 6695 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6696 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6697 | { |
| 6698 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6699 | struct net_device *dev = info->user_ptr[1]; |
| 6700 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6701 | u32 nla_rate; |
| 6702 | int err; |
| 6703 | |
| 6704 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6705 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6706 | return -EOPNOTSUPP; |
| 6707 | |
| 6708 | if (!rdev->ops->set_mcast_rate) |
| 6709 | return -EOPNOTSUPP; |
| 6710 | |
| 6711 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6712 | |
| 6713 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6714 | return -EINVAL; |
| 6715 | |
| 6716 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6717 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6718 | return -EINVAL; |
| 6719 | |
| 6720 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6721 | |
| 6722 | return err; |
| 6723 | } |
| 6724 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6725 | static struct sk_buff * |
| 6726 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 6727 | int approxlen, u32 portid, u32 seq, |
| 6728 | enum nl80211_commands cmd, |
| 6729 | enum nl80211_attrs attr, gfp_t gfp) |
| 6730 | { |
| 6731 | struct sk_buff *skb; |
| 6732 | void *hdr; |
| 6733 | struct nlattr *data; |
| 6734 | |
| 6735 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6736 | if (!skb) |
| 6737 | return NULL; |
| 6738 | |
| 6739 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 6740 | if (!hdr) { |
| 6741 | kfree_skb(skb); |
| 6742 | return NULL; |
| 6743 | } |
| 6744 | |
| 6745 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6746 | goto nla_put_failure; |
| 6747 | data = nla_nest_start(skb, attr); |
| 6748 | |
| 6749 | ((void **)skb->cb)[0] = rdev; |
| 6750 | ((void **)skb->cb)[1] = hdr; |
| 6751 | ((void **)skb->cb)[2] = data; |
| 6752 | |
| 6753 | return skb; |
| 6754 | |
| 6755 | nla_put_failure: |
| 6756 | kfree_skb(skb); |
| 6757 | return NULL; |
| 6758 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6759 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6760 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6761 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6762 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6763 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6764 | struct wireless_dev *wdev = |
| 6765 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6766 | int err; |
| 6767 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6768 | if (!rdev->ops->testmode_cmd) |
| 6769 | return -EOPNOTSUPP; |
| 6770 | |
| 6771 | if (IS_ERR(wdev)) { |
| 6772 | err = PTR_ERR(wdev); |
| 6773 | if (err != -EINVAL) |
| 6774 | return err; |
| 6775 | wdev = NULL; |
| 6776 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 6777 | return -EINVAL; |
| 6778 | } |
| 6779 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6780 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6781 | return -EINVAL; |
| 6782 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6783 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6784 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6785 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6786 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6787 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6788 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6789 | return err; |
| 6790 | } |
| 6791 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6792 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6793 | struct netlink_callback *cb) |
| 6794 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6795 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6796 | int err; |
| 6797 | long phy_idx; |
| 6798 | void *data = NULL; |
| 6799 | int data_len = 0; |
| 6800 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6801 | rtnl_lock(); |
| 6802 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6803 | if (cb->args[0]) { |
| 6804 | /* |
| 6805 | * 0 is a valid index, but not valid for args[0], |
| 6806 | * so we need to offset by 1. |
| 6807 | */ |
| 6808 | phy_idx = cb->args[0] - 1; |
| 6809 | } else { |
| 6810 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6811 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6812 | nl80211_policy); |
| 6813 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6814 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6815 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6816 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6817 | nl80211_fam.attrbuf); |
| 6818 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6819 | err = PTR_ERR(rdev); |
| 6820 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6821 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6822 | phy_idx = rdev->wiphy_idx; |
| 6823 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6824 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6825 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6826 | cb->args[1] = |
| 6827 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6828 | } |
| 6829 | |
| 6830 | if (cb->args[1]) { |
| 6831 | data = nla_data((void *)cb->args[1]); |
| 6832 | data_len = nla_len((void *)cb->args[1]); |
| 6833 | } |
| 6834 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6835 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6836 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6837 | err = -ENOENT; |
| 6838 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6839 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6840 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6841 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6842 | err = -EOPNOTSUPP; |
| 6843 | goto out_err; |
| 6844 | } |
| 6845 | |
| 6846 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6847 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6848 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6849 | NL80211_CMD_TESTMODE); |
| 6850 | struct nlattr *tmdata; |
| 6851 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 6852 | if (!hdr) |
| 6853 | break; |
| 6854 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6855 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6856 | genlmsg_cancel(skb, hdr); |
| 6857 | break; |
| 6858 | } |
| 6859 | |
| 6860 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6861 | if (!tmdata) { |
| 6862 | genlmsg_cancel(skb, hdr); |
| 6863 | break; |
| 6864 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6865 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6866 | nla_nest_end(skb, tmdata); |
| 6867 | |
| 6868 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6869 | genlmsg_cancel(skb, hdr); |
| 6870 | break; |
| 6871 | } else if (err) { |
| 6872 | genlmsg_cancel(skb, hdr); |
| 6873 | goto out_err; |
| 6874 | } |
| 6875 | |
| 6876 | genlmsg_end(skb, hdr); |
| 6877 | } |
| 6878 | |
| 6879 | err = skb->len; |
| 6880 | /* see above */ |
| 6881 | cb->args[0] = phy_idx + 1; |
| 6882 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6883 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6884 | return err; |
| 6885 | } |
| 6886 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6887 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6888 | int approxlen, gfp_t gfp) |
| 6889 | { |
| 6890 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6891 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6892 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
| 6893 | NL80211_CMD_TESTMODE, |
| 6894 | NL80211_ATTR_TESTDATA, gfp); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6895 | } |
| 6896 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6897 | |
| 6898 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6899 | { |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 6900 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6901 | void *hdr = ((void **)skb->cb)[1]; |
| 6902 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6903 | |
| 6904 | nla_nest_end(skb, data); |
| 6905 | genlmsg_end(skb, hdr); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 6906 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 6907 | NL80211_MCGRP_TESTMODE, gfp); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6908 | } |
| 6909 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6910 | #endif |
| 6911 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6912 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6913 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6915 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6916 | struct cfg80211_connect_params connect; |
| 6917 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6918 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6919 | int err; |
| 6920 | |
| 6921 | memset(&connect, 0, sizeof(connect)); |
| 6922 | |
| 6923 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6924 | return -EINVAL; |
| 6925 | |
| 6926 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6927 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6928 | return -EINVAL; |
| 6929 | |
| 6930 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6931 | connect.auth_type = |
| 6932 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6933 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6934 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6935 | return -EINVAL; |
| 6936 | } else |
| 6937 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6938 | |
| 6939 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6940 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6941 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6942 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6943 | if (err) |
| 6944 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6945 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6946 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6947 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6948 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6949 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6950 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6951 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6952 | connect.bg_scan_period = -1; |
| 6953 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6954 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6955 | connect.bg_scan_period = |
| 6956 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6957 | } |
| 6958 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6959 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6960 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6961 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6962 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6963 | |
| 6964 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6965 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6966 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6967 | } |
| 6968 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6969 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6970 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6971 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6972 | connect.mfp != NL80211_MFP_NO) |
| 6973 | return -EINVAL; |
| 6974 | } else { |
| 6975 | connect.mfp = NL80211_MFP_NO; |
| 6976 | } |
| 6977 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6978 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6979 | connect.channel = |
| 6980 | ieee80211_get_channel(wiphy, |
| 6981 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6982 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6983 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6984 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6985 | } |
| 6986 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6987 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6988 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6989 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6990 | if (IS_ERR(connkeys)) |
| 6991 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6992 | } |
| 6993 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6994 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6995 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6996 | |
| 6997 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6998 | memcpy(&connect.ht_capa_mask, |
| 6999 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7000 | sizeof(connect.ht_capa_mask)); |
| 7001 | |
| 7002 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7003 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 7004 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7005 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7006 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7007 | memcpy(&connect.ht_capa, |
| 7008 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7009 | sizeof(connect.ht_capa)); |
| 7010 | } |
| 7011 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7012 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7013 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7014 | |
| 7015 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7016 | memcpy(&connect.vht_capa_mask, |
| 7017 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7018 | sizeof(connect.vht_capa_mask)); |
| 7019 | |
| 7020 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7021 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 7022 | kfree(connkeys); |
| 7023 | return -EINVAL; |
| 7024 | } |
| 7025 | memcpy(&connect.vht_capa, |
| 7026 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7027 | sizeof(connect.vht_capa)); |
| 7028 | } |
| 7029 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7030 | wdev_lock(dev->ieee80211_ptr); |
| 7031 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7032 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7033 | if (err) |
| 7034 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7035 | return err; |
| 7036 | } |
| 7037 | |
| 7038 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7039 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7040 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7041 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7042 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7043 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7044 | |
| 7045 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7046 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7047 | else |
| 7048 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7049 | |
| 7050 | if (reason == 0) |
| 7051 | return -EINVAL; |
| 7052 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7053 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7054 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7055 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7056 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7057 | wdev_lock(dev->ieee80211_ptr); |
| 7058 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7059 | wdev_unlock(dev->ieee80211_ptr); |
| 7060 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7061 | } |
| 7062 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7063 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7064 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7065 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7066 | struct net *net; |
| 7067 | int err; |
| 7068 | u32 pid; |
| 7069 | |
| 7070 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7071 | return -EINVAL; |
| 7072 | |
| 7073 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7074 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7075 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7076 | if (IS_ERR(net)) |
| 7077 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7078 | |
| 7079 | err = 0; |
| 7080 | |
| 7081 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7082 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7083 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7084 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7085 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7086 | return err; |
| 7087 | } |
| 7088 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7089 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7090 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7091 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7092 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7093 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7094 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7095 | struct cfg80211_pmksa pmksa; |
| 7096 | |
| 7097 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7098 | |
| 7099 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7100 | return -EINVAL; |
| 7101 | |
| 7102 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7103 | return -EINVAL; |
| 7104 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7105 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7106 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7107 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7108 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7109 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7110 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7111 | |
| 7112 | switch (info->genlhdr->cmd) { |
| 7113 | case NL80211_CMD_SET_PMKSA: |
| 7114 | rdev_ops = rdev->ops->set_pmksa; |
| 7115 | break; |
| 7116 | case NL80211_CMD_DEL_PMKSA: |
| 7117 | rdev_ops = rdev->ops->del_pmksa; |
| 7118 | break; |
| 7119 | default: |
| 7120 | WARN_ON(1); |
| 7121 | break; |
| 7122 | } |
| 7123 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7124 | if (!rdev_ops) |
| 7125 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7126 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7127 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7128 | } |
| 7129 | |
| 7130 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7131 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7132 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7133 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7134 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7135 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7136 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7137 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7138 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7139 | if (!rdev->ops->flush_pmksa) |
| 7140 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7141 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7142 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7143 | } |
| 7144 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7145 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7146 | { |
| 7147 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7148 | struct net_device *dev = info->user_ptr[1]; |
| 7149 | u8 action_code, dialog_token; |
| 7150 | u16 status_code; |
| 7151 | u8 *peer; |
| 7152 | |
| 7153 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7154 | !rdev->ops->tdls_mgmt) |
| 7155 | return -EOPNOTSUPP; |
| 7156 | |
| 7157 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7158 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7159 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7160 | !info->attrs[NL80211_ATTR_IE] || |
| 7161 | !info->attrs[NL80211_ATTR_MAC]) |
| 7162 | return -EINVAL; |
| 7163 | |
| 7164 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7165 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7166 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7167 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 7168 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7169 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 7170 | dialog_token, status_code, |
| 7171 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7172 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7173 | } |
| 7174 | |
| 7175 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7176 | { |
| 7177 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7178 | struct net_device *dev = info->user_ptr[1]; |
| 7179 | enum nl80211_tdls_operation operation; |
| 7180 | u8 *peer; |
| 7181 | |
| 7182 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7183 | !rdev->ops->tdls_oper) |
| 7184 | return -EOPNOTSUPP; |
| 7185 | |
| 7186 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7187 | !info->attrs[NL80211_ATTR_MAC]) |
| 7188 | return -EINVAL; |
| 7189 | |
| 7190 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7191 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7192 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7193 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7194 | } |
| 7195 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7196 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7197 | struct genl_info *info) |
| 7198 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7199 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7200 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7201 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7202 | struct sk_buff *msg; |
| 7203 | void *hdr; |
| 7204 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7205 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7206 | int err; |
| 7207 | |
| 7208 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7209 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7210 | return -EINVAL; |
| 7211 | |
| 7212 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7213 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7214 | if (!rdev->ops->remain_on_channel || |
| 7215 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7216 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7217 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7218 | /* |
| 7219 | * We should be on that channel for at least a minimum amount of |
| 7220 | * time (10ms) but no longer than the driver supports. |
| 7221 | */ |
| 7222 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7223 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7224 | return -EINVAL; |
| 7225 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7226 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7227 | if (err) |
| 7228 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7229 | |
| 7230 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7231 | if (!msg) |
| 7232 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7233 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7234 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7235 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7236 | if (!hdr) { |
| 7237 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7238 | goto free_msg; |
| 7239 | } |
| 7240 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7241 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7242 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7243 | |
| 7244 | if (err) |
| 7245 | goto free_msg; |
| 7246 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7247 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7248 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7249 | |
| 7250 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7251 | |
| 7252 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7253 | |
| 7254 | nla_put_failure: |
| 7255 | err = -ENOBUFS; |
| 7256 | free_msg: |
| 7257 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7258 | return err; |
| 7259 | } |
| 7260 | |
| 7261 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7262 | struct genl_info *info) |
| 7263 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7264 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7265 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7266 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7267 | |
| 7268 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7269 | return -EINVAL; |
| 7270 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7271 | if (!rdev->ops->cancel_remain_on_channel) |
| 7272 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7273 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7274 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7275 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7276 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7277 | } |
| 7278 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7279 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7280 | u8 *rates, u8 rates_len) |
| 7281 | { |
| 7282 | u8 i; |
| 7283 | u32 mask = 0; |
| 7284 | |
| 7285 | for (i = 0; i < rates_len; i++) { |
| 7286 | int rate = (rates[i] & 0x7f) * 5; |
| 7287 | int ridx; |
| 7288 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7289 | struct ieee80211_rate *srate = |
| 7290 | &sband->bitrates[ridx]; |
| 7291 | if (rate == srate->bitrate) { |
| 7292 | mask |= 1 << ridx; |
| 7293 | break; |
| 7294 | } |
| 7295 | } |
| 7296 | if (ridx == sband->n_bitrates) |
| 7297 | return 0; /* rate not found */ |
| 7298 | } |
| 7299 | |
| 7300 | return mask; |
| 7301 | } |
| 7302 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7303 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7304 | u8 *rates, u8 rates_len, |
| 7305 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7306 | { |
| 7307 | u8 i; |
| 7308 | |
| 7309 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7310 | |
| 7311 | for (i = 0; i < rates_len; i++) { |
| 7312 | int ridx, rbit; |
| 7313 | |
| 7314 | ridx = rates[i] / 8; |
| 7315 | rbit = BIT(rates[i] % 8); |
| 7316 | |
| 7317 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7318 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7319 | return false; |
| 7320 | |
| 7321 | /* check availability */ |
| 7322 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7323 | mcs[ridx] |= rbit; |
| 7324 | else |
| 7325 | return false; |
| 7326 | } |
| 7327 | |
| 7328 | return true; |
| 7329 | } |
| 7330 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame^] | 7331 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 7332 | { |
| 7333 | u16 mcs_mask = 0; |
| 7334 | |
| 7335 | switch (vht_mcs_map) { |
| 7336 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 7337 | break; |
| 7338 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 7339 | mcs_mask = 0x00FF; |
| 7340 | break; |
| 7341 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 7342 | mcs_mask = 0x01FF; |
| 7343 | break; |
| 7344 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 7345 | mcs_mask = 0x03FF; |
| 7346 | break; |
| 7347 | default: |
| 7348 | break; |
| 7349 | } |
| 7350 | |
| 7351 | return mcs_mask; |
| 7352 | } |
| 7353 | |
| 7354 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 7355 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 7356 | { |
| 7357 | u8 nss; |
| 7358 | |
| 7359 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 7360 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 7361 | vht_mcs_map >>= 2; |
| 7362 | } |
| 7363 | } |
| 7364 | |
| 7365 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 7366 | struct nl80211_txrate_vht *txrate, |
| 7367 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 7368 | { |
| 7369 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7370 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 7371 | u8 i; |
| 7372 | |
| 7373 | if (!sband->vht_cap.vht_supported) |
| 7374 | return false; |
| 7375 | |
| 7376 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 7377 | |
| 7378 | /* Build vht_mcs_mask from VHT capabilities */ |
| 7379 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 7380 | |
| 7381 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 7382 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 7383 | mcs[i] = txrate->mcs[i]; |
| 7384 | else |
| 7385 | return false; |
| 7386 | } |
| 7387 | |
| 7388 | return true; |
| 7389 | } |
| 7390 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7391 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7392 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7393 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7394 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 7395 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame^] | 7396 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7397 | }; |
| 7398 | |
| 7399 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7400 | struct genl_info *info) |
| 7401 | { |
| 7402 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7403 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7404 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7405 | int rem, i; |
| 7406 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7407 | struct nlattr *tx_rates; |
| 7408 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame^] | 7409 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7410 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7411 | if (!rdev->ops->set_bitrate_mask) |
| 7412 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7413 | |
| 7414 | memset(&mask, 0, sizeof(mask)); |
| 7415 | /* Default to all rates enabled */ |
| 7416 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7417 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7418 | |
| 7419 | if (!sband) |
| 7420 | continue; |
| 7421 | |
| 7422 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7423 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7424 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7425 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame^] | 7426 | |
| 7427 | if (!sband->vht_cap.vht_supported) |
| 7428 | continue; |
| 7429 | |
| 7430 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7431 | 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] | 7432 | } |
| 7433 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7434 | /* if no rates are given set it back to the defaults */ |
| 7435 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 7436 | goto out; |
| 7437 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7438 | /* |
| 7439 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7440 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7441 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7442 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7443 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7444 | { |
| 7445 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7446 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7447 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7448 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7449 | if (sband == NULL) |
| 7450 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7451 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7452 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7453 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7454 | mask.control[band].legacy = rateset_to_mask( |
| 7455 | sband, |
| 7456 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7457 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7458 | if ((mask.control[band].legacy == 0) && |
| 7459 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7460 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7461 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7462 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7463 | if (!ht_rateset_to_mask( |
| 7464 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7465 | nla_data(tb[NL80211_TXRATE_HT]), |
| 7466 | nla_len(tb[NL80211_TXRATE_HT]), |
| 7467 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7468 | return -EINVAL; |
| 7469 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame^] | 7470 | if (tb[NL80211_TXRATE_VHT]) { |
| 7471 | if (!vht_set_mcs_mask( |
| 7472 | sband, |
| 7473 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 7474 | mask.control[band].vht_mcs)) |
| 7475 | return -EINVAL; |
| 7476 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7477 | |
| 7478 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame^] | 7479 | /* don't allow empty legacy rates if HT or VHT |
| 7480 | * are not even supported. |
| 7481 | */ |
| 7482 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 7483 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7484 | return -EINVAL; |
| 7485 | |
| 7486 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7487 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame^] | 7488 | goto out; |
| 7489 | |
| 7490 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 7491 | if (mask.control[band].vht_mcs[i]) |
| 7492 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7493 | |
| 7494 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame^] | 7495 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7496 | } |
| 7497 | } |
| 7498 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7499 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7500 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7501 | } |
| 7502 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7503 | 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] | 7504 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7505 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7506 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7507 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7508 | |
| 7509 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7510 | return -EINVAL; |
| 7511 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7512 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7513 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7514 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7515 | switch (wdev->iftype) { |
| 7516 | case NL80211_IFTYPE_STATION: |
| 7517 | case NL80211_IFTYPE_ADHOC: |
| 7518 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7519 | case NL80211_IFTYPE_AP: |
| 7520 | case NL80211_IFTYPE_AP_VLAN: |
| 7521 | case NL80211_IFTYPE_MESH_POINT: |
| 7522 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7523 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7524 | break; |
| 7525 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7526 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7527 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7528 | |
| 7529 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7530 | if (!rdev->ops->mgmt_tx) |
| 7531 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7532 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7533 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7534 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7535 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7536 | } |
| 7537 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7538 | 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] | 7539 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7540 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7541 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7542 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7543 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7544 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7545 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7546 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7547 | struct cfg80211_mgmt_tx_params params = { |
| 7548 | .dont_wait_for_ack = |
| 7549 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 7550 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7551 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7552 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7553 | return -EINVAL; |
| 7554 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7555 | if (!rdev->ops->mgmt_tx) |
| 7556 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7557 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7558 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7559 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7560 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7561 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7562 | case NL80211_IFTYPE_STATION: |
| 7563 | case NL80211_IFTYPE_ADHOC: |
| 7564 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7565 | case NL80211_IFTYPE_AP: |
| 7566 | case NL80211_IFTYPE_AP_VLAN: |
| 7567 | case NL80211_IFTYPE_MESH_POINT: |
| 7568 | case NL80211_IFTYPE_P2P_GO: |
| 7569 | break; |
| 7570 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7571 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7572 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7573 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7574 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7575 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7576 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7577 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7578 | |
| 7579 | /* |
| 7580 | * We should wait on the channel for at least a minimum amount |
| 7581 | * of time (10ms) but no longer than the driver supports. |
| 7582 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7583 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7584 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7585 | return -EINVAL; |
| 7586 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7587 | } |
| 7588 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7589 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7590 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7591 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7592 | return -EINVAL; |
| 7593 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7594 | 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] | 7595 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7596 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7597 | * the driver. The latter will use the current one |
| 7598 | */ |
| 7599 | chandef.chan = NULL; |
| 7600 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7601 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7602 | if (err) |
| 7603 | return err; |
| 7604 | } |
| 7605 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7606 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7607 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7608 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7609 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7610 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7611 | if (!msg) |
| 7612 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7613 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7614 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7615 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7616 | if (!hdr) { |
| 7617 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7618 | goto free_msg; |
| 7619 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7620 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7621 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7622 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 7623 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 7624 | params.chan = chandef.chan; |
| 7625 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7626 | if (err) |
| 7627 | goto free_msg; |
| 7628 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7629 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7630 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7631 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7632 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7633 | genlmsg_end(msg, hdr); |
| 7634 | return genlmsg_reply(msg, info); |
| 7635 | } |
| 7636 | |
| 7637 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7638 | |
| 7639 | nla_put_failure: |
| 7640 | err = -ENOBUFS; |
| 7641 | free_msg: |
| 7642 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7643 | return err; |
| 7644 | } |
| 7645 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7646 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7647 | { |
| 7648 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7649 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7650 | u64 cookie; |
| 7651 | |
| 7652 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7653 | return -EINVAL; |
| 7654 | |
| 7655 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7656 | return -EOPNOTSUPP; |
| 7657 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7658 | switch (wdev->iftype) { |
| 7659 | case NL80211_IFTYPE_STATION: |
| 7660 | case NL80211_IFTYPE_ADHOC: |
| 7661 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7662 | case NL80211_IFTYPE_AP: |
| 7663 | case NL80211_IFTYPE_AP_VLAN: |
| 7664 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7665 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7666 | break; |
| 7667 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7668 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7669 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7670 | |
| 7671 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7672 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7673 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7674 | } |
| 7675 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7676 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7677 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7678 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7679 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7680 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7681 | u8 ps_state; |
| 7682 | bool state; |
| 7683 | int err; |
| 7684 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7685 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7686 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7687 | |
| 7688 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7689 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7690 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7691 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7692 | |
| 7693 | wdev = dev->ieee80211_ptr; |
| 7694 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7695 | if (!rdev->ops->set_power_mgmt) |
| 7696 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7697 | |
| 7698 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7699 | |
| 7700 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7701 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7702 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7703 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7704 | if (!err) |
| 7705 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7706 | return err; |
| 7707 | } |
| 7708 | |
| 7709 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7710 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7711 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7712 | enum nl80211_ps_state ps_state; |
| 7713 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7714 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7715 | struct sk_buff *msg; |
| 7716 | void *hdr; |
| 7717 | int err; |
| 7718 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7719 | wdev = dev->ieee80211_ptr; |
| 7720 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7721 | if (!rdev->ops->set_power_mgmt) |
| 7722 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7723 | |
| 7724 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7725 | if (!msg) |
| 7726 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7727 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7728 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7729 | NL80211_CMD_GET_POWER_SAVE); |
| 7730 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7731 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7732 | goto free_msg; |
| 7733 | } |
| 7734 | |
| 7735 | if (wdev->ps) |
| 7736 | ps_state = NL80211_PS_ENABLED; |
| 7737 | else |
| 7738 | ps_state = NL80211_PS_DISABLED; |
| 7739 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7740 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7741 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7742 | |
| 7743 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7744 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7745 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7746 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7747 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7748 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7749 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7750 | return err; |
| 7751 | } |
| 7752 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7753 | static struct nla_policy |
| 7754 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7755 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7756 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7757 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7758 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7759 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7760 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7761 | }; |
| 7762 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7763 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7764 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7765 | { |
| 7766 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7767 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7768 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7769 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7770 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7771 | return -EINVAL; |
| 7772 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7773 | if (!rdev->ops->set_cqm_txe_config) |
| 7774 | return -EOPNOTSUPP; |
| 7775 | |
| 7776 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7777 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7778 | return -EOPNOTSUPP; |
| 7779 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7780 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7781 | } |
| 7782 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7783 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7784 | s32 threshold, u32 hysteresis) |
| 7785 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7786 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7787 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7788 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7789 | |
| 7790 | if (threshold > 0) |
| 7791 | return -EINVAL; |
| 7792 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7793 | /* disabling - hysteresis should also be zero then */ |
| 7794 | if (threshold == 0) |
| 7795 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7796 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7797 | if (!rdev->ops->set_cqm_rssi_config) |
| 7798 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7799 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7800 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7801 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7802 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7803 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7804 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7805 | } |
| 7806 | |
| 7807 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7808 | { |
| 7809 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7810 | struct nlattr *cqm; |
| 7811 | int err; |
| 7812 | |
| 7813 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7814 | if (!cqm) |
| 7815 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7816 | |
| 7817 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7818 | nl80211_attr_cqm_policy); |
| 7819 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7820 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7821 | |
| 7822 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7823 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7824 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7825 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7826 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7827 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 7828 | } |
| 7829 | |
| 7830 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7831 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7832 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7833 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7834 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7835 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7836 | |
| 7837 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 7838 | } |
| 7839 | |
| 7840 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7841 | } |
| 7842 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7843 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7844 | { |
| 7845 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7846 | struct net_device *dev = info->user_ptr[1]; |
| 7847 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7848 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7849 | int err; |
| 7850 | |
| 7851 | /* start with default */ |
| 7852 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7853 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7854 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7855 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7856 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7857 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7858 | if (err) |
| 7859 | return err; |
| 7860 | } |
| 7861 | |
| 7862 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7863 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7864 | return -EINVAL; |
| 7865 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7866 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7867 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7868 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7869 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7870 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7871 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7872 | return -EINVAL; |
| 7873 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7874 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7875 | setup.beacon_interval = |
| 7876 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7877 | if (setup.beacon_interval < 10 || |
| 7878 | setup.beacon_interval > 10000) |
| 7879 | return -EINVAL; |
| 7880 | } |
| 7881 | |
| 7882 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7883 | setup.dtim_period = |
| 7884 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7885 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7886 | return -EINVAL; |
| 7887 | } |
| 7888 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7889 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7890 | /* parse additional setup parameters if given */ |
| 7891 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7892 | if (err) |
| 7893 | return err; |
| 7894 | } |
| 7895 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7896 | if (setup.user_mpm) |
| 7897 | cfg.auto_open_plinks = false; |
| 7898 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7899 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7900 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7901 | if (err) |
| 7902 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7903 | } else { |
| 7904 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7905 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7906 | } |
| 7907 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 7908 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7909 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7910 | int n_rates = |
| 7911 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7912 | struct ieee80211_supported_band *sband; |
| 7913 | |
| 7914 | if (!setup.chandef.chan) |
| 7915 | return -EINVAL; |
| 7916 | |
| 7917 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 7918 | |
| 7919 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7920 | &setup.basic_rates); |
| 7921 | if (err) |
| 7922 | return err; |
| 7923 | } |
| 7924 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7925 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7926 | } |
| 7927 | |
| 7928 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7929 | { |
| 7930 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7931 | struct net_device *dev = info->user_ptr[1]; |
| 7932 | |
| 7933 | return cfg80211_leave_mesh(rdev, dev); |
| 7934 | } |
| 7935 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7936 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7937 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7938 | struct cfg80211_registered_device *rdev) |
| 7939 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7940 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7941 | struct nlattr *nl_pats, *nl_pat; |
| 7942 | int i, pat_len; |
| 7943 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7944 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7945 | return 0; |
| 7946 | |
| 7947 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7948 | if (!nl_pats) |
| 7949 | return -ENOBUFS; |
| 7950 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7951 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7952 | nl_pat = nla_nest_start(msg, i + 1); |
| 7953 | if (!nl_pat) |
| 7954 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7955 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7956 | 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] | 7957 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7958 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 7959 | wowlan->patterns[i].pattern) || |
| 7960 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7961 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7962 | return -ENOBUFS; |
| 7963 | nla_nest_end(msg, nl_pat); |
| 7964 | } |
| 7965 | nla_nest_end(msg, nl_pats); |
| 7966 | |
| 7967 | return 0; |
| 7968 | } |
| 7969 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7970 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7971 | struct cfg80211_wowlan_tcp *tcp) |
| 7972 | { |
| 7973 | struct nlattr *nl_tcp; |
| 7974 | |
| 7975 | if (!tcp) |
| 7976 | return 0; |
| 7977 | |
| 7978 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7979 | if (!nl_tcp) |
| 7980 | return -ENOBUFS; |
| 7981 | |
| 7982 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7983 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7984 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7985 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7986 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7987 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7988 | tcp->payload_len, tcp->payload) || |
| 7989 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7990 | tcp->data_interval) || |
| 7991 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7992 | tcp->wake_len, tcp->wake_data) || |
| 7993 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7994 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7995 | return -ENOBUFS; |
| 7996 | |
| 7997 | if (tcp->payload_seq.len && |
| 7998 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7999 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8000 | return -ENOBUFS; |
| 8001 | |
| 8002 | if (tcp->payload_tok.len && |
| 8003 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8004 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8005 | &tcp->payload_tok)) |
| 8006 | return -ENOBUFS; |
| 8007 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8008 | nla_nest_end(msg, nl_tcp); |
| 8009 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8010 | return 0; |
| 8011 | } |
| 8012 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8013 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8014 | { |
| 8015 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8016 | struct sk_buff *msg; |
| 8017 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8018 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8019 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8020 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8021 | return -EOPNOTSUPP; |
| 8022 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8023 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8024 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8025 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8026 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8027 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8028 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8029 | } |
| 8030 | |
| 8031 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8032 | if (!msg) |
| 8033 | return -ENOMEM; |
| 8034 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8035 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8036 | NL80211_CMD_GET_WOWLAN); |
| 8037 | if (!hdr) |
| 8038 | goto nla_put_failure; |
| 8039 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8040 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8041 | struct nlattr *nl_wowlan; |
| 8042 | |
| 8043 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8044 | if (!nl_wowlan) |
| 8045 | goto nla_put_failure; |
| 8046 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8047 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8048 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8049 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8050 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8051 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8052 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8053 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8054 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8055 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8056 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8057 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8058 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8059 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8060 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8061 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8062 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8063 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8064 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8065 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8066 | if (nl80211_send_wowlan_tcp(msg, |
| 8067 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8068 | goto nla_put_failure; |
| 8069 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8070 | nla_nest_end(msg, nl_wowlan); |
| 8071 | } |
| 8072 | |
| 8073 | genlmsg_end(msg, hdr); |
| 8074 | return genlmsg_reply(msg, info); |
| 8075 | |
| 8076 | nla_put_failure: |
| 8077 | nlmsg_free(msg); |
| 8078 | return -ENOBUFS; |
| 8079 | } |
| 8080 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8081 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8082 | struct nlattr *attr, |
| 8083 | struct cfg80211_wowlan *trig) |
| 8084 | { |
| 8085 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8086 | struct cfg80211_wowlan_tcp *cfg; |
| 8087 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8088 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8089 | u32 size; |
| 8090 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8091 | int err, port; |
| 8092 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8093 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8094 | return -EINVAL; |
| 8095 | |
| 8096 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8097 | nla_data(attr), nla_len(attr), |
| 8098 | nl80211_wowlan_tcp_policy); |
| 8099 | if (err) |
| 8100 | return err; |
| 8101 | |
| 8102 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8103 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8104 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8105 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8106 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8107 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8108 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8109 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8110 | return -EINVAL; |
| 8111 | |
| 8112 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8113 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8114 | return -EINVAL; |
| 8115 | |
| 8116 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8117 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8118 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8119 | return -EINVAL; |
| 8120 | |
| 8121 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8122 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8123 | return -EINVAL; |
| 8124 | |
| 8125 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8126 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8127 | return -EINVAL; |
| 8128 | |
| 8129 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8130 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8131 | |
| 8132 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8133 | tokens_size = tokln - sizeof(*tok); |
| 8134 | |
| 8135 | if (!tok->len || tokens_size % tok->len) |
| 8136 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8137 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8138 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8139 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8140 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8141 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8142 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8143 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8144 | return -EINVAL; |
| 8145 | if (tok->offset + tok->len > data_size) |
| 8146 | return -EINVAL; |
| 8147 | } |
| 8148 | |
| 8149 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8150 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8151 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8152 | return -EINVAL; |
| 8153 | if (seq->len == 0 || seq->len > 4) |
| 8154 | return -EINVAL; |
| 8155 | if (seq->len + seq->offset > data_size) |
| 8156 | return -EINVAL; |
| 8157 | } |
| 8158 | |
| 8159 | size = sizeof(*cfg); |
| 8160 | size += data_size; |
| 8161 | size += wake_size + wake_mask_size; |
| 8162 | size += tokens_size; |
| 8163 | |
| 8164 | cfg = kzalloc(size, GFP_KERNEL); |
| 8165 | if (!cfg) |
| 8166 | return -ENOMEM; |
| 8167 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8168 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8169 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8170 | ETH_ALEN); |
| 8171 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8172 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8173 | else |
| 8174 | port = 0; |
| 8175 | #ifdef CONFIG_INET |
| 8176 | /* allocate a socket and port for it and use it */ |
| 8177 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8178 | IPPROTO_TCP, &cfg->sock, 1); |
| 8179 | if (err) { |
| 8180 | kfree(cfg); |
| 8181 | return err; |
| 8182 | } |
| 8183 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8184 | sock_release(cfg->sock); |
| 8185 | kfree(cfg); |
| 8186 | return -EADDRINUSE; |
| 8187 | } |
| 8188 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8189 | #else |
| 8190 | if (!port) { |
| 8191 | kfree(cfg); |
| 8192 | return -EINVAL; |
| 8193 | } |
| 8194 | cfg->src_port = port; |
| 8195 | #endif |
| 8196 | |
| 8197 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8198 | cfg->payload_len = data_size; |
| 8199 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8200 | memcpy((void *)cfg->payload, |
| 8201 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8202 | data_size); |
| 8203 | if (seq) |
| 8204 | cfg->payload_seq = *seq; |
| 8205 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8206 | cfg->wake_len = wake_size; |
| 8207 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8208 | memcpy((void *)cfg->wake_data, |
| 8209 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8210 | wake_size); |
| 8211 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8212 | data_size + wake_size; |
| 8213 | memcpy((void *)cfg->wake_mask, |
| 8214 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8215 | wake_mask_size); |
| 8216 | if (tok) { |
| 8217 | cfg->tokens_size = tokens_size; |
| 8218 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8219 | } |
| 8220 | |
| 8221 | trig->tcp = cfg; |
| 8222 | |
| 8223 | return 0; |
| 8224 | } |
| 8225 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8226 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8227 | { |
| 8228 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8229 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8230 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8231 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8232 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8233 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8234 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8235 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8236 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8237 | return -EOPNOTSUPP; |
| 8238 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8239 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8240 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8241 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8242 | goto set_wakeup; |
| 8243 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8244 | |
| 8245 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8246 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8247 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8248 | nl80211_wowlan_policy); |
| 8249 | if (err) |
| 8250 | return err; |
| 8251 | |
| 8252 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8253 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8254 | return -EINVAL; |
| 8255 | new_triggers.any = true; |
| 8256 | } |
| 8257 | |
| 8258 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8259 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8260 | return -EINVAL; |
| 8261 | new_triggers.disconnect = true; |
| 8262 | } |
| 8263 | |
| 8264 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8265 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8266 | return -EINVAL; |
| 8267 | new_triggers.magic_pkt = true; |
| 8268 | } |
| 8269 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8270 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8271 | return -EINVAL; |
| 8272 | |
| 8273 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8274 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8275 | return -EINVAL; |
| 8276 | new_triggers.gtk_rekey_failure = true; |
| 8277 | } |
| 8278 | |
| 8279 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8280 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8281 | return -EINVAL; |
| 8282 | new_triggers.eap_identity_req = true; |
| 8283 | } |
| 8284 | |
| 8285 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8286 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8287 | return -EINVAL; |
| 8288 | new_triggers.four_way_handshake = true; |
| 8289 | } |
| 8290 | |
| 8291 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8292 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8293 | return -EINVAL; |
| 8294 | new_triggers.rfkill_release = true; |
| 8295 | } |
| 8296 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8297 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8298 | struct nlattr *pat; |
| 8299 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8300 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8301 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8302 | |
| 8303 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8304 | rem) |
| 8305 | n_patterns++; |
| 8306 | if (n_patterns > wowlan->n_patterns) |
| 8307 | return -EINVAL; |
| 8308 | |
| 8309 | new_triggers.patterns = kcalloc(n_patterns, |
| 8310 | sizeof(new_triggers.patterns[0]), |
| 8311 | GFP_KERNEL); |
| 8312 | if (!new_triggers.patterns) |
| 8313 | return -ENOMEM; |
| 8314 | |
| 8315 | new_triggers.n_patterns = n_patterns; |
| 8316 | i = 0; |
| 8317 | |
| 8318 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8319 | rem) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8320 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8321 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8322 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8323 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8324 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8325 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8326 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8327 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8328 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8329 | goto error; |
| 8330 | if (pat_len > wowlan->pattern_max_len || |
| 8331 | pat_len < wowlan->pattern_min_len) |
| 8332 | goto error; |
| 8333 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8334 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8335 | pkt_offset = 0; |
| 8336 | else |
| 8337 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8338 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8339 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8340 | goto error; |
| 8341 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8342 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8343 | new_triggers.patterns[i].mask = |
| 8344 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8345 | if (!new_triggers.patterns[i].mask) { |
| 8346 | err = -ENOMEM; |
| 8347 | goto error; |
| 8348 | } |
| 8349 | new_triggers.patterns[i].pattern = |
| 8350 | new_triggers.patterns[i].mask + mask_len; |
| 8351 | memcpy(new_triggers.patterns[i].mask, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8352 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8353 | mask_len); |
| 8354 | new_triggers.patterns[i].pattern_len = pat_len; |
| 8355 | memcpy(new_triggers.patterns[i].pattern, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8356 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8357 | pat_len); |
| 8358 | i++; |
| 8359 | } |
| 8360 | } |
| 8361 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8362 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8363 | err = nl80211_parse_wowlan_tcp( |
| 8364 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8365 | &new_triggers); |
| 8366 | if (err) |
| 8367 | goto error; |
| 8368 | } |
| 8369 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8370 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8371 | if (!ntrig) { |
| 8372 | err = -ENOMEM; |
| 8373 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8374 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8375 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8376 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8377 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8378 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8379 | if (rdev->ops->set_wakeup && |
| 8380 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8381 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8382 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8383 | return 0; |
| 8384 | error: |
| 8385 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8386 | kfree(new_triggers.patterns[i].mask); |
| 8387 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8388 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8389 | sock_release(new_triggers.tcp->sock); |
| 8390 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8391 | return err; |
| 8392 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8393 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8394 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8395 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8396 | struct cfg80211_registered_device *rdev) |
| 8397 | { |
| 8398 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8399 | int i, j, pat_len; |
| 8400 | struct cfg80211_coalesce_rules *rule; |
| 8401 | |
| 8402 | if (!rdev->coalesce->n_rules) |
| 8403 | return 0; |
| 8404 | |
| 8405 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8406 | if (!nl_rules) |
| 8407 | return -ENOBUFS; |
| 8408 | |
| 8409 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8410 | nl_rule = nla_nest_start(msg, i + 1); |
| 8411 | if (!nl_rule) |
| 8412 | return -ENOBUFS; |
| 8413 | |
| 8414 | rule = &rdev->coalesce->rules[i]; |
| 8415 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8416 | rule->delay)) |
| 8417 | return -ENOBUFS; |
| 8418 | |
| 8419 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8420 | rule->condition)) |
| 8421 | return -ENOBUFS; |
| 8422 | |
| 8423 | nl_pats = nla_nest_start(msg, |
| 8424 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8425 | if (!nl_pats) |
| 8426 | return -ENOBUFS; |
| 8427 | |
| 8428 | for (j = 0; j < rule->n_patterns; j++) { |
| 8429 | nl_pat = nla_nest_start(msg, j + 1); |
| 8430 | if (!nl_pat) |
| 8431 | return -ENOBUFS; |
| 8432 | pat_len = rule->patterns[j].pattern_len; |
| 8433 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8434 | DIV_ROUND_UP(pat_len, 8), |
| 8435 | rule->patterns[j].mask) || |
| 8436 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8437 | rule->patterns[j].pattern) || |
| 8438 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8439 | rule->patterns[j].pkt_offset)) |
| 8440 | return -ENOBUFS; |
| 8441 | nla_nest_end(msg, nl_pat); |
| 8442 | } |
| 8443 | nla_nest_end(msg, nl_pats); |
| 8444 | nla_nest_end(msg, nl_rule); |
| 8445 | } |
| 8446 | nla_nest_end(msg, nl_rules); |
| 8447 | |
| 8448 | return 0; |
| 8449 | } |
| 8450 | |
| 8451 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8452 | { |
| 8453 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8454 | struct sk_buff *msg; |
| 8455 | void *hdr; |
| 8456 | |
| 8457 | if (!rdev->wiphy.coalesce) |
| 8458 | return -EOPNOTSUPP; |
| 8459 | |
| 8460 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8461 | if (!msg) |
| 8462 | return -ENOMEM; |
| 8463 | |
| 8464 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8465 | NL80211_CMD_GET_COALESCE); |
| 8466 | if (!hdr) |
| 8467 | goto nla_put_failure; |
| 8468 | |
| 8469 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8470 | goto nla_put_failure; |
| 8471 | |
| 8472 | genlmsg_end(msg, hdr); |
| 8473 | return genlmsg_reply(msg, info); |
| 8474 | |
| 8475 | nla_put_failure: |
| 8476 | nlmsg_free(msg); |
| 8477 | return -ENOBUFS; |
| 8478 | } |
| 8479 | |
| 8480 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8481 | { |
| 8482 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8483 | int i, j; |
| 8484 | struct cfg80211_coalesce_rules *rule; |
| 8485 | |
| 8486 | if (!coalesce) |
| 8487 | return; |
| 8488 | |
| 8489 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8490 | rule = &coalesce->rules[i]; |
| 8491 | for (j = 0; j < rule->n_patterns; j++) |
| 8492 | kfree(rule->patterns[j].mask); |
| 8493 | kfree(rule->patterns); |
| 8494 | } |
| 8495 | kfree(coalesce->rules); |
| 8496 | kfree(coalesce); |
| 8497 | rdev->coalesce = NULL; |
| 8498 | } |
| 8499 | |
| 8500 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8501 | struct nlattr *rule, |
| 8502 | struct cfg80211_coalesce_rules *new_rule) |
| 8503 | { |
| 8504 | int err, i; |
| 8505 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8506 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8507 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8508 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8509 | |
| 8510 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8511 | nla_len(rule), nl80211_coalesce_policy); |
| 8512 | if (err) |
| 8513 | return err; |
| 8514 | |
| 8515 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8516 | new_rule->delay = |
| 8517 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8518 | if (new_rule->delay > coalesce->max_delay) |
| 8519 | return -EINVAL; |
| 8520 | |
| 8521 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8522 | new_rule->condition = |
| 8523 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8524 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8525 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8526 | return -EINVAL; |
| 8527 | |
| 8528 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8529 | return -EINVAL; |
| 8530 | |
| 8531 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8532 | rem) |
| 8533 | n_patterns++; |
| 8534 | if (n_patterns > coalesce->n_patterns) |
| 8535 | return -EINVAL; |
| 8536 | |
| 8537 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8538 | GFP_KERNEL); |
| 8539 | if (!new_rule->patterns) |
| 8540 | return -ENOMEM; |
| 8541 | |
| 8542 | new_rule->n_patterns = n_patterns; |
| 8543 | i = 0; |
| 8544 | |
| 8545 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8546 | rem) { |
| 8547 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8548 | nla_len(pat), NULL); |
| 8549 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8550 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8551 | return -EINVAL; |
| 8552 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8553 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8554 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8555 | return -EINVAL; |
| 8556 | if (pat_len > coalesce->pattern_max_len || |
| 8557 | pat_len < coalesce->pattern_min_len) |
| 8558 | return -EINVAL; |
| 8559 | |
| 8560 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8561 | pkt_offset = 0; |
| 8562 | else |
| 8563 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8564 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8565 | return -EINVAL; |
| 8566 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8567 | |
| 8568 | new_rule->patterns[i].mask = |
| 8569 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8570 | if (!new_rule->patterns[i].mask) |
| 8571 | return -ENOMEM; |
| 8572 | new_rule->patterns[i].pattern = |
| 8573 | new_rule->patterns[i].mask + mask_len; |
| 8574 | memcpy(new_rule->patterns[i].mask, |
| 8575 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); |
| 8576 | new_rule->patterns[i].pattern_len = pat_len; |
| 8577 | memcpy(new_rule->patterns[i].pattern, |
| 8578 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); |
| 8579 | i++; |
| 8580 | } |
| 8581 | |
| 8582 | return 0; |
| 8583 | } |
| 8584 | |
| 8585 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8586 | { |
| 8587 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8588 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8589 | struct cfg80211_coalesce new_coalesce = {}; |
| 8590 | struct cfg80211_coalesce *n_coalesce; |
| 8591 | int err, rem_rule, n_rules = 0, i, j; |
| 8592 | struct nlattr *rule; |
| 8593 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8594 | |
| 8595 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8596 | return -EOPNOTSUPP; |
| 8597 | |
| 8598 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8599 | cfg80211_rdev_free_coalesce(rdev); |
| 8600 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8601 | return 0; |
| 8602 | } |
| 8603 | |
| 8604 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8605 | rem_rule) |
| 8606 | n_rules++; |
| 8607 | if (n_rules > coalesce->n_rules) |
| 8608 | return -EINVAL; |
| 8609 | |
| 8610 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8611 | GFP_KERNEL); |
| 8612 | if (!new_coalesce.rules) |
| 8613 | return -ENOMEM; |
| 8614 | |
| 8615 | new_coalesce.n_rules = n_rules; |
| 8616 | i = 0; |
| 8617 | |
| 8618 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8619 | rem_rule) { |
| 8620 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8621 | &new_coalesce.rules[i]); |
| 8622 | if (err) |
| 8623 | goto error; |
| 8624 | |
| 8625 | i++; |
| 8626 | } |
| 8627 | |
| 8628 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8629 | if (err) |
| 8630 | goto error; |
| 8631 | |
| 8632 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8633 | if (!n_coalesce) { |
| 8634 | err = -ENOMEM; |
| 8635 | goto error; |
| 8636 | } |
| 8637 | cfg80211_rdev_free_coalesce(rdev); |
| 8638 | rdev->coalesce = n_coalesce; |
| 8639 | |
| 8640 | return 0; |
| 8641 | error: |
| 8642 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8643 | tmp_rule = &new_coalesce.rules[i]; |
| 8644 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8645 | kfree(tmp_rule->patterns[j].mask); |
| 8646 | kfree(tmp_rule->patterns); |
| 8647 | } |
| 8648 | kfree(new_coalesce.rules); |
| 8649 | |
| 8650 | return err; |
| 8651 | } |
| 8652 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8653 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8654 | { |
| 8655 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8656 | struct net_device *dev = info->user_ptr[1]; |
| 8657 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8658 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8659 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8660 | int err; |
| 8661 | |
| 8662 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8663 | return -EINVAL; |
| 8664 | |
| 8665 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8666 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8667 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8668 | nl80211_rekey_policy); |
| 8669 | if (err) |
| 8670 | return err; |
| 8671 | |
| 8672 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8673 | return -ERANGE; |
| 8674 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8675 | return -ERANGE; |
| 8676 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8677 | return -ERANGE; |
| 8678 | |
| 8679 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8680 | NL80211_KEK_LEN); |
| 8681 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8682 | NL80211_KCK_LEN); |
| 8683 | memcpy(rekey_data.replay_ctr, |
| 8684 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8685 | NL80211_REPLAY_CTR_LEN); |
| 8686 | |
| 8687 | wdev_lock(wdev); |
| 8688 | if (!wdev->current_bss) { |
| 8689 | err = -ENOTCONN; |
| 8690 | goto out; |
| 8691 | } |
| 8692 | |
| 8693 | if (!rdev->ops->set_rekey_data) { |
| 8694 | err = -EOPNOTSUPP; |
| 8695 | goto out; |
| 8696 | } |
| 8697 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8698 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8699 | out: |
| 8700 | wdev_unlock(wdev); |
| 8701 | return err; |
| 8702 | } |
| 8703 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8704 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8705 | struct genl_info *info) |
| 8706 | { |
| 8707 | struct net_device *dev = info->user_ptr[1]; |
| 8708 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8709 | |
| 8710 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8711 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8712 | return -EINVAL; |
| 8713 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8714 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8715 | return -EBUSY; |
| 8716 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8717 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8718 | return 0; |
| 8719 | } |
| 8720 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8721 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8722 | struct genl_info *info) |
| 8723 | { |
| 8724 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8725 | struct net_device *dev = info->user_ptr[1]; |
| 8726 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8727 | struct sk_buff *msg; |
| 8728 | void *hdr; |
| 8729 | const u8 *addr; |
| 8730 | u64 cookie; |
| 8731 | int err; |
| 8732 | |
| 8733 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8734 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8735 | return -EOPNOTSUPP; |
| 8736 | |
| 8737 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8738 | return -EINVAL; |
| 8739 | |
| 8740 | if (!rdev->ops->probe_client) |
| 8741 | return -EOPNOTSUPP; |
| 8742 | |
| 8743 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8744 | if (!msg) |
| 8745 | return -ENOMEM; |
| 8746 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8747 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8748 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8749 | if (!hdr) { |
| 8750 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8751 | goto free_msg; |
| 8752 | } |
| 8753 | |
| 8754 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8755 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8756 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8757 | if (err) |
| 8758 | goto free_msg; |
| 8759 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8760 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8761 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8762 | |
| 8763 | genlmsg_end(msg, hdr); |
| 8764 | |
| 8765 | return genlmsg_reply(msg, info); |
| 8766 | |
| 8767 | nla_put_failure: |
| 8768 | err = -ENOBUFS; |
| 8769 | free_msg: |
| 8770 | nlmsg_free(msg); |
| 8771 | return err; |
| 8772 | } |
| 8773 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8774 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8775 | { |
| 8776 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8777 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8778 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8779 | |
| 8780 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8781 | return -EOPNOTSUPP; |
| 8782 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8783 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8784 | if (!nreg) |
| 8785 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8786 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8787 | /* First, check if already registered. */ |
| 8788 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8789 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8790 | if (reg->nlportid == info->snd_portid) { |
| 8791 | rv = -EALREADY; |
| 8792 | goto out_err; |
| 8793 | } |
| 8794 | } |
| 8795 | /* Add it to the list */ |
| 8796 | nreg->nlportid = info->snd_portid; |
| 8797 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8798 | |
| 8799 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8800 | |
| 8801 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8802 | out_err: |
| 8803 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8804 | kfree(nreg); |
| 8805 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8806 | } |
| 8807 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8808 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8809 | { |
| 8810 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8811 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8812 | int err; |
| 8813 | |
| 8814 | if (!rdev->ops->start_p2p_device) |
| 8815 | return -EOPNOTSUPP; |
| 8816 | |
| 8817 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8818 | return -EOPNOTSUPP; |
| 8819 | |
| 8820 | if (wdev->p2p_started) |
| 8821 | return 0; |
| 8822 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8823 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8824 | if (err) |
| 8825 | return err; |
| 8826 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8827 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8828 | if (err) |
| 8829 | return err; |
| 8830 | |
| 8831 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8832 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8833 | |
| 8834 | return 0; |
| 8835 | } |
| 8836 | |
| 8837 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8838 | { |
| 8839 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8840 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8841 | |
| 8842 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8843 | return -EOPNOTSUPP; |
| 8844 | |
| 8845 | if (!rdev->ops->stop_p2p_device) |
| 8846 | return -EOPNOTSUPP; |
| 8847 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8848 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8849 | |
| 8850 | return 0; |
| 8851 | } |
| 8852 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8853 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8854 | struct genl_info *info) |
| 8855 | { |
| 8856 | void *hdr; |
| 8857 | struct sk_buff *msg; |
| 8858 | |
| 8859 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8860 | if (!msg) |
| 8861 | return -ENOMEM; |
| 8862 | |
| 8863 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8864 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8865 | if (!hdr) |
| 8866 | goto nla_put_failure; |
| 8867 | |
| 8868 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8869 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8870 | goto nla_put_failure; |
| 8871 | |
| 8872 | genlmsg_end(msg, hdr); |
| 8873 | return genlmsg_reply(msg, info); |
| 8874 | |
| 8875 | nla_put_failure: |
| 8876 | kfree_skb(msg); |
| 8877 | return -ENOBUFS; |
| 8878 | } |
| 8879 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8880 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8881 | { |
| 8882 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8883 | struct cfg80211_update_ft_ies_params ft_params; |
| 8884 | struct net_device *dev = info->user_ptr[1]; |
| 8885 | |
| 8886 | if (!rdev->ops->update_ft_ies) |
| 8887 | return -EOPNOTSUPP; |
| 8888 | |
| 8889 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8890 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8891 | return -EINVAL; |
| 8892 | |
| 8893 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8894 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8895 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8896 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8897 | |
| 8898 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8899 | } |
| 8900 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8901 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8902 | struct genl_info *info) |
| 8903 | { |
| 8904 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8905 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8906 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8907 | u16 duration; |
| 8908 | int ret; |
| 8909 | |
| 8910 | if (!rdev->ops->crit_proto_start) |
| 8911 | return -EOPNOTSUPP; |
| 8912 | |
| 8913 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8914 | return -EINVAL; |
| 8915 | |
| 8916 | if (rdev->crit_proto_nlportid) |
| 8917 | return -EBUSY; |
| 8918 | |
| 8919 | /* determine protocol if provided */ |
| 8920 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8921 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8922 | |
| 8923 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8924 | return -EINVAL; |
| 8925 | |
| 8926 | /* timeout must be provided */ |
| 8927 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8928 | return -EINVAL; |
| 8929 | |
| 8930 | duration = |
| 8931 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8932 | |
| 8933 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8934 | return -ERANGE; |
| 8935 | |
| 8936 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 8937 | if (!ret) |
| 8938 | rdev->crit_proto_nlportid = info->snd_portid; |
| 8939 | |
| 8940 | return ret; |
| 8941 | } |
| 8942 | |
| 8943 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 8944 | struct genl_info *info) |
| 8945 | { |
| 8946 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8947 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8948 | |
| 8949 | if (!rdev->ops->crit_proto_stop) |
| 8950 | return -EOPNOTSUPP; |
| 8951 | |
| 8952 | if (rdev->crit_proto_nlportid) { |
| 8953 | rdev->crit_proto_nlportid = 0; |
| 8954 | rdev_crit_proto_stop(rdev, wdev); |
| 8955 | } |
| 8956 | return 0; |
| 8957 | } |
| 8958 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8959 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 8960 | { |
| 8961 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8962 | struct wireless_dev *wdev = |
| 8963 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 8964 | int i, err; |
| 8965 | u32 vid, subcmd; |
| 8966 | |
| 8967 | if (!rdev->wiphy.vendor_commands) |
| 8968 | return -EOPNOTSUPP; |
| 8969 | |
| 8970 | if (IS_ERR(wdev)) { |
| 8971 | err = PTR_ERR(wdev); |
| 8972 | if (err != -EINVAL) |
| 8973 | return err; |
| 8974 | wdev = NULL; |
| 8975 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 8976 | return -EINVAL; |
| 8977 | } |
| 8978 | |
| 8979 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 8980 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 8981 | return -EINVAL; |
| 8982 | |
| 8983 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 8984 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 8985 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 8986 | const struct wiphy_vendor_command *vcmd; |
| 8987 | void *data = NULL; |
| 8988 | int len = 0; |
| 8989 | |
| 8990 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 8991 | |
| 8992 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 8993 | continue; |
| 8994 | |
| 8995 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 8996 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 8997 | if (!wdev) |
| 8998 | return -EINVAL; |
| 8999 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9000 | !wdev->netdev) |
| 9001 | return -EINVAL; |
| 9002 | |
| 9003 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9004 | if (wdev->netdev && |
| 9005 | !netif_running(wdev->netdev)) |
| 9006 | return -ENETDOWN; |
| 9007 | if (!wdev->netdev && !wdev->p2p_started) |
| 9008 | return -ENETDOWN; |
| 9009 | } |
| 9010 | } else { |
| 9011 | wdev = NULL; |
| 9012 | } |
| 9013 | |
| 9014 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9015 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9016 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9017 | } |
| 9018 | |
| 9019 | rdev->cur_cmd_info = info; |
| 9020 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9021 | data, len); |
| 9022 | rdev->cur_cmd_info = NULL; |
| 9023 | return err; |
| 9024 | } |
| 9025 | |
| 9026 | return -EOPNOTSUPP; |
| 9027 | } |
| 9028 | |
| 9029 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9030 | enum nl80211_commands cmd, |
| 9031 | enum nl80211_attrs attr, |
| 9032 | int approxlen) |
| 9033 | { |
| 9034 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9035 | |
| 9036 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9037 | return NULL; |
| 9038 | |
| 9039 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, |
| 9040 | rdev->cur_cmd_info->snd_portid, |
| 9041 | rdev->cur_cmd_info->snd_seq, |
| 9042 | cmd, attr, GFP_KERNEL); |
| 9043 | } |
| 9044 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9045 | |
| 9046 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9047 | { |
| 9048 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9049 | void *hdr = ((void **)skb->cb)[1]; |
| 9050 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9051 | |
| 9052 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9053 | kfree_skb(skb); |
| 9054 | return -EINVAL; |
| 9055 | } |
| 9056 | |
| 9057 | nla_nest_end(skb, data); |
| 9058 | genlmsg_end(skb, hdr); |
| 9059 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9060 | } |
| 9061 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9062 | |
| 9063 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9064 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 9065 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 9066 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9067 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 9068 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 9069 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9070 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9071 | /* 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] | 9072 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 9073 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9074 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9075 | 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] | 9076 | struct genl_info *info) |
| 9077 | { |
| 9078 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9079 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9080 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9081 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 9082 | |
| 9083 | if (rtnl) |
| 9084 | rtnl_lock(); |
| 9085 | |
| 9086 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 9087 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9088 | if (IS_ERR(rdev)) { |
| 9089 | if (rtnl) |
| 9090 | rtnl_unlock(); |
| 9091 | return PTR_ERR(rdev); |
| 9092 | } |
| 9093 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9094 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 9095 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9096 | ASSERT_RTNL(); |
| 9097 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9098 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 9099 | info->attrs); |
| 9100 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9101 | if (rtnl) |
| 9102 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9103 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9104 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9105 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9106 | dev = wdev->netdev; |
| 9107 | rdev = wiphy_to_dev(wdev->wiphy); |
| 9108 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9109 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 9110 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9111 | if (rtnl) |
| 9112 | rtnl_unlock(); |
| 9113 | return -EINVAL; |
| 9114 | } |
| 9115 | |
| 9116 | info->user_ptr[1] = dev; |
| 9117 | } else { |
| 9118 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9119 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9120 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9121 | if (dev) { |
| 9122 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 9123 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9124 | if (rtnl) |
| 9125 | rtnl_unlock(); |
| 9126 | return -ENETDOWN; |
| 9127 | } |
| 9128 | |
| 9129 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9130 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 9131 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9132 | if (rtnl) |
| 9133 | rtnl_unlock(); |
| 9134 | return -ENETDOWN; |
| 9135 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9136 | } |
| 9137 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9138 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9139 | } |
| 9140 | |
| 9141 | return 0; |
| 9142 | } |
| 9143 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9144 | 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] | 9145 | struct genl_info *info) |
| 9146 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9147 | if (info->user_ptr[1]) { |
| 9148 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 9149 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9150 | |
| 9151 | if (wdev->netdev) |
| 9152 | dev_put(wdev->netdev); |
| 9153 | } else { |
| 9154 | dev_put(info->user_ptr[1]); |
| 9155 | } |
| 9156 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9157 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 9158 | rtnl_unlock(); |
| 9159 | } |
| 9160 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 9161 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9162 | { |
| 9163 | .cmd = NL80211_CMD_GET_WIPHY, |
| 9164 | .doit = nl80211_get_wiphy, |
| 9165 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9166 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9167 | .policy = nl80211_policy, |
| 9168 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9169 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9170 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9171 | }, |
| 9172 | { |
| 9173 | .cmd = NL80211_CMD_SET_WIPHY, |
| 9174 | .doit = nl80211_set_wiphy, |
| 9175 | .policy = nl80211_policy, |
| 9176 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9177 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9178 | }, |
| 9179 | { |
| 9180 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 9181 | .doit = nl80211_get_interface, |
| 9182 | .dumpit = nl80211_dump_interface, |
| 9183 | .policy = nl80211_policy, |
| 9184 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9185 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9186 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9187 | }, |
| 9188 | { |
| 9189 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 9190 | .doit = nl80211_set_interface, |
| 9191 | .policy = nl80211_policy, |
| 9192 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9193 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9194 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9195 | }, |
| 9196 | { |
| 9197 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 9198 | .doit = nl80211_new_interface, |
| 9199 | .policy = nl80211_policy, |
| 9200 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9201 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9202 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9203 | }, |
| 9204 | { |
| 9205 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 9206 | .doit = nl80211_del_interface, |
| 9207 | .policy = nl80211_policy, |
| 9208 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 9209 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9210 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9211 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9212 | { |
| 9213 | .cmd = NL80211_CMD_GET_KEY, |
| 9214 | .doit = nl80211_get_key, |
| 9215 | .policy = nl80211_policy, |
| 9216 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9217 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9218 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9219 | }, |
| 9220 | { |
| 9221 | .cmd = NL80211_CMD_SET_KEY, |
| 9222 | .doit = nl80211_set_key, |
| 9223 | .policy = nl80211_policy, |
| 9224 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9225 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9226 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9227 | }, |
| 9228 | { |
| 9229 | .cmd = NL80211_CMD_NEW_KEY, |
| 9230 | .doit = nl80211_new_key, |
| 9231 | .policy = nl80211_policy, |
| 9232 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9233 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9234 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9235 | }, |
| 9236 | { |
| 9237 | .cmd = NL80211_CMD_DEL_KEY, |
| 9238 | .doit = nl80211_del_key, |
| 9239 | .policy = nl80211_policy, |
| 9240 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9241 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9242 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9243 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9244 | { |
| 9245 | .cmd = NL80211_CMD_SET_BEACON, |
| 9246 | .policy = nl80211_policy, |
| 9247 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9248 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9249 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9250 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9251 | }, |
| 9252 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9253 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9254 | .policy = nl80211_policy, |
| 9255 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9256 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9257 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9258 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9259 | }, |
| 9260 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9261 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9262 | .policy = nl80211_policy, |
| 9263 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9264 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9265 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9266 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9267 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9268 | { |
| 9269 | .cmd = NL80211_CMD_GET_STATION, |
| 9270 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9271 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9272 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9273 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9274 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9275 | }, |
| 9276 | { |
| 9277 | .cmd = NL80211_CMD_SET_STATION, |
| 9278 | .doit = nl80211_set_station, |
| 9279 | .policy = nl80211_policy, |
| 9280 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9281 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9282 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9283 | }, |
| 9284 | { |
| 9285 | .cmd = NL80211_CMD_NEW_STATION, |
| 9286 | .doit = nl80211_new_station, |
| 9287 | .policy = nl80211_policy, |
| 9288 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9289 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9290 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9291 | }, |
| 9292 | { |
| 9293 | .cmd = NL80211_CMD_DEL_STATION, |
| 9294 | .doit = nl80211_del_station, |
| 9295 | .policy = nl80211_policy, |
| 9296 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9297 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9298 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9299 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9300 | { |
| 9301 | .cmd = NL80211_CMD_GET_MPATH, |
| 9302 | .doit = nl80211_get_mpath, |
| 9303 | .dumpit = nl80211_dump_mpath, |
| 9304 | .policy = nl80211_policy, |
| 9305 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9306 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9307 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9308 | }, |
| 9309 | { |
| 9310 | .cmd = NL80211_CMD_SET_MPATH, |
| 9311 | .doit = nl80211_set_mpath, |
| 9312 | .policy = nl80211_policy, |
| 9313 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9314 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9315 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9316 | }, |
| 9317 | { |
| 9318 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9319 | .doit = nl80211_new_mpath, |
| 9320 | .policy = nl80211_policy, |
| 9321 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9322 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9323 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9324 | }, |
| 9325 | { |
| 9326 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9327 | .doit = nl80211_del_mpath, |
| 9328 | .policy = nl80211_policy, |
| 9329 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9330 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9331 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9332 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9333 | { |
| 9334 | .cmd = NL80211_CMD_SET_BSS, |
| 9335 | .doit = nl80211_set_bss, |
| 9336 | .policy = nl80211_policy, |
| 9337 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9338 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9339 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9340 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9341 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9342 | .cmd = NL80211_CMD_GET_REG, |
| 9343 | .doit = nl80211_get_reg, |
| 9344 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9345 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9346 | /* can be retrieved by unprivileged users */ |
| 9347 | }, |
| 9348 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9349 | .cmd = NL80211_CMD_SET_REG, |
| 9350 | .doit = nl80211_set_reg, |
| 9351 | .policy = nl80211_policy, |
| 9352 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9353 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9354 | }, |
| 9355 | { |
| 9356 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9357 | .doit = nl80211_req_set_reg, |
| 9358 | .policy = nl80211_policy, |
| 9359 | .flags = GENL_ADMIN_PERM, |
| 9360 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9361 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9362 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9363 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9364 | .policy = nl80211_policy, |
| 9365 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +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, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9368 | }, |
| 9369 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9370 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9371 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9372 | .policy = nl80211_policy, |
| 9373 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [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, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9376 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9377 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9378 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9379 | .doit = nl80211_trigger_scan, |
| 9380 | .policy = nl80211_policy, |
| 9381 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9382 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9383 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9384 | }, |
| 9385 | { |
| 9386 | .cmd = NL80211_CMD_GET_SCAN, |
| 9387 | .policy = nl80211_policy, |
| 9388 | .dumpit = nl80211_dump_scan, |
| 9389 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9390 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9391 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9392 | .doit = nl80211_start_sched_scan, |
| 9393 | .policy = nl80211_policy, |
| 9394 | .flags = GENL_ADMIN_PERM, |
| 9395 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9396 | NL80211_FLAG_NEED_RTNL, |
| 9397 | }, |
| 9398 | { |
| 9399 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9400 | .doit = nl80211_stop_sched_scan, |
| 9401 | .policy = nl80211_policy, |
| 9402 | .flags = GENL_ADMIN_PERM, |
| 9403 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9404 | NL80211_FLAG_NEED_RTNL, |
| 9405 | }, |
| 9406 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9407 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9408 | .doit = nl80211_authenticate, |
| 9409 | .policy = nl80211_policy, |
| 9410 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9411 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9412 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9413 | }, |
| 9414 | { |
| 9415 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9416 | .doit = nl80211_associate, |
| 9417 | .policy = nl80211_policy, |
| 9418 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9419 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9420 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9421 | }, |
| 9422 | { |
| 9423 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9424 | .doit = nl80211_deauthenticate, |
| 9425 | .policy = nl80211_policy, |
| 9426 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9427 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9428 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9429 | }, |
| 9430 | { |
| 9431 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9432 | .doit = nl80211_disassociate, |
| 9433 | .policy = nl80211_policy, |
| 9434 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9435 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9436 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9437 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9438 | { |
| 9439 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9440 | .doit = nl80211_join_ibss, |
| 9441 | .policy = nl80211_policy, |
| 9442 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9443 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9444 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9445 | }, |
| 9446 | { |
| 9447 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9448 | .doit = nl80211_leave_ibss, |
| 9449 | .policy = nl80211_policy, |
| 9450 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9451 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9452 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9453 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9454 | #ifdef CONFIG_NL80211_TESTMODE |
| 9455 | { |
| 9456 | .cmd = NL80211_CMD_TESTMODE, |
| 9457 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9458 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9459 | .policy = nl80211_policy, |
| 9460 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9461 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9462 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9463 | }, |
| 9464 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9465 | { |
| 9466 | .cmd = NL80211_CMD_CONNECT, |
| 9467 | .doit = nl80211_connect, |
| 9468 | .policy = nl80211_policy, |
| 9469 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9470 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9471 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9472 | }, |
| 9473 | { |
| 9474 | .cmd = NL80211_CMD_DISCONNECT, |
| 9475 | .doit = nl80211_disconnect, |
| 9476 | .policy = nl80211_policy, |
| 9477 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9478 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9479 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9480 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9481 | { |
| 9482 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9483 | .doit = nl80211_wiphy_netns, |
| 9484 | .policy = nl80211_policy, |
| 9485 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9486 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9487 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9488 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9489 | { |
| 9490 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9491 | .policy = nl80211_policy, |
| 9492 | .dumpit = nl80211_dump_survey, |
| 9493 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9494 | { |
| 9495 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9496 | .doit = nl80211_setdel_pmksa, |
| 9497 | .policy = nl80211_policy, |
| 9498 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [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, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9501 | }, |
| 9502 | { |
| 9503 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9504 | .doit = nl80211_setdel_pmksa, |
| 9505 | .policy = nl80211_policy, |
| 9506 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9507 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9508 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9509 | }, |
| 9510 | { |
| 9511 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9512 | .doit = nl80211_flush_pmksa, |
| 9513 | .policy = nl80211_policy, |
| 9514 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9515 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9516 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9517 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9518 | { |
| 9519 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9520 | .doit = nl80211_remain_on_channel, |
| 9521 | .policy = nl80211_policy, |
| 9522 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9523 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9524 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9525 | }, |
| 9526 | { |
| 9527 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9528 | .doit = nl80211_cancel_remain_on_channel, |
| 9529 | .policy = nl80211_policy, |
| 9530 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9531 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9532 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9533 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9534 | { |
| 9535 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9536 | .doit = nl80211_set_tx_bitrate_mask, |
| 9537 | .policy = nl80211_policy, |
| 9538 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9539 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9540 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9541 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9542 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9543 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9544 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9545 | .policy = nl80211_policy, |
| 9546 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9547 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9548 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9549 | }, |
| 9550 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9551 | .cmd = NL80211_CMD_FRAME, |
| 9552 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9553 | .policy = nl80211_policy, |
| 9554 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9555 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9556 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9557 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9558 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9559 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9560 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9561 | .policy = nl80211_policy, |
| 9562 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9563 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9564 | NL80211_FLAG_NEED_RTNL, |
| 9565 | }, |
| 9566 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9567 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9568 | .doit = nl80211_set_power_save, |
| 9569 | .policy = nl80211_policy, |
| 9570 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9571 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9572 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9573 | }, |
| 9574 | { |
| 9575 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9576 | .doit = nl80211_get_power_save, |
| 9577 | .policy = nl80211_policy, |
| 9578 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9579 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9580 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9581 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9582 | { |
| 9583 | .cmd = NL80211_CMD_SET_CQM, |
| 9584 | .doit = nl80211_set_cqm, |
| 9585 | .policy = nl80211_policy, |
| 9586 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9587 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9588 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9589 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9590 | { |
| 9591 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9592 | .doit = nl80211_set_channel, |
| 9593 | .policy = nl80211_policy, |
| 9594 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9595 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9596 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9597 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9598 | { |
| 9599 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9600 | .doit = nl80211_set_wds_peer, |
| 9601 | .policy = nl80211_policy, |
| 9602 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9603 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9604 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9605 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9606 | { |
| 9607 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9608 | .doit = nl80211_join_mesh, |
| 9609 | .policy = nl80211_policy, |
| 9610 | .flags = GENL_ADMIN_PERM, |
| 9611 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9612 | NL80211_FLAG_NEED_RTNL, |
| 9613 | }, |
| 9614 | { |
| 9615 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9616 | .doit = nl80211_leave_mesh, |
| 9617 | .policy = nl80211_policy, |
| 9618 | .flags = GENL_ADMIN_PERM, |
| 9619 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9620 | NL80211_FLAG_NEED_RTNL, |
| 9621 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9622 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9623 | { |
| 9624 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9625 | .doit = nl80211_get_wowlan, |
| 9626 | .policy = nl80211_policy, |
| 9627 | /* can be retrieved by unprivileged users */ |
| 9628 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9629 | NL80211_FLAG_NEED_RTNL, |
| 9630 | }, |
| 9631 | { |
| 9632 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9633 | .doit = nl80211_set_wowlan, |
| 9634 | .policy = nl80211_policy, |
| 9635 | .flags = GENL_ADMIN_PERM, |
| 9636 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9637 | NL80211_FLAG_NEED_RTNL, |
| 9638 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9639 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9640 | { |
| 9641 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9642 | .doit = nl80211_set_rekey_data, |
| 9643 | .policy = nl80211_policy, |
| 9644 | .flags = GENL_ADMIN_PERM, |
| 9645 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9646 | NL80211_FLAG_NEED_RTNL, |
| 9647 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9648 | { |
| 9649 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9650 | .doit = nl80211_tdls_mgmt, |
| 9651 | .policy = nl80211_policy, |
| 9652 | .flags = GENL_ADMIN_PERM, |
| 9653 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9654 | NL80211_FLAG_NEED_RTNL, |
| 9655 | }, |
| 9656 | { |
| 9657 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9658 | .doit = nl80211_tdls_oper, |
| 9659 | .policy = nl80211_policy, |
| 9660 | .flags = GENL_ADMIN_PERM, |
| 9661 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9662 | NL80211_FLAG_NEED_RTNL, |
| 9663 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9664 | { |
| 9665 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9666 | .doit = nl80211_register_unexpected_frame, |
| 9667 | .policy = nl80211_policy, |
| 9668 | .flags = GENL_ADMIN_PERM, |
| 9669 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9670 | NL80211_FLAG_NEED_RTNL, |
| 9671 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9672 | { |
| 9673 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9674 | .doit = nl80211_probe_client, |
| 9675 | .policy = nl80211_policy, |
| 9676 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9677 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9678 | NL80211_FLAG_NEED_RTNL, |
| 9679 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9680 | { |
| 9681 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9682 | .doit = nl80211_register_beacons, |
| 9683 | .policy = nl80211_policy, |
| 9684 | .flags = GENL_ADMIN_PERM, |
| 9685 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9686 | NL80211_FLAG_NEED_RTNL, |
| 9687 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9688 | { |
| 9689 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9690 | .doit = nl80211_set_noack_map, |
| 9691 | .policy = nl80211_policy, |
| 9692 | .flags = GENL_ADMIN_PERM, |
| 9693 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9694 | NL80211_FLAG_NEED_RTNL, |
| 9695 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9696 | { |
| 9697 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 9698 | .doit = nl80211_start_p2p_device, |
| 9699 | .policy = nl80211_policy, |
| 9700 | .flags = GENL_ADMIN_PERM, |
| 9701 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9702 | NL80211_FLAG_NEED_RTNL, |
| 9703 | }, |
| 9704 | { |
| 9705 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 9706 | .doit = nl80211_stop_p2p_device, |
| 9707 | .policy = nl80211_policy, |
| 9708 | .flags = GENL_ADMIN_PERM, |
| 9709 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9710 | NL80211_FLAG_NEED_RTNL, |
| 9711 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9712 | { |
| 9713 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 9714 | .doit = nl80211_set_mcast_rate, |
| 9715 | .policy = nl80211_policy, |
| 9716 | .flags = GENL_ADMIN_PERM, |
| 9717 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9718 | NL80211_FLAG_NEED_RTNL, |
| 9719 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 9720 | { |
| 9721 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 9722 | .doit = nl80211_set_mac_acl, |
| 9723 | .policy = nl80211_policy, |
| 9724 | .flags = GENL_ADMIN_PERM, |
| 9725 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9726 | NL80211_FLAG_NEED_RTNL, |
| 9727 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9728 | { |
| 9729 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 9730 | .doit = nl80211_start_radar_detection, |
| 9731 | .policy = nl80211_policy, |
| 9732 | .flags = GENL_ADMIN_PERM, |
| 9733 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9734 | NL80211_FLAG_NEED_RTNL, |
| 9735 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9736 | { |
| 9737 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 9738 | .doit = nl80211_get_protocol_features, |
| 9739 | .policy = nl80211_policy, |
| 9740 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9741 | { |
| 9742 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9743 | .doit = nl80211_update_ft_ies, |
| 9744 | .policy = nl80211_policy, |
| 9745 | .flags = GENL_ADMIN_PERM, |
| 9746 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9747 | NL80211_FLAG_NEED_RTNL, |
| 9748 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9749 | { |
| 9750 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9751 | .doit = nl80211_crit_protocol_start, |
| 9752 | .policy = nl80211_policy, |
| 9753 | .flags = GENL_ADMIN_PERM, |
| 9754 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9755 | NL80211_FLAG_NEED_RTNL, |
| 9756 | }, |
| 9757 | { |
| 9758 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9759 | .doit = nl80211_crit_protocol_stop, |
| 9760 | .policy = nl80211_policy, |
| 9761 | .flags = GENL_ADMIN_PERM, |
| 9762 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9763 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9764 | }, |
| 9765 | { |
| 9766 | .cmd = NL80211_CMD_GET_COALESCE, |
| 9767 | .doit = nl80211_get_coalesce, |
| 9768 | .policy = nl80211_policy, |
| 9769 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9770 | NL80211_FLAG_NEED_RTNL, |
| 9771 | }, |
| 9772 | { |
| 9773 | .cmd = NL80211_CMD_SET_COALESCE, |
| 9774 | .doit = nl80211_set_coalesce, |
| 9775 | .policy = nl80211_policy, |
| 9776 | .flags = GENL_ADMIN_PERM, |
| 9777 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9778 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9779 | }, |
| 9780 | { |
| 9781 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 9782 | .doit = nl80211_channel_switch, |
| 9783 | .policy = nl80211_policy, |
| 9784 | .flags = GENL_ADMIN_PERM, |
| 9785 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9786 | NL80211_FLAG_NEED_RTNL, |
| 9787 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9788 | { |
| 9789 | .cmd = NL80211_CMD_VENDOR, |
| 9790 | .doit = nl80211_vendor_cmd, |
| 9791 | .policy = nl80211_policy, |
| 9792 | .flags = GENL_ADMIN_PERM, |
| 9793 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9794 | NL80211_FLAG_NEED_RTNL, |
| 9795 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9796 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9797 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9798 | /* notification functions */ |
| 9799 | |
| 9800 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 9801 | { |
| 9802 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9803 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9804 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9805 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9806 | if (!msg) |
| 9807 | return; |
| 9808 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9809 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9810 | nlmsg_free(msg); |
| 9811 | return; |
| 9812 | } |
| 9813 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9814 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 9815 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9816 | } |
| 9817 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9818 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9819 | struct cfg80211_registered_device *rdev) |
| 9820 | { |
| 9821 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9822 | struct nlattr *nest; |
| 9823 | int i; |
| 9824 | |
| 9825 | if (WARN_ON(!req)) |
| 9826 | return 0; |
| 9827 | |
| 9828 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9829 | if (!nest) |
| 9830 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9831 | for (i = 0; i < req->n_ssids; i++) { |
| 9832 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9833 | goto nla_put_failure; |
| 9834 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9835 | nla_nest_end(msg, nest); |
| 9836 | |
| 9837 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9838 | if (!nest) |
| 9839 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9840 | for (i = 0; i < req->n_channels; i++) { |
| 9841 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9842 | goto nla_put_failure; |
| 9843 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9844 | nla_nest_end(msg, nest); |
| 9845 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9846 | if (req->ie && |
| 9847 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9848 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9849 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 9850 | if (req->flags && |
| 9851 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 9852 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9853 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9854 | return 0; |
| 9855 | nla_put_failure: |
| 9856 | return -ENOBUFS; |
| 9857 | } |
| 9858 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9859 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9860 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9861 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9862 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9863 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9864 | { |
| 9865 | void *hdr; |
| 9866 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9867 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9868 | if (!hdr) |
| 9869 | return -1; |
| 9870 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9871 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9872 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9873 | wdev->netdev->ifindex)) || |
| 9874 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9875 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9876 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9877 | /* ignore errors and send incomplete event anyway */ |
| 9878 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9879 | |
| 9880 | return genlmsg_end(msg, hdr); |
| 9881 | |
| 9882 | nla_put_failure: |
| 9883 | genlmsg_cancel(msg, hdr); |
| 9884 | return -EMSGSIZE; |
| 9885 | } |
| 9886 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9887 | static int |
| 9888 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9889 | struct cfg80211_registered_device *rdev, |
| 9890 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9891 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9892 | { |
| 9893 | void *hdr; |
| 9894 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9895 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9896 | if (!hdr) |
| 9897 | return -1; |
| 9898 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9899 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9900 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9901 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9902 | |
| 9903 | return genlmsg_end(msg, hdr); |
| 9904 | |
| 9905 | nla_put_failure: |
| 9906 | genlmsg_cancel(msg, hdr); |
| 9907 | return -EMSGSIZE; |
| 9908 | } |
| 9909 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9910 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9911 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9912 | { |
| 9913 | struct sk_buff *msg; |
| 9914 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9915 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9916 | if (!msg) |
| 9917 | return; |
| 9918 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9919 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9920 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9921 | nlmsg_free(msg); |
| 9922 | return; |
| 9923 | } |
| 9924 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9925 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 9926 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9927 | } |
| 9928 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9929 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9930 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9931 | { |
| 9932 | struct sk_buff *msg; |
| 9933 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9934 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9935 | if (!msg) |
| 9936 | return; |
| 9937 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9938 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9939 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9940 | nlmsg_free(msg); |
| 9941 | return; |
| 9942 | } |
| 9943 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9944 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 9945 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9946 | } |
| 9947 | |
| 9948 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9949 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9950 | { |
| 9951 | struct sk_buff *msg; |
| 9952 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9953 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9954 | if (!msg) |
| 9955 | return; |
| 9956 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9957 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9958 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9959 | nlmsg_free(msg); |
| 9960 | return; |
| 9961 | } |
| 9962 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9963 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 9964 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9965 | } |
| 9966 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9967 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9968 | struct net_device *netdev) |
| 9969 | { |
| 9970 | struct sk_buff *msg; |
| 9971 | |
| 9972 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9973 | if (!msg) |
| 9974 | return; |
| 9975 | |
| 9976 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9977 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9978 | nlmsg_free(msg); |
| 9979 | return; |
| 9980 | } |
| 9981 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9982 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 9983 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9984 | } |
| 9985 | |
| 9986 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9987 | struct net_device *netdev, u32 cmd) |
| 9988 | { |
| 9989 | struct sk_buff *msg; |
| 9990 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9991 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9992 | if (!msg) |
| 9993 | return; |
| 9994 | |
| 9995 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9996 | nlmsg_free(msg); |
| 9997 | return; |
| 9998 | } |
| 9999 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10000 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10001 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10002 | } |
| 10003 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10004 | /* |
| 10005 | * This can happen on global regulatory changes or device specific settings |
| 10006 | * based on custom world regulatory domains. |
| 10007 | */ |
| 10008 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 10009 | { |
| 10010 | struct sk_buff *msg; |
| 10011 | void *hdr; |
| 10012 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10013 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10014 | if (!msg) |
| 10015 | return; |
| 10016 | |
| 10017 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 10018 | if (!hdr) { |
| 10019 | nlmsg_free(msg); |
| 10020 | return; |
| 10021 | } |
| 10022 | |
| 10023 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10024 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 10025 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10026 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10027 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 10028 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10029 | NL80211_REGDOM_TYPE_WORLD)) |
| 10030 | goto nla_put_failure; |
| 10031 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 10032 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10033 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 10034 | goto nla_put_failure; |
| 10035 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 10036 | request->intersect) { |
| 10037 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10038 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 10039 | goto nla_put_failure; |
| 10040 | } else { |
| 10041 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10042 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 10043 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 10044 | request->alpha2)) |
| 10045 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10046 | } |
| 10047 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 10048 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10049 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 10050 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10051 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10052 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10053 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10054 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10055 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10056 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10057 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10058 | |
| 10059 | return; |
| 10060 | |
| 10061 | nla_put_failure: |
| 10062 | genlmsg_cancel(msg, hdr); |
| 10063 | nlmsg_free(msg); |
| 10064 | } |
| 10065 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10066 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 10067 | struct net_device *netdev, |
| 10068 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10069 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10070 | { |
| 10071 | struct sk_buff *msg; |
| 10072 | void *hdr; |
| 10073 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10074 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10075 | if (!msg) |
| 10076 | return; |
| 10077 | |
| 10078 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10079 | if (!hdr) { |
| 10080 | nlmsg_free(msg); |
| 10081 | return; |
| 10082 | } |
| 10083 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10084 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10085 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10086 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10087 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10088 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10089 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10090 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10091 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10092 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10093 | return; |
| 10094 | |
| 10095 | nla_put_failure: |
| 10096 | genlmsg_cancel(msg, hdr); |
| 10097 | nlmsg_free(msg); |
| 10098 | } |
| 10099 | |
| 10100 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10101 | struct net_device *netdev, const u8 *buf, |
| 10102 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10103 | { |
| 10104 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10105 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10106 | } |
| 10107 | |
| 10108 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 10109 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10110 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10111 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10112 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 10113 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10114 | } |
| 10115 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10116 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10117 | struct net_device *netdev, const u8 *buf, |
| 10118 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10119 | { |
| 10120 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10121 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10122 | } |
| 10123 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10124 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 10125 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10126 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10127 | { |
| 10128 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10129 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10130 | } |
| 10131 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10132 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 10133 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10134 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10135 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10136 | struct wiphy *wiphy = wdev->wiphy; |
| 10137 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10138 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 10139 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10140 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10141 | if (WARN_ON(len < 2)) |
| 10142 | return; |
| 10143 | |
| 10144 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 10145 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 10146 | else |
| 10147 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 10148 | |
| 10149 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 10150 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10151 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10152 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10153 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 10154 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 10155 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10156 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10157 | { |
| 10158 | struct sk_buff *msg; |
| 10159 | void *hdr; |
| 10160 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10161 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10162 | if (!msg) |
| 10163 | return; |
| 10164 | |
| 10165 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10166 | if (!hdr) { |
| 10167 | nlmsg_free(msg); |
| 10168 | return; |
| 10169 | } |
| 10170 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10171 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10172 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10173 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 10174 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10175 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10176 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10177 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10178 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10179 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10180 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10181 | return; |
| 10182 | |
| 10183 | nla_put_failure: |
| 10184 | genlmsg_cancel(msg, hdr); |
| 10185 | nlmsg_free(msg); |
| 10186 | } |
| 10187 | |
| 10188 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10189 | struct net_device *netdev, const u8 *addr, |
| 10190 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10191 | { |
| 10192 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10193 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10194 | } |
| 10195 | |
| 10196 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10197 | struct net_device *netdev, const u8 *addr, |
| 10198 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10199 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10200 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 10201 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10202 | } |
| 10203 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10204 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 10205 | struct net_device *netdev, const u8 *bssid, |
| 10206 | const u8 *req_ie, size_t req_ie_len, |
| 10207 | const u8 *resp_ie, size_t resp_ie_len, |
| 10208 | u16 status, gfp_t gfp) |
| 10209 | { |
| 10210 | struct sk_buff *msg; |
| 10211 | void *hdr; |
| 10212 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10213 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10214 | if (!msg) |
| 10215 | return; |
| 10216 | |
| 10217 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10218 | if (!hdr) { |
| 10219 | nlmsg_free(msg); |
| 10220 | return; |
| 10221 | } |
| 10222 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10223 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10224 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10225 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10226 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10227 | (req_ie && |
| 10228 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10229 | (resp_ie && |
| 10230 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10231 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10232 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10233 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10234 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10235 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10236 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10237 | return; |
| 10238 | |
| 10239 | nla_put_failure: |
| 10240 | genlmsg_cancel(msg, hdr); |
| 10241 | nlmsg_free(msg); |
| 10242 | |
| 10243 | } |
| 10244 | |
| 10245 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10246 | struct net_device *netdev, const u8 *bssid, |
| 10247 | const u8 *req_ie, size_t req_ie_len, |
| 10248 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10249 | { |
| 10250 | struct sk_buff *msg; |
| 10251 | void *hdr; |
| 10252 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10253 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10254 | if (!msg) |
| 10255 | return; |
| 10256 | |
| 10257 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10258 | if (!hdr) { |
| 10259 | nlmsg_free(msg); |
| 10260 | return; |
| 10261 | } |
| 10262 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10263 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10264 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10265 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10266 | (req_ie && |
| 10267 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10268 | (resp_ie && |
| 10269 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10270 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10271 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10272 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10273 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10274 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10275 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10276 | return; |
| 10277 | |
| 10278 | nla_put_failure: |
| 10279 | genlmsg_cancel(msg, hdr); |
| 10280 | nlmsg_free(msg); |
| 10281 | |
| 10282 | } |
| 10283 | |
| 10284 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10285 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10286 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10287 | { |
| 10288 | struct sk_buff *msg; |
| 10289 | void *hdr; |
| 10290 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10291 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10292 | if (!msg) |
| 10293 | return; |
| 10294 | |
| 10295 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10296 | if (!hdr) { |
| 10297 | nlmsg_free(msg); |
| 10298 | return; |
| 10299 | } |
| 10300 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10301 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10302 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10303 | (from_ap && reason && |
| 10304 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10305 | (from_ap && |
| 10306 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10307 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10308 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10309 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10310 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10311 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10312 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10313 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10314 | return; |
| 10315 | |
| 10316 | nla_put_failure: |
| 10317 | genlmsg_cancel(msg, hdr); |
| 10318 | nlmsg_free(msg); |
| 10319 | |
| 10320 | } |
| 10321 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10322 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10323 | struct net_device *netdev, const u8 *bssid, |
| 10324 | gfp_t gfp) |
| 10325 | { |
| 10326 | struct sk_buff *msg; |
| 10327 | void *hdr; |
| 10328 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10329 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10330 | if (!msg) |
| 10331 | return; |
| 10332 | |
| 10333 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10334 | if (!hdr) { |
| 10335 | nlmsg_free(msg); |
| 10336 | return; |
| 10337 | } |
| 10338 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10339 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10340 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10341 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10342 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10343 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10344 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10345 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10346 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10347 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10348 | return; |
| 10349 | |
| 10350 | nla_put_failure: |
| 10351 | genlmsg_cancel(msg, hdr); |
| 10352 | nlmsg_free(msg); |
| 10353 | } |
| 10354 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10355 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10356 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10357 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10358 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10359 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10360 | struct sk_buff *msg; |
| 10361 | void *hdr; |
| 10362 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10363 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10364 | return; |
| 10365 | |
| 10366 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10367 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10368 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10369 | if (!msg) |
| 10370 | return; |
| 10371 | |
| 10372 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10373 | if (!hdr) { |
| 10374 | nlmsg_free(msg); |
| 10375 | return; |
| 10376 | } |
| 10377 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10378 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10379 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10380 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10381 | (ie_len && ie && |
| 10382 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10383 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10384 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10385 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10386 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10387 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10388 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10389 | return; |
| 10390 | |
| 10391 | nla_put_failure: |
| 10392 | genlmsg_cancel(msg, hdr); |
| 10393 | nlmsg_free(msg); |
| 10394 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10395 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10396 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10397 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10398 | struct net_device *netdev, const u8 *addr, |
| 10399 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10400 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10401 | { |
| 10402 | struct sk_buff *msg; |
| 10403 | void *hdr; |
| 10404 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10405 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10406 | if (!msg) |
| 10407 | return; |
| 10408 | |
| 10409 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10410 | if (!hdr) { |
| 10411 | nlmsg_free(msg); |
| 10412 | return; |
| 10413 | } |
| 10414 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10415 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10416 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10417 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10418 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10419 | (key_id != -1 && |
| 10420 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10421 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10422 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10423 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10424 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10425 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10426 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10427 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10428 | return; |
| 10429 | |
| 10430 | nla_put_failure: |
| 10431 | genlmsg_cancel(msg, hdr); |
| 10432 | nlmsg_free(msg); |
| 10433 | } |
| 10434 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10435 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10436 | struct ieee80211_channel *channel_before, |
| 10437 | struct ieee80211_channel *channel_after) |
| 10438 | { |
| 10439 | struct sk_buff *msg; |
| 10440 | void *hdr; |
| 10441 | struct nlattr *nl_freq; |
| 10442 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10443 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10444 | if (!msg) |
| 10445 | return; |
| 10446 | |
| 10447 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10448 | if (!hdr) { |
| 10449 | nlmsg_free(msg); |
| 10450 | return; |
| 10451 | } |
| 10452 | |
| 10453 | /* |
| 10454 | * Since we are applying the beacon hint to a wiphy we know its |
| 10455 | * wiphy_idx is valid |
| 10456 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10457 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10458 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10459 | |
| 10460 | /* Before */ |
| 10461 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10462 | if (!nl_freq) |
| 10463 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10464 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10465 | goto nla_put_failure; |
| 10466 | nla_nest_end(msg, nl_freq); |
| 10467 | |
| 10468 | /* After */ |
| 10469 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10470 | if (!nl_freq) |
| 10471 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10472 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10473 | goto nla_put_failure; |
| 10474 | nla_nest_end(msg, nl_freq); |
| 10475 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10476 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10477 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10478 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10479 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10480 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10481 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10482 | |
| 10483 | return; |
| 10484 | |
| 10485 | nla_put_failure: |
| 10486 | genlmsg_cancel(msg, hdr); |
| 10487 | nlmsg_free(msg); |
| 10488 | } |
| 10489 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10490 | static void nl80211_send_remain_on_chan_event( |
| 10491 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10492 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10493 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10494 | unsigned int duration, gfp_t gfp) |
| 10495 | { |
| 10496 | struct sk_buff *msg; |
| 10497 | void *hdr; |
| 10498 | |
| 10499 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10500 | if (!msg) |
| 10501 | return; |
| 10502 | |
| 10503 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10504 | if (!hdr) { |
| 10505 | nlmsg_free(msg); |
| 10506 | return; |
| 10507 | } |
| 10508 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10509 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10510 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10511 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10512 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10513 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10514 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10515 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10516 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10517 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10518 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10519 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10520 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10521 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10522 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10523 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10524 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10525 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10526 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10527 | return; |
| 10528 | |
| 10529 | nla_put_failure: |
| 10530 | genlmsg_cancel(msg, hdr); |
| 10531 | nlmsg_free(msg); |
| 10532 | } |
| 10533 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10534 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10535 | struct ieee80211_channel *chan, |
| 10536 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10537 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10538 | struct wiphy *wiphy = wdev->wiphy; |
| 10539 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10540 | |
| 10541 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10542 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10543 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10544 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10545 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10546 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10547 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10548 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10549 | struct ieee80211_channel *chan, |
| 10550 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10551 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10552 | struct wiphy *wiphy = wdev->wiphy; |
| 10553 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10554 | |
| 10555 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10556 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10557 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10558 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10559 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10560 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10561 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10562 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10563 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10564 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10565 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10566 | struct sk_buff *msg; |
| 10567 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10568 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10569 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10570 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10571 | if (!msg) |
| 10572 | return; |
| 10573 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10574 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10575 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10576 | nlmsg_free(msg); |
| 10577 | return; |
| 10578 | } |
| 10579 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10580 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10581 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10582 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10583 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10584 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10585 | 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] | 10586 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10587 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10588 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10589 | struct sk_buff *msg; |
| 10590 | void *hdr; |
| 10591 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10592 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10593 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10594 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10595 | if (!msg) |
| 10596 | return; |
| 10597 | |
| 10598 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10599 | if (!hdr) { |
| 10600 | nlmsg_free(msg); |
| 10601 | return; |
| 10602 | } |
| 10603 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10604 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10605 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10606 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10607 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10608 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10609 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10610 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10611 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10612 | return; |
| 10613 | |
| 10614 | nla_put_failure: |
| 10615 | genlmsg_cancel(msg, hdr); |
| 10616 | nlmsg_free(msg); |
| 10617 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10618 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10619 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10620 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10621 | enum nl80211_connect_failed_reason reason, |
| 10622 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10623 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10624 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10625 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10626 | struct sk_buff *msg; |
| 10627 | void *hdr; |
| 10628 | |
| 10629 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10630 | if (!msg) |
| 10631 | return; |
| 10632 | |
| 10633 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10634 | if (!hdr) { |
| 10635 | nlmsg_free(msg); |
| 10636 | return; |
| 10637 | } |
| 10638 | |
| 10639 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10640 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10641 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10642 | goto nla_put_failure; |
| 10643 | |
| 10644 | genlmsg_end(msg, hdr); |
| 10645 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10646 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10647 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10648 | return; |
| 10649 | |
| 10650 | nla_put_failure: |
| 10651 | genlmsg_cancel(msg, hdr); |
| 10652 | nlmsg_free(msg); |
| 10653 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10654 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10655 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10656 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10657 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10658 | { |
| 10659 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10660 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10661 | struct sk_buff *msg; |
| 10662 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10663 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10664 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10665 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10666 | return false; |
| 10667 | |
| 10668 | msg = nlmsg_new(100, gfp); |
| 10669 | if (!msg) |
| 10670 | return true; |
| 10671 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10672 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10673 | if (!hdr) { |
| 10674 | nlmsg_free(msg); |
| 10675 | return true; |
| 10676 | } |
| 10677 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10678 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10679 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10680 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10681 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10682 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10683 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10684 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10685 | return true; |
| 10686 | |
| 10687 | nla_put_failure: |
| 10688 | genlmsg_cancel(msg, hdr); |
| 10689 | nlmsg_free(msg); |
| 10690 | return true; |
| 10691 | } |
| 10692 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10693 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 10694 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10695 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10696 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10697 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10698 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10699 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 10700 | |
| 10701 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10702 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 10703 | trace_cfg80211_return_bool(false); |
| 10704 | return false; |
| 10705 | } |
| 10706 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 10707 | addr, gfp); |
| 10708 | trace_cfg80211_return_bool(ret); |
| 10709 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10710 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10711 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 10712 | |
| 10713 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 10714 | const u8 *addr, gfp_t gfp) |
| 10715 | { |
| 10716 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10717 | bool ret; |
| 10718 | |
| 10719 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 10720 | |
| 10721 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10722 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 10723 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 10724 | trace_cfg80211_return_bool(false); |
| 10725 | return false; |
| 10726 | } |
| 10727 | ret = __nl80211_unexpected_frame(dev, |
| 10728 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 10729 | addr, gfp); |
| 10730 | trace_cfg80211_return_bool(ret); |
| 10731 | return ret; |
| 10732 | } |
| 10733 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10734 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10735 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10736 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 10737 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10738 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10739 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10740 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10741 | struct sk_buff *msg; |
| 10742 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10743 | |
| 10744 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10745 | if (!msg) |
| 10746 | return -ENOMEM; |
| 10747 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10748 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10749 | if (!hdr) { |
| 10750 | nlmsg_free(msg); |
| 10751 | return -ENOMEM; |
| 10752 | } |
| 10753 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10754 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10755 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10756 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10757 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10758 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10759 | (sig_dbm && |
| 10760 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10761 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10762 | (flags && |
| 10763 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10764 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10765 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10766 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10767 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10768 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10769 | |
| 10770 | nla_put_failure: |
| 10771 | genlmsg_cancel(msg, hdr); |
| 10772 | nlmsg_free(msg); |
| 10773 | return -ENOBUFS; |
| 10774 | } |
| 10775 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10776 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10777 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10778 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10779 | struct wiphy *wiphy = wdev->wiphy; |
| 10780 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10781 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10782 | struct sk_buff *msg; |
| 10783 | void *hdr; |
| 10784 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10785 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10786 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10787 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10788 | if (!msg) |
| 10789 | return; |
| 10790 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10791 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10792 | if (!hdr) { |
| 10793 | nlmsg_free(msg); |
| 10794 | return; |
| 10795 | } |
| 10796 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10797 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10798 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10799 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10800 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10801 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10802 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10803 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10804 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10805 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10806 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10807 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10808 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10809 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10810 | return; |
| 10811 | |
| 10812 | nla_put_failure: |
| 10813 | genlmsg_cancel(msg, hdr); |
| 10814 | nlmsg_free(msg); |
| 10815 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10816 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10817 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10818 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10819 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10820 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10821 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10822 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10823 | struct wiphy *wiphy = wdev->wiphy; |
| 10824 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10825 | struct sk_buff *msg; |
| 10826 | struct nlattr *pinfoattr; |
| 10827 | void *hdr; |
| 10828 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10829 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10830 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10831 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10832 | if (!msg) |
| 10833 | return; |
| 10834 | |
| 10835 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10836 | if (!hdr) { |
| 10837 | nlmsg_free(msg); |
| 10838 | return; |
| 10839 | } |
| 10840 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10841 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10842 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10843 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10844 | |
| 10845 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10846 | if (!pinfoattr) |
| 10847 | goto nla_put_failure; |
| 10848 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10849 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10850 | rssi_event)) |
| 10851 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10852 | |
| 10853 | nla_nest_end(msg, pinfoattr); |
| 10854 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10855 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10856 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10857 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10858 | NL80211_MCGRP_MLME, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10859 | return; |
| 10860 | |
| 10861 | nla_put_failure: |
| 10862 | genlmsg_cancel(msg, hdr); |
| 10863 | nlmsg_free(msg); |
| 10864 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10865 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10866 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10867 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10868 | struct net_device *netdev, const u8 *bssid, |
| 10869 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10870 | { |
| 10871 | struct sk_buff *msg; |
| 10872 | struct nlattr *rekey_attr; |
| 10873 | void *hdr; |
| 10874 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10875 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10876 | if (!msg) |
| 10877 | return; |
| 10878 | |
| 10879 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10880 | if (!hdr) { |
| 10881 | nlmsg_free(msg); |
| 10882 | return; |
| 10883 | } |
| 10884 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10885 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10886 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10887 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10888 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10889 | |
| 10890 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10891 | if (!rekey_attr) |
| 10892 | goto nla_put_failure; |
| 10893 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10894 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10895 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10896 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10897 | |
| 10898 | nla_nest_end(msg, rekey_attr); |
| 10899 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10900 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10901 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10902 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10903 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10904 | return; |
| 10905 | |
| 10906 | nla_put_failure: |
| 10907 | genlmsg_cancel(msg, hdr); |
| 10908 | nlmsg_free(msg); |
| 10909 | } |
| 10910 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10911 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10912 | const u8 *replay_ctr, gfp_t gfp) |
| 10913 | { |
| 10914 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10915 | struct wiphy *wiphy = wdev->wiphy; |
| 10916 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10917 | |
| 10918 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10919 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10920 | } |
| 10921 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10922 | |
| 10923 | static void |
| 10924 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10925 | struct net_device *netdev, int index, |
| 10926 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10927 | { |
| 10928 | struct sk_buff *msg; |
| 10929 | struct nlattr *attr; |
| 10930 | void *hdr; |
| 10931 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10932 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10933 | if (!msg) |
| 10934 | return; |
| 10935 | |
| 10936 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10937 | if (!hdr) { |
| 10938 | nlmsg_free(msg); |
| 10939 | return; |
| 10940 | } |
| 10941 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10942 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10943 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10944 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10945 | |
| 10946 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10947 | if (!attr) |
| 10948 | goto nla_put_failure; |
| 10949 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10950 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10951 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10952 | (preauth && |
| 10953 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10954 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10955 | |
| 10956 | nla_nest_end(msg, attr); |
| 10957 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10958 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10959 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10960 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10961 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10962 | return; |
| 10963 | |
| 10964 | nla_put_failure: |
| 10965 | genlmsg_cancel(msg, hdr); |
| 10966 | nlmsg_free(msg); |
| 10967 | } |
| 10968 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10969 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10970 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10971 | { |
| 10972 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10973 | struct wiphy *wiphy = wdev->wiphy; |
| 10974 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10975 | |
| 10976 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10977 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10978 | } |
| 10979 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10980 | |
| 10981 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10982 | struct net_device *netdev, |
| 10983 | struct cfg80211_chan_def *chandef, |
| 10984 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10985 | { |
| 10986 | struct sk_buff *msg; |
| 10987 | void *hdr; |
| 10988 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10989 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10990 | if (!msg) |
| 10991 | return; |
| 10992 | |
| 10993 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10994 | if (!hdr) { |
| 10995 | nlmsg_free(msg); |
| 10996 | return; |
| 10997 | } |
| 10998 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10999 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11000 | goto nla_put_failure; |
| 11001 | |
| 11002 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 11003 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11004 | |
| 11005 | genlmsg_end(msg, hdr); |
| 11006 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11007 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11008 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11009 | return; |
| 11010 | |
| 11011 | nla_put_failure: |
| 11012 | genlmsg_cancel(msg, hdr); |
| 11013 | nlmsg_free(msg); |
| 11014 | } |
| 11015 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11016 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 11017 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11018 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11019 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11020 | struct wiphy *wiphy = wdev->wiphy; |
| 11021 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11022 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11023 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11024 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11025 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11026 | |
| 11027 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 11028 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 11029 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 11030 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11031 | return; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11032 | |
| 11033 | wdev->channel = chandef->chan; |
| 11034 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11035 | } |
| 11036 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 11037 | |
| 11038 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 11039 | const u8 *peer, u32 num_packets, |
| 11040 | u32 rate, u32 intvl, gfp_t gfp) |
| 11041 | { |
| 11042 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11043 | struct wiphy *wiphy = wdev->wiphy; |
| 11044 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11045 | struct sk_buff *msg; |
| 11046 | struct nlattr *pinfoattr; |
| 11047 | void *hdr; |
| 11048 | |
| 11049 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11050 | if (!msg) |
| 11051 | return; |
| 11052 | |
| 11053 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11054 | if (!hdr) { |
| 11055 | nlmsg_free(msg); |
| 11056 | return; |
| 11057 | } |
| 11058 | |
| 11059 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11060 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11061 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11062 | goto nla_put_failure; |
| 11063 | |
| 11064 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11065 | if (!pinfoattr) |
| 11066 | goto nla_put_failure; |
| 11067 | |
| 11068 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 11069 | goto nla_put_failure; |
| 11070 | |
| 11071 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 11072 | goto nla_put_failure; |
| 11073 | |
| 11074 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 11075 | goto nla_put_failure; |
| 11076 | |
| 11077 | nla_nest_end(msg, pinfoattr); |
| 11078 | |
| 11079 | genlmsg_end(msg, hdr); |
| 11080 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11081 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11082 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11083 | return; |
| 11084 | |
| 11085 | nla_put_failure: |
| 11086 | genlmsg_cancel(msg, hdr); |
| 11087 | nlmsg_free(msg); |
| 11088 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11089 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11090 | |
| 11091 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11092 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 11093 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11094 | enum nl80211_radar_event event, |
| 11095 | struct net_device *netdev, gfp_t gfp) |
| 11096 | { |
| 11097 | struct sk_buff *msg; |
| 11098 | void *hdr; |
| 11099 | |
| 11100 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11101 | if (!msg) |
| 11102 | return; |
| 11103 | |
| 11104 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 11105 | if (!hdr) { |
| 11106 | nlmsg_free(msg); |
| 11107 | return; |
| 11108 | } |
| 11109 | |
| 11110 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 11111 | goto nla_put_failure; |
| 11112 | |
| 11113 | /* NOP and radar events don't need a netdev parameter */ |
| 11114 | if (netdev) { |
| 11115 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 11116 | |
| 11117 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11118 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11119 | goto nla_put_failure; |
| 11120 | } |
| 11121 | |
| 11122 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 11123 | goto nla_put_failure; |
| 11124 | |
| 11125 | if (nl80211_send_chandef(msg, chandef)) |
| 11126 | goto nla_put_failure; |
| 11127 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11128 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11129 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11130 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11131 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11132 | return; |
| 11133 | |
| 11134 | nla_put_failure: |
| 11135 | genlmsg_cancel(msg, hdr); |
| 11136 | nlmsg_free(msg); |
| 11137 | } |
| 11138 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11139 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 11140 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11141 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11142 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11143 | struct wiphy *wiphy = wdev->wiphy; |
| 11144 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11145 | struct sk_buff *msg; |
| 11146 | struct nlattr *pinfoattr; |
| 11147 | void *hdr; |
| 11148 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11149 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 11150 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11151 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11152 | if (!msg) |
| 11153 | return; |
| 11154 | |
| 11155 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11156 | if (!hdr) { |
| 11157 | nlmsg_free(msg); |
| 11158 | return; |
| 11159 | } |
| 11160 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11161 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11162 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11163 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11164 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11165 | |
| 11166 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11167 | if (!pinfoattr) |
| 11168 | goto nla_put_failure; |
| 11169 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11170 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 11171 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11172 | |
| 11173 | nla_nest_end(msg, pinfoattr); |
| 11174 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11175 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11176 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11177 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11178 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11179 | return; |
| 11180 | |
| 11181 | nla_put_failure: |
| 11182 | genlmsg_cancel(msg, hdr); |
| 11183 | nlmsg_free(msg); |
| 11184 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11185 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11186 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11187 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 11188 | u64 cookie, bool acked, gfp_t gfp) |
| 11189 | { |
| 11190 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11191 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11192 | struct sk_buff *msg; |
| 11193 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11194 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11195 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 11196 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11197 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11198 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11199 | if (!msg) |
| 11200 | return; |
| 11201 | |
| 11202 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 11203 | if (!hdr) { |
| 11204 | nlmsg_free(msg); |
| 11205 | return; |
| 11206 | } |
| 11207 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11208 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11209 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11210 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11211 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11212 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11213 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11214 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11215 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11216 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11217 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11218 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11219 | return; |
| 11220 | |
| 11221 | nla_put_failure: |
| 11222 | genlmsg_cancel(msg, hdr); |
| 11223 | nlmsg_free(msg); |
| 11224 | } |
| 11225 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11226 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11227 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11228 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11229 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11230 | { |
| 11231 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11232 | struct sk_buff *msg; |
| 11233 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11234 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11235 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11236 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11237 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11238 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11239 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11240 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11241 | if (!msg) { |
| 11242 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11243 | return; |
| 11244 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11245 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11246 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11247 | if (!hdr) |
| 11248 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11249 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11250 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11251 | (freq && |
| 11252 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11253 | (sig_dbm && |
| 11254 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11255 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11256 | goto nla_put_failure; |
| 11257 | |
| 11258 | genlmsg_end(msg, hdr); |
| 11259 | |
| 11260 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11261 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11262 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11263 | return; |
| 11264 | |
| 11265 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11266 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11267 | if (hdr) |
| 11268 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11269 | nlmsg_free(msg); |
| 11270 | } |
| 11271 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11272 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11273 | #ifdef CONFIG_PM |
| 11274 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11275 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11276 | gfp_t gfp) |
| 11277 | { |
| 11278 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11279 | struct sk_buff *msg; |
| 11280 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11281 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11282 | |
| 11283 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11284 | |
| 11285 | if (wakeup) |
| 11286 | size += wakeup->packet_present_len; |
| 11287 | |
| 11288 | msg = nlmsg_new(size, gfp); |
| 11289 | if (!msg) |
| 11290 | return; |
| 11291 | |
| 11292 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11293 | if (!hdr) |
| 11294 | goto free_msg; |
| 11295 | |
| 11296 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11297 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11298 | goto free_msg; |
| 11299 | |
| 11300 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11301 | wdev->netdev->ifindex)) |
| 11302 | goto free_msg; |
| 11303 | |
| 11304 | if (wakeup) { |
| 11305 | struct nlattr *reasons; |
| 11306 | |
| 11307 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 11308 | if (!reasons) |
| 11309 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11310 | |
| 11311 | if (wakeup->disconnect && |
| 11312 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11313 | goto free_msg; |
| 11314 | if (wakeup->magic_pkt && |
| 11315 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11316 | goto free_msg; |
| 11317 | if (wakeup->gtk_rekey_failure && |
| 11318 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11319 | goto free_msg; |
| 11320 | if (wakeup->eap_identity_req && |
| 11321 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11322 | goto free_msg; |
| 11323 | if (wakeup->four_way_handshake && |
| 11324 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11325 | goto free_msg; |
| 11326 | if (wakeup->rfkill_release && |
| 11327 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11328 | goto free_msg; |
| 11329 | |
| 11330 | if (wakeup->pattern_idx >= 0 && |
| 11331 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11332 | wakeup->pattern_idx)) |
| 11333 | goto free_msg; |
| 11334 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11335 | if (wakeup->tcp_match && |
| 11336 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 11337 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11338 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11339 | if (wakeup->tcp_connlost && |
| 11340 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 11341 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11342 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11343 | if (wakeup->tcp_nomoretokens && |
| 11344 | nla_put_flag(msg, |
| 11345 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 11346 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11347 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11348 | if (wakeup->packet) { |
| 11349 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11350 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11351 | |
| 11352 | if (!wakeup->packet_80211) { |
| 11353 | pkt_attr = |
| 11354 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11355 | len_attr = |
| 11356 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11357 | } |
| 11358 | |
| 11359 | if (wakeup->packet_len && |
| 11360 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11361 | goto free_msg; |
| 11362 | |
| 11363 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11364 | wakeup->packet)) |
| 11365 | goto free_msg; |
| 11366 | } |
| 11367 | |
| 11368 | nla_nest_end(msg, reasons); |
| 11369 | } |
| 11370 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11371 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11372 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11373 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11374 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11375 | return; |
| 11376 | |
| 11377 | free_msg: |
| 11378 | nlmsg_free(msg); |
| 11379 | } |
| 11380 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11381 | #endif |
| 11382 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11383 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11384 | enum nl80211_tdls_operation oper, |
| 11385 | u16 reason_code, gfp_t gfp) |
| 11386 | { |
| 11387 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11388 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11389 | struct sk_buff *msg; |
| 11390 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11391 | |
| 11392 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11393 | reason_code); |
| 11394 | |
| 11395 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11396 | if (!msg) |
| 11397 | return; |
| 11398 | |
| 11399 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11400 | if (!hdr) { |
| 11401 | nlmsg_free(msg); |
| 11402 | return; |
| 11403 | } |
| 11404 | |
| 11405 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11406 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11407 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11408 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11409 | (reason_code > 0 && |
| 11410 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11411 | goto nla_put_failure; |
| 11412 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11413 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11414 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11415 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11416 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11417 | return; |
| 11418 | |
| 11419 | nla_put_failure: |
| 11420 | genlmsg_cancel(msg, hdr); |
| 11421 | nlmsg_free(msg); |
| 11422 | } |
| 11423 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11424 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11425 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11426 | unsigned long state, |
| 11427 | void *_notify) |
| 11428 | { |
| 11429 | struct netlink_notify *notify = _notify; |
| 11430 | struct cfg80211_registered_device *rdev; |
| 11431 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11432 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11433 | |
| 11434 | if (state != NETLINK_URELEASE) |
| 11435 | return NOTIFY_DONE; |
| 11436 | |
| 11437 | rcu_read_lock(); |
| 11438 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11439 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11440 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11441 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11442 | |
| 11443 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11444 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11445 | list) { |
| 11446 | if (reg->nlportid == notify->portid) { |
| 11447 | list_del(®->list); |
| 11448 | kfree(reg); |
| 11449 | break; |
| 11450 | } |
| 11451 | } |
| 11452 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11453 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11454 | |
| 11455 | rcu_read_unlock(); |
| 11456 | |
| 11457 | return NOTIFY_DONE; |
| 11458 | } |
| 11459 | |
| 11460 | static struct notifier_block nl80211_netlink_notifier = { |
| 11461 | .notifier_call = nl80211_netlink_notify, |
| 11462 | }; |
| 11463 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11464 | void cfg80211_ft_event(struct net_device *netdev, |
| 11465 | struct cfg80211_ft_event_params *ft_event) |
| 11466 | { |
| 11467 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 11468 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11469 | struct sk_buff *msg; |
| 11470 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11471 | |
| 11472 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11473 | |
| 11474 | if (!ft_event->target_ap) |
| 11475 | return; |
| 11476 | |
| 11477 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11478 | if (!msg) |
| 11479 | return; |
| 11480 | |
| 11481 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11482 | if (!hdr) |
| 11483 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11484 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11485 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11486 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11487 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 11488 | goto out; |
| 11489 | |
| 11490 | if (ft_event->ies && |
| 11491 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 11492 | goto out; |
| 11493 | if (ft_event->ric_ies && |
| 11494 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11495 | ft_event->ric_ies)) |
| 11496 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11497 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11498 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11499 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11500 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11501 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11502 | return; |
| 11503 | out: |
| 11504 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11505 | } |
| 11506 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11507 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11508 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11509 | { |
| 11510 | struct cfg80211_registered_device *rdev; |
| 11511 | struct sk_buff *msg; |
| 11512 | void *hdr; |
| 11513 | u32 nlportid; |
| 11514 | |
| 11515 | rdev = wiphy_to_dev(wdev->wiphy); |
| 11516 | if (!rdev->crit_proto_nlportid) |
| 11517 | return; |
| 11518 | |
| 11519 | nlportid = rdev->crit_proto_nlportid; |
| 11520 | rdev->crit_proto_nlportid = 0; |
| 11521 | |
| 11522 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11523 | if (!msg) |
| 11524 | return; |
| 11525 | |
| 11526 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11527 | if (!hdr) |
| 11528 | goto nla_put_failure; |
| 11529 | |
| 11530 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11531 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11532 | goto nla_put_failure; |
| 11533 | |
| 11534 | genlmsg_end(msg, hdr); |
| 11535 | |
| 11536 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11537 | return; |
| 11538 | |
| 11539 | nla_put_failure: |
| 11540 | if (hdr) |
| 11541 | genlmsg_cancel(msg, hdr); |
| 11542 | nlmsg_free(msg); |
| 11543 | |
| 11544 | } |
| 11545 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11546 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11547 | /* initialisation/exit functions */ |
| 11548 | |
| 11549 | int nl80211_init(void) |
| 11550 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11551 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11552 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11553 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 11554 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11555 | if (err) |
| 11556 | return err; |
| 11557 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11558 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11559 | if (err) |
| 11560 | goto err_out; |
| 11561 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11562 | return 0; |
| 11563 | err_out: |
| 11564 | genl_unregister_family(&nl80211_fam); |
| 11565 | return err; |
| 11566 | } |
| 11567 | |
| 11568 | void nl80211_exit(void) |
| 11569 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11570 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11571 | genl_unregister_family(&nl80211_fam); |
| 11572 | } |