Commit | Line | Data |
---|---|---|
457c8996 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
55682965 JB |
2 | /* |
3 | * This is the new netlink-based wireless configuration interface. | |
4 | * | |
026331c4 | 5 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
2740f0cf | 6 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
66cd794e | 7 | * Copyright 2015-2017 Intel Deutschland GmbH |
55c1fdf0 | 8 | * Copyright (C) 2018-2019 Intel Corporation |
55682965 JB |
9 | */ |
10 | ||
11 | #include <linux/if.h> | |
12 | #include <linux/module.h> | |
13 | #include <linux/err.h> | |
5a0e3ad6 | 14 | #include <linux/slab.h> |
55682965 JB |
15 | #include <linux/list.h> |
16 | #include <linux/if_ether.h> | |
17 | #include <linux/ieee80211.h> | |
18 | #include <linux/nl80211.h> | |
19 | #include <linux/rtnetlink.h> | |
20 | #include <linux/netlink.h> | |
259d8c1e | 21 | #include <linux/nospec.h> |
2a519311 | 22 | #include <linux/etherdevice.h> |
463d0183 | 23 | #include <net/net_namespace.h> |
55682965 JB |
24 | #include <net/genetlink.h> |
25 | #include <net/cfg80211.h> | |
463d0183 | 26 | #include <net/sock.h> |
2a0e047e | 27 | #include <net/inet_connection_sock.h> |
55682965 JB |
28 | #include "core.h" |
29 | #include "nl80211.h" | |
b2e1b302 | 30 | #include "reg.h" |
e35e4d28 | 31 | #include "rdev-ops.h" |
55682965 | 32 | |
5fb628e9 JM |
33 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
34 | struct genl_info *info, | |
35 | struct cfg80211_crypto_settings *settings, | |
36 | int cipher_limit); | |
37 | ||
55682965 | 38 | /* the netlink family */ |
489111e5 | 39 | static struct genl_family nl80211_fam; |
55682965 | 40 | |
2a94fe48 JB |
41 | /* multicast groups */ |
42 | enum nl80211_multicast_groups { | |
43 | NL80211_MCGRP_CONFIG, | |
44 | NL80211_MCGRP_SCAN, | |
45 | NL80211_MCGRP_REGULATORY, | |
46 | NL80211_MCGRP_MLME, | |
567ffc35 | 47 | NL80211_MCGRP_VENDOR, |
50bcd31d | 48 | NL80211_MCGRP_NAN, |
2a94fe48 JB |
49 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
50 | }; | |
51 | ||
52 | static const struct genl_multicast_group nl80211_mcgrps[] = { | |
71b836ec JB |
53 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
54 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, | |
55 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, | |
56 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, | |
57 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, | |
50bcd31d | 58 | [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, |
2a94fe48 | 59 | #ifdef CONFIG_NL80211_TESTMODE |
71b836ec | 60 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
2a94fe48 JB |
61 | #endif |
62 | }; | |
63 | ||
89a54e48 JB |
64 | /* returns ERR_PTR values */ |
65 | static struct wireless_dev * | |
66 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 67 | { |
89a54e48 JB |
68 | struct cfg80211_registered_device *rdev; |
69 | struct wireless_dev *result = NULL; | |
70 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
71 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
72 | u64 wdev_id; | |
73 | int wiphy_idx = -1; | |
74 | int ifidx = -1; | |
55682965 | 75 | |
5fe231e8 | 76 | ASSERT_RTNL(); |
55682965 | 77 | |
89a54e48 JB |
78 | if (!have_ifidx && !have_wdev_id) |
79 | return ERR_PTR(-EINVAL); | |
55682965 | 80 | |
89a54e48 JB |
81 | if (have_ifidx) |
82 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
83 | if (have_wdev_id) { | |
84 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
85 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
86 | } |
87 | ||
89a54e48 JB |
88 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
89 | struct wireless_dev *wdev; | |
90 | ||
91 | if (wiphy_net(&rdev->wiphy) != netns) | |
92 | continue; | |
93 | ||
94 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
95 | continue; | |
96 | ||
53873f13 | 97 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
89a54e48 JB |
98 | if (have_ifidx && wdev->netdev && |
99 | wdev->netdev->ifindex == ifidx) { | |
100 | result = wdev; | |
101 | break; | |
102 | } | |
103 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
104 | result = wdev; | |
105 | break; | |
106 | } | |
107 | } | |
89a54e48 JB |
108 | |
109 | if (result) | |
110 | break; | |
111 | } | |
112 | ||
113 | if (result) | |
114 | return result; | |
115 | return ERR_PTR(-ENODEV); | |
55682965 JB |
116 | } |
117 | ||
a9455408 | 118 | static struct cfg80211_registered_device * |
878d9ec7 | 119 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 120 | { |
7fee4778 JB |
121 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
122 | struct net_device *netdev; | |
a9455408 | 123 | |
5fe231e8 | 124 | ASSERT_RTNL(); |
a9455408 | 125 | |
878d9ec7 | 126 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
127 | !attrs[NL80211_ATTR_IFINDEX] && |
128 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
129 | return ERR_PTR(-EINVAL); |
130 | ||
878d9ec7 | 131 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 132 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 133 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 134 | |
89a54e48 JB |
135 | if (attrs[NL80211_ATTR_WDEV]) { |
136 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
137 | struct wireless_dev *wdev; | |
138 | bool found = false; | |
139 | ||
140 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
141 | if (tmp) { | |
142 | /* make sure wdev exists */ | |
53873f13 | 143 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
89a54e48 JB |
144 | if (wdev->identifier != (u32)wdev_id) |
145 | continue; | |
146 | found = true; | |
147 | break; | |
148 | } | |
89a54e48 JB |
149 | |
150 | if (!found) | |
151 | tmp = NULL; | |
152 | ||
153 | if (rdev && tmp != rdev) | |
154 | return ERR_PTR(-EINVAL); | |
155 | rdev = tmp; | |
156 | } | |
157 | } | |
158 | ||
878d9ec7 JB |
159 | if (attrs[NL80211_ATTR_IFINDEX]) { |
160 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
7a087e74 | 161 | |
7f2b8562 | 162 | netdev = __dev_get_by_index(netns, ifindex); |
7fee4778 JB |
163 | if (netdev) { |
164 | if (netdev->ieee80211_ptr) | |
f26cbf40 ZG |
165 | tmp = wiphy_to_rdev( |
166 | netdev->ieee80211_ptr->wiphy); | |
7fee4778 JB |
167 | else |
168 | tmp = NULL; | |
169 | ||
7fee4778 JB |
170 | /* not wireless device -- return error */ |
171 | if (!tmp) | |
172 | return ERR_PTR(-EINVAL); | |
173 | ||
174 | /* mismatch -- return error */ | |
175 | if (rdev && tmp != rdev) | |
176 | return ERR_PTR(-EINVAL); | |
177 | ||
178 | rdev = tmp; | |
a9455408 | 179 | } |
a9455408 | 180 | } |
a9455408 | 181 | |
4f7eff10 JB |
182 | if (!rdev) |
183 | return ERR_PTR(-ENODEV); | |
a9455408 | 184 | |
4f7eff10 JB |
185 | if (netns != wiphy_net(&rdev->wiphy)) |
186 | return ERR_PTR(-ENODEV); | |
187 | ||
188 | return rdev; | |
a9455408 JB |
189 | } |
190 | ||
191 | /* | |
192 | * This function returns a pointer to the driver | |
193 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
194 | * |
195 | * The result of this can be a PTR_ERR and hence must | |
196 | * be checked with IS_ERR() for errors. | |
197 | */ | |
198 | static struct cfg80211_registered_device * | |
4f7eff10 | 199 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 200 | { |
5fe231e8 | 201 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
202 | } |
203 | ||
3d7af878 JB |
204 | static int validate_ie_attr(const struct nlattr *attr, |
205 | struct netlink_ext_ack *extack) | |
206 | { | |
9f308616 JB |
207 | const u8 *data = nla_data(attr); |
208 | unsigned int len = nla_len(attr); | |
7388afe0 | 209 | const struct element *elem; |
3d7af878 | 210 | |
9f308616 JB |
211 | for_each_element(elem, data, len) { |
212 | /* nothing */ | |
3d7af878 JB |
213 | } |
214 | ||
9f308616 JB |
215 | if (for_each_element_completed(elem, data, len)) |
216 | return 0; | |
217 | ||
3d7af878 JB |
218 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements"); |
219 | return -EINVAL; | |
220 | } | |
221 | ||
55682965 | 222 | /* policy for the attributes */ |
81e54d08 PKC |
223 | static const struct nla_policy |
224 | nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = { | |
225 | [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, }, | |
226 | [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY, | |
227 | .len = U8_MAX }, | |
228 | [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY, | |
229 | .len = U8_MAX }, | |
230 | }; | |
231 | ||
9bb7e0f2 JB |
232 | static const struct nla_policy |
233 | nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = { | |
234 | [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG }, | |
235 | [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 }, | |
236 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] = | |
237 | NLA_POLICY_MAX(NLA_U8, 15), | |
238 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 }, | |
239 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] = | |
240 | NLA_POLICY_MAX(NLA_U8, 15), | |
241 | [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] = | |
ea18709a | 242 | NLA_POLICY_MAX(NLA_U8, 31), |
9bb7e0f2 JB |
243 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 }, |
244 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG }, | |
245 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG }, | |
246 | }; | |
247 | ||
248 | static const struct nla_policy | |
249 | nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = { | |
250 | [NL80211_PMSR_TYPE_FTM] = | |
23323289 | 251 | NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy), |
9bb7e0f2 JB |
252 | }; |
253 | ||
254 | static const struct nla_policy | |
255 | nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = { | |
256 | [NL80211_PMSR_REQ_ATTR_DATA] = | |
23323289 | 257 | NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy), |
9bb7e0f2 JB |
258 | [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG }, |
259 | }; | |
260 | ||
261 | static const struct nla_policy | |
262 | nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = { | |
263 | [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR, | |
264 | /* | |
265 | * we could specify this again to be the top-level policy, | |
266 | * but that would open us up to recursion problems ... | |
267 | */ | |
268 | [NL80211_PMSR_PEER_ATTR_CHAN] = { .type = NLA_NESTED }, | |
269 | [NL80211_PMSR_PEER_ATTR_REQ] = | |
23323289 | 270 | NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy), |
9bb7e0f2 JB |
271 | [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT }, |
272 | }; | |
273 | ||
274 | static const struct nla_policy | |
275 | nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = { | |
276 | [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT }, | |
277 | [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT }, | |
278 | [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT }, | |
279 | [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT }, | |
280 | [NL80211_PMSR_ATTR_PEERS] = | |
23323289 | 281 | NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy), |
9bb7e0f2 JB |
282 | }; |
283 | ||
284 | const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { | |
55682965 JB |
285 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
286 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 287 | .len = 20-1 }, |
31888487 | 288 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 289 | |
72bdcf34 | 290 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 291 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
292 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
293 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
294 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
295 | ||
ab0d76f6 JB |
296 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), |
297 | [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), | |
b9a5f8ca JM |
298 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
299 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 300 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
3057dbfd | 301 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
55682965 | 302 | |
ab0d76f6 | 303 | [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX), |
55682965 JB |
304 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
305 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 306 | |
1a28ed21 JB |
307 | [NL80211_ATTR_MAC] = { .type = NLA_EXACT_LEN_WARN, .len = ETH_ALEN }, |
308 | [NL80211_ATTR_PREV_BSSID] = { | |
309 | .type = NLA_EXACT_LEN_WARN, | |
310 | .len = ETH_ALEN | |
311 | }, | |
41ade00f | 312 | |
b9454e83 | 313 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
314 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
315 | .len = WLAN_MAX_KEY_LEN }, | |
ab0d76f6 | 316 | [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 5), |
41ade00f JB |
317 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
318 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 319 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
ab0d76f6 JB |
320 | [NL80211_ATTR_KEY_TYPE] = |
321 | NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES), | |
ed1b6cc7 JB |
322 | |
323 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
324 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
325 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
326 | .len = IEEE80211_MAX_DATA_LEN }, | |
3d7af878 JB |
327 | [NL80211_ATTR_BEACON_TAIL] = |
328 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, | |
329 | IEEE80211_MAX_DATA_LEN), | |
ab0d76f6 JB |
330 | [NL80211_ATTR_STA_AID] = |
331 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), | |
5727ef1b JB |
332 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
333 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
334 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
335 | .len = NL80211_MAX_SUPP_RATES }, | |
ab0d76f6 JB |
336 | [NL80211_ATTR_STA_PLINK_ACTION] = |
337 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1), | |
e96d1cd2 ARN |
338 | [NL80211_ATTR_STA_TX_POWER_SETTING] = |
339 | NLA_POLICY_RANGE(NLA_U8, | |
340 | NL80211_TX_POWER_AUTOMATIC, | |
341 | NL80211_TX_POWER_FIXED), | |
342 | [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 }, | |
5727ef1b | 343 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 344 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 345 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 346 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 347 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 348 | |
b2e1b302 LR |
349 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
350 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
351 | ||
9f1ba906 JM |
352 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
353 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
354 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
355 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
356 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 357 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 358 | |
24bdd9f4 | 359 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 360 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 361 | |
1a28ed21 JB |
362 | [NL80211_ATTR_HT_CAPABILITY] = { |
363 | .type = NLA_EXACT_LEN_WARN, | |
364 | .len = NL80211_HT_CAPABILITY_LEN | |
365 | }, | |
9aed3cc1 JM |
366 | |
367 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
3d7af878 JB |
368 | [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, |
369 | validate_ie_attr, | |
370 | IEEE80211_MAX_DATA_LEN), | |
2a519311 JB |
371 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
372 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
373 | |
374 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
375 | .len = IEEE80211_MAX_SSID_LEN }, | |
376 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
377 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 378 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 379 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
ab0d76f6 JB |
380 | [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32, |
381 | NL80211_MFP_NO, | |
382 | NL80211_MFP_OPTIONAL), | |
eccb8e8f JB |
383 | [NL80211_ATTR_STA_FLAGS2] = { |
384 | .len = sizeof(struct nl80211_sta_flag_update), | |
385 | }, | |
3f77316c | 386 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
387 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
388 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
64bf3d4b | 389 | [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG }, |
b23aa676 SO |
390 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
391 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
392 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 393 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 394 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
1a28ed21 JB |
395 | [NL80211_ATTR_PMKID] = { |
396 | .type = NLA_EXACT_LEN_WARN, | |
397 | .len = WLAN_PMKID_LEN | |
398 | }, | |
9588bbd5 JM |
399 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
400 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 401 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
402 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
403 | .len = IEEE80211_MAX_DATA_LEN }, | |
404 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ab0d76f6 JB |
405 | [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32, |
406 | NL80211_PS_DISABLED, | |
407 | NL80211_PS_ENABLED), | |
d6dc1a38 | 408 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 409 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 410 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
411 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
412 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 413 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
414 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
415 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 416 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 417 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 418 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 419 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
ab0d76f6 JB |
420 | [NL80211_ATTR_STA_PLINK_STATE] = |
421 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1), | |
422 | [NL80211_ATTR_MESH_PEER_AID] = | |
423 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), | |
bbe6ad6d | 424 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 425 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 426 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
ab0d76f6 JB |
427 | [NL80211_ATTR_HIDDEN_SSID] = |
428 | NLA_POLICY_RANGE(NLA_U32, | |
429 | NL80211_HIDDEN_SSID_NOT_IN_USE, | |
430 | NL80211_HIDDEN_SSID_ZERO_CONTENTS), | |
3d7af878 JB |
431 | [NL80211_ATTR_IE_PROBE_RESP] = |
432 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, | |
433 | IEEE80211_MAX_DATA_LEN), | |
434 | [NL80211_ATTR_IE_ASSOC_RESP] = | |
435 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, | |
436 | IEEE80211_MAX_DATA_LEN), | |
f4b34b55 | 437 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 438 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 439 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
440 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
441 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
442 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
443 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
444 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
31fa97c5 | 445 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
e247bd90 | 446 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
447 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
448 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 449 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
450 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
451 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
452 | .len = NL80211_HT_CAPABILITY_LEN | |
453 | }, | |
1d9d9213 | 454 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 455 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 456 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 457 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 458 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
11b6b5a4 | 459 | [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, }, |
1a28ed21 JB |
460 | [NL80211_ATTR_VHT_CAPABILITY] = { |
461 | .type = NLA_EXACT_LEN_WARN, | |
462 | .len = NL80211_VHT_CAPABILITY_LEN | |
463 | }, | |
ed473771 | 464 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
ab0d76f6 JB |
465 | [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127), |
466 | [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1), | |
467 | [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = | |
468 | NLA_POLICY_RANGE(NLA_U32, | |
469 | NL80211_MESH_POWER_UNKNOWN + 1, | |
470 | NL80211_MESH_POWER_MAX), | |
77765eaf VT |
471 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
472 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
473 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
474 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 475 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
476 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
477 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
478 | .len = NL80211_VHT_CAPABILITY_LEN, | |
479 | }, | |
355199e0 JM |
480 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
481 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
482 | .len = IEEE80211_MAX_DATA_LEN }, | |
ab0d76f6 JB |
483 | [NL80211_ATTR_PEER_AID] = |
484 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), | |
16ef1fe2 SW |
485 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
486 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
487 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
9a774c78 AO |
488 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
489 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, | |
c01fc9ad SD |
490 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
491 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | |
5336fa88 | 492 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
60f4a7b1 | 493 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
ad7e718c JB |
494 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
495 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | |
496 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | |
fa9ffc74 KP |
497 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
498 | .len = IEEE80211_QOS_MAP_LEN_MAX }, | |
1a28ed21 JB |
499 | [NL80211_ATTR_MAC_HINT] = { |
500 | .type = NLA_EXACT_LEN_WARN, | |
501 | .len = ETH_ALEN | |
502 | }, | |
1df4a510 | 503 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
df942e7b | 504 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
18e5ca65 | 505 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
34d22ce2 | 506 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
bab5ab7d | 507 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
ab0d76f6 JB |
508 | [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1), |
509 | [NL80211_ATTR_USER_PRIO] = | |
510 | NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1), | |
960d01ac | 511 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
18998c38 | 512 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
1a28ed21 JB |
513 | [NL80211_ATTR_MAC_MASK] = { |
514 | .type = NLA_EXACT_LEN_WARN, | |
515 | .len = ETH_ALEN | |
516 | }, | |
1bdd716c | 517 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
4b681c82 | 518 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
9c748934 | 519 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
05050753 | 520 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
34d50519 | 521 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
38de03d2 | 522 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
ab0d76f6 JB |
523 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = |
524 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1), | |
c6e6a0c8 AE |
525 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
526 | .len = VHT_MUMIMO_GROUPS_DATA_LEN | |
527 | }, | |
1a28ed21 JB |
528 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { |
529 | .type = NLA_EXACT_LEN_WARN, | |
530 | .len = ETH_ALEN | |
531 | }, | |
ab0d76f6 | 532 | [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1), |
8585989d | 533 | [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, |
a442b761 | 534 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, |
348bd456 JM |
535 | [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, |
536 | .len = FILS_MAX_KEK_LEN }, | |
1a28ed21 JB |
537 | [NL80211_ATTR_FILS_NONCES] = { |
538 | .type = NLA_EXACT_LEN_WARN, | |
539 | .len = 2 * FILS_NONCE_LEN | |
540 | }, | |
ce0ce13a | 541 | [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, |
1a28ed21 | 542 | [NL80211_ATTR_BSSID] = { .type = NLA_EXACT_LEN_WARN, .len = ETH_ALEN }, |
bf95ecdb | 543 | [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, |
544 | [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { | |
545 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) | |
546 | }, | |
3093ebbe | 547 | [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, |
a3caf744 VK |
548 | [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, |
549 | .len = FILS_ERP_MAX_USERNAME_LEN }, | |
550 | [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, | |
551 | .len = FILS_ERP_MAX_REALM_LEN }, | |
552 | [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, | |
553 | [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, | |
554 | .len = FILS_ERP_MAX_RRK_LEN }, | |
1a28ed21 | 555 | [NL80211_ATTR_FILS_CACHE_ID] = { .type = NLA_EXACT_LEN_WARN, .len = 2 }, |
a3caf744 | 556 | [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, |
ca986ad9 | 557 | [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, |
40cbfa90 | 558 | [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, |
52539ca8 THJ |
559 | |
560 | [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 }, | |
561 | [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 }, | |
562 | [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 }, | |
c4cbaf79 LC |
563 | [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY, |
564 | .len = NL80211_HE_MAX_CAPABILITY_LEN }, | |
81e54d08 PKC |
565 | |
566 | [NL80211_ATTR_FTM_RESPONDER] = { | |
567 | .type = NLA_NESTED, | |
568 | .validation_data = nl80211_ftm_responder_policy, | |
569 | }, | |
9bb7e0f2 JB |
570 | [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1), |
571 | [NL80211_ATTR_PEER_MEASUREMENTS] = | |
23323289 | 572 | NLA_POLICY_NESTED(nl80211_pmsr_attr_policy), |
36647055 | 573 | [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1), |
55682965 JB |
574 | }; |
575 | ||
e31b8213 | 576 | /* policy for the key attributes */ |
b54452b0 | 577 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 578 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
579 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
580 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 581 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
582 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
583 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
ab0d76f6 | 584 | [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1), |
dbd2fd65 | 585 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
6cdd3979 | 586 | [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX), |
dbd2fd65 JB |
587 | }; |
588 | ||
589 | /* policy for the key default flags */ | |
590 | static const struct nla_policy | |
591 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
592 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
593 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
594 | }; |
595 | ||
f83ace3b | 596 | #ifdef CONFIG_PM |
ff1b6e69 JB |
597 | /* policy for WoWLAN attributes */ |
598 | static const struct nla_policy | |
599 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
600 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
601 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
602 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
603 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
604 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
605 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
606 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
607 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e | 608 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
8cd4d456 | 609 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
2a0e047e JB |
610 | }; |
611 | ||
612 | static const struct nla_policy | |
613 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
614 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
615 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
1a28ed21 JB |
616 | [NL80211_WOWLAN_TCP_DST_MAC] = { |
617 | .type = NLA_EXACT_LEN_WARN, | |
618 | .len = ETH_ALEN | |
619 | }, | |
2a0e047e JB |
620 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
621 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
1a28ed21 | 622 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 }, |
2a0e047e JB |
623 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
624 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
625 | }, | |
626 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
627 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
628 | }, | |
629 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
1a28ed21 JB |
630 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 }, |
631 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .type = NLA_MIN_LEN, .len = 1 }, | |
ff1b6e69 | 632 | }; |
f83ace3b | 633 | #endif /* CONFIG_PM */ |
ff1b6e69 | 634 | |
be29b99a AK |
635 | /* policy for coalesce rule attributes */ |
636 | static const struct nla_policy | |
637 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
638 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
ab0d76f6 JB |
639 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = |
640 | NLA_POLICY_RANGE(NLA_U32, | |
641 | NL80211_COALESCE_CONDITION_MATCH, | |
642 | NL80211_COALESCE_CONDITION_NO_MATCH), | |
be29b99a AK |
643 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
644 | }; | |
645 | ||
e5497d76 JB |
646 | /* policy for GTK rekey offload attributes */ |
647 | static const struct nla_policy | |
648 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
1a28ed21 JB |
649 | [NL80211_REKEY_DATA_KEK] = { .type = NLA_EXACT_LEN_WARN, .len = NL80211_KEK_LEN }, |
650 | [NL80211_REKEY_DATA_KCK] = { .type = NLA_EXACT_LEN_WARN, .len = NL80211_KCK_LEN }, | |
651 | [NL80211_REKEY_DATA_REPLAY_CTR] = { | |
652 | .type = NLA_EXACT_LEN_WARN, | |
653 | .len = NL80211_REPLAY_CTR_LEN | |
654 | }, | |
e5497d76 JB |
655 | }; |
656 | ||
1e1b11b6 | 657 | static const struct nla_policy |
658 | nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = { | |
659 | [NL80211_BAND_2GHZ] = { .type = NLA_S32 }, | |
660 | [NL80211_BAND_5GHZ] = { .type = NLA_S32 }, | |
661 | [NL80211_BAND_60GHZ] = { .type = NLA_S32 }, | |
662 | }; | |
663 | ||
a1f1c21c LC |
664 | static const struct nla_policy |
665 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 666 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 667 | .len = IEEE80211_MAX_SSID_LEN }, |
1a28ed21 JB |
668 | [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { |
669 | .type = NLA_EXACT_LEN_WARN, | |
670 | .len = ETH_ALEN | |
671 | }, | |
88e920b4 | 672 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
1e1b11b6 | 673 | [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] = |
674 | NLA_POLICY_NESTED(nl80211_match_band_rssi_policy), | |
a1f1c21c LC |
675 | }; |
676 | ||
3b06d277 AS |
677 | static const struct nla_policy |
678 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { | |
679 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, | |
680 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, | |
681 | }; | |
682 | ||
38de03d2 AS |
683 | static const struct nla_policy |
684 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { | |
685 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, | |
686 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, | |
687 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { | |
688 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) | |
689 | }, | |
690 | }; | |
691 | ||
a442b761 AB |
692 | /* policy for NAN function attributes */ |
693 | static const struct nla_policy | |
694 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { | |
695 | [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 }, | |
0a27844c | 696 | [NL80211_NAN_FUNC_SERVICE_ID] = { |
a442b761 AB |
697 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, |
698 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, | |
699 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, | |
700 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, | |
701 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, | |
702 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, | |
1a28ed21 JB |
703 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { |
704 | .type = NLA_EXACT_LEN_WARN, | |
705 | .len = ETH_ALEN | |
706 | }, | |
a442b761 AB |
707 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, |
708 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, | |
709 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, | |
710 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, | |
711 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, | |
712 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, | |
713 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, | |
714 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, | |
715 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, | |
716 | }; | |
717 | ||
718 | /* policy for Service Response Filter attributes */ | |
719 | static const struct nla_policy | |
720 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { | |
721 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, | |
722 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, | |
723 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, | |
724 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, | |
725 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, | |
726 | }; | |
727 | ||
ad670233 PX |
728 | /* policy for packet pattern attributes */ |
729 | static const struct nla_policy | |
730 | nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { | |
731 | [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, | |
732 | [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, | |
733 | [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, | |
734 | }; | |
735 | ||
9bb7e0f2 JB |
736 | int nl80211_prepare_wdev_dump(struct netlink_callback *cb, |
737 | struct cfg80211_registered_device **rdev, | |
738 | struct wireless_dev **wdev) | |
a043897a | 739 | { |
97990a06 | 740 | int err; |
a043897a | 741 | |
97990a06 | 742 | if (!cb->args[0]) { |
8cb08174 JB |
743 | err = nlmsg_parse_deprecated(cb->nlh, |
744 | GENL_HDRLEN + nl80211_fam.hdrsize, | |
745 | genl_family_attrbuf(&nl80211_fam), | |
746 | nl80211_fam.maxattr, | |
747 | nl80211_policy, NULL); | |
97990a06 | 748 | if (err) |
ea90e0dc | 749 | return err; |
67748893 | 750 | |
c90c39da | 751 | *wdev = __cfg80211_wdev_from_attrs( |
5297c65c | 752 | sock_net(cb->skb->sk), |
c90c39da | 753 | genl_family_attrbuf(&nl80211_fam)); |
ea90e0dc JB |
754 | if (IS_ERR(*wdev)) |
755 | return PTR_ERR(*wdev); | |
f26cbf40 | 756 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
757 | /* 0 is the first index - add 1 to parse only once */ |
758 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
759 | cb->args[1] = (*wdev)->identifier; |
760 | } else { | |
c319d50b JB |
761 | /* subtract the 1 again here */ |
762 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 763 | struct wireless_dev *tmp; |
67748893 | 764 | |
ea90e0dc JB |
765 | if (!wiphy) |
766 | return -ENODEV; | |
f26cbf40 | 767 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 768 | *wdev = NULL; |
67748893 | 769 | |
53873f13 | 770 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
97990a06 JB |
771 | if (tmp->identifier == cb->args[1]) { |
772 | *wdev = tmp; | |
773 | break; | |
774 | } | |
775 | } | |
67748893 | 776 | |
ea90e0dc JB |
777 | if (!*wdev) |
778 | return -ENODEV; | |
67748893 JB |
779 | } |
780 | ||
67748893 | 781 | return 0; |
67748893 JB |
782 | } |
783 | ||
55682965 | 784 | /* message building helper */ |
9bb7e0f2 JB |
785 | void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
786 | int flags, u8 cmd) | |
55682965 JB |
787 | { |
788 | /* since there is no private header just add the generic one */ | |
15e47304 | 789 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
790 | } |
791 | ||
50f32718 HD |
792 | static int nl80211_msg_put_wmm_rules(struct sk_buff *msg, |
793 | const struct ieee80211_reg_rule *rule) | |
794 | { | |
795 | int j; | |
796 | struct nlattr *nl_wmm_rules = | |
ae0be8de | 797 | nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM); |
50f32718 HD |
798 | |
799 | if (!nl_wmm_rules) | |
800 | goto nla_put_failure; | |
801 | ||
802 | for (j = 0; j < IEEE80211_NUM_ACS; j++) { | |
ae0be8de | 803 | struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j); |
50f32718 HD |
804 | |
805 | if (!nl_wmm_rule) | |
806 | goto nla_put_failure; | |
807 | ||
808 | if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, | |
38cb87ee | 809 | rule->wmm_rule.client[j].cw_min) || |
50f32718 | 810 | nla_put_u16(msg, NL80211_WMMR_CW_MAX, |
38cb87ee | 811 | rule->wmm_rule.client[j].cw_max) || |
50f32718 | 812 | nla_put_u8(msg, NL80211_WMMR_AIFSN, |
38cb87ee | 813 | rule->wmm_rule.client[j].aifsn) || |
d3c89bbc HD |
814 | nla_put_u16(msg, NL80211_WMMR_TXOP, |
815 | rule->wmm_rule.client[j].cot)) | |
50f32718 HD |
816 | goto nla_put_failure; |
817 | ||
818 | nla_nest_end(msg, nl_wmm_rule); | |
819 | } | |
820 | nla_nest_end(msg, nl_wmm_rules); | |
821 | ||
822 | return 0; | |
823 | ||
824 | nla_put_failure: | |
825 | return -ENOBUFS; | |
826 | } | |
827 | ||
828 | static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy, | |
cdc89b97 JB |
829 | struct ieee80211_channel *chan, |
830 | bool large) | |
5dab3b8a | 831 | { |
ea077c1c RL |
832 | /* Some channels must be completely excluded from the |
833 | * list to protect old user-space tools from breaking | |
834 | */ | |
835 | if (!large && chan->flags & | |
836 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
837 | return 0; | |
838 | ||
9360ffd1 DM |
839 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
840 | chan->center_freq)) | |
841 | goto nla_put_failure; | |
5dab3b8a | 842 | |
9360ffd1 DM |
843 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
844 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
845 | goto nla_put_failure; | |
8fe02e16 LR |
846 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
847 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
848 | goto nla_put_failure; | |
849 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
850 | goto nla_put_failure; | |
851 | } | |
cdc89b97 JB |
852 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
853 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
854 | goto nla_put_failure; | |
855 | if (large) { | |
856 | u32 time; | |
857 | ||
858 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
859 | ||
860 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
861 | chan->dfs_state)) | |
862 | goto nla_put_failure; | |
863 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
864 | time)) | |
865 | goto nla_put_failure; | |
089027e5 JD |
866 | if (nla_put_u32(msg, |
867 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
868 | chan->dfs_cac_ms)) | |
869 | goto nla_put_failure; | |
cdc89b97 JB |
870 | } |
871 | } | |
5dab3b8a | 872 | |
fe1abafd JB |
873 | if (large) { |
874 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
875 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
876 | goto nla_put_failure; | |
877 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
878 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
879 | goto nla_put_failure; | |
880 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
881 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
882 | goto nla_put_failure; | |
883 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
884 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
885 | goto nla_put_failure; | |
570dbde1 DS |
886 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
887 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
888 | goto nla_put_failure; | |
06f207fc AN |
889 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
890 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) | |
570dbde1 | 891 | goto nla_put_failure; |
ea077c1c RL |
892 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
893 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
894 | goto nla_put_failure; | |
895 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
896 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
897 | goto nla_put_failure; | |
fe1abafd JB |
898 | } |
899 | ||
9360ffd1 DM |
900 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
901 | DBM_TO_MBM(chan->max_power))) | |
902 | goto nla_put_failure; | |
5dab3b8a | 903 | |
50f32718 HD |
904 | if (large) { |
905 | const struct ieee80211_reg_rule *rule = | |
b88d26d9 | 906 | freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); |
50f32718 | 907 | |
38cb87ee | 908 | if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { |
50f32718 HD |
909 | if (nl80211_msg_put_wmm_rules(msg, rule)) |
910 | goto nla_put_failure; | |
911 | } | |
912 | } | |
913 | ||
5dab3b8a LR |
914 | return 0; |
915 | ||
916 | nla_put_failure: | |
917 | return -ENOBUFS; | |
918 | } | |
919 | ||
52539ca8 THJ |
920 | static bool nl80211_put_txq_stats(struct sk_buff *msg, |
921 | struct cfg80211_txq_stats *txqstats, | |
922 | int attrtype) | |
923 | { | |
924 | struct nlattr *txqattr; | |
925 | ||
926 | #define PUT_TXQVAL_U32(attr, memb) do { \ | |
927 | if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \ | |
928 | nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ | |
929 | return false; \ | |
930 | } while (0) | |
931 | ||
ae0be8de | 932 | txqattr = nla_nest_start_noflag(msg, attrtype); |
52539ca8 THJ |
933 | if (!txqattr) |
934 | return false; | |
935 | ||
936 | PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); | |
937 | PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); | |
938 | PUT_TXQVAL_U32(FLOWS, flows); | |
939 | PUT_TXQVAL_U32(DROPS, drops); | |
940 | PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); | |
941 | PUT_TXQVAL_U32(OVERLIMIT, overlimit); | |
942 | PUT_TXQVAL_U32(OVERMEMORY, overmemory); | |
943 | PUT_TXQVAL_U32(COLLISIONS, collisions); | |
944 | PUT_TXQVAL_U32(TX_BYTES, tx_bytes); | |
945 | PUT_TXQVAL_U32(TX_PACKETS, tx_packets); | |
946 | PUT_TXQVAL_U32(MAX_FLOWS, max_flows); | |
947 | nla_nest_end(msg, txqattr); | |
948 | ||
949 | #undef PUT_TXQVAL_U32 | |
950 | return true; | |
951 | } | |
952 | ||
55682965 JB |
953 | /* netlink command implementations */ |
954 | ||
b9454e83 JB |
955 | struct key_parse { |
956 | struct key_params p; | |
957 | int idx; | |
e31b8213 | 958 | int type; |
b9454e83 | 959 | bool def, defmgmt; |
dbd2fd65 | 960 | bool def_uni, def_multi; |
b9454e83 JB |
961 | }; |
962 | ||
768075eb JB |
963 | static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, |
964 | struct key_parse *k) | |
b9454e83 JB |
965 | { |
966 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
8cb08174 JB |
967 | int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key, |
968 | nl80211_key_policy, | |
969 | info->extack); | |
b9454e83 JB |
970 | if (err) |
971 | return err; | |
972 | ||
973 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
974 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
975 | ||
dbd2fd65 JB |
976 | if (k->def) { |
977 | k->def_uni = true; | |
978 | k->def_multi = true; | |
979 | } | |
980 | if (k->defmgmt) | |
981 | k->def_multi = true; | |
982 | ||
b9454e83 JB |
983 | if (tb[NL80211_KEY_IDX]) |
984 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
985 | ||
986 | if (tb[NL80211_KEY_DATA]) { | |
987 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
988 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
989 | } | |
990 | ||
991 | if (tb[NL80211_KEY_SEQ]) { | |
992 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
993 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
994 | } | |
995 | ||
996 | if (tb[NL80211_KEY_CIPHER]) | |
997 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
998 | ||
ab0d76f6 | 999 | if (tb[NL80211_KEY_TYPE]) |
e31b8213 | 1000 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
e31b8213 | 1001 | |
dbd2fd65 JB |
1002 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
1003 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
7a087e74 | 1004 | |
8cb08174 JB |
1005 | err = nla_parse_nested_deprecated(kdt, |
1006 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
1007 | tb[NL80211_KEY_DEFAULT_TYPES], | |
1008 | nl80211_key_default_policy, | |
1009 | info->extack); | |
dbd2fd65 JB |
1010 | if (err) |
1011 | return err; | |
1012 | ||
1013 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
1014 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
1015 | } | |
1016 | ||
6cdd3979 AW |
1017 | if (tb[NL80211_KEY_MODE]) |
1018 | k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]); | |
1019 | ||
b9454e83 JB |
1020 | return 0; |
1021 | } | |
1022 | ||
1023 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
1024 | { | |
1025 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
1026 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
1027 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
1028 | } | |
1029 | ||
1030 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
1031 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
1032 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
1033 | } | |
1034 | ||
1035 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
1036 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
1037 | ||
1038 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
1039 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
1040 | ||
1041 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
1042 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
1043 | ||
dbd2fd65 JB |
1044 | if (k->def) { |
1045 | k->def_uni = true; | |
1046 | k->def_multi = true; | |
1047 | } | |
1048 | if (k->defmgmt) | |
1049 | k->def_multi = true; | |
1050 | ||
ab0d76f6 | 1051 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) |
e31b8213 | 1052 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
e31b8213 | 1053 | |
dbd2fd65 JB |
1054 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
1055 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
8cb08174 JB |
1056 | int err = nla_parse_nested_deprecated(kdt, |
1057 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
1058 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
1059 | nl80211_key_default_policy, | |
1060 | info->extack); | |
dbd2fd65 JB |
1061 | if (err) |
1062 | return err; | |
1063 | ||
1064 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
1065 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
1066 | } | |
1067 | ||
b9454e83 JB |
1068 | return 0; |
1069 | } | |
1070 | ||
1071 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
1072 | { | |
1073 | int err; | |
1074 | ||
1075 | memset(k, 0, sizeof(*k)); | |
1076 | k->idx = -1; | |
e31b8213 | 1077 | k->type = -1; |
b9454e83 JB |
1078 | |
1079 | if (info->attrs[NL80211_ATTR_KEY]) | |
768075eb | 1080 | err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); |
b9454e83 JB |
1081 | else |
1082 | err = nl80211_parse_key_old(info, k); | |
1083 | ||
1084 | if (err) | |
1085 | return err; | |
1086 | ||
768075eb JB |
1087 | if (k->def && k->defmgmt) { |
1088 | GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid"); | |
b9454e83 | 1089 | return -EINVAL; |
768075eb | 1090 | } |
b9454e83 | 1091 | |
dbd2fd65 | 1092 | if (k->defmgmt) { |
768075eb JB |
1093 | if (k->def_uni || !k->def_multi) { |
1094 | GENL_SET_ERR_MSG(info, "defmgmt key must be mcast"); | |
dbd2fd65 | 1095 | return -EINVAL; |
768075eb | 1096 | } |
dbd2fd65 JB |
1097 | } |
1098 | ||
b9454e83 JB |
1099 | if (k->idx != -1) { |
1100 | if (k->defmgmt) { | |
768075eb JB |
1101 | if (k->idx < 4 || k->idx > 5) { |
1102 | GENL_SET_ERR_MSG(info, | |
1103 | "defmgmt key idx not 4 or 5"); | |
b9454e83 | 1104 | return -EINVAL; |
768075eb | 1105 | } |
b9454e83 | 1106 | } else if (k->def) { |
768075eb JB |
1107 | if (k->idx < 0 || k->idx > 3) { |
1108 | GENL_SET_ERR_MSG(info, "def key idx not 0-3"); | |
b9454e83 | 1109 | return -EINVAL; |
768075eb | 1110 | } |
b9454e83 | 1111 | } else { |
768075eb JB |
1112 | if (k->idx < 0 || k->idx > 5) { |
1113 | GENL_SET_ERR_MSG(info, "key idx not 0-5"); | |
b9454e83 | 1114 | return -EINVAL; |
768075eb | 1115 | } |
b9454e83 JB |
1116 | } |
1117 | } | |
1118 | ||
1119 | return 0; | |
1120 | } | |
1121 | ||
fffd0934 JB |
1122 | static struct cfg80211_cached_keys * |
1123 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
768075eb | 1124 | struct genl_info *info, bool *no_ht) |
fffd0934 | 1125 | { |
768075eb | 1126 | struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; |
fffd0934 JB |
1127 | struct key_parse parse; |
1128 | struct nlattr *key; | |
1129 | struct cfg80211_cached_keys *result; | |
1130 | int rem, err, def = 0; | |
f1c1f17a JB |
1131 | bool have_key = false; |
1132 | ||
1133 | nla_for_each_nested(key, keys, rem) { | |
1134 | have_key = true; | |
1135 | break; | |
1136 | } | |
1137 | ||
1138 | if (!have_key) | |
1139 | return NULL; | |
fffd0934 JB |
1140 | |
1141 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
1142 | if (!result) | |
1143 | return ERR_PTR(-ENOMEM); | |
1144 | ||
1145 | result->def = -1; | |
fffd0934 JB |
1146 | |
1147 | nla_for_each_nested(key, keys, rem) { | |
1148 | memset(&parse, 0, sizeof(parse)); | |
1149 | parse.idx = -1; | |
1150 | ||
768075eb | 1151 | err = nl80211_parse_key_new(info, key, &parse); |
fffd0934 JB |
1152 | if (err) |
1153 | goto error; | |
1154 | err = -EINVAL; | |
1155 | if (!parse.p.key) | |
1156 | goto error; | |
768075eb JB |
1157 | if (parse.idx < 0 || parse.idx > 3) { |
1158 | GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); | |
fffd0934 | 1159 | goto error; |
768075eb | 1160 | } |
fffd0934 | 1161 | if (parse.def) { |
768075eb JB |
1162 | if (def) { |
1163 | GENL_SET_ERR_MSG(info, | |
1164 | "only one key can be default"); | |
fffd0934 | 1165 | goto error; |
768075eb | 1166 | } |
fffd0934 JB |
1167 | def = 1; |
1168 | result->def = parse.idx; | |
dbd2fd65 JB |
1169 | if (!parse.def_uni || !parse.def_multi) |
1170 | goto error; | |
fffd0934 JB |
1171 | } else if (parse.defmgmt) |
1172 | goto error; | |
1173 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 1174 | parse.idx, false, NULL); |
fffd0934 JB |
1175 | if (err) |
1176 | goto error; | |
386b1f27 JB |
1177 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
1178 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { | |
768075eb | 1179 | GENL_SET_ERR_MSG(info, "connect key must be WEP"); |
386b1f27 JB |
1180 | err = -EINVAL; |
1181 | goto error; | |
1182 | } | |
fffd0934 JB |
1183 | result->params[parse.idx].cipher = parse.p.cipher; |
1184 | result->params[parse.idx].key_len = parse.p.key_len; | |
1185 | result->params[parse.idx].key = result->data[parse.idx]; | |
1186 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee | 1187 | |
386b1f27 JB |
1188 | /* must be WEP key if we got here */ |
1189 | if (no_ht) | |
1190 | *no_ht = true; | |
fffd0934 JB |
1191 | } |
1192 | ||
f1c1f17a JB |
1193 | if (result->def < 0) { |
1194 | err = -EINVAL; | |
768075eb | 1195 | GENL_SET_ERR_MSG(info, "need a default/TX key"); |
f1c1f17a JB |
1196 | goto error; |
1197 | } | |
1198 | ||
fffd0934 JB |
1199 | return result; |
1200 | error: | |
1201 | kfree(result); | |
1202 | return ERR_PTR(err); | |
1203 | } | |
1204 | ||
1205 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
1206 | { | |
1207 | ASSERT_WDEV_LOCK(wdev); | |
1208 | ||
fffd0934 JB |
1209 | switch (wdev->iftype) { |
1210 | case NL80211_IFTYPE_AP: | |
1211 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 1212 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 1213 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
1214 | break; |
1215 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 1216 | case NL80211_IFTYPE_STATION: |
074ac8df | 1217 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 1218 | if (!wdev->current_bss) |
fffd0934 JB |
1219 | return -ENOLINK; |
1220 | break; | |
de4fcbad | 1221 | case NL80211_IFTYPE_UNSPECIFIED: |
6e0bd6c3 | 1222 | case NL80211_IFTYPE_OCB: |
de4fcbad | 1223 | case NL80211_IFTYPE_MONITOR: |
cb3b7d87 | 1224 | case NL80211_IFTYPE_NAN: |
de4fcbad JB |
1225 | case NL80211_IFTYPE_P2P_DEVICE: |
1226 | case NL80211_IFTYPE_WDS: | |
1227 | case NUM_NL80211_IFTYPES: | |
fffd0934 JB |
1228 | return -EINVAL; |
1229 | } | |
1230 | ||
1231 | return 0; | |
1232 | } | |
1233 | ||
664834de JM |
1234 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
1235 | struct nlattr *tb) | |
1236 | { | |
1237 | struct ieee80211_channel *chan; | |
1238 | ||
1239 | if (tb == NULL) | |
1240 | return NULL; | |
1241 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
1242 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
1243 | return NULL; | |
1244 | return chan; | |
1245 | } | |
1246 | ||
7527a782 JB |
1247 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
1248 | { | |
ae0be8de | 1249 | struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr); |
7527a782 JB |
1250 | int i; |
1251 | ||
1252 | if (!nl_modes) | |
1253 | goto nla_put_failure; | |
1254 | ||
1255 | i = 0; | |
1256 | while (ifmodes) { | |
9360ffd1 DM |
1257 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
1258 | goto nla_put_failure; | |
7527a782 JB |
1259 | ifmodes >>= 1; |
1260 | i++; | |
1261 | } | |
1262 | ||
1263 | nla_nest_end(msg, nl_modes); | |
1264 | return 0; | |
1265 | ||
1266 | nla_put_failure: | |
1267 | return -ENOBUFS; | |
1268 | } | |
1269 | ||
1270 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
1271 | struct sk_buff *msg, |
1272 | bool large) | |
7527a782 JB |
1273 | { |
1274 | struct nlattr *nl_combis; | |
1275 | int i, j; | |
1276 | ||
ae0be8de MK |
1277 | nl_combis = nla_nest_start_noflag(msg, |
1278 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
7527a782 JB |
1279 | if (!nl_combis) |
1280 | goto nla_put_failure; | |
1281 | ||
1282 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
1283 | const struct ieee80211_iface_combination *c; | |
1284 | struct nlattr *nl_combi, *nl_limits; | |
1285 | ||
1286 | c = &wiphy->iface_combinations[i]; | |
1287 | ||
ae0be8de | 1288 | nl_combi = nla_nest_start_noflag(msg, i + 1); |
7527a782 JB |
1289 | if (!nl_combi) |
1290 | goto nla_put_failure; | |
1291 | ||
ae0be8de MK |
1292 | nl_limits = nla_nest_start_noflag(msg, |
1293 | NL80211_IFACE_COMB_LIMITS); | |
7527a782 JB |
1294 | if (!nl_limits) |
1295 | goto nla_put_failure; | |
1296 | ||
1297 | for (j = 0; j < c->n_limits; j++) { | |
1298 | struct nlattr *nl_limit; | |
1299 | ||
ae0be8de | 1300 | nl_limit = nla_nest_start_noflag(msg, j + 1); |
7527a782 JB |
1301 | if (!nl_limit) |
1302 | goto nla_put_failure; | |
9360ffd1 DM |
1303 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
1304 | c->limits[j].max)) | |
1305 | goto nla_put_failure; | |
7527a782 JB |
1306 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
1307 | c->limits[j].types)) | |
1308 | goto nla_put_failure; | |
1309 | nla_nest_end(msg, nl_limit); | |
1310 | } | |
1311 | ||
1312 | nla_nest_end(msg, nl_limits); | |
1313 | ||
9360ffd1 DM |
1314 | if (c->beacon_int_infra_match && |
1315 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
1316 | goto nla_put_failure; | |
1317 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
1318 | c->num_different_channels) || | |
1319 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
1320 | c->max_interfaces)) | |
1321 | goto nla_put_failure; | |
cdc89b97 | 1322 | if (large && |
8c48b50a FF |
1323 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
1324 | c->radar_detect_widths) || | |
1325 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
1326 | c->radar_detect_regions))) | |
cdc89b97 | 1327 | goto nla_put_failure; |
0c317a02 PK |
1328 | if (c->beacon_int_min_gcd && |
1329 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, | |
1330 | c->beacon_int_min_gcd)) | |
1331 | goto nla_put_failure; | |
7527a782 JB |
1332 | |
1333 | nla_nest_end(msg, nl_combi); | |
1334 | } | |
1335 | ||
1336 | nla_nest_end(msg, nl_combis); | |
1337 | ||
1338 | return 0; | |
1339 | nla_put_failure: | |
1340 | return -ENOBUFS; | |
1341 | } | |
1342 | ||
3713b4e3 | 1343 | #ifdef CONFIG_PM |
b56cf720 JB |
1344 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
1345 | struct sk_buff *msg) | |
1346 | { | |
964dc9e2 | 1347 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
1348 | struct nlattr *nl_tcp; |
1349 | ||
1350 | if (!tcp) | |
1351 | return 0; | |
1352 | ||
ae0be8de MK |
1353 | nl_tcp = nla_nest_start_noflag(msg, |
1354 | NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
b56cf720 JB |
1355 | if (!nl_tcp) |
1356 | return -ENOBUFS; | |
1357 | ||
1358 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1359 | tcp->data_payload_max)) | |
1360 | return -ENOBUFS; | |
1361 | ||
1362 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1363 | tcp->data_payload_max)) | |
1364 | return -ENOBUFS; | |
1365 | ||
1366 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1367 | return -ENOBUFS; | |
1368 | ||
1369 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1370 | sizeof(*tcp->tok), tcp->tok)) | |
1371 | return -ENOBUFS; | |
1372 | ||
1373 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1374 | tcp->data_interval_max)) | |
1375 | return -ENOBUFS; | |
1376 | ||
1377 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1378 | tcp->wake_payload_max)) | |
1379 | return -ENOBUFS; | |
1380 | ||
1381 | nla_nest_end(msg, nl_tcp); | |
1382 | return 0; | |
1383 | } | |
1384 | ||
3713b4e3 | 1385 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1386 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1387 | bool large) |
55682965 | 1388 | { |
3713b4e3 | 1389 | struct nlattr *nl_wowlan; |
55682965 | 1390 | |
1b8ec87a | 1391 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1392 | return 0; |
55682965 | 1393 | |
ae0be8de MK |
1394 | nl_wowlan = nla_nest_start_noflag(msg, |
1395 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); | |
3713b4e3 JB |
1396 | if (!nl_wowlan) |
1397 | return -ENOBUFS; | |
9360ffd1 | 1398 | |
1b8ec87a | 1399 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1400 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1401 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1402 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1403 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1404 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1405 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1406 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1407 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1408 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1409 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1410 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1411 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1412 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1413 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1414 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1415 | return -ENOBUFS; | |
9360ffd1 | 1416 | |
1b8ec87a | 1417 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1418 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1419 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1420 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1421 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1422 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1423 | }; |
9360ffd1 | 1424 | |
3713b4e3 JB |
1425 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1426 | sizeof(pat), &pat)) | |
1427 | return -ENOBUFS; | |
1428 | } | |
9360ffd1 | 1429 | |
75453ccb LC |
1430 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
1431 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, | |
1432 | rdev->wiphy.wowlan->max_nd_match_sets)) | |
1433 | return -ENOBUFS; | |
1434 | ||
1b8ec87a | 1435 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1436 | return -ENOBUFS; |
1437 | ||
3713b4e3 | 1438 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1439 | |
3713b4e3 JB |
1440 | return 0; |
1441 | } | |
1442 | #endif | |
9360ffd1 | 1443 | |
be29b99a | 1444 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1445 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1446 | { |
1447 | struct nl80211_coalesce_rule_support rule; | |
1448 | ||
1b8ec87a | 1449 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1450 | return 0; |
1451 | ||
1b8ec87a ZG |
1452 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1453 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1454 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1455 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1456 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1457 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1458 | |
1459 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1460 | return -ENOBUFS; | |
1461 | ||
1462 | return 0; | |
1463 | } | |
1464 | ||
c4cbaf79 LC |
1465 | static int |
1466 | nl80211_send_iftype_data(struct sk_buff *msg, | |
1467 | const struct ieee80211_sband_iftype_data *iftdata) | |
1468 | { | |
1469 | const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; | |
1470 | ||
1471 | if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, | |
1472 | iftdata->types_mask)) | |
1473 | return -ENOBUFS; | |
1474 | ||
1475 | if (he_cap->has_he) { | |
1476 | if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, | |
1477 | sizeof(he_cap->he_cap_elem.mac_cap_info), | |
1478 | he_cap->he_cap_elem.mac_cap_info) || | |
1479 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, | |
1480 | sizeof(he_cap->he_cap_elem.phy_cap_info), | |
1481 | he_cap->he_cap_elem.phy_cap_info) || | |
1482 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, | |
1483 | sizeof(he_cap->he_mcs_nss_supp), | |
1484 | &he_cap->he_mcs_nss_supp) || | |
1485 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, | |
1486 | sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) | |
1487 | return -ENOBUFS; | |
1488 | } | |
1489 | ||
1490 | return 0; | |
1491 | } | |
1492 | ||
3713b4e3 JB |
1493 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1494 | struct ieee80211_supported_band *sband) | |
1495 | { | |
1496 | struct nlattr *nl_rates, *nl_rate; | |
1497 | struct ieee80211_rate *rate; | |
1498 | int i; | |
87bbbe22 | 1499 | |
3713b4e3 JB |
1500 | /* add HT info */ |
1501 | if (sband->ht_cap.ht_supported && | |
1502 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1503 | sizeof(sband->ht_cap.mcs), | |
1504 | &sband->ht_cap.mcs) || | |
1505 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1506 | sband->ht_cap.cap) || | |
1507 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1508 | sband->ht_cap.ampdu_factor) || | |
1509 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1510 | sband->ht_cap.ampdu_density))) | |
1511 | return -ENOBUFS; | |
afe0cbf8 | 1512 | |
3713b4e3 JB |
1513 | /* add VHT info */ |
1514 | if (sband->vht_cap.vht_supported && | |
1515 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1516 | sizeof(sband->vht_cap.vht_mcs), | |
1517 | &sband->vht_cap.vht_mcs) || | |
1518 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1519 | sband->vht_cap.cap))) | |
1520 | return -ENOBUFS; | |
f59ac048 | 1521 | |
c4cbaf79 LC |
1522 | if (sband->n_iftype_data) { |
1523 | struct nlattr *nl_iftype_data = | |
ae0be8de MK |
1524 | nla_nest_start_noflag(msg, |
1525 | NL80211_BAND_ATTR_IFTYPE_DATA); | |
c4cbaf79 LC |
1526 | int err; |
1527 | ||
1528 | if (!nl_iftype_data) | |
1529 | return -ENOBUFS; | |
1530 | ||
1531 | for (i = 0; i < sband->n_iftype_data; i++) { | |
1532 | struct nlattr *iftdata; | |
1533 | ||
ae0be8de | 1534 | iftdata = nla_nest_start_noflag(msg, i + 1); |
c4cbaf79 LC |
1535 | if (!iftdata) |
1536 | return -ENOBUFS; | |
1537 | ||
1538 | err = nl80211_send_iftype_data(msg, | |
1539 | &sband->iftype_data[i]); | |
1540 | if (err) | |
1541 | return err; | |
1542 | ||
1543 | nla_nest_end(msg, iftdata); | |
1544 | } | |
1545 | ||
1546 | nla_nest_end(msg, nl_iftype_data); | |
1547 | } | |
1548 | ||
3713b4e3 | 1549 | /* add bitrates */ |
ae0be8de | 1550 | nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES); |
3713b4e3 JB |
1551 | if (!nl_rates) |
1552 | return -ENOBUFS; | |
ee688b00 | 1553 | |
3713b4e3 | 1554 | for (i = 0; i < sband->n_bitrates; i++) { |
ae0be8de | 1555 | nl_rate = nla_nest_start_noflag(msg, i); |
3713b4e3 JB |
1556 | if (!nl_rate) |
1557 | return -ENOBUFS; | |
ee688b00 | 1558 | |
3713b4e3 JB |
1559 | rate = &sband->bitrates[i]; |
1560 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1561 | rate->bitrate)) | |
1562 | return -ENOBUFS; | |
1563 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1564 | nla_put_flag(msg, | |
1565 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1566 | return -ENOBUFS; | |
ee688b00 | 1567 | |
3713b4e3 JB |
1568 | nla_nest_end(msg, nl_rate); |
1569 | } | |
d51626df | 1570 | |
3713b4e3 | 1571 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1572 | |
3713b4e3 JB |
1573 | return 0; |
1574 | } | |
ee688b00 | 1575 | |
3713b4e3 JB |
1576 | static int |
1577 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1578 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1579 | { | |
1580 | u16 stypes; | |
1581 | struct nlattr *nl_ftypes, *nl_ifs; | |
1582 | enum nl80211_iftype ift; | |
1583 | int i; | |
ee688b00 | 1584 | |
3713b4e3 JB |
1585 | if (!mgmt_stypes) |
1586 | return 0; | |
5dab3b8a | 1587 | |
ae0be8de | 1588 | nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES); |
3713b4e3 JB |
1589 | if (!nl_ifs) |
1590 | return -ENOBUFS; | |
e2f367f2 | 1591 | |
3713b4e3 | 1592 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
ae0be8de | 1593 | nl_ftypes = nla_nest_start_noflag(msg, ift); |
3713b4e3 JB |
1594 | if (!nl_ftypes) |
1595 | return -ENOBUFS; | |
1596 | i = 0; | |
1597 | stypes = mgmt_stypes[ift].tx; | |
1598 | while (stypes) { | |
1599 | if ((stypes & 1) && | |
1600 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1601 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1602 | return -ENOBUFS; | |
1603 | stypes >>= 1; | |
1604 | i++; | |
ee688b00 | 1605 | } |
3713b4e3 JB |
1606 | nla_nest_end(msg, nl_ftypes); |
1607 | } | |
ee688b00 | 1608 | |
3713b4e3 | 1609 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1610 | |
ae0be8de | 1611 | nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES); |
3713b4e3 JB |
1612 | if (!nl_ifs) |
1613 | return -ENOBUFS; | |
ee688b00 | 1614 | |
3713b4e3 | 1615 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
ae0be8de | 1616 | nl_ftypes = nla_nest_start_noflag(msg, ift); |
3713b4e3 JB |
1617 | if (!nl_ftypes) |
1618 | return -ENOBUFS; | |
1619 | i = 0; | |
1620 | stypes = mgmt_stypes[ift].rx; | |
1621 | while (stypes) { | |
1622 | if ((stypes & 1) && | |
1623 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1624 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1625 | return -ENOBUFS; | |
1626 | stypes >>= 1; | |
1627 | i++; | |
1628 | } | |
1629 | nla_nest_end(msg, nl_ftypes); | |
1630 | } | |
1631 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1632 | |
3713b4e3 JB |
1633 | return 0; |
1634 | } | |
ee688b00 | 1635 | |
1794899e JB |
1636 | #define CMD(op, n) \ |
1637 | do { \ | |
1638 | if (rdev->ops->op) { \ | |
1639 | i++; \ | |
1640 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1641 | goto nla_put_failure; \ | |
1642 | } \ | |
1643 | } while (0) | |
1644 | ||
1645 | static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, | |
1646 | struct sk_buff *msg) | |
1647 | { | |
1648 | int i = 0; | |
1649 | ||
1650 | /* | |
1651 | * do *NOT* add anything into this function, new things need to be | |
1652 | * advertised only to new versions of userspace that can deal with | |
1653 | * the split (and they can't possibly care about new features... | |
1654 | */ | |
1655 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1656 | CMD(change_virtual_intf, SET_INTERFACE); | |
1657 | CMD(add_key, NEW_KEY); | |
1658 | CMD(start_ap, START_AP); | |
1659 | CMD(add_station, NEW_STATION); | |
1660 | CMD(add_mpath, NEW_MPATH); | |
1661 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1662 | CMD(change_bss, SET_BSS); | |
1663 | CMD(auth, AUTHENTICATE); | |
1664 | CMD(assoc, ASSOCIATE); | |
1665 | CMD(deauth, DEAUTHENTICATE); | |
1666 | CMD(disassoc, DISASSOCIATE); | |
1667 | CMD(join_ibss, JOIN_IBSS); | |
1668 | CMD(join_mesh, JOIN_MESH); | |
1669 | CMD(set_pmksa, SET_PMKSA); | |
1670 | CMD(del_pmksa, DEL_PMKSA); | |
1671 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1672 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) | |
1673 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
1674 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1675 | CMD(mgmt_tx, FRAME); | |
1676 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1677 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | |
1678 | i++; | |
1679 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
1680 | goto nla_put_failure; | |
1681 | } | |
1682 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || | |
1683 | rdev->ops->join_mesh) { | |
1684 | i++; | |
1685 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1686 | goto nla_put_failure; | |
1687 | } | |
1688 | CMD(set_wds_peer, SET_WDS_PEER); | |
1689 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { | |
1690 | CMD(tdls_mgmt, TDLS_MGMT); | |
1691 | CMD(tdls_oper, TDLS_OPER); | |
1692 | } | |
ca986ad9 | 1693 | if (rdev->wiphy.max_sched_scan_reqs) |
1794899e JB |
1694 | CMD(sched_scan_start, START_SCHED_SCAN); |
1695 | CMD(probe_client, PROBE_CLIENT); | |
1696 | CMD(set_noack_map, SET_NOACK_MAP); | |
1697 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { | |
1698 | i++; | |
1699 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1700 | goto nla_put_failure; | |
1701 | } | |
1702 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1703 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
1704 | #ifdef CONFIG_NL80211_TESTMODE | |
1705 | CMD(testmode_cmd, TESTMODE); | |
1706 | #endif | |
1707 | ||
1708 | if (rdev->ops->connect || rdev->ops->auth) { | |
1709 | i++; | |
1710 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
1711 | goto nla_put_failure; | |
1712 | } | |
1713 | ||
1714 | if (rdev->ops->disconnect || rdev->ops->deauth) { | |
1715 | i++; | |
1716 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1717 | goto nla_put_failure; | |
1718 | } | |
1719 | ||
1720 | return i; | |
1721 | nla_put_failure: | |
1722 | return -ENOBUFS; | |
1723 | } | |
1724 | ||
9bb7e0f2 JB |
1725 | static int |
1726 | nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, | |
1727 | struct sk_buff *msg) | |
1728 | { | |
1729 | struct nlattr *ftm; | |
1730 | ||
1731 | if (!cap->ftm.supported) | |
1732 | return 0; | |
1733 | ||
ae0be8de | 1734 | ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM); |
9bb7e0f2 JB |
1735 | if (!ftm) |
1736 | return -ENOBUFS; | |
1737 | ||
1738 | if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP)) | |
1739 | return -ENOBUFS; | |
1740 | if (cap->ftm.non_asap && | |
1741 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP)) | |
1742 | return -ENOBUFS; | |
1743 | if (cap->ftm.request_lci && | |
1744 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI)) | |
1745 | return -ENOBUFS; | |
1746 | if (cap->ftm.request_civicloc && | |
1747 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC)) | |
1748 | return -ENOBUFS; | |
1749 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES, | |
1750 | cap->ftm.preambles)) | |
1751 | return -ENOBUFS; | |
1752 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS, | |
1753 | cap->ftm.bandwidths)) | |
1754 | return -ENOBUFS; | |
1755 | if (cap->ftm.max_bursts_exponent >= 0 && | |
1756 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT, | |
1757 | cap->ftm.max_bursts_exponent)) | |
1758 | return -ENOBUFS; | |
1759 | if (cap->ftm.max_ftms_per_burst && | |
1760 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST, | |
1761 | cap->ftm.max_ftms_per_burst)) | |
1762 | return -ENOBUFS; | |
1763 | ||
1764 | nla_nest_end(msg, ftm); | |
1765 | return 0; | |
1766 | } | |
1767 | ||
1768 | static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev, | |
1769 | struct sk_buff *msg) | |
1770 | { | |
1771 | const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa; | |
1772 | struct nlattr *pmsr, *caps; | |
1773 | ||
1774 | if (!cap) | |
1775 | return 0; | |
1776 | ||
1777 | /* | |
1778 | * we don't need to clean up anything here since the caller | |
1779 | * will genlmsg_cancel() if we fail | |
1780 | */ | |
1781 | ||
ae0be8de | 1782 | pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS); |
9bb7e0f2 JB |
1783 | if (!pmsr) |
1784 | return -ENOBUFS; | |
1785 | ||
1786 | if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers)) | |
1787 | return -ENOBUFS; | |
1788 | ||
1789 | if (cap->report_ap_tsf && | |
1790 | nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF)) | |
1791 | return -ENOBUFS; | |
1792 | ||
1793 | if (cap->randomize_mac_addr && | |
1794 | nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR)) | |
1795 | return -ENOBUFS; | |
1796 | ||
ae0be8de | 1797 | caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA); |
9bb7e0f2 JB |
1798 | if (!caps) |
1799 | return -ENOBUFS; | |
1800 | ||
1801 | if (nl80211_send_pmsr_ftm_capa(cap, msg)) | |
1802 | return -ENOBUFS; | |
1803 | ||
1804 | nla_nest_end(msg, caps); | |
1805 | nla_nest_end(msg, pmsr); | |
1806 | ||
1807 | return 0; | |
1808 | } | |
1809 | ||
86e8cf98 JB |
1810 | struct nl80211_dump_wiphy_state { |
1811 | s64 filter_wiphy; | |
1812 | long start; | |
019ae3a9 | 1813 | long split_start, band_start, chan_start, capa_start; |
86e8cf98 JB |
1814 | bool split; |
1815 | }; | |
1816 | ||
1b8ec87a | 1817 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1818 | enum nl80211_commands cmd, |
3713b4e3 | 1819 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1820 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1821 | { |
1822 | void *hdr; | |
1823 | struct nlattr *nl_bands, *nl_band; | |
1824 | struct nlattr *nl_freqs, *nl_freq; | |
1825 | struct nlattr *nl_cmds; | |
57fbcce3 | 1826 | enum nl80211_band band; |
3713b4e3 JB |
1827 | struct ieee80211_channel *chan; |
1828 | int i; | |
1829 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1830 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1831 | u32 features; |
ee688b00 | 1832 | |
3bb20556 | 1833 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1834 | if (!hdr) |
1835 | return -ENOBUFS; | |
ee688b00 | 1836 | |
86e8cf98 JB |
1837 | if (WARN_ON(!state)) |
1838 | return -EINVAL; | |
ee688b00 | 1839 | |
1b8ec87a | 1840 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1841 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1842 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1843 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1844 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1845 | goto nla_put_failure; |
1846 | ||
3bb20556 JB |
1847 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1848 | goto finish; | |
1849 | ||
86e8cf98 | 1850 | switch (state->split_start) { |
3713b4e3 JB |
1851 | case 0: |
1852 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1853 | rdev->wiphy.retry_short) || |
3713b4e3 | 1854 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1855 | rdev->wiphy.retry_long) || |
3713b4e3 | 1856 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1857 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1858 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1859 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1860 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1861 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1862 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1863 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1864 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1865 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1866 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1867 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1868 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1869 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1870 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
3b06d277 AS |
1871 | rdev->wiphy.max_match_sets) || |
1872 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, | |
1873 | rdev->wiphy.max_sched_scan_plans) || | |
1874 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, | |
1875 | rdev->wiphy.max_sched_scan_plan_interval) || | |
1876 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, | |
1877 | rdev->wiphy.max_sched_scan_plan_iterations)) | |
9360ffd1 | 1878 | goto nla_put_failure; |
3713b4e3 | 1879 | |
1b8ec87a | 1880 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1881 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1882 | goto nla_put_failure; |
1b8ec87a | 1883 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1884 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1885 | goto nla_put_failure; | |
1b8ec87a | 1886 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1887 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1888 | goto nla_put_failure; | |
1b8ec87a | 1889 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1890 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1891 | goto nla_put_failure; | |
1b8ec87a | 1892 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1893 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1894 | goto nla_put_failure; | |
1b8ec87a | 1895 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1896 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1897 | goto nla_put_failure; |
86e8cf98 JB |
1898 | state->split_start++; |
1899 | if (state->split) | |
3713b4e3 | 1900 | break; |
925b5978 | 1901 | /* fall through */ |
3713b4e3 JB |
1902 | case 1: |
1903 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1904 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1905 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1906 | goto nla_put_failure; |
4745fc09 | 1907 | |
3713b4e3 | 1908 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1909 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1910 | goto nla_put_failure; |
b23aa676 | 1911 | |
1b8ec87a | 1912 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1913 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1914 | goto nla_put_failure; |
b23aa676 | 1915 | |
3713b4e3 | 1916 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1917 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1918 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1919 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1920 | goto nla_put_failure; |
b23aa676 | 1921 | |
1b8ec87a | 1922 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1923 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1924 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1925 | goto nla_put_failure; |
8fdc621d | 1926 | |
1b8ec87a ZG |
1927 | if ((rdev->wiphy.available_antennas_tx || |
1928 | rdev->wiphy.available_antennas_rx) && | |
1929 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1930 | u32 tx_ant = 0, rx_ant = 0; |
1931 | int res; | |
7a087e74 | 1932 | |
1b8ec87a | 1933 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1934 | if (!res) { |
1935 | if (nla_put_u32(msg, | |
1936 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1937 | tx_ant) || | |
1938 | nla_put_u32(msg, | |
1939 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1940 | rx_ant)) | |
1941 | goto nla_put_failure; | |
1942 | } | |
1943 | } | |
a293911d | 1944 | |
86e8cf98 JB |
1945 | state->split_start++; |
1946 | if (state->split) | |
3713b4e3 | 1947 | break; |
925b5978 | 1948 | /* fall through */ |
3713b4e3 JB |
1949 | case 2: |
1950 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1951 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1952 | goto nla_put_failure; |
86e8cf98 JB |
1953 | state->split_start++; |
1954 | if (state->split) | |
3713b4e3 | 1955 | break; |
925b5978 | 1956 | /* fall through */ |
3713b4e3 | 1957 | case 3: |
ae0be8de MK |
1958 | nl_bands = nla_nest_start_noflag(msg, |
1959 | NL80211_ATTR_WIPHY_BANDS); | |
3713b4e3 JB |
1960 | if (!nl_bands) |
1961 | goto nla_put_failure; | |
f7ca38df | 1962 | |
86e8cf98 | 1963 | for (band = state->band_start; |
57fbcce3 | 1964 | band < NUM_NL80211_BANDS; band++) { |
3713b4e3 | 1965 | struct ieee80211_supported_band *sband; |
2e161f78 | 1966 | |
1b8ec87a | 1967 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1968 | |
3713b4e3 JB |
1969 | if (!sband) |
1970 | continue; | |
1971 | ||
ae0be8de | 1972 | nl_band = nla_nest_start_noflag(msg, band); |
3713b4e3 | 1973 | if (!nl_band) |
2e161f78 | 1974 | goto nla_put_failure; |
3713b4e3 | 1975 | |
86e8cf98 | 1976 | switch (state->chan_start) { |
3713b4e3 JB |
1977 | case 0: |
1978 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1979 | goto nla_put_failure; |
86e8cf98 JB |
1980 | state->chan_start++; |
1981 | if (state->split) | |
3713b4e3 | 1982 | break; |
925b5978 | 1983 | /* fall through */ |
3713b4e3 JB |
1984 | default: |
1985 | /* add frequencies */ | |
ae0be8de MK |
1986 | nl_freqs = nla_nest_start_noflag(msg, |
1987 | NL80211_BAND_ATTR_FREQS); | |
3713b4e3 JB |
1988 | if (!nl_freqs) |
1989 | goto nla_put_failure; | |
1990 | ||
86e8cf98 | 1991 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1992 | i < sband->n_channels; |
1993 | i++) { | |
ae0be8de MK |
1994 | nl_freq = nla_nest_start_noflag(msg, |
1995 | i); | |
3713b4e3 JB |
1996 | if (!nl_freq) |
1997 | goto nla_put_failure; | |
1998 | ||
1999 | chan = &sband->channels[i]; | |
2000 | ||
86e8cf98 | 2001 | if (nl80211_msg_put_channel( |
50f32718 | 2002 | msg, &rdev->wiphy, chan, |
86e8cf98 | 2003 | state->split)) |
3713b4e3 JB |
2004 | goto nla_put_failure; |
2005 | ||
2006 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 2007 | if (state->split) |
3713b4e3 JB |
2008 | break; |
2009 | } | |
2010 | if (i < sband->n_channels) | |
86e8cf98 | 2011 | state->chan_start = i + 2; |
3713b4e3 | 2012 | else |
86e8cf98 | 2013 | state->chan_start = 0; |
3713b4e3 JB |
2014 | nla_nest_end(msg, nl_freqs); |
2015 | } | |
2016 | ||
2017 | nla_nest_end(msg, nl_band); | |
2018 | ||
86e8cf98 | 2019 | if (state->split) { |
3713b4e3 | 2020 | /* start again here */ |
86e8cf98 | 2021 | if (state->chan_start) |
3713b4e3 JB |
2022 | band--; |
2023 | break; | |
2e161f78 | 2024 | } |
2e161f78 | 2025 | } |
3713b4e3 | 2026 | nla_nest_end(msg, nl_bands); |
2e161f78 | 2027 | |
57fbcce3 | 2028 | if (band < NUM_NL80211_BANDS) |
86e8cf98 | 2029 | state->band_start = band + 1; |
3713b4e3 | 2030 | else |
86e8cf98 | 2031 | state->band_start = 0; |
74b70a4e | 2032 | |
3713b4e3 | 2033 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
2034 | if (state->band_start == 0 && state->chan_start == 0) |
2035 | state->split_start++; | |
2036 | if (state->split) | |
3713b4e3 | 2037 | break; |
925b5978 | 2038 | /* fall through */ |
3713b4e3 | 2039 | case 4: |
ae0be8de MK |
2040 | nl_cmds = nla_nest_start_noflag(msg, |
2041 | NL80211_ATTR_SUPPORTED_COMMANDS); | |
3713b4e3 | 2042 | if (!nl_cmds) |
2e161f78 JB |
2043 | goto nla_put_failure; |
2044 | ||
1794899e JB |
2045 | i = nl80211_add_commands_unsplit(rdev, msg); |
2046 | if (i < 0) | |
2047 | goto nla_put_failure; | |
86e8cf98 | 2048 | if (state->split) { |
5de17984 AS |
2049 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
2050 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 2051 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 2052 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 2053 | CMD(set_qos_map, SET_QOS_MAP); |
723e73ac JB |
2054 | if (rdev->wiphy.features & |
2055 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | |
960d01ac | 2056 | CMD(add_tx_ts, ADD_TX_TS); |
ce0ce13a | 2057 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); |
088e8df8 | 2058 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); |
5de17984 | 2059 | } |
3713b4e3 | 2060 | #undef CMD |
ff1b6e69 | 2061 | |
3713b4e3 | 2062 | nla_nest_end(msg, nl_cmds); |
86e8cf98 JB |
2063 | state->split_start++; |
2064 | if (state->split) | |
3713b4e3 | 2065 | break; |
925b5978 | 2066 | /* fall through */ |
3713b4e3 | 2067 | case 5: |
1b8ec87a ZG |
2068 | if (rdev->ops->remain_on_channel && |
2069 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
2070 | nla_put_u32(msg, |
2071 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 2072 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
2073 | goto nla_put_failure; |
2074 | ||
1b8ec87a | 2075 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
2076 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
2077 | goto nla_put_failure; | |
2078 | ||
2079 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
2080 | goto nla_put_failure; | |
86e8cf98 JB |
2081 | state->split_start++; |
2082 | if (state->split) | |
3713b4e3 | 2083 | break; |
925b5978 | 2084 | /* fall through */ |
3713b4e3 JB |
2085 | case 6: |
2086 | #ifdef CONFIG_PM | |
1b8ec87a | 2087 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 2088 | goto nla_put_failure; |
86e8cf98 JB |
2089 | state->split_start++; |
2090 | if (state->split) | |
3713b4e3 JB |
2091 | break; |
2092 | #else | |
86e8cf98 | 2093 | state->split_start++; |
dfb89c56 | 2094 | #endif |
925b5978 | 2095 | /* fall through */ |
3713b4e3 JB |
2096 | case 7: |
2097 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 2098 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 2099 | goto nla_put_failure; |
ff1b6e69 | 2100 | |
1b8ec87a | 2101 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 2102 | state->split)) |
3713b4e3 | 2103 | goto nla_put_failure; |
7527a782 | 2104 | |
86e8cf98 JB |
2105 | state->split_start++; |
2106 | if (state->split) | |
3713b4e3 | 2107 | break; |
925b5978 | 2108 | /* fall through */ |
3713b4e3 | 2109 | case 8: |
1b8ec87a | 2110 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 2111 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 2112 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 2113 | goto nla_put_failure; |
7527a782 | 2114 | |
1b8ec87a | 2115 | features = rdev->wiphy.features; |
fe1abafd JB |
2116 | /* |
2117 | * We can only add the per-channel limit information if the | |
2118 | * dump is split, otherwise it makes it too big. Therefore | |
2119 | * only advertise it in that case. | |
2120 | */ | |
86e8cf98 | 2121 | if (state->split) |
fe1abafd JB |
2122 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
2123 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 2124 | goto nla_put_failure; |
562a7480 | 2125 | |
1b8ec87a | 2126 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 2127 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
2128 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
2129 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 2130 | goto nla_put_failure; |
1f074bd8 | 2131 | |
1b8ec87a ZG |
2132 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
2133 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 2134 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 2135 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 2136 | goto nla_put_failure; |
7e7c8926 | 2137 | |
3713b4e3 JB |
2138 | /* |
2139 | * Any information below this point is only available to | |
2140 | * applications that can deal with it being split. This | |
2141 | * helps ensure that newly added capabilities don't break | |
2142 | * older tools by overrunning their buffers. | |
2143 | * | |
2144 | * We still increment split_start so that in the split | |
2145 | * case we'll continue with more data in the next round, | |
2146 | * but break unconditionally so unsplit data stops here. | |
2147 | */ | |
86e8cf98 | 2148 | state->split_start++; |
3713b4e3 JB |
2149 | break; |
2150 | case 9: | |
1b8ec87a | 2151 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 2152 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
2153 | rdev->wiphy.extended_capabilities_len, |
2154 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 2155 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
2156 | rdev->wiphy.extended_capabilities_len, |
2157 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 2158 | goto nla_put_failure; |
a50df0c4 | 2159 | |
1b8ec87a | 2160 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 2161 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
2162 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
2163 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
2164 | goto nla_put_failure; |
2165 | ||
be29b99a AK |
2166 | state->split_start++; |
2167 | break; | |
2168 | case 10: | |
1b8ec87a | 2169 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
2170 | goto nla_put_failure; |
2171 | ||
1b8ec87a | 2172 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
2173 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
2174 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
2175 | goto nla_put_failure; | |
b43504cf | 2176 | |
1b8ec87a | 2177 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 2178 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 2179 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
2180 | goto nla_put_failure; |
2181 | ||
ad7e718c JB |
2182 | state->split_start++; |
2183 | break; | |
2184 | case 11: | |
1b8ec87a | 2185 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
2186 | const struct nl80211_vendor_cmd_info *info; |
2187 | struct nlattr *nested; | |
2188 | ||
ae0be8de MK |
2189 | nested = nla_nest_start_noflag(msg, |
2190 | NL80211_ATTR_VENDOR_DATA); | |
567ffc35 JB |
2191 | if (!nested) |
2192 | goto nla_put_failure; | |
2193 | ||
1b8ec87a ZG |
2194 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
2195 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
2196 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
2197 | goto nla_put_failure; | |
2198 | } | |
2199 | nla_nest_end(msg, nested); | |
2200 | } | |
2201 | ||
1b8ec87a | 2202 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
2203 | const struct nl80211_vendor_cmd_info *info; |
2204 | struct nlattr *nested; | |
ad7e718c | 2205 | |
ae0be8de MK |
2206 | nested = nla_nest_start_noflag(msg, |
2207 | NL80211_ATTR_VENDOR_EVENTS); | |
567ffc35 | 2208 | if (!nested) |
ad7e718c | 2209 | goto nla_put_failure; |
567ffc35 | 2210 | |
1b8ec87a ZG |
2211 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
2212 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
2213 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
2214 | goto nla_put_failure; | |
2215 | } | |
2216 | nla_nest_end(msg, nested); | |
2217 | } | |
9a774c78 AO |
2218 | state->split_start++; |
2219 | break; | |
2220 | case 12: | |
2221 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
2222 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
2223 | rdev->wiphy.max_num_csa_counters)) | |
2224 | goto nla_put_failure; | |
01e0daa4 | 2225 | |
1bdd716c AN |
2226 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
2227 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
2228 | goto nla_put_failure; | |
2229 | ||
ca986ad9 AVS |
2230 | if (rdev->wiphy.max_sched_scan_reqs && |
2231 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, | |
2232 | rdev->wiphy.max_sched_scan_reqs)) | |
2233 | goto nla_put_failure; | |
2234 | ||
d75bb06b GKS |
2235 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
2236 | sizeof(rdev->wiphy.ext_features), | |
2237 | rdev->wiphy.ext_features)) | |
2238 | goto nla_put_failure; | |
2239 | ||
38de03d2 AS |
2240 | if (rdev->wiphy.bss_select_support) { |
2241 | struct nlattr *nested; | |
2242 | u32 bss_select_support = rdev->wiphy.bss_select_support; | |
2243 | ||
ae0be8de MK |
2244 | nested = nla_nest_start_noflag(msg, |
2245 | NL80211_ATTR_BSS_SELECT); | |
38de03d2 AS |
2246 | if (!nested) |
2247 | goto nla_put_failure; | |
2248 | ||
2249 | i = 0; | |
2250 | while (bss_select_support) { | |
2251 | if ((bss_select_support & 1) && | |
2252 | nla_put_flag(msg, i)) | |
2253 | goto nla_put_failure; | |
2254 | i++; | |
2255 | bss_select_support >>= 1; | |
2256 | } | |
2257 | nla_nest_end(msg, nested); | |
2258 | } | |
2259 | ||
019ae3a9 KV |
2260 | state->split_start++; |
2261 | break; | |
2262 | case 13: | |
2263 | if (rdev->wiphy.num_iftype_ext_capab && | |
2264 | rdev->wiphy.iftype_ext_capab) { | |
2265 | struct nlattr *nested_ext_capab, *nested; | |
2266 | ||
ae0be8de MK |
2267 | nested = nla_nest_start_noflag(msg, |
2268 | NL80211_ATTR_IFTYPE_EXT_CAPA); | |
019ae3a9 KV |
2269 | if (!nested) |
2270 | goto nla_put_failure; | |
2271 | ||
2272 | for (i = state->capa_start; | |
2273 | i < rdev->wiphy.num_iftype_ext_capab; i++) { | |
2274 | const struct wiphy_iftype_ext_capab *capab; | |
2275 | ||
2276 | capab = &rdev->wiphy.iftype_ext_capab[i]; | |
2277 | ||
ae0be8de MK |
2278 | nested_ext_capab = nla_nest_start_noflag(msg, |
2279 | i); | |
019ae3a9 KV |
2280 | if (!nested_ext_capab || |
2281 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, | |
2282 | capab->iftype) || | |
2283 | nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
2284 | capab->extended_capabilities_len, | |
2285 | capab->extended_capabilities) || | |
2286 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
2287 | capab->extended_capabilities_len, | |
2288 | capab->extended_capabilities_mask)) | |
2289 | goto nla_put_failure; | |
2290 | ||
2291 | nla_nest_end(msg, nested_ext_capab); | |
2292 | if (state->split) | |
2293 | break; | |
2294 | } | |
2295 | nla_nest_end(msg, nested); | |
2296 | if (i < rdev->wiphy.num_iftype_ext_capab) { | |
2297 | state->capa_start = i + 1; | |
2298 | break; | |
2299 | } | |
2300 | } | |
2301 | ||
8585989d LC |
2302 | if (nla_put_u32(msg, NL80211_ATTR_BANDS, |
2303 | rdev->wiphy.nan_supported_bands)) | |
2304 | goto nla_put_failure; | |
2305 | ||
52539ca8 THJ |
2306 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
2307 | NL80211_EXT_FEATURE_TXQS)) { | |
2308 | struct cfg80211_txq_stats txqstats = {}; | |
2309 | int res; | |
2310 | ||
2311 | res = rdev_get_txq_stats(rdev, NULL, &txqstats); | |
2312 | if (!res && | |
2313 | !nl80211_put_txq_stats(msg, &txqstats, | |
2314 | NL80211_ATTR_TXQ_STATS)) | |
2315 | goto nla_put_failure; | |
2316 | ||
2317 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, | |
2318 | rdev->wiphy.txq_limit)) | |
2319 | goto nla_put_failure; | |
2320 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, | |
2321 | rdev->wiphy.txq_memory_limit)) | |
2322 | goto nla_put_failure; | |
2323 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, | |
2324 | rdev->wiphy.txq_quantum)) | |
2325 | goto nla_put_failure; | |
2326 | } | |
2327 | ||
9bb7e0f2 JB |
2328 | state->split_start++; |
2329 | break; | |
2330 | case 14: | |
2331 | if (nl80211_send_pmsr_capa(rdev, msg)) | |
2332 | goto nla_put_failure; | |
2333 | ||
ab4dfa20 VJ |
2334 | state->split_start++; |
2335 | break; | |
2336 | case 15: | |
2337 | if (rdev->wiphy.akm_suites && | |
2338 | nla_put(msg, NL80211_ATTR_AKM_SUITES, | |
2339 | sizeof(u32) * rdev->wiphy.n_akm_suites, | |
2340 | rdev->wiphy.akm_suites)) | |
2341 | goto nla_put_failure; | |
2342 | ||
3713b4e3 | 2343 | /* done */ |
86e8cf98 | 2344 | state->split_start = 0; |
3713b4e3 JB |
2345 | break; |
2346 | } | |
3bb20556 | 2347 | finish: |
053c095a JB |
2348 | genlmsg_end(msg, hdr); |
2349 | return 0; | |
55682965 JB |
2350 | |
2351 | nla_put_failure: | |
bc3ed28c TG |
2352 | genlmsg_cancel(msg, hdr); |
2353 | return -EMSGSIZE; | |
55682965 JB |
2354 | } |
2355 | ||
86e8cf98 JB |
2356 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
2357 | struct netlink_callback *cb, | |
2358 | struct nl80211_dump_wiphy_state *state) | |
2359 | { | |
c90c39da | 2360 | struct nlattr **tb = genl_family_attrbuf(&nl80211_fam); |
8cb08174 JB |
2361 | int ret = nlmsg_parse_deprecated(cb->nlh, |
2362 | GENL_HDRLEN + nl80211_fam.hdrsize, | |
2363 | tb, nl80211_fam.maxattr, | |
2364 | nl80211_policy, NULL); | |
86e8cf98 JB |
2365 | /* ignore parse errors for backward compatibility */ |
2366 | if (ret) | |
2367 | return 0; | |
2368 | ||
2369 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
2370 | if (tb[NL80211_ATTR_WIPHY]) | |
2371 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
2372 | if (tb[NL80211_ATTR_WDEV]) | |
2373 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
2374 | if (tb[NL80211_ATTR_IFINDEX]) { | |
2375 | struct net_device *netdev; | |
2376 | struct cfg80211_registered_device *rdev; | |
2377 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
2378 | ||
7f2b8562 | 2379 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
2380 | if (!netdev) |
2381 | return -ENODEV; | |
2382 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 2383 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
2384 | netdev->ieee80211_ptr->wiphy); |
2385 | state->filter_wiphy = rdev->wiphy_idx; | |
2386 | } | |
86e8cf98 JB |
2387 | } |
2388 | ||
2389 | return 0; | |
2390 | } | |
2391 | ||
55682965 JB |
2392 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
2393 | { | |
645e77de | 2394 | int idx = 0, ret; |
86e8cf98 | 2395 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 2396 | struct cfg80211_registered_device *rdev; |
3a5a423b | 2397 | |
5fe231e8 | 2398 | rtnl_lock(); |
86e8cf98 JB |
2399 | if (!state) { |
2400 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
2401 | if (!state) { |
2402 | rtnl_unlock(); | |
86e8cf98 | 2403 | return -ENOMEM; |
3713b4e3 | 2404 | } |
86e8cf98 JB |
2405 | state->filter_wiphy = -1; |
2406 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
2407 | if (ret) { | |
2408 | kfree(state); | |
2409 | rtnl_unlock(); | |
2410 | return ret; | |
3713b4e3 | 2411 | } |
86e8cf98 | 2412 | cb->args[0] = (long)state; |
3713b4e3 JB |
2413 | } |
2414 | ||
1b8ec87a ZG |
2415 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2416 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2417 | continue; |
86e8cf98 | 2418 | if (++idx <= state->start) |
55682965 | 2419 | continue; |
86e8cf98 | 2420 | if (state->filter_wiphy != -1 && |
1b8ec87a | 2421 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
2422 | continue; |
2423 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
2424 | do { | |
3bb20556 JB |
2425 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
2426 | skb, | |
3713b4e3 JB |
2427 | NETLINK_CB(cb->skb).portid, |
2428 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 2429 | NLM_F_MULTI, state); |
3713b4e3 JB |
2430 | if (ret < 0) { |
2431 | /* | |
2432 | * If sending the wiphy data didn't fit (ENOBUFS | |
2433 | * or EMSGSIZE returned), this SKB is still | |
2434 | * empty (so it's not too big because another | |
2435 | * wiphy dataset is already in the skb) and | |
2436 | * we've not tried to adjust the dump allocation | |
2437 | * yet ... then adjust the alloc size to be | |
2438 | * bigger, and return 1 but with the empty skb. | |
2439 | * This results in an empty message being RX'ed | |
2440 | * in userspace, but that is ignored. | |
2441 | * | |
2442 | * We can then retry with the larger buffer. | |
2443 | */ | |
2444 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 2445 | !skb->len && !state->split && |
3713b4e3 JB |
2446 | cb->min_dump_alloc < 4096) { |
2447 | cb->min_dump_alloc = 4096; | |
f12cb289 | 2448 | state->split_start = 0; |
d98cae64 | 2449 | rtnl_unlock(); |
3713b4e3 JB |
2450 | return 1; |
2451 | } | |
2452 | idx--; | |
2453 | break; | |
645e77de | 2454 | } |
86e8cf98 | 2455 | } while (state->split_start > 0); |
3713b4e3 | 2456 | break; |
55682965 | 2457 | } |
5fe231e8 | 2458 | rtnl_unlock(); |
55682965 | 2459 | |
86e8cf98 | 2460 | state->start = idx; |
55682965 JB |
2461 | |
2462 | return skb->len; | |
2463 | } | |
2464 | ||
86e8cf98 JB |
2465 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
2466 | { | |
2467 | kfree((void *)cb->args[0]); | |
2468 | return 0; | |
2469 | } | |
2470 | ||
55682965 JB |
2471 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
2472 | { | |
2473 | struct sk_buff *msg; | |
1b8ec87a | 2474 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 2475 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 2476 | |
645e77de | 2477 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 2478 | if (!msg) |
4c476991 | 2479 | return -ENOMEM; |
55682965 | 2480 | |
3bb20556 JB |
2481 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
2482 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 2483 | &state) < 0) { |
4c476991 JB |
2484 | nlmsg_free(msg); |
2485 | return -ENOBUFS; | |
2486 | } | |
55682965 | 2487 | |
134e6375 | 2488 | return genlmsg_reply(msg, info); |
55682965 JB |
2489 | } |
2490 | ||
31888487 JM |
2491 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
2492 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
2493 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
2494 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
2495 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
2496 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
2497 | }; | |
2498 | ||
2499 | static int parse_txq_params(struct nlattr *tb[], | |
2500 | struct ieee80211_txq_params *txq_params) | |
2501 | { | |
259d8c1e DW |
2502 | u8 ac; |
2503 | ||
a3304b0a | 2504 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
2505 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
2506 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
2507 | return -EINVAL; | |
2508 | ||
259d8c1e | 2509 | ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
2510 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
2511 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
2512 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
2513 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
2514 | ||
259d8c1e | 2515 | if (ac >= NL80211_NUM_ACS) |
a3304b0a | 2516 | return -EINVAL; |
259d8c1e | 2517 | txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); |
31888487 JM |
2518 | return 0; |
2519 | } | |
2520 | ||
f444de05 JB |
2521 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
2522 | { | |
2523 | /* | |
cc1d2806 JB |
2524 | * You can only set the channel explicitly for WDS interfaces, |
2525 | * all others have their channel managed via their respective | |
2526 | * "establish a connection" command (connect, join, ...) | |
2527 | * | |
2528 | * For AP/GO and mesh mode, the channel can be set with the | |
2529 | * channel userspace API, but is only stored and passed to the | |
2530 | * low-level driver when the AP starts or the mesh is joined. | |
2531 | * This is for backward compatibility, userspace can also give | |
2532 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
2533 | * |
2534 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
2535 | * whatever else is going on, so they have their own special |
2536 | * operation to set the monitor channel if possible. | |
f444de05 JB |
2537 | */ |
2538 | return !wdev || | |
2539 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 2540 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
2541 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
2542 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
2543 | } |
2544 | ||
9bb7e0f2 JB |
2545 | int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
2546 | struct genl_info *info, | |
2547 | struct cfg80211_chan_def *chandef) | |
683b6d3b | 2548 | { |
49f9cf0e JB |
2549 | struct netlink_ext_ack *extack = info->extack; |
2550 | struct nlattr **attrs = info->attrs; | |
dbeca2ea | 2551 | u32 control_freq; |
683b6d3b | 2552 | |
49f9cf0e | 2553 | if (!attrs[NL80211_ATTR_WIPHY_FREQ]) |
683b6d3b JB |
2554 | return -EINVAL; |
2555 | ||
49f9cf0e | 2556 | control_freq = nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]); |
683b6d3b JB |
2557 | |
2558 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
2559 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
2560 | chandef->center_freq1 = control_freq; | |
2561 | chandef->center_freq2 = 0; | |
683b6d3b JB |
2562 | |
2563 | /* Primary channel not allowed */ | |
49f9cf0e JB |
2564 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) { |
2565 | NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], | |
2566 | "Channel is disabled"); | |
683b6d3b | 2567 | return -EINVAL; |
49f9cf0e | 2568 | } |
683b6d3b | 2569 | |
49f9cf0e | 2570 | if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
3d9d1d66 JB |
2571 | enum nl80211_channel_type chantype; |
2572 | ||
49f9cf0e | 2573 | chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
3d9d1d66 JB |
2574 | |
2575 | switch (chantype) { | |
2576 | case NL80211_CHAN_NO_HT: | |
2577 | case NL80211_CHAN_HT20: | |
2578 | case NL80211_CHAN_HT40PLUS: | |
2579 | case NL80211_CHAN_HT40MINUS: | |
2580 | cfg80211_chandef_create(chandef, chandef->chan, | |
2581 | chantype); | |
ffa4629e | 2582 | /* user input for center_freq is incorrect */ |
49f9cf0e JB |
2583 | if (attrs[NL80211_ATTR_CENTER_FREQ1] && |
2584 | chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) { | |
2585 | NL_SET_ERR_MSG_ATTR(extack, | |
2586 | attrs[NL80211_ATTR_CENTER_FREQ1], | |
2587 | "bad center frequency 1"); | |
ffa4629e | 2588 | return -EINVAL; |
49f9cf0e | 2589 | } |
ffa4629e | 2590 | /* center_freq2 must be zero */ |
49f9cf0e JB |
2591 | if (attrs[NL80211_ATTR_CENTER_FREQ2] && |
2592 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) { | |
2593 | NL_SET_ERR_MSG_ATTR(extack, | |
2594 | attrs[NL80211_ATTR_CENTER_FREQ2], | |
2595 | "center frequency 2 can't be used"); | |
ffa4629e | 2596 | return -EINVAL; |
49f9cf0e | 2597 | } |
3d9d1d66 JB |
2598 | break; |
2599 | default: | |
49f9cf0e JB |
2600 | NL_SET_ERR_MSG_ATTR(extack, |
2601 | attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE], | |
2602 | "invalid channel type"); | |
3d9d1d66 JB |
2603 | return -EINVAL; |
2604 | } | |
49f9cf0e | 2605 | } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
3d9d1d66 | 2606 | chandef->width = |
49f9cf0e JB |
2607 | nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
2608 | if (attrs[NL80211_ATTR_CENTER_FREQ1]) | |
3d9d1d66 | 2609 | chandef->center_freq1 = |
49f9cf0e JB |
2610 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]); |
2611 | if (attrs[NL80211_ATTR_CENTER_FREQ2]) | |
3d9d1d66 | 2612 | chandef->center_freq2 = |
49f9cf0e | 2613 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]); |
3d9d1d66 JB |
2614 | } |
2615 | ||
49f9cf0e JB |
2616 | if (!cfg80211_chandef_valid(chandef)) { |
2617 | NL_SET_ERR_MSG(extack, "invalid channel definition"); | |
3d9d1d66 | 2618 | return -EINVAL; |
49f9cf0e | 2619 | } |
3d9d1d66 | 2620 | |
9f5e8f6e | 2621 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
49f9cf0e JB |
2622 | IEEE80211_CHAN_DISABLED)) { |
2623 | NL_SET_ERR_MSG(extack, "(extension) channel is disabled"); | |
3d9d1d66 | 2624 | return -EINVAL; |
49f9cf0e | 2625 | } |
3d9d1d66 | 2626 | |
2f301ab2 SW |
2627 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
2628 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
49f9cf0e JB |
2629 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) { |
2630 | NL_SET_ERR_MSG(extack, "5/10 MHz not supported"); | |
2f301ab2 | 2631 | return -EINVAL; |
49f9cf0e | 2632 | } |
2f301ab2 | 2633 | |
683b6d3b JB |
2634 | return 0; |
2635 | } | |
2636 | ||
f444de05 | 2637 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 2638 | struct net_device *dev, |
f444de05 JB |
2639 | struct genl_info *info) |
2640 | { | |
683b6d3b | 2641 | struct cfg80211_chan_def chandef; |
f444de05 | 2642 | int result; |
e8c9bd5b | 2643 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 2644 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 2645 | |
e16821bc JM |
2646 | if (dev) |
2647 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
2648 | if (!nl80211_can_set_dev_channel(wdev)) |
2649 | return -EOPNOTSUPP; | |
e16821bc JM |
2650 | if (wdev) |
2651 | iftype = wdev->iftype; | |
f444de05 | 2652 | |
683b6d3b JB |
2653 | result = nl80211_parse_chandef(rdev, info, &chandef); |
2654 | if (result) | |
2655 | return result; | |
f444de05 | 2656 | |
e8c9bd5b | 2657 | switch (iftype) { |
aa430da4 JB |
2658 | case NL80211_IFTYPE_AP: |
2659 | case NL80211_IFTYPE_P2P_GO: | |
923b352f AN |
2660 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
2661 | iftype)) { | |
aa430da4 JB |
2662 | result = -EINVAL; |
2663 | break; | |
2664 | } | |
e16821bc JM |
2665 | if (wdev->beacon_interval) { |
2666 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
2667 | !(rdev->wiphy.features & | |
2668 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
2669 | result = -EBUSY; | |
2670 | break; | |
2671 | } | |
2672 | ||
2673 | /* Only allow dynamic channel width changes */ | |
2674 | if (chandef.chan != wdev->preset_chandef.chan) { | |
2675 | result = -EBUSY; | |
2676 | break; | |
2677 | } | |
2678 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
2679 | if (result) | |
2680 | break; | |
2681 | } | |
683b6d3b | 2682 | wdev->preset_chandef = chandef; |
aa430da4 JB |
2683 | result = 0; |
2684 | break; | |
cc1d2806 | 2685 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 2686 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 2687 | break; |
e8c9bd5b | 2688 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 2689 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2690 | break; |
aa430da4 | 2691 | default: |
e8c9bd5b | 2692 | result = -EINVAL; |
f444de05 | 2693 | } |
f444de05 JB |
2694 | |
2695 | return result; | |
2696 | } | |
2697 | ||
2698 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2699 | { | |
4c476991 JB |
2700 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2701 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2702 | |
e16821bc | 2703 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2704 | } |
2705 | ||
e8347eba BJ |
2706 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2707 | { | |
43b19952 JB |
2708 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2709 | struct net_device *dev = info->user_ptr[1]; | |
2710 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2711 | const u8 *bssid; |
e8347eba BJ |
2712 | |
2713 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2714 | return -EINVAL; | |
2715 | ||
43b19952 JB |
2716 | if (netif_running(dev)) |
2717 | return -EBUSY; | |
e8347eba | 2718 | |
43b19952 JB |
2719 | if (!rdev->ops->set_wds_peer) |
2720 | return -EOPNOTSUPP; | |
e8347eba | 2721 | |
43b19952 JB |
2722 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2723 | return -EOPNOTSUPP; | |
e8347eba BJ |
2724 | |
2725 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2726 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2727 | } |
2728 | ||
55682965 JB |
2729 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2730 | { | |
2731 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2732 | struct net_device *netdev = NULL; |
2733 | struct wireless_dev *wdev; | |
a1e567c8 | 2734 | int result = 0, rem_txq_params = 0; |
31888487 | 2735 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2736 | u32 changed; |
2737 | u8 retry_short = 0, retry_long = 0; | |
2738 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2739 | u8 coverage_class = 0; |
52539ca8 | 2740 | u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; |
55682965 | 2741 | |
5fe231e8 JB |
2742 | ASSERT_RTNL(); |
2743 | ||
f444de05 JB |
2744 | /* |
2745 | * Try to find the wiphy and netdev. Normally this | |
2746 | * function shouldn't need the netdev, but this is | |
2747 | * done for backward compatibility -- previously | |
2748 | * setting the channel was done per wiphy, but now | |
2749 | * it is per netdev. Previous userland like hostapd | |
2750 | * also passed a netdev to set_wiphy, so that it is | |
2751 | * possible to let that go to the right netdev! | |
2752 | */ | |
4bbf4d56 | 2753 | |
f444de05 JB |
2754 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2755 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2756 | ||
7f2b8562 | 2757 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2758 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2759 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2760 | else |
f444de05 | 2761 | netdev = NULL; |
4bbf4d56 JB |
2762 | } |
2763 | ||
f444de05 | 2764 | if (!netdev) { |
878d9ec7 JB |
2765 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2766 | info->attrs); | |
5fe231e8 | 2767 | if (IS_ERR(rdev)) |
4c476991 | 2768 | return PTR_ERR(rdev); |
f444de05 JB |
2769 | wdev = NULL; |
2770 | netdev = NULL; | |
2771 | result = 0; | |
71fe96bf | 2772 | } else |
f444de05 | 2773 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2774 | |
2775 | /* | |
2776 | * end workaround code, by now the rdev is available | |
2777 | * and locked, and wdev may or may not be NULL. | |
2778 | */ | |
4bbf4d56 JB |
2779 | |
2780 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2781 | result = cfg80211_dev_rename( |
2782 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2783 | |
4bbf4d56 | 2784 | if (result) |
7f2b8562 | 2785 | return result; |
31888487 JM |
2786 | |
2787 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2788 | struct ieee80211_txq_params txq_params; | |
2789 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2790 | ||
7f2b8562 YX |
2791 | if (!rdev->ops->set_txq_params) |
2792 | return -EOPNOTSUPP; | |
31888487 | 2793 | |
7f2b8562 YX |
2794 | if (!netdev) |
2795 | return -EINVAL; | |
f70f01c2 | 2796 | |
133a3ff2 | 2797 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2798 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2799 | return -EINVAL; | |
133a3ff2 | 2800 | |
7f2b8562 YX |
2801 | if (!netif_running(netdev)) |
2802 | return -ENETDOWN; | |
2b5f8b0b | 2803 | |
31888487 JM |
2804 | nla_for_each_nested(nl_txq_params, |
2805 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2806 | rem_txq_params) { | |
8cb08174 JB |
2807 | result = nla_parse_nested_deprecated(tb, |
2808 | NL80211_TXQ_ATTR_MAX, | |
2809 | nl_txq_params, | |
2810 | txq_params_policy, | |
2811 | info->extack); | |
ae811e21 JB |
2812 | if (result) |
2813 | return result; | |
31888487 JM |
2814 | result = parse_txq_params(tb, &txq_params); |
2815 | if (result) | |
7f2b8562 | 2816 | return result; |
31888487 | 2817 | |
e35e4d28 HG |
2818 | result = rdev_set_txq_params(rdev, netdev, |
2819 | &txq_params); | |
31888487 | 2820 | if (result) |
7f2b8562 | 2821 | return result; |
31888487 JM |
2822 | } |
2823 | } | |
55682965 | 2824 | |
72bdcf34 | 2825 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2826 | result = __nl80211_set_channel( |
2827 | rdev, | |
2828 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2829 | info); | |
72bdcf34 | 2830 | if (result) |
7f2b8562 | 2831 | return result; |
72bdcf34 JM |
2832 | } |
2833 | ||
98d2ff8b | 2834 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2835 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2836 | enum nl80211_tx_power_setting type; |
2837 | int idx, mbm = 0; | |
2838 | ||
c8442118 JB |
2839 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2840 | txp_wdev = NULL; | |
2841 | ||
7f2b8562 YX |
2842 | if (!rdev->ops->set_tx_power) |
2843 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2844 | |
2845 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2846 | type = nla_get_u32(info->attrs[idx]); | |
2847 | ||
2848 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2849 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2850 | return -EINVAL; | |
98d2ff8b JO |
2851 | |
2852 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2853 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2854 | mbm = nla_get_u32(info->attrs[idx]); | |
2855 | } | |
2856 | ||
c8442118 | 2857 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2858 | if (result) |
7f2b8562 | 2859 | return result; |
98d2ff8b JO |
2860 | } |
2861 | ||
afe0cbf8 BR |
2862 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2863 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2864 | u32 tx_ant, rx_ant; | |
7a087e74 | 2865 | |
7f531e03 BR |
2866 | if ((!rdev->wiphy.available_antennas_tx && |
2867 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2868 | !rdev->ops->set_antenna) |
2869 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2870 | |
2871 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2872 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2873 | ||
a7ffac95 | 2874 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2875 | * available antenna masks, except for the "all" mask */ |
2876 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2877 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2878 | return -EINVAL; | |
a7ffac95 | 2879 | |
7f531e03 BR |
2880 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2881 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2882 | |
e35e4d28 | 2883 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2884 | if (result) |
7f2b8562 | 2885 | return result; |
afe0cbf8 BR |
2886 | } |
2887 | ||
b9a5f8ca JM |
2888 | changed = 0; |
2889 | ||
2890 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2891 | retry_short = nla_get_u8( | |
2892 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 | 2893 | |
b9a5f8ca JM |
2894 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2895 | } | |
2896 | ||
2897 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2898 | retry_long = nla_get_u8( | |
2899 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 | 2900 | |
b9a5f8ca JM |
2901 | changed |= WIPHY_PARAM_RETRY_LONG; |
2902 | } | |
2903 | ||
2904 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2905 | frag_threshold = nla_get_u32( | |
2906 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2907 | if (frag_threshold < 256) |
2908 | return -EINVAL; | |
2909 | ||
b9a5f8ca JM |
2910 | if (frag_threshold != (u32) -1) { |
2911 | /* | |
2912 | * Fragments (apart from the last one) are required to | |
2913 | * have even length. Make the fragmentation code | |
2914 | * simpler by stripping LSB should someone try to use | |
2915 | * odd threshold value. | |
2916 | */ | |
2917 | frag_threshold &= ~0x1; | |
2918 | } | |
2919 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2920 | } | |
2921 | ||
2922 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2923 | rts_threshold = nla_get_u32( | |
2924 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2925 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2926 | } | |
2927 | ||
81077e82 | 2928 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
3057dbfd LB |
2929 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
2930 | return -EINVAL; | |
2931 | ||
81077e82 LT |
2932 | coverage_class = nla_get_u8( |
2933 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2934 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2935 | } | |
2936 | ||
3057dbfd LB |
2937 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
2938 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | |
2939 | return -EOPNOTSUPP; | |
2940 | ||
2941 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
2942 | } |
2943 | ||
52539ca8 THJ |
2944 | if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { |
2945 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
2946 | NL80211_EXT_FEATURE_TXQS)) | |
2947 | return -EOPNOTSUPP; | |
2948 | txq_limit = nla_get_u32( | |
2949 | info->attrs[NL80211_ATTR_TXQ_LIMIT]); | |
2950 | changed |= WIPHY_PARAM_TXQ_LIMIT; | |
2951 | } | |
2952 | ||
2953 | if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { | |
2954 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
2955 | NL80211_EXT_FEATURE_TXQS)) | |
2956 | return -EOPNOTSUPP; | |
2957 | txq_memory_limit = nla_get_u32( | |
2958 | info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); | |
2959 | changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; | |
2960 | } | |
2961 | ||
2962 | if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { | |
2963 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
2964 | NL80211_EXT_FEATURE_TXQS)) | |
2965 | return -EOPNOTSUPP; | |
2966 | txq_quantum = nla_get_u32( | |
2967 | info->attrs[NL80211_ATTR_TXQ_QUANTUM]); | |
2968 | changed |= WIPHY_PARAM_TXQ_QUANTUM; | |
2969 | } | |
2970 | ||
b9a5f8ca JM |
2971 | if (changed) { |
2972 | u8 old_retry_short, old_retry_long; | |
2973 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2974 | u8 old_coverage_class; |
52539ca8 | 2975 | u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; |
b9a5f8ca | 2976 | |
7f2b8562 YX |
2977 | if (!rdev->ops->set_wiphy_params) |
2978 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2979 | |
2980 | old_retry_short = rdev->wiphy.retry_short; | |
2981 | old_retry_long = rdev->wiphy.retry_long; | |
2982 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2983 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2984 | old_coverage_class = rdev->wiphy.coverage_class; |
52539ca8 THJ |
2985 | old_txq_limit = rdev->wiphy.txq_limit; |
2986 | old_txq_memory_limit = rdev->wiphy.txq_memory_limit; | |
2987 | old_txq_quantum = rdev->wiphy.txq_quantum; | |
b9a5f8ca JM |
2988 | |
2989 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2990 | rdev->wiphy.retry_short = retry_short; | |
2991 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2992 | rdev->wiphy.retry_long = retry_long; | |
2993 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2994 | rdev->wiphy.frag_threshold = frag_threshold; | |
2995 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2996 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2997 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2998 | rdev->wiphy.coverage_class = coverage_class; | |
52539ca8 THJ |
2999 | if (changed & WIPHY_PARAM_TXQ_LIMIT) |
3000 | rdev->wiphy.txq_limit = txq_limit; | |
3001 | if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) | |
3002 | rdev->wiphy.txq_memory_limit = txq_memory_limit; | |
3003 | if (changed & WIPHY_PARAM_TXQ_QUANTUM) | |
3004 | rdev->wiphy.txq_quantum = txq_quantum; | |
b9a5f8ca | 3005 | |
e35e4d28 | 3006 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
3007 | if (result) { |
3008 | rdev->wiphy.retry_short = old_retry_short; | |
3009 | rdev->wiphy.retry_long = old_retry_long; | |
3010 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
3011 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 3012 | rdev->wiphy.coverage_class = old_coverage_class; |
52539ca8 THJ |
3013 | rdev->wiphy.txq_limit = old_txq_limit; |
3014 | rdev->wiphy.txq_memory_limit = old_txq_memory_limit; | |
3015 | rdev->wiphy.txq_quantum = old_txq_quantum; | |
9189ee31 | 3016 | return result; |
b9a5f8ca JM |
3017 | } |
3018 | } | |
7f2b8562 | 3019 | return 0; |
55682965 JB |
3020 | } |
3021 | ||
683b6d3b | 3022 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 3023 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 3024 | { |
601555cd JB |
3025 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
3026 | return -EINVAL; | |
3d9d1d66 | 3027 | |
683b6d3b JB |
3028 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
3029 | chandef->chan->center_freq)) | |
3030 | return -ENOBUFS; | |
3d9d1d66 JB |
3031 | switch (chandef->width) { |
3032 | case NL80211_CHAN_WIDTH_20_NOHT: | |
3033 | case NL80211_CHAN_WIDTH_20: | |
3034 | case NL80211_CHAN_WIDTH_40: | |
3035 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
3036 | cfg80211_get_chandef_type(chandef))) | |
3037 | return -ENOBUFS; | |
3038 | break; | |
3039 | default: | |
3040 | break; | |
3041 | } | |
3042 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
3043 | return -ENOBUFS; | |
3044 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
3045 | return -ENOBUFS; | |
3046 | if (chandef->center_freq2 && | |
3047 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
3048 | return -ENOBUFS; |
3049 | return 0; | |
3050 | } | |
3051 | ||
15e47304 | 3052 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 3053 | struct cfg80211_registered_device *rdev, |
3d1a5bbf AZ |
3054 | struct wireless_dev *wdev, |
3055 | enum nl80211_commands cmd) | |
55682965 | 3056 | { |
72fb2abc | 3057 | struct net_device *dev = wdev->netdev; |
55682965 JB |
3058 | void *hdr; |
3059 | ||
3d1a5bbf AZ |
3060 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
3061 | cmd != NL80211_CMD_DEL_INTERFACE && | |
3062 | cmd != NL80211_CMD_SET_INTERFACE); | |
8f894be2 TB |
3063 | |
3064 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | |
55682965 JB |
3065 | if (!hdr) |
3066 | return -1; | |
3067 | ||
72fb2abc JB |
3068 | if (dev && |
3069 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 3070 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
3071 | goto nla_put_failure; |
3072 | ||
3073 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
3074 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
2dad624e ND |
3075 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
3076 | NL80211_ATTR_PAD) || | |
98104fde | 3077 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
3078 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
3079 | rdev->devlist_generation ^ | |
446faa15 AQ |
3080 | (cfg80211_rdev_list_generation << 2)) || |
3081 | nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) | |
9360ffd1 | 3082 | goto nla_put_failure; |
f5ea9120 | 3083 | |
5b7ccaf3 | 3084 | if (rdev->ops->get_channel) { |
683b6d3b JB |
3085 | int ret; |
3086 | struct cfg80211_chan_def chandef; | |
3087 | ||
3088 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
3089 | if (ret == 0) { | |
3090 | if (nl80211_send_chandef(msg, &chandef)) | |
3091 | goto nla_put_failure; | |
3092 | } | |
d91df0e3 PF |
3093 | } |
3094 | ||
d55d0d59 RM |
3095 | if (rdev->ops->get_tx_power) { |
3096 | int dbm, ret; | |
3097 | ||
3098 | ret = rdev_get_tx_power(rdev, wdev, &dbm); | |
3099 | if (ret == 0 && | |
3100 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, | |
3101 | DBM_TO_MBM(dbm))) | |
3102 | goto nla_put_failure; | |
3103 | } | |
3104 | ||
44905265 JB |
3105 | wdev_lock(wdev); |
3106 | switch (wdev->iftype) { | |
3107 | case NL80211_IFTYPE_AP: | |
3108 | if (wdev->ssid_len && | |
3109 | nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
4564b187 | 3110 | goto nla_put_failure_locked; |
44905265 JB |
3111 | break; |
3112 | case NL80211_IFTYPE_STATION: | |
3113 | case NL80211_IFTYPE_P2P_CLIENT: | |
3114 | case NL80211_IFTYPE_ADHOC: { | |
3115 | const u8 *ssid_ie; | |
3116 | if (!wdev->current_bss) | |
3117 | break; | |
7a94b8c2 | 3118 | rcu_read_lock(); |
44905265 JB |
3119 | ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, |
3120 | WLAN_EID_SSID); | |
7a94b8c2 DB |
3121 | if (ssid_ie && |
3122 | nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2)) | |
3123 | goto nla_put_failure_rcu_locked; | |
3124 | rcu_read_unlock(); | |
44905265 JB |
3125 | break; |
3126 | } | |
3127 | default: | |
3128 | /* nothing */ | |
3129 | break; | |
b84e7a05 | 3130 | } |
44905265 | 3131 | wdev_unlock(wdev); |
b84e7a05 | 3132 | |
52539ca8 THJ |
3133 | if (rdev->ops->get_txq_stats) { |
3134 | struct cfg80211_txq_stats txqstats = {}; | |
3135 | int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); | |
3136 | ||
3137 | if (ret == 0 && | |
3138 | !nl80211_put_txq_stats(msg, &txqstats, | |
3139 | NL80211_ATTR_TXQ_STATS)) | |
3140 | goto nla_put_failure; | |
3141 | } | |
3142 | ||
053c095a JB |
3143 | genlmsg_end(msg, hdr); |
3144 | return 0; | |
55682965 | 3145 | |
7a94b8c2 DB |
3146 | nla_put_failure_rcu_locked: |
3147 | rcu_read_unlock(); | |
4564b187 JB |
3148 | nla_put_failure_locked: |
3149 | wdev_unlock(wdev); | |
55682965 | 3150 | nla_put_failure: |
bc3ed28c TG |
3151 | genlmsg_cancel(msg, hdr); |
3152 | return -EMSGSIZE; | |
55682965 JB |
3153 | } |
3154 | ||
3155 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
3156 | { | |
3157 | int wp_idx = 0; | |
3158 | int if_idx = 0; | |
3159 | int wp_start = cb->args[0]; | |
3160 | int if_start = cb->args[1]; | |
b7fb44da | 3161 | int filter_wiphy = -1; |
f5ea9120 | 3162 | struct cfg80211_registered_device *rdev; |
55682965 | 3163 | struct wireless_dev *wdev; |
ea90e0dc | 3164 | int ret; |
55682965 | 3165 | |
5fe231e8 | 3166 | rtnl_lock(); |
b7fb44da DK |
3167 | if (!cb->args[2]) { |
3168 | struct nl80211_dump_wiphy_state state = { | |
3169 | .filter_wiphy = -1, | |
3170 | }; | |
b7fb44da DK |
3171 | |
3172 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); | |
3173 | if (ret) | |
ea90e0dc | 3174 | goto out_unlock; |
b7fb44da DK |
3175 | |
3176 | filter_wiphy = state.filter_wiphy; | |
3177 | ||
3178 | /* | |
3179 | * if filtering, set cb->args[2] to +1 since 0 is the default | |
3180 | * value needed to determine that parsing is necessary. | |
3181 | */ | |
3182 | if (filter_wiphy >= 0) | |
3183 | cb->args[2] = filter_wiphy + 1; | |
3184 | else | |
3185 | cb->args[2] = -1; | |
3186 | } else if (cb->args[2] > 0) { | |
3187 | filter_wiphy = cb->args[2] - 1; | |
3188 | } | |
3189 | ||
f5ea9120 JB |
3190 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
3191 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 3192 | continue; |
bba95fef JB |
3193 | if (wp_idx < wp_start) { |
3194 | wp_idx++; | |
55682965 | 3195 | continue; |
bba95fef | 3196 | } |
b7fb44da DK |
3197 | |
3198 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) | |
3199 | continue; | |
3200 | ||
55682965 JB |
3201 | if_idx = 0; |
3202 | ||
53873f13 | 3203 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
bba95fef JB |
3204 | if (if_idx < if_start) { |
3205 | if_idx++; | |
55682965 | 3206 | continue; |
bba95fef | 3207 | } |
15e47304 | 3208 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 3209 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
3d1a5bbf AZ |
3210 | rdev, wdev, |
3211 | NL80211_CMD_NEW_INTERFACE) < 0) { | |
bba95fef JB |
3212 | goto out; |
3213 | } | |
3214 | if_idx++; | |
55682965 | 3215 | } |
bba95fef JB |
3216 | |
3217 | wp_idx++; | |
55682965 | 3218 | } |
bba95fef | 3219 | out: |
55682965 JB |
3220 | cb->args[0] = wp_idx; |
3221 | cb->args[1] = if_idx; | |
3222 | ||
ea90e0dc JB |
3223 | ret = skb->len; |
3224 | out_unlock: | |
3225 | rtnl_unlock(); | |
3226 | ||
3227 | return ret; | |
55682965 JB |
3228 | } |
3229 | ||
3230 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
3231 | { | |
3232 | struct sk_buff *msg; | |
1b8ec87a | 3233 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 3234 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 3235 | |
fd2120ca | 3236 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 3237 | if (!msg) |
4c476991 | 3238 | return -ENOMEM; |
55682965 | 3239 | |
15e47304 | 3240 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
3d1a5bbf | 3241 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
4c476991 JB |
3242 | nlmsg_free(msg); |
3243 | return -ENOBUFS; | |
3244 | } | |
55682965 | 3245 | |
134e6375 | 3246 | return genlmsg_reply(msg, info); |
55682965 JB |
3247 | } |
3248 | ||
66f7ac50 MW |
3249 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
3250 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
3251 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
3252 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
3253 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
3254 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 3255 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
3256 | }; |
3257 | ||
3258 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
3259 | { | |
3260 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
3261 | int flag; | |
3262 | ||
3263 | *mntrflags = 0; | |
3264 | ||
3265 | if (!nla) | |
3266 | return -EINVAL; | |
3267 | ||
8cb08174 | 3268 | if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL)) |
66f7ac50 MW |
3269 | return -EINVAL; |
3270 | ||
3271 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
3272 | if (flags[flag]) | |
3273 | *mntrflags |= (1<<flag); | |
3274 | ||
818a986e JB |
3275 | *mntrflags |= MONITOR_FLAG_CHANGED; |
3276 | ||
66f7ac50 MW |
3277 | return 0; |
3278 | } | |
3279 | ||
1db77596 JB |
3280 | static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, |
3281 | enum nl80211_iftype type, | |
3282 | struct genl_info *info, | |
3283 | struct vif_params *params) | |
3284 | { | |
3285 | bool change = false; | |
3286 | int err; | |
3287 | ||
3288 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { | |
3289 | if (type != NL80211_IFTYPE_MONITOR) | |
3290 | return -EINVAL; | |
3291 | ||
3292 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], | |
3293 | ¶ms->flags); | |
3294 | if (err) | |
3295 | return err; | |
3296 | ||
3297 | change = true; | |
3298 | } | |
3299 | ||
3300 | if (params->flags & MONITOR_FLAG_ACTIVE && | |
3301 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) | |
3302 | return -EOPNOTSUPP; | |
3303 | ||
3304 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { | |
3305 | const u8 *mumimo_groups; | |
3306 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; | |
3307 | ||
3308 | if (type != NL80211_IFTYPE_MONITOR) | |
3309 | return -EINVAL; | |
3310 | ||
3311 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) | |
3312 | return -EOPNOTSUPP; | |
3313 | ||
3314 | mumimo_groups = | |
3315 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); | |
3316 | ||
3317 | /* bits 0 and 63 are reserved and must be zero */ | |
4954601f JB |
3318 | if ((mumimo_groups[0] & BIT(0)) || |
3319 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) | |
1db77596 JB |
3320 | return -EINVAL; |
3321 | ||
3322 | params->vht_mumimo_groups = mumimo_groups; | |
3323 | change = true; | |
3324 | } | |
3325 | ||
3326 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { | |
3327 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; | |
3328 | ||
3329 | if (type != NL80211_IFTYPE_MONITOR) | |
3330 | return -EINVAL; | |
3331 | ||
3332 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) | |
3333 | return -EOPNOTSUPP; | |
3334 | ||
3335 | params->vht_mumimo_follow_addr = | |
3336 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); | |
3337 | change = true; | |
3338 | } | |
3339 | ||
3340 | return change ? 1 : 0; | |
3341 | } | |
3342 | ||
9bc383de | 3343 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
3344 | struct net_device *netdev, u8 use_4addr, |
3345 | enum nl80211_iftype iftype) | |
9bc383de | 3346 | { |
ad4bb6f8 | 3347 | if (!use_4addr) { |
f350a0a8 | 3348 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 3349 | return -EBUSY; |
9bc383de | 3350 | return 0; |
ad4bb6f8 | 3351 | } |
9bc383de JB |
3352 | |
3353 | switch (iftype) { | |
3354 | case NL80211_IFTYPE_AP_VLAN: | |
3355 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
3356 | return 0; | |
3357 | break; | |
3358 | case NL80211_IFTYPE_STATION: | |
3359 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
3360 | return 0; | |
3361 | break; | |
3362 | default: | |
3363 | break; | |
3364 | } | |
3365 | ||
3366 | return -EOPNOTSUPP; | |
3367 | } | |
3368 | ||
55682965 JB |
3369 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
3370 | { | |
4c476991 | 3371 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 3372 | struct vif_params params; |
e36d56b6 | 3373 | int err; |
04a773ad | 3374 | enum nl80211_iftype otype, ntype; |
4c476991 | 3375 | struct net_device *dev = info->user_ptr[1]; |
ac7f9cfa | 3376 | bool change = false; |
55682965 | 3377 | |
2ec600d6 LCC |
3378 | memset(¶ms, 0, sizeof(params)); |
3379 | ||
04a773ad | 3380 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 3381 | |
723b038d | 3382 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 3383 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 3384 | if (otype != ntype) |
ac7f9cfa | 3385 | change = true; |
723b038d JB |
3386 | } |
3387 | ||
92ffe055 | 3388 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
3389 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
3390 | ||
4c476991 JB |
3391 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
3392 | return -EINVAL; | |
29cbe68c JB |
3393 | if (netif_running(dev)) |
3394 | return -EBUSY; | |
3395 | ||
3396 | wdev_lock(wdev); | |
3397 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
3398 | IEEE80211_MAX_MESH_ID_LEN); | |
3399 | wdev->mesh_id_up_len = | |
3400 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
3401 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
3402 | wdev->mesh_id_up_len); | |
3403 | wdev_unlock(wdev); | |
2ec600d6 LCC |
3404 | } |
3405 | ||
8b787643 FF |
3406 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
3407 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
3408 | change = true; | |
ad4bb6f8 | 3409 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 3410 | if (err) |
4c476991 | 3411 | return err; |
8b787643 FF |
3412 | } else { |
3413 | params.use_4addr = -1; | |
3414 | } | |
3415 | ||
1db77596 JB |
3416 | err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); |
3417 | if (err < 0) | |
3418 | return err; | |
3419 | if (err > 0) | |
c6e6a0c8 | 3420 | change = true; |
e057d3c3 | 3421 | |
ac7f9cfa | 3422 | if (change) |
818a986e | 3423 | err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); |
ac7f9cfa JB |
3424 | else |
3425 | err = 0; | |
60719ffd | 3426 | |
9bc383de JB |
3427 | if (!err && params.use_4addr != -1) |
3428 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
3429 | ||
3d1a5bbf AZ |
3430 | if (change && !err) { |
3431 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3432 | ||
3433 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE); | |
3434 | } | |
3435 | ||
55682965 JB |
3436 | return err; |
3437 | } | |
3438 | ||
3439 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
3440 | { | |
4c476991 | 3441 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 3442 | struct vif_params params; |
84efbb84 | 3443 | struct wireless_dev *wdev; |
896ff063 | 3444 | struct sk_buff *msg; |
55682965 JB |
3445 | int err; |
3446 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
3447 | ||
78f22b6a JB |
3448 | /* to avoid failing a new interface creation due to pending removal */ |
3449 | cfg80211_destroy_ifaces(rdev); | |
3450 | ||
2ec600d6 LCC |
3451 | memset(¶ms, 0, sizeof(params)); |
3452 | ||
55682965 JB |
3453 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
3454 | return -EINVAL; | |
3455 | ||
ab0d76f6 | 3456 | if (info->attrs[NL80211_ATTR_IFTYPE]) |
55682965 | 3457 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
55682965 | 3458 | |
79c97e97 | 3459 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
3460 | !(rdev->wiphy.interface_modes & (1 << type))) |
3461 | return -EOPNOTSUPP; | |
55682965 | 3462 | |
cb3b7d87 | 3463 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
e8f479b1 BG |
3464 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
3465 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
3466 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
3467 | ETH_ALEN); | |
3468 | if (!is_valid_ether_addr(params.macaddr)) | |
3469 | return -EADDRNOTAVAIL; | |
3470 | } | |
3471 | ||
9bc383de | 3472 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 3473 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 3474 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 3475 | if (err) |
4c476991 | 3476 | return err; |
9bc383de | 3477 | } |
8b787643 | 3478 | |
1db77596 JB |
3479 | err = nl80211_parse_mon_options(rdev, type, info, ¶ms); |
3480 | if (err < 0) | |
3481 | return err; | |
e057d3c3 | 3482 | |
a18c7192 JB |
3483 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
3484 | if (!msg) | |
3485 | return -ENOMEM; | |
3486 | ||
e35e4d28 HG |
3487 | wdev = rdev_add_virtual_intf(rdev, |
3488 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
818a986e | 3489 | NET_NAME_USER, type, ¶ms); |
d687cbb7 RM |
3490 | if (WARN_ON(!wdev)) { |
3491 | nlmsg_free(msg); | |
3492 | return -EPROTO; | |
3493 | } else if (IS_ERR(wdev)) { | |
1c90f9d4 | 3494 | nlmsg_free(msg); |
84efbb84 | 3495 | return PTR_ERR(wdev); |
1c90f9d4 | 3496 | } |
2ec600d6 | 3497 | |
18e5ca65 | 3498 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
78f22b6a JB |
3499 | wdev->owner_nlportid = info->snd_portid; |
3500 | ||
98104fde JB |
3501 | switch (type) { |
3502 | case NL80211_IFTYPE_MESH_POINT: | |
3503 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
3504 | break; | |
29cbe68c JB |
3505 | wdev_lock(wdev); |
3506 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
3507 | IEEE80211_MAX_MESH_ID_LEN); | |
3508 | wdev->mesh_id_up_len = | |
3509 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
3510 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
3511 | wdev->mesh_id_up_len); | |
3512 | wdev_unlock(wdev); | |
98104fde | 3513 | break; |
cb3b7d87 | 3514 | case NL80211_IFTYPE_NAN: |
98104fde JB |
3515 | case NL80211_IFTYPE_P2P_DEVICE: |
3516 | /* | |
cb3b7d87 | 3517 | * P2P Device and NAN do not have a netdev, so don't go |
98104fde JB |
3518 | * through the netdev notifier and must be added here |
3519 | */ | |
e4d4216e | 3520 | cfg80211_init_wdev(rdev, wdev); |
98104fde JB |
3521 | break; |
3522 | default: | |
3523 | break; | |
29cbe68c JB |
3524 | } |
3525 | ||
15e47304 | 3526 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
3d1a5bbf | 3527 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
1c90f9d4 JB |
3528 | nlmsg_free(msg); |
3529 | return -ENOBUFS; | |
3530 | } | |
3531 | ||
3532 | return genlmsg_reply(msg, info); | |
55682965 JB |
3533 | } |
3534 | ||
3535 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
3536 | { | |
4c476991 | 3537 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 3538 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 3539 | |
4c476991 JB |
3540 | if (!rdev->ops->del_virtual_intf) |
3541 | return -EOPNOTSUPP; | |
55682965 | 3542 | |
84efbb84 JB |
3543 | /* |
3544 | * If we remove a wireless device without a netdev then clear | |
3545 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
3546 | * to check if it needs to do dev_put(). Otherwise it crashes | |
3547 | * since the wdev has been freed, unlike with a netdev where | |
3548 | * we need the dev_put() for the netdev to really be freed. | |
3549 | */ | |
3550 | if (!wdev->netdev) | |
3551 | info->user_ptr[1] = NULL; | |
3552 | ||
7f8ed01e | 3553 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
3554 | } |
3555 | ||
1d9d9213 SW |
3556 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
3557 | { | |
3558 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3559 | struct net_device *dev = info->user_ptr[1]; | |
3560 | u16 noack_map; | |
3561 | ||
3562 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
3563 | return -EINVAL; | |
3564 | ||
3565 | if (!rdev->ops->set_noack_map) | |
3566 | return -EOPNOTSUPP; | |
3567 | ||
3568 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
3569 | ||
e35e4d28 | 3570 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
3571 | } |
3572 | ||
41ade00f JB |
3573 | struct get_key_cookie { |
3574 | struct sk_buff *msg; | |
3575 | int error; | |
b9454e83 | 3576 | int idx; |
41ade00f JB |
3577 | }; |
3578 | ||
3579 | static void get_key_callback(void *c, struct key_params *params) | |
3580 | { | |
b9454e83 | 3581 | struct nlattr *key; |
41ade00f JB |
3582 | struct get_key_cookie *cookie = c; |
3583 | ||
9360ffd1 DM |
3584 | if ((params->key && |
3585 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
3586 | params->key_len, params->key)) || | |
3587 | (params->seq && | |
3588 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
3589 | params->seq_len, params->seq)) || | |
3590 | (params->cipher && | |
3591 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
3592 | params->cipher))) | |
3593 | goto nla_put_failure; | |
41ade00f | 3594 | |
ae0be8de | 3595 | key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY); |
b9454e83 JB |
3596 | if (!key) |
3597 | goto nla_put_failure; | |
3598 | ||
9360ffd1 DM |
3599 | if ((params->key && |
3600 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
3601 | params->key_len, params->key)) || | |
3602 | (params->seq && | |
3603 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
3604 | params->seq_len, params->seq)) || | |
3605 | (params->cipher && | |
3606 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
3607 | params->cipher))) | |
3608 | goto nla_put_failure; | |
b9454e83 | 3609 | |
efdfce72 | 3610 | if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx)) |
9360ffd1 | 3611 | goto nla_put_failure; |
b9454e83 JB |
3612 | |
3613 | nla_nest_end(cookie->msg, key); | |
3614 | ||
41ade00f JB |
3615 | return; |
3616 | nla_put_failure: | |
3617 | cookie->error = 1; | |
3618 | } | |
3619 | ||
3620 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
3621 | { | |
4c476991 | 3622 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3623 | int err; |
4c476991 | 3624 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3625 | u8 key_idx = 0; |
e31b8213 JB |
3626 | const u8 *mac_addr = NULL; |
3627 | bool pairwise; | |
41ade00f JB |
3628 | struct get_key_cookie cookie = { |
3629 | .error = 0, | |
3630 | }; | |
3631 | void *hdr; | |
3632 | struct sk_buff *msg; | |
3633 | ||
3634 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
3635 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
3636 | ||
41ade00f JB |
3637 | if (info->attrs[NL80211_ATTR_MAC]) |
3638 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3639 | ||
e31b8213 JB |
3640 | pairwise = !!mac_addr; |
3641 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
3642 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
7a087e74 | 3643 | |
e31b8213 JB |
3644 | if (kt != NL80211_KEYTYPE_GROUP && |
3645 | kt != NL80211_KEYTYPE_PAIRWISE) | |
3646 | return -EINVAL; | |
3647 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
3648 | } | |
3649 | ||
4c476991 JB |
3650 | if (!rdev->ops->get_key) |
3651 | return -EOPNOTSUPP; | |
41ade00f | 3652 | |
0fa7b391 JB |
3653 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
3654 | return -ENOENT; | |
3655 | ||
fd2120ca | 3656 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
3657 | if (!msg) |
3658 | return -ENOMEM; | |
41ade00f | 3659 | |
15e47304 | 3660 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 3661 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 3662 | if (!hdr) |
9fe271af | 3663 | goto nla_put_failure; |
41ade00f JB |
3664 | |
3665 | cookie.msg = msg; | |
b9454e83 | 3666 | cookie.idx = key_idx; |
41ade00f | 3667 | |
9360ffd1 DM |
3668 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3669 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
3670 | goto nla_put_failure; | |
3671 | if (mac_addr && | |
3672 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
3673 | goto nla_put_failure; | |
41ade00f | 3674 | |
e35e4d28 HG |
3675 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
3676 | get_key_callback); | |
41ade00f JB |
3677 | |
3678 | if (err) | |
6c95e2a2 | 3679 | goto free_msg; |
41ade00f JB |
3680 | |
3681 | if (cookie.error) | |
3682 | goto nla_put_failure; | |
3683 | ||
3684 | genlmsg_end(msg, hdr); | |
4c476991 | 3685 | return genlmsg_reply(msg, info); |
41ade00f JB |
3686 | |
3687 | nla_put_failure: | |
3688 | err = -ENOBUFS; | |
6c95e2a2 | 3689 | free_msg: |
41ade00f | 3690 | nlmsg_free(msg); |
41ade00f JB |
3691 | return err; |
3692 | } | |
3693 | ||
3694 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
3695 | { | |
4c476991 | 3696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 3697 | struct key_parse key; |
41ade00f | 3698 | int err; |
4c476991 | 3699 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3700 | |
b9454e83 JB |
3701 | err = nl80211_parse_key(info, &key); |
3702 | if (err) | |
3703 | return err; | |
41ade00f | 3704 | |
b9454e83 | 3705 | if (key.idx < 0) |
41ade00f JB |
3706 | return -EINVAL; |
3707 | ||
6cdd3979 AW |
3708 | /* Only support setting default key and |
3709 | * Extended Key ID action NL80211_KEY_SET_TX. | |
3710 | */ | |
3711 | if (!key.def && !key.defmgmt && | |
3712 | !(key.p.mode == NL80211_KEY_SET_TX)) | |
41ade00f JB |
3713 | return -EINVAL; |
3714 | ||
dbd2fd65 | 3715 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 3716 | |
dbd2fd65 JB |
3717 | if (key.def) { |
3718 | if (!rdev->ops->set_default_key) { | |
3719 | err = -EOPNOTSUPP; | |
3720 | goto out; | |
3721 | } | |
41ade00f | 3722 | |
dbd2fd65 JB |
3723 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
3724 | if (err) | |
3725 | goto out; | |
3726 | ||
e35e4d28 | 3727 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
3728 | key.def_uni, key.def_multi); |
3729 | ||
3730 | if (err) | |
3731 | goto out; | |
fffd0934 | 3732 | |
3d23e349 | 3733 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
3734 | dev->ieee80211_ptr->wext.default_key = key.idx; |
3735 | #endif | |
6cdd3979 | 3736 | } else if (key.defmgmt) { |
dbd2fd65 JB |
3737 | if (key.def_uni || !key.def_multi) { |
3738 | err = -EINVAL; | |
3739 | goto out; | |
3740 | } | |
3741 | ||
3742 | if (!rdev->ops->set_default_mgmt_key) { | |
3743 | err = -EOPNOTSUPP; | |
3744 | goto out; | |
3745 | } | |
3746 | ||
3747 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3748 | if (err) | |
3749 | goto out; | |
3750 | ||
e35e4d28 | 3751 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
3752 | if (err) |
3753 | goto out; | |
3754 | ||
3755 | #ifdef CONFIG_CFG80211_WEXT | |
3756 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 3757 | #endif |
6cdd3979 AW |
3758 | } else if (key.p.mode == NL80211_KEY_SET_TX && |
3759 | wiphy_ext_feature_isset(&rdev->wiphy, | |
3760 | NL80211_EXT_FEATURE_EXT_KEY_ID)) { | |
3761 | u8 *mac_addr = NULL; | |
3762 | ||
3763 | if (info->attrs[NL80211_ATTR_MAC]) | |
3764 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3765 | ||
3766 | if (!mac_addr || key.idx < 0 || key.idx > 1) { | |
3767 | err = -EINVAL; | |
3768 | goto out; | |
3769 | } | |
dbd2fd65 | 3770 | |
6cdd3979 AW |
3771 | err = rdev_add_key(rdev, dev, key.idx, |
3772 | NL80211_KEYTYPE_PAIRWISE, | |
3773 | mac_addr, &key.p); | |
3774 | } else { | |
3775 | err = -EINVAL; | |
3776 | } | |
dbd2fd65 | 3777 | out: |
fffd0934 | 3778 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3779 | |
41ade00f JB |
3780 | return err; |
3781 | } | |
3782 | ||
3783 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
3784 | { | |
4c476991 | 3785 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 3786 | int err; |
4c476991 | 3787 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 3788 | struct key_parse key; |
e31b8213 | 3789 | const u8 *mac_addr = NULL; |
41ade00f | 3790 | |
b9454e83 JB |
3791 | err = nl80211_parse_key(info, &key); |
3792 | if (err) | |
3793 | return err; | |
41ade00f | 3794 | |
b9454e83 | 3795 | if (!key.p.key) |
41ade00f JB |
3796 | return -EINVAL; |
3797 | ||
41ade00f JB |
3798 | if (info->attrs[NL80211_ATTR_MAC]) |
3799 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3800 | ||
e31b8213 JB |
3801 | if (key.type == -1) { |
3802 | if (mac_addr) | |
3803 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3804 | else | |
3805 | key.type = NL80211_KEYTYPE_GROUP; | |
3806 | } | |
3807 | ||
3808 | /* for now */ | |
3809 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3810 | key.type != NL80211_KEYTYPE_GROUP) | |
3811 | return -EINVAL; | |
3812 | ||
4c476991 JB |
3813 | if (!rdev->ops->add_key) |
3814 | return -EOPNOTSUPP; | |
25e47c18 | 3815 | |
e31b8213 JB |
3816 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
3817 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3818 | mac_addr)) | |
4c476991 | 3819 | return -EINVAL; |
41ade00f | 3820 | |
fffd0934 JB |
3821 | wdev_lock(dev->ieee80211_ptr); |
3822 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3823 | if (!err) | |
e35e4d28 HG |
3824 | err = rdev_add_key(rdev, dev, key.idx, |
3825 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3826 | mac_addr, &key.p); | |
fffd0934 | 3827 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3828 | |
41ade00f JB |
3829 | return err; |
3830 | } | |
3831 | ||
3832 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
3833 | { | |
4c476991 | 3834 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3835 | int err; |
4c476991 | 3836 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3837 | u8 *mac_addr = NULL; |
b9454e83 | 3838 | struct key_parse key; |
41ade00f | 3839 | |
b9454e83 JB |
3840 | err = nl80211_parse_key(info, &key); |
3841 | if (err) | |
3842 | return err; | |
41ade00f JB |
3843 | |
3844 | if (info->attrs[NL80211_ATTR_MAC]) | |
3845 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3846 | ||
e31b8213 JB |
3847 | if (key.type == -1) { |
3848 | if (mac_addr) | |
3849 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3850 | else | |
3851 | key.type = NL80211_KEYTYPE_GROUP; | |
3852 | } | |
3853 | ||
3854 | /* for now */ | |
3855 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3856 | key.type != NL80211_KEYTYPE_GROUP) | |
3857 | return -EINVAL; | |
3858 | ||
4c476991 JB |
3859 | if (!rdev->ops->del_key) |
3860 | return -EOPNOTSUPP; | |
41ade00f | 3861 | |
fffd0934 JB |
3862 | wdev_lock(dev->ieee80211_ptr); |
3863 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 | 3864 | |
0fa7b391 | 3865 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
e31b8213 JB |
3866 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
3867 | err = -ENOENT; | |
3868 | ||
fffd0934 | 3869 | if (!err) |
e35e4d28 HG |
3870 | err = rdev_del_key(rdev, dev, key.idx, |
3871 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3872 | mac_addr); | |
41ade00f | 3873 | |
3d23e349 | 3874 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 3875 | if (!err) { |
b9454e83 | 3876 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 3877 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 3878 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
3879 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
3880 | } | |
3881 | #endif | |
fffd0934 | 3882 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 3883 | |
41ade00f JB |
3884 | return err; |
3885 | } | |
3886 | ||
77765eaf VT |
3887 | /* This function returns an error or the number of nested attributes */ |
3888 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3889 | { | |
3890 | struct nlattr *attr; | |
3891 | int n_entries = 0, tmp; | |
3892 | ||
3893 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3894 | if (nla_len(attr) != ETH_ALEN) | |
3895 | return -EINVAL; | |
3896 | ||
3897 | n_entries++; | |
3898 | } | |
3899 | ||
3900 | return n_entries; | |
3901 | } | |
3902 | ||
3903 | /* | |
3904 | * This function parses ACL information and allocates memory for ACL data. | |
3905 | * On successful return, the calling function is responsible to free the | |
3906 | * ACL buffer returned by this function. | |
3907 | */ | |
3908 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3909 | struct genl_info *info) | |
3910 | { | |
3911 | enum nl80211_acl_policy acl_policy; | |
3912 | struct nlattr *attr; | |
3913 | struct cfg80211_acl_data *acl; | |
3914 | int i = 0, n_entries, tmp; | |
3915 | ||
3916 | if (!wiphy->max_acl_mac_addrs) | |
3917 | return ERR_PTR(-EOPNOTSUPP); | |
3918 | ||
3919 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3920 | return ERR_PTR(-EINVAL); | |
3921 | ||
3922 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3923 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3924 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3925 | return ERR_PTR(-EINVAL); | |
3926 | ||
3927 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3928 | return ERR_PTR(-EINVAL); | |
3929 | ||
3930 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3931 | if (n_entries < 0) | |
3932 | return ERR_PTR(n_entries); | |
3933 | ||
3934 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3935 | return ERR_PTR(-ENOTSUPP); | |
3936 | ||
391d132c | 3937 | acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL); |
77765eaf VT |
3938 | if (!acl) |
3939 | return ERR_PTR(-ENOMEM); | |
3940 | ||
3941 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3942 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3943 | i++; | |
3944 | } | |
3945 | ||
3946 | acl->n_acl_entries = n_entries; | |
3947 | acl->acl_policy = acl_policy; | |
3948 | ||
3949 | return acl; | |
3950 | } | |
3951 | ||
3952 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3953 | { | |
3954 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3955 | struct net_device *dev = info->user_ptr[1]; | |
3956 | struct cfg80211_acl_data *acl; | |
3957 | int err; | |
3958 | ||
3959 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3960 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3961 | return -EOPNOTSUPP; | |
3962 | ||
3963 | if (!dev->ieee80211_ptr->beacon_interval) | |
3964 | return -EINVAL; | |
3965 | ||
3966 | acl = parse_acl_data(&rdev->wiphy, info); | |
3967 | if (IS_ERR(acl)) | |
3968 | return PTR_ERR(acl); | |
3969 | ||
3970 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3971 | ||
3972 | kfree(acl); | |
3973 | ||
3974 | return err; | |
3975 | } | |
3976 | ||
a7c7fbff PK |
3977 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
3978 | u8 *rates, u8 rates_len) | |
3979 | { | |
3980 | u8 i; | |
3981 | u32 mask = 0; | |
3982 | ||
3983 | for (i = 0; i < rates_len; i++) { | |
3984 | int rate = (rates[i] & 0x7f) * 5; | |
3985 | int ridx; | |
3986 | ||
3987 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
3988 | struct ieee80211_rate *srate = | |
3989 | &sband->bitrates[ridx]; | |
3990 | if (rate == srate->bitrate) { | |
3991 | mask |= 1 << ridx; | |
3992 | break; | |
3993 | } | |
3994 | } | |
3995 | if (ridx == sband->n_bitrates) | |
3996 | return 0; /* rate not found */ | |
3997 | } | |
3998 | ||
3999 | return mask; | |
4000 | } | |
4001 | ||
4002 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, | |
4003 | u8 *rates, u8 rates_len, | |
4004 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
4005 | { | |
4006 | u8 i; | |
4007 | ||
4008 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
4009 | ||
4010 | for (i = 0; i < rates_len; i++) { | |
4011 | int ridx, rbit; | |
4012 | ||
4013 | ridx = rates[i] / 8; | |
4014 | rbit = BIT(rates[i] % 8); | |
4015 | ||
4016 | /* check validity */ | |
4017 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) | |
4018 | return false; | |
4019 | ||
4020 | /* check availability */ | |
30fe6d50 | 4021 | ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); |
a7c7fbff PK |
4022 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
4023 | mcs[ridx] |= rbit; | |
4024 | else | |
4025 | return false; | |
4026 | } | |
4027 | ||
4028 | return true; | |
4029 | } | |
4030 | ||
4031 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) | |
4032 | { | |
4033 | u16 mcs_mask = 0; | |
4034 | ||
4035 | switch (vht_mcs_map) { | |
4036 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
4037 | break; | |
4038 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
4039 | mcs_mask = 0x00FF; | |
4040 | break; | |
4041 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
4042 | mcs_mask = 0x01FF; | |
4043 | break; | |
4044 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
4045 | mcs_mask = 0x03FF; | |
4046 | break; | |
4047 | default: | |
4048 | break; | |
4049 | } | |
4050 | ||
4051 | return mcs_mask; | |
4052 | } | |
4053 | ||
4054 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
4055 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
4056 | { | |
4057 | u8 nss; | |
4058 | ||
4059 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
4060 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
4061 | vht_mcs_map >>= 2; | |
4062 | } | |
4063 | } | |
4064 | ||
4065 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
4066 | struct nl80211_txrate_vht *txrate, | |
4067 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
4068 | { | |
4069 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
4070 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
4071 | u8 i; | |
4072 | ||
4073 | if (!sband->vht_cap.vht_supported) | |
4074 | return false; | |
4075 | ||
4076 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
4077 | ||
4078 | /* Build vht_mcs_mask from VHT capabilities */ | |
4079 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
4080 | ||
4081 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
4082 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
4083 | mcs[i] = txrate->mcs[i]; | |
4084 | else | |
4085 | return false; | |
4086 | } | |
4087 | ||
4088 | return true; | |
4089 | } | |
4090 | ||
4091 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { | |
4092 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, | |
4093 | .len = NL80211_MAX_SUPP_RATES }, | |
4094 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, | |
4095 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
1a28ed21 | 4096 | [NL80211_TXRATE_VHT] = { .type = NLA_EXACT_LEN_WARN, .len = sizeof(struct nl80211_txrate_vht)}, |
a7c7fbff PK |
4097 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
4098 | }; | |
4099 | ||
4100 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, | |
4101 | struct cfg80211_bitrate_mask *mask) | |
4102 | { | |
4103 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4104 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4105 | int rem, i; | |
4106 | struct nlattr *tx_rates; | |
4107 | struct ieee80211_supported_band *sband; | |
4108 | u16 vht_tx_mcs_map; | |
4109 | ||
4110 | memset(mask, 0, sizeof(*mask)); | |
4111 | /* Default to all rates enabled */ | |
4112 | for (i = 0; i < NUM_NL80211_BANDS; i++) { | |
4113 | sband = rdev->wiphy.bands[i]; | |
4114 | ||
4115 | if (!sband) | |
4116 | continue; | |
4117 | ||
4118 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; | |
4119 | memcpy(mask->control[i].ht_mcs, | |
4120 | sband->ht_cap.mcs.rx_mask, | |
4121 | sizeof(mask->control[i].ht_mcs)); | |
4122 | ||
4123 | if (!sband->vht_cap.vht_supported) | |
4124 | continue; | |
4125 | ||
4126 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
4127 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); | |
4128 | } | |
4129 | ||
4130 | /* if no rates are given set it back to the defaults */ | |
4131 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
4132 | goto out; | |
4133 | ||
4134 | /* The nested attribute uses enum nl80211_band as the index. This maps | |
4135 | * directly to the enum nl80211_band values used in cfg80211. | |
4136 | */ | |
4137 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); | |
4138 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { | |
4139 | enum nl80211_band band = nla_type(tx_rates); | |
4140 | int err; | |
4141 | ||
4142 | if (band < 0 || band >= NUM_NL80211_BANDS) | |
4143 | return -EINVAL; | |
4144 | sband = rdev->wiphy.bands[band]; | |
4145 | if (sband == NULL) | |
4146 | return -EINVAL; | |
8cb08174 JB |
4147 | err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX, |
4148 | tx_rates, | |
4149 | nl80211_txattr_policy, | |
4150 | info->extack); | |
a7c7fbff PK |
4151 | if (err) |
4152 | return err; | |
4153 | if (tb[NL80211_TXRATE_LEGACY]) { | |
4154 | mask->control[band].legacy = rateset_to_mask( | |
4155 | sband, | |
4156 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
4157 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
4158 | if ((mask->control[band].legacy == 0) && | |
4159 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
4160 | return -EINVAL; | |
4161 | } | |
4162 | if (tb[NL80211_TXRATE_HT]) { | |
4163 | if (!ht_rateset_to_mask( | |
4164 | sband, | |
4165 | nla_data(tb[NL80211_TXRATE_HT]), | |
4166 | nla_len(tb[NL80211_TXRATE_HT]), | |
4167 | mask->control[band].ht_mcs)) | |
4168 | return -EINVAL; | |
4169 | } | |
4170 | if (tb[NL80211_TXRATE_VHT]) { | |
4171 | if (!vht_set_mcs_mask( | |
4172 | sband, | |
4173 | nla_data(tb[NL80211_TXRATE_VHT]), | |
4174 | mask->control[band].vht_mcs)) | |
4175 | return -EINVAL; | |
4176 | } | |
4177 | if (tb[NL80211_TXRATE_GI]) { | |
4178 | mask->control[band].gi = | |
4179 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
4180 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
4181 | return -EINVAL; | |
4182 | } | |
4183 | ||
4184 | if (mask->control[band].legacy == 0) { | |
4185 | /* don't allow empty legacy rates if HT or VHT | |
4186 | * are not even supported. | |
4187 | */ | |
4188 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
4189 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
4190 | return -EINVAL; | |
4191 | ||
4192 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
4193 | if (mask->control[band].ht_mcs[i]) | |
4194 | goto out; | |
4195 | ||
4196 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
4197 | if (mask->control[band].vht_mcs[i]) | |
4198 | goto out; | |
4199 | ||
4200 | /* legacy and mcs rates may not be both empty */ | |
4201 | return -EINVAL; | |
4202 | } | |
4203 | } | |
4204 | ||
4205 | out: | |
4206 | return 0; | |
4207 | } | |
4208 | ||
8564e382 JB |
4209 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
4210 | enum nl80211_band band, | |
4211 | struct cfg80211_bitrate_mask *beacon_rate) | |
a7c7fbff | 4212 | { |
8564e382 JB |
4213 | u32 count_ht, count_vht, i; |
4214 | u32 rate = beacon_rate->control[band].legacy; | |
a7c7fbff PK |
4215 | |
4216 | /* Allow only one rate */ | |
4217 | if (hweight32(rate) > 1) | |
4218 | return -EINVAL; | |
4219 | ||
4220 | count_ht = 0; | |
4221 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { | |
8564e382 | 4222 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
a7c7fbff | 4223 | return -EINVAL; |
8564e382 | 4224 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
a7c7fbff PK |
4225 | count_ht++; |
4226 | if (count_ht > 1) | |
4227 | return -EINVAL; | |
4228 | } | |
4229 | if (count_ht && rate) | |
4230 | return -EINVAL; | |
4231 | } | |
4232 | ||
4233 | count_vht = 0; | |
4234 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
8564e382 | 4235 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
a7c7fbff | 4236 | return -EINVAL; |
8564e382 | 4237 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
a7c7fbff PK |
4238 | count_vht++; |
4239 | if (count_vht > 1) | |
4240 | return -EINVAL; | |
4241 | } | |
4242 | if (count_vht && rate) | |
4243 | return -EINVAL; | |
4244 | } | |
4245 | ||
4246 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) | |
4247 | return -EINVAL; | |
4248 | ||
8564e382 JB |
4249 | if (rate && |
4250 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
4251 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) | |
4252 | return -EINVAL; | |
4253 | if (count_ht && | |
4254 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
4255 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) | |
4256 | return -EINVAL; | |
4257 | if (count_vht && | |
4258 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
4259 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) | |
4260 | return -EINVAL; | |
4261 | ||
a7c7fbff PK |
4262 | return 0; |
4263 | } | |
4264 | ||
81e54d08 PKC |
4265 | static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev, |
4266 | struct nlattr *attrs[], | |
8860020e | 4267 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 4268 | { |
8860020e | 4269 | bool haveinfo = false; |
81e54d08 | 4270 | int err; |
ed1b6cc7 | 4271 | |
8860020e | 4272 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 4273 | |
a1193be8 SW |
4274 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
4275 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
4276 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
4277 | if (!bcn->head_len) |
4278 | return -EINVAL; | |
4279 | haveinfo = true; | |
ed1b6cc7 JB |
4280 | } |
4281 | ||
a1193be8 SW |
4282 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
4283 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
4284 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 4285 | haveinfo = true; |
ed1b6cc7 JB |
4286 | } |
4287 | ||
4c476991 JB |
4288 | if (!haveinfo) |
4289 | return -EINVAL; | |
3b85875a | 4290 | |
a1193be8 SW |
4291 | if (attrs[NL80211_ATTR_IE]) { |
4292 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
4293 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
4294 | } |
4295 | ||
a1193be8 | 4296 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 4297 | bcn->proberesp_ies = |
a1193be8 | 4298 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 4299 | bcn->proberesp_ies_len = |
a1193be8 | 4300 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
4301 | } |
4302 | ||
a1193be8 | 4303 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 4304 | bcn->assocresp_ies = |
a1193be8 | 4305 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 4306 | bcn->assocresp_ies_len = |
a1193be8 | 4307 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
4308 | } |
4309 | ||
a1193be8 SW |
4310 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
4311 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
4312 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
4313 | } |
4314 | ||
81e54d08 PKC |
4315 | if (attrs[NL80211_ATTR_FTM_RESPONDER]) { |
4316 | struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1]; | |
4317 | ||
8cb08174 JB |
4318 | err = nla_parse_nested_deprecated(tb, |
4319 | NL80211_FTM_RESP_ATTR_MAX, | |
4320 | attrs[NL80211_ATTR_FTM_RESPONDER], | |
4321 | NULL, NULL); | |
81e54d08 PKC |
4322 | if (err) |
4323 | return err; | |
4324 | ||
4325 | if (tb[NL80211_FTM_RESP_ATTR_ENABLED] && | |
4326 | wiphy_ext_feature_isset(&rdev->wiphy, | |
4327 | NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER)) | |
4328 | bcn->ftm_responder = 1; | |
4329 | else | |
4330 | return -EOPNOTSUPP; | |
4331 | ||
4332 | if (tb[NL80211_FTM_RESP_ATTR_LCI]) { | |
4333 | bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]); | |
4334 | bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]); | |
4335 | } | |
4336 | ||
4337 | if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) { | |
4338 | bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); | |
4339 | bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); | |
4340 | } | |
4341 | } else { | |
4342 | bcn->ftm_responder = -1; | |
4343 | } | |
4344 | ||
8860020e JB |
4345 | return 0; |
4346 | } | |
4347 | ||
66cd794e JB |
4348 | static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, |
4349 | const u8 *rates) | |
4350 | { | |
4351 | int i; | |
4352 | ||
4353 | if (!rates) | |
4354 | return; | |
4355 | ||
4356 | for (i = 0; i < rates[1]; i++) { | |
4357 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) | |
4358 | params->ht_required = true; | |
4359 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) | |
4360 | params->vht_required = true; | |
4361 | } | |
4362 | } | |
4363 | ||
4364 | /* | |
4365 | * Since the nl80211 API didn't include, from the beginning, attributes about | |
4366 | * HT/VHT requirements/capabilities, we parse them out of the IEs for the | |
4367 | * benefit of drivers that rebuild IEs in the firmware. | |
4368 | */ | |
4369 | static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) | |
4370 | { | |
4371 | const struct cfg80211_beacon_data *bcn = ¶ms->beacon; | |
ba83bfb1 IM |
4372 | size_t ies_len = bcn->tail_len; |
4373 | const u8 *ies = bcn->tail; | |
66cd794e JB |
4374 | const u8 *rates; |
4375 | const u8 *cap; | |
4376 | ||
4377 | rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); | |
4378 | nl80211_check_ap_rate_selectors(params, rates); | |
4379 | ||
4380 | rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); | |
4381 | nl80211_check_ap_rate_selectors(params, rates); | |
4382 | ||
4383 | cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); | |
4384 | if (cap && cap[1] >= sizeof(*params->ht_cap)) | |
4385 | params->ht_cap = (void *)(cap + 2); | |
4386 | cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); | |
4387 | if (cap && cap[1] >= sizeof(*params->vht_cap)) | |
4388 | params->vht_cap = (void *)(cap + 2); | |
244eb9ae ST |
4389 | cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len); |
4390 | if (cap && cap[1] >= sizeof(*params->he_cap) + 1) | |
4391 | params->he_cap = (void *)(cap + 3); | |
66cd794e JB |
4392 | } |
4393 | ||
46c1dd0c FF |
4394 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
4395 | struct cfg80211_ap_settings *params) | |
4396 | { | |
4397 | struct wireless_dev *wdev; | |
4398 | bool ret = false; | |
4399 | ||
53873f13 | 4400 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
46c1dd0c FF |
4401 | if (wdev->iftype != NL80211_IFTYPE_AP && |
4402 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
4403 | continue; | |
4404 | ||
683b6d3b | 4405 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
4406 | continue; |
4407 | ||
683b6d3b | 4408 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
4409 | ret = true; |
4410 | break; | |
4411 | } | |
4412 | ||
46c1dd0c FF |
4413 | return ret; |
4414 | } | |
4415 | ||
e39e5b5e JM |
4416 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
4417 | enum nl80211_auth_type auth_type, | |
4418 | enum nl80211_commands cmd) | |
4419 | { | |
4420 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
4421 | return false; | |
4422 | ||
4423 | switch (cmd) { | |
4424 | case NL80211_CMD_AUTHENTICATE: | |
4425 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
4426 | auth_type == NL80211_AUTHTYPE_SAE) | |
4427 | return false; | |
63181060 JM |
4428 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
4429 | NL80211_EXT_FEATURE_FILS_STA) && | |
4430 | (auth_type == NL80211_AUTHTYPE_FILS_SK || | |
4431 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || | |
4432 | auth_type == NL80211_AUTHTYPE_FILS_PK)) | |
4433 | return false; | |
e39e5b5e JM |
4434 | return true; |
4435 | case NL80211_CMD_CONNECT: | |
10773a7c SD |
4436 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
4437 | auth_type == NL80211_AUTHTYPE_SAE) | |
a3caf744 | 4438 | return false; |
10773a7c | 4439 | |
a3caf744 VK |
4440 | /* FILS with SK PFS or PK not supported yet */ |
4441 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || | |
4442 | auth_type == NL80211_AUTHTYPE_FILS_PK) | |
4443 | return false; | |
4444 | if (!wiphy_ext_feature_isset( | |
4445 | &rdev->wiphy, | |
4446 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && | |
4447 | auth_type == NL80211_AUTHTYPE_FILS_SK) | |
4448 | return false; | |
4449 | return true; | |
e39e5b5e JM |
4450 | case NL80211_CMD_START_AP: |
4451 | /* SAE not supported yet */ | |
4452 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
4453 | return false; | |
63181060 JM |
4454 | /* FILS not supported yet */ |
4455 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || | |
4456 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || | |
4457 | auth_type == NL80211_AUTHTYPE_FILS_PK) | |
4458 | return false; | |
e39e5b5e JM |
4459 | return true; |
4460 | default: | |
4461 | return false; | |
4462 | } | |
4463 | } | |
4464 | ||
8860020e JB |
4465 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
4466 | { | |
4467 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4468 | struct net_device *dev = info->user_ptr[1]; | |
4469 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
4470 | struct cfg80211_ap_settings params; | |
4471 | int err; | |
4472 | ||
4473 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4474 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4475 | return -EOPNOTSUPP; | |
4476 | ||
4477 | if (!rdev->ops->start_ap) | |
4478 | return -EOPNOTSUPP; | |
4479 | ||
4480 | if (wdev->beacon_interval) | |
4481 | return -EALREADY; | |
4482 | ||
4483 | memset(¶ms, 0, sizeof(params)); | |
4484 | ||
4485 | /* these are required for START_AP */ | |
4486 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
4487 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
4488 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
4489 | return -EINVAL; | |
4490 | ||
81e54d08 | 4491 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon); |
8860020e JB |
4492 | if (err) |
4493 | return err; | |
4494 | ||
4495 | params.beacon_interval = | |
4496 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
4497 | params.dtim_period = | |
4498 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
4499 | ||
0c317a02 PK |
4500 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
4501 | params.beacon_interval); | |
8860020e JB |
4502 | if (err) |
4503 | return err; | |
4504 | ||
4505 | /* | |
4506 | * In theory, some of these attributes should be required here | |
4507 | * but since they were not used when the command was originally | |
4508 | * added, keep them optional for old user space programs to let | |
4509 | * them continue to work with drivers that do not need the | |
4510 | * additional information -- drivers must check! | |
4511 | */ | |
4512 | if (info->attrs[NL80211_ATTR_SSID]) { | |
4513 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
4514 | params.ssid_len = | |
4515 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
4516 | if (params.ssid_len == 0 || | |
4517 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
4518 | return -EINVAL; | |
4519 | } | |
4520 | ||
ab0d76f6 | 4521 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) |
8860020e JB |
4522 | params.hidden_ssid = nla_get_u32( |
4523 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
8860020e JB |
4524 | |
4525 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
4526 | ||
4527 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
4528 | params.auth_type = nla_get_u32( | |
4529 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
4530 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
4531 | NL80211_CMD_START_AP)) | |
8860020e JB |
4532 | return -EINVAL; |
4533 | } else | |
4534 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
4535 | ||
4536 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
4537 | NL80211_MAX_NR_CIPHER_SUITES); | |
4538 | if (err) | |
4539 | return err; | |
4540 | ||
1b658f11 VT |
4541 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
4542 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
4543 | return -EOPNOTSUPP; | |
4544 | params.inactivity_timeout = nla_get_u16( | |
4545 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
4546 | } | |
4547 | ||
53cabad7 JB |
4548 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4549 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4550 | return -EINVAL; | |
4551 | params.p2p_ctwindow = | |
4552 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
53cabad7 JB |
4553 | if (params.p2p_ctwindow != 0 && |
4554 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4555 | return -EINVAL; | |
4556 | } | |
4557 | ||
4558 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4559 | u8 tmp; | |
4560 | ||
4561 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4562 | return -EINVAL; | |
4563 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
53cabad7 JB |
4564 | params.p2p_opp_ps = tmp; |
4565 | if (params.p2p_opp_ps != 0 && | |
4566 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4567 | return -EINVAL; | |
4568 | } | |
4569 | ||
aa430da4 | 4570 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
4571 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
4572 | if (err) | |
4573 | return err; | |
4574 | } else if (wdev->preset_chandef.chan) { | |
4575 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 4576 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
4577 | return -EINVAL; |
4578 | ||
923b352f AN |
4579 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
4580 | wdev->iftype)) | |
aa430da4 JB |
4581 | return -EINVAL; |
4582 | ||
a7c7fbff PK |
4583 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
4584 | err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); | |
4585 | if (err) | |
4586 | return err; | |
4587 | ||
8564e382 JB |
4588 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
4589 | ¶ms.beacon_rate); | |
a7c7fbff PK |
4590 | if (err) |
4591 | return err; | |
4592 | } | |
4593 | ||
18998c38 EP |
4594 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
4595 | params.smps_mode = | |
4596 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | |
4597 | switch (params.smps_mode) { | |
4598 | case NL80211_SMPS_OFF: | |
4599 | break; | |
4600 | case NL80211_SMPS_STATIC: | |
4601 | if (!(rdev->wiphy.features & | |
4602 | NL80211_FEATURE_STATIC_SMPS)) | |
4603 | return -EINVAL; | |
4604 | break; | |
4605 | case NL80211_SMPS_DYNAMIC: | |
4606 | if (!(rdev->wiphy.features & | |
4607 | NL80211_FEATURE_DYNAMIC_SMPS)) | |
4608 | return -EINVAL; | |
4609 | break; | |
4610 | default: | |
4611 | return -EINVAL; | |
4612 | } | |
4613 | } else { | |
4614 | params.smps_mode = NL80211_SMPS_OFF; | |
4615 | } | |
4616 | ||
6e8ef842 PK |
4617 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
4618 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) | |
4619 | return -EOPNOTSUPP; | |
4620 | ||
4baf6bea OO |
4621 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
4622 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
4623 | if (IS_ERR(params.acl)) | |
4624 | return PTR_ERR(params.acl); | |
4625 | } | |
4626 | ||
66cd794e JB |
4627 | nl80211_calculate_ap_params(¶ms); |
4628 | ||
fe494370 SD |
4629 | if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT]) |
4630 | params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; | |
4631 | ||
c56589ed | 4632 | wdev_lock(wdev); |
e35e4d28 | 4633 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 4634 | if (!err) { |
683b6d3b | 4635 | wdev->preset_chandef = params.chandef; |
8860020e | 4636 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 4637 | wdev->chandef = params.chandef; |
06e191e2 AQ |
4638 | wdev->ssid_len = params.ssid_len; |
4639 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
466a3061 DK |
4640 | |
4641 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) | |
4642 | wdev->conn_owner_nlportid = info->snd_portid; | |
46c1dd0c | 4643 | } |
c56589ed | 4644 | wdev_unlock(wdev); |
77765eaf VT |
4645 | |
4646 | kfree(params.acl); | |
4647 | ||
56d1893d | 4648 | return err; |
ed1b6cc7 JB |
4649 | } |
4650 | ||
8860020e JB |
4651 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
4652 | { | |
4653 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4654 | struct net_device *dev = info->user_ptr[1]; | |
4655 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
4656 | struct cfg80211_beacon_data params; | |
4657 | int err; | |
4658 | ||
4659 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4660 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4661 | return -EOPNOTSUPP; | |
4662 | ||
4663 | if (!rdev->ops->change_beacon) | |
4664 | return -EOPNOTSUPP; | |
4665 | ||
4666 | if (!wdev->beacon_interval) | |
4667 | return -EINVAL; | |
4668 | ||
81e54d08 | 4669 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms); |
8860020e JB |
4670 | if (err) |
4671 | return err; | |
4672 | ||
c56589ed SW |
4673 | wdev_lock(wdev); |
4674 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
4675 | wdev_unlock(wdev); | |
4676 | ||
4677 | return err; | |
8860020e JB |
4678 | } |
4679 | ||
4680 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 4681 | { |
4c476991 JB |
4682 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4683 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 4684 | |
7c8d5e03 | 4685 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
4686 | } |
4687 | ||
5727ef1b JB |
4688 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
4689 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
4690 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
4691 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 4692 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 4693 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 4694 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
4695 | }; |
4696 | ||
eccb8e8f | 4697 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 4698 | enum nl80211_iftype iftype, |
eccb8e8f | 4699 | struct station_parameters *params) |
5727ef1b JB |
4700 | { |
4701 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 4702 | struct nlattr *nla; |
5727ef1b JB |
4703 | int flag; |
4704 | ||
eccb8e8f JB |
4705 | /* |
4706 | * Try parsing the new attribute first so userspace | |
4707 | * can specify both for older kernels. | |
4708 | */ | |
4709 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
4710 | if (nla) { | |
4711 | struct nl80211_sta_flag_update *sta_flags; | |
4712 | ||
4713 | sta_flags = nla_data(nla); | |
4714 | params->sta_flags_mask = sta_flags->mask; | |
4715 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 4716 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
4717 | if ((params->sta_flags_mask | |
4718 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
4719 | return -EINVAL; | |
4720 | return 0; | |
4721 | } | |
4722 | ||
4723 | /* if present, parse the old attribute */ | |
5727ef1b | 4724 | |
eccb8e8f | 4725 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
4726 | if (!nla) |
4727 | return 0; | |
4728 | ||
8cb08174 | 4729 | if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack)) |
5727ef1b JB |
4730 | return -EINVAL; |
4731 | ||
bdd3ae3d JB |
4732 | /* |
4733 | * Only allow certain flags for interface types so that | |
4734 | * other attributes are silently ignored. Remember that | |
4735 | * this is backward compatibility code with old userspace | |
4736 | * and shouldn't be hit in other cases anyway. | |
4737 | */ | |
4738 | switch (iftype) { | |
4739 | case NL80211_IFTYPE_AP: | |
4740 | case NL80211_IFTYPE_AP_VLAN: | |
4741 | case NL80211_IFTYPE_P2P_GO: | |
4742 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4743 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4744 | BIT(NL80211_STA_FLAG_WME) | | |
4745 | BIT(NL80211_STA_FLAG_MFP); | |
4746 | break; | |
4747 | case NL80211_IFTYPE_P2P_CLIENT: | |
4748 | case NL80211_IFTYPE_STATION: | |
4749 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4750 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
4751 | break; | |
4752 | case NL80211_IFTYPE_MESH_POINT: | |
4753 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4754 | BIT(NL80211_STA_FLAG_MFP) | | |
4755 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
5cf3006c | 4756 | break; |
bdd3ae3d JB |
4757 | default: |
4758 | return -EINVAL; | |
4759 | } | |
5727ef1b | 4760 | |
3383b5a6 JB |
4761 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
4762 | if (flags[flag]) { | |
eccb8e8f | 4763 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 4764 | |
3383b5a6 JB |
4765 | /* no longer support new API additions in old API */ |
4766 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
4767 | return -EINVAL; | |
4768 | } | |
4769 | } | |
4770 | ||
5727ef1b JB |
4771 | return 0; |
4772 | } | |
4773 | ||
9bb7e0f2 | 4774 | bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr) |
c8dcfd8a FF |
4775 | { |
4776 | struct nlattr *rate; | |
8eb41c8d VK |
4777 | u32 bitrate; |
4778 | u16 bitrate_compat; | |
bbf67e45 | 4779 | enum nl80211_rate_info rate_flg; |
c8dcfd8a | 4780 | |
ae0be8de | 4781 | rate = nla_nest_start_noflag(msg, attr); |
c8dcfd8a | 4782 | if (!rate) |
db9c64cf | 4783 | return false; |
c8dcfd8a FF |
4784 | |
4785 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
4786 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
4787 | /* report 16-bit bitrate only if we can */ |
4788 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
4789 | if (bitrate > 0 && |
4790 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
4791 | return false; | |
4792 | if (bitrate_compat > 0 && | |
4793 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
4794 | return false; | |
4795 | ||
b51f3bee JB |
4796 | switch (info->bw) { |
4797 | case RATE_INFO_BW_5: | |
4798 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; | |
4799 | break; | |
4800 | case RATE_INFO_BW_10: | |
4801 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; | |
4802 | break; | |
4803 | default: | |
4804 | WARN_ON(1); | |
4805 | /* fall through */ | |
4806 | case RATE_INFO_BW_20: | |
4807 | rate_flg = 0; | |
4808 | break; | |
4809 | case RATE_INFO_BW_40: | |
4810 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; | |
4811 | break; | |
4812 | case RATE_INFO_BW_80: | |
4813 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; | |
4814 | break; | |
4815 | case RATE_INFO_BW_160: | |
4816 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; | |
4817 | break; | |
c4cbaf79 LC |
4818 | case RATE_INFO_BW_HE_RU: |
4819 | rate_flg = 0; | |
4820 | WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); | |
b51f3bee JB |
4821 | } |
4822 | ||
4823 | if (rate_flg && nla_put_flag(msg, rate_flg)) | |
4824 | return false; | |
4825 | ||
db9c64cf JB |
4826 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
4827 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
4828 | return false; | |
db9c64cf JB |
4829 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
4830 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
4831 | return false; | |
4832 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
4833 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
4834 | return false; | |
4835 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
4836 | return false; | |
db9c64cf JB |
4837 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
4838 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
4839 | return false; | |
c4cbaf79 LC |
4840 | } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { |
4841 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) | |
4842 | return false; | |
4843 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) | |
4844 | return false; | |
4845 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) | |
4846 | return false; | |
4847 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) | |
4848 | return false; | |
4849 | if (info->bw == RATE_INFO_BW_HE_RU && | |
4850 | nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, | |
4851 | info->he_ru_alloc)) | |
4852 | return false; | |
db9c64cf | 4853 | } |
c8dcfd8a FF |
4854 | |
4855 | nla_nest_end(msg, rate); | |
4856 | return true; | |
c8dcfd8a FF |
4857 | } |
4858 | ||
119363c7 FF |
4859 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
4860 | int id) | |
4861 | { | |
4862 | void *attr; | |
4863 | int i = 0; | |
4864 | ||
4865 | if (!mask) | |
4866 | return true; | |
4867 | ||
ae0be8de | 4868 | attr = nla_nest_start_noflag(msg, id); |
119363c7 FF |
4869 | if (!attr) |
4870 | return false; | |
4871 | ||
4872 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
4873 | if (!(mask & BIT(i))) | |
4874 | continue; | |
4875 | ||
4876 | if (nla_put_u8(msg, i, signal[i])) | |
4877 | return false; | |
4878 | } | |
4879 | ||
4880 | nla_nest_end(msg, attr); | |
4881 | ||
4882 | return true; | |
4883 | } | |
4884 | ||
cf5ead82 JB |
4885 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
4886 | u32 seq, int flags, | |
66266b3a JL |
4887 | struct cfg80211_registered_device *rdev, |
4888 | struct net_device *dev, | |
98b62183 | 4889 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
4890 | { |
4891 | void *hdr; | |
f4263c98 | 4892 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 4893 | |
cf5ead82 | 4894 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
fd5b74dc JB |
4895 | if (!hdr) |
4896 | return -1; | |
4897 | ||
9360ffd1 DM |
4898 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4899 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
4900 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
4901 | goto nla_put_failure; | |
f5ea9120 | 4902 | |
ae0be8de | 4903 | sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO); |
2ec600d6 | 4904 | if (!sinfoattr) |
fd5b74dc | 4905 | goto nla_put_failure; |
319090bf JB |
4906 | |
4907 | #define PUT_SINFO(attr, memb, type) do { \ | |
d686b920 | 4908 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
397c657a | 4909 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
319090bf JB |
4910 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
4911 | sinfo->memb)) \ | |
4912 | goto nla_put_failure; \ | |
4913 | } while (0) | |
d686b920 | 4914 | #define PUT_SINFO_U64(attr, memb) do { \ |
397c657a | 4915 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
d686b920 JB |
4916 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
4917 | sinfo->memb, NL80211_STA_INFO_PAD)) \ | |
4918 | goto nla_put_failure; \ | |
4919 | } while (0) | |
319090bf JB |
4920 | |
4921 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); | |
4922 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); | |
4923 | ||
397c657a OE |
4924 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | |
4925 | BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && | |
9360ffd1 | 4926 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 4927 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 4928 | goto nla_put_failure; |
319090bf | 4929 | |
397c657a OE |
4930 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | |
4931 | BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 4932 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
4933 | (u32)sinfo->tx_bytes)) |
4934 | goto nla_put_failure; | |
319090bf | 4935 | |
d686b920 JB |
4936 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
4937 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); | |
319090bf JB |
4938 | PUT_SINFO(LLID, llid, u16); |
4939 | PUT_SINFO(PLID, plid, u16); | |
4940 | PUT_SINFO(PLINK_STATE, plink_state, u8); | |
d686b920 | 4941 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
36647055 THJ |
4942 | PUT_SINFO_U64(TX_DURATION, tx_duration); |
4943 | ||
4944 | if (wiphy_ext_feature_isset(&rdev->wiphy, | |
4945 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) | |
4946 | PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16); | |
319090bf | 4947 | |
66266b3a JL |
4948 | switch (rdev->wiphy.signal_type) { |
4949 | case CFG80211_SIGNAL_TYPE_MBM: | |
319090bf JB |
4950 | PUT_SINFO(SIGNAL, signal, u8); |
4951 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); | |
66266b3a JL |
4952 | break; |
4953 | default: | |
4954 | break; | |
4955 | } | |
397c657a | 4956 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
119363c7 FF |
4957 | if (!nl80211_put_signal(msg, sinfo->chains, |
4958 | sinfo->chain_signal, | |
4959 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
4960 | goto nla_put_failure; | |
4961 | } | |
397c657a | 4962 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
119363c7 FF |
4963 | if (!nl80211_put_signal(msg, sinfo->chains, |
4964 | sinfo->chain_signal_avg, | |
4965 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
4966 | goto nla_put_failure; | |
4967 | } | |
397c657a | 4968 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { |
c8dcfd8a FF |
4969 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
4970 | NL80211_STA_INFO_TX_BITRATE)) | |
4971 | goto nla_put_failure; | |
4972 | } | |
397c657a | 4973 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { |
c8dcfd8a FF |
4974 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
4975 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 4976 | goto nla_put_failure; |
420e7fab | 4977 | } |
319090bf JB |
4978 | |
4979 | PUT_SINFO(RX_PACKETS, rx_packets, u32); | |
4980 | PUT_SINFO(TX_PACKETS, tx_packets, u32); | |
4981 | PUT_SINFO(TX_RETRIES, tx_retries, u32); | |
4982 | PUT_SINFO(TX_FAILED, tx_failed, u32); | |
4983 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); | |
ab60633c | 4984 | PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32); |
319090bf JB |
4985 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
4986 | PUT_SINFO(LOCAL_PM, local_pm, u32); | |
4987 | PUT_SINFO(PEER_PM, peer_pm, u32); | |
4988 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); | |
dbdaee7a | 4989 | PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8); |
319090bf | 4990 | |
397c657a | 4991 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { |
ae0be8de MK |
4992 | bss_param = nla_nest_start_noflag(msg, |
4993 | NL80211_STA_INFO_BSS_PARAM); | |
f4263c98 PS |
4994 | if (!bss_param) |
4995 | goto nla_put_failure; | |
4996 | ||
9360ffd1 DM |
4997 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
4998 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
4999 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
5000 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
5001 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
5002 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
5003 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
5004 | sinfo->bss_param.dtim_period) || | |
5005 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
5006 | sinfo->bss_param.beacon_interval)) | |
5007 | goto nla_put_failure; | |
f4263c98 PS |
5008 | |
5009 | nla_nest_end(msg, bss_param); | |
5010 | } | |
397c657a | 5011 | if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && |
9360ffd1 DM |
5012 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
5013 | sizeof(struct nl80211_sta_flag_update), | |
5014 | &sinfo->sta_flags)) | |
5015 | goto nla_put_failure; | |
319090bf | 5016 | |
d686b920 JB |
5017 | PUT_SINFO_U64(T_OFFSET, t_offset); |
5018 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); | |
5019 | PUT_SINFO_U64(BEACON_RX, rx_beacon); | |
a76b1942 | 5020 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
0d4e14a3 AB |
5021 | PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32); |
5022 | PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32); | |
81d5439d | 5023 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
9c06602b BP |
5024 | NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) { |
5025 | PUT_SINFO(ACK_SIGNAL, ack_signal, u8); | |
5026 | PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8); | |
5027 | } | |
319090bf JB |
5028 | |
5029 | #undef PUT_SINFO | |
d686b920 | 5030 | #undef PUT_SINFO_U64 |
6de39808 | 5031 | |
8689c051 | 5032 | if (sinfo->pertid) { |
6de39808 JB |
5033 | struct nlattr *tidsattr; |
5034 | int tid; | |
5035 | ||
ae0be8de MK |
5036 | tidsattr = nla_nest_start_noflag(msg, |
5037 | NL80211_STA_INFO_TID_STATS); | |
6de39808 JB |
5038 | if (!tidsattr) |
5039 | goto nla_put_failure; | |
5040 | ||
5041 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { | |
5042 | struct cfg80211_tid_stats *tidstats; | |
5043 | struct nlattr *tidattr; | |
5044 | ||
5045 | tidstats = &sinfo->pertid[tid]; | |
5046 | ||
5047 | if (!tidstats->filled) | |
5048 | continue; | |
5049 | ||
ae0be8de | 5050 | tidattr = nla_nest_start_noflag(msg, tid + 1); |
6de39808 JB |
5051 | if (!tidattr) |
5052 | goto nla_put_failure; | |
5053 | ||
d686b920 | 5054 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
6de39808 | 5055 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
d686b920 JB |
5056 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
5057 | tidstats->memb, NL80211_TID_STATS_PAD)) \ | |
6de39808 JB |
5058 | goto nla_put_failure; \ |
5059 | } while (0) | |
5060 | ||
d686b920 JB |
5061 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
5062 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); | |
5063 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); | |
5064 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); | |
6de39808 | 5065 | |
d686b920 | 5066 | #undef PUT_TIDVAL_U64 |
52539ca8 THJ |
5067 | if ((tidstats->filled & |
5068 | BIT(NL80211_TID_STATS_TXQ_STATS)) && | |
5069 | !nl80211_put_txq_stats(msg, &tidstats->txq_stats, | |
5070 | NL80211_TID_STATS_TXQ_STATS)) | |
5071 | goto nla_put_failure; | |
5072 | ||
6de39808 JB |
5073 | nla_nest_end(msg, tidattr); |
5074 | } | |
5075 | ||
5076 | nla_nest_end(msg, tidsattr); | |
5077 | } | |
5078 | ||
2ec600d6 | 5079 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 5080 | |
319090bf | 5081 | if (sinfo->assoc_req_ies_len && |
9360ffd1 DM |
5082 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
5083 | sinfo->assoc_req_ies)) | |
5084 | goto nla_put_failure; | |
50d3dfb7 | 5085 | |
7ea3e110 | 5086 | cfg80211_sinfo_release_content(sinfo); |
053c095a JB |
5087 | genlmsg_end(msg, hdr); |
5088 | return 0; | |
fd5b74dc JB |
5089 | |
5090 | nla_put_failure: | |
7ea3e110 | 5091 | cfg80211_sinfo_release_content(sinfo); |
bc3ed28c TG |
5092 | genlmsg_cancel(msg, hdr); |
5093 | return -EMSGSIZE; | |
fd5b74dc JB |
5094 | } |
5095 | ||
2ec600d6 | 5096 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 5097 | struct netlink_callback *cb) |
2ec600d6 | 5098 | { |
73887fd9 | 5099 | struct station_info sinfo; |
1b8ec87a | 5100 | struct cfg80211_registered_device *rdev; |
97990a06 | 5101 | struct wireless_dev *wdev; |
2ec600d6 | 5102 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 5103 | int sta_idx = cb->args[2]; |
2ec600d6 | 5104 | int err; |
2ec600d6 | 5105 | |
ea90e0dc | 5106 | rtnl_lock(); |
5297c65c | 5107 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
67748893 | 5108 | if (err) |
ea90e0dc | 5109 | goto out_err; |
bba95fef | 5110 | |
97990a06 JB |
5111 | if (!wdev->netdev) { |
5112 | err = -EINVAL; | |
5113 | goto out_err; | |
5114 | } | |
5115 | ||
1b8ec87a | 5116 | if (!rdev->ops->dump_station) { |
eec60b03 | 5117 | err = -EOPNOTSUPP; |
bba95fef JB |
5118 | goto out_err; |
5119 | } | |
5120 | ||
bba95fef | 5121 | while (1) { |
73887fd9 | 5122 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 5123 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
73887fd9 | 5124 | mac_addr, &sinfo); |
bba95fef JB |
5125 | if (err == -ENOENT) |
5126 | break; | |
5127 | if (err) | |
3b85875a | 5128 | goto out_err; |
bba95fef | 5129 | |
cf5ead82 | 5130 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
15e47304 | 5131 | NETLINK_CB(cb->skb).portid, |
bba95fef | 5132 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 5133 | rdev, wdev->netdev, mac_addr, |
73887fd9 | 5134 | &sinfo) < 0) |
bba95fef JB |
5135 | goto out; |
5136 | ||
5137 | sta_idx++; | |
5138 | } | |
5139 | ||
bba95fef | 5140 | out: |
97990a06 | 5141 | cb->args[2] = sta_idx; |
bba95fef | 5142 | err = skb->len; |
bba95fef | 5143 | out_err: |
ea90e0dc | 5144 | rtnl_unlock(); |
bba95fef JB |
5145 | |
5146 | return err; | |
2ec600d6 | 5147 | } |
fd5b74dc | 5148 | |
5727ef1b JB |
5149 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
5150 | { | |
4c476991 JB |
5151 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5152 | struct net_device *dev = info->user_ptr[1]; | |
73887fd9 | 5153 | struct station_info sinfo; |
fd5b74dc JB |
5154 | struct sk_buff *msg; |
5155 | u8 *mac_addr = NULL; | |
4c476991 | 5156 | int err; |
fd5b74dc | 5157 | |
73887fd9 | 5158 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc | 5159 | |
73887fd9 JB |
5160 | if (!info->attrs[NL80211_ATTR_MAC]) |
5161 | return -EINVAL; | |
fd5b74dc JB |
5162 | |
5163 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5164 | ||
73887fd9 JB |
5165 | if (!rdev->ops->get_station) |
5166 | return -EOPNOTSUPP; | |
3b85875a | 5167 | |
73887fd9 | 5168 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 5169 | if (err) |
73887fd9 | 5170 | return err; |
2ec600d6 | 5171 | |
fd2120ca | 5172 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
7ea3e110 | 5173 | if (!msg) { |
ba8f566a | 5174 | cfg80211_sinfo_release_content(&sinfo); |
73887fd9 | 5175 | return -ENOMEM; |
7ea3e110 | 5176 | } |
fd5b74dc | 5177 | |
cf5ead82 JB |
5178 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
5179 | info->snd_portid, info->snd_seq, 0, | |
73887fd9 | 5180 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 | 5181 | nlmsg_free(msg); |
73887fd9 | 5182 | return -ENOBUFS; |
4c476991 | 5183 | } |
3b85875a | 5184 | |
73887fd9 | 5185 | return genlmsg_reply(msg, info); |
5727ef1b JB |
5186 | } |
5187 | ||
77ee7c89 JB |
5188 | int cfg80211_check_station_change(struct wiphy *wiphy, |
5189 | struct station_parameters *params, | |
5190 | enum cfg80211_station_type statype) | |
5191 | { | |
e4208427 AB |
5192 | if (params->listen_interval != -1 && |
5193 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
77ee7c89 | 5194 | return -EINVAL; |
e4208427 | 5195 | |
17b94247 AB |
5196 | if (params->support_p2p_ps != -1 && |
5197 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
5198 | return -EINVAL; | |
5199 | ||
c72e1140 | 5200 | if (params->aid && |
e4208427 AB |
5201 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
5202 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
77ee7c89 JB |
5203 | return -EINVAL; |
5204 | ||
5205 | /* When you run into this, adjust the code below for the new flag */ | |
5206 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
5207 | ||
5208 | switch (statype) { | |
eef941e6 TP |
5209 | case CFG80211_STA_MESH_PEER_KERNEL: |
5210 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
5211 | /* |
5212 | * No ignoring the TDLS flag here -- the userspace mesh | |
5213 | * code doesn't have the bug of including TDLS in the | |
5214 | * mask everywhere. | |
5215 | */ | |
5216 | if (params->sta_flags_mask & | |
5217 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
5218 | BIT(NL80211_STA_FLAG_MFP) | | |
5219 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
5220 | return -EINVAL; | |
5221 | break; | |
5222 | case CFG80211_STA_TDLS_PEER_SETUP: | |
5223 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
5224 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
5225 | return -EINVAL; | |
5226 | /* ignore since it can't change */ | |
5227 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
5228 | break; | |
5229 | default: | |
5230 | /* disallow mesh-specific things */ | |
5231 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
5232 | return -EINVAL; | |
5233 | if (params->local_pm) | |
5234 | return -EINVAL; | |
5235 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
5236 | return -EINVAL; | |
5237 | } | |
5238 | ||
5239 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
5240 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
5241 | /* TDLS can't be set, ... */ | |
5242 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
5243 | return -EINVAL; | |
5244 | /* | |
5245 | * ... but don't bother the driver with it. This works around | |
5246 | * a hostapd/wpa_supplicant issue -- it always includes the | |
5247 | * TLDS_PEER flag in the mask even for AP mode. | |
5248 | */ | |
5249 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
5250 | } | |
5251 | ||
47edb11b AB |
5252 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
5253 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { | |
77ee7c89 JB |
5254 | /* reject other things that can't change */ |
5255 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
5256 | return -EINVAL; | |
5257 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
5258 | return -EINVAL; | |
5259 | if (params->supported_rates) | |
5260 | return -EINVAL; | |
c4cbaf79 LC |
5261 | if (params->ext_capab || params->ht_capa || params->vht_capa || |
5262 | params->he_capa) | |
77ee7c89 JB |
5263 | return -EINVAL; |
5264 | } | |
5265 | ||
47edb11b AB |
5266 | if (statype != CFG80211_STA_AP_CLIENT && |
5267 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { | |
77ee7c89 JB |
5268 | if (params->vlan) |
5269 | return -EINVAL; | |
5270 | } | |
5271 | ||
5272 | switch (statype) { | |
5273 | case CFG80211_STA_AP_MLME_CLIENT: | |
5274 | /* Use this only for authorizing/unauthorizing a station */ | |
5275 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
5276 | return -EOPNOTSUPP; | |
5277 | break; | |
5278 | case CFG80211_STA_AP_CLIENT: | |
47edb11b | 5279 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
77ee7c89 JB |
5280 | /* accept only the listed bits */ |
5281 | if (params->sta_flags_mask & | |
5282 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
5283 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
5284 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
5285 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
5286 | BIT(NL80211_STA_FLAG_WME) | | |
5287 | BIT(NL80211_STA_FLAG_MFP))) | |
5288 | return -EINVAL; | |
5289 | ||
5290 | /* but authenticated/associated only if driver handles it */ | |
5291 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
5292 | params->sta_flags_mask & | |
5293 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
5294 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
5295 | return -EINVAL; | |
5296 | break; | |
5297 | case CFG80211_STA_IBSS: | |
5298 | case CFG80211_STA_AP_STA: | |
5299 | /* reject any changes other than AUTHORIZED */ | |
5300 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
5301 | return -EINVAL; | |
5302 | break; | |
5303 | case CFG80211_STA_TDLS_PEER_SETUP: | |
5304 | /* reject any changes other than AUTHORIZED or WME */ | |
5305 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
5306 | BIT(NL80211_STA_FLAG_WME))) | |
5307 | return -EINVAL; | |
5308 | /* force (at least) rates when authorizing */ | |
5309 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
5310 | !params->supported_rates) | |
5311 | return -EINVAL; | |
5312 | break; | |
5313 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
5314 | /* reject any changes */ | |
5315 | return -EINVAL; | |
eef941e6 | 5316 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
5317 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
5318 | return -EINVAL; | |
5319 | break; | |
eef941e6 | 5320 | case CFG80211_STA_MESH_PEER_USER: |
42925040 CYY |
5321 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
5322 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) | |
77ee7c89 JB |
5323 | return -EINVAL; |
5324 | break; | |
5325 | } | |
5326 | ||
06f7c88c BL |
5327 | /* |
5328 | * Older kernel versions ignored this attribute entirely, so don't | |
5329 | * reject attempts to update it but mark it as unused instead so the | |
5330 | * driver won't look at the data. | |
5331 | */ | |
5332 | if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && | |
5333 | statype != CFG80211_STA_TDLS_PEER_SETUP) | |
5334 | params->opmode_notif_used = false; | |
5335 | ||
77ee7c89 JB |
5336 | return 0; |
5337 | } | |
5338 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
5339 | ||
5727ef1b | 5340 | /* |
c258d2de | 5341 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 5342 | */ |
80b99899 JB |
5343 | static struct net_device *get_vlan(struct genl_info *info, |
5344 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 5345 | { |
463d0183 | 5346 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
5347 | struct net_device *v; |
5348 | int ret; | |
5349 | ||
5350 | if (!vlanattr) | |
5351 | return NULL; | |
5352 | ||
5353 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
5354 | if (!v) | |
5355 | return ERR_PTR(-ENODEV); | |
5356 | ||
5357 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
5358 | ret = -EINVAL; | |
5359 | goto error; | |
5727ef1b | 5360 | } |
80b99899 | 5361 | |
77ee7c89 JB |
5362 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
5363 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
5364 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
5365 | ret = -EINVAL; | |
5366 | goto error; | |
5367 | } | |
5368 | ||
80b99899 JB |
5369 | if (!netif_running(v)) { |
5370 | ret = -ENETDOWN; | |
5371 | goto error; | |
5372 | } | |
5373 | ||
5374 | return v; | |
5375 | error: | |
5376 | dev_put(v); | |
5377 | return ERR_PTR(ret); | |
5727ef1b JB |
5378 | } |
5379 | ||
94e860f1 JB |
5380 | static const struct nla_policy |
5381 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
5382 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
5383 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
5384 | }; | |
5385 | ||
ff276691 JB |
5386 | static int nl80211_parse_sta_wme(struct genl_info *info, |
5387 | struct station_parameters *params) | |
df881293 | 5388 | { |
df881293 JM |
5389 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
5390 | struct nlattr *nla; | |
5391 | int err; | |
5392 | ||
df881293 JM |
5393 | /* parse WME attributes if present */ |
5394 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
5395 | return 0; | |
5396 | ||
5397 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
8cb08174 JB |
5398 | err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla, |
5399 | nl80211_sta_wme_policy, | |
5400 | info->extack); | |
df881293 JM |
5401 | if (err) |
5402 | return err; | |
5403 | ||
5404 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
5405 | params->uapsd_queues = nla_get_u8( | |
5406 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
5407 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
5408 | return -EINVAL; | |
5409 | ||
5410 | if (tb[NL80211_STA_WME_MAX_SP]) | |
5411 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
5412 | ||
5413 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
5414 | return -EINVAL; | |
5415 | ||
5416 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
5417 | ||
5418 | return 0; | |
5419 | } | |
5420 | ||
c01fc9ad SD |
5421 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
5422 | struct station_parameters *params) | |
5423 | { | |
5424 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
5425 | params->supported_channels = | |
5426 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
5427 | params->supported_channels_len = | |
5428 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
5429 | /* | |
5430 | * Need to include at least one (first channel, number of | |
5431 | * channels) tuple for each subband, and must have proper | |
5432 | * tuples for the rest of the data as well. | |
5433 | */ | |
5434 | if (params->supported_channels_len < 2) | |
5435 | return -EINVAL; | |
5436 | if (params->supported_channels_len % 2) | |
5437 | return -EINVAL; | |
5438 | } | |
5439 | ||
5440 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
5441 | params->supported_oper_classes = | |
5442 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
5443 | params->supported_oper_classes_len = | |
5444 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
5445 | /* | |
5446 | * The value of the Length field of the Supported Operating | |
5447 | * Classes element is between 2 and 253. | |
5448 | */ | |
5449 | if (params->supported_oper_classes_len < 2 || | |
5450 | params->supported_oper_classes_len > 253) | |
5451 | return -EINVAL; | |
5452 | } | |
5453 | return 0; | |
5454 | } | |
5455 | ||
ff276691 JB |
5456 | static int nl80211_set_station_tdls(struct genl_info *info, |
5457 | struct station_parameters *params) | |
5458 | { | |
c01fc9ad | 5459 | int err; |
ff276691 | 5460 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
5461 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5462 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
5463 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
5464 | params->ht_capa = | |
5465 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5466 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
5467 | params->vht_capa = | |
5468 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
c4cbaf79 LC |
5469 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
5470 | params->he_capa = | |
5471 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); | |
5472 | params->he_capa_len = | |
5473 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); | |
5474 | ||
5475 | if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN) | |
5476 | return -EINVAL; | |
5477 | } | |
ff276691 | 5478 | |
c01fc9ad SD |
5479 | err = nl80211_parse_sta_channel_info(info, params); |
5480 | if (err) | |
5481 | return err; | |
5482 | ||
ff276691 JB |
5483 | return nl80211_parse_sta_wme(info, params); |
5484 | } | |
5485 | ||
e96d1cd2 ARN |
5486 | static int nl80211_parse_sta_txpower_setting(struct genl_info *info, |
5487 | struct station_parameters *params) | |
5488 | { | |
5489 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5490 | int idx; | |
5491 | ||
5492 | if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) { | |
5493 | if (!rdev->ops->set_tx_power || | |
5494 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
5495 | NL80211_EXT_FEATURE_STA_TX_PWR)) | |
5496 | return -EOPNOTSUPP; | |
5497 | ||
5498 | idx = NL80211_ATTR_STA_TX_POWER_SETTING; | |
5499 | params->txpwr.type = nla_get_u8(info->attrs[idx]); | |
5500 | ||
5501 | if (params->txpwr.type == NL80211_TX_POWER_LIMITED) { | |
5502 | idx = NL80211_ATTR_STA_TX_POWER; | |
5503 | ||
5504 | if (info->attrs[idx]) | |
5505 | params->txpwr.power = | |
5506 | nla_get_s16(info->attrs[idx]); | |
5507 | else | |
5508 | return -EINVAL; | |
5509 | } | |
5510 | params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER; | |
5511 | } | |
5512 | ||
5513 | return 0; | |
5514 | } | |
5515 | ||
5727ef1b JB |
5516 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
5517 | { | |
4c476991 | 5518 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 5519 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 5520 | struct station_parameters params; |
77ee7c89 JB |
5521 | u8 *mac_addr; |
5522 | int err; | |
5727ef1b JB |
5523 | |
5524 | memset(¶ms, 0, sizeof(params)); | |
5525 | ||
77ee7c89 JB |
5526 | if (!rdev->ops->change_station) |
5527 | return -EOPNOTSUPP; | |
5528 | ||
e4208427 AB |
5529 | /* |
5530 | * AID and listen_interval properties can be set only for unassociated | |
5531 | * station. Include these parameters here and will check them in | |
5532 | * cfg80211_check_station_change(). | |
5533 | */ | |
a9bc31e4 AB |
5534 | if (info->attrs[NL80211_ATTR_STA_AID]) |
5535 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
e4208427 AB |
5536 | |
5537 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | |
5538 | params.listen_interval = | |
5539 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
5540 | else | |
5541 | params.listen_interval = -1; | |
5727ef1b | 5542 | |
ab0d76f6 JB |
5543 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) |
5544 | params.support_p2p_ps = | |
5545 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); | |
5546 | else | |
17b94247 | 5547 | params.support_p2p_ps = -1; |
17b94247 | 5548 | |
5727ef1b JB |
5549 | if (!info->attrs[NL80211_ATTR_MAC]) |
5550 | return -EINVAL; | |
5551 | ||
5552 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5553 | ||
5554 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
5555 | params.supported_rates = | |
5556 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
5557 | params.supported_rates_len = | |
5558 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
5559 | } | |
5560 | ||
9d62a986 JM |
5561 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
5562 | params.capability = | |
5563 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
5564 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
5565 | } | |
5566 | ||
5567 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
5568 | params.ext_capab = | |
5569 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
5570 | params.ext_capab_len = | |
5571 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
5572 | } | |
5573 | ||
bdd3ae3d | 5574 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
5575 | return -EINVAL; |
5576 | ||
ab0d76f6 | 5577 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
2ec600d6 | 5578 | params.plink_action = |
f8bacc21 | 5579 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
2ec600d6 | 5580 | |
f8bacc21 | 5581 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 5582 | params.plink_state = |
f8bacc21 | 5583 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
ab0d76f6 | 5584 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) |
7d27a0ba MH |
5585 | params.peer_aid = nla_get_u16( |
5586 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); | |
f8bacc21 JB |
5587 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
5588 | } | |
9c3990aa | 5589 | |
ab0d76f6 JB |
5590 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) |
5591 | params.local_pm = nla_get_u32( | |
3b1c5a53 MP |
5592 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
5593 | ||
06f7c88c BL |
5594 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
5595 | params.opmode_notif_used = true; | |
5596 | params.opmode_notif = | |
5597 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
5598 | } | |
5599 | ||
36647055 THJ |
5600 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
5601 | params.airtime_weight = | |
5602 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); | |
5603 | ||
5604 | if (params.airtime_weight && | |
5605 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
5606 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) | |
5607 | return -EOPNOTSUPP; | |
5608 | ||
e96d1cd2 ARN |
5609 | err = nl80211_parse_sta_txpower_setting(info, ¶ms); |
5610 | if (err) | |
5611 | return err; | |
5612 | ||
77ee7c89 JB |
5613 | /* Include parameters for TDLS peer (will check later) */ |
5614 | err = nl80211_set_station_tdls(info, ¶ms); | |
5615 | if (err) | |
5616 | return err; | |
5617 | ||
5618 | params.vlan = get_vlan(info, rdev); | |
5619 | if (IS_ERR(params.vlan)) | |
5620 | return PTR_ERR(params.vlan); | |
5621 | ||
a97f4424 JB |
5622 | switch (dev->ieee80211_ptr->iftype) { |
5623 | case NL80211_IFTYPE_AP: | |
5624 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 5625 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 5626 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 5627 | case NL80211_IFTYPE_STATION: |
267335d6 | 5628 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 5629 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
5630 | break; |
5631 | default: | |
77ee7c89 JB |
5632 | err = -EOPNOTSUPP; |
5633 | goto out_put_vlan; | |
034d655e JB |
5634 | } |
5635 | ||
77ee7c89 | 5636 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 5637 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 5638 | |
77ee7c89 | 5639 | out_put_vlan: |
5727ef1b JB |
5640 | if (params.vlan) |
5641 | dev_put(params.vlan); | |
3b85875a | 5642 | |
5727ef1b JB |
5643 | return err; |
5644 | } | |
5645 | ||
5646 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
5647 | { | |
4c476991 | 5648 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 5649 | int err; |
4c476991 | 5650 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
5651 | struct station_parameters params; |
5652 | u8 *mac_addr = NULL; | |
bda95eb1 JB |
5653 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
5654 | BIT(NL80211_STA_FLAG_ASSOCIATED); | |
5727ef1b JB |
5655 | |
5656 | memset(¶ms, 0, sizeof(params)); | |
5657 | ||
984c311b JB |
5658 | if (!rdev->ops->add_station) |
5659 | return -EOPNOTSUPP; | |
5660 | ||
5727ef1b JB |
5661 | if (!info->attrs[NL80211_ATTR_MAC]) |
5662 | return -EINVAL; | |
5663 | ||
5727ef1b JB |
5664 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
5665 | return -EINVAL; | |
5666 | ||
5667 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
5668 | return -EINVAL; | |
5669 | ||
5e4b6f56 JM |
5670 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
5671 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
5672 | return -EINVAL; |
5673 | ||
5727ef1b JB |
5674 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5675 | params.supported_rates = | |
5676 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
5677 | params.supported_rates_len = | |
5678 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
5679 | params.listen_interval = | |
5680 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 5681 | |
17b94247 | 5682 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
ab0d76f6 JB |
5683 | params.support_p2p_ps = |
5684 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); | |
17b94247 AB |
5685 | } else { |
5686 | /* | |
5687 | * if not specified, assume it's supported for P2P GO interface, | |
5688 | * and is NOT supported for AP interface | |
5689 | */ | |
5690 | params.support_p2p_ps = | |
5691 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; | |
5692 | } | |
5693 | ||
3d124ea2 | 5694 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 5695 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
5696 | else |
5697 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
51b50fbe | 5698 | |
9d62a986 JM |
5699 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
5700 | params.capability = | |
5701 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
5702 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
5703 | } | |
5704 | ||
5705 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
5706 | params.ext_capab = | |
5707 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
5708 | params.ext_capab_len = | |
5709 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
5710 | } | |
5711 | ||
36aedc90 JM |
5712 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
5713 | params.ht_capa = | |
5714 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 5715 | |
f461be3e MP |
5716 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
5717 | params.vht_capa = | |
5718 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
5719 | ||
c4cbaf79 LC |
5720 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
5721 | params.he_capa = | |
5722 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); | |
5723 | params.he_capa_len = | |
5724 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); | |
5725 | ||
5726 | /* max len is validated in nla policy */ | |
5727 | if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN) | |
5728 | return -EINVAL; | |
5729 | } | |
5730 | ||
60f4a7b1 MK |
5731 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
5732 | params.opmode_notif_used = true; | |
5733 | params.opmode_notif = | |
5734 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
5735 | } | |
5736 | ||
ab0d76f6 | 5737 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
96b78dff | 5738 | params.plink_action = |
f8bacc21 | 5739 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
96b78dff | 5740 | |
36647055 THJ |
5741 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
5742 | params.airtime_weight = | |
5743 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); | |
5744 | ||
5745 | if (params.airtime_weight && | |
5746 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
5747 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) | |
5748 | return -EOPNOTSUPP; | |
5749 | ||
e96d1cd2 ARN |
5750 | err = nl80211_parse_sta_txpower_setting(info, ¶ms); |
5751 | if (err) | |
5752 | return err; | |
5753 | ||
c01fc9ad SD |
5754 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
5755 | if (err) | |
5756 | return err; | |
5757 | ||
ff276691 JB |
5758 | err = nl80211_parse_sta_wme(info, ¶ms); |
5759 | if (err) | |
5760 | return err; | |
bdd90d5e | 5761 | |
bdd3ae3d | 5762 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
5763 | return -EINVAL; |
5764 | ||
496fcc29 JB |
5765 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
5766 | * as userspace might just pass through the capabilities from the IEs | |
5767 | * directly, rather than enforcing this restriction and returning an | |
5768 | * error in this case. | |
5769 | */ | |
5770 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { | |
5771 | params.ht_capa = NULL; | |
5772 | params.vht_capa = NULL; | |
c4cbaf79 LC |
5773 | |
5774 | /* HE requires WME */ | |
5775 | if (params.he_capa_len) | |
5776 | return -EINVAL; | |
496fcc29 JB |
5777 | } |
5778 | ||
77ee7c89 JB |
5779 | /* When you run into this, adjust the code below for the new flag */ |
5780 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
5781 | ||
bdd90d5e JB |
5782 | switch (dev->ieee80211_ptr->iftype) { |
5783 | case NL80211_IFTYPE_AP: | |
5784 | case NL80211_IFTYPE_AP_VLAN: | |
5785 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
5786 | /* ignore WME attributes if iface/sta is not capable */ |
5787 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
5788 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
5789 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 5790 | |
bdd90d5e | 5791 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
5792 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
5793 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 5794 | return -EINVAL; |
bdd90d5e JB |
5795 | /* but don't bother the driver with it */ |
5796 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 5797 | |
d582cffb JB |
5798 | /* allow authenticated/associated only if driver handles it */ |
5799 | if (!(rdev->wiphy.features & | |
5800 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
bda95eb1 | 5801 | params.sta_flags_mask & auth_assoc) |
d582cffb JB |
5802 | return -EINVAL; |
5803 | ||
bda95eb1 JB |
5804 | /* Older userspace, or userspace wanting to be compatible with |
5805 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth | |
5806 | * and assoc flags in the mask, but assumes the station will be | |
5807 | * added as associated anyway since this was the required driver | |
5808 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was | |
5809 | * introduced. | |
5810 | * In order to not bother drivers with this quirk in the API | |
5811 | * set the flags in both the mask and set for new stations in | |
5812 | * this case. | |
5813 | */ | |
5814 | if (!(params.sta_flags_mask & auth_assoc)) { | |
5815 | params.sta_flags_mask |= auth_assoc; | |
5816 | params.sta_flags_set |= auth_assoc; | |
5817 | } | |
5818 | ||
bdd90d5e JB |
5819 | /* must be last in here for error handling */ |
5820 | params.vlan = get_vlan(info, rdev); | |
5821 | if (IS_ERR(params.vlan)) | |
5822 | return PTR_ERR(params.vlan); | |
5823 | break; | |
5824 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
5825 | /* ignore uAPSD data */ |
5826 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
5827 | ||
d582cffb JB |
5828 | /* associated is disallowed */ |
5829 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
5830 | return -EINVAL; | |
bdd90d5e | 5831 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
5832 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
5833 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
5834 | return -EINVAL; |
5835 | break; | |
5836 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 5837 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
5838 | /* ignore uAPSD data */ |
5839 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
5840 | ||
77ee7c89 JB |
5841 | /* these are disallowed */ |
5842 | if (params.sta_flags_mask & | |
5843 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
5844 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 5845 | return -EINVAL; |
bdd90d5e JB |
5846 | /* Only TDLS peers can be added */ |
5847 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
5848 | return -EINVAL; | |
5849 | /* Can only add if TDLS ... */ | |
5850 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
5851 | return -EOPNOTSUPP; | |
5852 | /* ... with external setup is supported */ | |
5853 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
5854 | return -EOPNOTSUPP; | |
77ee7c89 JB |
5855 | /* |
5856 | * Older wpa_supplicant versions always mark the TDLS peer | |
5857 | * as authorized, but it shouldn't yet be. | |
5858 | */ | |
5859 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
5860 | break; |
5861 | default: | |
5862 | return -EOPNOTSUPP; | |
c75786c9 EP |
5863 | } |
5864 | ||
bdd90d5e | 5865 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 5866 | |
e35e4d28 | 5867 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 5868 | |
5727ef1b JB |
5869 | if (params.vlan) |
5870 | dev_put(params.vlan); | |
5727ef1b JB |
5871 | return err; |
5872 | } | |
5873 | ||
5874 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
5875 | { | |
4c476991 JB |
5876 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5877 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 JM |
5878 | struct station_del_parameters params; |
5879 | ||
5880 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
5881 | |
5882 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 5883 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 5884 | |
e80cf853 | 5885 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 5886 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 5887 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
5888 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
5889 | return -EINVAL; | |
5727ef1b | 5890 | |
4c476991 JB |
5891 | if (!rdev->ops->del_station) |
5892 | return -EOPNOTSUPP; | |
3b85875a | 5893 | |
98856866 JM |
5894 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
5895 | params.subtype = | |
5896 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
5897 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
5898 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
5899 | return -EINVAL; | |
5900 | } else { | |
5901 | /* Default to Deauthentication frame */ | |
5902 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
5903 | } | |
5904 | ||
5905 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
5906 | params.reason_code = | |
5907 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
5908 | if (params.reason_code == 0) | |
5909 | return -EINVAL; /* 0 is reserved */ | |
5910 | } else { | |
5911 | /* Default to reason code 2 */ | |
5912 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
5913 | } | |
5914 | ||
89c771e5 | 5915 | return rdev_del_station(rdev, dev, ¶ms); |
5727ef1b JB |
5916 | } |
5917 | ||
15e47304 | 5918 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
5919 | int flags, struct net_device *dev, |
5920 | u8 *dst, u8 *next_hop, | |
5921 | struct mpath_info *pinfo) | |
5922 | { | |
5923 | void *hdr; | |
5924 | struct nlattr *pinfoattr; | |
5925 | ||
1ef4c850 | 5926 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
2ec600d6 LCC |
5927 | if (!hdr) |
5928 | return -1; | |
5929 | ||
9360ffd1 DM |
5930 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5931 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
5932 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
5933 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
5934 | goto nla_put_failure; | |
f5ea9120 | 5935 | |
ae0be8de | 5936 | pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO); |
2ec600d6 LCC |
5937 | if (!pinfoattr) |
5938 | goto nla_put_failure; | |
9360ffd1 DM |
5939 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
5940 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
5941 | pinfo->frame_qlen)) | |
5942 | goto nla_put_failure; | |
5943 | if (((pinfo->filled & MPATH_INFO_SN) && | |
5944 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
5945 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
5946 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
5947 | pinfo->metric)) || | |
5948 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
5949 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
5950 | pinfo->exptime)) || | |
5951 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
5952 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
5953 | pinfo->flags)) || | |
5954 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
5955 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
5956 | pinfo->discovery_timeout)) || | |
5957 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
5958 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
cc241636 JH |
5959 | pinfo->discovery_retries)) || |
5960 | ((pinfo->filled & MPATH_INFO_HOP_COUNT) && | |
5961 | nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT, | |
540bbcb9 JH |
5962 | pinfo->hop_count)) || |
5963 | ((pinfo->filled & MPATH_INFO_PATH_CHANGE) && | |
5964 | nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE, | |
5965 | pinfo->path_change_count))) | |
9360ffd1 | 5966 | goto nla_put_failure; |
2ec600d6 LCC |
5967 | |
5968 | nla_nest_end(msg, pinfoattr); | |
5969 | ||
053c095a JB |
5970 | genlmsg_end(msg, hdr); |
5971 | return 0; | |
2ec600d6 LCC |
5972 | |
5973 | nla_put_failure: | |
bc3ed28c TG |
5974 | genlmsg_cancel(msg, hdr); |
5975 | return -EMSGSIZE; | |
2ec600d6 LCC |
5976 | } |
5977 | ||
5978 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 5979 | struct netlink_callback *cb) |
2ec600d6 | 5980 | { |
2ec600d6 | 5981 | struct mpath_info pinfo; |
1b8ec87a | 5982 | struct cfg80211_registered_device *rdev; |
97990a06 | 5983 | struct wireless_dev *wdev; |
2ec600d6 LCC |
5984 | u8 dst[ETH_ALEN]; |
5985 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 5986 | int path_idx = cb->args[2]; |
2ec600d6 | 5987 | int err; |
2ec600d6 | 5988 | |
ea90e0dc | 5989 | rtnl_lock(); |
5297c65c | 5990 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
67748893 | 5991 | if (err) |
ea90e0dc | 5992 | goto out_err; |
bba95fef | 5993 | |
1b8ec87a | 5994 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 5995 | err = -EOPNOTSUPP; |
bba95fef JB |
5996 | goto out_err; |
5997 | } | |
5998 | ||
97990a06 | 5999 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 6000 | err = -EOPNOTSUPP; |
0448b5fc | 6001 | goto out_err; |
eec60b03 JM |
6002 | } |
6003 | ||
bba95fef | 6004 | while (1) { |
1b8ec87a | 6005 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 6006 | next_hop, &pinfo); |
bba95fef | 6007 | if (err == -ENOENT) |
2ec600d6 | 6008 | break; |
bba95fef | 6009 | if (err) |
3b85875a | 6010 | goto out_err; |
2ec600d6 | 6011 | |
15e47304 | 6012 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 6013 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 6014 | wdev->netdev, dst, next_hop, |
bba95fef JB |
6015 | &pinfo) < 0) |
6016 | goto out; | |
2ec600d6 | 6017 | |
bba95fef | 6018 | path_idx++; |
2ec600d6 | 6019 | } |
2ec600d6 | 6020 | |
bba95fef | 6021 | out: |
97990a06 | 6022 | cb->args[2] = path_idx; |
bba95fef | 6023 | err = skb->len; |
bba95fef | 6024 | out_err: |
ea90e0dc | 6025 | rtnl_unlock(); |
bba95fef | 6026 | return err; |
2ec600d6 LCC |
6027 | } |
6028 | ||
6029 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
6030 | { | |
4c476991 | 6031 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 6032 | int err; |
4c476991 | 6033 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
6034 | struct mpath_info pinfo; |
6035 | struct sk_buff *msg; | |
6036 | u8 *dst = NULL; | |
6037 | u8 next_hop[ETH_ALEN]; | |
6038 | ||
6039 | memset(&pinfo, 0, sizeof(pinfo)); | |
6040 | ||
6041 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6042 | return -EINVAL; | |
6043 | ||
6044 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6045 | ||
4c476991 JB |
6046 | if (!rdev->ops->get_mpath) |
6047 | return -EOPNOTSUPP; | |
2ec600d6 | 6048 | |
4c476991 JB |
6049 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
6050 | return -EOPNOTSUPP; | |
eec60b03 | 6051 | |
e35e4d28 | 6052 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 6053 | if (err) |
4c476991 | 6054 | return err; |
2ec600d6 | 6055 | |
fd2120ca | 6056 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 6057 | if (!msg) |
4c476991 | 6058 | return -ENOMEM; |
2ec600d6 | 6059 | |
15e47304 | 6060 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
6061 | dev, dst, next_hop, &pinfo) < 0) { |
6062 | nlmsg_free(msg); | |
6063 | return -ENOBUFS; | |
6064 | } | |
3b85875a | 6065 | |
4c476991 | 6066 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
6067 | } |
6068 | ||
6069 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
6070 | { | |
4c476991 JB |
6071 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6072 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
6073 | u8 *dst = NULL; |
6074 | u8 *next_hop = NULL; | |
6075 | ||
6076 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6077 | return -EINVAL; | |
6078 | ||
6079 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
6080 | return -EINVAL; | |
6081 | ||
6082 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6083 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
6084 | ||
4c476991 JB |
6085 | if (!rdev->ops->change_mpath) |
6086 | return -EOPNOTSUPP; | |
35a8efe1 | 6087 | |
4c476991 JB |
6088 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
6089 | return -EOPNOTSUPP; | |
2ec600d6 | 6090 | |
e35e4d28 | 6091 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 6092 | } |
4c476991 | 6093 | |
2ec600d6 LCC |
6094 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
6095 | { | |
4c476991 JB |
6096 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6097 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
6098 | u8 *dst = NULL; |
6099 | u8 *next_hop = NULL; | |
6100 | ||
6101 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6102 | return -EINVAL; | |
6103 | ||
6104 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
6105 | return -EINVAL; | |
6106 | ||
6107 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6108 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
6109 | ||
4c476991 JB |
6110 | if (!rdev->ops->add_mpath) |
6111 | return -EOPNOTSUPP; | |
35a8efe1 | 6112 | |
4c476991 JB |
6113 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
6114 | return -EOPNOTSUPP; | |
2ec600d6 | 6115 | |
e35e4d28 | 6116 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
6117 | } |
6118 | ||
6119 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
6120 | { | |
4c476991 JB |
6121 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6122 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
6123 | u8 *dst = NULL; |
6124 | ||
6125 | if (info->attrs[NL80211_ATTR_MAC]) | |
6126 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6127 | ||
4c476991 JB |
6128 | if (!rdev->ops->del_mpath) |
6129 | return -EOPNOTSUPP; | |
3b85875a | 6130 | |
e35e4d28 | 6131 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
6132 | } |
6133 | ||
66be7d2b HR |
6134 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
6135 | { | |
6136 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6137 | int err; | |
6138 | struct net_device *dev = info->user_ptr[1]; | |
6139 | struct mpath_info pinfo; | |
6140 | struct sk_buff *msg; | |
6141 | u8 *dst = NULL; | |
6142 | u8 mpp[ETH_ALEN]; | |
6143 | ||
6144 | memset(&pinfo, 0, sizeof(pinfo)); | |
6145 | ||
6146 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6147 | return -EINVAL; | |
6148 | ||
6149 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6150 | ||
6151 | if (!rdev->ops->get_mpp) | |
6152 | return -EOPNOTSUPP; | |
6153 | ||
6154 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
6155 | return -EOPNOTSUPP; | |
6156 | ||
6157 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
6158 | if (err) | |
6159 | return err; | |
6160 | ||
6161 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
6162 | if (!msg) | |
6163 | return -ENOMEM; | |
6164 | ||
6165 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
6166 | dev, dst, mpp, &pinfo) < 0) { | |
6167 | nlmsg_free(msg); | |
6168 | return -ENOBUFS; | |
6169 | } | |
6170 | ||
6171 | return genlmsg_reply(msg, info); | |
6172 | } | |
6173 | ||
6174 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
6175 | struct netlink_callback *cb) | |
6176 | { | |
6177 | struct mpath_info pinfo; | |
6178 | struct cfg80211_registered_device *rdev; | |
6179 | struct wireless_dev *wdev; | |
6180 | u8 dst[ETH_ALEN]; | |
6181 | u8 mpp[ETH_ALEN]; | |
6182 | int path_idx = cb->args[2]; | |
6183 | int err; | |
6184 | ||
ea90e0dc | 6185 | rtnl_lock(); |
5297c65c | 6186 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
66be7d2b | 6187 | if (err) |
ea90e0dc | 6188 | goto out_err; |
66be7d2b HR |
6189 | |
6190 | if (!rdev->ops->dump_mpp) { | |
6191 | err = -EOPNOTSUPP; | |
6192 | goto out_err; | |
6193 | } | |
6194 | ||
6195 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
6196 | err = -EOPNOTSUPP; | |
6197 | goto out_err; | |
6198 | } | |
6199 | ||
6200 | while (1) { | |
6201 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
6202 | mpp, &pinfo); | |
6203 | if (err == -ENOENT) | |
6204 | break; | |
6205 | if (err) | |
6206 | goto out_err; | |
6207 | ||
6208 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
6209 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
6210 | wdev->netdev, dst, mpp, | |
6211 | &pinfo) < 0) | |
6212 | goto out; | |
6213 | ||
6214 | path_idx++; | |
6215 | } | |
6216 | ||
6217 | out: | |
6218 | cb->args[2] = path_idx; | |
6219 | err = skb->len; | |
6220 | out_err: | |
ea90e0dc | 6221 | rtnl_unlock(); |
66be7d2b HR |
6222 | return err; |
6223 | } | |
6224 | ||
9f1ba906 JM |
6225 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
6226 | { | |
4c476991 JB |
6227 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6228 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 6229 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 6230 | struct bss_parameters params; |
c56589ed | 6231 | int err; |
9f1ba906 JM |
6232 | |
6233 | memset(¶ms, 0, sizeof(params)); | |
6234 | /* default to not changing parameters */ | |
6235 | params.use_cts_prot = -1; | |
6236 | params.use_short_preamble = -1; | |
6237 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 6238 | params.ap_isolate = -1; |
50b12f59 | 6239 | params.ht_opmode = -1; |
53cabad7 JB |
6240 | params.p2p_ctwindow = -1; |
6241 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
6242 | |
6243 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
6244 | params.use_cts_prot = | |
6245 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
6246 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
6247 | params.use_short_preamble = | |
6248 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
6249 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
6250 | params.use_short_slot_time = | |
6251 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
6252 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6253 | params.basic_rates = | |
6254 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6255 | params.basic_rates_len = | |
6256 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6257 | } | |
fd8aaaf3 FF |
6258 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
6259 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
6260 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
6261 | params.ht_opmode = | |
6262 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 6263 | |
53cabad7 JB |
6264 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
6265 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
6266 | return -EINVAL; | |
6267 | params.p2p_ctwindow = | |
ab0d76f6 | 6268 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
53cabad7 JB |
6269 | if (params.p2p_ctwindow != 0 && |
6270 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
6271 | return -EINVAL; | |
6272 | } | |
6273 | ||
6274 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
6275 | u8 tmp; | |
6276 | ||
6277 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
6278 | return -EINVAL; | |
6279 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
53cabad7 JB |
6280 | params.p2p_opp_ps = tmp; |
6281 | if (params.p2p_opp_ps && | |
6282 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
6283 | return -EINVAL; | |
6284 | } | |
6285 | ||
4c476991 JB |
6286 | if (!rdev->ops->change_bss) |
6287 | return -EOPNOTSUPP; | |
9f1ba906 | 6288 | |
074ac8df | 6289 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
6290 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
6291 | return -EOPNOTSUPP; | |
3b85875a | 6292 | |
c56589ed SW |
6293 | wdev_lock(wdev); |
6294 | err = rdev_change_bss(rdev, dev, ¶ms); | |
6295 | wdev_unlock(wdev); | |
6296 | ||
6297 | return err; | |
9f1ba906 JM |
6298 | } |
6299 | ||
b2e1b302 LR |
6300 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
6301 | { | |
b2e1b302 | 6302 | char *data = NULL; |
05050753 | 6303 | bool is_indoor; |
57b5ce07 | 6304 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
05050753 I |
6305 | u32 owner_nlportid; |
6306 | ||
80778f18 LR |
6307 | /* |
6308 | * You should only get this when cfg80211 hasn't yet initialized | |
6309 | * completely when built-in to the kernel right between the time | |
6310 | * window between nl80211_init() and regulatory_init(), if that is | |
6311 | * even possible. | |
6312 | */ | |
458f4f9e | 6313 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 6314 | return -EINPROGRESS; |
80778f18 | 6315 | |
57b5ce07 LR |
6316 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
6317 | user_reg_hint_type = | |
6318 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
6319 | else | |
6320 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
6321 | ||
6322 | switch (user_reg_hint_type) { | |
6323 | case NL80211_USER_REG_HINT_USER: | |
6324 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
6325 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
6326 | return -EINVAL; | |
6327 | ||
6328 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
6329 | return regulatory_hint_user(data, user_reg_hint_type); | |
6330 | case NL80211_USER_REG_HINT_INDOOR: | |
05050753 I |
6331 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
6332 | owner_nlportid = info->snd_portid; | |
6333 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; | |
6334 | } else { | |
6335 | owner_nlportid = 0; | |
6336 | is_indoor = true; | |
6337 | } | |
6338 | ||
6339 | return regulatory_hint_indoor(is_indoor, owner_nlportid); | |
57b5ce07 LR |
6340 | default: |
6341 | return -EINVAL; | |
6342 | } | |
b2e1b302 LR |
6343 | } |
6344 | ||
1ea4ff3e JB |
6345 | static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) |
6346 | { | |
6347 | return reg_reload_regdb(); | |
6348 | } | |
6349 | ||
24bdd9f4 | 6350 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 6351 | struct genl_info *info) |
93da9cc1 | 6352 | { |
4c476991 | 6353 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 6354 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
6355 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
6356 | struct mesh_config cur_params; | |
6357 | int err = 0; | |
93da9cc1 | 6358 | void *hdr; |
6359 | struct nlattr *pinfoattr; | |
6360 | struct sk_buff *msg; | |
6361 | ||
29cbe68c JB |
6362 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
6363 | return -EOPNOTSUPP; | |
6364 | ||
24bdd9f4 | 6365 | if (!rdev->ops->get_mesh_config) |
4c476991 | 6366 | return -EOPNOTSUPP; |
f3f92586 | 6367 | |
29cbe68c JB |
6368 | wdev_lock(wdev); |
6369 | /* If not connected, get default parameters */ | |
6370 | if (!wdev->mesh_id_len) | |
6371 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
6372 | else | |
e35e4d28 | 6373 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
6374 | wdev_unlock(wdev); |
6375 | ||
93da9cc1 | 6376 | if (err) |
4c476991 | 6377 | return err; |
93da9cc1 | 6378 | |
6379 | /* Draw up a netlink message to send back */ | |
fd2120ca | 6380 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
6381 | if (!msg) |
6382 | return -ENOMEM; | |
15e47304 | 6383 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 6384 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 6385 | if (!hdr) |
efe1cf0c | 6386 | goto out; |
ae0be8de | 6387 | pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 6388 | if (!pinfoattr) |
6389 | goto nla_put_failure; | |
9360ffd1 DM |
6390 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
6391 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
6392 | cur_params.dot11MeshRetryTimeout) || | |
6393 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
6394 | cur_params.dot11MeshConfirmTimeout) || | |
6395 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
6396 | cur_params.dot11MeshHoldingTimeout) || | |
6397 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
6398 | cur_params.dot11MeshMaxPeerLinks) || | |
6399 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
6400 | cur_params.dot11MeshMaxRetries) || | |
6401 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
6402 | cur_params.dot11MeshTTL) || | |
6403 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
6404 | cur_params.element_ttl) || | |
6405 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
6406 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
6407 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
6408 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
6409 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
6410 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
6411 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
6412 | cur_params.path_refresh_time) || | |
6413 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
6414 | cur_params.min_discovery_timeout) || | |
6415 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
6416 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
6417 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
6418 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
6419 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
6420 | cur_params.dot11MeshHWMPperrMinInterval) || | |
6421 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
6422 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
6423 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
6424 | cur_params.dot11MeshHWMPRootMode) || | |
6425 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
6426 | cur_params.dot11MeshHWMPRannInterval) || | |
6427 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
6428 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
6429 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
6430 | cur_params.dot11MeshForwarding) || | |
335d5349 | 6431 | nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
70c33eaa AN |
6432 | cur_params.rssi_threshold) || |
6433 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
6434 | cur_params.ht_opmode) || |
6435 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
6436 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
6437 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
6438 | cur_params.dot11MeshHWMProotInterval) || |
6439 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
6440 | cur_params.dot11MeshHWMPconfirmationInterval) || |
6441 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
6442 | cur_params.power_mode) || | |
6443 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
6444 | cur_params.dot11MeshAwakeWindowDuration) || |
6445 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
01d66fbd BC |
6446 | cur_params.plink_timeout) || |
6447 | nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE, | |
6448 | cur_params.dot11MeshConnectedToMeshGate)) | |
9360ffd1 | 6449 | goto nla_put_failure; |
93da9cc1 | 6450 | nla_nest_end(msg, pinfoattr); |
6451 | genlmsg_end(msg, hdr); | |
4c476991 | 6452 | return genlmsg_reply(msg, info); |
93da9cc1 | 6453 | |
3b85875a | 6454 | nla_put_failure: |
efe1cf0c | 6455 | out: |
d080e275 | 6456 | nlmsg_free(msg); |
4c476991 | 6457 | return -ENOBUFS; |
93da9cc1 | 6458 | } |
6459 | ||
ab0d76f6 JB |
6460 | static const struct nla_policy |
6461 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { | |
6462 | [NL80211_MESHCONF_RETRY_TIMEOUT] = | |
6463 | NLA_POLICY_RANGE(NLA_U16, 1, 255), | |
6464 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = | |
6465 | NLA_POLICY_RANGE(NLA_U16, 1, 255), | |
6466 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = | |
6467 | NLA_POLICY_RANGE(NLA_U16, 1, 255), | |
6468 | [NL80211_MESHCONF_MAX_PEER_LINKS] = | |
6469 | NLA_POLICY_RANGE(NLA_U16, 0, 255), | |
6470 | [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16), | |
6471 | [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1), | |
6472 | [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1), | |
6473 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1), | |
6474 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = | |
6475 | NLA_POLICY_RANGE(NLA_U32, 1, 255), | |
93da9cc1 | 6476 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
6477 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
ab0d76f6 | 6478 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1), |
93da9cc1 | 6479 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
ab0d76f6 JB |
6480 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = |
6481 | NLA_POLICY_MIN(NLA_U16, 1), | |
6482 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = | |
6483 | NLA_POLICY_MIN(NLA_U16, 1), | |
6484 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = | |
6485 | NLA_POLICY_MIN(NLA_U16, 1), | |
6486 | [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4), | |
6487 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = | |
6488 | NLA_POLICY_MIN(NLA_U16, 1), | |
6489 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1), | |
6490 | [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1), | |
6491 | [NL80211_MESHCONF_RSSI_THRESHOLD] = | |
6492 | NLA_POLICY_RANGE(NLA_S32, -255, 0), | |
a4f606ea | 6493 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
ac1073a6 | 6494 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
ab0d76f6 JB |
6495 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = |
6496 | NLA_POLICY_MIN(NLA_U16, 1), | |
6497 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = | |
6498 | NLA_POLICY_MIN(NLA_U16, 1), | |
6499 | [NL80211_MESHCONF_POWER_MODE] = | |
6500 | NLA_POLICY_RANGE(NLA_U32, | |
6501 | NL80211_MESH_POWER_ACTIVE, | |
6502 | NL80211_MESH_POWER_MAX), | |
3b1c5a53 | 6503 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
8e7c0538 | 6504 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
01d66fbd | 6505 | [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1), |
93da9cc1 | 6506 | }; |
6507 | ||
c80d545d JC |
6508 | static const struct nla_policy |
6509 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 6510 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
6511 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
6512 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 6513 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 6514 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 6515 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
3d7af878 JB |
6516 | [NL80211_MESH_SETUP_IE] = |
6517 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, | |
6518 | IEEE80211_MAX_DATA_LEN), | |
b130e5ce | 6519 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
6520 | }; |
6521 | ||
24bdd9f4 | 6522 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
6523 | struct mesh_config *cfg, |
6524 | u32 *mask_out) | |
93da9cc1 | 6525 | { |
93da9cc1 | 6526 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 6527 | u32 mask = 0; |
9757235f | 6528 | u16 ht_opmode; |
93da9cc1 | 6529 | |
ab0d76f6 JB |
6530 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \ |
6531 | do { \ | |
6532 | if (tb[attr]) { \ | |
6533 | cfg->param = fn(tb[attr]); \ | |
6534 | mask |= BIT((attr) - 1); \ | |
6535 | } \ | |
ea54fba2 | 6536 | } while (0) |
bd90fdcc | 6537 | |
24bdd9f4 | 6538 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 6539 | return -EINVAL; |
8cb08174 | 6540 | if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack)) |
93da9cc1 | 6541 | return -EINVAL; |
6542 | ||
93da9cc1 | 6543 | /* This makes sure that there aren't more than 32 mesh config |
6544 | * parameters (otherwise our bitfield scheme would not work.) */ | |
6545 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
6546 | ||
6547 | /* Fill in the params struct */ | |
ab0d76f6 JB |
6548 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask, |
6549 | NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); | |
6550 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask, | |
6551 | NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
6552 | nla_get_u16); | |
6553 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask, | |
6554 | NL80211_MESHCONF_HOLDING_TIMEOUT, | |
6555 | nla_get_u16); | |
6556 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask, | |
6557 | NL80211_MESHCONF_MAX_PEER_LINKS, | |
6558 | nla_get_u16); | |
6559 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask, | |
6560 | NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); | |
6561 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask, | |
6562 | NL80211_MESHCONF_TTL, nla_get_u8); | |
6563 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask, | |
6564 | NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); | |
6565 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask, | |
6566 | NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
6567 | nla_get_u8); | |
ea54fba2 | 6568 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
ab0d76f6 | 6569 | mask, |
a4f606ea | 6570 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
ab0d76f6 JB |
6571 | nla_get_u32); |
6572 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask, | |
6573 | NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | |
6574 | nla_get_u8); | |
6575 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask, | |
6576 | NL80211_MESHCONF_PATH_REFRESH_TIME, | |
6577 | nla_get_u32); | |
6578 | if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) && | |
6579 | (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535)) | |
6580 | return -EINVAL; | |
6581 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask, | |
6582 | NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
6583 | nla_get_u16); | |
ea54fba2 | 6584 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
ab0d76f6 | 6585 | mask, |
a4f606ea | 6586 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
ab0d76f6 JB |
6587 | nla_get_u32); |
6588 | if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) && | |
6589 | (cfg->dot11MeshHWMPactivePathTimeout < 1 || | |
6590 | cfg->dot11MeshHWMPactivePathTimeout > 65535)) | |
6591 | return -EINVAL; | |
6592 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask, | |
ea54fba2 | 6593 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
ab0d76f6 JB |
6594 | nla_get_u16); |
6595 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask, | |
ea54fba2 | 6596 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
ab0d76f6 | 6597 | nla_get_u16); |
93da9cc1 | 6598 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ab0d76f6 | 6599 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
a4f606ea | 6600 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
ab0d76f6 JB |
6601 | nla_get_u16); |
6602 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, | |
6603 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); | |
6604 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, | |
6605 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
6606 | nla_get_u16); | |
6607 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol, | |
ea54fba2 | 6608 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
ab0d76f6 JB |
6609 | nla_get_u8); |
6610 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask, | |
6611 | NL80211_MESHCONF_FORWARDING, nla_get_u8); | |
6612 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask, | |
6613 | NL80211_MESHCONF_RSSI_THRESHOLD, | |
6614 | nla_get_s32); | |
01d66fbd BC |
6615 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask, |
6616 | NL80211_MESHCONF_CONNECTED_TO_GATE, | |
6617 | nla_get_u8); | |
9757235f MH |
6618 | /* |
6619 | * Check HT operation mode based on | |
188f60ab | 6620 | * IEEE 802.11-2016 9.4.2.57 HT Operation element. |
9757235f MH |
6621 | */ |
6622 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { | |
6623 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); | |
6624 | ||
6625 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | | |
6626 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | | |
6627 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) | |
6628 | return -EINVAL; | |
6629 | ||
188f60ab BC |
6630 | /* NON_HT_STA bit is reserved, but some programs set it */ |
6631 | ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; | |
9757235f | 6632 | |
9757235f | 6633 | cfg->ht_opmode = ht_opmode; |
fd551bac | 6634 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
9757235f | 6635 | } |
728b19e5 | 6636 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ab0d76f6 JB |
6637 | dot11MeshHWMPactivePathToRootTimeout, mask, |
6638 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
6639 | nla_get_u32); | |
6640 | if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) && | |
6641 | (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 || | |
6642 | cfg->dot11MeshHWMPactivePathToRootTimeout > 65535)) | |
6643 | return -EINVAL; | |
6644 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask, | |
6645 | NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
6646 | nla_get_u16); | |
6647 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval, | |
6648 | mask, | |
728b19e5 | 6649 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
ab0d76f6 JB |
6650 | nla_get_u16); |
6651 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask, | |
6652 | NL80211_MESHCONF_POWER_MODE, nla_get_u32); | |
6653 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask, | |
6654 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
6655 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask, | |
6656 | NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32); | |
bd90fdcc JB |
6657 | if (mask_out) |
6658 | *mask_out = mask; | |
c80d545d | 6659 | |
bd90fdcc JB |
6660 | return 0; |
6661 | ||
6662 | #undef FILL_IN_MESH_PARAM_IF_SET | |
6663 | } | |
6664 | ||
c80d545d JC |
6665 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
6666 | struct mesh_setup *setup) | |
6667 | { | |
bb2798d4 | 6668 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
6669 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
6670 | ||
6671 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
6672 | return -EINVAL; | |
8cb08174 | 6673 | if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack)) |
c80d545d JC |
6674 | return -EINVAL; |
6675 | ||
d299a1f2 JC |
6676 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
6677 | setup->sync_method = | |
6678 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
6679 | IEEE80211_SYNC_METHOD_VENDOR : | |
6680 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
6681 | ||
c80d545d JC |
6682 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
6683 | setup->path_sel_proto = | |
6684 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
6685 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
6686 | IEEE80211_PATH_PROTOCOL_HWMP; | |
6687 | ||
6688 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
6689 | setup->path_metric = | |
6690 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
6691 | IEEE80211_PATH_METRIC_VENDOR : | |
6692 | IEEE80211_PATH_METRIC_AIRTIME; | |
6693 | ||
581a8b0f | 6694 | if (tb[NL80211_MESH_SETUP_IE]) { |
c80d545d | 6695 | struct nlattr *ieattr = |
581a8b0f | 6696 | tb[NL80211_MESH_SETUP_IE]; |
581a8b0f JC |
6697 | setup->ie = nla_data(ieattr); |
6698 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 6699 | } |
bb2798d4 TP |
6700 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
6701 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
6702 | return -EINVAL; | |
6703 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
6704 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
6705 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
6706 | if (setup->is_secure) |
6707 | setup->user_mpm = true; | |
c80d545d | 6708 | |
6e16d90b CT |
6709 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
6710 | if (!setup->user_mpm) | |
6711 | return -EINVAL; | |
6712 | setup->auth_id = | |
6713 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
6714 | } | |
6715 | ||
c80d545d JC |
6716 | return 0; |
6717 | } | |
6718 | ||
24bdd9f4 | 6719 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 6720 | struct genl_info *info) |
bd90fdcc JB |
6721 | { |
6722 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6723 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 6724 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
6725 | struct mesh_config cfg; |
6726 | u32 mask; | |
6727 | int err; | |
6728 | ||
29cbe68c JB |
6729 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
6730 | return -EOPNOTSUPP; | |
6731 | ||
24bdd9f4 | 6732 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
6733 | return -EOPNOTSUPP; |
6734 | ||
24bdd9f4 | 6735 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
6736 | if (err) |
6737 | return err; | |
6738 | ||
29cbe68c JB |
6739 | wdev_lock(wdev); |
6740 | if (!wdev->mesh_id_len) | |
6741 | err = -ENOLINK; | |
6742 | ||
6743 | if (!err) | |
e35e4d28 | 6744 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
6745 | |
6746 | wdev_unlock(wdev); | |
6747 | ||
6748 | return err; | |
93da9cc1 | 6749 | } |
6750 | ||
ad30ca2c AN |
6751 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
6752 | struct sk_buff *msg) | |
f130347c | 6753 | { |
f130347c LR |
6754 | struct nlattr *nl_reg_rules; |
6755 | unsigned int i; | |
f130347c | 6756 | |
458f4f9e JB |
6757 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
6758 | (regdom->dfs_region && | |
6759 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
ad30ca2c | 6760 | goto nla_put_failure; |
458f4f9e | 6761 | |
ae0be8de | 6762 | nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES); |
f130347c | 6763 | if (!nl_reg_rules) |
ad30ca2c | 6764 | goto nla_put_failure; |
f130347c | 6765 | |
458f4f9e | 6766 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
6767 | struct nlattr *nl_reg_rule; |
6768 | const struct ieee80211_reg_rule *reg_rule; | |
6769 | const struct ieee80211_freq_range *freq_range; | |
6770 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 6771 | unsigned int max_bandwidth_khz; |
f130347c | 6772 | |
458f4f9e | 6773 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
6774 | freq_range = ®_rule->freq_range; |
6775 | power_rule = ®_rule->power_rule; | |
6776 | ||
ae0be8de | 6777 | nl_reg_rule = nla_nest_start_noflag(msg, i); |
f130347c | 6778 | if (!nl_reg_rule) |
ad30ca2c | 6779 | goto nla_put_failure; |
f130347c | 6780 | |
97524820 JD |
6781 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
6782 | if (!max_bandwidth_khz) | |
6783 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
6784 | reg_rule); | |
6785 | ||
9360ffd1 DM |
6786 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
6787 | reg_rule->flags) || | |
6788 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
6789 | freq_range->start_freq_khz) || | |
6790 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
6791 | freq_range->end_freq_khz) || | |
6792 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 6793 | max_bandwidth_khz) || |
9360ffd1 DM |
6794 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
6795 | power_rule->max_antenna_gain) || | |
6796 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
6797 | power_rule->max_eirp) || |
6798 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
6799 | reg_rule->dfs_cac_ms)) | |
ad30ca2c | 6800 | goto nla_put_failure; |
f130347c LR |
6801 | |
6802 | nla_nest_end(msg, nl_reg_rule); | |
6803 | } | |
6804 | ||
6805 | nla_nest_end(msg, nl_reg_rules); | |
ad30ca2c AN |
6806 | return 0; |
6807 | ||
6808 | nla_put_failure: | |
6809 | return -EMSGSIZE; | |
6810 | } | |
6811 | ||
6812 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | |
6813 | { | |
6814 | const struct ieee80211_regdomain *regdom = NULL; | |
6815 | struct cfg80211_registered_device *rdev; | |
6816 | struct wiphy *wiphy = NULL; | |
6817 | struct sk_buff *msg; | |
6818 | void *hdr; | |
6819 | ||
6820 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
6821 | if (!msg) | |
6822 | return -ENOBUFS; | |
6823 | ||
6824 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
6825 | NL80211_CMD_GET_REG); | |
6826 | if (!hdr) | |
6827 | goto put_failure; | |
6828 | ||
6829 | if (info->attrs[NL80211_ATTR_WIPHY]) { | |
1bdd716c AN |
6830 | bool self_managed; |
6831 | ||
ad30ca2c AN |
6832 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
6833 | if (IS_ERR(rdev)) { | |
6834 | nlmsg_free(msg); | |
6835 | return PTR_ERR(rdev); | |
6836 | } | |
6837 | ||
6838 | wiphy = &rdev->wiphy; | |
1bdd716c AN |
6839 | self_managed = wiphy->regulatory_flags & |
6840 | REGULATORY_WIPHY_SELF_MANAGED; | |
ad30ca2c AN |
6841 | regdom = get_wiphy_regdom(wiphy); |
6842 | ||
1bdd716c AN |
6843 | /* a self-managed-reg device must have a private regdom */ |
6844 | if (WARN_ON(!regdom && self_managed)) { | |
6845 | nlmsg_free(msg); | |
6846 | return -EINVAL; | |
6847 | } | |
6848 | ||
ad30ca2c AN |
6849 | if (regdom && |
6850 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
6851 | goto nla_put_failure; | |
6852 | } | |
6853 | ||
6854 | if (!wiphy && reg_last_request_cell_base() && | |
6855 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
6856 | NL80211_USER_REG_HINT_CELL_BASE)) | |
6857 | goto nla_put_failure; | |
6858 | ||
6859 | rcu_read_lock(); | |
6860 | ||
6861 | if (!regdom) | |
6862 | regdom = rcu_dereference(cfg80211_regdomain); | |
6863 | ||
6864 | if (nl80211_put_regdom(regdom, msg)) | |
6865 | goto nla_put_failure_rcu; | |
6866 | ||
6867 | rcu_read_unlock(); | |
f130347c LR |
6868 | |
6869 | genlmsg_end(msg, hdr); | |
5fe231e8 | 6870 | return genlmsg_reply(msg, info); |
f130347c | 6871 | |
458f4f9e JB |
6872 | nla_put_failure_rcu: |
6873 | rcu_read_unlock(); | |
f130347c | 6874 | nla_put_failure: |
efe1cf0c | 6875 | put_failure: |
d080e275 | 6876 | nlmsg_free(msg); |
5fe231e8 | 6877 | return -EMSGSIZE; |
f130347c LR |
6878 | } |
6879 | ||
ad30ca2c AN |
6880 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
6881 | u32 seq, int flags, struct wiphy *wiphy, | |
6882 | const struct ieee80211_regdomain *regdom) | |
6883 | { | |
6884 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | |
6885 | NL80211_CMD_GET_REG); | |
6886 | ||
6887 | if (!hdr) | |
6888 | return -1; | |
6889 | ||
0a833c29 | 6890 | genl_dump_check_consistent(cb, hdr); |
ad30ca2c AN |
6891 | |
6892 | if (nl80211_put_regdom(regdom, msg)) | |
6893 | goto nla_put_failure; | |
6894 | ||
6895 | if (!wiphy && reg_last_request_cell_base() && | |
6896 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
6897 | NL80211_USER_REG_HINT_CELL_BASE)) | |
6898 | goto nla_put_failure; | |
6899 | ||
6900 | if (wiphy && | |
6901 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
6902 | goto nla_put_failure; | |
6903 | ||
1bdd716c AN |
6904 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
6905 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
6906 | goto nla_put_failure; | |
6907 | ||
053c095a JB |
6908 | genlmsg_end(msg, hdr); |
6909 | return 0; | |
ad30ca2c AN |
6910 | |
6911 | nla_put_failure: | |
6912 | genlmsg_cancel(msg, hdr); | |
6913 | return -EMSGSIZE; | |
6914 | } | |
6915 | ||
6916 | static int nl80211_get_reg_dump(struct sk_buff *skb, | |
6917 | struct netlink_callback *cb) | |
6918 | { | |
6919 | const struct ieee80211_regdomain *regdom = NULL; | |
6920 | struct cfg80211_registered_device *rdev; | |
6921 | int err, reg_idx, start = cb->args[2]; | |
6922 | ||
6923 | rtnl_lock(); | |
6924 | ||
6925 | if (cfg80211_regdomain && start == 0) { | |
6926 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
6927 | NLM_F_MULTI, NULL, | |
6928 | rtnl_dereference(cfg80211_regdomain)); | |
6929 | if (err < 0) | |
6930 | goto out_err; | |
6931 | } | |
6932 | ||
6933 | /* the global regdom is idx 0 */ | |
6934 | reg_idx = 1; | |
6935 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
6936 | regdom = get_wiphy_regdom(&rdev->wiphy); | |
6937 | if (!regdom) | |
6938 | continue; | |
6939 | ||
6940 | if (++reg_idx <= start) | |
6941 | continue; | |
6942 | ||
6943 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
6944 | NLM_F_MULTI, &rdev->wiphy, regdom); | |
6945 | if (err < 0) { | |
6946 | reg_idx--; | |
6947 | break; | |
6948 | } | |
6949 | } | |
6950 | ||
6951 | cb->args[2] = reg_idx; | |
6952 | err = skb->len; | |
6953 | out_err: | |
6954 | rtnl_unlock(); | |
6955 | return err; | |
6956 | } | |
6957 | ||
b6863036 JB |
6958 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
6959 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { | |
6960 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, | |
6961 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
6962 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
6963 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
6964 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
6965 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
6966 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, | |
6967 | }; | |
6968 | ||
6969 | static int parse_reg_rule(struct nlattr *tb[], | |
6970 | struct ieee80211_reg_rule *reg_rule) | |
6971 | { | |
6972 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
6973 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
6974 | ||
6975 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
6976 | return -EINVAL; | |
6977 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
6978 | return -EINVAL; | |
6979 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
6980 | return -EINVAL; | |
6981 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
6982 | return -EINVAL; | |
6983 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
6984 | return -EINVAL; | |
6985 | ||
6986 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
6987 | ||
6988 | freq_range->start_freq_khz = | |
6989 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
6990 | freq_range->end_freq_khz = | |
6991 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
6992 | freq_range->max_bandwidth_khz = | |
6993 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
6994 | ||
6995 | power_rule->max_eirp = | |
6996 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
6997 | ||
6998 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
6999 | power_rule->max_antenna_gain = | |
7000 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
7001 | ||
7002 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) | |
7003 | reg_rule->dfs_cac_ms = | |
7004 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
7005 | ||
7006 | return 0; | |
7007 | } | |
7008 | ||
b2e1b302 LR |
7009 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
7010 | { | |
7011 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
7012 | struct nlattr *nl_reg_rule; | |
ea372c54 JB |
7013 | char *alpha2; |
7014 | int rem_reg_rules, r; | |
391d132c | 7015 | u32 num_rules = 0, rule_idx = 0; |
4c7d3982 | 7016 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
ea372c54 | 7017 | struct ieee80211_regdomain *rd; |
b2e1b302 LR |
7018 | |
7019 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
7020 | return -EINVAL; | |
7021 | ||
7022 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
7023 | return -EINVAL; | |
7024 | ||
7025 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
7026 | ||
8b60b078 LR |
7027 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
7028 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
7029 | ||
b2e1b302 | 7030 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 7031 | rem_reg_rules) { |
b2e1b302 LR |
7032 | num_rules++; |
7033 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 7034 | return -EINVAL; |
b2e1b302 LR |
7035 | } |
7036 | ||
e438768f LR |
7037 | if (!reg_is_valid_request(alpha2)) |
7038 | return -EINVAL; | |
7039 | ||
391d132c | 7040 | rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL); |
6913b49a JB |
7041 | if (!rd) |
7042 | return -ENOMEM; | |
b2e1b302 LR |
7043 | |
7044 | rd->n_reg_rules = num_rules; | |
7045 | rd->alpha2[0] = alpha2[0]; | |
7046 | rd->alpha2[1] = alpha2[1]; | |
7047 | ||
8b60b078 LR |
7048 | /* |
7049 | * Disable DFS master mode if the DFS region was | |
7050 | * not supported or known on this kernel. | |
7051 | */ | |
7052 | if (reg_supported_dfs_region(dfs_region)) | |
7053 | rd->dfs_region = dfs_region; | |
7054 | ||
b2e1b302 | 7055 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 7056 | rem_reg_rules) { |
8cb08174 JB |
7057 | r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX, |
7058 | nl_reg_rule, reg_rule_policy, | |
7059 | info->extack); | |
ae811e21 JB |
7060 | if (r) |
7061 | goto bad_reg; | |
b2e1b302 LR |
7062 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
7063 | if (r) | |
7064 | goto bad_reg; | |
7065 | ||
7066 | rule_idx++; | |
7067 | ||
d0e18f83 LR |
7068 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
7069 | r = -EINVAL; | |
b2e1b302 | 7070 | goto bad_reg; |
d0e18f83 | 7071 | } |
b2e1b302 LR |
7072 | } |
7073 | ||
06627990 JB |
7074 | /* set_regdom takes ownership of rd */ |
7075 | return set_regdom(rd, REGD_SOURCE_CRDA); | |
d2372b31 | 7076 | bad_reg: |
b2e1b302 | 7077 | kfree(rd); |
d0e18f83 | 7078 | return r; |
b2e1b302 | 7079 | } |
b6863036 | 7080 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
b2e1b302 | 7081 | |
83f5e2cf JB |
7082 | static int validate_scan_freqs(struct nlattr *freqs) |
7083 | { | |
7084 | struct nlattr *attr1, *attr2; | |
7085 | int n_channels = 0, tmp1, tmp2; | |
7086 | ||
d7f13f74 SD |
7087 | nla_for_each_nested(attr1, freqs, tmp1) |
7088 | if (nla_len(attr1) != sizeof(u32)) | |
7089 | return 0; | |
7090 | ||
83f5e2cf JB |
7091 | nla_for_each_nested(attr1, freqs, tmp1) { |
7092 | n_channels++; | |
7093 | /* | |
7094 | * Some hardware has a limited channel list for | |
7095 | * scanning, and it is pretty much nonsensical | |
7096 | * to scan for a channel twice, so disallow that | |
7097 | * and don't require drivers to check that the | |
7098 | * channel list they get isn't longer than what | |
7099 | * they can scan, as long as they can scan all | |
7100 | * the channels they registered at once. | |
7101 | */ | |
7102 | nla_for_each_nested(attr2, freqs, tmp2) | |
7103 | if (attr1 != attr2 && | |
7104 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
7105 | return 0; | |
7106 | } | |
7107 | ||
7108 | return n_channels; | |
7109 | } | |
7110 | ||
57fbcce3 | 7111 | static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) |
38de03d2 | 7112 | { |
57fbcce3 | 7113 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
38de03d2 AS |
7114 | } |
7115 | ||
7116 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, | |
7117 | struct cfg80211_bss_selection *bss_select) | |
7118 | { | |
7119 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; | |
7120 | struct nlattr *nest; | |
7121 | int err; | |
7122 | bool found = false; | |
7123 | int i; | |
7124 | ||
7125 | /* only process one nested attribute */ | |
7126 | nest = nla_data(nla); | |
7127 | if (!nla_ok(nest, nla_len(nest))) | |
7128 | return -EINVAL; | |
7129 | ||
8cb08174 JB |
7130 | err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX, |
7131 | nest, nl80211_bss_select_policy, | |
7132 | NULL); | |
38de03d2 AS |
7133 | if (err) |
7134 | return err; | |
7135 | ||
7136 | /* only one attribute may be given */ | |
7137 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { | |
7138 | if (attr[i]) { | |
7139 | if (found) | |
7140 | return -EINVAL; | |
7141 | found = true; | |
7142 | } | |
7143 | } | |
7144 | ||
7145 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; | |
7146 | ||
7147 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) | |
7148 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; | |
7149 | ||
7150 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { | |
7151 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; | |
7152 | bss_select->param.band_pref = | |
7153 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); | |
7154 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) | |
7155 | return -EINVAL; | |
7156 | } | |
7157 | ||
7158 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { | |
7159 | struct nl80211_bss_select_rssi_adjust *adj_param; | |
7160 | ||
7161 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); | |
7162 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; | |
7163 | bss_select->param.adjust.band = adj_param->band; | |
7164 | bss_select->param.adjust.delta = adj_param->delta; | |
7165 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) | |
7166 | return -EINVAL; | |
7167 | } | |
7168 | ||
7169 | /* user-space did not provide behaviour attribute */ | |
7170 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) | |
7171 | return -EINVAL; | |
7172 | ||
7173 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) | |
7174 | return -EINVAL; | |
7175 | ||
7176 | return 0; | |
7177 | } | |
7178 | ||
9bb7e0f2 JB |
7179 | int nl80211_parse_random_mac(struct nlattr **attrs, |
7180 | u8 *mac_addr, u8 *mac_addr_mask) | |
ad2b26ab JB |
7181 | { |
7182 | int i; | |
7183 | ||
7184 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | |
d2beae10 JP |
7185 | eth_zero_addr(mac_addr); |
7186 | eth_zero_addr(mac_addr_mask); | |
ad2b26ab JB |
7187 | mac_addr[0] = 0x2; |
7188 | mac_addr_mask[0] = 0x3; | |
7189 | ||
7190 | return 0; | |
7191 | } | |
7192 | ||
7193 | /* need both or none */ | |
7194 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | |
7195 | return -EINVAL; | |
7196 | ||
7197 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | |
7198 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | |
7199 | ||
7200 | /* don't allow or configure an mcast address */ | |
7201 | if (!is_multicast_ether_addr(mac_addr_mask) || | |
7202 | is_multicast_ether_addr(mac_addr)) | |
7203 | return -EINVAL; | |
7204 | ||
7205 | /* | |
7206 | * allow users to pass a MAC address that has bits set outside | |
7207 | * of the mask, but don't bother drivers with having to deal | |
7208 | * with such bits | |
7209 | */ | |
7210 | for (i = 0; i < ETH_ALEN; i++) | |
7211 | mac_addr[i] &= mac_addr_mask[i]; | |
7212 | ||
7213 | return 0; | |
7214 | } | |
7215 | ||
34373d12 VT |
7216 | static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) |
7217 | { | |
7218 | ASSERT_WDEV_LOCK(wdev); | |
7219 | ||
7220 | if (!cfg80211_beaconing_iface_active(wdev)) | |
7221 | return true; | |
7222 | ||
7223 | if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) | |
7224 | return true; | |
7225 | ||
7226 | return regulatory_pre_cac_allowed(wdev->wiphy); | |
7227 | } | |
7228 | ||
db0a4ad8 JB |
7229 | static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, |
7230 | enum nl80211_ext_feature_index feat) | |
7231 | { | |
7232 | if (!(flags & flag)) | |
7233 | return true; | |
7234 | if (wiphy_ext_feature_isset(wiphy, feat)) | |
7235 | return true; | |
7236 | return false; | |
7237 | } | |
7238 | ||
2d23d073 RZ |
7239 | static int |
7240 | nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, | |
7241 | void *request, struct nlattr **attrs, | |
7242 | bool is_sched_scan) | |
7243 | { | |
7244 | u8 *mac_addr, *mac_addr_mask; | |
7245 | u32 *flags; | |
7246 | enum nl80211_feature_flags randomness_flag; | |
7247 | ||
7248 | if (!attrs[NL80211_ATTR_SCAN_FLAGS]) | |
7249 | return 0; | |
7250 | ||
7251 | if (is_sched_scan) { | |
7252 | struct cfg80211_sched_scan_request *req = request; | |
7253 | ||
7254 | randomness_flag = wdev ? | |
7255 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : | |
7256 | NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
7257 | flags = &req->flags; | |
7258 | mac_addr = req->mac_addr; | |
7259 | mac_addr_mask = req->mac_addr_mask; | |
7260 | } else { | |
7261 | struct cfg80211_scan_request *req = request; | |
7262 | ||
7263 | randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; | |
7264 | flags = &req->flags; | |
7265 | mac_addr = req->mac_addr; | |
7266 | mac_addr_mask = req->mac_addr_mask; | |
7267 | } | |
7268 | ||
7269 | *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); | |
7270 | ||
5037a009 SD |
7271 | if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
7272 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
db0a4ad8 JB |
7273 | !nl80211_check_scan_feat(wiphy, *flags, |
7274 | NL80211_SCAN_FLAG_LOW_SPAN, | |
7275 | NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || | |
7276 | !nl80211_check_scan_feat(wiphy, *flags, | |
7277 | NL80211_SCAN_FLAG_LOW_POWER, | |
7278 | NL80211_EXT_FEATURE_LOW_POWER_SCAN) || | |
7279 | !nl80211_check_scan_feat(wiphy, *flags, | |
7280 | NL80211_SCAN_FLAG_HIGH_ACCURACY, | |
7281 | NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || | |
7282 | !nl80211_check_scan_feat(wiphy, *flags, | |
7283 | NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, | |
7284 | NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || | |
7285 | !nl80211_check_scan_feat(wiphy, *flags, | |
7286 | NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, | |
7287 | NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || | |
7288 | !nl80211_check_scan_feat(wiphy, *flags, | |
7289 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, | |
7290 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || | |
7291 | !nl80211_check_scan_feat(wiphy, *flags, | |
7292 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, | |
2e076f19 JB |
7293 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || |
7294 | !nl80211_check_scan_feat(wiphy, *flags, | |
7295 | NL80211_SCAN_FLAG_RANDOM_SN, | |
7296 | NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || | |
7297 | !nl80211_check_scan_feat(wiphy, *flags, | |
7298 | NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, | |
7299 | NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) | |
2d23d073 RZ |
7300 | return -EOPNOTSUPP; |
7301 | ||
7302 | if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
7303 | int err; | |
7304 | ||
7305 | if (!(wiphy->features & randomness_flag) || | |
7306 | (wdev && wdev->current_bss)) | |
7307 | return -EOPNOTSUPP; | |
7308 | ||
7309 | err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); | |
7310 | if (err) | |
7311 | return err; | |
7312 | } | |
7313 | ||
2d23d073 RZ |
7314 | return 0; |
7315 | } | |
7316 | ||
2a519311 JB |
7317 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
7318 | { | |
4c476991 | 7319 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 7320 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 7321 | struct cfg80211_scan_request *request; |
2a519311 JB |
7322 | struct nlattr *attr; |
7323 | struct wiphy *wiphy; | |
83f5e2cf | 7324 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 7325 | size_t ie_len; |
2a519311 | 7326 | |
79c97e97 | 7327 | wiphy = &rdev->wiphy; |
2a519311 | 7328 | |
cb3b7d87 AB |
7329 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
7330 | return -EOPNOTSUPP; | |
7331 | ||
4c476991 JB |
7332 | if (!rdev->ops->scan) |
7333 | return -EOPNOTSUPP; | |
2a519311 | 7334 | |
f9d15d16 | 7335 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
7336 | err = -EBUSY; |
7337 | goto unlock; | |
7338 | } | |
2a519311 JB |
7339 | |
7340 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
7341 | n_channels = validate_scan_freqs( |
7342 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
7343 | if (!n_channels) { |
7344 | err = -EINVAL; | |
7345 | goto unlock; | |
7346 | } | |
2a519311 | 7347 | } else { |
bdfbec2d | 7348 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
7349 | } |
7350 | ||
7351 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
7352 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
7353 | n_ssids++; | |
7354 | ||
f9f47529 JB |
7355 | if (n_ssids > wiphy->max_scan_ssids) { |
7356 | err = -EINVAL; | |
7357 | goto unlock; | |
7358 | } | |
2a519311 | 7359 | |
70692ad2 JM |
7360 | if (info->attrs[NL80211_ATTR_IE]) |
7361 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7362 | else | |
7363 | ie_len = 0; | |
7364 | ||
f9f47529 JB |
7365 | if (ie_len > wiphy->max_scan_ie_len) { |
7366 | err = -EINVAL; | |
7367 | goto unlock; | |
7368 | } | |
18a83659 | 7369 | |
2a519311 | 7370 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
7371 | + sizeof(*request->ssids) * n_ssids |
7372 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 7373 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
7374 | if (!request) { |
7375 | err = -ENOMEM; | |
7376 | goto unlock; | |
7377 | } | |
2a519311 | 7378 | |
2a519311 | 7379 | if (n_ssids) |
5ba63533 | 7380 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 7381 | request->n_ssids = n_ssids; |
70692ad2 | 7382 | if (ie_len) { |
13874e4b | 7383 | if (n_ssids) |
70692ad2 JM |
7384 | request->ie = (void *)(request->ssids + n_ssids); |
7385 | else | |
7386 | request->ie = (void *)(request->channels + n_channels); | |
7387 | } | |
2a519311 | 7388 | |
584991dc | 7389 | i = 0; |
2a519311 JB |
7390 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
7391 | /* user specified, bail out if channel not found */ | |
2a519311 | 7392 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
7393 | struct ieee80211_channel *chan; |
7394 | ||
7395 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
7396 | ||
7397 | if (!chan) { | |
2a519311 JB |
7398 | err = -EINVAL; |
7399 | goto out_free; | |
7400 | } | |
584991dc JB |
7401 | |
7402 | /* ignore disabled channels */ | |
7403 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
7404 | continue; | |
7405 | ||
7406 | request->channels[i] = chan; | |
2a519311 JB |
7407 | i++; |
7408 | } | |
7409 | } else { | |
57fbcce3 | 7410 | enum nl80211_band band; |
34850ab2 | 7411 | |
2a519311 | 7412 | /* all channels */ |
57fbcce3 | 7413 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
2a519311 | 7414 | int j; |
7a087e74 | 7415 | |
2a519311 JB |
7416 | if (!wiphy->bands[band]) |
7417 | continue; | |
7418 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
7419 | struct ieee80211_channel *chan; |
7420 | ||
7421 | chan = &wiphy->bands[band]->channels[j]; | |
7422 | ||
7423 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
7424 | continue; | |
7425 | ||
7426 | request->channels[i] = chan; | |
2a519311 JB |
7427 | i++; |
7428 | } | |
7429 | } | |
7430 | } | |
7431 | ||
584991dc JB |
7432 | if (!i) { |
7433 | err = -EINVAL; | |
7434 | goto out_free; | |
7435 | } | |
7436 | ||
7437 | request->n_channels = i; | |
7438 | ||
34373d12 VT |
7439 | wdev_lock(wdev); |
7440 | if (!cfg80211_off_channel_oper_allowed(wdev)) { | |
7441 | struct ieee80211_channel *chan; | |
7442 | ||
7443 | if (request->n_channels != 1) { | |
7444 | wdev_unlock(wdev); | |
7445 | err = -EBUSY; | |
7446 | goto out_free; | |
7447 | } | |
7448 | ||
7449 | chan = request->channels[0]; | |
7450 | if (chan->center_freq != wdev->chandef.chan->center_freq) { | |
7451 | wdev_unlock(wdev); | |
7452 | err = -EBUSY; | |
7453 | goto out_free; | |
7454 | } | |
7455 | } | |
7456 | wdev_unlock(wdev); | |
7457 | ||
2a519311 | 7458 | i = 0; |
13874e4b | 7459 | if (n_ssids) { |
2a519311 | 7460 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
57a27e1d | 7461 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
7462 | err = -EINVAL; |
7463 | goto out_free; | |
7464 | } | |
57a27e1d | 7465 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 7466 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
7467 | i++; |
7468 | } | |
7469 | } | |
7470 | ||
70692ad2 JM |
7471 | if (info->attrs[NL80211_ATTR_IE]) { |
7472 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
7473 | memcpy((void *)request->ie, |
7474 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
7475 | request->ie_len); |
7476 | } | |
7477 | ||
57fbcce3 | 7478 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
a401d2bb JB |
7479 | if (wiphy->bands[i]) |
7480 | request->rates[i] = | |
7481 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
7482 | |
7483 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
7484 | nla_for_each_nested(attr, | |
7485 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
7486 | tmp) { | |
57fbcce3 | 7487 | enum nl80211_band band = nla_type(attr); |
34850ab2 | 7488 | |
57fbcce3 | 7489 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
34850ab2 JB |
7490 | err = -EINVAL; |
7491 | goto out_free; | |
7492 | } | |
1b09cd82 FF |
7493 | |
7494 | if (!wiphy->bands[band]) | |
7495 | continue; | |
7496 | ||
34850ab2 JB |
7497 | err = ieee80211_get_ratemask(wiphy->bands[band], |
7498 | nla_data(attr), | |
7499 | nla_len(attr), | |
7500 | &request->rates[band]); | |
7501 | if (err) | |
7502 | goto out_free; | |
7503 | } | |
7504 | } | |
7505 | ||
1d76250b AS |
7506 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
7507 | if (!wiphy_ext_feature_isset(wiphy, | |
7508 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { | |
7509 | err = -EOPNOTSUPP; | |
7510 | goto out_free; | |
7511 | } | |
7512 | ||
7513 | request->duration = | |
7514 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); | |
7515 | request->duration_mandatory = | |
7516 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); | |
7517 | } | |
7518 | ||
2d23d073 RZ |
7519 | err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, |
7520 | false); | |
7521 | if (err) | |
7522 | goto out_free; | |
ed473771 | 7523 | |
e9f935e3 RM |
7524 | request->no_cck = |
7525 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
7526 | ||
2fa436b3 VK |
7527 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
7528 | * BSSID to scan for. This was problematic because that same attribute | |
7529 | * was already used for another purpose (local random MAC address). The | |
7530 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards | |
7531 | * compatibility with older userspace components, also use the | |
7532 | * NL80211_ATTR_MAC value here if it can be determined to be used for | |
7533 | * the specific BSSID use case instead of the random MAC address | |
7534 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). | |
7535 | */ | |
7536 | if (info->attrs[NL80211_ATTR_BSSID]) | |
7537 | memcpy(request->bssid, | |
7538 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); | |
7539 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && | |
7540 | info->attrs[NL80211_ATTR_MAC]) | |
818965d3 JM |
7541 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
7542 | ETH_ALEN); | |
7543 | else | |
7544 | eth_broadcast_addr(request->bssid); | |
7545 | ||
fd014284 | 7546 | request->wdev = wdev; |
79c97e97 | 7547 | request->wiphy = &rdev->wiphy; |
15d6030b | 7548 | request->scan_start = jiffies; |
2a519311 | 7549 | |
79c97e97 | 7550 | rdev->scan_req = request; |
e35e4d28 | 7551 | err = rdev_scan(rdev, request); |
2a519311 | 7552 | |
463d0183 | 7553 | if (!err) { |
fd014284 JB |
7554 | nl80211_send_scan_start(rdev, wdev); |
7555 | if (wdev->netdev) | |
7556 | dev_hold(wdev->netdev); | |
4c476991 | 7557 | } else { |
2a519311 | 7558 | out_free: |
79c97e97 | 7559 | rdev->scan_req = NULL; |
2a519311 JB |
7560 | kfree(request); |
7561 | } | |
3b85875a | 7562 | |
f9f47529 | 7563 | unlock: |
2a519311 JB |
7564 | return err; |
7565 | } | |
7566 | ||
91d3ab46 VK |
7567 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
7568 | { | |
7569 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7570 | struct wireless_dev *wdev = info->user_ptr[1]; | |
7571 | ||
7572 | if (!rdev->ops->abort_scan) | |
7573 | return -EOPNOTSUPP; | |
7574 | ||
7575 | if (rdev->scan_msg) | |
7576 | return 0; | |
7577 | ||
7578 | if (!rdev->scan_req) | |
7579 | return -ENOENT; | |
7580 | ||
7581 | rdev_abort_scan(rdev, wdev); | |
7582 | return 0; | |
7583 | } | |
7584 | ||
3b06d277 AS |
7585 | static int |
7586 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, | |
7587 | struct cfg80211_sched_scan_request *request, | |
7588 | struct nlattr **attrs) | |
7589 | { | |
7590 | int tmp, err, i = 0; | |
7591 | struct nlattr *attr; | |
7592 | ||
7593 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { | |
7594 | u32 interval; | |
7595 | ||
7596 | /* | |
7597 | * If scan plans are not specified, | |
5a88de53 | 7598 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this |
3b06d277 AS |
7599 | * case one scan plan will be set with the specified scan |
7600 | * interval and infinite number of iterations. | |
7601 | */ | |
3b06d277 AS |
7602 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
7603 | if (!interval) | |
7604 | return -EINVAL; | |
7605 | ||
7606 | request->scan_plans[0].interval = | |
7607 | DIV_ROUND_UP(interval, MSEC_PER_SEC); | |
7608 | if (!request->scan_plans[0].interval) | |
7609 | return -EINVAL; | |
7610 | ||
7611 | if (request->scan_plans[0].interval > | |
7612 | wiphy->max_sched_scan_plan_interval) | |
7613 | request->scan_plans[0].interval = | |
7614 | wiphy->max_sched_scan_plan_interval; | |
7615 | ||
7616 | return 0; | |
7617 | } | |
7618 | ||
7619 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { | |
7620 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; | |
7621 | ||
7622 | if (WARN_ON(i >= n_plans)) | |
7623 | return -EINVAL; | |
7624 | ||
8cb08174 JB |
7625 | err = nla_parse_nested_deprecated(plan, |
7626 | NL80211_SCHED_SCAN_PLAN_MAX, | |
7627 | attr, nl80211_plan_policy, | |
7628 | NULL); | |
3b06d277 AS |
7629 | if (err) |
7630 | return err; | |
7631 | ||
7632 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) | |
7633 | return -EINVAL; | |
7634 | ||
7635 | request->scan_plans[i].interval = | |
7636 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); | |
7637 | if (!request->scan_plans[i].interval || | |
7638 | request->scan_plans[i].interval > | |
7639 | wiphy->max_sched_scan_plan_interval) | |
7640 | return -EINVAL; | |
7641 | ||
7642 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { | |
7643 | request->scan_plans[i].iterations = | |
7644 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); | |
7645 | if (!request->scan_plans[i].iterations || | |
7646 | (request->scan_plans[i].iterations > | |
7647 | wiphy->max_sched_scan_plan_iterations)) | |
7648 | return -EINVAL; | |
7649 | } else if (i < n_plans - 1) { | |
7650 | /* | |
7651 | * All scan plans but the last one must specify | |
7652 | * a finite number of iterations | |
7653 | */ | |
7654 | return -EINVAL; | |
7655 | } | |
7656 | ||
7657 | i++; | |
7658 | } | |
7659 | ||
7660 | /* | |
7661 | * The last scan plan must not specify the number of | |
7662 | * iterations, it is supposed to run infinitely | |
7663 | */ | |
7664 | if (request->scan_plans[n_plans - 1].iterations) | |
7665 | return -EINVAL; | |
7666 | ||
7667 | return 0; | |
7668 | } | |
7669 | ||
1e1b11b6 | 7670 | static int |
7671 | nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy, | |
7672 | struct cfg80211_match_set *match_sets, | |
7673 | struct nlattr *tb_band_rssi, | |
7674 | s32 rssi_thold) | |
7675 | { | |
7676 | struct nlattr *attr; | |
7677 | int i, tmp, ret = 0; | |
7678 | ||
7679 | if (!wiphy_ext_feature_isset(wiphy, | |
7680 | NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) { | |
7681 | if (tb_band_rssi) | |
7682 | ret = -EOPNOTSUPP; | |
7683 | else | |
7684 | for (i = 0; i < NUM_NL80211_BANDS; i++) | |
7685 | match_sets->per_band_rssi_thold[i] = | |
7686 | NL80211_SCAN_RSSI_THOLD_OFF; | |
7687 | return ret; | |
7688 | } | |
7689 | ||
7690 | for (i = 0; i < NUM_NL80211_BANDS; i++) | |
7691 | match_sets->per_band_rssi_thold[i] = rssi_thold; | |
7692 | ||
7693 | nla_for_each_nested(attr, tb_band_rssi, tmp) { | |
7694 | enum nl80211_band band = nla_type(attr); | |
7695 | ||
7696 | if (band < 0 || band >= NUM_NL80211_BANDS) | |
7697 | return -EINVAL; | |
7698 | ||
7699 | match_sets->per_band_rssi_thold[band] = nla_get_s32(attr); | |
7700 | } | |
7701 | ||
7702 | return 0; | |
7703 | } | |
7704 | ||
256da02d | 7705 | static struct cfg80211_sched_scan_request * |
ad2b26ab | 7706 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
aad1e812 | 7707 | struct nlattr **attrs, int max_match_sets) |
807f8a8c LC |
7708 | { |
7709 | struct cfg80211_sched_scan_request *request; | |
807f8a8c | 7710 | struct nlattr *attr; |
3b06d277 | 7711 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; |
57fbcce3 | 7712 | enum nl80211_band band; |
807f8a8c | 7713 | size_t ie_len; |
a1f1c21c | 7714 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 7715 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c | 7716 | |
256da02d | 7717 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c | 7718 | n_channels = validate_scan_freqs( |
256da02d | 7719 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
807f8a8c | 7720 | if (!n_channels) |
256da02d | 7721 | return ERR_PTR(-EINVAL); |
807f8a8c | 7722 | } else { |
bdfbec2d | 7723 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
7724 | } |
7725 | ||
256da02d LC |
7726 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
7727 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c LC |
7728 | tmp) |
7729 | n_ssids++; | |
7730 | ||
93b6aa69 | 7731 | if (n_ssids > wiphy->max_sched_scan_ssids) |
256da02d | 7732 | return ERR_PTR(-EINVAL); |
807f8a8c | 7733 | |
ea73cbce JB |
7734 | /* |
7735 | * First, count the number of 'real' matchsets. Due to an issue with | |
7736 | * the old implementation, matchsets containing only the RSSI attribute | |
7737 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
7738 | * RSSI for all matchsets, rather than their own matchset for reporting | |
7739 | * all APs with a strong RSSI. This is needed to be compatible with | |
7740 | * older userspace that treated a matchset with only the RSSI as the | |
7741 | * global RSSI for all other matchsets - if there are other matchsets. | |
7742 | */ | |
256da02d | 7743 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 7744 | nla_for_each_nested(attr, |
256da02d | 7745 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
ea73cbce JB |
7746 | tmp) { |
7747 | struct nlattr *rssi; | |
7748 | ||
8cb08174 JB |
7749 | err = nla_parse_nested_deprecated(tb, |
7750 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
7751 | attr, | |
7752 | nl80211_match_policy, | |
7753 | NULL); | |
ea73cbce | 7754 | if (err) |
256da02d | 7755 | return ERR_PTR(err); |
3007e352 AVS |
7756 | |
7757 | /* SSID and BSSID are mutually exclusive */ | |
7758 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && | |
7759 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) | |
7760 | return ERR_PTR(-EINVAL); | |
7761 | ||
ea73cbce | 7762 | /* add other standalone attributes here */ |
3007e352 AVS |
7763 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || |
7764 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { | |
ea73cbce JB |
7765 | n_match_sets++; |
7766 | continue; | |
7767 | } | |
7768 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
7769 | if (rssi) | |
7770 | default_match_rssi = nla_get_s32(rssi); | |
7771 | } | |
7772 | } | |
7773 | ||
7774 | /* However, if there's no other matchset, add the RSSI one */ | |
7775 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
7776 | n_match_sets = 1; | |
a1f1c21c | 7777 | |
aad1e812 | 7778 | if (n_match_sets > max_match_sets) |
256da02d | 7779 | return ERR_PTR(-EINVAL); |
a1f1c21c | 7780 | |
256da02d LC |
7781 | if (attrs[NL80211_ATTR_IE]) |
7782 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | |
807f8a8c LC |
7783 | else |
7784 | ie_len = 0; | |
7785 | ||
5a865bad | 7786 | if (ie_len > wiphy->max_sched_scan_ie_len) |
256da02d | 7787 | return ERR_PTR(-EINVAL); |
c10841ca | 7788 | |
3b06d277 AS |
7789 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
7790 | /* | |
7791 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since | |
7792 | * each scan plan already specifies its own interval | |
7793 | */ | |
7794 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
7795 | return ERR_PTR(-EINVAL); | |
7796 | ||
7797 | nla_for_each_nested(attr, | |
7798 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) | |
7799 | n_plans++; | |
7800 | } else { | |
7801 | /* | |
7802 | * The scan interval attribute is kept for backward | |
7803 | * compatibility. If no scan plans are specified and sched scan | |
7804 | * interval is specified, one scan plan will be set with this | |
7805 | * scan interval and infinite number of iterations. | |
7806 | */ | |
7807 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
7808 | return ERR_PTR(-EINVAL); | |
7809 | ||
7810 | n_plans = 1; | |
7811 | } | |
7812 | ||
7813 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) | |
7814 | return ERR_PTR(-EINVAL); | |
7815 | ||
bf95ecdb | 7816 | if (!wiphy_ext_feature_isset( |
7817 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && | |
7818 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || | |
7819 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) | |
7820 | return ERR_PTR(-EINVAL); | |
7821 | ||
807f8a8c | 7822 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 7823 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 7824 | + sizeof(*request->match_sets) * n_match_sets |
3b06d277 | 7825 | + sizeof(*request->scan_plans) * n_plans |
a2cd43c5 | 7826 | + sizeof(*request->channels) * n_channels |
807f8a8c | 7827 | + ie_len, GFP_KERNEL); |
256da02d LC |
7828 | if (!request) |
7829 | return ERR_PTR(-ENOMEM); | |
807f8a8c LC |
7830 | |
7831 | if (n_ssids) | |
7832 | request->ssids = (void *)&request->channels[n_channels]; | |
7833 | request->n_ssids = n_ssids; | |
7834 | if (ie_len) { | |
13874e4b | 7835 | if (n_ssids) |
807f8a8c LC |
7836 | request->ie = (void *)(request->ssids + n_ssids); |
7837 | else | |
7838 | request->ie = (void *)(request->channels + n_channels); | |
7839 | } | |
7840 | ||
a1f1c21c LC |
7841 | if (n_match_sets) { |
7842 | if (request->ie) | |
7843 | request->match_sets = (void *)(request->ie + ie_len); | |
13874e4b | 7844 | else if (n_ssids) |
a1f1c21c LC |
7845 | request->match_sets = |
7846 | (void *)(request->ssids + n_ssids); | |
7847 | else | |
7848 | request->match_sets = | |
7849 | (void *)(request->channels + n_channels); | |
7850 | } | |
7851 | request->n_match_sets = n_match_sets; | |
7852 | ||
3b06d277 AS |
7853 | if (n_match_sets) |
7854 | request->scan_plans = (void *)(request->match_sets + | |
7855 | n_match_sets); | |
7856 | else if (request->ie) | |
7857 | request->scan_plans = (void *)(request->ie + ie_len); | |
7858 | else if (n_ssids) | |
7859 | request->scan_plans = (void *)(request->ssids + n_ssids); | |
7860 | else | |
7861 | request->scan_plans = (void *)(request->channels + n_channels); | |
7862 | ||
7863 | request->n_scan_plans = n_plans; | |
7864 | ||
807f8a8c | 7865 | i = 0; |
256da02d | 7866 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c LC |
7867 | /* user specified, bail out if channel not found */ |
7868 | nla_for_each_nested(attr, | |
256da02d | 7869 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
807f8a8c LC |
7870 | tmp) { |
7871 | struct ieee80211_channel *chan; | |
7872 | ||
7873 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
7874 | ||
7875 | if (!chan) { | |
7876 | err = -EINVAL; | |
7877 | goto out_free; | |
7878 | } | |
7879 | ||
7880 | /* ignore disabled channels */ | |
7881 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
7882 | continue; | |
7883 | ||
7884 | request->channels[i] = chan; | |
7885 | i++; | |
7886 | } | |
7887 | } else { | |
7888 | /* all channels */ | |
57fbcce3 | 7889 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
807f8a8c | 7890 | int j; |
7a087e74 | 7891 | |
807f8a8c LC |
7892 | if (!wiphy->bands[band]) |
7893 | continue; | |
7894 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
7895 | struct ieee80211_channel *chan; | |
7896 | ||
7897 | chan = &wiphy->bands[band]->channels[j]; | |
7898 | ||
7899 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
7900 | continue; | |
7901 | ||
7902 | request->channels[i] = chan; | |
7903 | i++; | |
7904 | } | |
7905 | } | |
7906 | } | |
7907 | ||
7908 | if (!i) { | |
7909 | err = -EINVAL; | |
7910 | goto out_free; | |
7911 | } | |
7912 | ||
7913 | request->n_channels = i; | |
7914 | ||
7915 | i = 0; | |
13874e4b | 7916 | if (n_ssids) { |
256da02d | 7917 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
807f8a8c | 7918 | tmp) { |
57a27e1d | 7919 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
7920 | err = -EINVAL; |
7921 | goto out_free; | |
7922 | } | |
57a27e1d | 7923 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
7924 | memcpy(request->ssids[i].ssid, nla_data(attr), |
7925 | nla_len(attr)); | |
807f8a8c LC |
7926 | i++; |
7927 | } | |
7928 | } | |
7929 | ||
a1f1c21c | 7930 | i = 0; |
256da02d | 7931 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 7932 | nla_for_each_nested(attr, |
256da02d | 7933 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
a1f1c21c | 7934 | tmp) { |
3007e352 | 7935 | struct nlattr *ssid, *bssid, *rssi; |
a1f1c21c | 7936 | |
8cb08174 JB |
7937 | err = nla_parse_nested_deprecated(tb, |
7938 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
7939 | attr, | |
7940 | nl80211_match_policy, | |
7941 | NULL); | |
ae811e21 JB |
7942 | if (err) |
7943 | goto out_free; | |
4a4ab0d7 | 7944 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
3007e352 | 7945 | bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; |
d39f3b4f JB |
7946 | |
7947 | if (!ssid && !bssid) { | |
7948 | i++; | |
7949 | continue; | |
7950 | } | |
7951 | ||
7952 | if (WARN_ON(i >= n_match_sets)) { | |
7953 | /* this indicates a programming error, | |
7954 | * the loop above should have verified | |
7955 | * things properly | |
7956 | */ | |
7957 | err = -EINVAL; | |
7958 | goto out_free; | |
7959 | } | |
7960 | ||
7961 | if (ssid) { | |
7962 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | |
ea73cbce JB |
7963 | err = -EINVAL; |
7964 | goto out_free; | |
7965 | } | |
d39f3b4f JB |
7966 | memcpy(request->match_sets[i].ssid.ssid, |
7967 | nla_data(ssid), nla_len(ssid)); | |
7968 | request->match_sets[i].ssid.ssid_len = | |
7969 | nla_len(ssid); | |
7970 | } | |
7971 | if (bssid) { | |
7972 | if (nla_len(bssid) != ETH_ALEN) { | |
7973 | err = -EINVAL; | |
7974 | goto out_free; | |
a1f1c21c | 7975 | } |
d39f3b4f JB |
7976 | memcpy(request->match_sets[i].bssid, |
7977 | nla_data(bssid), ETH_ALEN); | |
7978 | } | |
3007e352 | 7979 | |
d39f3b4f JB |
7980 | /* special attribute - old implementation w/a */ |
7981 | request->match_sets[i].rssi_thold = default_match_rssi; | |
7982 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
7983 | if (rssi) | |
ea73cbce | 7984 | request->match_sets[i].rssi_thold = |
d39f3b4f | 7985 | nla_get_s32(rssi); |
1e1b11b6 | 7986 | |
7987 | /* Parse per band RSSI attribute */ | |
7988 | err = nl80211_parse_sched_scan_per_band_rssi(wiphy, | |
7989 | &request->match_sets[i], | |
7990 | tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI], | |
7991 | request->match_sets[i].rssi_thold); | |
7992 | if (err) | |
7993 | goto out_free; | |
7994 | ||
a1f1c21c LC |
7995 | i++; |
7996 | } | |
ea73cbce JB |
7997 | |
7998 | /* there was no other matchset, so the RSSI one is alone */ | |
f89f46cf | 7999 | if (i == 0 && n_match_sets) |
ea73cbce JB |
8000 | request->match_sets[0].rssi_thold = default_match_rssi; |
8001 | ||
8002 | request->min_rssi_thold = INT_MAX; | |
8003 | for (i = 0; i < n_match_sets; i++) | |
8004 | request->min_rssi_thold = | |
8005 | min(request->match_sets[i].rssi_thold, | |
8006 | request->min_rssi_thold); | |
8007 | } else { | |
8008 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
8009 | } |
8010 | ||
9900e484 JB |
8011 | if (ie_len) { |
8012 | request->ie_len = ie_len; | |
807f8a8c | 8013 | memcpy((void *)request->ie, |
256da02d | 8014 | nla_data(attrs[NL80211_ATTR_IE]), |
807f8a8c LC |
8015 | request->ie_len); |
8016 | } | |
8017 | ||
2d23d073 RZ |
8018 | err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); |
8019 | if (err) | |
8020 | goto out_free; | |
ed473771 | 8021 | |
9c748934 LC |
8022 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
8023 | request->delay = | |
8024 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); | |
8025 | ||
bf95ecdb | 8026 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { |
8027 | request->relative_rssi = nla_get_s8( | |
8028 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); | |
8029 | request->relative_rssi_set = true; | |
8030 | } | |
8031 | ||
8032 | if (request->relative_rssi_set && | |
8033 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { | |
8034 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; | |
8035 | ||
8036 | rssi_adjust = nla_data( | |
8037 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); | |
8038 | request->rssi_adjust.band = rssi_adjust->band; | |
8039 | request->rssi_adjust.delta = rssi_adjust->delta; | |
8040 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { | |
8041 | err = -EINVAL; | |
8042 | goto out_free; | |
8043 | } | |
8044 | } | |
8045 | ||
3b06d277 AS |
8046 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
8047 | if (err) | |
8048 | goto out_free; | |
8049 | ||
15d6030b | 8050 | request->scan_start = jiffies; |
807f8a8c | 8051 | |
256da02d | 8052 | return request; |
807f8a8c LC |
8053 | |
8054 | out_free: | |
8055 | kfree(request); | |
256da02d LC |
8056 | return ERR_PTR(err); |
8057 | } | |
8058 | ||
8059 | static int nl80211_start_sched_scan(struct sk_buff *skb, | |
8060 | struct genl_info *info) | |
8061 | { | |
8062 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8063 | struct net_device *dev = info->user_ptr[1]; | |
ad2b26ab | 8064 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
31a60ed1 | 8065 | struct cfg80211_sched_scan_request *sched_scan_req; |
ca986ad9 | 8066 | bool want_multi; |
256da02d LC |
8067 | int err; |
8068 | ||
ca986ad9 | 8069 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) |
256da02d LC |
8070 | return -EOPNOTSUPP; |
8071 | ||
ca986ad9 AVS |
8072 | want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; |
8073 | err = cfg80211_sched_scan_req_possible(rdev, want_multi); | |
8074 | if (err) | |
8075 | return err; | |
256da02d | 8076 | |
31a60ed1 | 8077 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
aad1e812 AVS |
8078 | info->attrs, |
8079 | rdev->wiphy.max_match_sets); | |
31a60ed1 JR |
8080 | |
8081 | err = PTR_ERR_OR_ZERO(sched_scan_req); | |
256da02d LC |
8082 | if (err) |
8083 | goto out_err; | |
8084 | ||
ca986ad9 AVS |
8085 | /* leave request id zero for legacy request |
8086 | * or if driver does not support multi-scheduled scan | |
8087 | */ | |
8088 | if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) { | |
8089 | while (!sched_scan_req->reqid) | |
b60ad348 | 8090 | sched_scan_req->reqid = cfg80211_assign_cookie(rdev); |
ca986ad9 AVS |
8091 | } |
8092 | ||
31a60ed1 | 8093 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
256da02d LC |
8094 | if (err) |
8095 | goto out_free; | |
8096 | ||
31a60ed1 JR |
8097 | sched_scan_req->dev = dev; |
8098 | sched_scan_req->wiphy = &rdev->wiphy; | |
8099 | ||
93a1e86c JR |
8100 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
8101 | sched_scan_req->owner_nlportid = info->snd_portid; | |
8102 | ||
ca986ad9 | 8103 | cfg80211_add_sched_scan_req(rdev, sched_scan_req); |
256da02d | 8104 | |
96b08fd6 | 8105 | nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); |
256da02d LC |
8106 | return 0; |
8107 | ||
8108 | out_free: | |
31a60ed1 | 8109 | kfree(sched_scan_req); |
256da02d | 8110 | out_err: |
807f8a8c LC |
8111 | return err; |
8112 | } | |
8113 | ||
8114 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
8115 | struct genl_info *info) | |
8116 | { | |
ca986ad9 | 8117 | struct cfg80211_sched_scan_request *req; |
807f8a8c | 8118 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ca986ad9 | 8119 | u64 cookie; |
807f8a8c | 8120 | |
ca986ad9 | 8121 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) |
807f8a8c LC |
8122 | return -EOPNOTSUPP; |
8123 | ||
ca986ad9 AVS |
8124 | if (info->attrs[NL80211_ATTR_COOKIE]) { |
8125 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
8126 | return __cfg80211_stop_sched_scan(rdev, cookie, false); | |
8127 | } | |
8128 | ||
8129 | req = list_first_or_null_rcu(&rdev->sched_scan_req_list, | |
8130 | struct cfg80211_sched_scan_request, | |
8131 | list); | |
8132 | if (!req || req->reqid || | |
8133 | (req->owner_nlportid && | |
8134 | req->owner_nlportid != info->snd_portid)) | |
8135 | return -ENOENT; | |
8136 | ||
8137 | return cfg80211_stop_sched_scan_req(rdev, req, false); | |
807f8a8c LC |
8138 | } |
8139 | ||
04f39047 SW |
8140 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
8141 | struct genl_info *info) | |
8142 | { | |
8143 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8144 | struct net_device *dev = info->user_ptr[1]; | |
8145 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13cf6dec | 8146 | struct wiphy *wiphy = wdev->wiphy; |
04f39047 | 8147 | struct cfg80211_chan_def chandef; |
55f7435c | 8148 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 8149 | unsigned int cac_time_ms; |
04f39047 SW |
8150 | int err; |
8151 | ||
13cf6dec | 8152 | dfs_region = reg_get_dfs_region(wiphy); |
55f7435c LR |
8153 | if (dfs_region == NL80211_DFS_UNSET) |
8154 | return -EINVAL; | |
8155 | ||
04f39047 SW |
8156 | err = nl80211_parse_chandef(rdev, info, &chandef); |
8157 | if (err) | |
8158 | return err; | |
8159 | ||
ff311bc1 SW |
8160 | if (netif_carrier_ok(dev)) |
8161 | return -EBUSY; | |
8162 | ||
04f39047 SW |
8163 | if (wdev->cac_started) |
8164 | return -EBUSY; | |
8165 | ||
13cf6dec | 8166 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
04f39047 SW |
8167 | if (err < 0) |
8168 | return err; | |
8169 | ||
8170 | if (err == 0) | |
8171 | return -EINVAL; | |
8172 | ||
13cf6dec | 8173 | if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) |
04f39047 SW |
8174 | return -EINVAL; |
8175 | ||
13cf6dec DL |
8176 | /* CAC start is offloaded to HW and can't be started manually */ |
8177 | if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) | |
8178 | return -EOPNOTSUPP; | |
8179 | ||
04f39047 SW |
8180 | if (!rdev->ops->start_radar_detection) |
8181 | return -EOPNOTSUPP; | |
8182 | ||
31559f35 JD |
8183 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
8184 | if (WARN_ON(!cac_time_ms)) | |
8185 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
8186 | ||
a1056b1b | 8187 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
04f39047 | 8188 | if (!err) { |
9e0e2961 | 8189 | wdev->chandef = chandef; |
04f39047 SW |
8190 | wdev->cac_started = true; |
8191 | wdev->cac_start_time = jiffies; | |
31559f35 | 8192 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 8193 | } |
04f39047 SW |
8194 | return err; |
8195 | } | |
8196 | ||
30c63115 S |
8197 | static int nl80211_notify_radar_detection(struct sk_buff *skb, |
8198 | struct genl_info *info) | |
8199 | { | |
8200 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8201 | struct net_device *dev = info->user_ptr[1]; | |
8202 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8203 | struct wiphy *wiphy = wdev->wiphy; | |
8204 | struct cfg80211_chan_def chandef; | |
8205 | enum nl80211_dfs_regions dfs_region; | |
8206 | int err; | |
8207 | ||
8208 | dfs_region = reg_get_dfs_region(wiphy); | |
8209 | if (dfs_region == NL80211_DFS_UNSET) { | |
8210 | GENL_SET_ERR_MSG(info, | |
8211 | "DFS Region is not set. Unexpected Radar indication"); | |
8212 | return -EINVAL; | |
8213 | } | |
8214 | ||
8215 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
8216 | if (err) { | |
8217 | GENL_SET_ERR_MSG(info, "Unable to extract chandef info"); | |
8218 | return err; | |
8219 | } | |
8220 | ||
8221 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); | |
8222 | if (err < 0) { | |
8223 | GENL_SET_ERR_MSG(info, "chandef is invalid"); | |
8224 | return err; | |
8225 | } | |
8226 | ||
8227 | if (err == 0) { | |
8228 | GENL_SET_ERR_MSG(info, | |
8229 | "Unexpected Radar indication for chandef/iftype"); | |
8230 | return -EINVAL; | |
8231 | } | |
8232 | ||
8233 | /* Do not process this notification if radar is already detected | |
8234 | * by kernel on this channel, and return success. | |
8235 | */ | |
8236 | if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE) | |
8237 | return 0; | |
8238 | ||
8239 | cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE); | |
8240 | ||
8241 | cfg80211_sched_dfs_chan_update(rdev); | |
8242 | ||
a680fe46 | 8243 | rdev->radar_chandef = chandef; |
30c63115 S |
8244 | |
8245 | /* Propagate this notification to other radios as well */ | |
8246 | queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk); | |
8247 | ||
8248 | return 0; | |
8249 | } | |
8250 | ||
16ef1fe2 SW |
8251 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
8252 | { | |
8253 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8254 | struct net_device *dev = info->user_ptr[1]; | |
8255 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8256 | struct cfg80211_csa_settings params; | |
8257 | /* csa_attrs is defined static to avoid waste of stack size - this | |
8258 | * function is called under RTNL lock, so this should not be a problem. | |
8259 | */ | |
8260 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
16ef1fe2 | 8261 | int err; |
ee4bc9e7 | 8262 | bool need_new_beacon = false; |
8d9de16f | 8263 | bool need_handle_dfs_flag = true; |
9a774c78 | 8264 | int len, i; |
252e07ca | 8265 | u32 cs_count; |
16ef1fe2 SW |
8266 | |
8267 | if (!rdev->ops->channel_switch || | |
8268 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
8269 | return -EOPNOTSUPP; | |
8270 | ||
ee4bc9e7 SW |
8271 | switch (dev->ieee80211_ptr->iftype) { |
8272 | case NL80211_IFTYPE_AP: | |
8273 | case NL80211_IFTYPE_P2P_GO: | |
8274 | need_new_beacon = true; | |
8d9de16f BB |
8275 | /* For all modes except AP the handle_dfs flag needs to be |
8276 | * supplied to tell the kernel that userspace will handle radar | |
8277 | * events when they happen. Otherwise a switch to a channel | |
8278 | * requiring DFS will be rejected. | |
8279 | */ | |
8280 | need_handle_dfs_flag = false; | |
ee4bc9e7 SW |
8281 | |
8282 | /* useless if AP is not running */ | |
8283 | if (!wdev->beacon_interval) | |
1ff79dfa | 8284 | return -ENOTCONN; |
ee4bc9e7 SW |
8285 | break; |
8286 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
8287 | if (!wdev->ssid_len) |
8288 | return -ENOTCONN; | |
8289 | break; | |
c6da674a | 8290 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
8291 | if (!wdev->mesh_id_len) |
8292 | return -ENOTCONN; | |
ee4bc9e7 SW |
8293 | break; |
8294 | default: | |
16ef1fe2 | 8295 | return -EOPNOTSUPP; |
ee4bc9e7 | 8296 | } |
16ef1fe2 SW |
8297 | |
8298 | memset(¶ms, 0, sizeof(params)); | |
c177db2d | 8299 | params.beacon_csa.ftm_responder = -1; |
16ef1fe2 SW |
8300 | |
8301 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
8302 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
8303 | return -EINVAL; | |
8304 | ||
8305 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 8306 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
8307 | return -EINVAL; |
8308 | ||
252e07ca LC |
8309 | /* Even though the attribute is u32, the specification says |
8310 | * u8, so let's make sure we don't overflow. | |
8311 | */ | |
8312 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
8313 | if (cs_count > 255) | |
8314 | return -EINVAL; | |
8315 | ||
8316 | params.count = cs_count; | |
16ef1fe2 | 8317 | |
ee4bc9e7 SW |
8318 | if (!need_new_beacon) |
8319 | goto skip_beacons; | |
8320 | ||
81e54d08 | 8321 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after); |
16ef1fe2 SW |
8322 | if (err) |
8323 | return err; | |
8324 | ||
8cb08174 JB |
8325 | err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX, |
8326 | info->attrs[NL80211_ATTR_CSA_IES], | |
8327 | nl80211_policy, info->extack); | |
16ef1fe2 SW |
8328 | if (err) |
8329 | return err; | |
8330 | ||
81e54d08 | 8331 | err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa); |
16ef1fe2 SW |
8332 | if (err) |
8333 | return err; | |
8334 | ||
8335 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
8336 | return -EINVAL; | |
8337 | ||
9a774c78 AO |
8338 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
8339 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
8340 | return -EINVAL; |
8341 | ||
9a774c78 AO |
8342 | params.n_counter_offsets_beacon = len / sizeof(u16); |
8343 | if (rdev->wiphy.max_num_csa_counters && | |
8344 | (params.n_counter_offsets_beacon > | |
8345 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
8346 | return -EINVAL; |
8347 | ||
9a774c78 AO |
8348 | params.counter_offsets_beacon = |
8349 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
8350 | ||
8351 | /* sanity checks - counters should fit and be the same */ | |
8352 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
8353 | u16 offset = params.counter_offsets_beacon[i]; | |
8354 | ||
8355 | if (offset >= params.beacon_csa.tail_len) | |
8356 | return -EINVAL; | |
8357 | ||
8358 | if (params.beacon_csa.tail[offset] != params.count) | |
8359 | return -EINVAL; | |
8360 | } | |
8361 | ||
16ef1fe2 | 8362 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
8363 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
8364 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
8365 | return -EINVAL; |
8366 | ||
9a774c78 AO |
8367 | params.n_counter_offsets_presp = len / sizeof(u16); |
8368 | if (rdev->wiphy.max_num_csa_counters && | |
ad5987b4 | 8369 | (params.n_counter_offsets_presp > |
9a774c78 | 8370 | rdev->wiphy.max_num_csa_counters)) |
16ef1fe2 | 8371 | return -EINVAL; |
9a774c78 AO |
8372 | |
8373 | params.counter_offsets_presp = | |
8374 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
8375 | ||
8376 | /* sanity checks - counters should fit and be the same */ | |
8377 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
8378 | u16 offset = params.counter_offsets_presp[i]; | |
8379 | ||
8380 | if (offset >= params.beacon_csa.probe_resp_len) | |
8381 | return -EINVAL; | |
8382 | ||
8383 | if (params.beacon_csa.probe_resp[offset] != | |
8384 | params.count) | |
8385 | return -EINVAL; | |
8386 | } | |
16ef1fe2 SW |
8387 | } |
8388 | ||
ee4bc9e7 | 8389 | skip_beacons: |
16ef1fe2 SW |
8390 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
8391 | if (err) | |
8392 | return err; | |
8393 | ||
923b352f AN |
8394 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
8395 | wdev->iftype)) | |
16ef1fe2 SW |
8396 | return -EINVAL; |
8397 | ||
2beb6dab LC |
8398 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
8399 | ¶ms.chandef, | |
8400 | wdev->iftype); | |
8401 | if (err < 0) | |
8402 | return err; | |
8403 | ||
8d9de16f | 8404 | if (err > 0) { |
2beb6dab | 8405 | params.radar_required = true; |
8d9de16f BB |
8406 | if (need_handle_dfs_flag && |
8407 | !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { | |
8408 | return -EINVAL; | |
8409 | } | |
8410 | } | |
16ef1fe2 | 8411 | |
16ef1fe2 SW |
8412 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
8413 | params.block_tx = true; | |
8414 | ||
c56589ed SW |
8415 | wdev_lock(wdev); |
8416 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
8417 | wdev_unlock(wdev); | |
8418 | ||
8419 | return err; | |
16ef1fe2 SW |
8420 | } |
8421 | ||
9720bb3a JB |
8422 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
8423 | u32 seq, int flags, | |
2a519311 | 8424 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
8425 | struct wireless_dev *wdev, |
8426 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 8427 | { |
48ab905d | 8428 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 8429 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
8430 | void *hdr; |
8431 | struct nlattr *bss; | |
48ab905d JB |
8432 | |
8433 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 8434 | |
15e47304 | 8435 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
8436 | NL80211_CMD_NEW_SCAN_RESULTS); |
8437 | if (!hdr) | |
8438 | return -1; | |
8439 | ||
0a833c29 | 8440 | genl_dump_check_consistent(cb, hdr); |
9720bb3a | 8441 | |
97990a06 JB |
8442 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
8443 | goto nla_put_failure; | |
8444 | if (wdev->netdev && | |
9360ffd1 DM |
8445 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
8446 | goto nla_put_failure; | |
2dad624e ND |
8447 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
8448 | NL80211_ATTR_PAD)) | |
97990a06 | 8449 | goto nla_put_failure; |
2a519311 | 8450 | |
ae0be8de | 8451 | bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS); |
2a519311 JB |
8452 | if (!bss) |
8453 | goto nla_put_failure; | |
9360ffd1 | 8454 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 8455 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 8456 | goto nla_put_failure; |
9caf0364 JB |
8457 | |
8458 | rcu_read_lock(); | |
0e227084 JB |
8459 | /* indicate whether we have probe response data or not */ |
8460 | if (rcu_access_pointer(res->proberesp_ies) && | |
8461 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
8462 | goto fail_unlock_rcu; | |
8463 | ||
8464 | /* this pointer prefers to be pointed to probe response data | |
8465 | * but is always valid | |
8466 | */ | |
9caf0364 | 8467 | ies = rcu_dereference(res->ies); |
8cef2c9d | 8468 | if (ies) { |
2dad624e ND |
8469 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
8470 | NL80211_BSS_PAD)) | |
8cef2c9d | 8471 | goto fail_unlock_rcu; |
8cef2c9d JB |
8472 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
8473 | ies->len, ies->data)) | |
8474 | goto fail_unlock_rcu; | |
9caf0364 | 8475 | } |
0e227084 JB |
8476 | |
8477 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 8478 | ies = rcu_dereference(res->beacon_ies); |
0e227084 | 8479 | if (ies && ies->from_beacon) { |
2dad624e ND |
8480 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
8481 | NL80211_BSS_PAD)) | |
8cef2c9d JB |
8482 | goto fail_unlock_rcu; |
8483 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
8484 | ies->len, ies->data)) | |
8485 | goto fail_unlock_rcu; | |
9caf0364 JB |
8486 | } |
8487 | rcu_read_unlock(); | |
8488 | ||
9360ffd1 DM |
8489 | if (res->beacon_interval && |
8490 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
8491 | goto nla_put_failure; | |
8492 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
8493 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 8494 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
8495 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
8496 | jiffies_to_msecs(jiffies - intbss->ts))) | |
8497 | goto nla_put_failure; | |
2a519311 | 8498 | |
1d76250b AS |
8499 | if (intbss->parent_tsf && |
8500 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, | |
8501 | intbss->parent_tsf, NL80211_BSS_PAD) || | |
8502 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, | |
8503 | intbss->parent_bssid))) | |
8504 | goto nla_put_failure; | |
8505 | ||
6e19bc4b | 8506 | if (intbss->ts_boottime && |
2dad624e ND |
8507 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
8508 | intbss->ts_boottime, NL80211_BSS_PAD)) | |
6e19bc4b DS |
8509 | goto nla_put_failure; |
8510 | ||
983dafaa SD |
8511 | if (!nl80211_put_signal(msg, intbss->pub.chains, |
8512 | intbss->pub.chain_signal, | |
8513 | NL80211_BSS_CHAIN_SIGNAL)) | |
8514 | goto nla_put_failure; | |
8515 | ||
77965c97 | 8516 | switch (rdev->wiphy.signal_type) { |
2a519311 | 8517 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
8518 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
8519 | goto nla_put_failure; | |
2a519311 JB |
8520 | break; |
8521 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
8522 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
8523 | goto nla_put_failure; | |
2a519311 JB |
8524 | break; |
8525 | default: | |
8526 | break; | |
8527 | } | |
8528 | ||
48ab905d | 8529 | switch (wdev->iftype) { |
074ac8df | 8530 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 8531 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
8532 | if (intbss == wdev->current_bss && |
8533 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
8534 | NL80211_BSS_STATUS_ASSOCIATED)) | |
8535 | goto nla_put_failure; | |
48ab905d JB |
8536 | break; |
8537 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
8538 | if (intbss == wdev->current_bss && |
8539 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
8540 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
8541 | goto nla_put_failure; | |
48ab905d JB |
8542 | break; |
8543 | default: | |
8544 | break; | |
8545 | } | |
8546 | ||
2a519311 JB |
8547 | nla_nest_end(msg, bss); |
8548 | ||
053c095a JB |
8549 | genlmsg_end(msg, hdr); |
8550 | return 0; | |
2a519311 | 8551 | |
8cef2c9d JB |
8552 | fail_unlock_rcu: |
8553 | rcu_read_unlock(); | |
2a519311 JB |
8554 | nla_put_failure: |
8555 | genlmsg_cancel(msg, hdr); | |
8556 | return -EMSGSIZE; | |
8557 | } | |
8558 | ||
97990a06 | 8559 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 8560 | { |
48ab905d | 8561 | struct cfg80211_registered_device *rdev; |
2a519311 | 8562 | struct cfg80211_internal_bss *scan; |
48ab905d | 8563 | struct wireless_dev *wdev; |
97990a06 | 8564 | int start = cb->args[2], idx = 0; |
2a519311 JB |
8565 | int err; |
8566 | ||
ea90e0dc | 8567 | rtnl_lock(); |
5297c65c | 8568 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
ea90e0dc JB |
8569 | if (err) { |
8570 | rtnl_unlock(); | |
67748893 | 8571 | return err; |
ea90e0dc | 8572 | } |
2a519311 | 8573 | |
48ab905d JB |
8574 | wdev_lock(wdev); |
8575 | spin_lock_bh(&rdev->bss_lock); | |
d1e23c94 DK |
8576 | |
8577 | /* | |
8578 | * dump_scan will be called multiple times to break up the scan results | |
8579 | * into multiple messages. It is unlikely that any more bss-es will be | |
8580 | * expired after the first call, so only call only call this on the | |
8581 | * first dump_scan invocation. | |
8582 | */ | |
8583 | if (start == 0) | |
8584 | cfg80211_bss_expire(rdev); | |
48ab905d | 8585 | |
9720bb3a JB |
8586 | cb->seq = rdev->bss_generation; |
8587 | ||
48ab905d | 8588 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
8589 | if (++idx <= start) |
8590 | continue; | |
9720bb3a | 8591 | if (nl80211_send_bss(skb, cb, |
2a519311 | 8592 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 8593 | rdev, wdev, scan) < 0) { |
2a519311 | 8594 | idx--; |
67748893 | 8595 | break; |
2a519311 JB |
8596 | } |
8597 | } | |
8598 | ||
48ab905d JB |
8599 | spin_unlock_bh(&rdev->bss_lock); |
8600 | wdev_unlock(wdev); | |
2a519311 | 8601 | |
97990a06 | 8602 | cb->args[2] = idx; |
ea90e0dc | 8603 | rtnl_unlock(); |
2a519311 | 8604 | |
67748893 | 8605 | return skb->len; |
2a519311 JB |
8606 | } |
8607 | ||
15e47304 | 8608 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
11f78ac3 JB |
8609 | int flags, struct net_device *dev, |
8610 | bool allow_radio_stats, | |
8611 | struct survey_info *survey) | |
61fa713c HS |
8612 | { |
8613 | void *hdr; | |
8614 | struct nlattr *infoattr; | |
8615 | ||
11f78ac3 JB |
8616 | /* skip radio stats if userspace didn't request them */ |
8617 | if (!survey->channel && !allow_radio_stats) | |
8618 | return 0; | |
8619 | ||
15e47304 | 8620 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
8621 | NL80211_CMD_NEW_SURVEY_RESULTS); |
8622 | if (!hdr) | |
8623 | return -ENOMEM; | |
8624 | ||
9360ffd1 DM |
8625 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
8626 | goto nla_put_failure; | |
61fa713c | 8627 | |
ae0be8de | 8628 | infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO); |
61fa713c HS |
8629 | if (!infoattr) |
8630 | goto nla_put_failure; | |
8631 | ||
11f78ac3 JB |
8632 | if (survey->channel && |
8633 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
9360ffd1 DM |
8634 | survey->channel->center_freq)) |
8635 | goto nla_put_failure; | |
8636 | ||
8637 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
8638 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
8639 | goto nla_put_failure; | |
8640 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
8641 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
8642 | goto nla_put_failure; | |
4ed20beb | 8643 | if ((survey->filled & SURVEY_INFO_TIME) && |
2dad624e ND |
8644 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
8645 | survey->time, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 8646 | goto nla_put_failure; |
4ed20beb | 8647 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
2dad624e ND |
8648 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
8649 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 8650 | goto nla_put_failure; |
4ed20beb | 8651 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
2dad624e ND |
8652 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
8653 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 8654 | goto nla_put_failure; |
4ed20beb | 8655 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
2dad624e ND |
8656 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
8657 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 8658 | goto nla_put_failure; |
4ed20beb | 8659 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
2dad624e ND |
8660 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
8661 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 8662 | goto nla_put_failure; |
052536ab | 8663 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
2dad624e ND |
8664 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
8665 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) | |
052536ab | 8666 | goto nla_put_failure; |
61fa713c HS |
8667 | |
8668 | nla_nest_end(msg, infoattr); | |
8669 | ||
053c095a JB |
8670 | genlmsg_end(msg, hdr); |
8671 | return 0; | |
61fa713c HS |
8672 | |
8673 | nla_put_failure: | |
8674 | genlmsg_cancel(msg, hdr); | |
8675 | return -EMSGSIZE; | |
8676 | } | |
8677 | ||
11f78ac3 | 8678 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
61fa713c | 8679 | { |
c90c39da | 8680 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
61fa713c | 8681 | struct survey_info survey; |
1b8ec87a | 8682 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
8683 | struct wireless_dev *wdev; |
8684 | int survey_idx = cb->args[2]; | |
61fa713c | 8685 | int res; |
11f78ac3 | 8686 | bool radio_stats; |
61fa713c | 8687 | |
ea90e0dc | 8688 | rtnl_lock(); |
5297c65c | 8689 | res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
67748893 | 8690 | if (res) |
ea90e0dc | 8691 | goto out_err; |
61fa713c | 8692 | |
11f78ac3 | 8693 | /* prepare_wdev_dump parsed the attributes */ |
c90c39da | 8694 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
11f78ac3 | 8695 | |
97990a06 JB |
8696 | if (!wdev->netdev) { |
8697 | res = -EINVAL; | |
8698 | goto out_err; | |
8699 | } | |
8700 | ||
1b8ec87a | 8701 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
8702 | res = -EOPNOTSUPP; |
8703 | goto out_err; | |
8704 | } | |
8705 | ||
8706 | while (1) { | |
1b8ec87a | 8707 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
8708 | if (res == -ENOENT) |
8709 | break; | |
8710 | if (res) | |
8711 | goto out_err; | |
8712 | ||
11f78ac3 JB |
8713 | /* don't send disabled channels, but do send non-channel data */ |
8714 | if (survey.channel && | |
8715 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { | |
180cdc79 LR |
8716 | survey_idx++; |
8717 | continue; | |
8718 | } | |
8719 | ||
61fa713c | 8720 | if (nl80211_send_survey(skb, |
15e47304 | 8721 | NETLINK_CB(cb->skb).portid, |
61fa713c | 8722 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
11f78ac3 | 8723 | wdev->netdev, radio_stats, &survey) < 0) |
61fa713c HS |
8724 | goto out; |
8725 | survey_idx++; | |
8726 | } | |
8727 | ||
8728 | out: | |
97990a06 | 8729 | cb->args[2] = survey_idx; |
61fa713c HS |
8730 | res = skb->len; |
8731 | out_err: | |
ea90e0dc | 8732 | rtnl_unlock(); |
61fa713c HS |
8733 | return res; |
8734 | } | |
8735 | ||
b23aa676 SO |
8736 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
8737 | { | |
8738 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
8739 | NL80211_WPA_VERSION_2)); | |
8740 | } | |
8741 | ||
636a5d36 JM |
8742 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
8743 | { | |
4c476991 JB |
8744 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8745 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 8746 | struct ieee80211_channel *chan; |
11b6b5a4 JM |
8747 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; |
8748 | int err, ssid_len, ie_len = 0, auth_data_len = 0; | |
19957bb3 | 8749 | enum nl80211_auth_type auth_type; |
fffd0934 | 8750 | struct key_parse key; |
d5cdfacb | 8751 | bool local_state_change; |
636a5d36 | 8752 | |
f4a11bb0 JB |
8753 | if (!info->attrs[NL80211_ATTR_MAC]) |
8754 | return -EINVAL; | |
8755 | ||
1778092e JM |
8756 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
8757 | return -EINVAL; | |
8758 | ||
19957bb3 JB |
8759 | if (!info->attrs[NL80211_ATTR_SSID]) |
8760 | return -EINVAL; | |
8761 | ||
8762 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
8763 | return -EINVAL; | |
8764 | ||
fffd0934 JB |
8765 | err = nl80211_parse_key(info, &key); |
8766 | if (err) | |
8767 | return err; | |
8768 | ||
8769 | if (key.idx >= 0) { | |
e31b8213 JB |
8770 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
8771 | return -EINVAL; | |
fffd0934 JB |
8772 | if (!key.p.key || !key.p.key_len) |
8773 | return -EINVAL; | |
8774 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
8775 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
8776 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
8777 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
8778 | return -EINVAL; | |
b6b5555b | 8779 | if (key.idx > 3) |
fffd0934 JB |
8780 | return -EINVAL; |
8781 | } else { | |
8782 | key.p.key_len = 0; | |
8783 | key.p.key = NULL; | |
8784 | } | |
8785 | ||
afea0b7a JB |
8786 | if (key.idx >= 0) { |
8787 | int i; | |
8788 | bool ok = false; | |
7a087e74 | 8789 | |
afea0b7a JB |
8790 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
8791 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
8792 | ok = true; | |
8793 | break; | |
8794 | } | |
8795 | } | |
4c476991 JB |
8796 | if (!ok) |
8797 | return -EINVAL; | |
afea0b7a JB |
8798 | } |
8799 | ||
4c476991 JB |
8800 | if (!rdev->ops->auth) |
8801 | return -EOPNOTSUPP; | |
636a5d36 | 8802 | |
074ac8df | 8803 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8804 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8805 | return -EOPNOTSUPP; | |
eec60b03 | 8806 | |
19957bb3 | 8807 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
8808 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
8809 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
8810 | if (!chan) | |
4c476991 | 8811 | return -EINVAL; |
636a5d36 | 8812 | |
19957bb3 JB |
8813 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
8814 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
8815 | |
8816 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
8817 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
8818 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
8819 | } |
8820 | ||
19957bb3 | 8821 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 8822 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 8823 | return -EINVAL; |
636a5d36 | 8824 | |
63181060 JM |
8825 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
8826 | auth_type == NL80211_AUTHTYPE_FILS_SK || | |
8827 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || | |
8828 | auth_type == NL80211_AUTHTYPE_FILS_PK) && | |
11b6b5a4 | 8829 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
e39e5b5e JM |
8830 | return -EINVAL; |
8831 | ||
11b6b5a4 | 8832 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
63181060 JM |
8833 | if (auth_type != NL80211_AUTHTYPE_SAE && |
8834 | auth_type != NL80211_AUTHTYPE_FILS_SK && | |
8835 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && | |
8836 | auth_type != NL80211_AUTHTYPE_FILS_PK) | |
e39e5b5e | 8837 | return -EINVAL; |
11b6b5a4 JM |
8838 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
8839 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); | |
e39e5b5e | 8840 | /* need to include at least Auth Transaction and Status Code */ |
11b6b5a4 | 8841 | if (auth_data_len < 4) |
e39e5b5e JM |
8842 | return -EINVAL; |
8843 | } | |
8844 | ||
d5cdfacb JM |
8845 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
8846 | ||
95de817b JB |
8847 | /* |
8848 | * Since we no longer track auth state, ignore | |
8849 | * requests to only change local state. | |
8850 | */ | |
8851 | if (local_state_change) | |
8852 | return 0; | |
8853 | ||
91bf9b26 JB |
8854 | wdev_lock(dev->ieee80211_ptr); |
8855 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
8856 | ssid, ssid_len, ie, ie_len, | |
8857 | key.p.key, key.p.key_len, key.idx, | |
11b6b5a4 | 8858 | auth_data, auth_data_len); |
91bf9b26 JB |
8859 | wdev_unlock(dev->ieee80211_ptr); |
8860 | return err; | |
636a5d36 JM |
8861 | } |
8862 | ||
64bf3d4b DK |
8863 | static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, |
8864 | struct genl_info *info) | |
8865 | { | |
8866 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { | |
8867 | GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); | |
8868 | return -EINVAL; | |
8869 | } | |
8870 | ||
8871 | if (!rdev->ops->tx_control_port || | |
8872 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
8873 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) | |
8874 | return -EOPNOTSUPP; | |
8875 | ||
8876 | return 0; | |
8877 | } | |
8878 | ||
c0692b8f JB |
8879 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
8880 | struct genl_info *info, | |
3dc27d25 JB |
8881 | struct cfg80211_crypto_settings *settings, |
8882 | int cipher_limit) | |
b23aa676 | 8883 | { |
c0b2bbd8 JB |
8884 | memset(settings, 0, sizeof(*settings)); |
8885 | ||
b23aa676 SO |
8886 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
8887 | ||
c0692b8f JB |
8888 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
8889 | u16 proto; | |
7a087e74 | 8890 | |
c0692b8f JB |
8891 | proto = nla_get_u16( |
8892 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
8893 | settings->control_port_ethertype = cpu_to_be16(proto); | |
8894 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
8895 | proto != ETH_P_PAE) | |
8896 | return -EINVAL; | |
8897 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
8898 | settings->control_port_no_encrypt = true; | |
8899 | } else | |
8900 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
8901 | ||
64bf3d4b DK |
8902 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
8903 | int r = validate_pae_over_nl80211(rdev, info); | |
8904 | ||
8905 | if (r < 0) | |
8906 | return r; | |
8907 | ||
8908 | settings->control_port_over_nl80211 = true; | |
8909 | } | |
8910 | ||
b23aa676 SO |
8911 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
8912 | void *data; | |
8913 | int len, i; | |
8914 | ||
8915 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
8916 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
8917 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
8918 | ||
8919 | if (len % sizeof(u32)) | |
8920 | return -EINVAL; | |
8921 | ||
3dc27d25 | 8922 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
8923 | return -EINVAL; |
8924 | ||
8925 | memcpy(settings->ciphers_pairwise, data, len); | |
8926 | ||
8927 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
8928 | if (!cfg80211_supported_cipher_suite( |
8929 | &rdev->wiphy, | |
b23aa676 SO |
8930 | settings->ciphers_pairwise[i])) |
8931 | return -EINVAL; | |
8932 | } | |
8933 | ||
8934 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
8935 | settings->cipher_group = | |
8936 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
8937 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
8938 | settings->cipher_group)) | |
b23aa676 SO |
8939 | return -EINVAL; |
8940 | } | |
8941 | ||
8942 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
8943 | settings->wpa_versions = | |
8944 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
8945 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
8946 | return -EINVAL; | |
8947 | } | |
8948 | ||
8949 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
8950 | void *data; | |
6d30240e | 8951 | int len; |
b23aa676 SO |
8952 | |
8953 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
8954 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
8955 | settings->n_akm_suites = len / sizeof(u32); | |
8956 | ||
8957 | if (len % sizeof(u32)) | |
8958 | return -EINVAL; | |
8959 | ||
1b9ca027 JM |
8960 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
8961 | return -EINVAL; | |
8962 | ||
b23aa676 | 8963 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
8964 | } |
8965 | ||
91b5ab62 EP |
8966 | if (info->attrs[NL80211_ATTR_PMK]) { |
8967 | if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) | |
8968 | return -EINVAL; | |
8969 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
8970 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK)) | |
8971 | return -EINVAL; | |
8972 | settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); | |
8973 | } | |
8974 | ||
b23aa676 SO |
8975 | return 0; |
8976 | } | |
8977 | ||
636a5d36 JM |
8978 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
8979 | { | |
4c476991 JB |
8980 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8981 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 8982 | struct ieee80211_channel *chan; |
f62fab73 JB |
8983 | struct cfg80211_assoc_request req = {}; |
8984 | const u8 *bssid, *ssid; | |
8985 | int err, ssid_len = 0; | |
636a5d36 | 8986 | |
bad29297 AZ |
8987 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
8988 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) | |
8989 | return -EPERM; | |
8990 | ||
f4a11bb0 | 8991 | if (!info->attrs[NL80211_ATTR_MAC] || |
19957bb3 JB |
8992 | !info->attrs[NL80211_ATTR_SSID] || |
8993 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
8994 | return -EINVAL; |
8995 | ||
4c476991 JB |
8996 | if (!rdev->ops->assoc) |
8997 | return -EOPNOTSUPP; | |
636a5d36 | 8998 | |
074ac8df | 8999 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
9000 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
9001 | return -EOPNOTSUPP; | |
eec60b03 | 9002 | |
19957bb3 | 9003 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 9004 | |
664834de JM |
9005 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
9006 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
9007 | if (!chan) | |
4c476991 | 9008 | return -EINVAL; |
636a5d36 | 9009 | |
19957bb3 JB |
9010 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
9011 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
9012 | |
9013 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
9014 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
9015 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
9016 | } |
9017 | ||
dc6382ce | 9018 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 9019 | enum nl80211_mfp mfp = |
dc6382ce | 9020 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 9021 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 9022 | req.use_mfp = true; |
4c476991 JB |
9023 | else if (mfp != NL80211_MFP_NO) |
9024 | return -EINVAL; | |
dc6382ce JM |
9025 | } |
9026 | ||
3e5d7649 | 9027 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 9028 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 9029 | |
7e7c8926 | 9030 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 9031 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
9032 | |
9033 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
9034 | memcpy(&req.ht_capa_mask, |
9035 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
9036 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
9037 | |
9038 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 9039 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 9040 | return -EINVAL; |
f62fab73 JB |
9041 | memcpy(&req.ht_capa, |
9042 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
9043 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
9044 | } |
9045 | ||
ee2aca34 | 9046 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 9047 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
9048 | |
9049 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
9050 | memcpy(&req.vht_capa_mask, |
9051 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
9052 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
9053 | |
9054 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 9055 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 9056 | return -EINVAL; |
f62fab73 JB |
9057 | memcpy(&req.vht_capa, |
9058 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
9059 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
9060 | } |
9061 | ||
bab5ab7d | 9062 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
0c9ca11b BL |
9063 | if (!((rdev->wiphy.features & |
9064 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && | |
9065 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && | |
9066 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
9067 | NL80211_EXT_FEATURE_RRM)) | |
bab5ab7d AK |
9068 | return -EINVAL; |
9069 | req.flags |= ASSOC_REQ_USE_RRM; | |
9070 | } | |
9071 | ||
348bd456 JM |
9072 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
9073 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); | |
9074 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); | |
9075 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) | |
9076 | return -EINVAL; | |
9077 | req.fils_nonces = | |
9078 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); | |
9079 | } | |
9080 | ||
f62fab73 | 9081 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
9082 | if (!err) { |
9083 | wdev_lock(dev->ieee80211_ptr); | |
bd2522b1 | 9084 | |
f62fab73 JB |
9085 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
9086 | ssid, ssid_len, &req); | |
bd2522b1 AZ |
9087 | |
9088 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { | |
9089 | dev->ieee80211_ptr->conn_owner_nlportid = | |
9090 | info->snd_portid; | |
9091 | memcpy(dev->ieee80211_ptr->disconnect_bssid, | |
9092 | bssid, ETH_ALEN); | |
9093 | } | |
9094 | ||
91bf9b26 JB |
9095 | wdev_unlock(dev->ieee80211_ptr); |
9096 | } | |
636a5d36 | 9097 | |
636a5d36 JM |
9098 | return err; |
9099 | } | |
9100 | ||
9101 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
9102 | { | |
4c476991 JB |
9103 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
9104 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 9105 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 9106 | int ie_len = 0, err; |
19957bb3 | 9107 | u16 reason_code; |
d5cdfacb | 9108 | bool local_state_change; |
636a5d36 | 9109 | |
bad29297 AZ |
9110 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
9111 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) | |
9112 | return -EPERM; | |
9113 | ||
f4a11bb0 JB |
9114 | if (!info->attrs[NL80211_ATTR_MAC]) |
9115 | return -EINVAL; | |
9116 | ||
9117 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
9118 | return -EINVAL; | |
9119 | ||
4c476991 JB |
9120 | if (!rdev->ops->deauth) |
9121 | return -EOPNOTSUPP; | |
636a5d36 | 9122 | |
074ac8df | 9123 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
9124 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
9125 | return -EOPNOTSUPP; | |
eec60b03 | 9126 | |
19957bb3 | 9127 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 9128 | |
19957bb3 JB |
9129 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
9130 | if (reason_code == 0) { | |
f4a11bb0 | 9131 | /* Reason Code 0 is reserved */ |
4c476991 | 9132 | return -EINVAL; |
255e737e | 9133 | } |
636a5d36 JM |
9134 | |
9135 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
9136 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
9137 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
9138 | } |
9139 | ||
d5cdfacb JM |
9140 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
9141 | ||
91bf9b26 JB |
9142 | wdev_lock(dev->ieee80211_ptr); |
9143 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
9144 | local_state_change); | |
9145 | wdev_unlock(dev->ieee80211_ptr); | |
9146 | return err; | |
636a5d36 JM |
9147 | } |
9148 | ||
9149 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
9150 | { | |
4c476991 JB |
9151 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
9152 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 9153 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 9154 | int ie_len = 0, err; |
19957bb3 | 9155 | u16 reason_code; |
d5cdfacb | 9156 | bool local_state_change; |
636a5d36 | 9157 | |
bad29297 AZ |
9158 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
9159 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) | |
9160 | return -EPERM; | |
9161 | ||
f4a11bb0 JB |
9162 | if (!info->attrs[NL80211_ATTR_MAC]) |
9163 | return -EINVAL; | |
9164 | ||
9165 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
9166 | return -EINVAL; | |
9167 | ||
4c476991 JB |
9168 | if (!rdev->ops->disassoc) |
9169 | return -EOPNOTSUPP; | |
636a5d36 | 9170 | |
074ac8df | 9171 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
9172 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
9173 | return -EOPNOTSUPP; | |
eec60b03 | 9174 | |
19957bb3 | 9175 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 9176 | |
19957bb3 JB |
9177 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
9178 | if (reason_code == 0) { | |
f4a11bb0 | 9179 | /* Reason Code 0 is reserved */ |
4c476991 | 9180 | return -EINVAL; |
255e737e | 9181 | } |
636a5d36 JM |
9182 | |
9183 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
9184 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
9185 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
9186 | } |
9187 | ||
d5cdfacb JM |
9188 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
9189 | ||
91bf9b26 JB |
9190 | wdev_lock(dev->ieee80211_ptr); |
9191 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
9192 | local_state_change); | |
9193 | wdev_unlock(dev->ieee80211_ptr); | |
9194 | return err; | |
636a5d36 JM |
9195 | } |
9196 | ||
dd5b4cc7 FF |
9197 | static bool |
9198 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
57fbcce3 | 9199 | int mcast_rate[NUM_NL80211_BANDS], |
dd5b4cc7 FF |
9200 | int rateval) |
9201 | { | |
9202 | struct wiphy *wiphy = &rdev->wiphy; | |
9203 | bool found = false; | |
9204 | int band, i; | |
9205 | ||
57fbcce3 | 9206 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
dd5b4cc7 FF |
9207 | struct ieee80211_supported_band *sband; |
9208 | ||
9209 | sband = wiphy->bands[band]; | |
9210 | if (!sband) | |
9211 | continue; | |
9212 | ||
9213 | for (i = 0; i < sband->n_bitrates; i++) { | |
9214 | if (sband->bitrates[i].bitrate == rateval) { | |
9215 | mcast_rate[band] = i + 1; | |
9216 | found = true; | |
9217 | break; | |
9218 | } | |
9219 | } | |
9220 | } | |
9221 | ||
9222 | return found; | |
9223 | } | |
9224 | ||
04a773ad JB |
9225 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
9226 | { | |
4c476991 JB |
9227 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
9228 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
9229 | struct cfg80211_ibss_params ibss; |
9230 | struct wiphy *wiphy; | |
fffd0934 | 9231 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
9232 | int err; |
9233 | ||
8e30bc55 JB |
9234 | memset(&ibss, 0, sizeof(ibss)); |
9235 | ||
683b6d3b | 9236 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
9237 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
9238 | return -EINVAL; | |
9239 | ||
8e30bc55 JB |
9240 | ibss.beacon_interval = 100; |
9241 | ||
12d20fc9 | 9242 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
8e30bc55 JB |
9243 | ibss.beacon_interval = |
9244 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
12d20fc9 | 9245 | |
0c317a02 PK |
9246 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
9247 | ibss.beacon_interval); | |
12d20fc9 PK |
9248 | if (err) |
9249 | return err; | |
8e30bc55 | 9250 | |
4c476991 JB |
9251 | if (!rdev->ops->join_ibss) |
9252 | return -EOPNOTSUPP; | |
04a773ad | 9253 | |
4c476991 JB |
9254 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
9255 | return -EOPNOTSUPP; | |
04a773ad | 9256 | |
79c97e97 | 9257 | wiphy = &rdev->wiphy; |
04a773ad | 9258 | |
39193498 | 9259 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 9260 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
9261 | |
9262 | if (!is_valid_ether_addr(ibss.bssid)) | |
9263 | return -EINVAL; | |
9264 | } | |
04a773ad JB |
9265 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
9266 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
9267 | ||
9268 | if (info->attrs[NL80211_ATTR_IE]) { | |
9269 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9270 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9271 | } | |
9272 | ||
683b6d3b JB |
9273 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
9274 | if (err) | |
9275 | return err; | |
04a773ad | 9276 | |
174e0cd2 IP |
9277 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
9278 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
9279 | return -EINVAL; |
9280 | ||
2f301ab2 | 9281 | switch (ibss.chandef.width) { |
bf372645 SW |
9282 | case NL80211_CHAN_WIDTH_5: |
9283 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
9284 | case NL80211_CHAN_WIDTH_20_NOHT: |
9285 | break; | |
9286 | case NL80211_CHAN_WIDTH_20: | |
9287 | case NL80211_CHAN_WIDTH_40: | |
ffc11991 JD |
9288 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
9289 | return -EINVAL; | |
9290 | break; | |
9291 | case NL80211_CHAN_WIDTH_80: | |
9292 | case NL80211_CHAN_WIDTH_80P80: | |
9293 | case NL80211_CHAN_WIDTH_160: | |
9294 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | |
9295 | return -EINVAL; | |
9296 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
9297 | NL80211_EXT_FEATURE_VHT_IBSS)) | |
9298 | return -EINVAL; | |
9299 | break; | |
2f301ab2 | 9300 | default: |
c04d6150 | 9301 | return -EINVAL; |
2f301ab2 | 9302 | } |
db9c64cf | 9303 | |
04a773ad | 9304 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
9305 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
9306 | ||
fbd2c8dc TP |
9307 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
9308 | u8 *rates = | |
9309 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
9310 | int n_rates = | |
9311 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
9312 | struct ieee80211_supported_band *sband = | |
683b6d3b | 9313 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 9314 | |
34850ab2 JB |
9315 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
9316 | &ibss.basic_rates); | |
9317 | if (err) | |
9318 | return err; | |
fbd2c8dc | 9319 | } |
dd5b4cc7 | 9320 | |
803768f5 SW |
9321 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
9322 | memcpy(&ibss.ht_capa_mask, | |
9323 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
9324 | sizeof(ibss.ht_capa_mask)); | |
9325 | ||
9326 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
9327 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
9328 | return -EINVAL; | |
9329 | memcpy(&ibss.ht_capa, | |
9330 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
9331 | sizeof(ibss.ht_capa)); | |
9332 | } | |
9333 | ||
dd5b4cc7 FF |
9334 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
9335 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
9336 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
9337 | return -EINVAL; | |
fbd2c8dc | 9338 | |
4c476991 | 9339 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
9340 | bool no_ht = false; |
9341 | ||
768075eb | 9342 | connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); |
4c476991 JB |
9343 | if (IS_ERR(connkeys)) |
9344 | return PTR_ERR(connkeys); | |
de7044ee | 9345 | |
3d9d1d66 JB |
9346 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
9347 | no_ht) { | |
5e950a78 | 9348 | kzfree(connkeys); |
de7044ee SM |
9349 | return -EINVAL; |
9350 | } | |
4c476991 | 9351 | } |
04a773ad | 9352 | |
267335d6 AQ |
9353 | ibss.control_port = |
9354 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
9355 | ||
c3bfe1f6 DK |
9356 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
9357 | int r = validate_pae_over_nl80211(rdev, info); | |
9358 | ||
d350a0f4 JB |
9359 | if (r < 0) { |
9360 | kzfree(connkeys); | |
c3bfe1f6 | 9361 | return r; |
d350a0f4 | 9362 | } |
c3bfe1f6 DK |
9363 | |
9364 | ibss.control_port_over_nl80211 = true; | |
9365 | } | |
9366 | ||
5336fa88 SW |
9367 | ibss.userspace_handles_dfs = |
9368 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
9369 | ||
f8d16d3e DK |
9370 | wdev_lock(dev->ieee80211_ptr); |
9371 | err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); | |
fffd0934 | 9372 | if (err) |
b47f610b | 9373 | kzfree(connkeys); |
f8d16d3e DK |
9374 | else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
9375 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; | |
9376 | wdev_unlock(dev->ieee80211_ptr); | |
9377 | ||
04a773ad JB |
9378 | return err; |
9379 | } | |
9380 | ||
9381 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
9382 | { | |
4c476991 JB |
9383 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
9384 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 9385 | |
4c476991 JB |
9386 | if (!rdev->ops->leave_ibss) |
9387 | return -EOPNOTSUPP; | |
04a773ad | 9388 | |
4c476991 JB |
9389 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
9390 | return -EOPNOTSUPP; | |
04a773ad | 9391 | |
4c476991 | 9392 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
9393 | } |
9394 | ||
f4e583c8 AQ |
9395 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
9396 | { | |
9397 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9398 | struct net_device *dev = info->user_ptr[1]; | |
57fbcce3 | 9399 | int mcast_rate[NUM_NL80211_BANDS]; |
f4e583c8 AQ |
9400 | u32 nla_rate; |
9401 | int err; | |
9402 | ||
9403 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
876dc930 BVB |
9404 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
9405 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) | |
f4e583c8 AQ |
9406 | return -EOPNOTSUPP; |
9407 | ||
9408 | if (!rdev->ops->set_mcast_rate) | |
9409 | return -EOPNOTSUPP; | |
9410 | ||
9411 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
9412 | ||
9413 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
9414 | return -EINVAL; | |
9415 | ||
9416 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
9417 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
9418 | return -EINVAL; | |
9419 | ||
a1056b1b | 9420 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
f4e583c8 AQ |
9421 | |
9422 | return err; | |
9423 | } | |
9424 | ||
ad7e718c JB |
9425 | static struct sk_buff * |
9426 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
6c09e791 AK |
9427 | struct wireless_dev *wdev, int approxlen, |
9428 | u32 portid, u32 seq, enum nl80211_commands cmd, | |
567ffc35 JB |
9429 | enum nl80211_attrs attr, |
9430 | const struct nl80211_vendor_cmd_info *info, | |
9431 | gfp_t gfp) | |
ad7e718c JB |
9432 | { |
9433 | struct sk_buff *skb; | |
9434 | void *hdr; | |
9435 | struct nlattr *data; | |
9436 | ||
9437 | skb = nlmsg_new(approxlen + 100, gfp); | |
9438 | if (!skb) | |
9439 | return NULL; | |
9440 | ||
9441 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
9442 | if (!hdr) { | |
9443 | kfree_skb(skb); | |
9444 | return NULL; | |
9445 | } | |
9446 | ||
9447 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
9448 | goto nla_put_failure; | |
567ffc35 JB |
9449 | |
9450 | if (info) { | |
9451 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
9452 | info->vendor_id)) | |
9453 | goto nla_put_failure; | |
9454 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
9455 | info->subcmd)) | |
9456 | goto nla_put_failure; | |
9457 | } | |
9458 | ||
6c09e791 | 9459 | if (wdev) { |
2dad624e ND |
9460 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
9461 | wdev_id(wdev), NL80211_ATTR_PAD)) | |
6c09e791 AK |
9462 | goto nla_put_failure; |
9463 | if (wdev->netdev && | |
9464 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, | |
9465 | wdev->netdev->ifindex)) | |
9466 | goto nla_put_failure; | |
9467 | } | |
9468 | ||
ae0be8de | 9469 | data = nla_nest_start_noflag(skb, attr); |
76e1fb4b JB |
9470 | if (!data) |
9471 | goto nla_put_failure; | |
ad7e718c JB |
9472 | |
9473 | ((void **)skb->cb)[0] = rdev; | |
9474 | ((void **)skb->cb)[1] = hdr; | |
9475 | ((void **)skb->cb)[2] = data; | |
9476 | ||
9477 | return skb; | |
9478 | ||
9479 | nla_put_failure: | |
9480 | kfree_skb(skb); | |
9481 | return NULL; | |
9482 | } | |
f4e583c8 | 9483 | |
e03ad6ea | 9484 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
6c09e791 | 9485 | struct wireless_dev *wdev, |
e03ad6ea JB |
9486 | enum nl80211_commands cmd, |
9487 | enum nl80211_attrs attr, | |
55c1fdf0 | 9488 | unsigned int portid, |
e03ad6ea JB |
9489 | int vendor_event_idx, |
9490 | int approxlen, gfp_t gfp) | |
9491 | { | |
f26cbf40 | 9492 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
9493 | const struct nl80211_vendor_cmd_info *info; |
9494 | ||
9495 | switch (cmd) { | |
9496 | case NL80211_CMD_TESTMODE: | |
9497 | if (WARN_ON(vendor_event_idx != -1)) | |
9498 | return NULL; | |
9499 | info = NULL; | |
9500 | break; | |
9501 | case NL80211_CMD_VENDOR: | |
9502 | if (WARN_ON(vendor_event_idx < 0 || | |
9503 | vendor_event_idx >= wiphy->n_vendor_events)) | |
9504 | return NULL; | |
9505 | info = &wiphy->vendor_events[vendor_event_idx]; | |
9506 | break; | |
9507 | default: | |
9508 | WARN_ON(1); | |
9509 | return NULL; | |
9510 | } | |
9511 | ||
55c1fdf0 | 9512 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0, |
e03ad6ea JB |
9513 | cmd, attr, info, gfp); |
9514 | } | |
9515 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
9516 | ||
9517 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
9518 | { | |
9519 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
9520 | void *hdr = ((void **)skb->cb)[1]; | |
55c1fdf0 | 9521 | struct nlmsghdr *nlhdr = nlmsg_hdr(skb); |
e03ad6ea JB |
9522 | struct nlattr *data = ((void **)skb->cb)[2]; |
9523 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
9524 | ||
bd8c78e7 JB |
9525 | /* clear CB data for netlink core to own from now on */ |
9526 | memset(skb->cb, 0, sizeof(skb->cb)); | |
9527 | ||
e03ad6ea JB |
9528 | nla_nest_end(skb, data); |
9529 | genlmsg_end(skb, hdr); | |
9530 | ||
55c1fdf0 JB |
9531 | if (nlhdr->nlmsg_pid) { |
9532 | genlmsg_unicast(wiphy_net(&rdev->wiphy), skb, | |
9533 | nlhdr->nlmsg_pid); | |
9534 | } else { | |
9535 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
9536 | mcgrp = NL80211_MCGRP_VENDOR; | |
e03ad6ea | 9537 | |
55c1fdf0 JB |
9538 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
9539 | skb, 0, mcgrp, gfp); | |
9540 | } | |
e03ad6ea JB |
9541 | } |
9542 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
9543 | ||
aff89a9b | 9544 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
9545 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
9546 | { | |
4c476991 | 9547 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
9548 | struct wireless_dev *wdev = |
9549 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
9550 | int err; |
9551 | ||
fc73f11f DS |
9552 | if (!rdev->ops->testmode_cmd) |
9553 | return -EOPNOTSUPP; | |
9554 | ||
9555 | if (IS_ERR(wdev)) { | |
9556 | err = PTR_ERR(wdev); | |
9557 | if (err != -EINVAL) | |
9558 | return err; | |
9559 | wdev = NULL; | |
9560 | } else if (wdev->wiphy != &rdev->wiphy) { | |
9561 | return -EINVAL; | |
9562 | } | |
9563 | ||
aff89a9b JB |
9564 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
9565 | return -EINVAL; | |
9566 | ||
ad7e718c | 9567 | rdev->cur_cmd_info = info; |
fc73f11f | 9568 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
9569 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
9570 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 9571 | rdev->cur_cmd_info = NULL; |
aff89a9b | 9572 | |
aff89a9b JB |
9573 | return err; |
9574 | } | |
9575 | ||
71063f0e WYG |
9576 | static int nl80211_testmode_dump(struct sk_buff *skb, |
9577 | struct netlink_callback *cb) | |
9578 | { | |
00918d33 | 9579 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
9580 | int err; |
9581 | long phy_idx; | |
9582 | void *data = NULL; | |
9583 | int data_len = 0; | |
9584 | ||
5fe231e8 JB |
9585 | rtnl_lock(); |
9586 | ||
71063f0e WYG |
9587 | if (cb->args[0]) { |
9588 | /* | |
9589 | * 0 is a valid index, but not valid for args[0], | |
9590 | * so we need to offset by 1. | |
9591 | */ | |
9592 | phy_idx = cb->args[0] - 1; | |
a4956dca LC |
9593 | |
9594 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); | |
9595 | if (!rdev) { | |
9596 | err = -ENOENT; | |
9597 | goto out_err; | |
9598 | } | |
71063f0e | 9599 | } else { |
c90c39da JB |
9600 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
9601 | ||
8cb08174 JB |
9602 | err = nlmsg_parse_deprecated(cb->nlh, |
9603 | GENL_HDRLEN + nl80211_fam.hdrsize, | |
9604 | attrbuf, nl80211_fam.maxattr, | |
9605 | nl80211_policy, NULL); | |
71063f0e | 9606 | if (err) |
5fe231e8 | 9607 | goto out_err; |
00918d33 | 9608 | |
c90c39da | 9609 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
2bd7e35d | 9610 | if (IS_ERR(rdev)) { |
5fe231e8 JB |
9611 | err = PTR_ERR(rdev); |
9612 | goto out_err; | |
00918d33 | 9613 | } |
2bd7e35d | 9614 | phy_idx = rdev->wiphy_idx; |
2bd7e35d | 9615 | |
c90c39da JB |
9616 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
9617 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; | |
71063f0e WYG |
9618 | } |
9619 | ||
9620 | if (cb->args[1]) { | |
9621 | data = nla_data((void *)cb->args[1]); | |
9622 | data_len = nla_len((void *)cb->args[1]); | |
9623 | } | |
9624 | ||
00918d33 | 9625 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
9626 | err = -EOPNOTSUPP; |
9627 | goto out_err; | |
9628 | } | |
9629 | ||
9630 | while (1) { | |
15e47304 | 9631 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
9632 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
9633 | NL80211_CMD_TESTMODE); | |
9634 | struct nlattr *tmdata; | |
9635 | ||
cb35fba3 DC |
9636 | if (!hdr) |
9637 | break; | |
9638 | ||
9360ffd1 | 9639 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
9640 | genlmsg_cancel(skb, hdr); |
9641 | break; | |
9642 | } | |
9643 | ||
ae0be8de | 9644 | tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA); |
71063f0e WYG |
9645 | if (!tmdata) { |
9646 | genlmsg_cancel(skb, hdr); | |
9647 | break; | |
9648 | } | |
e35e4d28 | 9649 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
9650 | nla_nest_end(skb, tmdata); |
9651 | ||
9652 | if (err == -ENOBUFS || err == -ENOENT) { | |
9653 | genlmsg_cancel(skb, hdr); | |
9654 | break; | |
9655 | } else if (err) { | |
9656 | genlmsg_cancel(skb, hdr); | |
9657 | goto out_err; | |
9658 | } | |
9659 | ||
9660 | genlmsg_end(skb, hdr); | |
9661 | } | |
9662 | ||
9663 | err = skb->len; | |
9664 | /* see above */ | |
9665 | cb->args[0] = phy_idx + 1; | |
9666 | out_err: | |
5fe231e8 | 9667 | rtnl_unlock(); |
71063f0e WYG |
9668 | return err; |
9669 | } | |
aff89a9b JB |
9670 | #endif |
9671 | ||
b23aa676 SO |
9672 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
9673 | { | |
4c476991 JB |
9674 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
9675 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
9676 | struct cfg80211_connect_params connect; |
9677 | struct wiphy *wiphy; | |
fffd0934 | 9678 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
9679 | int err; |
9680 | ||
9681 | memset(&connect, 0, sizeof(connect)); | |
9682 | ||
b23aa676 SO |
9683 | if (!info->attrs[NL80211_ATTR_SSID] || |
9684 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
9685 | return -EINVAL; | |
9686 | ||
9687 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
9688 | connect.auth_type = | |
9689 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
9690 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
9691 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
9692 | return -EINVAL; |
9693 | } else | |
9694 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
9695 | ||
9696 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
9697 | ||
3a00df57 AS |
9698 | if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && |
9699 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
9700 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) | |
9701 | return -EINVAL; | |
9702 | connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; | |
9703 | ||
c0692b8f | 9704 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 9705 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
9706 | if (err) |
9707 | return err; | |
b23aa676 | 9708 | |
074ac8df | 9709 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
9710 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
9711 | return -EOPNOTSUPP; | |
b23aa676 | 9712 | |
79c97e97 | 9713 | wiphy = &rdev->wiphy; |
b23aa676 | 9714 | |
4486ea98 BS |
9715 | connect.bg_scan_period = -1; |
9716 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
9717 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
9718 | connect.bg_scan_period = | |
9719 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
9720 | } | |
9721 | ||
b23aa676 SO |
9722 | if (info->attrs[NL80211_ATTR_MAC]) |
9723 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
9724 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
9725 | connect.bssid_hint = | |
9726 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
9727 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
9728 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
9729 | ||
9730 | if (info->attrs[NL80211_ATTR_IE]) { | |
9731 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9732 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9733 | } | |
9734 | ||
cee00a95 JM |
9735 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
9736 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
65026002 EG |
9737 | if (connect.mfp == NL80211_MFP_OPTIONAL && |
9738 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
9739 | NL80211_EXT_FEATURE_MFP_OPTIONAL)) | |
9740 | return -EOPNOTSUPP; | |
cee00a95 JM |
9741 | } else { |
9742 | connect.mfp = NL80211_MFP_NO; | |
9743 | } | |
9744 | ||
ba6fbacf JM |
9745 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
9746 | connect.prev_bssid = | |
9747 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | |
9748 | ||
b23aa676 | 9749 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
9750 | connect.channel = nl80211_get_valid_chan( |
9751 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
9752 | if (!connect.channel) | |
1df4a510 JM |
9753 | return -EINVAL; |
9754 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
9755 | connect.channel_hint = nl80211_get_valid_chan( |
9756 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
9757 | if (!connect.channel_hint) | |
4c476991 | 9758 | return -EINVAL; |
b23aa676 SO |
9759 | } |
9760 | ||
fffd0934 | 9761 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
768075eb | 9762 | connkeys = nl80211_parse_connkeys(rdev, info, NULL); |
4c476991 JB |
9763 | if (IS_ERR(connkeys)) |
9764 | return PTR_ERR(connkeys); | |
fffd0934 JB |
9765 | } |
9766 | ||
7e7c8926 BG |
9767 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
9768 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
9769 | ||
9770 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
9771 | memcpy(&connect.ht_capa_mask, | |
9772 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
9773 | sizeof(connect.ht_capa_mask)); | |
9774 | ||
9775 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 9776 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
b47f610b | 9777 | kzfree(connkeys); |
7e7c8926 | 9778 | return -EINVAL; |
b4e4f47e | 9779 | } |
7e7c8926 BG |
9780 | memcpy(&connect.ht_capa, |
9781 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
9782 | sizeof(connect.ht_capa)); | |
9783 | } | |
9784 | ||
ee2aca34 JB |
9785 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
9786 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
9787 | ||
9788 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
9789 | memcpy(&connect.vht_capa_mask, | |
9790 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
9791 | sizeof(connect.vht_capa_mask)); | |
9792 | ||
9793 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
9794 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
b47f610b | 9795 | kzfree(connkeys); |
ee2aca34 JB |
9796 | return -EINVAL; |
9797 | } | |
9798 | memcpy(&connect.vht_capa, | |
9799 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
9800 | sizeof(connect.vht_capa)); | |
9801 | } | |
9802 | ||
bab5ab7d | 9803 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
0c9ca11b BL |
9804 | if (!((rdev->wiphy.features & |
9805 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && | |
9806 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && | |
9807 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
9808 | NL80211_EXT_FEATURE_RRM)) { | |
707554b4 | 9809 | kzfree(connkeys); |
bab5ab7d | 9810 | return -EINVAL; |
707554b4 | 9811 | } |
bab5ab7d AK |
9812 | connect.flags |= ASSOC_REQ_USE_RRM; |
9813 | } | |
9814 | ||
34d50519 | 9815 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
57fbcce3 | 9816 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
34d50519 LD |
9817 | kzfree(connkeys); |
9818 | return -EOPNOTSUPP; | |
9819 | } | |
9820 | ||
38de03d2 AS |
9821 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
9822 | /* bss selection makes no sense if bssid is set */ | |
9823 | if (connect.bssid) { | |
9824 | kzfree(connkeys); | |
9825 | return -EINVAL; | |
9826 | } | |
9827 | ||
9828 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], | |
9829 | wiphy, &connect.bss_select); | |
9830 | if (err) { | |
9831 | kzfree(connkeys); | |
9832 | return err; | |
9833 | } | |
9834 | } | |
9835 | ||
a3caf744 VK |
9836 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
9837 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && | |
9838 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && | |
9839 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && | |
9840 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && | |
9841 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { | |
9842 | connect.fils_erp_username = | |
9843 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); | |
9844 | connect.fils_erp_username_len = | |
9845 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); | |
9846 | connect.fils_erp_realm = | |
9847 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); | |
9848 | connect.fils_erp_realm_len = | |
9849 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); | |
9850 | connect.fils_erp_next_seq_num = | |
9851 | nla_get_u16( | |
9852 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); | |
9853 | connect.fils_erp_rrk = | |
9854 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); | |
9855 | connect.fils_erp_rrk_len = | |
9856 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); | |
9857 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || | |
9858 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || | |
9859 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || | |
9860 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { | |
9861 | kzfree(connkeys); | |
9862 | return -EINVAL; | |
9863 | } | |
9864 | ||
40cbfa90 SD |
9865 | if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { |
9866 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { | |
2f0605a6 | 9867 | kzfree(connkeys); |
40cbfa90 SD |
9868 | GENL_SET_ERR_MSG(info, |
9869 | "external auth requires connection ownership"); | |
9870 | return -EINVAL; | |
9871 | } | |
9872 | connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; | |
9873 | } | |
9874 | ||
83739b03 | 9875 | wdev_lock(dev->ieee80211_ptr); |
bd2522b1 | 9876 | |
4ce2bd9c JM |
9877 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
9878 | connect.prev_bssid); | |
fffd0934 | 9879 | if (err) |
b47f610b | 9880 | kzfree(connkeys); |
bd2522b1 AZ |
9881 | |
9882 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { | |
9883 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; | |
9884 | if (connect.bssid) | |
9885 | memcpy(dev->ieee80211_ptr->disconnect_bssid, | |
9886 | connect.bssid, ETH_ALEN); | |
9887 | else | |
9888 | memset(dev->ieee80211_ptr->disconnect_bssid, | |
9889 | 0, ETH_ALEN); | |
9890 | } | |
9891 | ||
9892 | wdev_unlock(dev->ieee80211_ptr); | |
9893 | ||
b23aa676 SO |
9894 | return err; |
9895 | } | |
9896 | ||
088e8df8 | 9897 | static int nl80211_update_connect_params(struct sk_buff *skb, |
9898 | struct genl_info *info) | |
9899 | { | |
9900 | struct cfg80211_connect_params connect = {}; | |
9901 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9902 | struct net_device *dev = info->user_ptr[1]; | |
9903 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7f9a3e15 VK |
9904 | bool fils_sk_offload; |
9905 | u32 auth_type; | |
088e8df8 | 9906 | u32 changed = 0; |
9907 | int ret; | |
9908 | ||
9909 | if (!rdev->ops->update_connect_params) | |
9910 | return -EOPNOTSUPP; | |
9911 | ||
9912 | if (info->attrs[NL80211_ATTR_IE]) { | |
088e8df8 | 9913 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
9914 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9915 | changed |= UPDATE_ASSOC_IES; | |
9916 | } | |
9917 | ||
7f9a3e15 VK |
9918 | fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, |
9919 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); | |
9920 | ||
9921 | /* | |
9922 | * when driver supports fils-sk offload all attributes must be | |
9923 | * provided. So the else covers "fils-sk-not-all" and | |
9924 | * "no-fils-sk-any". | |
9925 | */ | |
9926 | if (fils_sk_offload && | |
9927 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && | |
9928 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && | |
9929 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && | |
9930 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { | |
9931 | connect.fils_erp_username = | |
9932 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); | |
9933 | connect.fils_erp_username_len = | |
9934 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); | |
9935 | connect.fils_erp_realm = | |
9936 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); | |
9937 | connect.fils_erp_realm_len = | |
9938 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); | |
9939 | connect.fils_erp_next_seq_num = | |
9940 | nla_get_u16( | |
9941 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); | |
9942 | connect.fils_erp_rrk = | |
9943 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); | |
9944 | connect.fils_erp_rrk_len = | |
9945 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); | |
9946 | changed |= UPDATE_FILS_ERP_INFO; | |
9947 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || | |
9948 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || | |
9949 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || | |
9950 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { | |
9951 | return -EINVAL; | |
9952 | } | |
9953 | ||
9954 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
9955 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
9956 | if (!nl80211_valid_auth_type(rdev, auth_type, | |
9957 | NL80211_CMD_CONNECT)) | |
9958 | return -EINVAL; | |
9959 | ||
9960 | if (auth_type == NL80211_AUTHTYPE_FILS_SK && | |
9961 | fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) | |
9962 | return -EINVAL; | |
9963 | ||
9964 | connect.auth_type = auth_type; | |
9965 | changed |= UPDATE_AUTH_TYPE; | |
9966 | } | |
9967 | ||
088e8df8 | 9968 | wdev_lock(dev->ieee80211_ptr); |
9969 | if (!wdev->current_bss) | |
9970 | ret = -ENOLINK; | |
9971 | else | |
9972 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); | |
9973 | wdev_unlock(dev->ieee80211_ptr); | |
9974 | ||
9975 | return ret; | |
9976 | } | |
9977 | ||
b23aa676 SO |
9978 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
9979 | { | |
4c476991 JB |
9980 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
9981 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 9982 | u16 reason; |
83739b03 | 9983 | int ret; |
b23aa676 | 9984 | |
bad29297 AZ |
9985 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
9986 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) | |
9987 | return -EPERM; | |
9988 | ||
b23aa676 SO |
9989 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
9990 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
9991 | else | |
9992 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
9993 | ||
9994 | if (reason == 0) | |
9995 | return -EINVAL; | |
9996 | ||
074ac8df | 9997 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
9998 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
9999 | return -EOPNOTSUPP; | |
b23aa676 | 10000 | |
83739b03 JB |
10001 | wdev_lock(dev->ieee80211_ptr); |
10002 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
10003 | wdev_unlock(dev->ieee80211_ptr); | |
10004 | return ret; | |
b23aa676 SO |
10005 | } |
10006 | ||
463d0183 JB |
10007 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
10008 | { | |
4c476991 | 10009 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
10010 | struct net *net; |
10011 | int err; | |
463d0183 | 10012 | |
4b681c82 VK |
10013 | if (info->attrs[NL80211_ATTR_PID]) { |
10014 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
10015 | ||
10016 | net = get_net_ns_by_pid(pid); | |
10017 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { | |
10018 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); | |
463d0183 | 10019 | |
4b681c82 VK |
10020 | net = get_net_ns_by_fd(fd); |
10021 | } else { | |
10022 | return -EINVAL; | |
10023 | } | |
463d0183 | 10024 | |
4c476991 JB |
10025 | if (IS_ERR(net)) |
10026 | return PTR_ERR(net); | |
463d0183 JB |
10027 | |
10028 | err = 0; | |
10029 | ||
10030 | /* check if anything to do */ | |
4c476991 JB |
10031 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
10032 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 10033 | |
463d0183 | 10034 | put_net(net); |
463d0183 JB |
10035 | return err; |
10036 | } | |
10037 | ||
67fbb16b SO |
10038 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
10039 | { | |
4c476991 | 10040 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
10041 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
10042 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 10043 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
10044 | struct cfg80211_pmksa pmksa; |
10045 | ||
10046 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
10047 | ||
67fbb16b SO |
10048 | if (!info->attrs[NL80211_ATTR_PMKID]) |
10049 | return -EINVAL; | |
10050 | ||
67fbb16b | 10051 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
a3caf744 VK |
10052 | |
10053 | if (info->attrs[NL80211_ATTR_MAC]) { | |
10054 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10055 | } else if (info->attrs[NL80211_ATTR_SSID] && | |
10056 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && | |
10057 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || | |
10058 | info->attrs[NL80211_ATTR_PMK])) { | |
10059 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
10060 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
10061 | pmksa.cache_id = | |
10062 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); | |
10063 | } else { | |
10064 | return -EINVAL; | |
10065 | } | |
10066 | if (info->attrs[NL80211_ATTR_PMK]) { | |
10067 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); | |
10068 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); | |
10069 | } | |
67fbb16b | 10070 | |
074ac8df | 10071 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
6c900360 LD |
10072 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
10073 | !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP && | |
10074 | wiphy_ext_feature_isset(&rdev->wiphy, | |
10075 | NL80211_EXT_FEATURE_AP_PMKSA_CACHING))) | |
4c476991 | 10076 | return -EOPNOTSUPP; |
67fbb16b SO |
10077 | |
10078 | switch (info->genlhdr->cmd) { | |
10079 | case NL80211_CMD_SET_PMKSA: | |
10080 | rdev_ops = rdev->ops->set_pmksa; | |
10081 | break; | |
10082 | case NL80211_CMD_DEL_PMKSA: | |
10083 | rdev_ops = rdev->ops->del_pmksa; | |
10084 | break; | |
10085 | default: | |
10086 | WARN_ON(1); | |
10087 | break; | |
10088 | } | |
10089 | ||
4c476991 JB |
10090 | if (!rdev_ops) |
10091 | return -EOPNOTSUPP; | |
67fbb16b | 10092 | |
4c476991 | 10093 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
10094 | } |
10095 | ||
10096 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
10097 | { | |
4c476991 JB |
10098 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
10099 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 10100 | |
074ac8df | 10101 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
10102 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
10103 | return -EOPNOTSUPP; | |
67fbb16b | 10104 | |
4c476991 JB |
10105 | if (!rdev->ops->flush_pmksa) |
10106 | return -EOPNOTSUPP; | |
67fbb16b | 10107 | |
e35e4d28 | 10108 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
10109 | } |
10110 | ||
109086ce AN |
10111 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
10112 | { | |
10113 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10114 | struct net_device *dev = info->user_ptr[1]; | |
10115 | u8 action_code, dialog_token; | |
df942e7b | 10116 | u32 peer_capability = 0; |
109086ce AN |
10117 | u16 status_code; |
10118 | u8 *peer; | |
31fa97c5 | 10119 | bool initiator; |
109086ce AN |
10120 | |
10121 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
10122 | !rdev->ops->tdls_mgmt) | |
10123 | return -EOPNOTSUPP; | |
10124 | ||
10125 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
10126 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
10127 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
10128 | !info->attrs[NL80211_ATTR_IE] || | |
10129 | !info->attrs[NL80211_ATTR_MAC]) | |
10130 | return -EINVAL; | |
10131 | ||
10132 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10133 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
10134 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
10135 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 10136 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
10137 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
10138 | peer_capability = | |
10139 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 10140 | |
e35e4d28 | 10141 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 10142 | dialog_token, status_code, peer_capability, |
31fa97c5 | 10143 | initiator, |
e35e4d28 HG |
10144 | nla_data(info->attrs[NL80211_ATTR_IE]), |
10145 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
10146 | } |
10147 | ||
10148 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
10149 | { | |
10150 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10151 | struct net_device *dev = info->user_ptr[1]; | |
10152 | enum nl80211_tdls_operation operation; | |
10153 | u8 *peer; | |
10154 | ||
10155 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
10156 | !rdev->ops->tdls_oper) | |
10157 | return -EOPNOTSUPP; | |
10158 | ||
10159 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
10160 | !info->attrs[NL80211_ATTR_MAC]) | |
10161 | return -EINVAL; | |
10162 | ||
10163 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
10164 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10165 | ||
e35e4d28 | 10166 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
10167 | } |
10168 | ||
9588bbd5 JM |
10169 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
10170 | struct genl_info *info) | |
10171 | { | |
4c476991 | 10172 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 10173 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 10174 | struct cfg80211_chan_def chandef; |
34373d12 | 10175 | const struct cfg80211_chan_def *compat_chandef; |
9588bbd5 JM |
10176 | struct sk_buff *msg; |
10177 | void *hdr; | |
10178 | u64 cookie; | |
683b6d3b | 10179 | u32 duration; |
9588bbd5 JM |
10180 | int err; |
10181 | ||
10182 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
10183 | !info->attrs[NL80211_ATTR_DURATION]) | |
10184 | return -EINVAL; | |
10185 | ||
10186 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
10187 | ||
ebf348fc JB |
10188 | if (!rdev->ops->remain_on_channel || |
10189 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
10190 | return -EOPNOTSUPP; | |
10191 | ||
9588bbd5 | 10192 | /* |
ebf348fc JB |
10193 | * We should be on that channel for at least a minimum amount of |
10194 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 10195 | */ |
ebf348fc | 10196 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 10197 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
10198 | return -EINVAL; |
10199 | ||
683b6d3b JB |
10200 | err = nl80211_parse_chandef(rdev, info, &chandef); |
10201 | if (err) | |
10202 | return err; | |
9588bbd5 | 10203 | |
34373d12 VT |
10204 | wdev_lock(wdev); |
10205 | if (!cfg80211_off_channel_oper_allowed(wdev) && | |
10206 | !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { | |
10207 | compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, | |
10208 | &chandef); | |
10209 | if (compat_chandef != &chandef) { | |
10210 | wdev_unlock(wdev); | |
10211 | return -EBUSY; | |
10212 | } | |
10213 | } | |
10214 | wdev_unlock(wdev); | |
10215 | ||
9588bbd5 | 10216 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
10217 | if (!msg) |
10218 | return -ENOMEM; | |
9588bbd5 | 10219 | |
15e47304 | 10220 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 10221 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
10222 | if (!hdr) { |
10223 | err = -ENOBUFS; | |
9588bbd5 JM |
10224 | goto free_msg; |
10225 | } | |
10226 | ||
683b6d3b JB |
10227 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
10228 | duration, &cookie); | |
9588bbd5 JM |
10229 | |
10230 | if (err) | |
10231 | goto free_msg; | |
10232 | ||
2dad624e ND |
10233 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
10234 | NL80211_ATTR_PAD)) | |
9360ffd1 | 10235 | goto nla_put_failure; |
9588bbd5 JM |
10236 | |
10237 | genlmsg_end(msg, hdr); | |
4c476991 JB |
10238 | |
10239 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
10240 | |
10241 | nla_put_failure: | |
10242 | err = -ENOBUFS; | |
10243 | free_msg: | |
10244 | nlmsg_free(msg); | |
9588bbd5 JM |
10245 | return err; |
10246 | } | |
10247 | ||
10248 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
10249 | struct genl_info *info) | |
10250 | { | |
4c476991 | 10251 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 10252 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 10253 | u64 cookie; |
9588bbd5 JM |
10254 | |
10255 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
10256 | return -EINVAL; | |
10257 | ||
4c476991 JB |
10258 | if (!rdev->ops->cancel_remain_on_channel) |
10259 | return -EOPNOTSUPP; | |
9588bbd5 | 10260 | |
9588bbd5 JM |
10261 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
10262 | ||
e35e4d28 | 10263 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
10264 | } |
10265 | ||
13ae75b1 JM |
10266 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
10267 | struct genl_info *info) | |
10268 | { | |
13ae75b1 | 10269 | struct cfg80211_bitrate_mask mask; |
a7c7fbff | 10270 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 10271 | struct net_device *dev = info->user_ptr[1]; |
a7c7fbff | 10272 | int err; |
13ae75b1 | 10273 | |
4c476991 JB |
10274 | if (!rdev->ops->set_bitrate_mask) |
10275 | return -EOPNOTSUPP; | |
13ae75b1 | 10276 | |
a7c7fbff PK |
10277 | err = nl80211_parse_tx_bitrate_mask(info, &mask); |
10278 | if (err) | |
10279 | return err; | |
13ae75b1 | 10280 | |
e35e4d28 | 10281 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
10282 | } |
10283 | ||
2e161f78 | 10284 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 10285 | { |
4c476991 | 10286 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 10287 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 10288 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
10289 | |
10290 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
10291 | return -EINVAL; | |
10292 | ||
2e161f78 JB |
10293 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
10294 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 10295 | |
71bbc994 JB |
10296 | switch (wdev->iftype) { |
10297 | case NL80211_IFTYPE_STATION: | |
10298 | case NL80211_IFTYPE_ADHOC: | |
10299 | case NL80211_IFTYPE_P2P_CLIENT: | |
10300 | case NL80211_IFTYPE_AP: | |
10301 | case NL80211_IFTYPE_AP_VLAN: | |
10302 | case NL80211_IFTYPE_MESH_POINT: | |
10303 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 10304 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 | 10305 | break; |
cb3b7d87 | 10306 | case NL80211_IFTYPE_NAN: |
71bbc994 | 10307 | default: |
4c476991 | 10308 | return -EOPNOTSUPP; |
71bbc994 | 10309 | } |
026331c4 JM |
10310 | |
10311 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
10312 | if (!rdev->ops->mgmt_tx) |
10313 | return -EOPNOTSUPP; | |
026331c4 | 10314 | |
15e47304 | 10315 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
10316 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
10317 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
10318 | } |
10319 | ||
2e161f78 | 10320 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 10321 | { |
4c476991 | 10322 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 10323 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 10324 | struct cfg80211_chan_def chandef; |
026331c4 | 10325 | int err; |
d64d373f | 10326 | void *hdr = NULL; |
026331c4 | 10327 | u64 cookie; |
e247bd90 | 10328 | struct sk_buff *msg = NULL; |
b176e629 AO |
10329 | struct cfg80211_mgmt_tx_params params = { |
10330 | .dont_wait_for_ack = | |
10331 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
10332 | }; | |
026331c4 | 10333 | |
683b6d3b | 10334 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
10335 | return -EINVAL; |
10336 | ||
4c476991 JB |
10337 | if (!rdev->ops->mgmt_tx) |
10338 | return -EOPNOTSUPP; | |
026331c4 | 10339 | |
71bbc994 | 10340 | switch (wdev->iftype) { |
ea141b75 AQ |
10341 | case NL80211_IFTYPE_P2P_DEVICE: |
10342 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
10343 | return -EINVAL; | |
71bbc994 JB |
10344 | case NL80211_IFTYPE_STATION: |
10345 | case NL80211_IFTYPE_ADHOC: | |
10346 | case NL80211_IFTYPE_P2P_CLIENT: | |
10347 | case NL80211_IFTYPE_AP: | |
10348 | case NL80211_IFTYPE_AP_VLAN: | |
10349 | case NL80211_IFTYPE_MESH_POINT: | |
10350 | case NL80211_IFTYPE_P2P_GO: | |
10351 | break; | |
cb3b7d87 | 10352 | case NL80211_IFTYPE_NAN: |
71bbc994 | 10353 | default: |
4c476991 | 10354 | return -EOPNOTSUPP; |
71bbc994 | 10355 | } |
026331c4 | 10356 | |
f7ca38df | 10357 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 10358 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 10359 | return -EINVAL; |
b176e629 | 10360 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
10361 | |
10362 | /* | |
10363 | * We should wait on the channel for at least a minimum amount | |
10364 | * of time (10ms) but no longer than the driver supports. | |
10365 | */ | |
b176e629 AO |
10366 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
10367 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc | 10368 | return -EINVAL; |
f7ca38df JB |
10369 | } |
10370 | ||
b176e629 | 10371 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 10372 | |
b176e629 | 10373 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
10374 | return -EINVAL; |
10375 | ||
b176e629 | 10376 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 10377 | |
ea141b75 AQ |
10378 | /* get the channel if any has been specified, otherwise pass NULL to |
10379 | * the driver. The latter will use the current one | |
10380 | */ | |
10381 | chandef.chan = NULL; | |
10382 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
10383 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
10384 | if (err) | |
10385 | return err; | |
10386 | } | |
10387 | ||
b176e629 | 10388 | if (!chandef.chan && params.offchan) |
ea141b75 | 10389 | return -EINVAL; |
026331c4 | 10390 | |
34373d12 VT |
10391 | wdev_lock(wdev); |
10392 | if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { | |
10393 | wdev_unlock(wdev); | |
10394 | return -EBUSY; | |
10395 | } | |
10396 | wdev_unlock(wdev); | |
10397 | ||
34d22ce2 AO |
10398 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
10399 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
10400 | ||
10401 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
10402 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
10403 | int i; | |
10404 | ||
10405 | if (len % sizeof(u16)) | |
10406 | return -EINVAL; | |
10407 | ||
10408 | params.n_csa_offsets = len / sizeof(u16); | |
10409 | params.csa_offsets = | |
10410 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
10411 | ||
10412 | /* check that all the offsets fit the frame */ | |
10413 | for (i = 0; i < params.n_csa_offsets; i++) { | |
10414 | if (params.csa_offsets[i] >= params.len) | |
10415 | return -EINVAL; | |
10416 | } | |
10417 | } | |
10418 | ||
b176e629 | 10419 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
10420 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
10421 | if (!msg) | |
10422 | return -ENOMEM; | |
026331c4 | 10423 | |
15e47304 | 10424 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 10425 | NL80211_CMD_FRAME); |
cb35fba3 DC |
10426 | if (!hdr) { |
10427 | err = -ENOBUFS; | |
e247bd90 JB |
10428 | goto free_msg; |
10429 | } | |
026331c4 | 10430 | } |
e247bd90 | 10431 | |
b176e629 AO |
10432 | params.chan = chandef.chan; |
10433 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
10434 | if (err) |
10435 | goto free_msg; | |
10436 | ||
e247bd90 | 10437 | if (msg) { |
2dad624e ND |
10438 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
10439 | NL80211_ATTR_PAD)) | |
9360ffd1 | 10440 | goto nla_put_failure; |
026331c4 | 10441 | |
e247bd90 JB |
10442 | genlmsg_end(msg, hdr); |
10443 | return genlmsg_reply(msg, info); | |
10444 | } | |
10445 | ||
10446 | return 0; | |
026331c4 JM |
10447 | |
10448 | nla_put_failure: | |
10449 | err = -ENOBUFS; | |
10450 | free_msg: | |
10451 | nlmsg_free(msg); | |
026331c4 JM |
10452 | return err; |
10453 | } | |
10454 | ||
f7ca38df JB |
10455 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
10456 | { | |
10457 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 10458 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
10459 | u64 cookie; |
10460 | ||
10461 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
10462 | return -EINVAL; | |
10463 | ||
10464 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
10465 | return -EOPNOTSUPP; | |
10466 | ||
71bbc994 JB |
10467 | switch (wdev->iftype) { |
10468 | case NL80211_IFTYPE_STATION: | |
10469 | case NL80211_IFTYPE_ADHOC: | |
10470 | case NL80211_IFTYPE_P2P_CLIENT: | |
10471 | case NL80211_IFTYPE_AP: | |
10472 | case NL80211_IFTYPE_AP_VLAN: | |
10473 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 10474 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 | 10475 | break; |
cb3b7d87 | 10476 | case NL80211_IFTYPE_NAN: |
71bbc994 | 10477 | default: |
f7ca38df | 10478 | return -EOPNOTSUPP; |
71bbc994 | 10479 | } |
f7ca38df JB |
10480 | |
10481 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
10482 | ||
e35e4d28 | 10483 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
10484 | } |
10485 | ||
ffb9eb3d KV |
10486 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
10487 | { | |
4c476991 | 10488 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 10489 | struct wireless_dev *wdev; |
4c476991 | 10490 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
10491 | u8 ps_state; |
10492 | bool state; | |
10493 | int err; | |
10494 | ||
4c476991 JB |
10495 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
10496 | return -EINVAL; | |
ffb9eb3d KV |
10497 | |
10498 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
10499 | ||
ffb9eb3d KV |
10500 | wdev = dev->ieee80211_ptr; |
10501 | ||
4c476991 JB |
10502 | if (!rdev->ops->set_power_mgmt) |
10503 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
10504 | |
10505 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
10506 | ||
10507 | if (state == wdev->ps) | |
4c476991 | 10508 | return 0; |
ffb9eb3d | 10509 | |
e35e4d28 | 10510 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
10511 | if (!err) |
10512 | wdev->ps = state; | |
ffb9eb3d KV |
10513 | return err; |
10514 | } | |
10515 | ||
10516 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
10517 | { | |
4c476991 | 10518 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
10519 | enum nl80211_ps_state ps_state; |
10520 | struct wireless_dev *wdev; | |
4c476991 | 10521 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
10522 | struct sk_buff *msg; |
10523 | void *hdr; | |
10524 | int err; | |
10525 | ||
ffb9eb3d KV |
10526 | wdev = dev->ieee80211_ptr; |
10527 | ||
4c476991 JB |
10528 | if (!rdev->ops->set_power_mgmt) |
10529 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
10530 | |
10531 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
10532 | if (!msg) |
10533 | return -ENOMEM; | |
ffb9eb3d | 10534 | |
15e47304 | 10535 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
10536 | NL80211_CMD_GET_POWER_SAVE); |
10537 | if (!hdr) { | |
4c476991 | 10538 | err = -ENOBUFS; |
ffb9eb3d KV |
10539 | goto free_msg; |
10540 | } | |
10541 | ||
10542 | if (wdev->ps) | |
10543 | ps_state = NL80211_PS_ENABLED; | |
10544 | else | |
10545 | ps_state = NL80211_PS_DISABLED; | |
10546 | ||
9360ffd1 DM |
10547 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
10548 | goto nla_put_failure; | |
ffb9eb3d KV |
10549 | |
10550 | genlmsg_end(msg, hdr); | |
4c476991 | 10551 | return genlmsg_reply(msg, info); |
ffb9eb3d | 10552 | |
4c476991 | 10553 | nla_put_failure: |
ffb9eb3d | 10554 | err = -ENOBUFS; |
4c476991 | 10555 | free_msg: |
ffb9eb3d | 10556 | nlmsg_free(msg); |
ffb9eb3d KV |
10557 | return err; |
10558 | } | |
10559 | ||
94e860f1 JB |
10560 | static const struct nla_policy |
10561 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
4a4b8169 | 10562 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, |
d6dc1a38 JO |
10563 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
10564 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
10565 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
10566 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
10567 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
bee427b8 | 10568 | [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, |
d6dc1a38 JO |
10569 | }; |
10570 | ||
84f10708 | 10571 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 10572 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
10573 | { |
10574 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 10575 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 10576 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 10577 | |
d9d8b019 | 10578 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
10579 | return -EINVAL; |
10580 | ||
84f10708 TP |
10581 | if (!rdev->ops->set_cqm_txe_config) |
10582 | return -EOPNOTSUPP; | |
10583 | ||
10584 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
10585 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
10586 | return -EOPNOTSUPP; | |
10587 | ||
e35e4d28 | 10588 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
10589 | } |
10590 | ||
4a4b8169 AZ |
10591 | static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, |
10592 | struct net_device *dev) | |
10593 | { | |
10594 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10595 | s32 last, low, high; | |
10596 | u32 hyst; | |
1222a160 | 10597 | int i, n, low_index; |
4a4b8169 AZ |
10598 | int err; |
10599 | ||
10600 | /* RSSI reporting disabled? */ | |
10601 | if (!wdev->cqm_config) | |
10602 | return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); | |
10603 | ||
10604 | /* | |
10605 | * Obtain current RSSI value if possible, if not and no RSSI threshold | |
10606 | * event has been received yet, we should receive an event after a | |
10607 | * connection is established and enough beacons received to calculate | |
10608 | * the average. | |
10609 | */ | |
10610 | if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && | |
10611 | rdev->ops->get_station) { | |
73887fd9 | 10612 | struct station_info sinfo = {}; |
4a4b8169 AZ |
10613 | u8 *mac_addr; |
10614 | ||
10615 | mac_addr = wdev->current_bss->pub.bssid; | |
10616 | ||
73887fd9 JB |
10617 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
10618 | if (err) | |
4a4b8169 AZ |
10619 | return err; |
10620 | ||
397c657a | 10621 | if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) |
4a4b8169 | 10622 | wdev->cqm_config->last_rssi_event_value = |
73887fd9 | 10623 | (s8) sinfo.rx_beacon_signal_avg; |
4a4b8169 AZ |
10624 | } |
10625 | ||
10626 | last = wdev->cqm_config->last_rssi_event_value; | |
10627 | hyst = wdev->cqm_config->rssi_hyst; | |
10628 | n = wdev->cqm_config->n_rssi_thresholds; | |
10629 | ||
10630 | for (i = 0; i < n; i++) | |
10631 | if (last < wdev->cqm_config->rssi_thresholds[i]) | |
10632 | break; | |
10633 | ||
1222a160 MH |
10634 | low_index = i - 1; |
10635 | if (low_index >= 0) { | |
10636 | low_index = array_index_nospec(low_index, n); | |
10637 | low = wdev->cqm_config->rssi_thresholds[low_index] - hyst; | |
10638 | } else { | |
10639 | low = S32_MIN; | |
10640 | } | |
10641 | if (i < n) { | |
10642 | i = array_index_nospec(i, n); | |
10643 | high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1; | |
10644 | } else { | |
10645 | high = S32_MAX; | |
10646 | } | |
4a4b8169 AZ |
10647 | |
10648 | return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); | |
10649 | } | |
10650 | ||
d6dc1a38 | 10651 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
4a4b8169 AZ |
10652 | const s32 *thresholds, int n_thresholds, |
10653 | u32 hysteresis) | |
d6dc1a38 | 10654 | { |
4c476991 | 10655 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 10656 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 10657 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4a4b8169 AZ |
10658 | int i, err; |
10659 | s32 prev = S32_MIN; | |
d6dc1a38 | 10660 | |
4a4b8169 AZ |
10661 | /* Check all values negative and sorted */ |
10662 | for (i = 0; i < n_thresholds; i++) { | |
10663 | if (thresholds[i] > 0 || thresholds[i] <= prev) | |
10664 | return -EINVAL; | |
d6dc1a38 | 10665 | |
4a4b8169 AZ |
10666 | prev = thresholds[i]; |
10667 | } | |
d6dc1a38 | 10668 | |
074ac8df | 10669 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
10670 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
10671 | return -EOPNOTSUPP; | |
d6dc1a38 | 10672 | |
4a4b8169 AZ |
10673 | wdev_lock(wdev); |
10674 | cfg80211_cqm_config_free(wdev); | |
10675 | wdev_unlock(wdev); | |
10676 | ||
10677 | if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { | |
10678 | if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ | |
10679 | return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); | |
10680 | ||
10681 | return rdev_set_cqm_rssi_config(rdev, dev, | |
10682 | thresholds[0], hysteresis); | |
10683 | } | |
10684 | ||
10685 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
10686 | NL80211_EXT_FEATURE_CQM_RSSI_LIST)) | |
10687 | return -EOPNOTSUPP; | |
10688 | ||
10689 | if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ | |
10690 | n_thresholds = 0; | |
10691 | ||
10692 | wdev_lock(wdev); | |
10693 | if (n_thresholds) { | |
10694 | struct cfg80211_cqm_config *cqm_config; | |
10695 | ||
10696 | cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + | |
10697 | n_thresholds * sizeof(s32), GFP_KERNEL); | |
10698 | if (!cqm_config) { | |
10699 | err = -ENOMEM; | |
10700 | goto unlock; | |
10701 | } | |
10702 | ||
10703 | cqm_config->rssi_hyst = hysteresis; | |
10704 | cqm_config->n_rssi_thresholds = n_thresholds; | |
10705 | memcpy(cqm_config->rssi_thresholds, thresholds, | |
10706 | n_thresholds * sizeof(s32)); | |
10707 | ||
10708 | wdev->cqm_config = cqm_config; | |
10709 | } | |
10710 | ||
10711 | err = cfg80211_cqm_rssi_update(rdev, dev); | |
10712 | ||
10713 | unlock: | |
10714 | wdev_unlock(wdev); | |
10715 | ||
10716 | return err; | |
d6dc1a38 JO |
10717 | } |
10718 | ||
10719 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
10720 | { | |
10721 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
10722 | struct nlattr *cqm; | |
10723 | int err; | |
10724 | ||
10725 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
10726 | if (!cqm) |
10727 | return -EINVAL; | |
d6dc1a38 | 10728 | |
8cb08174 JB |
10729 | err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm, |
10730 | nl80211_attr_cqm_policy, | |
10731 | info->extack); | |
d6dc1a38 | 10732 | if (err) |
1da5fcc8 | 10733 | return err; |
d6dc1a38 JO |
10734 | |
10735 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
10736 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
4a4b8169 AZ |
10737 | const s32 *thresholds = |
10738 | nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
10739 | int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
1da5fcc8 | 10740 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
d6dc1a38 | 10741 | |
4a4b8169 AZ |
10742 | if (len % 4) |
10743 | return -EINVAL; | |
10744 | ||
10745 | return nl80211_set_cqm_rssi(info, thresholds, len / 4, | |
10746 | hysteresis); | |
1da5fcc8 JB |
10747 | } |
10748 | ||
10749 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
10750 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
10751 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
10752 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
10753 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
10754 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
10755 | ||
10756 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
10757 | } | |
10758 | ||
10759 | return -EINVAL; | |
d6dc1a38 JO |
10760 | } |
10761 | ||
6e0bd6c3 RL |
10762 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
10763 | { | |
10764 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10765 | struct net_device *dev = info->user_ptr[1]; | |
10766 | struct ocb_setup setup = {}; | |
10767 | int err; | |
10768 | ||
10769 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | |
10770 | if (err) | |
10771 | return err; | |
10772 | ||
10773 | return cfg80211_join_ocb(rdev, dev, &setup); | |
10774 | } | |
10775 | ||
10776 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | |
10777 | { | |
10778 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10779 | struct net_device *dev = info->user_ptr[1]; | |
10780 | ||
10781 | return cfg80211_leave_ocb(rdev, dev); | |
10782 | } | |
10783 | ||
29cbe68c JB |
10784 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
10785 | { | |
10786 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10787 | struct net_device *dev = info->user_ptr[1]; | |
10788 | struct mesh_config cfg; | |
c80d545d | 10789 | struct mesh_setup setup; |
29cbe68c JB |
10790 | int err; |
10791 | ||
10792 | /* start with default */ | |
10793 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 10794 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 10795 | |
24bdd9f4 | 10796 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 10797 | /* and parse parameters if given */ |
24bdd9f4 | 10798 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
10799 | if (err) |
10800 | return err; | |
10801 | } | |
10802 | ||
10803 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
10804 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
10805 | return -EINVAL; | |
10806 | ||
c80d545d JC |
10807 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
10808 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
10809 | ||
4bb62344 CYY |
10810 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
10811 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
10812 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
10813 | return -EINVAL; | |
10814 | ||
9bdbf04d MP |
10815 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
10816 | setup.beacon_interval = | |
10817 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
12d20fc9 | 10818 | |
0c317a02 PK |
10819 | err = cfg80211_validate_beacon_int(rdev, |
10820 | NL80211_IFTYPE_MESH_POINT, | |
10821 | setup.beacon_interval); | |
12d20fc9 PK |
10822 | if (err) |
10823 | return err; | |
9bdbf04d MP |
10824 | } |
10825 | ||
10826 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
10827 | setup.dtim_period = | |
10828 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
10829 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
10830 | return -EINVAL; | |
10831 | } | |
10832 | ||
c80d545d JC |
10833 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
10834 | /* parse additional setup parameters if given */ | |
10835 | err = nl80211_parse_mesh_setup(info, &setup); | |
10836 | if (err) | |
10837 | return err; | |
10838 | } | |
10839 | ||
d37bb18a TP |
10840 | if (setup.user_mpm) |
10841 | cfg.auto_open_plinks = false; | |
10842 | ||
cc1d2806 | 10843 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
10844 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
10845 | if (err) | |
10846 | return err; | |
cc1d2806 | 10847 | } else { |
188c1b3c | 10848 | /* __cfg80211_join_mesh() will sort it out */ |
683b6d3b | 10849 | setup.chandef.chan = NULL; |
cc1d2806 JB |
10850 | } |
10851 | ||
ffb3cf30 AN |
10852 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
10853 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
10854 | int n_rates = | |
10855 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
10856 | struct ieee80211_supported_band *sband; | |
10857 | ||
10858 | if (!setup.chandef.chan) | |
10859 | return -EINVAL; | |
10860 | ||
10861 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
10862 | ||
10863 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
10864 | &setup.basic_rates); | |
10865 | if (err) | |
10866 | return err; | |
10867 | } | |
10868 | ||
8564e382 JB |
10869 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
10870 | err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); | |
10871 | if (err) | |
10872 | return err; | |
10873 | ||
265698d7 JB |
10874 | if (!setup.chandef.chan) |
10875 | return -EINVAL; | |
10876 | ||
8564e382 JB |
10877 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
10878 | &setup.beacon_rate); | |
10879 | if (err) | |
10880 | return err; | |
10881 | } | |
10882 | ||
d37d49c2 BB |
10883 | setup.userspace_handles_dfs = |
10884 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
10885 | ||
1224f583 DK |
10886 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
10887 | int r = validate_pae_over_nl80211(rdev, info); | |
10888 | ||
10889 | if (r < 0) | |
10890 | return r; | |
10891 | ||
10892 | setup.control_port_over_nl80211 = true; | |
10893 | } | |
10894 | ||
188c1b3c DK |
10895 | wdev_lock(dev->ieee80211_ptr); |
10896 | err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); | |
10897 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) | |
10898 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; | |
10899 | wdev_unlock(dev->ieee80211_ptr); | |
10900 | ||
10901 | return err; | |
29cbe68c JB |
10902 | } |
10903 | ||
10904 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
10905 | { | |
10906 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10907 | struct net_device *dev = info->user_ptr[1]; | |
10908 | ||
10909 | return cfg80211_leave_mesh(rdev, dev); | |
10910 | } | |
10911 | ||
dfb89c56 | 10912 | #ifdef CONFIG_PM |
bb92d199 AK |
10913 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
10914 | struct cfg80211_registered_device *rdev) | |
10915 | { | |
6abb9cb9 | 10916 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
10917 | struct nlattr *nl_pats, *nl_pat; |
10918 | int i, pat_len; | |
10919 | ||
6abb9cb9 | 10920 | if (!wowlan->n_patterns) |
bb92d199 AK |
10921 | return 0; |
10922 | ||
ae0be8de | 10923 | nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
bb92d199 AK |
10924 | if (!nl_pats) |
10925 | return -ENOBUFS; | |
10926 | ||
6abb9cb9 | 10927 | for (i = 0; i < wowlan->n_patterns; i++) { |
ae0be8de | 10928 | nl_pat = nla_nest_start_noflag(msg, i + 1); |
bb92d199 AK |
10929 | if (!nl_pat) |
10930 | return -ENOBUFS; | |
6abb9cb9 | 10931 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 10932 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 10933 | wowlan->patterns[i].mask) || |
50ac6607 AK |
10934 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
10935 | wowlan->patterns[i].pattern) || | |
10936 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 10937 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
10938 | return -ENOBUFS; |
10939 | nla_nest_end(msg, nl_pat); | |
10940 | } | |
10941 | nla_nest_end(msg, nl_pats); | |
10942 | ||
10943 | return 0; | |
10944 | } | |
10945 | ||
2a0e047e JB |
10946 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
10947 | struct cfg80211_wowlan_tcp *tcp) | |
10948 | { | |
10949 | struct nlattr *nl_tcp; | |
10950 | ||
10951 | if (!tcp) | |
10952 | return 0; | |
10953 | ||
ae0be8de MK |
10954 | nl_tcp = nla_nest_start_noflag(msg, |
10955 | NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
2a0e047e JB |
10956 | if (!nl_tcp) |
10957 | return -ENOBUFS; | |
10958 | ||
930345ea JB |
10959 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
10960 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
2a0e047e JB |
10961 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
10962 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
10963 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
10964 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
10965 | tcp->payload_len, tcp->payload) || | |
10966 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
10967 | tcp->data_interval) || | |
10968 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
10969 | tcp->wake_len, tcp->wake_data) || | |
10970 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
10971 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
10972 | return -ENOBUFS; | |
10973 | ||
10974 | if (tcp->payload_seq.len && | |
10975 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
10976 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
10977 | return -ENOBUFS; | |
10978 | ||
10979 | if (tcp->payload_tok.len && | |
10980 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
10981 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
10982 | &tcp->payload_tok)) | |
10983 | return -ENOBUFS; | |
10984 | ||
e248ad30 JB |
10985 | nla_nest_end(msg, nl_tcp); |
10986 | ||
2a0e047e JB |
10987 | return 0; |
10988 | } | |
10989 | ||
75453ccb LC |
10990 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
10991 | struct cfg80211_sched_scan_request *req) | |
10992 | { | |
3b06d277 | 10993 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
75453ccb LC |
10994 | int i; |
10995 | ||
10996 | if (!req) | |
10997 | return 0; | |
10998 | ||
ae0be8de | 10999 | nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
75453ccb LC |
11000 | if (!nd) |
11001 | return -ENOBUFS; | |
11002 | ||
3b06d277 AS |
11003 | if (req->n_scan_plans == 1 && |
11004 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, | |
11005 | req->scan_plans[0].interval * 1000)) | |
75453ccb LC |
11006 | return -ENOBUFS; |
11007 | ||
21fea567 LC |
11008 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
11009 | return -ENOBUFS; | |
11010 | ||
bf95ecdb | 11011 | if (req->relative_rssi_set) { |
11012 | struct nl80211_bss_select_rssi_adjust rssi_adjust; | |
11013 | ||
11014 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, | |
11015 | req->relative_rssi)) | |
11016 | return -ENOBUFS; | |
11017 | ||
11018 | rssi_adjust.band = req->rssi_adjust.band; | |
11019 | rssi_adjust.delta = req->rssi_adjust.delta; | |
11020 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, | |
11021 | sizeof(rssi_adjust), &rssi_adjust)) | |
11022 | return -ENOBUFS; | |
11023 | } | |
11024 | ||
ae0be8de | 11025 | freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
75453ccb LC |
11026 | if (!freqs) |
11027 | return -ENOBUFS; | |
11028 | ||
53b18980 JB |
11029 | for (i = 0; i < req->n_channels; i++) { |
11030 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
11031 | return -ENOBUFS; | |
11032 | } | |
75453ccb LC |
11033 | |
11034 | nla_nest_end(msg, freqs); | |
11035 | ||
11036 | if (req->n_match_sets) { | |
ae0be8de MK |
11037 | matches = nla_nest_start_noflag(msg, |
11038 | NL80211_ATTR_SCHED_SCAN_MATCH); | |
76e1fb4b JB |
11039 | if (!matches) |
11040 | return -ENOBUFS; | |
11041 | ||
75453ccb | 11042 | for (i = 0; i < req->n_match_sets; i++) { |
ae0be8de | 11043 | match = nla_nest_start_noflag(msg, i); |
76e1fb4b JB |
11044 | if (!match) |
11045 | return -ENOBUFS; | |
11046 | ||
53b18980 JB |
11047 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
11048 | req->match_sets[i].ssid.ssid_len, | |
11049 | req->match_sets[i].ssid.ssid)) | |
11050 | return -ENOBUFS; | |
75453ccb LC |
11051 | nla_nest_end(msg, match); |
11052 | } | |
11053 | nla_nest_end(msg, matches); | |
11054 | } | |
11055 | ||
ae0be8de | 11056 | scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
3b06d277 AS |
11057 | if (!scan_plans) |
11058 | return -ENOBUFS; | |
11059 | ||
11060 | for (i = 0; i < req->n_scan_plans; i++) { | |
ae0be8de | 11061 | scan_plan = nla_nest_start_noflag(msg, i + 1); |
76e1fb4b JB |
11062 | if (!scan_plan) |
11063 | return -ENOBUFS; | |
11064 | ||
67626964 | 11065 | if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
3b06d277 AS |
11066 | req->scan_plans[i].interval) || |
11067 | (req->scan_plans[i].iterations && | |
11068 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, | |
11069 | req->scan_plans[i].iterations))) | |
11070 | return -ENOBUFS; | |
11071 | nla_nest_end(msg, scan_plan); | |
11072 | } | |
11073 | nla_nest_end(msg, scan_plans); | |
11074 | ||
75453ccb LC |
11075 | nla_nest_end(msg, nd); |
11076 | ||
11077 | return 0; | |
11078 | } | |
11079 | ||
ff1b6e69 JB |
11080 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
11081 | { | |
11082 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11083 | struct sk_buff *msg; | |
11084 | void *hdr; | |
2a0e047e | 11085 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 11086 | |
964dc9e2 | 11087 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
11088 | return -EOPNOTSUPP; |
11089 | ||
6abb9cb9 | 11090 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 11091 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
11092 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
11093 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
11094 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
11095 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
11096 | } |
11097 | ||
11098 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
11099 | if (!msg) |
11100 | return -ENOMEM; | |
11101 | ||
15e47304 | 11102 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
11103 | NL80211_CMD_GET_WOWLAN); |
11104 | if (!hdr) | |
11105 | goto nla_put_failure; | |
11106 | ||
6abb9cb9 | 11107 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
11108 | struct nlattr *nl_wowlan; |
11109 | ||
ae0be8de MK |
11110 | nl_wowlan = nla_nest_start_noflag(msg, |
11111 | NL80211_ATTR_WOWLAN_TRIGGERS); | |
ff1b6e69 JB |
11112 | if (!nl_wowlan) |
11113 | goto nla_put_failure; | |
11114 | ||
6abb9cb9 | 11115 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 11116 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 11117 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 11118 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 11119 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 11120 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 11121 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 11122 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 11123 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 11124 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 11125 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 11126 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 11127 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
11128 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
11129 | goto nla_put_failure; | |
2a0e047e | 11130 | |
bb92d199 AK |
11131 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
11132 | goto nla_put_failure; | |
2a0e047e | 11133 | |
6abb9cb9 JB |
11134 | if (nl80211_send_wowlan_tcp(msg, |
11135 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e | 11136 | goto nla_put_failure; |
75453ccb LC |
11137 | |
11138 | if (nl80211_send_wowlan_nd( | |
11139 | msg, | |
11140 | rdev->wiphy.wowlan_config->nd_config)) | |
11141 | goto nla_put_failure; | |
2a0e047e | 11142 | |
ff1b6e69 JB |
11143 | nla_nest_end(msg, nl_wowlan); |
11144 | } | |
11145 | ||
11146 | genlmsg_end(msg, hdr); | |
11147 | return genlmsg_reply(msg, info); | |
11148 | ||
11149 | nla_put_failure: | |
11150 | nlmsg_free(msg); | |
11151 | return -ENOBUFS; | |
11152 | } | |
11153 | ||
2a0e047e JB |
11154 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
11155 | struct nlattr *attr, | |
11156 | struct cfg80211_wowlan *trig) | |
11157 | { | |
11158 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
11159 | struct cfg80211_wowlan_tcp *cfg; | |
11160 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
11161 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
11162 | u32 size; | |
11163 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
11164 | int err, port; | |
11165 | ||
964dc9e2 | 11166 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
11167 | return -EINVAL; |
11168 | ||
8cb08174 JB |
11169 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr, |
11170 | nl80211_wowlan_tcp_policy, NULL); | |
2a0e047e JB |
11171 | if (err) |
11172 | return err; | |
11173 | ||
11174 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
11175 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
11176 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
11177 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
11178 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
11179 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
11180 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
11181 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
11182 | return -EINVAL; | |
11183 | ||
11184 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 11185 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
11186 | return -EINVAL; |
11187 | ||
11188 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 11189 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 11190 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
11191 | return -EINVAL; |
11192 | ||
11193 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 11194 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
11195 | return -EINVAL; |
11196 | ||
11197 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
11198 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
11199 | return -EINVAL; | |
11200 | ||
11201 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
11202 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
11203 | ||
11204 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
11205 | tokens_size = tokln - sizeof(*tok); | |
11206 | ||
11207 | if (!tok->len || tokens_size % tok->len) | |
11208 | return -EINVAL; | |
964dc9e2 | 11209 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 11210 | return -EINVAL; |
964dc9e2 | 11211 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 11212 | return -EINVAL; |
964dc9e2 | 11213 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 11214 | return -EINVAL; |
964dc9e2 | 11215 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
11216 | return -EINVAL; |
11217 | if (tok->offset + tok->len > data_size) | |
11218 | return -EINVAL; | |
11219 | } | |
11220 | ||
11221 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
11222 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 11223 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
11224 | return -EINVAL; |
11225 | if (seq->len == 0 || seq->len > 4) | |
11226 | return -EINVAL; | |
11227 | if (seq->len + seq->offset > data_size) | |
11228 | return -EINVAL; | |
11229 | } | |
11230 | ||
11231 | size = sizeof(*cfg); | |
11232 | size += data_size; | |
11233 | size += wake_size + wake_mask_size; | |
11234 | size += tokens_size; | |
11235 | ||
11236 | cfg = kzalloc(size, GFP_KERNEL); | |
11237 | if (!cfg) | |
11238 | return -ENOMEM; | |
67b61f6c JB |
11239 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
11240 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
2a0e047e JB |
11241 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
11242 | ETH_ALEN); | |
11243 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
11244 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
11245 | else | |
11246 | port = 0; | |
11247 | #ifdef CONFIG_INET | |
11248 | /* allocate a socket and port for it and use it */ | |
11249 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
11250 | IPPROTO_TCP, &cfg->sock, 1); | |
11251 | if (err) { | |
11252 | kfree(cfg); | |
11253 | return err; | |
11254 | } | |
11255 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
11256 | sock_release(cfg->sock); | |
11257 | kfree(cfg); | |
11258 | return -EADDRINUSE; | |
11259 | } | |
11260 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
11261 | #else | |
11262 | if (!port) { | |
11263 | kfree(cfg); | |
11264 | return -EINVAL; | |
11265 | } | |
11266 | cfg->src_port = port; | |
11267 | #endif | |
11268 | ||
11269 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
11270 | cfg->payload_len = data_size; | |
11271 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
11272 | memcpy((void *)cfg->payload, | |
11273 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
11274 | data_size); | |
11275 | if (seq) | |
11276 | cfg->payload_seq = *seq; | |
11277 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
11278 | cfg->wake_len = wake_size; | |
11279 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
11280 | memcpy((void *)cfg->wake_data, | |
11281 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
11282 | wake_size); | |
11283 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
11284 | data_size + wake_size; | |
11285 | memcpy((void *)cfg->wake_mask, | |
11286 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
11287 | wake_mask_size); | |
11288 | if (tok) { | |
11289 | cfg->tokens_size = tokens_size; | |
11290 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
11291 | } | |
11292 | ||
11293 | trig->tcp = cfg; | |
11294 | ||
11295 | return 0; | |
11296 | } | |
11297 | ||
8cd4d456 LC |
11298 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
11299 | const struct wiphy_wowlan_support *wowlan, | |
11300 | struct nlattr *attr, | |
11301 | struct cfg80211_wowlan *trig) | |
11302 | { | |
11303 | struct nlattr **tb; | |
11304 | int err; | |
11305 | ||
6396bb22 | 11306 | tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
8cd4d456 LC |
11307 | if (!tb) |
11308 | return -ENOMEM; | |
11309 | ||
11310 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | |
11311 | err = -EOPNOTSUPP; | |
11312 | goto out; | |
11313 | } | |
11314 | ||
8cb08174 JB |
11315 | err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr, |
11316 | nl80211_policy, NULL); | |
8cd4d456 LC |
11317 | if (err) |
11318 | goto out; | |
11319 | ||
aad1e812 AVS |
11320 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, |
11321 | wowlan->max_nd_match_sets); | |
8cd4d456 LC |
11322 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
11323 | if (err) | |
11324 | trig->nd_config = NULL; | |
11325 | ||
11326 | out: | |
11327 | kfree(tb); | |
11328 | return err; | |
11329 | } | |
11330 | ||
ff1b6e69 JB |
11331 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
11332 | { | |
11333 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11334 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 11335 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 11336 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 11337 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 11338 | int err, i; |
6abb9cb9 | 11339 | bool prev_enabled = rdev->wiphy.wowlan_config; |
98fc4386 | 11340 | bool regular = false; |
ff1b6e69 | 11341 | |
964dc9e2 | 11342 | if (!wowlan) |
ff1b6e69 JB |
11343 | return -EOPNOTSUPP; |
11344 | ||
ae33bd81 JB |
11345 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
11346 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 11347 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
11348 | goto set_wakeup; |
11349 | } | |
ff1b6e69 | 11350 | |
8cb08174 JB |
11351 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG, |
11352 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], | |
11353 | nl80211_wowlan_policy, info->extack); | |
ff1b6e69 JB |
11354 | if (err) |
11355 | return err; | |
11356 | ||
11357 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
11358 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
11359 | return -EINVAL; | |
11360 | new_triggers.any = true; | |
11361 | } | |
11362 | ||
11363 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
11364 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
11365 | return -EINVAL; | |
11366 | new_triggers.disconnect = true; | |
98fc4386 | 11367 | regular = true; |
ff1b6e69 JB |
11368 | } |
11369 | ||
11370 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
11371 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
11372 | return -EINVAL; | |
11373 | new_triggers.magic_pkt = true; | |
98fc4386 | 11374 | regular = true; |
ff1b6e69 JB |
11375 | } |
11376 | ||
77dbbb13 JB |
11377 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
11378 | return -EINVAL; | |
11379 | ||
11380 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
11381 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
11382 | return -EINVAL; | |
11383 | new_triggers.gtk_rekey_failure = true; | |
98fc4386 | 11384 | regular = true; |
77dbbb13 JB |
11385 | } |
11386 | ||
11387 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
11388 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
11389 | return -EINVAL; | |
11390 | new_triggers.eap_identity_req = true; | |
98fc4386 | 11391 | regular = true; |
77dbbb13 JB |
11392 | } |
11393 | ||
11394 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
11395 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
11396 | return -EINVAL; | |
11397 | new_triggers.four_way_handshake = true; | |
98fc4386 | 11398 | regular = true; |
77dbbb13 JB |
11399 | } |
11400 | ||
11401 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
11402 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
11403 | return -EINVAL; | |
11404 | new_triggers.rfkill_release = true; | |
98fc4386 | 11405 | regular = true; |
77dbbb13 JB |
11406 | } |
11407 | ||
ff1b6e69 JB |
11408 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
11409 | struct nlattr *pat; | |
11410 | int n_patterns = 0; | |
bb92d199 | 11411 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 11412 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 | 11413 | |
98fc4386 JB |
11414 | regular = true; |
11415 | ||
ff1b6e69 JB |
11416 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
11417 | rem) | |
11418 | n_patterns++; | |
11419 | if (n_patterns > wowlan->n_patterns) | |
11420 | return -EINVAL; | |
11421 | ||
11422 | new_triggers.patterns = kcalloc(n_patterns, | |
11423 | sizeof(new_triggers.patterns[0]), | |
11424 | GFP_KERNEL); | |
11425 | if (!new_triggers.patterns) | |
11426 | return -ENOMEM; | |
11427 | ||
11428 | new_triggers.n_patterns = n_patterns; | |
11429 | i = 0; | |
11430 | ||
11431 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
11432 | rem) { | |
922bd80f JB |
11433 | u8 *mask_pat; |
11434 | ||
8cb08174 JB |
11435 | err = nla_parse_nested_deprecated(pat_tb, |
11436 | MAX_NL80211_PKTPAT, | |
11437 | pat, | |
11438 | nl80211_packet_pattern_policy, | |
11439 | info->extack); | |
95bca62f JB |
11440 | if (err) |
11441 | goto error; | |
11442 | ||
ff1b6e69 | 11443 | err = -EINVAL; |
50ac6607 AK |
11444 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
11445 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 11446 | goto error; |
50ac6607 | 11447 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 11448 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 11449 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
11450 | goto error; |
11451 | if (pat_len > wowlan->pattern_max_len || | |
11452 | pat_len < wowlan->pattern_min_len) | |
11453 | goto error; | |
11454 | ||
50ac6607 | 11455 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
11456 | pkt_offset = 0; |
11457 | else | |
11458 | pkt_offset = nla_get_u32( | |
50ac6607 | 11459 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
11460 | if (pkt_offset > wowlan->max_pkt_offset) |
11461 | goto error; | |
11462 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
11463 | ||
922bd80f JB |
11464 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
11465 | if (!mask_pat) { | |
ff1b6e69 JB |
11466 | err = -ENOMEM; |
11467 | goto error; | |
11468 | } | |
922bd80f JB |
11469 | new_triggers.patterns[i].mask = mask_pat; |
11470 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 11471 | mask_len); |
922bd80f JB |
11472 | mask_pat += mask_len; |
11473 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 11474 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 11475 | memcpy(mask_pat, |
50ac6607 | 11476 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
11477 | pat_len); |
11478 | i++; | |
11479 | } | |
11480 | } | |
11481 | ||
2a0e047e | 11482 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
98fc4386 | 11483 | regular = true; |
2a0e047e JB |
11484 | err = nl80211_parse_wowlan_tcp( |
11485 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
11486 | &new_triggers); | |
11487 | if (err) | |
11488 | goto error; | |
11489 | } | |
11490 | ||
8cd4d456 | 11491 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
98fc4386 | 11492 | regular = true; |
8cd4d456 LC |
11493 | err = nl80211_parse_wowlan_nd( |
11494 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | |
11495 | &new_triggers); | |
11496 | if (err) | |
11497 | goto error; | |
11498 | } | |
11499 | ||
98fc4386 JB |
11500 | /* The 'any' trigger means the device continues operating more or less |
11501 | * as in its normal operation mode and wakes up the host on most of the | |
11502 | * normal interrupts (like packet RX, ...) | |
11503 | * It therefore makes little sense to combine with the more constrained | |
11504 | * wakeup trigger modes. | |
11505 | */ | |
11506 | if (new_triggers.any && regular) { | |
11507 | err = -EINVAL; | |
11508 | goto error; | |
11509 | } | |
11510 | ||
ae33bd81 JB |
11511 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
11512 | if (!ntrig) { | |
11513 | err = -ENOMEM; | |
11514 | goto error; | |
ff1b6e69 | 11515 | } |
ae33bd81 | 11516 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 11517 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 11518 | |
ae33bd81 | 11519 | set_wakeup: |
6abb9cb9 JB |
11520 | if (rdev->ops->set_wakeup && |
11521 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
11522 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 11523 | |
ff1b6e69 JB |
11524 | return 0; |
11525 | error: | |
11526 | for (i = 0; i < new_triggers.n_patterns; i++) | |
11527 | kfree(new_triggers.patterns[i].mask); | |
11528 | kfree(new_triggers.patterns); | |
2a0e047e JB |
11529 | if (new_triggers.tcp && new_triggers.tcp->sock) |
11530 | sock_release(new_triggers.tcp->sock); | |
11531 | kfree(new_triggers.tcp); | |
e5dbe070 | 11532 | kfree(new_triggers.nd_config); |
ff1b6e69 JB |
11533 | return err; |
11534 | } | |
dfb89c56 | 11535 | #endif |
ff1b6e69 | 11536 | |
be29b99a AK |
11537 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
11538 | struct cfg80211_registered_device *rdev) | |
11539 | { | |
11540 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
11541 | int i, j, pat_len; | |
11542 | struct cfg80211_coalesce_rules *rule; | |
11543 | ||
11544 | if (!rdev->coalesce->n_rules) | |
11545 | return 0; | |
11546 | ||
ae0be8de | 11547 | nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE); |
be29b99a AK |
11548 | if (!nl_rules) |
11549 | return -ENOBUFS; | |
11550 | ||
11551 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
ae0be8de | 11552 | nl_rule = nla_nest_start_noflag(msg, i + 1); |
be29b99a AK |
11553 | if (!nl_rule) |
11554 | return -ENOBUFS; | |
11555 | ||
11556 | rule = &rdev->coalesce->rules[i]; | |
11557 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
11558 | rule->delay)) | |
11559 | return -ENOBUFS; | |
11560 | ||
11561 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
11562 | rule->condition)) | |
11563 | return -ENOBUFS; | |
11564 | ||
ae0be8de MK |
11565 | nl_pats = nla_nest_start_noflag(msg, |
11566 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
be29b99a AK |
11567 | if (!nl_pats) |
11568 | return -ENOBUFS; | |
11569 | ||
11570 | for (j = 0; j < rule->n_patterns; j++) { | |
ae0be8de | 11571 | nl_pat = nla_nest_start_noflag(msg, j + 1); |
be29b99a AK |
11572 | if (!nl_pat) |
11573 | return -ENOBUFS; | |
11574 | pat_len = rule->patterns[j].pattern_len; | |
11575 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
11576 | DIV_ROUND_UP(pat_len, 8), | |
11577 | rule->patterns[j].mask) || | |
11578 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
11579 | rule->patterns[j].pattern) || | |
11580 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
11581 | rule->patterns[j].pkt_offset)) | |
11582 | return -ENOBUFS; | |
11583 | nla_nest_end(msg, nl_pat); | |
11584 | } | |
11585 | nla_nest_end(msg, nl_pats); | |
11586 | nla_nest_end(msg, nl_rule); | |
11587 | } | |
11588 | nla_nest_end(msg, nl_rules); | |
11589 | ||
11590 | return 0; | |
11591 | } | |
11592 | ||
11593 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
11594 | { | |
11595 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11596 | struct sk_buff *msg; | |
11597 | void *hdr; | |
11598 | ||
11599 | if (!rdev->wiphy.coalesce) | |
11600 | return -EOPNOTSUPP; | |
11601 | ||
11602 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11603 | if (!msg) | |
11604 | return -ENOMEM; | |
11605 | ||
11606 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
11607 | NL80211_CMD_GET_COALESCE); | |
11608 | if (!hdr) | |
11609 | goto nla_put_failure; | |
11610 | ||
11611 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
11612 | goto nla_put_failure; | |
11613 | ||
11614 | genlmsg_end(msg, hdr); | |
11615 | return genlmsg_reply(msg, info); | |
11616 | ||
11617 | nla_put_failure: | |
11618 | nlmsg_free(msg); | |
11619 | return -ENOBUFS; | |
11620 | } | |
11621 | ||
11622 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
11623 | { | |
11624 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
11625 | int i, j; | |
11626 | struct cfg80211_coalesce_rules *rule; | |
11627 | ||
11628 | if (!coalesce) | |
11629 | return; | |
11630 | ||
11631 | for (i = 0; i < coalesce->n_rules; i++) { | |
11632 | rule = &coalesce->rules[i]; | |
11633 | for (j = 0; j < rule->n_patterns; j++) | |
11634 | kfree(rule->patterns[j].mask); | |
11635 | kfree(rule->patterns); | |
11636 | } | |
11637 | kfree(coalesce->rules); | |
11638 | kfree(coalesce); | |
11639 | rdev->coalesce = NULL; | |
11640 | } | |
11641 | ||
11642 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
11643 | struct nlattr *rule, | |
11644 | struct cfg80211_coalesce_rules *new_rule) | |
11645 | { | |
11646 | int err, i; | |
11647 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
11648 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
11649 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
11650 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
11651 | ||
8cb08174 JB |
11652 | err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX, |
11653 | rule, nl80211_coalesce_policy, NULL); | |
be29b99a AK |
11654 | if (err) |
11655 | return err; | |
11656 | ||
11657 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
11658 | new_rule->delay = | |
11659 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
11660 | if (new_rule->delay > coalesce->max_delay) | |
11661 | return -EINVAL; | |
11662 | ||
11663 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
11664 | new_rule->condition = | |
11665 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
be29b99a AK |
11666 | |
11667 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
11668 | return -EINVAL; | |
11669 | ||
11670 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
11671 | rem) | |
11672 | n_patterns++; | |
11673 | if (n_patterns > coalesce->n_patterns) | |
11674 | return -EINVAL; | |
11675 | ||
11676 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
11677 | GFP_KERNEL); | |
11678 | if (!new_rule->patterns) | |
11679 | return -ENOMEM; | |
11680 | ||
11681 | new_rule->n_patterns = n_patterns; | |
11682 | i = 0; | |
11683 | ||
11684 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
11685 | rem) { | |
922bd80f JB |
11686 | u8 *mask_pat; |
11687 | ||
8cb08174 JB |
11688 | err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT, |
11689 | pat, | |
11690 | nl80211_packet_pattern_policy, | |
11691 | NULL); | |
95bca62f JB |
11692 | if (err) |
11693 | return err; | |
11694 | ||
be29b99a AK |
11695 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
11696 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
11697 | return -EINVAL; | |
11698 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
11699 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
11700 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
11701 | return -EINVAL; | |
11702 | if (pat_len > coalesce->pattern_max_len || | |
11703 | pat_len < coalesce->pattern_min_len) | |
11704 | return -EINVAL; | |
11705 | ||
11706 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
11707 | pkt_offset = 0; | |
11708 | else | |
11709 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
11710 | if (pkt_offset > coalesce->max_pkt_offset) | |
11711 | return -EINVAL; | |
11712 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
11713 | ||
922bd80f JB |
11714 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
11715 | if (!mask_pat) | |
be29b99a | 11716 | return -ENOMEM; |
922bd80f JB |
11717 | |
11718 | new_rule->patterns[i].mask = mask_pat; | |
11719 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
11720 | mask_len); | |
11721 | ||
11722 | mask_pat += mask_len; | |
11723 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 11724 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
11725 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
11726 | pat_len); | |
be29b99a AK |
11727 | i++; |
11728 | } | |
11729 | ||
11730 | return 0; | |
11731 | } | |
11732 | ||
11733 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
11734 | { | |
11735 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11736 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
11737 | struct cfg80211_coalesce new_coalesce = {}; | |
11738 | struct cfg80211_coalesce *n_coalesce; | |
11739 | int err, rem_rule, n_rules = 0, i, j; | |
11740 | struct nlattr *rule; | |
11741 | struct cfg80211_coalesce_rules *tmp_rule; | |
11742 | ||
11743 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
11744 | return -EOPNOTSUPP; | |
11745 | ||
11746 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
11747 | cfg80211_rdev_free_coalesce(rdev); | |
a1056b1b | 11748 | rdev_set_coalesce(rdev, NULL); |
be29b99a AK |
11749 | return 0; |
11750 | } | |
11751 | ||
11752 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
11753 | rem_rule) | |
11754 | n_rules++; | |
11755 | if (n_rules > coalesce->n_rules) | |
11756 | return -EINVAL; | |
11757 | ||
11758 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
11759 | GFP_KERNEL); | |
11760 | if (!new_coalesce.rules) | |
11761 | return -ENOMEM; | |
11762 | ||
11763 | new_coalesce.n_rules = n_rules; | |
11764 | i = 0; | |
11765 | ||
11766 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
11767 | rem_rule) { | |
11768 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
11769 | &new_coalesce.rules[i]); | |
11770 | if (err) | |
11771 | goto error; | |
11772 | ||
11773 | i++; | |
11774 | } | |
11775 | ||
a1056b1b | 11776 | err = rdev_set_coalesce(rdev, &new_coalesce); |
be29b99a AK |
11777 | if (err) |
11778 | goto error; | |
11779 | ||
11780 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
11781 | if (!n_coalesce) { | |
11782 | err = -ENOMEM; | |
11783 | goto error; | |
11784 | } | |
11785 | cfg80211_rdev_free_coalesce(rdev); | |
11786 | rdev->coalesce = n_coalesce; | |
11787 | ||
11788 | return 0; | |
11789 | error: | |
11790 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
11791 | tmp_rule = &new_coalesce.rules[i]; | |
11792 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
11793 | kfree(tmp_rule->patterns[j].mask); | |
11794 | kfree(tmp_rule->patterns); | |
11795 | } | |
11796 | kfree(new_coalesce.rules); | |
11797 | ||
11798 | return err; | |
11799 | } | |
11800 | ||
e5497d76 JB |
11801 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
11802 | { | |
11803 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11804 | struct net_device *dev = info->user_ptr[1]; | |
11805 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11806 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
11807 | struct cfg80211_gtk_rekey_data rekey_data; | |
11808 | int err; | |
11809 | ||
11810 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
11811 | return -EINVAL; | |
11812 | ||
8cb08174 JB |
11813 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA, |
11814 | info->attrs[NL80211_ATTR_REKEY_DATA], | |
11815 | nl80211_rekey_policy, info->extack); | |
e5497d76 JB |
11816 | if (err) |
11817 | return err; | |
11818 | ||
e785fa0a VD |
11819 | if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || |
11820 | !tb[NL80211_REKEY_DATA_KCK]) | |
11821 | return -EINVAL; | |
e5497d76 JB |
11822 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
11823 | return -ERANGE; | |
11824 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
11825 | return -ERANGE; | |
11826 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
11827 | return -ERANGE; | |
11828 | ||
78f686ca JB |
11829 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
11830 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
11831 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
e5497d76 JB |
11832 | |
11833 | wdev_lock(wdev); | |
11834 | if (!wdev->current_bss) { | |
11835 | err = -ENOTCONN; | |
11836 | goto out; | |
11837 | } | |
11838 | ||
11839 | if (!rdev->ops->set_rekey_data) { | |
11840 | err = -EOPNOTSUPP; | |
11841 | goto out; | |
11842 | } | |
11843 | ||
e35e4d28 | 11844 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
11845 | out: |
11846 | wdev_unlock(wdev); | |
11847 | return err; | |
11848 | } | |
11849 | ||
28946da7 JB |
11850 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
11851 | struct genl_info *info) | |
11852 | { | |
11853 | struct net_device *dev = info->user_ptr[1]; | |
11854 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11855 | ||
11856 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
11857 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
11858 | return -EINVAL; | |
11859 | ||
15e47304 | 11860 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
11861 | return -EBUSY; |
11862 | ||
15e47304 | 11863 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
11864 | return 0; |
11865 | } | |
11866 | ||
7f6cf311 JB |
11867 | static int nl80211_probe_client(struct sk_buff *skb, |
11868 | struct genl_info *info) | |
11869 | { | |
11870 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11871 | struct net_device *dev = info->user_ptr[1]; | |
11872 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11873 | struct sk_buff *msg; | |
11874 | void *hdr; | |
11875 | const u8 *addr; | |
11876 | u64 cookie; | |
11877 | int err; | |
11878 | ||
11879 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
11880 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
11881 | return -EOPNOTSUPP; | |
11882 | ||
11883 | if (!info->attrs[NL80211_ATTR_MAC]) | |
11884 | return -EINVAL; | |
11885 | ||
11886 | if (!rdev->ops->probe_client) | |
11887 | return -EOPNOTSUPP; | |
11888 | ||
11889 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11890 | if (!msg) | |
11891 | return -ENOMEM; | |
11892 | ||
15e47304 | 11893 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 11894 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
11895 | if (!hdr) { |
11896 | err = -ENOBUFS; | |
7f6cf311 JB |
11897 | goto free_msg; |
11898 | } | |
11899 | ||
11900 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
11901 | ||
e35e4d28 | 11902 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
11903 | if (err) |
11904 | goto free_msg; | |
11905 | ||
2dad624e ND |
11906 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
11907 | NL80211_ATTR_PAD)) | |
9360ffd1 | 11908 | goto nla_put_failure; |
7f6cf311 JB |
11909 | |
11910 | genlmsg_end(msg, hdr); | |
11911 | ||
11912 | return genlmsg_reply(msg, info); | |
11913 | ||
11914 | nla_put_failure: | |
11915 | err = -ENOBUFS; | |
11916 | free_msg: | |
11917 | nlmsg_free(msg); | |
11918 | return err; | |
11919 | } | |
11920 | ||
5e760230 JB |
11921 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
11922 | { | |
11923 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
11924 | struct cfg80211_beacon_registration *reg, *nreg; |
11925 | int rv; | |
5e760230 JB |
11926 | |
11927 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
11928 | return -EOPNOTSUPP; | |
11929 | ||
37c73b5f BG |
11930 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
11931 | if (!nreg) | |
11932 | return -ENOMEM; | |
11933 | ||
11934 | /* First, check if already registered. */ | |
11935 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
11936 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
11937 | if (reg->nlportid == info->snd_portid) { | |
11938 | rv = -EALREADY; | |
11939 | goto out_err; | |
11940 | } | |
11941 | } | |
11942 | /* Add it to the list */ | |
11943 | nreg->nlportid = info->snd_portid; | |
11944 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 11945 | |
37c73b5f | 11946 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
11947 | |
11948 | return 0; | |
37c73b5f BG |
11949 | out_err: |
11950 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
11951 | kfree(nreg); | |
11952 | return rv; | |
5e760230 JB |
11953 | } |
11954 | ||
98104fde JB |
11955 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
11956 | { | |
11957 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11958 | struct wireless_dev *wdev = info->user_ptr[1]; | |
11959 | int err; | |
11960 | ||
11961 | if (!rdev->ops->start_p2p_device) | |
11962 | return -EOPNOTSUPP; | |
11963 | ||
11964 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
11965 | return -EOPNOTSUPP; | |
11966 | ||
73c7da3d | 11967 | if (wdev_running(wdev)) |
98104fde JB |
11968 | return 0; |
11969 | ||
b6a55015 LC |
11970 | if (rfkill_blocked(rdev->rfkill)) |
11971 | return -ERFKILL; | |
98104fde | 11972 | |
eeb126e9 | 11973 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
11974 | if (err) |
11975 | return err; | |
11976 | ||
73c7da3d | 11977 | wdev->is_running = true; |
98104fde | 11978 | rdev->opencount++; |
98104fde JB |
11979 | |
11980 | return 0; | |
11981 | } | |
11982 | ||
11983 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
11984 | { | |
11985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11986 | struct wireless_dev *wdev = info->user_ptr[1]; | |
11987 | ||
11988 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
11989 | return -EOPNOTSUPP; | |
11990 | ||
11991 | if (!rdev->ops->stop_p2p_device) | |
11992 | return -EOPNOTSUPP; | |
11993 | ||
f9f47529 | 11994 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
11995 | |
11996 | return 0; | |
11997 | } | |
11998 | ||
cb3b7d87 AB |
11999 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
12000 | { | |
12001 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12002 | struct wireless_dev *wdev = info->user_ptr[1]; | |
12003 | struct cfg80211_nan_conf conf = {}; | |
12004 | int err; | |
12005 | ||
12006 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
12007 | return -EOPNOTSUPP; | |
12008 | ||
eeb04a96 | 12009 | if (wdev_running(wdev)) |
cb3b7d87 AB |
12010 | return -EEXIST; |
12011 | ||
12012 | if (rfkill_blocked(rdev->rfkill)) | |
12013 | return -ERFKILL; | |
12014 | ||
12015 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) | |
12016 | return -EINVAL; | |
12017 | ||
cb3b7d87 AB |
12018 | conf.master_pref = |
12019 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); | |
cb3b7d87 | 12020 | |
8585989d LC |
12021 | if (info->attrs[NL80211_ATTR_BANDS]) { |
12022 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); | |
12023 | ||
12024 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) | |
12025 | return -EOPNOTSUPP; | |
12026 | ||
12027 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) | |
12028 | return -EINVAL; | |
12029 | ||
12030 | conf.bands = bands; | |
12031 | } | |
cb3b7d87 AB |
12032 | |
12033 | err = rdev_start_nan(rdev, wdev, &conf); | |
12034 | if (err) | |
12035 | return err; | |
12036 | ||
73c7da3d | 12037 | wdev->is_running = true; |
cb3b7d87 AB |
12038 | rdev->opencount++; |
12039 | ||
12040 | return 0; | |
12041 | } | |
12042 | ||
12043 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) | |
12044 | { | |
12045 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12046 | struct wireless_dev *wdev = info->user_ptr[1]; | |
12047 | ||
12048 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
12049 | return -EOPNOTSUPP; | |
12050 | ||
12051 | cfg80211_stop_nan(rdev, wdev); | |
12052 | ||
12053 | return 0; | |
12054 | } | |
12055 | ||
a442b761 AB |
12056 | static int validate_nan_filter(struct nlattr *filter_attr) |
12057 | { | |
12058 | struct nlattr *attr; | |
12059 | int len = 0, n_entries = 0, rem; | |
12060 | ||
12061 | nla_for_each_nested(attr, filter_attr, rem) { | |
12062 | len += nla_len(attr); | |
12063 | n_entries++; | |
12064 | } | |
12065 | ||
12066 | if (len >= U8_MAX) | |
12067 | return -EINVAL; | |
12068 | ||
12069 | return n_entries; | |
12070 | } | |
12071 | ||
12072 | static int handle_nan_filter(struct nlattr *attr_filter, | |
12073 | struct cfg80211_nan_func *func, | |
12074 | bool tx) | |
12075 | { | |
12076 | struct nlattr *attr; | |
12077 | int n_entries, rem, i; | |
12078 | struct cfg80211_nan_func_filter *filter; | |
12079 | ||
12080 | n_entries = validate_nan_filter(attr_filter); | |
12081 | if (n_entries < 0) | |
12082 | return n_entries; | |
12083 | ||
12084 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); | |
12085 | ||
12086 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); | |
12087 | if (!filter) | |
12088 | return -ENOMEM; | |
12089 | ||
12090 | i = 0; | |
12091 | nla_for_each_nested(attr, attr_filter, rem) { | |
b15ca182 | 12092 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); |
a442b761 AB |
12093 | filter[i].len = nla_len(attr); |
12094 | i++; | |
12095 | } | |
12096 | if (tx) { | |
12097 | func->num_tx_filters = n_entries; | |
12098 | func->tx_filters = filter; | |
12099 | } else { | |
12100 | func->num_rx_filters = n_entries; | |
12101 | func->rx_filters = filter; | |
12102 | } | |
12103 | ||
12104 | return 0; | |
12105 | } | |
12106 | ||
12107 | static int nl80211_nan_add_func(struct sk_buff *skb, | |
12108 | struct genl_info *info) | |
12109 | { | |
12110 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12111 | struct wireless_dev *wdev = info->user_ptr[1]; | |
12112 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; | |
12113 | struct cfg80211_nan_func *func; | |
12114 | struct sk_buff *msg = NULL; | |
12115 | void *hdr = NULL; | |
12116 | int err = 0; | |
12117 | ||
12118 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
12119 | return -EOPNOTSUPP; | |
12120 | ||
73c7da3d | 12121 | if (!wdev_running(wdev)) |
a442b761 AB |
12122 | return -ENOTCONN; |
12123 | ||
12124 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) | |
12125 | return -EINVAL; | |
12126 | ||
8cb08174 JB |
12127 | err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX, |
12128 | info->attrs[NL80211_ATTR_NAN_FUNC], | |
12129 | nl80211_nan_func_policy, | |
12130 | info->extack); | |
a442b761 AB |
12131 | if (err) |
12132 | return err; | |
12133 | ||
12134 | func = kzalloc(sizeof(*func), GFP_KERNEL); | |
12135 | if (!func) | |
12136 | return -ENOMEM; | |
12137 | ||
b60ad348 | 12138 | func->cookie = cfg80211_assign_cookie(rdev); |
a442b761 AB |
12139 | |
12140 | if (!tb[NL80211_NAN_FUNC_TYPE] || | |
12141 | nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) { | |
12142 | err = -EINVAL; | |
12143 | goto out; | |
12144 | } | |
12145 | ||
12146 | ||
12147 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); | |
12148 | ||
12149 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { | |
12150 | err = -EINVAL; | |
12151 | goto out; | |
12152 | } | |
12153 | ||
12154 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), | |
12155 | sizeof(func->service_id)); | |
12156 | ||
12157 | func->close_range = | |
12158 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); | |
12159 | ||
12160 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { | |
12161 | func->serv_spec_info_len = | |
12162 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); | |
12163 | func->serv_spec_info = | |
12164 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), | |
12165 | func->serv_spec_info_len, | |
12166 | GFP_KERNEL); | |
12167 | if (!func->serv_spec_info) { | |
12168 | err = -ENOMEM; | |
12169 | goto out; | |
12170 | } | |
12171 | } | |
12172 | ||
12173 | if (tb[NL80211_NAN_FUNC_TTL]) | |
12174 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); | |
12175 | ||
12176 | switch (func->type) { | |
12177 | case NL80211_NAN_FUNC_PUBLISH: | |
12178 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { | |
12179 | err = -EINVAL; | |
12180 | goto out; | |
12181 | } | |
12182 | ||
12183 | func->publish_type = | |
12184 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); | |
12185 | func->publish_bcast = | |
12186 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); | |
12187 | ||
12188 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && | |
12189 | func->publish_bcast) { | |
12190 | err = -EINVAL; | |
12191 | goto out; | |
12192 | } | |
12193 | break; | |
12194 | case NL80211_NAN_FUNC_SUBSCRIBE: | |
12195 | func->subscribe_active = | |
12196 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); | |
12197 | break; | |
12198 | case NL80211_NAN_FUNC_FOLLOW_UP: | |
12199 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || | |
3ea15452 HC |
12200 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || |
12201 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { | |
a442b761 AB |
12202 | err = -EINVAL; |
12203 | goto out; | |
12204 | } | |
12205 | ||
12206 | func->followup_id = | |
12207 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); | |
12208 | func->followup_reqid = | |
12209 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); | |
12210 | memcpy(func->followup_dest.addr, | |
12211 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), | |
12212 | sizeof(func->followup_dest.addr)); | |
12213 | if (func->ttl) { | |
12214 | err = -EINVAL; | |
12215 | goto out; | |
12216 | } | |
12217 | break; | |
12218 | default: | |
12219 | err = -EINVAL; | |
12220 | goto out; | |
12221 | } | |
12222 | ||
12223 | if (tb[NL80211_NAN_FUNC_SRF]) { | |
12224 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; | |
12225 | ||
8cb08174 JB |
12226 | err = nla_parse_nested_deprecated(srf_tb, |
12227 | NL80211_NAN_SRF_ATTR_MAX, | |
12228 | tb[NL80211_NAN_FUNC_SRF], | |
12229 | nl80211_nan_srf_policy, | |
12230 | info->extack); | |
a442b761 AB |
12231 | if (err) |
12232 | goto out; | |
12233 | ||
12234 | func->srf_include = | |
12235 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); | |
12236 | ||
12237 | if (srf_tb[NL80211_NAN_SRF_BF]) { | |
12238 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || | |
12239 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { | |
12240 | err = -EINVAL; | |
12241 | goto out; | |
12242 | } | |
12243 | ||
12244 | func->srf_bf_len = | |
12245 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); | |
12246 | func->srf_bf = | |
12247 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), | |
12248 | func->srf_bf_len, GFP_KERNEL); | |
12249 | if (!func->srf_bf) { | |
12250 | err = -ENOMEM; | |
12251 | goto out; | |
12252 | } | |
12253 | ||
12254 | func->srf_bf_idx = | |
12255 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); | |
12256 | } else { | |
12257 | struct nlattr *attr, *mac_attr = | |
12258 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; | |
12259 | int n_entries, rem, i = 0; | |
12260 | ||
12261 | if (!mac_attr) { | |
12262 | err = -EINVAL; | |
12263 | goto out; | |
12264 | } | |
12265 | ||
12266 | n_entries = validate_acl_mac_addrs(mac_attr); | |
12267 | if (n_entries <= 0) { | |
12268 | err = -EINVAL; | |
12269 | goto out; | |
12270 | } | |
12271 | ||
12272 | func->srf_num_macs = n_entries; | |
12273 | func->srf_macs = | |
6396bb22 | 12274 | kcalloc(n_entries, sizeof(*func->srf_macs), |
a442b761 AB |
12275 | GFP_KERNEL); |
12276 | if (!func->srf_macs) { | |
12277 | err = -ENOMEM; | |
12278 | goto out; | |
12279 | } | |
12280 | ||
12281 | nla_for_each_nested(attr, mac_attr, rem) | |
12282 | memcpy(func->srf_macs[i++].addr, nla_data(attr), | |
12283 | sizeof(*func->srf_macs)); | |
12284 | } | |
12285 | } | |
12286 | ||
12287 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { | |
12288 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], | |
12289 | func, true); | |
12290 | if (err) | |
12291 | goto out; | |
12292 | } | |
12293 | ||
12294 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { | |
12295 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], | |
12296 | func, false); | |
12297 | if (err) | |
12298 | goto out; | |
12299 | } | |
12300 | ||
12301 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12302 | if (!msg) { | |
12303 | err = -ENOMEM; | |
12304 | goto out; | |
12305 | } | |
12306 | ||
12307 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
12308 | NL80211_CMD_ADD_NAN_FUNCTION); | |
12309 | /* This can't really happen - we just allocated 4KB */ | |
12310 | if (WARN_ON(!hdr)) { | |
12311 | err = -ENOMEM; | |
12312 | goto out; | |
12313 | } | |
12314 | ||
12315 | err = rdev_add_nan_func(rdev, wdev, func); | |
12316 | out: | |
12317 | if (err < 0) { | |
12318 | cfg80211_free_nan_func(func); | |
12319 | nlmsg_free(msg); | |
12320 | return err; | |
12321 | } | |
12322 | ||
12323 | /* propagate the instance id and cookie to userspace */ | |
12324 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, | |
12325 | NL80211_ATTR_PAD)) | |
12326 | goto nla_put_failure; | |
12327 | ||
ae0be8de | 12328 | func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); |
a442b761 AB |
12329 | if (!func_attr) |
12330 | goto nla_put_failure; | |
12331 | ||
12332 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, | |
12333 | func->instance_id)) | |
12334 | goto nla_put_failure; | |
12335 | ||
12336 | nla_nest_end(msg, func_attr); | |
12337 | ||
12338 | genlmsg_end(msg, hdr); | |
12339 | return genlmsg_reply(msg, info); | |
12340 | ||
12341 | nla_put_failure: | |
12342 | nlmsg_free(msg); | |
12343 | return -ENOBUFS; | |
12344 | } | |
12345 | ||
12346 | static int nl80211_nan_del_func(struct sk_buff *skb, | |
12347 | struct genl_info *info) | |
12348 | { | |
12349 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12350 | struct wireless_dev *wdev = info->user_ptr[1]; | |
12351 | u64 cookie; | |
12352 | ||
12353 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
12354 | return -EOPNOTSUPP; | |
12355 | ||
73c7da3d | 12356 | if (!wdev_running(wdev)) |
a442b761 AB |
12357 | return -ENOTCONN; |
12358 | ||
12359 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
12360 | return -EINVAL; | |
12361 | ||
a442b761 AB |
12362 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
12363 | ||
12364 | rdev_del_nan_func(rdev, wdev, cookie); | |
12365 | ||
12366 | return 0; | |
12367 | } | |
12368 | ||
a5a9dcf2 AB |
12369 | static int nl80211_nan_change_config(struct sk_buff *skb, |
12370 | struct genl_info *info) | |
12371 | { | |
12372 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12373 | struct wireless_dev *wdev = info->user_ptr[1]; | |
12374 | struct cfg80211_nan_conf conf = {}; | |
12375 | u32 changed = 0; | |
12376 | ||
12377 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
12378 | return -EOPNOTSUPP; | |
12379 | ||
73c7da3d | 12380 | if (!wdev_running(wdev)) |
a5a9dcf2 AB |
12381 | return -ENOTCONN; |
12382 | ||
12383 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { | |
12384 | conf.master_pref = | |
12385 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); | |
12386 | if (conf.master_pref <= 1 || conf.master_pref == 255) | |
12387 | return -EINVAL; | |
12388 | ||
12389 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; | |
12390 | } | |
12391 | ||
8585989d LC |
12392 | if (info->attrs[NL80211_ATTR_BANDS]) { |
12393 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); | |
12394 | ||
12395 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) | |
12396 | return -EOPNOTSUPP; | |
12397 | ||
12398 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) | |
12399 | return -EINVAL; | |
12400 | ||
12401 | conf.bands = bands; | |
12402 | changed |= CFG80211_NAN_CONF_CHANGED_BANDS; | |
a5a9dcf2 AB |
12403 | } |
12404 | ||
12405 | if (!changed) | |
12406 | return -EINVAL; | |
12407 | ||
12408 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); | |
12409 | } | |
12410 | ||
50bcd31d AB |
12411 | void cfg80211_nan_match(struct wireless_dev *wdev, |
12412 | struct cfg80211_nan_match_params *match, gfp_t gfp) | |
12413 | { | |
12414 | struct wiphy *wiphy = wdev->wiphy; | |
12415 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
12416 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; | |
12417 | struct sk_buff *msg; | |
12418 | void *hdr; | |
12419 | ||
12420 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) | |
12421 | return; | |
12422 | ||
12423 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12424 | if (!msg) | |
12425 | return; | |
12426 | ||
12427 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); | |
12428 | if (!hdr) { | |
12429 | nlmsg_free(msg); | |
12430 | return; | |
12431 | } | |
12432 | ||
12433 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12434 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
12435 | wdev->netdev->ifindex)) || | |
12436 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | |
12437 | NL80211_ATTR_PAD)) | |
12438 | goto nla_put_failure; | |
12439 | ||
12440 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, | |
12441 | NL80211_ATTR_PAD) || | |
12442 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) | |
12443 | goto nla_put_failure; | |
12444 | ||
ae0be8de | 12445 | match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH); |
50bcd31d AB |
12446 | if (!match_attr) |
12447 | goto nla_put_failure; | |
12448 | ||
ae0be8de MK |
12449 | local_func_attr = nla_nest_start_noflag(msg, |
12450 | NL80211_NAN_MATCH_FUNC_LOCAL); | |
50bcd31d AB |
12451 | if (!local_func_attr) |
12452 | goto nla_put_failure; | |
12453 | ||
12454 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) | |
12455 | goto nla_put_failure; | |
12456 | ||
12457 | nla_nest_end(msg, local_func_attr); | |
12458 | ||
ae0be8de MK |
12459 | peer_func_attr = nla_nest_start_noflag(msg, |
12460 | NL80211_NAN_MATCH_FUNC_PEER); | |
50bcd31d AB |
12461 | if (!peer_func_attr) |
12462 | goto nla_put_failure; | |
12463 | ||
12464 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || | |
12465 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) | |
12466 | goto nla_put_failure; | |
12467 | ||
12468 | if (match->info && match->info_len && | |
12469 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, | |
12470 | match->info)) | |
12471 | goto nla_put_failure; | |
12472 | ||
12473 | nla_nest_end(msg, peer_func_attr); | |
12474 | nla_nest_end(msg, match_attr); | |
12475 | genlmsg_end(msg, hdr); | |
12476 | ||
12477 | if (!wdev->owner_nlportid) | |
12478 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
12479 | msg, 0, NL80211_MCGRP_NAN, gfp); | |
12480 | else | |
12481 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, | |
12482 | wdev->owner_nlportid); | |
12483 | ||
12484 | return; | |
12485 | ||
12486 | nla_put_failure: | |
12487 | nlmsg_free(msg); | |
12488 | } | |
12489 | EXPORT_SYMBOL(cfg80211_nan_match); | |
12490 | ||
368e5a7b AB |
12491 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
12492 | u8 inst_id, | |
12493 | enum nl80211_nan_func_term_reason reason, | |
12494 | u64 cookie, gfp_t gfp) | |
12495 | { | |
12496 | struct wiphy *wiphy = wdev->wiphy; | |
12497 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
12498 | struct sk_buff *msg; | |
12499 | struct nlattr *func_attr; | |
12500 | void *hdr; | |
12501 | ||
12502 | if (WARN_ON(!inst_id)) | |
12503 | return; | |
12504 | ||
12505 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12506 | if (!msg) | |
12507 | return; | |
12508 | ||
12509 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); | |
12510 | if (!hdr) { | |
12511 | nlmsg_free(msg); | |
12512 | return; | |
12513 | } | |
12514 | ||
12515 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12516 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
12517 | wdev->netdev->ifindex)) || | |
12518 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | |
12519 | NL80211_ATTR_PAD)) | |
12520 | goto nla_put_failure; | |
12521 | ||
12522 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, | |
12523 | NL80211_ATTR_PAD)) | |
12524 | goto nla_put_failure; | |
12525 | ||
ae0be8de | 12526 | func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); |
368e5a7b AB |
12527 | if (!func_attr) |
12528 | goto nla_put_failure; | |
12529 | ||
12530 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || | |
12531 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) | |
12532 | goto nla_put_failure; | |
12533 | ||
12534 | nla_nest_end(msg, func_attr); | |
12535 | genlmsg_end(msg, hdr); | |
12536 | ||
12537 | if (!wdev->owner_nlportid) | |
12538 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
12539 | msg, 0, NL80211_MCGRP_NAN, gfp); | |
12540 | else | |
12541 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, | |
12542 | wdev->owner_nlportid); | |
12543 | ||
12544 | return; | |
12545 | ||
12546 | nla_put_failure: | |
12547 | nlmsg_free(msg); | |
12548 | } | |
12549 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); | |
12550 | ||
3713b4e3 JB |
12551 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
12552 | struct genl_info *info) | |
12553 | { | |
12554 | void *hdr; | |
12555 | struct sk_buff *msg; | |
12556 | ||
12557 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12558 | if (!msg) | |
12559 | return -ENOMEM; | |
12560 | ||
12561 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
12562 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
12563 | if (!hdr) | |
12564 | goto nla_put_failure; | |
12565 | ||
12566 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
12567 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
12568 | goto nla_put_failure; | |
12569 | ||
12570 | genlmsg_end(msg, hdr); | |
12571 | return genlmsg_reply(msg, info); | |
12572 | ||
12573 | nla_put_failure: | |
12574 | kfree_skb(msg); | |
12575 | return -ENOBUFS; | |
12576 | } | |
12577 | ||
355199e0 JM |
12578 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
12579 | { | |
12580 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12581 | struct cfg80211_update_ft_ies_params ft_params; | |
12582 | struct net_device *dev = info->user_ptr[1]; | |
12583 | ||
12584 | if (!rdev->ops->update_ft_ies) | |
12585 | return -EOPNOTSUPP; | |
12586 | ||
12587 | if (!info->attrs[NL80211_ATTR_MDID] || | |
3d7af878 | 12588 | !info->attrs[NL80211_ATTR_IE]) |
355199e0 JM |
12589 | return -EINVAL; |
12590 | ||
12591 | memset(&ft_params, 0, sizeof(ft_params)); | |
12592 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
12593 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
12594 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
12595 | ||
12596 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
12597 | } | |
12598 | ||
5de17984 AS |
12599 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
12600 | struct genl_info *info) | |
12601 | { | |
12602 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12603 | struct wireless_dev *wdev = info->user_ptr[1]; | |
12604 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
12605 | u16 duration; | |
12606 | int ret; | |
12607 | ||
12608 | if (!rdev->ops->crit_proto_start) | |
12609 | return -EOPNOTSUPP; | |
12610 | ||
12611 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
12612 | return -EINVAL; | |
12613 | ||
12614 | if (rdev->crit_proto_nlportid) | |
12615 | return -EBUSY; | |
12616 | ||
12617 | /* determine protocol if provided */ | |
12618 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
12619 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
12620 | ||
12621 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
12622 | return -EINVAL; | |
12623 | ||
12624 | /* timeout must be provided */ | |
12625 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
12626 | return -EINVAL; | |
12627 | ||
12628 | duration = | |
12629 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
12630 | ||
12631 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
12632 | return -ERANGE; | |
12633 | ||
12634 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
12635 | if (!ret) | |
12636 | rdev->crit_proto_nlportid = info->snd_portid; | |
12637 | ||
12638 | return ret; | |
12639 | } | |
12640 | ||
12641 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
12642 | struct genl_info *info) | |
12643 | { | |
12644 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12645 | struct wireless_dev *wdev = info->user_ptr[1]; | |
12646 | ||
12647 | if (!rdev->ops->crit_proto_stop) | |
12648 | return -EOPNOTSUPP; | |
12649 | ||
12650 | if (rdev->crit_proto_nlportid) { | |
12651 | rdev->crit_proto_nlportid = 0; | |
12652 | rdev_crit_proto_stop(rdev, wdev); | |
12653 | } | |
12654 | return 0; | |
12655 | } | |
12656 | ||
ad7e718c JB |
12657 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
12658 | { | |
12659 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12660 | struct wireless_dev *wdev = | |
12661 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
12662 | int i, err; | |
12663 | u32 vid, subcmd; | |
12664 | ||
12665 | if (!rdev->wiphy.vendor_commands) | |
12666 | return -EOPNOTSUPP; | |
12667 | ||
12668 | if (IS_ERR(wdev)) { | |
12669 | err = PTR_ERR(wdev); | |
12670 | if (err != -EINVAL) | |
12671 | return err; | |
12672 | wdev = NULL; | |
12673 | } else if (wdev->wiphy != &rdev->wiphy) { | |
12674 | return -EINVAL; | |
12675 | } | |
12676 | ||
12677 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
12678 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
12679 | return -EINVAL; | |
12680 | ||
12681 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
12682 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
12683 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
12684 | const struct wiphy_vendor_command *vcmd; | |
12685 | void *data = NULL; | |
12686 | int len = 0; | |
12687 | ||
12688 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
12689 | ||
12690 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
12691 | continue; | |
12692 | ||
12693 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
12694 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
12695 | if (!wdev) | |
12696 | return -EINVAL; | |
12697 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
12698 | !wdev->netdev) | |
12699 | return -EINVAL; | |
12700 | ||
12701 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
73c7da3d | 12702 | if (!wdev_running(wdev)) |
ad7e718c JB |
12703 | return -ENETDOWN; |
12704 | } | |
7bdbe400 JB |
12705 | |
12706 | if (!vcmd->doit) | |
12707 | return -EOPNOTSUPP; | |
ad7e718c JB |
12708 | } else { |
12709 | wdev = NULL; | |
12710 | } | |
12711 | ||
12712 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
12713 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
12714 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
12715 | } | |
12716 | ||
12717 | rdev->cur_cmd_info = info; | |
12718 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
12719 | data, len); | |
12720 | rdev->cur_cmd_info = NULL; | |
12721 | return err; | |
12722 | } | |
12723 | ||
12724 | return -EOPNOTSUPP; | |
12725 | } | |
12726 | ||
7bdbe400 JB |
12727 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
12728 | struct netlink_callback *cb, | |
12729 | struct cfg80211_registered_device **rdev, | |
12730 | struct wireless_dev **wdev) | |
12731 | { | |
c90c39da | 12732 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
7bdbe400 JB |
12733 | u32 vid, subcmd; |
12734 | unsigned int i; | |
12735 | int vcmd_idx = -1; | |
12736 | int err; | |
12737 | void *data = NULL; | |
12738 | unsigned int data_len = 0; | |
12739 | ||
7bdbe400 JB |
12740 | if (cb->args[0]) { |
12741 | /* subtract the 1 again here */ | |
12742 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
12743 | struct wireless_dev *tmp; | |
12744 | ||
ea90e0dc JB |
12745 | if (!wiphy) |
12746 | return -ENODEV; | |
7bdbe400 JB |
12747 | *rdev = wiphy_to_rdev(wiphy); |
12748 | *wdev = NULL; | |
12749 | ||
12750 | if (cb->args[1]) { | |
53873f13 | 12751 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
7bdbe400 JB |
12752 | if (tmp->identifier == cb->args[1] - 1) { |
12753 | *wdev = tmp; | |
12754 | break; | |
12755 | } | |
12756 | } | |
12757 | } | |
12758 | ||
12759 | /* keep rtnl locked in successful case */ | |
12760 | return 0; | |
12761 | } | |
12762 | ||
8cb08174 JB |
12763 | err = nlmsg_parse_deprecated(cb->nlh, |
12764 | GENL_HDRLEN + nl80211_fam.hdrsize, | |
12765 | attrbuf, nl80211_fam.maxattr, | |
12766 | nl80211_policy, NULL); | |
7bdbe400 | 12767 | if (err) |
ea90e0dc | 12768 | return err; |
7bdbe400 | 12769 | |
c90c39da | 12770 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
ea90e0dc JB |
12771 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) |
12772 | return -EINVAL; | |
7bdbe400 | 12773 | |
c90c39da | 12774 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); |
7bdbe400 JB |
12775 | if (IS_ERR(*wdev)) |
12776 | *wdev = NULL; | |
12777 | ||
c90c39da | 12778 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
ea90e0dc JB |
12779 | if (IS_ERR(*rdev)) |
12780 | return PTR_ERR(*rdev); | |
7bdbe400 | 12781 | |
c90c39da JB |
12782 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
12783 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); | |
7bdbe400 JB |
12784 | |
12785 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { | |
12786 | const struct wiphy_vendor_command *vcmd; | |
12787 | ||
12788 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; | |
12789 | ||
12790 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
12791 | continue; | |
12792 | ||
ea90e0dc JB |
12793 | if (!vcmd->dumpit) |
12794 | return -EOPNOTSUPP; | |
7bdbe400 JB |
12795 | |
12796 | vcmd_idx = i; | |
12797 | break; | |
12798 | } | |
12799 | ||
ea90e0dc JB |
12800 | if (vcmd_idx < 0) |
12801 | return -EOPNOTSUPP; | |
7bdbe400 | 12802 | |
c90c39da JB |
12803 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
12804 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); | |
12805 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); | |
7bdbe400 JB |
12806 | } |
12807 | ||
12808 | /* 0 is the first index - add 1 to parse only once */ | |
12809 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
12810 | /* add 1 to know if it was NULL */ | |
12811 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; | |
12812 | cb->args[2] = vcmd_idx; | |
12813 | cb->args[3] = (unsigned long)data; | |
12814 | cb->args[4] = data_len; | |
12815 | ||
12816 | /* keep rtnl locked in successful case */ | |
12817 | return 0; | |
7bdbe400 JB |
12818 | } |
12819 | ||
12820 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, | |
12821 | struct netlink_callback *cb) | |
12822 | { | |
12823 | struct cfg80211_registered_device *rdev; | |
12824 | struct wireless_dev *wdev; | |
12825 | unsigned int vcmd_idx; | |
12826 | const struct wiphy_vendor_command *vcmd; | |
12827 | void *data; | |
12828 | int data_len; | |
12829 | int err; | |
12830 | struct nlattr *vendor_data; | |
12831 | ||
ea90e0dc | 12832 | rtnl_lock(); |
7bdbe400 JB |
12833 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
12834 | if (err) | |
ea90e0dc | 12835 | goto out; |
7bdbe400 JB |
12836 | |
12837 | vcmd_idx = cb->args[2]; | |
12838 | data = (void *)cb->args[3]; | |
12839 | data_len = cb->args[4]; | |
12840 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; | |
12841 | ||
12842 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
12843 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
ea90e0dc JB |
12844 | if (!wdev) { |
12845 | err = -EINVAL; | |
12846 | goto out; | |
12847 | } | |
7bdbe400 | 12848 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
ea90e0dc JB |
12849 | !wdev->netdev) { |
12850 | err = -EINVAL; | |
12851 | goto out; | |
12852 | } | |
7bdbe400 JB |
12853 | |
12854 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
ea90e0dc JB |
12855 | if (!wdev_running(wdev)) { |
12856 | err = -ENETDOWN; | |
12857 | goto out; | |
12858 | } | |
7bdbe400 JB |
12859 | } |
12860 | } | |
12861 | ||
12862 | while (1) { | |
12863 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, | |
12864 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
12865 | NL80211_CMD_VENDOR); | |
12866 | if (!hdr) | |
12867 | break; | |
12868 | ||
12869 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
12870 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
12871 | wdev_id(wdev), | |
12872 | NL80211_ATTR_PAD))) { | |
7bdbe400 JB |
12873 | genlmsg_cancel(skb, hdr); |
12874 | break; | |
12875 | } | |
12876 | ||
ae0be8de MK |
12877 | vendor_data = nla_nest_start_noflag(skb, |
12878 | NL80211_ATTR_VENDOR_DATA); | |
7bdbe400 JB |
12879 | if (!vendor_data) { |
12880 | genlmsg_cancel(skb, hdr); | |
12881 | break; | |
12882 | } | |
12883 | ||
12884 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, | |
12885 | (unsigned long *)&cb->args[5]); | |
12886 | nla_nest_end(skb, vendor_data); | |
12887 | ||
12888 | if (err == -ENOBUFS || err == -ENOENT) { | |
12889 | genlmsg_cancel(skb, hdr); | |
12890 | break; | |
12891 | } else if (err) { | |
12892 | genlmsg_cancel(skb, hdr); | |
12893 | goto out; | |
12894 | } | |
12895 | ||
12896 | genlmsg_end(skb, hdr); | |
12897 | } | |
12898 | ||
12899 | err = skb->len; | |
12900 | out: | |
12901 | rtnl_unlock(); | |
12902 | return err; | |
12903 | } | |
12904 | ||
ad7e718c JB |
12905 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
12906 | enum nl80211_commands cmd, | |
12907 | enum nl80211_attrs attr, | |
12908 | int approxlen) | |
12909 | { | |
f26cbf40 | 12910 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
12911 | |
12912 | if (WARN_ON(!rdev->cur_cmd_info)) | |
12913 | return NULL; | |
12914 | ||
6c09e791 | 12915 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
ad7e718c JB |
12916 | rdev->cur_cmd_info->snd_portid, |
12917 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 12918 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
12919 | } |
12920 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
12921 | ||
12922 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
12923 | { | |
12924 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
12925 | void *hdr = ((void **)skb->cb)[1]; | |
12926 | struct nlattr *data = ((void **)skb->cb)[2]; | |
12927 | ||
bd8c78e7 JB |
12928 | /* clear CB data for netlink core to own from now on */ |
12929 | memset(skb->cb, 0, sizeof(skb->cb)); | |
12930 | ||
ad7e718c JB |
12931 | if (WARN_ON(!rdev->cur_cmd_info)) { |
12932 | kfree_skb(skb); | |
12933 | return -EINVAL; | |
12934 | } | |
12935 | ||
12936 | nla_nest_end(skb, data); | |
12937 | genlmsg_end(skb, hdr); | |
12938 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
12939 | } | |
12940 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
12941 | ||
55c1fdf0 JB |
12942 | unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy) |
12943 | { | |
12944 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
12945 | ||
12946 | if (WARN_ON(!rdev->cur_cmd_info)) | |
12947 | return 0; | |
12948 | ||
12949 | return rdev->cur_cmd_info->snd_portid; | |
12950 | } | |
12951 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender); | |
12952 | ||
fa9ffc74 KP |
12953 | static int nl80211_set_qos_map(struct sk_buff *skb, |
12954 | struct genl_info *info) | |
12955 | { | |
12956 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12957 | struct cfg80211_qos_map *qos_map = NULL; | |
12958 | struct net_device *dev = info->user_ptr[1]; | |
12959 | u8 *pos, len, num_des, des_len, des; | |
12960 | int ret; | |
12961 | ||
12962 | if (!rdev->ops->set_qos_map) | |
12963 | return -EOPNOTSUPP; | |
12964 | ||
12965 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
12966 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
12967 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
12968 | ||
12969 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
12970 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
12971 | return -EINVAL; | |
12972 | ||
12973 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
12974 | if (!qos_map) | |
12975 | return -ENOMEM; | |
12976 | ||
12977 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
12978 | if (num_des) { | |
12979 | des_len = num_des * | |
12980 | sizeof(struct cfg80211_dscp_exception); | |
12981 | memcpy(qos_map->dscp_exception, pos, des_len); | |
12982 | qos_map->num_des = num_des; | |
12983 | for (des = 0; des < num_des; des++) { | |
12984 | if (qos_map->dscp_exception[des].up > 7) { | |
12985 | kfree(qos_map); | |
12986 | return -EINVAL; | |
12987 | } | |
12988 | } | |
12989 | pos += des_len; | |
12990 | } | |
12991 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
12992 | } | |
12993 | ||
12994 | wdev_lock(dev->ieee80211_ptr); | |
12995 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
12996 | if (!ret) | |
12997 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
12998 | wdev_unlock(dev->ieee80211_ptr); | |
12999 | ||
13000 | kfree(qos_map); | |
13001 | return ret; | |
13002 | } | |
13003 | ||
960d01ac JB |
13004 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
13005 | { | |
13006 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13007 | struct net_device *dev = info->user_ptr[1]; | |
13008 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13009 | const u8 *peer; | |
13010 | u8 tsid, up; | |
13011 | u16 admitted_time = 0; | |
13012 | int err; | |
13013 | ||
723e73ac | 13014 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
13015 | return -EOPNOTSUPP; |
13016 | ||
13017 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
13018 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
13019 | return -EINVAL; | |
13020 | ||
13021 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
960d01ac | 13022 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
960d01ac JB |
13023 | |
13024 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 13025 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 13026 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
13027 | * need more attributes for that (e.g. BA session requirement); |
13028 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
13029 | */ |
13030 | return -EINVAL; | |
13031 | } | |
13032 | ||
13033 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
13034 | ||
13035 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
13036 | admitted_time = | |
13037 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
13038 | if (!admitted_time) | |
13039 | return -EINVAL; | |
13040 | } | |
13041 | ||
13042 | wdev_lock(wdev); | |
13043 | switch (wdev->iftype) { | |
13044 | case NL80211_IFTYPE_STATION: | |
13045 | case NL80211_IFTYPE_P2P_CLIENT: | |
13046 | if (wdev->current_bss) | |
13047 | break; | |
13048 | err = -ENOTCONN; | |
13049 | goto out; | |
13050 | default: | |
13051 | err = -EOPNOTSUPP; | |
13052 | goto out; | |
13053 | } | |
13054 | ||
13055 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
13056 | ||
13057 | out: | |
13058 | wdev_unlock(wdev); | |
13059 | return err; | |
13060 | } | |
13061 | ||
13062 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
13063 | { | |
13064 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13065 | struct net_device *dev = info->user_ptr[1]; | |
13066 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13067 | const u8 *peer; | |
13068 | u8 tsid; | |
13069 | int err; | |
13070 | ||
13071 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
13072 | return -EINVAL; | |
13073 | ||
13074 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
13075 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
13076 | ||
13077 | wdev_lock(wdev); | |
13078 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
13079 | wdev_unlock(wdev); | |
13080 | ||
13081 | return err; | |
13082 | } | |
13083 | ||
1057d35e AN |
13084 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
13085 | struct genl_info *info) | |
13086 | { | |
13087 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13088 | struct net_device *dev = info->user_ptr[1]; | |
13089 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13090 | struct cfg80211_chan_def chandef = {}; | |
13091 | const u8 *addr; | |
13092 | u8 oper_class; | |
13093 | int err; | |
13094 | ||
13095 | if (!rdev->ops->tdls_channel_switch || | |
13096 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
13097 | return -EOPNOTSUPP; | |
13098 | ||
13099 | switch (dev->ieee80211_ptr->iftype) { | |
13100 | case NL80211_IFTYPE_STATION: | |
13101 | case NL80211_IFTYPE_P2P_CLIENT: | |
13102 | break; | |
13103 | default: | |
13104 | return -EOPNOTSUPP; | |
13105 | } | |
13106 | ||
13107 | if (!info->attrs[NL80211_ATTR_MAC] || | |
13108 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | |
13109 | return -EINVAL; | |
13110 | ||
13111 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
13112 | if (err) | |
13113 | return err; | |
13114 | ||
13115 | /* | |
13116 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | |
13117 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | |
13118 | * specification is not defined for them. | |
13119 | */ | |
57fbcce3 | 13120 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
1057d35e AN |
13121 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
13122 | chandef.width != NL80211_CHAN_WIDTH_20) | |
13123 | return -EINVAL; | |
13124 | ||
13125 | /* we will be active on the TDLS link */ | |
923b352f AN |
13126 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
13127 | wdev->iftype)) | |
1057d35e AN |
13128 | return -EINVAL; |
13129 | ||
13130 | /* don't allow switching to DFS channels */ | |
13131 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | |
13132 | return -EINVAL; | |
13133 | ||
13134 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
13135 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | |
13136 | ||
13137 | wdev_lock(wdev); | |
13138 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | |
13139 | wdev_unlock(wdev); | |
13140 | ||
13141 | return err; | |
13142 | } | |
13143 | ||
13144 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | |
13145 | struct genl_info *info) | |
13146 | { | |
13147 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13148 | struct net_device *dev = info->user_ptr[1]; | |
13149 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13150 | const u8 *addr; | |
13151 | ||
13152 | if (!rdev->ops->tdls_channel_switch || | |
13153 | !rdev->ops->tdls_cancel_channel_switch || | |
13154 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
13155 | return -EOPNOTSUPP; | |
13156 | ||
13157 | switch (dev->ieee80211_ptr->iftype) { | |
13158 | case NL80211_IFTYPE_STATION: | |
13159 | case NL80211_IFTYPE_P2P_CLIENT: | |
13160 | break; | |
13161 | default: | |
13162 | return -EOPNOTSUPP; | |
13163 | } | |
13164 | ||
13165 | if (!info->attrs[NL80211_ATTR_MAC]) | |
13166 | return -EINVAL; | |
13167 | ||
13168 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
13169 | ||
13170 | wdev_lock(wdev); | |
13171 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | |
13172 | wdev_unlock(wdev); | |
13173 | ||
13174 | return 0; | |
13175 | } | |
13176 | ||
ce0ce13a MB |
13177 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
13178 | struct genl_info *info) | |
13179 | { | |
13180 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13181 | struct net_device *dev = info->user_ptr[1]; | |
13182 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13183 | const struct nlattr *nla; | |
13184 | bool enabled; | |
13185 | ||
ce0ce13a MB |
13186 | if (!rdev->ops->set_multicast_to_unicast) |
13187 | return -EOPNOTSUPP; | |
13188 | ||
13189 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
13190 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
13191 | return -EOPNOTSUPP; | |
13192 | ||
13193 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; | |
13194 | enabled = nla_get_flag(nla); | |
13195 | ||
13196 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); | |
13197 | } | |
13198 | ||
3a00df57 AS |
13199 | static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) |
13200 | { | |
13201 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13202 | struct net_device *dev = info->user_ptr[1]; | |
13203 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13204 | struct cfg80211_pmk_conf pmk_conf = {}; | |
13205 | int ret; | |
13206 | ||
13207 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
13208 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
13209 | return -EOPNOTSUPP; | |
13210 | ||
13211 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
13212 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) | |
13213 | return -EOPNOTSUPP; | |
13214 | ||
13215 | if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) | |
13216 | return -EINVAL; | |
13217 | ||
13218 | wdev_lock(wdev); | |
13219 | if (!wdev->current_bss) { | |
13220 | ret = -ENOTCONN; | |
13221 | goto out; | |
13222 | } | |
13223 | ||
13224 | pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
13225 | if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { | |
13226 | ret = -EINVAL; | |
13227 | goto out; | |
13228 | } | |
13229 | ||
13230 | pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); | |
13231 | pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); | |
13232 | if (pmk_conf.pmk_len != WLAN_PMK_LEN && | |
13233 | pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { | |
13234 | ret = -EINVAL; | |
13235 | goto out; | |
13236 | } | |
13237 | ||
13238 | if (info->attrs[NL80211_ATTR_PMKR0_NAME]) { | |
13239 | int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]); | |
13240 | ||
13241 | if (r0_name_len != WLAN_PMK_NAME_LEN) { | |
13242 | ret = -EINVAL; | |
13243 | goto out; | |
13244 | } | |
13245 | ||
13246 | pmk_conf.pmk_r0_name = | |
13247 | nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); | |
13248 | } | |
13249 | ||
13250 | ret = rdev_set_pmk(rdev, dev, &pmk_conf); | |
13251 | out: | |
13252 | wdev_unlock(wdev); | |
13253 | return ret; | |
13254 | } | |
13255 | ||
13256 | static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) | |
13257 | { | |
13258 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13259 | struct net_device *dev = info->user_ptr[1]; | |
13260 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13261 | const u8 *aa; | |
13262 | int ret; | |
13263 | ||
13264 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
13265 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
13266 | return -EOPNOTSUPP; | |
13267 | ||
13268 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
13269 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) | |
13270 | return -EOPNOTSUPP; | |
13271 | ||
13272 | if (!info->attrs[NL80211_ATTR_MAC]) | |
13273 | return -EINVAL; | |
13274 | ||
13275 | wdev_lock(wdev); | |
13276 | aa = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
13277 | ret = rdev_del_pmk(rdev, dev, aa); | |
13278 | wdev_unlock(wdev); | |
13279 | ||
13280 | return ret; | |
13281 | } | |
13282 | ||
40cbfa90 SD |
13283 | static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) |
13284 | { | |
13285 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13286 | struct net_device *dev = info->user_ptr[1]; | |
13287 | struct cfg80211_external_auth_params params; | |
13288 | ||
db8d93a7 | 13289 | if (!rdev->ops->external_auth) |
40cbfa90 SD |
13290 | return -EOPNOTSUPP; |
13291 | ||
fe494370 SD |
13292 | if (!info->attrs[NL80211_ATTR_SSID] && |
13293 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
13294 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
40cbfa90 SD |
13295 | return -EINVAL; |
13296 | ||
13297 | if (!info->attrs[NL80211_ATTR_BSSID]) | |
13298 | return -EINVAL; | |
13299 | ||
13300 | if (!info->attrs[NL80211_ATTR_STATUS_CODE]) | |
13301 | return -EINVAL; | |
13302 | ||
13303 | memset(¶ms, 0, sizeof(params)); | |
13304 | ||
fe494370 SD |
13305 | if (info->attrs[NL80211_ATTR_SSID]) { |
13306 | params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
13307 | if (params.ssid.ssid_len == 0 || | |
13308 | params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN) | |
13309 | return -EINVAL; | |
13310 | memcpy(params.ssid.ssid, | |
13311 | nla_data(info->attrs[NL80211_ATTR_SSID]), | |
13312 | params.ssid.ssid_len); | |
13313 | } | |
40cbfa90 SD |
13314 | |
13315 | memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), | |
13316 | ETH_ALEN); | |
13317 | ||
13318 | params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
13319 | ||
fe494370 SD |
13320 | if (info->attrs[NL80211_ATTR_PMKID]) |
13321 | params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); | |
13322 | ||
40cbfa90 SD |
13323 | return rdev_external_auth(rdev, dev, ¶ms); |
13324 | } | |
13325 | ||
2576a9ac DK |
13326 | static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) |
13327 | { | |
13328 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13329 | struct net_device *dev = info->user_ptr[1]; | |
13330 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13331 | const u8 *buf; | |
13332 | size_t len; | |
13333 | u8 *dest; | |
13334 | u16 proto; | |
13335 | bool noencrypt; | |
13336 | int err; | |
13337 | ||
13338 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
13339 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) | |
13340 | return -EOPNOTSUPP; | |
13341 | ||
13342 | if (!rdev->ops->tx_control_port) | |
13343 | return -EOPNOTSUPP; | |
13344 | ||
13345 | if (!info->attrs[NL80211_ATTR_FRAME] || | |
13346 | !info->attrs[NL80211_ATTR_MAC] || | |
13347 | !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { | |
13348 | GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); | |
13349 | return -EINVAL; | |
13350 | } | |
13351 | ||
13352 | wdev_lock(wdev); | |
13353 | ||
13354 | switch (wdev->iftype) { | |
13355 | case NL80211_IFTYPE_AP: | |
13356 | case NL80211_IFTYPE_P2P_GO: | |
13357 | case NL80211_IFTYPE_MESH_POINT: | |
13358 | break; | |
13359 | case NL80211_IFTYPE_ADHOC: | |
13360 | case NL80211_IFTYPE_STATION: | |
13361 | case NL80211_IFTYPE_P2P_CLIENT: | |
13362 | if (wdev->current_bss) | |
13363 | break; | |
13364 | err = -ENOTCONN; | |
13365 | goto out; | |
13366 | default: | |
13367 | err = -EOPNOTSUPP; | |
13368 | goto out; | |
13369 | } | |
13370 | ||
13371 | wdev_unlock(wdev); | |
13372 | ||
13373 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); | |
13374 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
13375 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
13376 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
13377 | noencrypt = | |
13378 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); | |
13379 | ||
13380 | return rdev_tx_control_port(rdev, dev, buf, len, | |
13381 | dest, cpu_to_be16(proto), noencrypt); | |
13382 | ||
13383 | out: | |
13384 | wdev_unlock(wdev); | |
13385 | return err; | |
13386 | } | |
13387 | ||
81e54d08 PKC |
13388 | static int nl80211_get_ftm_responder_stats(struct sk_buff *skb, |
13389 | struct genl_info *info) | |
13390 | { | |
13391 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13392 | struct net_device *dev = info->user_ptr[1]; | |
13393 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13394 | struct cfg80211_ftm_responder_stats ftm_stats = {}; | |
13395 | struct sk_buff *msg; | |
13396 | void *hdr; | |
13397 | struct nlattr *ftm_stats_attr; | |
13398 | int err; | |
13399 | ||
13400 | if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval) | |
13401 | return -EOPNOTSUPP; | |
13402 | ||
13403 | err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats); | |
13404 | if (err) | |
13405 | return err; | |
13406 | ||
13407 | if (!ftm_stats.filled) | |
13408 | return -ENODATA; | |
13409 | ||
13410 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
13411 | if (!msg) | |
13412 | return -ENOMEM; | |
13413 | ||
13414 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
13415 | NL80211_CMD_GET_FTM_RESPONDER_STATS); | |
13416 | if (!hdr) | |
13417 | return -ENOBUFS; | |
13418 | ||
13419 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) | |
13420 | goto nla_put_failure; | |
13421 | ||
ae0be8de MK |
13422 | ftm_stats_attr = nla_nest_start_noflag(msg, |
13423 | NL80211_ATTR_FTM_RESPONDER_STATS); | |
81e54d08 PKC |
13424 | if (!ftm_stats_attr) |
13425 | goto nla_put_failure; | |
13426 | ||
13427 | #define SET_FTM(field, name, type) \ | |
13428 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ | |
13429 | nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \ | |
13430 | ftm_stats.field)) \ | |
13431 | goto nla_put_failure; } while (0) | |
13432 | #define SET_FTM_U64(field, name) \ | |
13433 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ | |
13434 | nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \ | |
13435 | ftm_stats.field, NL80211_FTM_STATS_PAD)) \ | |
13436 | goto nla_put_failure; } while (0) | |
13437 | ||
13438 | SET_FTM(success_num, SUCCESS_NUM, u32); | |
13439 | SET_FTM(partial_num, PARTIAL_NUM, u32); | |
13440 | SET_FTM(failed_num, FAILED_NUM, u32); | |
13441 | SET_FTM(asap_num, ASAP_NUM, u32); | |
13442 | SET_FTM(non_asap_num, NON_ASAP_NUM, u32); | |
13443 | SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC); | |
13444 | SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32); | |
13445 | SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32); | |
13446 | SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32); | |
13447 | #undef SET_FTM | |
13448 | ||
13449 | nla_nest_end(msg, ftm_stats_attr); | |
13450 | ||
13451 | genlmsg_end(msg, hdr); | |
13452 | return genlmsg_reply(msg, info); | |
13453 | ||
13454 | nla_put_failure: | |
13455 | nlmsg_free(msg); | |
13456 | return -ENOBUFS; | |
13457 | } | |
13458 | ||
cb74e977 SD |
13459 | static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info) |
13460 | { | |
13461 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13462 | struct cfg80211_update_owe_info owe_info; | |
13463 | struct net_device *dev = info->user_ptr[1]; | |
13464 | ||
13465 | if (!rdev->ops->update_owe_info) | |
13466 | return -EOPNOTSUPP; | |
13467 | ||
13468 | if (!info->attrs[NL80211_ATTR_STATUS_CODE] || | |
13469 | !info->attrs[NL80211_ATTR_MAC]) | |
13470 | return -EINVAL; | |
13471 | ||
13472 | memset(&owe_info, 0, sizeof(owe_info)); | |
13473 | owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
13474 | nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN); | |
13475 | ||
13476 | if (info->attrs[NL80211_ATTR_IE]) { | |
13477 | owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
13478 | owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
13479 | } | |
13480 | ||
13481 | return rdev_update_owe_info(rdev, dev, &owe_info); | |
13482 | } | |
13483 | ||
5ab92e7f RM |
13484 | static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info) |
13485 | { | |
13486 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13487 | struct net_device *dev = info->user_ptr[1]; | |
13488 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13489 | struct station_info sinfo = {}; | |
13490 | const u8 *buf; | |
13491 | size_t len; | |
13492 | u8 *dest; | |
13493 | int err; | |
13494 | ||
13495 | if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station) | |
13496 | return -EOPNOTSUPP; | |
13497 | ||
13498 | if (!info->attrs[NL80211_ATTR_MAC] || | |
13499 | !info->attrs[NL80211_ATTR_FRAME]) { | |
13500 | GENL_SET_ERR_MSG(info, "Frame or MAC missing"); | |
13501 | return -EINVAL; | |
13502 | } | |
13503 | ||
13504 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) | |
13505 | return -EOPNOTSUPP; | |
13506 | ||
13507 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
13508 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); | |
13509 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
13510 | ||
13511 | if (len < sizeof(struct ethhdr)) | |
13512 | return -EINVAL; | |
13513 | ||
13514 | if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) || | |
13515 | !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr)) | |
13516 | return -EINVAL; | |
13517 | ||
13518 | err = rdev_get_station(rdev, dev, dest, &sinfo); | |
13519 | if (err) | |
13520 | return err; | |
13521 | ||
13522 | return rdev_probe_mesh_link(rdev, dev, dest, buf, len); | |
13523 | } | |
13524 | ||
4c476991 JB |
13525 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
13526 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
13527 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
13528 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
13529 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
13530 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 13531 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 13532 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
13533 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
13534 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 13535 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
4c476991 | 13536 | |
f84f771d | 13537 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
13538 | struct genl_info *info) |
13539 | { | |
13540 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 13541 | struct wireless_dev *wdev; |
4c476991 | 13542 | struct net_device *dev; |
4c476991 JB |
13543 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
13544 | ||
13545 | if (rtnl) | |
13546 | rtnl_lock(); | |
13547 | ||
13548 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 13549 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
13550 | if (IS_ERR(rdev)) { |
13551 | if (rtnl) | |
13552 | rtnl_unlock(); | |
13553 | return PTR_ERR(rdev); | |
13554 | } | |
13555 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
13556 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
13557 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
13558 | ASSERT_RTNL(); |
13559 | ||
89a54e48 JB |
13560 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
13561 | info->attrs); | |
13562 | if (IS_ERR(wdev)) { | |
4c476991 JB |
13563 | if (rtnl) |
13564 | rtnl_unlock(); | |
89a54e48 | 13565 | return PTR_ERR(wdev); |
4c476991 | 13566 | } |
89a54e48 | 13567 | |
89a54e48 | 13568 | dev = wdev->netdev; |
f26cbf40 | 13569 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 13570 | |
1bf614ef JB |
13571 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
13572 | if (!dev) { | |
1bf614ef JB |
13573 | if (rtnl) |
13574 | rtnl_unlock(); | |
13575 | return -EINVAL; | |
13576 | } | |
13577 | ||
13578 | info->user_ptr[1] = dev; | |
13579 | } else { | |
13580 | info->user_ptr[1] = wdev; | |
41265714 | 13581 | } |
1bf614ef | 13582 | |
73c7da3d AVS |
13583 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
13584 | !wdev_running(wdev)) { | |
13585 | if (rtnl) | |
13586 | rtnl_unlock(); | |
13587 | return -ENETDOWN; | |
13588 | } | |
1bf614ef | 13589 | |
73c7da3d | 13590 | if (dev) |
1bf614ef | 13591 | dev_hold(dev); |
89a54e48 | 13592 | |
4c476991 | 13593 | info->user_ptr[0] = rdev; |
4c476991 JB |
13594 | } |
13595 | ||
13596 | return 0; | |
13597 | } | |
13598 | ||
f84f771d | 13599 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
13600 | struct genl_info *info) |
13601 | { | |
1bf614ef JB |
13602 | if (info->user_ptr[1]) { |
13603 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
13604 | struct wireless_dev *wdev = info->user_ptr[1]; | |
13605 | ||
13606 | if (wdev->netdev) | |
13607 | dev_put(wdev->netdev); | |
13608 | } else { | |
13609 | dev_put(info->user_ptr[1]); | |
13610 | } | |
13611 | } | |
5393b917 | 13612 | |
4c476991 JB |
13613 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
13614 | rtnl_unlock(); | |
5393b917 JB |
13615 | |
13616 | /* If needed, clear the netlink message payload from the SKB | |
13617 | * as it might contain key data that shouldn't stick around on | |
13618 | * the heap after the SKB is freed. The netlink message header | |
13619 | * is still needed for further processing, so leave it intact. | |
13620 | */ | |
13621 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | |
13622 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | |
13623 | ||
13624 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
13625 | } | |
4c476991 JB |
13626 | } |
13627 | ||
4534de83 | 13628 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
13629 | { |
13630 | .cmd = NL80211_CMD_GET_WIPHY, | |
ef6243ac | 13631 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
55682965 JB |
13632 | .doit = nl80211_get_wiphy, |
13633 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 13634 | .done = nl80211_dump_wiphy_done, |
55682965 | 13635 | /* can be retrieved by unprivileged users */ |
5fe231e8 JB |
13636 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
13637 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
13638 | }, |
13639 | { | |
13640 | .cmd = NL80211_CMD_SET_WIPHY, | |
ef6243ac | 13641 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
55682965 | 13642 | .doit = nl80211_set_wiphy, |
5617c6cd | 13643 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 | 13644 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
13645 | }, |
13646 | { | |
13647 | .cmd = NL80211_CMD_GET_INTERFACE, | |
ef6243ac | 13648 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
55682965 JB |
13649 | .doit = nl80211_get_interface, |
13650 | .dumpit = nl80211_dump_interface, | |
55682965 | 13651 | /* can be retrieved by unprivileged users */ |
5fe231e8 JB |
13652 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
13653 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
13654 | }, |
13655 | { | |
13656 | .cmd = NL80211_CMD_SET_INTERFACE, | |
ef6243ac | 13657 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
55682965 | 13658 | .doit = nl80211_set_interface, |
5617c6cd | 13659 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
13660 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
13661 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
13662 | }, |
13663 | { | |
13664 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
ef6243ac | 13665 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
55682965 | 13666 | .doit = nl80211_new_interface, |
5617c6cd | 13667 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
13668 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
13669 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
13670 | }, |
13671 | { | |
13672 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
ef6243ac | 13673 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
55682965 | 13674 | .doit = nl80211_del_interface, |
5617c6cd | 13675 | .flags = GENL_UNS_ADMIN_PERM, |
84efbb84 | 13676 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 13677 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
13678 | }, |
13679 | { | |
13680 | .cmd = NL80211_CMD_GET_KEY, | |
ef6243ac | 13681 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
41ade00f | 13682 | .doit = nl80211_get_key, |
5617c6cd | 13683 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 13684 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13685 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
13686 | }, |
13687 | { | |
13688 | .cmd = NL80211_CMD_SET_KEY, | |
ef6243ac | 13689 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
41ade00f | 13690 | .doit = nl80211_set_key, |
5617c6cd | 13691 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 13692 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
13693 | NL80211_FLAG_NEED_RTNL | |
13694 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
13695 | }, |
13696 | { | |
13697 | .cmd = NL80211_CMD_NEW_KEY, | |
ef6243ac | 13698 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
41ade00f | 13699 | .doit = nl80211_new_key, |
5617c6cd | 13700 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 13701 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
13702 | NL80211_FLAG_NEED_RTNL | |
13703 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
13704 | }, |
13705 | { | |
13706 | .cmd = NL80211_CMD_DEL_KEY, | |
ef6243ac | 13707 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
41ade00f | 13708 | .doit = nl80211_del_key, |
5617c6cd | 13709 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 13710 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13711 | NL80211_FLAG_NEED_RTNL, |
55682965 | 13712 | }, |
ed1b6cc7 JB |
13713 | { |
13714 | .cmd = NL80211_CMD_SET_BEACON, | |
ef6243ac | 13715 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5617c6cd | 13716 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 13717 | .doit = nl80211_set_beacon, |
2b5f8b0b | 13718 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13719 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
13720 | }, |
13721 | { | |
8860020e | 13722 | .cmd = NL80211_CMD_START_AP, |
ef6243ac | 13723 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5617c6cd | 13724 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 13725 | .doit = nl80211_start_ap, |
2b5f8b0b | 13726 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13727 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
13728 | }, |
13729 | { | |
8860020e | 13730 | .cmd = NL80211_CMD_STOP_AP, |
ef6243ac | 13731 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5617c6cd | 13732 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 13733 | .doit = nl80211_stop_ap, |
2b5f8b0b | 13734 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13735 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 13736 | }, |
5727ef1b JB |
13737 | { |
13738 | .cmd = NL80211_CMD_GET_STATION, | |
ef6243ac | 13739 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5727ef1b | 13740 | .doit = nl80211_get_station, |
2ec600d6 | 13741 | .dumpit = nl80211_dump_station, |
4c476991 JB |
13742 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
13743 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
13744 | }, |
13745 | { | |
13746 | .cmd = NL80211_CMD_SET_STATION, | |
ef6243ac | 13747 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5727ef1b | 13748 | .doit = nl80211_set_station, |
5617c6cd | 13749 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 13750 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13751 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
13752 | }, |
13753 | { | |
13754 | .cmd = NL80211_CMD_NEW_STATION, | |
ef6243ac | 13755 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5727ef1b | 13756 | .doit = nl80211_new_station, |
5617c6cd | 13757 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 13758 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13759 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
13760 | }, |
13761 | { | |
13762 | .cmd = NL80211_CMD_DEL_STATION, | |
ef6243ac | 13763 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5727ef1b | 13764 | .doit = nl80211_del_station, |
5617c6cd | 13765 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 13766 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13767 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
13768 | }, |
13769 | { | |
13770 | .cmd = NL80211_CMD_GET_MPATH, | |
ef6243ac | 13771 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2ec600d6 LCC |
13772 | .doit = nl80211_get_mpath, |
13773 | .dumpit = nl80211_dump_mpath, | |
5617c6cd | 13774 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 13775 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13776 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 | 13777 | }, |
66be7d2b HR |
13778 | { |
13779 | .cmd = NL80211_CMD_GET_MPP, | |
ef6243ac | 13780 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
66be7d2b HR |
13781 | .doit = nl80211_get_mpp, |
13782 | .dumpit = nl80211_dump_mpp, | |
5617c6cd | 13783 | .flags = GENL_UNS_ADMIN_PERM, |
66be7d2b HR |
13784 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13785 | NL80211_FLAG_NEED_RTNL, | |
13786 | }, | |
2ec600d6 LCC |
13787 | { |
13788 | .cmd = NL80211_CMD_SET_MPATH, | |
ef6243ac | 13789 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2ec600d6 | 13790 | .doit = nl80211_set_mpath, |
5617c6cd | 13791 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 13792 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13793 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
13794 | }, |
13795 | { | |
13796 | .cmd = NL80211_CMD_NEW_MPATH, | |
ef6243ac | 13797 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2ec600d6 | 13798 | .doit = nl80211_new_mpath, |
5617c6cd | 13799 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 13800 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13801 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
13802 | }, |
13803 | { | |
13804 | .cmd = NL80211_CMD_DEL_MPATH, | |
ef6243ac | 13805 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2ec600d6 | 13806 | .doit = nl80211_del_mpath, |
5617c6cd | 13807 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 13808 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13809 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
13810 | }, |
13811 | { | |
13812 | .cmd = NL80211_CMD_SET_BSS, | |
ef6243ac | 13813 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
9f1ba906 | 13814 | .doit = nl80211_set_bss, |
5617c6cd | 13815 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 13816 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13817 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 13818 | }, |
f130347c LR |
13819 | { |
13820 | .cmd = NL80211_CMD_GET_REG, | |
ef6243ac | 13821 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
ad30ca2c AN |
13822 | .doit = nl80211_get_reg_do, |
13823 | .dumpit = nl80211_get_reg_dump, | |
5fe231e8 | 13824 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
13825 | /* can be retrieved by unprivileged users */ |
13826 | }, | |
b6863036 | 13827 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
b2e1b302 LR |
13828 | { |
13829 | .cmd = NL80211_CMD_SET_REG, | |
ef6243ac | 13830 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
b2e1b302 | 13831 | .doit = nl80211_set_reg, |
b2e1b302 | 13832 | .flags = GENL_ADMIN_PERM, |
5fe231e8 | 13833 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 13834 | }, |
b6863036 | 13835 | #endif |
b2e1b302 LR |
13836 | { |
13837 | .cmd = NL80211_CMD_REQ_SET_REG, | |
ef6243ac | 13838 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
b2e1b302 | 13839 | .doit = nl80211_req_set_reg, |
93da9cc1 | 13840 | .flags = GENL_ADMIN_PERM, |
13841 | }, | |
1ea4ff3e JB |
13842 | { |
13843 | .cmd = NL80211_CMD_RELOAD_REGDB, | |
ef6243ac | 13844 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
1ea4ff3e | 13845 | .doit = nl80211_reload_regdb, |
1ea4ff3e JB |
13846 | .flags = GENL_ADMIN_PERM, |
13847 | }, | |
93da9cc1 | 13848 | { |
24bdd9f4 | 13849 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
ef6243ac | 13850 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
24bdd9f4 | 13851 | .doit = nl80211_get_mesh_config, |
93da9cc1 | 13852 | /* can be retrieved by unprivileged users */ |
2b5f8b0b | 13853 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13854 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 13855 | }, |
13856 | { | |
24bdd9f4 | 13857 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
ef6243ac | 13858 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
24bdd9f4 | 13859 | .doit = nl80211_update_mesh_config, |
5617c6cd | 13860 | .flags = GENL_UNS_ADMIN_PERM, |
29cbe68c | 13861 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13862 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 13863 | }, |
2a519311 JB |
13864 | { |
13865 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
ef6243ac | 13866 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2a519311 | 13867 | .doit = nl80211_trigger_scan, |
5617c6cd | 13868 | .flags = GENL_UNS_ADMIN_PERM, |
fd014284 | 13869 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 13870 | NL80211_FLAG_NEED_RTNL, |
2a519311 | 13871 | }, |
91d3ab46 VK |
13872 | { |
13873 | .cmd = NL80211_CMD_ABORT_SCAN, | |
ef6243ac | 13874 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
91d3ab46 | 13875 | .doit = nl80211_abort_scan, |
5617c6cd | 13876 | .flags = GENL_UNS_ADMIN_PERM, |
91d3ab46 VK |
13877 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
13878 | NL80211_FLAG_NEED_RTNL, | |
13879 | }, | |
2a519311 JB |
13880 | { |
13881 | .cmd = NL80211_CMD_GET_SCAN, | |
ef6243ac | 13882 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2a519311 JB |
13883 | .dumpit = nl80211_dump_scan, |
13884 | }, | |
807f8a8c LC |
13885 | { |
13886 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
ef6243ac | 13887 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
807f8a8c | 13888 | .doit = nl80211_start_sched_scan, |
5617c6cd | 13889 | .flags = GENL_UNS_ADMIN_PERM, |
807f8a8c LC |
13890 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13891 | NL80211_FLAG_NEED_RTNL, | |
13892 | }, | |
13893 | { | |
13894 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
ef6243ac | 13895 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
807f8a8c | 13896 | .doit = nl80211_stop_sched_scan, |
5617c6cd | 13897 | .flags = GENL_UNS_ADMIN_PERM, |
807f8a8c LC |
13898 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13899 | NL80211_FLAG_NEED_RTNL, | |
13900 | }, | |
636a5d36 JM |
13901 | { |
13902 | .cmd = NL80211_CMD_AUTHENTICATE, | |
ef6243ac | 13903 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
636a5d36 | 13904 | .doit = nl80211_authenticate, |
5617c6cd | 13905 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 13906 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
13907 | NL80211_FLAG_NEED_RTNL | |
13908 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
13909 | }, |
13910 | { | |
13911 | .cmd = NL80211_CMD_ASSOCIATE, | |
ef6243ac | 13912 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
636a5d36 | 13913 | .doit = nl80211_associate, |
5617c6cd | 13914 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 13915 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
d6db02a8 SD |
13916 | NL80211_FLAG_NEED_RTNL | |
13917 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
13918 | }, |
13919 | { | |
13920 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
ef6243ac | 13921 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
636a5d36 | 13922 | .doit = nl80211_deauthenticate, |
5617c6cd | 13923 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 13924 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13925 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
13926 | }, |
13927 | { | |
13928 | .cmd = NL80211_CMD_DISASSOCIATE, | |
ef6243ac | 13929 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
636a5d36 | 13930 | .doit = nl80211_disassociate, |
5617c6cd | 13931 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 13932 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13933 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 13934 | }, |
04a773ad JB |
13935 | { |
13936 | .cmd = NL80211_CMD_JOIN_IBSS, | |
ef6243ac | 13937 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
04a773ad | 13938 | .doit = nl80211_join_ibss, |
5617c6cd | 13939 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 13940 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13941 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
13942 | }, |
13943 | { | |
13944 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
ef6243ac | 13945 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
04a773ad | 13946 | .doit = nl80211_leave_ibss, |
5617c6cd | 13947 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 13948 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13949 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 13950 | }, |
aff89a9b JB |
13951 | #ifdef CONFIG_NL80211_TESTMODE |
13952 | { | |
13953 | .cmd = NL80211_CMD_TESTMODE, | |
ef6243ac | 13954 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
aff89a9b | 13955 | .doit = nl80211_testmode_do, |
71063f0e | 13956 | .dumpit = nl80211_testmode_dump, |
5617c6cd | 13957 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
13958 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
13959 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
13960 | }, |
13961 | #endif | |
b23aa676 SO |
13962 | { |
13963 | .cmd = NL80211_CMD_CONNECT, | |
ef6243ac | 13964 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
b23aa676 | 13965 | .doit = nl80211_connect, |
5617c6cd | 13966 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 13967 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
d6db02a8 SD |
13968 | NL80211_FLAG_NEED_RTNL | |
13969 | NL80211_FLAG_CLEAR_SKB, | |
b23aa676 | 13970 | }, |
088e8df8 | 13971 | { |
13972 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, | |
ef6243ac | 13973 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
088e8df8 | 13974 | .doit = nl80211_update_connect_params, |
088e8df8 | 13975 | .flags = GENL_ADMIN_PERM, |
13976 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
d6db02a8 SD |
13977 | NL80211_FLAG_NEED_RTNL | |
13978 | NL80211_FLAG_CLEAR_SKB, | |
088e8df8 | 13979 | }, |
b23aa676 SO |
13980 | { |
13981 | .cmd = NL80211_CMD_DISCONNECT, | |
ef6243ac | 13982 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
b23aa676 | 13983 | .doit = nl80211_disconnect, |
5617c6cd | 13984 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 13985 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 13986 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 13987 | }, |
463d0183 JB |
13988 | { |
13989 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
ef6243ac | 13990 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
463d0183 | 13991 | .doit = nl80211_wiphy_netns, |
5617c6cd | 13992 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
13993 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
13994 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 13995 | }, |
61fa713c HS |
13996 | { |
13997 | .cmd = NL80211_CMD_GET_SURVEY, | |
ef6243ac | 13998 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
61fa713c HS |
13999 | .dumpit = nl80211_dump_survey, |
14000 | }, | |
67fbb16b SO |
14001 | { |
14002 | .cmd = NL80211_CMD_SET_PMKSA, | |
ef6243ac | 14003 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
67fbb16b | 14004 | .doit = nl80211_setdel_pmksa, |
5617c6cd | 14005 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 14006 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
d6db02a8 SD |
14007 | NL80211_FLAG_NEED_RTNL | |
14008 | NL80211_FLAG_CLEAR_SKB, | |
67fbb16b SO |
14009 | }, |
14010 | { | |
14011 | .cmd = NL80211_CMD_DEL_PMKSA, | |
ef6243ac | 14012 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
67fbb16b | 14013 | .doit = nl80211_setdel_pmksa, |
5617c6cd | 14014 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 14015 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 14016 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
14017 | }, |
14018 | { | |
14019 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
ef6243ac | 14020 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
67fbb16b | 14021 | .doit = nl80211_flush_pmksa, |
5617c6cd | 14022 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 14023 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 14024 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 14025 | }, |
9588bbd5 JM |
14026 | { |
14027 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
ef6243ac | 14028 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
9588bbd5 | 14029 | .doit = nl80211_remain_on_channel, |
5617c6cd | 14030 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 14031 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 14032 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
14033 | }, |
14034 | { | |
14035 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
ef6243ac | 14036 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
9588bbd5 | 14037 | .doit = nl80211_cancel_remain_on_channel, |
5617c6cd | 14038 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 14039 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 14040 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 14041 | }, |
13ae75b1 JM |
14042 | { |
14043 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
ef6243ac | 14044 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
13ae75b1 | 14045 | .doit = nl80211_set_tx_bitrate_mask, |
5617c6cd | 14046 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
14047 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
14048 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 14049 | }, |
026331c4 | 14050 | { |
2e161f78 | 14051 | .cmd = NL80211_CMD_REGISTER_FRAME, |
ef6243ac | 14052 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2e161f78 | 14053 | .doit = nl80211_register_mgmt, |
5617c6cd | 14054 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 14055 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 14056 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
14057 | }, |
14058 | { | |
2e161f78 | 14059 | .cmd = NL80211_CMD_FRAME, |
ef6243ac | 14060 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2e161f78 | 14061 | .doit = nl80211_tx_mgmt, |
5617c6cd | 14062 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 14063 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
14064 | NL80211_FLAG_NEED_RTNL, |
14065 | }, | |
14066 | { | |
14067 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
ef6243ac | 14068 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
f7ca38df | 14069 | .doit = nl80211_tx_mgmt_cancel_wait, |
5617c6cd | 14070 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 14071 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 14072 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 14073 | }, |
ffb9eb3d KV |
14074 | { |
14075 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
ef6243ac | 14076 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
ffb9eb3d | 14077 | .doit = nl80211_set_power_save, |
5617c6cd | 14078 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
14079 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
14080 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
14081 | }, |
14082 | { | |
14083 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
ef6243ac | 14084 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
ffb9eb3d | 14085 | .doit = nl80211_get_power_save, |
ffb9eb3d | 14086 | /* can be retrieved by unprivileged users */ |
4c476991 JB |
14087 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
14088 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 14089 | }, |
d6dc1a38 JO |
14090 | { |
14091 | .cmd = NL80211_CMD_SET_CQM, | |
ef6243ac | 14092 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
d6dc1a38 | 14093 | .doit = nl80211_set_cqm, |
5617c6cd | 14094 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
14095 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
14096 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 14097 | }, |
f444de05 JB |
14098 | { |
14099 | .cmd = NL80211_CMD_SET_CHANNEL, | |
ef6243ac | 14100 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
f444de05 | 14101 | .doit = nl80211_set_channel, |
5617c6cd | 14102 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
14103 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
14104 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 14105 | }, |
e8347eba BJ |
14106 | { |
14107 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
ef6243ac | 14108 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
e8347eba | 14109 | .doit = nl80211_set_wds_peer, |
5617c6cd | 14110 | .flags = GENL_UNS_ADMIN_PERM, |
43b19952 JB |
14111 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
14112 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 14113 | }, |
29cbe68c JB |
14114 | { |
14115 | .cmd = NL80211_CMD_JOIN_MESH, | |
ef6243ac | 14116 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
29cbe68c | 14117 | .doit = nl80211_join_mesh, |
5617c6cd | 14118 | .flags = GENL_UNS_ADMIN_PERM, |
29cbe68c JB |
14119 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14120 | NL80211_FLAG_NEED_RTNL, | |
14121 | }, | |
14122 | { | |
14123 | .cmd = NL80211_CMD_LEAVE_MESH, | |
ef6243ac | 14124 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
29cbe68c | 14125 | .doit = nl80211_leave_mesh, |
5617c6cd | 14126 | .flags = GENL_UNS_ADMIN_PERM, |
29cbe68c JB |
14127 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14128 | NL80211_FLAG_NEED_RTNL, | |
14129 | }, | |
6e0bd6c3 RL |
14130 | { |
14131 | .cmd = NL80211_CMD_JOIN_OCB, | |
ef6243ac | 14132 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
6e0bd6c3 | 14133 | .doit = nl80211_join_ocb, |
5617c6cd | 14134 | .flags = GENL_UNS_ADMIN_PERM, |
6e0bd6c3 RL |
14135 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14136 | NL80211_FLAG_NEED_RTNL, | |
14137 | }, | |
14138 | { | |
14139 | .cmd = NL80211_CMD_LEAVE_OCB, | |
ef6243ac | 14140 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
6e0bd6c3 | 14141 | .doit = nl80211_leave_ocb, |
5617c6cd | 14142 | .flags = GENL_UNS_ADMIN_PERM, |
6e0bd6c3 RL |
14143 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14144 | NL80211_FLAG_NEED_RTNL, | |
14145 | }, | |
dfb89c56 | 14146 | #ifdef CONFIG_PM |
ff1b6e69 JB |
14147 | { |
14148 | .cmd = NL80211_CMD_GET_WOWLAN, | |
ef6243ac | 14149 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
ff1b6e69 | 14150 | .doit = nl80211_get_wowlan, |
ff1b6e69 JB |
14151 | /* can be retrieved by unprivileged users */ |
14152 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
14153 | NL80211_FLAG_NEED_RTNL, | |
14154 | }, | |
14155 | { | |
14156 | .cmd = NL80211_CMD_SET_WOWLAN, | |
ef6243ac | 14157 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
ff1b6e69 | 14158 | .doit = nl80211_set_wowlan, |
5617c6cd | 14159 | .flags = GENL_UNS_ADMIN_PERM, |
ff1b6e69 JB |
14160 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
14161 | NL80211_FLAG_NEED_RTNL, | |
14162 | }, | |
dfb89c56 | 14163 | #endif |
e5497d76 JB |
14164 | { |
14165 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
ef6243ac | 14166 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
e5497d76 | 14167 | .doit = nl80211_set_rekey_data, |
5617c6cd | 14168 | .flags = GENL_UNS_ADMIN_PERM, |
e5497d76 | 14169 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
14170 | NL80211_FLAG_NEED_RTNL | |
14171 | NL80211_FLAG_CLEAR_SKB, | |
e5497d76 | 14172 | }, |
109086ce AN |
14173 | { |
14174 | .cmd = NL80211_CMD_TDLS_MGMT, | |
ef6243ac | 14175 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
109086ce | 14176 | .doit = nl80211_tdls_mgmt, |
5617c6cd | 14177 | .flags = GENL_UNS_ADMIN_PERM, |
109086ce AN |
14178 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14179 | NL80211_FLAG_NEED_RTNL, | |
14180 | }, | |
14181 | { | |
14182 | .cmd = NL80211_CMD_TDLS_OPER, | |
ef6243ac | 14183 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
109086ce | 14184 | .doit = nl80211_tdls_oper, |
5617c6cd | 14185 | .flags = GENL_UNS_ADMIN_PERM, |
109086ce AN |
14186 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14187 | NL80211_FLAG_NEED_RTNL, | |
14188 | }, | |
28946da7 JB |
14189 | { |
14190 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
ef6243ac | 14191 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
28946da7 | 14192 | .doit = nl80211_register_unexpected_frame, |
5617c6cd | 14193 | .flags = GENL_UNS_ADMIN_PERM, |
28946da7 JB |
14194 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
14195 | NL80211_FLAG_NEED_RTNL, | |
14196 | }, | |
7f6cf311 JB |
14197 | { |
14198 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
ef6243ac | 14199 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
7f6cf311 | 14200 | .doit = nl80211_probe_client, |
5617c6cd | 14201 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 14202 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
14203 | NL80211_FLAG_NEED_RTNL, |
14204 | }, | |
5e760230 JB |
14205 | { |
14206 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
ef6243ac | 14207 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5e760230 | 14208 | .doit = nl80211_register_beacons, |
5617c6cd | 14209 | .flags = GENL_UNS_ADMIN_PERM, |
5e760230 JB |
14210 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
14211 | NL80211_FLAG_NEED_RTNL, | |
14212 | }, | |
1d9d9213 SW |
14213 | { |
14214 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
ef6243ac | 14215 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
1d9d9213 | 14216 | .doit = nl80211_set_noack_map, |
5617c6cd | 14217 | .flags = GENL_UNS_ADMIN_PERM, |
1d9d9213 SW |
14218 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
14219 | NL80211_FLAG_NEED_RTNL, | |
14220 | }, | |
98104fde JB |
14221 | { |
14222 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
ef6243ac | 14223 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
98104fde | 14224 | .doit = nl80211_start_p2p_device, |
5617c6cd | 14225 | .flags = GENL_UNS_ADMIN_PERM, |
98104fde JB |
14226 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
14227 | NL80211_FLAG_NEED_RTNL, | |
14228 | }, | |
14229 | { | |
14230 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
ef6243ac | 14231 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
98104fde | 14232 | .doit = nl80211_stop_p2p_device, |
5617c6cd | 14233 | .flags = GENL_UNS_ADMIN_PERM, |
98104fde JB |
14234 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
14235 | NL80211_FLAG_NEED_RTNL, | |
cb3b7d87 AB |
14236 | }, |
14237 | { | |
14238 | .cmd = NL80211_CMD_START_NAN, | |
ef6243ac | 14239 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
cb3b7d87 | 14240 | .doit = nl80211_start_nan, |
cb3b7d87 AB |
14241 | .flags = GENL_ADMIN_PERM, |
14242 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
14243 | NL80211_FLAG_NEED_RTNL, | |
14244 | }, | |
14245 | { | |
14246 | .cmd = NL80211_CMD_STOP_NAN, | |
ef6243ac | 14247 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
cb3b7d87 | 14248 | .doit = nl80211_stop_nan, |
cb3b7d87 AB |
14249 | .flags = GENL_ADMIN_PERM, |
14250 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
14251 | NL80211_FLAG_NEED_RTNL, | |
a442b761 AB |
14252 | }, |
14253 | { | |
14254 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, | |
ef6243ac | 14255 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
a442b761 | 14256 | .doit = nl80211_nan_add_func, |
a442b761 AB |
14257 | .flags = GENL_ADMIN_PERM, |
14258 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
14259 | NL80211_FLAG_NEED_RTNL, | |
14260 | }, | |
14261 | { | |
14262 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, | |
ef6243ac | 14263 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
a442b761 | 14264 | .doit = nl80211_nan_del_func, |
a442b761 AB |
14265 | .flags = GENL_ADMIN_PERM, |
14266 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
14267 | NL80211_FLAG_NEED_RTNL, | |
a5a9dcf2 AB |
14268 | }, |
14269 | { | |
14270 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, | |
ef6243ac | 14271 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
a5a9dcf2 | 14272 | .doit = nl80211_nan_change_config, |
a5a9dcf2 AB |
14273 | .flags = GENL_ADMIN_PERM, |
14274 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
14275 | NL80211_FLAG_NEED_RTNL, | |
98104fde | 14276 | }, |
f4e583c8 AQ |
14277 | { |
14278 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
ef6243ac | 14279 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
f4e583c8 | 14280 | .doit = nl80211_set_mcast_rate, |
5617c6cd | 14281 | .flags = GENL_UNS_ADMIN_PERM, |
77765eaf VT |
14282 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
14283 | NL80211_FLAG_NEED_RTNL, | |
14284 | }, | |
14285 | { | |
14286 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
ef6243ac | 14287 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
77765eaf | 14288 | .doit = nl80211_set_mac_acl, |
5617c6cd | 14289 | .flags = GENL_UNS_ADMIN_PERM, |
f4e583c8 AQ |
14290 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
14291 | NL80211_FLAG_NEED_RTNL, | |
14292 | }, | |
04f39047 SW |
14293 | { |
14294 | .cmd = NL80211_CMD_RADAR_DETECT, | |
ef6243ac | 14295 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
04f39047 | 14296 | .doit = nl80211_start_radar_detection, |
5617c6cd | 14297 | .flags = GENL_UNS_ADMIN_PERM, |
04f39047 SW |
14298 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14299 | NL80211_FLAG_NEED_RTNL, | |
14300 | }, | |
3713b4e3 JB |
14301 | { |
14302 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
ef6243ac | 14303 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
3713b4e3 | 14304 | .doit = nl80211_get_protocol_features, |
3713b4e3 | 14305 | }, |
355199e0 JM |
14306 | { |
14307 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
ef6243ac | 14308 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
355199e0 | 14309 | .doit = nl80211_update_ft_ies, |
5617c6cd | 14310 | .flags = GENL_UNS_ADMIN_PERM, |
355199e0 JM |
14311 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14312 | NL80211_FLAG_NEED_RTNL, | |
14313 | }, | |
5de17984 AS |
14314 | { |
14315 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
ef6243ac | 14316 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5de17984 | 14317 | .doit = nl80211_crit_protocol_start, |
5617c6cd | 14318 | .flags = GENL_UNS_ADMIN_PERM, |
5de17984 AS |
14319 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
14320 | NL80211_FLAG_NEED_RTNL, | |
14321 | }, | |
14322 | { | |
14323 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
ef6243ac | 14324 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5de17984 | 14325 | .doit = nl80211_crit_protocol_stop, |
5617c6cd | 14326 | .flags = GENL_UNS_ADMIN_PERM, |
5de17984 AS |
14327 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
14328 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
14329 | }, |
14330 | { | |
14331 | .cmd = NL80211_CMD_GET_COALESCE, | |
ef6243ac | 14332 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
be29b99a | 14333 | .doit = nl80211_get_coalesce, |
be29b99a AK |
14334 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
14335 | NL80211_FLAG_NEED_RTNL, | |
14336 | }, | |
14337 | { | |
14338 | .cmd = NL80211_CMD_SET_COALESCE, | |
ef6243ac | 14339 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
be29b99a | 14340 | .doit = nl80211_set_coalesce, |
5617c6cd | 14341 | .flags = GENL_UNS_ADMIN_PERM, |
be29b99a AK |
14342 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
14343 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
14344 | }, |
14345 | { | |
14346 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
ef6243ac | 14347 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
16ef1fe2 | 14348 | .doit = nl80211_channel_switch, |
5617c6cd | 14349 | .flags = GENL_UNS_ADMIN_PERM, |
16ef1fe2 SW |
14350 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14351 | NL80211_FLAG_NEED_RTNL, | |
14352 | }, | |
ad7e718c JB |
14353 | { |
14354 | .cmd = NL80211_CMD_VENDOR, | |
ef6243ac | 14355 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
ad7e718c | 14356 | .doit = nl80211_vendor_cmd, |
7bdbe400 | 14357 | .dumpit = nl80211_vendor_cmd_dump, |
5617c6cd | 14358 | .flags = GENL_UNS_ADMIN_PERM, |
ad7e718c | 14359 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
d6db02a8 SD |
14360 | NL80211_FLAG_NEED_RTNL | |
14361 | NL80211_FLAG_CLEAR_SKB, | |
ad7e718c | 14362 | }, |
fa9ffc74 KP |
14363 | { |
14364 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
ef6243ac | 14365 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
fa9ffc74 | 14366 | .doit = nl80211_set_qos_map, |
5617c6cd | 14367 | .flags = GENL_UNS_ADMIN_PERM, |
fa9ffc74 KP |
14368 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14369 | NL80211_FLAG_NEED_RTNL, | |
14370 | }, | |
960d01ac JB |
14371 | { |
14372 | .cmd = NL80211_CMD_ADD_TX_TS, | |
ef6243ac | 14373 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
960d01ac | 14374 | .doit = nl80211_add_tx_ts, |
5617c6cd | 14375 | .flags = GENL_UNS_ADMIN_PERM, |
960d01ac JB |
14376 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14377 | NL80211_FLAG_NEED_RTNL, | |
14378 | }, | |
14379 | { | |
14380 | .cmd = NL80211_CMD_DEL_TX_TS, | |
ef6243ac | 14381 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
960d01ac | 14382 | .doit = nl80211_del_tx_ts, |
5617c6cd | 14383 | .flags = GENL_UNS_ADMIN_PERM, |
960d01ac JB |
14384 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14385 | NL80211_FLAG_NEED_RTNL, | |
14386 | }, | |
1057d35e AN |
14387 | { |
14388 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | |
ef6243ac | 14389 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
1057d35e | 14390 | .doit = nl80211_tdls_channel_switch, |
5617c6cd | 14391 | .flags = GENL_UNS_ADMIN_PERM, |
1057d35e AN |
14392 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14393 | NL80211_FLAG_NEED_RTNL, | |
14394 | }, | |
14395 | { | |
14396 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | |
ef6243ac | 14397 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
1057d35e | 14398 | .doit = nl80211_tdls_cancel_channel_switch, |
5617c6cd | 14399 | .flags = GENL_UNS_ADMIN_PERM, |
1057d35e AN |
14400 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14401 | NL80211_FLAG_NEED_RTNL, | |
14402 | }, | |
ce0ce13a MB |
14403 | { |
14404 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, | |
ef6243ac | 14405 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
ce0ce13a | 14406 | .doit = nl80211_set_multicast_to_unicast, |
ce0ce13a MB |
14407 | .flags = GENL_UNS_ADMIN_PERM, |
14408 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
14409 | NL80211_FLAG_NEED_RTNL, | |
14410 | }, | |
3a00df57 AS |
14411 | { |
14412 | .cmd = NL80211_CMD_SET_PMK, | |
ef6243ac | 14413 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
3a00df57 | 14414 | .doit = nl80211_set_pmk, |
3a00df57 | 14415 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
d6db02a8 SD |
14416 | NL80211_FLAG_NEED_RTNL | |
14417 | NL80211_FLAG_CLEAR_SKB, | |
3a00df57 AS |
14418 | }, |
14419 | { | |
14420 | .cmd = NL80211_CMD_DEL_PMK, | |
ef6243ac | 14421 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
3a00df57 | 14422 | .doit = nl80211_del_pmk, |
3a00df57 AS |
14423 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14424 | NL80211_FLAG_NEED_RTNL, | |
14425 | }, | |
40cbfa90 SD |
14426 | { |
14427 | .cmd = NL80211_CMD_EXTERNAL_AUTH, | |
ef6243ac | 14428 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
40cbfa90 | 14429 | .doit = nl80211_external_auth, |
40cbfa90 SD |
14430 | .flags = GENL_ADMIN_PERM, |
14431 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
14432 | NL80211_FLAG_NEED_RTNL, | |
14433 | }, | |
2576a9ac DK |
14434 | { |
14435 | .cmd = NL80211_CMD_CONTROL_PORT_FRAME, | |
ef6243ac | 14436 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2576a9ac | 14437 | .doit = nl80211_tx_control_port, |
2576a9ac DK |
14438 | .flags = GENL_UNS_ADMIN_PERM, |
14439 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
14440 | NL80211_FLAG_NEED_RTNL, | |
14441 | }, | |
81e54d08 PKC |
14442 | { |
14443 | .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, | |
ef6243ac | 14444 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
81e54d08 | 14445 | .doit = nl80211_get_ftm_responder_stats, |
81e54d08 PKC |
14446 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
14447 | NL80211_FLAG_NEED_RTNL, | |
14448 | }, | |
9bb7e0f2 JB |
14449 | { |
14450 | .cmd = NL80211_CMD_PEER_MEASUREMENT_START, | |
ef6243ac | 14451 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
9bb7e0f2 | 14452 | .doit = nl80211_pmsr_start, |
9bb7e0f2 JB |
14453 | .flags = GENL_UNS_ADMIN_PERM, |
14454 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
14455 | NL80211_FLAG_NEED_RTNL, | |
14456 | }, | |
30c63115 S |
14457 | { |
14458 | .cmd = NL80211_CMD_NOTIFY_RADAR, | |
ef6243ac | 14459 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
30c63115 | 14460 | .doit = nl80211_notify_radar_detection, |
30c63115 S |
14461 | .flags = GENL_UNS_ADMIN_PERM, |
14462 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
14463 | NL80211_FLAG_NEED_RTNL, | |
14464 | }, | |
cb74e977 SD |
14465 | { |
14466 | .cmd = NL80211_CMD_UPDATE_OWE_INFO, | |
14467 | .doit = nl80211_update_owe_info, | |
14468 | .flags = GENL_ADMIN_PERM, | |
5ab92e7f RM |
14469 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14470 | NL80211_FLAG_NEED_RTNL, | |
14471 | }, | |
14472 | { | |
14473 | .cmd = NL80211_CMD_PROBE_MESH_LINK, | |
14474 | .doit = nl80211_probe_mesh_link, | |
14475 | .flags = GENL_UNS_ADMIN_PERM, | |
cb74e977 SD |
14476 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
14477 | NL80211_FLAG_NEED_RTNL, | |
14478 | }, | |
55682965 | 14479 | }; |
9588bbd5 | 14480 | |
56989f6d | 14481 | static struct genl_family nl80211_fam __ro_after_init = { |
489111e5 JB |
14482 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
14483 | .hdrsize = 0, /* no private header */ | |
14484 | .version = 1, /* no particular meaning now */ | |
14485 | .maxattr = NL80211_ATTR_MAX, | |
3b0f31f2 | 14486 | .policy = nl80211_policy, |
489111e5 JB |
14487 | .netnsok = true, |
14488 | .pre_doit = nl80211_pre_doit, | |
14489 | .post_doit = nl80211_post_doit, | |
14490 | .module = THIS_MODULE, | |
14491 | .ops = nl80211_ops, | |
14492 | .n_ops = ARRAY_SIZE(nl80211_ops), | |
14493 | .mcgrps = nl80211_mcgrps, | |
14494 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), | |
14495 | }; | |
14496 | ||
55682965 JB |
14497 | /* notification functions */ |
14498 | ||
3bb20556 JB |
14499 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
14500 | enum nl80211_commands cmd) | |
55682965 JB |
14501 | { |
14502 | struct sk_buff *msg; | |
86e8cf98 | 14503 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 14504 | |
3bb20556 JB |
14505 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
14506 | cmd != NL80211_CMD_DEL_WIPHY); | |
14507 | ||
fd2120ca | 14508 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
14509 | if (!msg) |
14510 | return; | |
14511 | ||
3bb20556 | 14512 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
14513 | nlmsg_free(msg); |
14514 | return; | |
14515 | } | |
14516 | ||
68eb5503 | 14517 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14518 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
14519 | } |
14520 | ||
896ff063 DK |
14521 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
14522 | struct wireless_dev *wdev, | |
14523 | enum nl80211_commands cmd) | |
14524 | { | |
14525 | struct sk_buff *msg; | |
14526 | ||
896ff063 DK |
14527 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
14528 | if (!msg) | |
14529 | return; | |
14530 | ||
3d1a5bbf | 14531 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) { |
896ff063 DK |
14532 | nlmsg_free(msg); |
14533 | return; | |
14534 | } | |
14535 | ||
14536 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | |
14537 | NL80211_MCGRP_CONFIG, GFP_KERNEL); | |
14538 | } | |
14539 | ||
362a415d JB |
14540 | static int nl80211_add_scan_req(struct sk_buff *msg, |
14541 | struct cfg80211_registered_device *rdev) | |
14542 | { | |
14543 | struct cfg80211_scan_request *req = rdev->scan_req; | |
14544 | struct nlattr *nest; | |
14545 | int i; | |
14546 | ||
14547 | if (WARN_ON(!req)) | |
14548 | return 0; | |
14549 | ||
ae0be8de | 14550 | nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS); |
362a415d JB |
14551 | if (!nest) |
14552 | goto nla_put_failure; | |
9360ffd1 DM |
14553 | for (i = 0; i < req->n_ssids; i++) { |
14554 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
14555 | goto nla_put_failure; | |
14556 | } | |
362a415d JB |
14557 | nla_nest_end(msg, nest); |
14558 | ||
ae0be8de | 14559 | nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
362a415d JB |
14560 | if (!nest) |
14561 | goto nla_put_failure; | |
9360ffd1 DM |
14562 | for (i = 0; i < req->n_channels; i++) { |
14563 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
14564 | goto nla_put_failure; | |
14565 | } | |
362a415d JB |
14566 | nla_nest_end(msg, nest); |
14567 | ||
9360ffd1 DM |
14568 | if (req->ie && |
14569 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
14570 | goto nla_put_failure; | |
362a415d | 14571 | |
ae917c9f JB |
14572 | if (req->flags && |
14573 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
14574 | goto nla_put_failure; | |
ed473771 | 14575 | |
1d76250b AS |
14576 | if (req->info.scan_start_tsf && |
14577 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, | |
14578 | req->info.scan_start_tsf, NL80211_BSS_PAD) || | |
14579 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, | |
14580 | req->info.tsf_bssid))) | |
14581 | goto nla_put_failure; | |
14582 | ||
362a415d JB |
14583 | return 0; |
14584 | nla_put_failure: | |
14585 | return -ENOBUFS; | |
14586 | } | |
14587 | ||
505a2e88 | 14588 | static int nl80211_prep_scan_msg(struct sk_buff *msg, |
a538e2d5 | 14589 | struct cfg80211_registered_device *rdev, |
fd014284 | 14590 | struct wireless_dev *wdev, |
15e47304 | 14591 | u32 portid, u32 seq, int flags, |
a538e2d5 | 14592 | u32 cmd) |
2a519311 JB |
14593 | { |
14594 | void *hdr; | |
14595 | ||
15e47304 | 14596 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
14597 | if (!hdr) |
14598 | return -1; | |
14599 | ||
9360ffd1 | 14600 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
14601 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
14602 | wdev->netdev->ifindex)) || | |
2dad624e ND |
14603 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
14604 | NL80211_ATTR_PAD)) | |
9360ffd1 | 14605 | goto nla_put_failure; |
2a519311 | 14606 | |
362a415d JB |
14607 | /* ignore errors and send incomplete event anyway */ |
14608 | nl80211_add_scan_req(msg, rdev); | |
2a519311 | 14609 | |
053c095a JB |
14610 | genlmsg_end(msg, hdr); |
14611 | return 0; | |
2a519311 JB |
14612 | |
14613 | nla_put_failure: | |
14614 | genlmsg_cancel(msg, hdr); | |
14615 | return -EMSGSIZE; | |
14616 | } | |
14617 | ||
807f8a8c | 14618 | static int |
505a2e88 | 14619 | nl80211_prep_sched_scan_msg(struct sk_buff *msg, |
96b08fd6 | 14620 | struct cfg80211_sched_scan_request *req, u32 cmd) |
807f8a8c LC |
14621 | { |
14622 | void *hdr; | |
14623 | ||
96b08fd6 | 14624 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
807f8a8c LC |
14625 | if (!hdr) |
14626 | return -1; | |
14627 | ||
96b08fd6 AVS |
14628 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, |
14629 | wiphy_to_rdev(req->wiphy)->wiphy_idx) || | |
14630 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || | |
14631 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, | |
14632 | NL80211_ATTR_PAD)) | |
9360ffd1 | 14633 | goto nla_put_failure; |
807f8a8c | 14634 | |
053c095a JB |
14635 | genlmsg_end(msg, hdr); |
14636 | return 0; | |
807f8a8c LC |
14637 | |
14638 | nla_put_failure: | |
14639 | genlmsg_cancel(msg, hdr); | |
14640 | return -EMSGSIZE; | |
14641 | } | |
14642 | ||
a538e2d5 | 14643 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 14644 | struct wireless_dev *wdev) |
a538e2d5 JB |
14645 | { |
14646 | struct sk_buff *msg; | |
14647 | ||
58050fce | 14648 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
14649 | if (!msg) |
14650 | return; | |
14651 | ||
505a2e88 | 14652 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
14653 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
14654 | nlmsg_free(msg); | |
14655 | return; | |
14656 | } | |
14657 | ||
68eb5503 | 14658 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14659 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
14660 | } |
14661 | ||
f9d15d16 JB |
14662 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
14663 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
14664 | { |
14665 | struct sk_buff *msg; | |
14666 | ||
fd2120ca | 14667 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 14668 | if (!msg) |
f9d15d16 | 14669 | return NULL; |
2a519311 | 14670 | |
505a2e88 | 14671 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
14672 | aborted ? NL80211_CMD_SCAN_ABORTED : |
14673 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 14674 | nlmsg_free(msg); |
f9d15d16 | 14675 | return NULL; |
2a519311 JB |
14676 | } |
14677 | ||
f9d15d16 | 14678 | return msg; |
2a519311 JB |
14679 | } |
14680 | ||
505a2e88 AVS |
14681 | /* send message created by nl80211_build_scan_msg() */ |
14682 | void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, | |
14683 | struct sk_buff *msg) | |
807f8a8c | 14684 | { |
807f8a8c LC |
14685 | if (!msg) |
14686 | return; | |
14687 | ||
68eb5503 | 14688 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14689 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
14690 | } |
14691 | ||
96b08fd6 | 14692 | void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd) |
807f8a8c LC |
14693 | { |
14694 | struct sk_buff *msg; | |
14695 | ||
58050fce | 14696 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
14697 | if (!msg) |
14698 | return; | |
14699 | ||
96b08fd6 | 14700 | if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { |
807f8a8c LC |
14701 | nlmsg_free(msg); |
14702 | return; | |
14703 | } | |
14704 | ||
96b08fd6 | 14705 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, |
2a94fe48 | 14706 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
14707 | } |
14708 | ||
b0d7aa59 JD |
14709 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
14710 | struct regulatory_request *request) | |
73d54c9e | 14711 | { |
73d54c9e | 14712 | /* Userspace can always count this one always being set */ |
9360ffd1 DM |
14713 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
14714 | goto nla_put_failure; | |
14715 | ||
14716 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
14717 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
14718 | NL80211_REGDOM_TYPE_WORLD)) | |
14719 | goto nla_put_failure; | |
14720 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
14721 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
14722 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
14723 | goto nla_put_failure; | |
14724 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
14725 | request->intersect) { | |
14726 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
14727 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
14728 | goto nla_put_failure; | |
14729 | } else { | |
14730 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
14731 | NL80211_REGDOM_TYPE_COUNTRY) || | |
14732 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
14733 | request->alpha2)) | |
14734 | goto nla_put_failure; | |
14735 | } | |
14736 | ||
ad30ca2c AN |
14737 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
14738 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | |
14739 | ||
14740 | if (wiphy && | |
14741 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
14742 | goto nla_put_failure; | |
1bdd716c AN |
14743 | |
14744 | if (wiphy && | |
14745 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | |
14746 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
14747 | goto nla_put_failure; | |
ad30ca2c | 14748 | } |
73d54c9e | 14749 | |
b0d7aa59 JD |
14750 | return true; |
14751 | ||
14752 | nla_put_failure: | |
14753 | return false; | |
14754 | } | |
14755 | ||
14756 | /* | |
14757 | * This can happen on global regulatory changes or device specific settings | |
14758 | * based on custom regulatory domains. | |
14759 | */ | |
14760 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | |
14761 | struct regulatory_request *request) | |
14762 | { | |
14763 | struct sk_buff *msg; | |
14764 | void *hdr; | |
14765 | ||
14766 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
14767 | if (!msg) | |
14768 | return; | |
14769 | ||
14770 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | |
14771 | if (!hdr) { | |
14772 | nlmsg_free(msg); | |
14773 | return; | |
14774 | } | |
14775 | ||
14776 | if (nl80211_reg_change_event_fill(msg, request) == false) | |
14777 | goto nla_put_failure; | |
14778 | ||
3b7b72ee | 14779 | genlmsg_end(msg, hdr); |
73d54c9e | 14780 | |
bc43b28c | 14781 | rcu_read_lock(); |
68eb5503 | 14782 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 14783 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 14784 | rcu_read_unlock(); |
73d54c9e LR |
14785 | |
14786 | return; | |
14787 | ||
14788 | nla_put_failure: | |
73d54c9e LR |
14789 | nlmsg_free(msg); |
14790 | } | |
14791 | ||
6039f6d2 JM |
14792 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
14793 | struct net_device *netdev, | |
14794 | const u8 *buf, size_t len, | |
b0b6aa2c | 14795 | enum nl80211_commands cmd, gfp_t gfp, |
4d9ec73d JM |
14796 | int uapsd_queues, const u8 *req_ies, |
14797 | size_t req_ies_len) | |
6039f6d2 JM |
14798 | { |
14799 | struct sk_buff *msg; | |
14800 | void *hdr; | |
14801 | ||
4d9ec73d | 14802 | msg = nlmsg_new(100 + len + req_ies_len, gfp); |
6039f6d2 JM |
14803 | if (!msg) |
14804 | return; | |
14805 | ||
14806 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
14807 | if (!hdr) { | |
14808 | nlmsg_free(msg); | |
14809 | return; | |
14810 | } | |
14811 | ||
9360ffd1 DM |
14812 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
14813 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
4d9ec73d JM |
14814 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
14815 | (req_ies && | |
14816 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies))) | |
9360ffd1 | 14817 | goto nla_put_failure; |
6039f6d2 | 14818 | |
b0b6aa2c EP |
14819 | if (uapsd_queues >= 0) { |
14820 | struct nlattr *nla_wmm = | |
ae0be8de | 14821 | nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME); |
b0b6aa2c EP |
14822 | if (!nla_wmm) |
14823 | goto nla_put_failure; | |
14824 | ||
14825 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
14826 | uapsd_queues)) | |
14827 | goto nla_put_failure; | |
14828 | ||
14829 | nla_nest_end(msg, nla_wmm); | |
14830 | } | |
14831 | ||
3b7b72ee | 14832 | genlmsg_end(msg, hdr); |
6039f6d2 | 14833 | |
68eb5503 | 14834 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14835 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
14836 | return; |
14837 | ||
14838 | nla_put_failure: | |
6039f6d2 JM |
14839 | nlmsg_free(msg); |
14840 | } | |
14841 | ||
14842 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
14843 | struct net_device *netdev, const u8 *buf, |
14844 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
14845 | { |
14846 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
4d9ec73d | 14847 | NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0); |
6039f6d2 JM |
14848 | } |
14849 | ||
14850 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
14851 | struct net_device *netdev, const u8 *buf, | |
4d9ec73d JM |
14852 | size_t len, gfp_t gfp, int uapsd_queues, |
14853 | const u8 *req_ies, size_t req_ies_len) | |
6039f6d2 | 14854 | { |
e6d6e342 | 14855 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
4d9ec73d JM |
14856 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues, |
14857 | req_ies, req_ies_len); | |
6039f6d2 JM |
14858 | } |
14859 | ||
53b46b84 | 14860 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
14861 | struct net_device *netdev, const u8 *buf, |
14862 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
14863 | { |
14864 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
4d9ec73d | 14865 | NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0); |
6039f6d2 JM |
14866 | } |
14867 | ||
53b46b84 JM |
14868 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
14869 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 14870 | size_t len, gfp_t gfp) |
6039f6d2 JM |
14871 | { |
14872 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
4d9ec73d | 14873 | NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0); |
6039f6d2 JM |
14874 | } |
14875 | ||
6ff57cf8 JB |
14876 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
14877 | size_t len) | |
cf4e594e | 14878 | { |
947add36 JB |
14879 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
14880 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 14881 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
14882 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
14883 | u32 cmd; | |
947add36 | 14884 | |
6ff57cf8 JB |
14885 | if (WARN_ON(len < 2)) |
14886 | return; | |
cf4e594e | 14887 | |
6ff57cf8 JB |
14888 | if (ieee80211_is_deauth(mgmt->frame_control)) |
14889 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
14890 | else | |
14891 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 14892 | |
6ff57cf8 | 14893 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
4d9ec73d JM |
14894 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1, |
14895 | NULL, 0); | |
cf4e594e | 14896 | } |
6ff57cf8 | 14897 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 14898 | |
1b06bb40 LR |
14899 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
14900 | struct net_device *netdev, int cmd, | |
e6d6e342 | 14901 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
14902 | { |
14903 | struct sk_buff *msg; | |
14904 | void *hdr; | |
14905 | ||
e6d6e342 | 14906 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
14907 | if (!msg) |
14908 | return; | |
14909 | ||
14910 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
14911 | if (!hdr) { | |
14912 | nlmsg_free(msg); | |
14913 | return; | |
14914 | } | |
14915 | ||
9360ffd1 DM |
14916 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
14917 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
14918 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
14919 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
14920 | goto nla_put_failure; | |
1965c853 | 14921 | |
3b7b72ee | 14922 | genlmsg_end(msg, hdr); |
1965c853 | 14923 | |
68eb5503 | 14924 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14925 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
14926 | return; |
14927 | ||
14928 | nla_put_failure: | |
1965c853 JM |
14929 | nlmsg_free(msg); |
14930 | } | |
14931 | ||
14932 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
14933 | struct net_device *netdev, const u8 *addr, |
14934 | gfp_t gfp) | |
1965c853 JM |
14935 | { |
14936 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 14937 | addr, gfp); |
1965c853 JM |
14938 | } |
14939 | ||
14940 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
14941 | struct net_device *netdev, const u8 *addr, |
14942 | gfp_t gfp) | |
1965c853 | 14943 | { |
e6d6e342 JB |
14944 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
14945 | addr, gfp); | |
1965c853 JM |
14946 | } |
14947 | ||
b23aa676 | 14948 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
5349a0f7 VK |
14949 | struct net_device *netdev, |
14950 | struct cfg80211_connect_resp_params *cr, | |
3093ebbe | 14951 | gfp_t gfp) |
b23aa676 SO |
14952 | { |
14953 | struct sk_buff *msg; | |
14954 | void *hdr; | |
14955 | ||
a3caf744 | 14956 | msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + |
76804d28 AVS |
14957 | cr->fils.kek_len + cr->fils.pmk_len + |
14958 | (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); | |
b23aa676 SO |
14959 | if (!msg) |
14960 | return; | |
14961 | ||
14962 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
14963 | if (!hdr) { | |
14964 | nlmsg_free(msg); | |
14965 | return; | |
14966 | } | |
14967 | ||
9360ffd1 DM |
14968 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
14969 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
5349a0f7 VK |
14970 | (cr->bssid && |
14971 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || | |
bf1ecd21 | 14972 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
5349a0f7 VK |
14973 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
14974 | cr->status) || | |
14975 | (cr->status < 0 && | |
3093ebbe | 14976 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
5349a0f7 VK |
14977 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, |
14978 | cr->timeout_reason))) || | |
14979 | (cr->req_ie && | |
14980 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || | |
14981 | (cr->resp_ie && | |
14982 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, | |
a3caf744 | 14983 | cr->resp_ie)) || |
76804d28 | 14984 | (cr->fils.update_erp_next_seq_num && |
a3caf744 | 14985 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
76804d28 | 14986 | cr->fils.erp_next_seq_num)) || |
a3caf744 | 14987 | (cr->status == WLAN_STATUS_SUCCESS && |
76804d28 AVS |
14988 | ((cr->fils.kek && |
14989 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, | |
14990 | cr->fils.kek)) || | |
14991 | (cr->fils.pmk && | |
14992 | nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || | |
14993 | (cr->fils.pmkid && | |
14994 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid))))) | |
9360ffd1 | 14995 | goto nla_put_failure; |
b23aa676 | 14996 | |
3b7b72ee | 14997 | genlmsg_end(msg, hdr); |
b23aa676 | 14998 | |
68eb5503 | 14999 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15000 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
15001 | return; |
15002 | ||
15003 | nla_put_failure: | |
b23aa676 | 15004 | nlmsg_free(msg); |
b23aa676 SO |
15005 | } |
15006 | ||
15007 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
29ce6ecb AS |
15008 | struct net_device *netdev, |
15009 | struct cfg80211_roam_info *info, gfp_t gfp) | |
b23aa676 SO |
15010 | { |
15011 | struct sk_buff *msg; | |
15012 | void *hdr; | |
29ce6ecb | 15013 | const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; |
b23aa676 | 15014 | |
e841b7b1 AVS |
15015 | msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + |
15016 | info->fils.kek_len + info->fils.pmk_len + | |
15017 | (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); | |
b23aa676 SO |
15018 | if (!msg) |
15019 | return; | |
15020 | ||
15021 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
15022 | if (!hdr) { | |
15023 | nlmsg_free(msg); | |
15024 | return; | |
15025 | } | |
15026 | ||
9360ffd1 DM |
15027 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
15028 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
15029 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
29ce6ecb AS |
15030 | (info->req_ie && |
15031 | nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, | |
15032 | info->req_ie)) || | |
15033 | (info->resp_ie && | |
15034 | nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, | |
e841b7b1 AVS |
15035 | info->resp_ie)) || |
15036 | (info->fils.update_erp_next_seq_num && | |
15037 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, | |
15038 | info->fils.erp_next_seq_num)) || | |
15039 | (info->fils.kek && | |
15040 | nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, | |
15041 | info->fils.kek)) || | |
15042 | (info->fils.pmk && | |
15043 | nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || | |
15044 | (info->fils.pmkid && | |
15045 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid))) | |
9360ffd1 | 15046 | goto nla_put_failure; |
b23aa676 | 15047 | |
3b7b72ee | 15048 | genlmsg_end(msg, hdr); |
b23aa676 | 15049 | |
68eb5503 | 15050 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15051 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
15052 | return; |
15053 | ||
503c1fb9 | 15054 | nla_put_failure: |
503c1fb9 AS |
15055 | nlmsg_free(msg); |
15056 | } | |
15057 | ||
15058 | void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, | |
15059 | struct net_device *netdev, const u8 *bssid) | |
15060 | { | |
15061 | struct sk_buff *msg; | |
15062 | void *hdr; | |
15063 | ||
15064 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
15065 | if (!msg) | |
15066 | return; | |
15067 | ||
15068 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); | |
15069 | if (!hdr) { | |
15070 | nlmsg_free(msg); | |
15071 | return; | |
15072 | } | |
15073 | ||
15074 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
15075 | goto nla_put_failure; | |
15076 | ||
15077 | genlmsg_end(msg, hdr); | |
15078 | ||
15079 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | |
15080 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
15081 | return; | |
15082 | ||
b23aa676 | 15083 | nla_put_failure: |
b23aa676 | 15084 | nlmsg_free(msg); |
b23aa676 SO |
15085 | } |
15086 | ||
15087 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
15088 | struct net_device *netdev, u16 reason, | |
667503dd | 15089 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
15090 | { |
15091 | struct sk_buff *msg; | |
15092 | void *hdr; | |
15093 | ||
4ef8c1c9 | 15094 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); |
b23aa676 SO |
15095 | if (!msg) |
15096 | return; | |
15097 | ||
15098 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
15099 | if (!hdr) { | |
15100 | nlmsg_free(msg); | |
15101 | return; | |
15102 | } | |
15103 | ||
9360ffd1 DM |
15104 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
15105 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
86b6c465 | 15106 | (reason && |
9360ffd1 DM |
15107 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
15108 | (from_ap && | |
15109 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
15110 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
15111 | goto nla_put_failure; | |
b23aa676 | 15112 | |
3b7b72ee | 15113 | genlmsg_end(msg, hdr); |
b23aa676 | 15114 | |
68eb5503 | 15115 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15116 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
15117 | return; |
15118 | ||
15119 | nla_put_failure: | |
b23aa676 | 15120 | nlmsg_free(msg); |
b23aa676 SO |
15121 | } |
15122 | ||
04a773ad JB |
15123 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
15124 | struct net_device *netdev, const u8 *bssid, | |
15125 | gfp_t gfp) | |
15126 | { | |
15127 | struct sk_buff *msg; | |
15128 | void *hdr; | |
15129 | ||
fd2120ca | 15130 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
15131 | if (!msg) |
15132 | return; | |
15133 | ||
15134 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
15135 | if (!hdr) { | |
15136 | nlmsg_free(msg); | |
15137 | return; | |
15138 | } | |
15139 | ||
9360ffd1 DM |
15140 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
15141 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
15142 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
15143 | goto nla_put_failure; | |
04a773ad | 15144 | |
3b7b72ee | 15145 | genlmsg_end(msg, hdr); |
04a773ad | 15146 | |
68eb5503 | 15147 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15148 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
15149 | return; |
15150 | ||
15151 | nla_put_failure: | |
04a773ad JB |
15152 | nlmsg_free(msg); |
15153 | } | |
15154 | ||
947add36 | 15155 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
ecbc12ad BC |
15156 | const u8 *ie, u8 ie_len, |
15157 | int sig_dbm, gfp_t gfp) | |
c93b5e71 | 15158 | { |
947add36 | 15159 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 15160 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
15161 | struct sk_buff *msg; |
15162 | void *hdr; | |
15163 | ||
947add36 JB |
15164 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
15165 | return; | |
15166 | ||
15167 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
15168 | ||
4ef8c1c9 | 15169 | msg = nlmsg_new(100 + ie_len, gfp); |
c93b5e71 JC |
15170 | if (!msg) |
15171 | return; | |
15172 | ||
15173 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
15174 | if (!hdr) { | |
15175 | nlmsg_free(msg); | |
15176 | return; | |
15177 | } | |
15178 | ||
9360ffd1 | 15179 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
15180 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
15181 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 | 15182 | (ie_len && ie && |
ecbc12ad BC |
15183 | nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) || |
15184 | (sig_dbm && | |
15185 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm))) | |
9360ffd1 | 15186 | goto nla_put_failure; |
c93b5e71 | 15187 | |
3b7b72ee | 15188 | genlmsg_end(msg, hdr); |
c93b5e71 | 15189 | |
68eb5503 | 15190 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15191 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
15192 | return; |
15193 | ||
15194 | nla_put_failure: | |
c93b5e71 JC |
15195 | nlmsg_free(msg); |
15196 | } | |
947add36 | 15197 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 15198 | |
a3b8b056 JM |
15199 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
15200 | struct net_device *netdev, const u8 *addr, | |
15201 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 15202 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
15203 | { |
15204 | struct sk_buff *msg; | |
15205 | void *hdr; | |
15206 | ||
e6d6e342 | 15207 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
15208 | if (!msg) |
15209 | return; | |
15210 | ||
15211 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
15212 | if (!hdr) { | |
15213 | nlmsg_free(msg); | |
15214 | return; | |
15215 | } | |
15216 | ||
9360ffd1 DM |
15217 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
15218 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
15219 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
15220 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
15221 | (key_id != -1 && | |
15222 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
15223 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
15224 | goto nla_put_failure; | |
a3b8b056 | 15225 | |
3b7b72ee | 15226 | genlmsg_end(msg, hdr); |
a3b8b056 | 15227 | |
68eb5503 | 15228 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15229 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
15230 | return; |
15231 | ||
15232 | nla_put_failure: | |
a3b8b056 JM |
15233 | nlmsg_free(msg); |
15234 | } | |
15235 | ||
6bad8766 LR |
15236 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
15237 | struct ieee80211_channel *channel_before, | |
15238 | struct ieee80211_channel *channel_after) | |
15239 | { | |
15240 | struct sk_buff *msg; | |
15241 | void *hdr; | |
15242 | struct nlattr *nl_freq; | |
15243 | ||
fd2120ca | 15244 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
15245 | if (!msg) |
15246 | return; | |
15247 | ||
15248 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
15249 | if (!hdr) { | |
15250 | nlmsg_free(msg); | |
15251 | return; | |
15252 | } | |
15253 | ||
15254 | /* | |
15255 | * Since we are applying the beacon hint to a wiphy we know its | |
15256 | * wiphy_idx is valid | |
15257 | */ | |
9360ffd1 DM |
15258 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
15259 | goto nla_put_failure; | |
6bad8766 LR |
15260 | |
15261 | /* Before */ | |
ae0be8de | 15262 | nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE); |
6bad8766 LR |
15263 | if (!nl_freq) |
15264 | goto nla_put_failure; | |
50f32718 HD |
15265 | |
15266 | if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) | |
6bad8766 LR |
15267 | goto nla_put_failure; |
15268 | nla_nest_end(msg, nl_freq); | |
15269 | ||
15270 | /* After */ | |
ae0be8de | 15271 | nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER); |
6bad8766 LR |
15272 | if (!nl_freq) |
15273 | goto nla_put_failure; | |
50f32718 HD |
15274 | |
15275 | if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) | |
6bad8766 LR |
15276 | goto nla_put_failure; |
15277 | nla_nest_end(msg, nl_freq); | |
15278 | ||
3b7b72ee | 15279 | genlmsg_end(msg, hdr); |
6bad8766 | 15280 | |
463d0183 | 15281 | rcu_read_lock(); |
68eb5503 | 15282 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 15283 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 15284 | rcu_read_unlock(); |
6bad8766 LR |
15285 | |
15286 | return; | |
15287 | ||
15288 | nla_put_failure: | |
6bad8766 LR |
15289 | nlmsg_free(msg); |
15290 | } | |
15291 | ||
9588bbd5 JM |
15292 | static void nl80211_send_remain_on_chan_event( |
15293 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 15294 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 15295 | struct ieee80211_channel *chan, |
9588bbd5 JM |
15296 | unsigned int duration, gfp_t gfp) |
15297 | { | |
15298 | struct sk_buff *msg; | |
15299 | void *hdr; | |
15300 | ||
15301 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
15302 | if (!msg) | |
15303 | return; | |
15304 | ||
15305 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
15306 | if (!hdr) { | |
15307 | nlmsg_free(msg); | |
15308 | return; | |
15309 | } | |
15310 | ||
9360ffd1 | 15311 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
15312 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
15313 | wdev->netdev->ifindex)) || | |
2dad624e ND |
15314 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
15315 | NL80211_ATTR_PAD) || | |
9360ffd1 | 15316 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
15317 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
15318 | NL80211_CHAN_NO_HT) || | |
2dad624e ND |
15319 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
15320 | NL80211_ATTR_PAD)) | |
9360ffd1 | 15321 | goto nla_put_failure; |
9588bbd5 | 15322 | |
9360ffd1 DM |
15323 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
15324 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
15325 | goto nla_put_failure; | |
9588bbd5 | 15326 | |
3b7b72ee | 15327 | genlmsg_end(msg, hdr); |
9588bbd5 | 15328 | |
68eb5503 | 15329 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15330 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
15331 | return; |
15332 | ||
15333 | nla_put_failure: | |
9588bbd5 JM |
15334 | nlmsg_free(msg); |
15335 | } | |
15336 | ||
947add36 JB |
15337 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
15338 | struct ieee80211_channel *chan, | |
15339 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 15340 | { |
947add36 | 15341 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 15342 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
15343 | |
15344 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 15345 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 15346 | rdev, wdev, cookie, chan, |
42d97a59 | 15347 | duration, gfp); |
9588bbd5 | 15348 | } |
947add36 | 15349 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 15350 | |
947add36 JB |
15351 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
15352 | struct ieee80211_channel *chan, | |
15353 | gfp_t gfp) | |
9588bbd5 | 15354 | { |
947add36 | 15355 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 15356 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
15357 | |
15358 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 15359 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 15360 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 15361 | } |
947add36 | 15362 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 15363 | |
947add36 JB |
15364 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
15365 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 15366 | { |
947add36 | 15367 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 15368 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
15369 | struct sk_buff *msg; |
15370 | ||
947add36 JB |
15371 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
15372 | ||
58050fce | 15373 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
15374 | if (!msg) |
15375 | return; | |
15376 | ||
cf5ead82 | 15377 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
66266b3a | 15378 | rdev, dev, mac_addr, sinfo) < 0) { |
98b62183 JB |
15379 | nlmsg_free(msg); |
15380 | return; | |
15381 | } | |
15382 | ||
68eb5503 | 15383 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15384 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 15385 | } |
947add36 | 15386 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 15387 | |
cf5ead82 JB |
15388 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
15389 | struct station_info *sinfo, gfp_t gfp) | |
ec15e68b | 15390 | { |
947add36 | 15391 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 15392 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b | 15393 | struct sk_buff *msg; |
73887fd9 | 15394 | struct station_info empty_sinfo = {}; |
cf5ead82 | 15395 | |
73887fd9 JB |
15396 | if (!sinfo) |
15397 | sinfo = &empty_sinfo; | |
ec15e68b | 15398 | |
947add36 JB |
15399 | trace_cfg80211_del_sta(dev, mac_addr); |
15400 | ||
58050fce | 15401 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
7ea3e110 JB |
15402 | if (!msg) { |
15403 | cfg80211_sinfo_release_content(sinfo); | |
73887fd9 | 15404 | return; |
7ea3e110 | 15405 | } |
ec15e68b | 15406 | |
cf5ead82 | 15407 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
57007121 | 15408 | rdev, dev, mac_addr, sinfo) < 0) { |
ec15e68b | 15409 | nlmsg_free(msg); |
73887fd9 | 15410 | return; |
ec15e68b JM |
15411 | } |
15412 | ||
68eb5503 | 15413 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15414 | NL80211_MCGRP_MLME, gfp); |
ec15e68b | 15415 | } |
cf5ead82 | 15416 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
ec15e68b | 15417 | |
947add36 JB |
15418 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
15419 | enum nl80211_connect_failed_reason reason, | |
15420 | gfp_t gfp) | |
ed44a951 | 15421 | { |
947add36 | 15422 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 15423 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
15424 | struct sk_buff *msg; |
15425 | void *hdr; | |
15426 | ||
15427 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
15428 | if (!msg) | |
15429 | return; | |
15430 | ||
15431 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
15432 | if (!hdr) { | |
15433 | nlmsg_free(msg); | |
15434 | return; | |
15435 | } | |
15436 | ||
15437 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
15438 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
15439 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
15440 | goto nla_put_failure; | |
15441 | ||
15442 | genlmsg_end(msg, hdr); | |
15443 | ||
68eb5503 | 15444 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15445 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
15446 | return; |
15447 | ||
15448 | nla_put_failure: | |
ed44a951 PP |
15449 | nlmsg_free(msg); |
15450 | } | |
947add36 | 15451 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 15452 | |
b92ab5d8 JB |
15453 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
15454 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
15455 | { |
15456 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 15457 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
15458 | struct sk_buff *msg; |
15459 | void *hdr; | |
6aa7de05 | 15460 | u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 15461 | |
15e47304 | 15462 | if (!nlportid) |
28946da7 JB |
15463 | return false; |
15464 | ||
15465 | msg = nlmsg_new(100, gfp); | |
15466 | if (!msg) | |
15467 | return true; | |
15468 | ||
b92ab5d8 | 15469 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
15470 | if (!hdr) { |
15471 | nlmsg_free(msg); | |
15472 | return true; | |
15473 | } | |
15474 | ||
9360ffd1 DM |
15475 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
15476 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
15477 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
15478 | goto nla_put_failure; | |
28946da7 | 15479 | |
9c90a9f6 | 15480 | genlmsg_end(msg, hdr); |
15e47304 | 15481 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
15482 | return true; |
15483 | ||
15484 | nla_put_failure: | |
28946da7 JB |
15485 | nlmsg_free(msg); |
15486 | return true; | |
15487 | } | |
15488 | ||
947add36 JB |
15489 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
15490 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 15491 | { |
947add36 JB |
15492 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
15493 | bool ret; | |
15494 | ||
15495 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
15496 | ||
15497 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
15498 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
15499 | trace_cfg80211_return_bool(false); | |
15500 | return false; | |
15501 | } | |
15502 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
15503 | addr, gfp); | |
15504 | trace_cfg80211_return_bool(ret); | |
15505 | return ret; | |
b92ab5d8 | 15506 | } |
947add36 | 15507 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 15508 | |
947add36 JB |
15509 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
15510 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 15511 | { |
947add36 JB |
15512 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
15513 | bool ret; | |
15514 | ||
15515 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
15516 | ||
15517 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
15518 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
15519 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
15520 | trace_cfg80211_return_bool(false); | |
15521 | return false; | |
15522 | } | |
15523 | ret = __nl80211_unexpected_frame(dev, | |
15524 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
15525 | addr, gfp); | |
15526 | trace_cfg80211_return_bool(ret); | |
15527 | return ret; | |
b92ab5d8 | 15528 | } |
947add36 | 15529 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 15530 | |
2e161f78 | 15531 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 15532 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 15533 | int freq, int sig_dbm, |
19504cf5 | 15534 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 15535 | { |
71bbc994 | 15536 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
15537 | struct sk_buff *msg; |
15538 | void *hdr; | |
026331c4 | 15539 | |
4ef8c1c9 | 15540 | msg = nlmsg_new(100 + len, gfp); |
026331c4 JM |
15541 | if (!msg) |
15542 | return -ENOMEM; | |
15543 | ||
2e161f78 | 15544 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
15545 | if (!hdr) { |
15546 | nlmsg_free(msg); | |
15547 | return -ENOMEM; | |
15548 | } | |
15549 | ||
9360ffd1 | 15550 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
15551 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
15552 | netdev->ifindex)) || | |
2dad624e ND |
15553 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
15554 | NL80211_ATTR_PAD) || | |
9360ffd1 DM |
15555 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
15556 | (sig_dbm && | |
15557 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
15558 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
15559 | (flags && | |
15560 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 15561 | goto nla_put_failure; |
026331c4 | 15562 | |
3b7b72ee | 15563 | genlmsg_end(msg, hdr); |
026331c4 | 15564 | |
15e47304 | 15565 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
15566 | |
15567 | nla_put_failure: | |
026331c4 JM |
15568 | nlmsg_free(msg); |
15569 | return -ENOBUFS; | |
15570 | } | |
15571 | ||
947add36 JB |
15572 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
15573 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 15574 | { |
947add36 | 15575 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 15576 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 15577 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
15578 | struct sk_buff *msg; |
15579 | void *hdr; | |
15580 | ||
947add36 JB |
15581 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
15582 | ||
4ef8c1c9 | 15583 | msg = nlmsg_new(100 + len, gfp); |
026331c4 JM |
15584 | if (!msg) |
15585 | return; | |
15586 | ||
2e161f78 | 15587 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
15588 | if (!hdr) { |
15589 | nlmsg_free(msg); | |
15590 | return; | |
15591 | } | |
15592 | ||
9360ffd1 | 15593 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
15594 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
15595 | netdev->ifindex)) || | |
2dad624e ND |
15596 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
15597 | NL80211_ATTR_PAD) || | |
9360ffd1 | 15598 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
2dad624e ND |
15599 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
15600 | NL80211_ATTR_PAD) || | |
9360ffd1 DM |
15601 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
15602 | goto nla_put_failure; | |
026331c4 | 15603 | |
3b7b72ee | 15604 | genlmsg_end(msg, hdr); |
026331c4 | 15605 | |
68eb5503 | 15606 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15607 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
15608 | return; |
15609 | ||
15610 | nla_put_failure: | |
026331c4 JM |
15611 | nlmsg_free(msg); |
15612 | } | |
947add36 | 15613 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 15614 | |
6a671a50 | 15615 | static int __nl80211_rx_control_port(struct net_device *dev, |
a948f713 | 15616 | struct sk_buff *skb, |
6a671a50 DK |
15617 | bool unencrypted, gfp_t gfp) |
15618 | { | |
15619 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
15620 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | |
a948f713 DK |
15621 | struct ethhdr *ehdr = eth_hdr(skb); |
15622 | const u8 *addr = ehdr->h_source; | |
15623 | u16 proto = be16_to_cpu(skb->protocol); | |
6a671a50 DK |
15624 | struct sk_buff *msg; |
15625 | void *hdr; | |
a948f713 DK |
15626 | struct nlattr *frame; |
15627 | ||
6a671a50 DK |
15628 | u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); |
15629 | ||
15630 | if (!nlportid) | |
15631 | return -ENOENT; | |
15632 | ||
a948f713 | 15633 | msg = nlmsg_new(100 + skb->len, gfp); |
6a671a50 DK |
15634 | if (!msg) |
15635 | return -ENOMEM; | |
15636 | ||
15637 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); | |
15638 | if (!hdr) { | |
15639 | nlmsg_free(msg); | |
15640 | return -ENOBUFS; | |
15641 | } | |
15642 | ||
15643 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
15644 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
15645 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | |
15646 | NL80211_ATTR_PAD) || | |
6a671a50 DK |
15647 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
15648 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || | |
15649 | (unencrypted && nla_put_flag(msg, | |
15650 | NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | |
15651 | goto nla_put_failure; | |
15652 | ||
a948f713 DK |
15653 | frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len); |
15654 | if (!frame) | |
15655 | goto nla_put_failure; | |
15656 | ||
15657 | skb_copy_bits(skb, 0, nla_data(frame), skb->len); | |
6a671a50 DK |
15658 | genlmsg_end(msg, hdr); |
15659 | ||
15660 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
15661 | ||
15662 | nla_put_failure: | |
15663 | nlmsg_free(msg); | |
15664 | return -ENOBUFS; | |
15665 | } | |
15666 | ||
15667 | bool cfg80211_rx_control_port(struct net_device *dev, | |
a948f713 | 15668 | struct sk_buff *skb, bool unencrypted) |
6a671a50 DK |
15669 | { |
15670 | int ret; | |
15671 | ||
a948f713 DK |
15672 | trace_cfg80211_rx_control_port(dev, skb, unencrypted); |
15673 | ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC); | |
6a671a50 DK |
15674 | trace_cfg80211_return_bool(ret == 0); |
15675 | return ret == 0; | |
15676 | } | |
15677 | EXPORT_SYMBOL(cfg80211_rx_control_port); | |
15678 | ||
5b97f49d JB |
15679 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
15680 | const char *mac, gfp_t gfp) | |
d6dc1a38 | 15681 | { |
947add36 | 15682 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5b97f49d JB |
15683 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
15684 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
15685 | void **cb; | |
947add36 | 15686 | |
d6dc1a38 | 15687 | if (!msg) |
5b97f49d | 15688 | return NULL; |
d6dc1a38 | 15689 | |
5b97f49d JB |
15690 | cb = (void **)msg->cb; |
15691 | ||
15692 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
15693 | if (!cb[0]) { | |
d6dc1a38 | 15694 | nlmsg_free(msg); |
5b97f49d | 15695 | return NULL; |
d6dc1a38 JO |
15696 | } |
15697 | ||
9360ffd1 | 15698 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 15699 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 15700 | goto nla_put_failure; |
d6dc1a38 | 15701 | |
5b97f49d | 15702 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
d6dc1a38 JO |
15703 | goto nla_put_failure; |
15704 | ||
ae0be8de | 15705 | cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM); |
5b97f49d | 15706 | if (!cb[1]) |
9360ffd1 | 15707 | goto nla_put_failure; |
d6dc1a38 | 15708 | |
5b97f49d | 15709 | cb[2] = rdev; |
d6dc1a38 | 15710 | |
5b97f49d JB |
15711 | return msg; |
15712 | nla_put_failure: | |
15713 | nlmsg_free(msg); | |
15714 | return NULL; | |
15715 | } | |
15716 | ||
15717 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | |
15718 | { | |
15719 | void **cb = (void **)msg->cb; | |
15720 | struct cfg80211_registered_device *rdev = cb[2]; | |
15721 | ||
15722 | nla_nest_end(msg, cb[1]); | |
15723 | genlmsg_end(msg, cb[0]); | |
15724 | ||
15725 | memset(msg->cb, 0, sizeof(msg->cb)); | |
d6dc1a38 | 15726 | |
68eb5503 | 15727 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15728 | NL80211_MCGRP_MLME, gfp); |
5b97f49d JB |
15729 | } |
15730 | ||
15731 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | |
15732 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
bee427b8 | 15733 | s32 rssi_level, gfp_t gfp) |
5b97f49d JB |
15734 | { |
15735 | struct sk_buff *msg; | |
4a4b8169 AZ |
15736 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
15737 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | |
5b97f49d | 15738 | |
bee427b8 | 15739 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); |
5b97f49d | 15740 | |
98f03342 JB |
15741 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
15742 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | |
15743 | return; | |
15744 | ||
4a4b8169 AZ |
15745 | if (wdev->cqm_config) { |
15746 | wdev->cqm_config->last_rssi_event_value = rssi_level; | |
15747 | ||
15748 | cfg80211_cqm_rssi_update(rdev, dev); | |
15749 | ||
15750 | if (rssi_level == 0) | |
15751 | rssi_level = wdev->cqm_config->last_rssi_event_value; | |
15752 | } | |
15753 | ||
5b97f49d JB |
15754 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
15755 | if (!msg) | |
15756 | return; | |
15757 | ||
15758 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
15759 | rssi_event)) | |
15760 | goto nla_put_failure; | |
15761 | ||
bee427b8 AZ |
15762 | if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, |
15763 | rssi_level)) | |
15764 | goto nla_put_failure; | |
15765 | ||
5b97f49d JB |
15766 | cfg80211_send_cqm(msg, gfp); |
15767 | ||
d6dc1a38 JO |
15768 | return; |
15769 | ||
15770 | nla_put_failure: | |
d6dc1a38 JO |
15771 | nlmsg_free(msg); |
15772 | } | |
947add36 | 15773 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 15774 | |
5b97f49d JB |
15775 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
15776 | const u8 *peer, u32 num_packets, | |
15777 | u32 rate, u32 intvl, gfp_t gfp) | |
15778 | { | |
15779 | struct sk_buff *msg; | |
15780 | ||
15781 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
15782 | if (!msg) | |
15783 | return; | |
15784 | ||
15785 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
15786 | goto nla_put_failure; | |
15787 | ||
15788 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
15789 | goto nla_put_failure; | |
15790 | ||
15791 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
15792 | goto nla_put_failure; | |
15793 | ||
15794 | cfg80211_send_cqm(msg, gfp); | |
15795 | return; | |
15796 | ||
15797 | nla_put_failure: | |
15798 | nlmsg_free(msg); | |
15799 | } | |
15800 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | |
15801 | ||
15802 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | |
15803 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
15804 | { | |
15805 | struct sk_buff *msg; | |
15806 | ||
15807 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | |
15808 | ||
15809 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
15810 | if (!msg) | |
15811 | return; | |
15812 | ||
15813 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | |
15814 | goto nla_put_failure; | |
15815 | ||
15816 | cfg80211_send_cqm(msg, gfp); | |
15817 | return; | |
15818 | ||
15819 | nla_put_failure: | |
15820 | nlmsg_free(msg); | |
15821 | } | |
15822 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | |
15823 | ||
98f03342 JB |
15824 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
15825 | { | |
15826 | struct sk_buff *msg; | |
15827 | ||
15828 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | |
15829 | if (!msg) | |
15830 | return; | |
15831 | ||
15832 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | |
15833 | goto nla_put_failure; | |
15834 | ||
15835 | cfg80211_send_cqm(msg, gfp); | |
15836 | return; | |
15837 | ||
15838 | nla_put_failure: | |
15839 | nlmsg_free(msg); | |
15840 | } | |
15841 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); | |
15842 | ||
947add36 JB |
15843 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
15844 | struct net_device *netdev, const u8 *bssid, | |
15845 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
15846 | { |
15847 | struct sk_buff *msg; | |
15848 | struct nlattr *rekey_attr; | |
15849 | void *hdr; | |
15850 | ||
58050fce | 15851 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
15852 | if (!msg) |
15853 | return; | |
15854 | ||
15855 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
15856 | if (!hdr) { | |
15857 | nlmsg_free(msg); | |
15858 | return; | |
15859 | } | |
15860 | ||
9360ffd1 DM |
15861 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
15862 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
15863 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
15864 | goto nla_put_failure; | |
e5497d76 | 15865 | |
ae0be8de | 15866 | rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA); |
e5497d76 JB |
15867 | if (!rekey_attr) |
15868 | goto nla_put_failure; | |
15869 | ||
9360ffd1 DM |
15870 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
15871 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
15872 | goto nla_put_failure; | |
e5497d76 JB |
15873 | |
15874 | nla_nest_end(msg, rekey_attr); | |
15875 | ||
3b7b72ee | 15876 | genlmsg_end(msg, hdr); |
e5497d76 | 15877 | |
68eb5503 | 15878 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15879 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
15880 | return; |
15881 | ||
15882 | nla_put_failure: | |
e5497d76 JB |
15883 | nlmsg_free(msg); |
15884 | } | |
15885 | ||
947add36 JB |
15886 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
15887 | const u8 *replay_ctr, gfp_t gfp) | |
15888 | { | |
15889 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
15890 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 15891 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
15892 | |
15893 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
15894 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
15895 | } | |
15896 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
15897 | ||
15898 | static void | |
15899 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
15900 | struct net_device *netdev, int index, | |
15901 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
15902 | { |
15903 | struct sk_buff *msg; | |
15904 | struct nlattr *attr; | |
15905 | void *hdr; | |
15906 | ||
58050fce | 15907 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
15908 | if (!msg) |
15909 | return; | |
15910 | ||
15911 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
15912 | if (!hdr) { | |
15913 | nlmsg_free(msg); | |
15914 | return; | |
15915 | } | |
15916 | ||
9360ffd1 DM |
15917 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
15918 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
15919 | goto nla_put_failure; | |
c9df56b4 | 15920 | |
ae0be8de | 15921 | attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
c9df56b4 JM |
15922 | if (!attr) |
15923 | goto nla_put_failure; | |
15924 | ||
9360ffd1 DM |
15925 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
15926 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
15927 | (preauth && | |
15928 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
15929 | goto nla_put_failure; | |
c9df56b4 JM |
15930 | |
15931 | nla_nest_end(msg, attr); | |
15932 | ||
3b7b72ee | 15933 | genlmsg_end(msg, hdr); |
c9df56b4 | 15934 | |
68eb5503 | 15935 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15936 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
15937 | return; |
15938 | ||
15939 | nla_put_failure: | |
c9df56b4 JM |
15940 | nlmsg_free(msg); |
15941 | } | |
15942 | ||
947add36 JB |
15943 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
15944 | const u8 *bssid, bool preauth, gfp_t gfp) | |
15945 | { | |
15946 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
15947 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 15948 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
15949 | |
15950 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
15951 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
15952 | } | |
15953 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
15954 | ||
15955 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
15956 | struct net_device *netdev, | |
15957 | struct cfg80211_chan_def *chandef, | |
f8d7552e LC |
15958 | gfp_t gfp, |
15959 | enum nl80211_commands notif, | |
15960 | u8 count) | |
5314526b TP |
15961 | { |
15962 | struct sk_buff *msg; | |
15963 | void *hdr; | |
15964 | ||
58050fce | 15965 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
15966 | if (!msg) |
15967 | return; | |
15968 | ||
f8d7552e | 15969 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
5314526b TP |
15970 | if (!hdr) { |
15971 | nlmsg_free(msg); | |
15972 | return; | |
15973 | } | |
15974 | ||
683b6d3b JB |
15975 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
15976 | goto nla_put_failure; | |
15977 | ||
15978 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 15979 | goto nla_put_failure; |
5314526b | 15980 | |
f8d7552e LC |
15981 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
15982 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | |
15983 | goto nla_put_failure; | |
15984 | ||
5314526b TP |
15985 | genlmsg_end(msg, hdr); |
15986 | ||
68eb5503 | 15987 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15988 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
15989 | return; |
15990 | ||
15991 | nla_put_failure: | |
5314526b TP |
15992 | nlmsg_free(msg); |
15993 | } | |
15994 | ||
947add36 JB |
15995 | void cfg80211_ch_switch_notify(struct net_device *dev, |
15996 | struct cfg80211_chan_def *chandef) | |
84f10708 | 15997 | { |
947add36 JB |
15998 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
15999 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 16000 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 16001 | |
e487eaeb | 16002 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 16003 | |
e487eaeb | 16004 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 | 16005 | |
9e0e2961 | 16006 | wdev->chandef = *chandef; |
96f55f12 | 16007 | wdev->preset_chandef = *chandef; |
5dc8cdce SM |
16008 | |
16009 | if (wdev->iftype == NL80211_IFTYPE_STATION && | |
16010 | !WARN_ON(!wdev->current_bss)) | |
16011 | wdev->current_bss->pub.channel = chandef->chan; | |
16012 | ||
f8d7552e LC |
16013 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
16014 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); | |
947add36 JB |
16015 | } |
16016 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
16017 | ||
f8d7552e LC |
16018 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
16019 | struct cfg80211_chan_def *chandef, | |
16020 | u8 count) | |
16021 | { | |
16022 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
16023 | struct wiphy *wiphy = wdev->wiphy; | |
16024 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
16025 | ||
16026 | trace_cfg80211_ch_switch_started_notify(dev, chandef); | |
16027 | ||
16028 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | |
16029 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | |
16030 | } | |
16031 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | |
16032 | ||
04f39047 SW |
16033 | void |
16034 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 16035 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
16036 | enum nl80211_radar_event event, |
16037 | struct net_device *netdev, gfp_t gfp) | |
16038 | { | |
16039 | struct sk_buff *msg; | |
16040 | void *hdr; | |
16041 | ||
16042 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
16043 | if (!msg) | |
16044 | return; | |
16045 | ||
16046 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
16047 | if (!hdr) { | |
16048 | nlmsg_free(msg); | |
16049 | return; | |
16050 | } | |
16051 | ||
16052 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
16053 | goto nla_put_failure; | |
16054 | ||
16055 | /* NOP and radar events don't need a netdev parameter */ | |
16056 | if (netdev) { | |
16057 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
16058 | ||
16059 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
2dad624e ND |
16060 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
16061 | NL80211_ATTR_PAD)) | |
04f39047 SW |
16062 | goto nla_put_failure; |
16063 | } | |
16064 | ||
16065 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
16066 | goto nla_put_failure; | |
16067 | ||
16068 | if (nl80211_send_chandef(msg, chandef)) | |
16069 | goto nla_put_failure; | |
16070 | ||
9c90a9f6 | 16071 | genlmsg_end(msg, hdr); |
04f39047 | 16072 | |
68eb5503 | 16073 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 16074 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
16075 | return; |
16076 | ||
16077 | nla_put_failure: | |
04f39047 SW |
16078 | nlmsg_free(msg); |
16079 | } | |
16080 | ||
466b9936 | 16081 | void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, |
16082 | struct sta_opmode_info *sta_opmode, | |
16083 | gfp_t gfp) | |
16084 | { | |
16085 | struct sk_buff *msg; | |
16086 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
16087 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | |
16088 | void *hdr; | |
16089 | ||
16090 | if (WARN_ON(!mac)) | |
16091 | return; | |
16092 | ||
16093 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
16094 | if (!msg) | |
16095 | return; | |
16096 | ||
16097 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); | |
16098 | if (!hdr) { | |
16099 | nlmsg_free(msg); | |
16100 | return; | |
16101 | } | |
16102 | ||
16103 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
16104 | goto nla_put_failure; | |
16105 | ||
16106 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) | |
16107 | goto nla_put_failure; | |
16108 | ||
16109 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) | |
16110 | goto nla_put_failure; | |
16111 | ||
16112 | if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && | |
16113 | nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) | |
16114 | goto nla_put_failure; | |
16115 | ||
16116 | if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && | |
16117 | nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) | |
16118 | goto nla_put_failure; | |
16119 | ||
16120 | if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && | |
16121 | nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) | |
16122 | goto nla_put_failure; | |
16123 | ||
16124 | genlmsg_end(msg, hdr); | |
16125 | ||
16126 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | |
16127 | NL80211_MCGRP_MLME, gfp); | |
16128 | ||
16129 | return; | |
16130 | ||
16131 | nla_put_failure: | |
16132 | nlmsg_free(msg); | |
16133 | } | |
16134 | EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); | |
16135 | ||
7f6cf311 | 16136 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
c4b50cd3 VN |
16137 | u64 cookie, bool acked, s32 ack_signal, |
16138 | bool is_valid_ack_signal, gfp_t gfp) | |
7f6cf311 JB |
16139 | { |
16140 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 16141 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
16142 | struct sk_buff *msg; |
16143 | void *hdr; | |
7f6cf311 | 16144 | |
4ee3e063 BL |
16145 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
16146 | ||
58050fce | 16147 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 16148 | |
7f6cf311 JB |
16149 | if (!msg) |
16150 | return; | |
16151 | ||
16152 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
16153 | if (!hdr) { | |
16154 | nlmsg_free(msg); | |
16155 | return; | |
16156 | } | |
16157 | ||
9360ffd1 DM |
16158 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
16159 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
16160 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
2dad624e ND |
16161 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
16162 | NL80211_ATTR_PAD) || | |
c4b50cd3 VN |
16163 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || |
16164 | (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, | |
16165 | ack_signal))) | |
9360ffd1 | 16166 | goto nla_put_failure; |
7f6cf311 | 16167 | |
9c90a9f6 | 16168 | genlmsg_end(msg, hdr); |
7f6cf311 | 16169 | |
68eb5503 | 16170 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 16171 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
16172 | return; |
16173 | ||
16174 | nla_put_failure: | |
7f6cf311 JB |
16175 | nlmsg_free(msg); |
16176 | } | |
16177 | EXPORT_SYMBOL(cfg80211_probe_status); | |
16178 | ||
5e760230 JB |
16179 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
16180 | const u8 *frame, size_t len, | |
37c73b5f | 16181 | int freq, int sig_dbm) |
5e760230 | 16182 | { |
f26cbf40 | 16183 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
16184 | struct sk_buff *msg; |
16185 | void *hdr; | |
37c73b5f | 16186 | struct cfg80211_beacon_registration *reg; |
5e760230 | 16187 | |
4ee3e063 BL |
16188 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
16189 | ||
37c73b5f BG |
16190 | spin_lock_bh(&rdev->beacon_registrations_lock); |
16191 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
16192 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
16193 | if (!msg) { | |
16194 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
16195 | return; | |
16196 | } | |
5e760230 | 16197 | |
37c73b5f BG |
16198 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
16199 | if (!hdr) | |
16200 | goto nla_put_failure; | |
5e760230 | 16201 | |
37c73b5f BG |
16202 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
16203 | (freq && | |
16204 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
16205 | (sig_dbm && | |
16206 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
16207 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
16208 | goto nla_put_failure; | |
5e760230 | 16209 | |
37c73b5f | 16210 | genlmsg_end(msg, hdr); |
5e760230 | 16211 | |
37c73b5f BG |
16212 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
16213 | } | |
16214 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
16215 | return; |
16216 | ||
16217 | nla_put_failure: | |
37c73b5f | 16218 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
16219 | nlmsg_free(msg); |
16220 | } | |
16221 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
16222 | ||
cd8f7cb4 | 16223 | #ifdef CONFIG_PM |
8cd4d456 LC |
16224 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
16225 | struct cfg80211_wowlan_wakeup *wakeup) | |
16226 | { | |
16227 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | |
16228 | struct nlattr *nl_results, *nl_match, *nl_freqs; | |
16229 | int i, j; | |
16230 | ||
ae0be8de MK |
16231 | nl_results = nla_nest_start_noflag(msg, |
16232 | NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | |
8cd4d456 LC |
16233 | if (!nl_results) |
16234 | return -EMSGSIZE; | |
16235 | ||
16236 | for (i = 0; i < nd->n_matches; i++) { | |
16237 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | |
16238 | ||
ae0be8de | 16239 | nl_match = nla_nest_start_noflag(msg, i); |
8cd4d456 LC |
16240 | if (!nl_match) |
16241 | break; | |
16242 | ||
16243 | /* The SSID attribute is optional in nl80211, but for | |
16244 | * simplicity reasons it's always present in the | |
16245 | * cfg80211 structure. If a driver can't pass the | |
16246 | * SSID, that needs to be changed. A zero length SSID | |
16247 | * is still a valid SSID (wildcard), so it cannot be | |
16248 | * used for this purpose. | |
16249 | */ | |
16250 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | |
16251 | match->ssid.ssid)) { | |
16252 | nla_nest_cancel(msg, nl_match); | |
16253 | goto out; | |
16254 | } | |
16255 | ||
16256 | if (match->n_channels) { | |
ae0be8de MK |
16257 | nl_freqs = nla_nest_start_noflag(msg, |
16258 | NL80211_ATTR_SCAN_FREQUENCIES); | |
8cd4d456 LC |
16259 | if (!nl_freqs) { |
16260 | nla_nest_cancel(msg, nl_match); | |
16261 | goto out; | |
16262 | } | |
16263 | ||
16264 | for (j = 0; j < match->n_channels; j++) { | |
5528fae8 | 16265 | if (nla_put_u32(msg, j, match->channels[j])) { |
8cd4d456 LC |
16266 | nla_nest_cancel(msg, nl_freqs); |
16267 | nla_nest_cancel(msg, nl_match); | |
16268 | goto out; | |
16269 | } | |
16270 | } | |
16271 | ||
16272 | nla_nest_end(msg, nl_freqs); | |
16273 | } | |
16274 | ||
16275 | nla_nest_end(msg, nl_match); | |
16276 | } | |
16277 | ||
16278 | out: | |
16279 | nla_nest_end(msg, nl_results); | |
16280 | return 0; | |
16281 | } | |
16282 | ||
cd8f7cb4 JB |
16283 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
16284 | struct cfg80211_wowlan_wakeup *wakeup, | |
16285 | gfp_t gfp) | |
16286 | { | |
f26cbf40 | 16287 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
16288 | struct sk_buff *msg; |
16289 | void *hdr; | |
9c90a9f6 | 16290 | int size = 200; |
cd8f7cb4 JB |
16291 | |
16292 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
16293 | ||
16294 | if (wakeup) | |
16295 | size += wakeup->packet_present_len; | |
16296 | ||
16297 | msg = nlmsg_new(size, gfp); | |
16298 | if (!msg) | |
16299 | return; | |
16300 | ||
16301 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
16302 | if (!hdr) | |
16303 | goto free_msg; | |
16304 | ||
16305 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
16306 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
16307 | NL80211_ATTR_PAD)) | |
cd8f7cb4 JB |
16308 | goto free_msg; |
16309 | ||
16310 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
16311 | wdev->netdev->ifindex)) | |
16312 | goto free_msg; | |
16313 | ||
16314 | if (wakeup) { | |
16315 | struct nlattr *reasons; | |
16316 | ||
ae0be8de MK |
16317 | reasons = nla_nest_start_noflag(msg, |
16318 | NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
16319 | if (!reasons) |
16320 | goto free_msg; | |
cd8f7cb4 JB |
16321 | |
16322 | if (wakeup->disconnect && | |
16323 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
16324 | goto free_msg; | |
16325 | if (wakeup->magic_pkt && | |
16326 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
16327 | goto free_msg; | |
16328 | if (wakeup->gtk_rekey_failure && | |
16329 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
16330 | goto free_msg; | |
16331 | if (wakeup->eap_identity_req && | |
16332 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
16333 | goto free_msg; | |
16334 | if (wakeup->four_way_handshake && | |
16335 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
16336 | goto free_msg; | |
16337 | if (wakeup->rfkill_release && | |
16338 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
16339 | goto free_msg; | |
16340 | ||
16341 | if (wakeup->pattern_idx >= 0 && | |
16342 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
16343 | wakeup->pattern_idx)) | |
16344 | goto free_msg; | |
16345 | ||
ae917c9f JB |
16346 | if (wakeup->tcp_match && |
16347 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
16348 | goto free_msg; | |
2a0e047e | 16349 | |
ae917c9f JB |
16350 | if (wakeup->tcp_connlost && |
16351 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
16352 | goto free_msg; | |
2a0e047e | 16353 | |
ae917c9f JB |
16354 | if (wakeup->tcp_nomoretokens && |
16355 | nla_put_flag(msg, | |
16356 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
16357 | goto free_msg; | |
2a0e047e | 16358 | |
cd8f7cb4 JB |
16359 | if (wakeup->packet) { |
16360 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
16361 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
16362 | ||
16363 | if (!wakeup->packet_80211) { | |
16364 | pkt_attr = | |
16365 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
16366 | len_attr = | |
16367 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
16368 | } | |
16369 | ||
16370 | if (wakeup->packet_len && | |
16371 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
16372 | goto free_msg; | |
16373 | ||
16374 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
16375 | wakeup->packet)) | |
16376 | goto free_msg; | |
16377 | } | |
16378 | ||
8cd4d456 LC |
16379 | if (wakeup->net_detect && |
16380 | cfg80211_net_detect_results(msg, wakeup)) | |
16381 | goto free_msg; | |
16382 | ||
cd8f7cb4 JB |
16383 | nla_nest_end(msg, reasons); |
16384 | } | |
16385 | ||
9c90a9f6 | 16386 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 16387 | |
68eb5503 | 16388 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 16389 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
16390 | return; |
16391 | ||
16392 | free_msg: | |
16393 | nlmsg_free(msg); | |
16394 | } | |
16395 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
16396 | #endif | |
16397 | ||
3475b094 JM |
16398 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
16399 | enum nl80211_tdls_operation oper, | |
16400 | u16 reason_code, gfp_t gfp) | |
16401 | { | |
16402 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 16403 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
16404 | struct sk_buff *msg; |
16405 | void *hdr; | |
3475b094 JM |
16406 | |
16407 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
16408 | reason_code); | |
16409 | ||
16410 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
16411 | if (!msg) | |
16412 | return; | |
16413 | ||
16414 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
16415 | if (!hdr) { | |
16416 | nlmsg_free(msg); | |
16417 | return; | |
16418 | } | |
16419 | ||
16420 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
16421 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
16422 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
16423 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
16424 | (reason_code > 0 && | |
16425 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
16426 | goto nla_put_failure; | |
16427 | ||
9c90a9f6 | 16428 | genlmsg_end(msg, hdr); |
3475b094 | 16429 | |
68eb5503 | 16430 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 16431 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
16432 | return; |
16433 | ||
16434 | nla_put_failure: | |
3475b094 JM |
16435 | nlmsg_free(msg); |
16436 | } | |
16437 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
16438 | ||
026331c4 JM |
16439 | static int nl80211_netlink_notify(struct notifier_block * nb, |
16440 | unsigned long state, | |
16441 | void *_notify) | |
16442 | { | |
16443 | struct netlink_notify *notify = _notify; | |
16444 | struct cfg80211_registered_device *rdev; | |
16445 | struct wireless_dev *wdev; | |
37c73b5f | 16446 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 | 16447 | |
8f815cdd | 16448 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
026331c4 JM |
16449 | return NOTIFY_DONE; |
16450 | ||
16451 | rcu_read_lock(); | |
16452 | ||
5e760230 | 16453 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
ca986ad9 | 16454 | struct cfg80211_sched_scan_request *sched_scan_req; |
753aacfd | 16455 | |
ca986ad9 AVS |
16456 | list_for_each_entry_rcu(sched_scan_req, |
16457 | &rdev->sched_scan_req_list, | |
16458 | list) { | |
16459 | if (sched_scan_req->owner_nlportid == notify->portid) { | |
16460 | sched_scan_req->nl_owner_dead = true; | |
753aacfd | 16461 | schedule_work(&rdev->sched_scan_stop_wk); |
ca986ad9 | 16462 | } |
753aacfd | 16463 | } |
78f22b6a | 16464 | |
53873f13 | 16465 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
15e47304 | 16466 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 16467 | |
ab81007a JB |
16468 | if (wdev->owner_nlportid == notify->portid) { |
16469 | wdev->nl_owner_dead = true; | |
16470 | schedule_work(&rdev->destroy_work); | |
16471 | } else if (wdev->conn_owner_nlportid == notify->portid) { | |
bd2522b1 | 16472 | schedule_work(&wdev->disconnect_wk); |
ab81007a | 16473 | } |
9bb7e0f2 JB |
16474 | |
16475 | cfg80211_release_pmsr(wdev, notify->portid); | |
78f22b6a JB |
16476 | } |
16477 | ||
37c73b5f BG |
16478 | spin_lock_bh(&rdev->beacon_registrations_lock); |
16479 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
16480 | list) { | |
16481 | if (reg->nlportid == notify->portid) { | |
16482 | list_del(®->list); | |
16483 | kfree(reg); | |
16484 | break; | |
16485 | } | |
16486 | } | |
16487 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 | 16488 | } |
026331c4 JM |
16489 | |
16490 | rcu_read_unlock(); | |
16491 | ||
05050753 I |
16492 | /* |
16493 | * It is possible that the user space process that is controlling the | |
16494 | * indoor setting disappeared, so notify the regulatory core. | |
16495 | */ | |
16496 | regulatory_netlink_notify(notify->portid); | |
6784c7db | 16497 | return NOTIFY_OK; |
026331c4 JM |
16498 | } |
16499 | ||
16500 | static struct notifier_block nl80211_netlink_notifier = { | |
16501 | .notifier_call = nl80211_netlink_notify, | |
16502 | }; | |
16503 | ||
355199e0 JM |
16504 | void cfg80211_ft_event(struct net_device *netdev, |
16505 | struct cfg80211_ft_event_params *ft_event) | |
16506 | { | |
16507 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 16508 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
16509 | struct sk_buff *msg; |
16510 | void *hdr; | |
355199e0 JM |
16511 | |
16512 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
16513 | ||
16514 | if (!ft_event->target_ap) | |
16515 | return; | |
16516 | ||
1039d081 DL |
16517 | msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, |
16518 | GFP_KERNEL); | |
355199e0 JM |
16519 | if (!msg) |
16520 | return; | |
16521 | ||
16522 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
16523 | if (!hdr) |
16524 | goto out; | |
355199e0 | 16525 | |
ae917c9f JB |
16526 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
16527 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
16528 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
16529 | goto out; | |
355199e0 | 16530 | |
ae917c9f JB |
16531 | if (ft_event->ies && |
16532 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
16533 | goto out; | |
16534 | if (ft_event->ric_ies && | |
16535 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
16536 | ft_event->ric_ies)) | |
16537 | goto out; | |
355199e0 | 16538 | |
9c90a9f6 | 16539 | genlmsg_end(msg, hdr); |
355199e0 | 16540 | |
68eb5503 | 16541 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 16542 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
16543 | return; |
16544 | out: | |
16545 | nlmsg_free(msg); | |
355199e0 JM |
16546 | } |
16547 | EXPORT_SYMBOL(cfg80211_ft_event); | |
16548 | ||
5de17984 AS |
16549 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
16550 | { | |
16551 | struct cfg80211_registered_device *rdev; | |
16552 | struct sk_buff *msg; | |
16553 | void *hdr; | |
16554 | u32 nlportid; | |
16555 | ||
f26cbf40 | 16556 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
16557 | if (!rdev->crit_proto_nlportid) |
16558 | return; | |
16559 | ||
16560 | nlportid = rdev->crit_proto_nlportid; | |
16561 | rdev->crit_proto_nlportid = 0; | |
16562 | ||
16563 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
16564 | if (!msg) | |
16565 | return; | |
16566 | ||
16567 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
16568 | if (!hdr) | |
16569 | goto nla_put_failure; | |
16570 | ||
16571 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
16572 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
16573 | NL80211_ATTR_PAD)) | |
5de17984 AS |
16574 | goto nla_put_failure; |
16575 | ||
16576 | genlmsg_end(msg, hdr); | |
16577 | ||
16578 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
16579 | return; | |
16580 | ||
16581 | nla_put_failure: | |
5de17984 | 16582 | nlmsg_free(msg); |
5de17984 AS |
16583 | } |
16584 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
16585 | ||
348baf0e JB |
16586 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
16587 | { | |
16588 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 16589 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
16590 | struct sk_buff *msg; |
16591 | void *hdr; | |
16592 | ||
16593 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
16594 | if (!msg) | |
16595 | return; | |
16596 | ||
16597 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
16598 | if (!hdr) | |
16599 | goto out; | |
16600 | ||
16601 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
16602 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
2dad624e ND |
16603 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
16604 | NL80211_ATTR_PAD)) | |
348baf0e JB |
16605 | goto out; |
16606 | ||
16607 | genlmsg_end(msg, hdr); | |
16608 | ||
16609 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
16610 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
16611 | return; | |
16612 | out: | |
16613 | nlmsg_free(msg); | |
16614 | } | |
16615 | ||
40cbfa90 SD |
16616 | int cfg80211_external_auth_request(struct net_device *dev, |
16617 | struct cfg80211_external_auth_params *params, | |
16618 | gfp_t gfp) | |
16619 | { | |
16620 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
16621 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | |
16622 | struct sk_buff *msg; | |
16623 | void *hdr; | |
16624 | ||
16625 | if (!wdev->conn_owner_nlportid) | |
16626 | return -EINVAL; | |
16627 | ||
16628 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
16629 | if (!msg) | |
16630 | return -ENOMEM; | |
16631 | ||
16632 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); | |
16633 | if (!hdr) | |
16634 | goto nla_put_failure; | |
16635 | ||
16636 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
16637 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
16638 | nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || | |
16639 | nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, | |
16640 | params->action) || | |
16641 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || | |
16642 | nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, | |
16643 | params->ssid.ssid)) | |
16644 | goto nla_put_failure; | |
16645 | ||
16646 | genlmsg_end(msg, hdr); | |
16647 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, | |
16648 | wdev->conn_owner_nlportid); | |
16649 | return 0; | |
16650 | ||
16651 | nla_put_failure: | |
16652 | nlmsg_free(msg); | |
16653 | return -ENOBUFS; | |
16654 | } | |
16655 | EXPORT_SYMBOL(cfg80211_external_auth_request); | |
16656 | ||
cb74e977 SD |
16657 | void cfg80211_update_owe_info_event(struct net_device *netdev, |
16658 | struct cfg80211_update_owe_info *owe_info, | |
16659 | gfp_t gfp) | |
16660 | { | |
16661 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
16662 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
16663 | struct sk_buff *msg; | |
16664 | void *hdr; | |
16665 | ||
16666 | trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info); | |
16667 | ||
16668 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
16669 | if (!msg) | |
16670 | return; | |
16671 | ||
16672 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO); | |
16673 | if (!hdr) | |
16674 | goto nla_put_failure; | |
16675 | ||
16676 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
16677 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
16678 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer)) | |
16679 | goto nla_put_failure; | |
16680 | ||
16681 | if (!owe_info->ie_len || | |
16682 | nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie)) | |
16683 | goto nla_put_failure; | |
16684 | ||
16685 | genlmsg_end(msg, hdr); | |
16686 | ||
16687 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | |
16688 | NL80211_MCGRP_MLME, gfp); | |
16689 | return; | |
16690 | ||
16691 | nla_put_failure: | |
16692 | genlmsg_cancel(msg, hdr); | |
16693 | nlmsg_free(msg); | |
16694 | } | |
16695 | EXPORT_SYMBOL(cfg80211_update_owe_info_event); | |
16696 | ||
55682965 JB |
16697 | /* initialisation/exit functions */ |
16698 | ||
56989f6d | 16699 | int __init nl80211_init(void) |
55682965 | 16700 | { |
0d63cbb5 | 16701 | int err; |
55682965 | 16702 | |
489111e5 | 16703 | err = genl_register_family(&nl80211_fam); |
55682965 JB |
16704 | if (err) |
16705 | return err; | |
16706 | ||
026331c4 JM |
16707 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
16708 | if (err) | |
16709 | goto err_out; | |
16710 | ||
55682965 JB |
16711 | return 0; |
16712 | err_out: | |
16713 | genl_unregister_family(&nl80211_fam); | |
16714 | return err; | |
16715 | } | |
16716 | ||
16717 | void nl80211_exit(void) | |
16718 | { | |
026331c4 | 16719 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
16720 | genl_unregister_family(&nl80211_fam); |
16721 | } |