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 |
ea05fd35 | 8 | * Copyright (C) 2018-2022 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> |
e3ae39ed | 23 | #include <linux/if_vlan.h> |
463d0183 | 24 | #include <net/net_namespace.h> |
55682965 JB |
25 | #include <net/genetlink.h> |
26 | #include <net/cfg80211.h> | |
463d0183 | 27 | #include <net/sock.h> |
2a0e047e | 28 | #include <net/inet_connection_sock.h> |
55682965 JB |
29 | #include "core.h" |
30 | #include "nl80211.h" | |
b2e1b302 | 31 | #include "reg.h" |
e35e4d28 | 32 | #include "rdev-ops.h" |
55682965 | 33 | |
5fb628e9 JM |
34 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
35 | struct genl_info *info, | |
36 | struct cfg80211_crypto_settings *settings, | |
37 | int cipher_limit); | |
38 | ||
55682965 | 39 | /* the netlink family */ |
489111e5 | 40 | static struct genl_family nl80211_fam; |
55682965 | 41 | |
2a94fe48 JB |
42 | /* multicast groups */ |
43 | enum nl80211_multicast_groups { | |
44 | NL80211_MCGRP_CONFIG, | |
45 | NL80211_MCGRP_SCAN, | |
46 | NL80211_MCGRP_REGULATORY, | |
47 | NL80211_MCGRP_MLME, | |
567ffc35 | 48 | NL80211_MCGRP_VENDOR, |
50bcd31d | 49 | NL80211_MCGRP_NAN, |
2a94fe48 JB |
50 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
51 | }; | |
52 | ||
53 | static const struct genl_multicast_group nl80211_mcgrps[] = { | |
71b836ec JB |
54 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
55 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, | |
56 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, | |
57 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, | |
58 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, | |
50bcd31d | 59 | [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, |
2a94fe48 | 60 | #ifdef CONFIG_NL80211_TESTMODE |
71b836ec | 61 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
2a94fe48 JB |
62 | #endif |
63 | }; | |
64 | ||
89a54e48 JB |
65 | /* returns ERR_PTR values */ |
66 | static struct wireless_dev * | |
a05829a7 JB |
67 | __cfg80211_wdev_from_attrs(struct cfg80211_registered_device *rdev, |
68 | struct net *netns, struct nlattr **attrs) | |
55682965 | 69 | { |
89a54e48 JB |
70 | struct wireless_dev *result = NULL; |
71 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
72 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
239729a2 | 73 | u64 wdev_id = 0; |
89a54e48 JB |
74 | int wiphy_idx = -1; |
75 | int ifidx = -1; | |
55682965 | 76 | |
89a54e48 JB |
77 | if (!have_ifidx && !have_wdev_id) |
78 | return ERR_PTR(-EINVAL); | |
55682965 | 79 | |
89a54e48 JB |
80 | if (have_ifidx) |
81 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
82 | if (have_wdev_id) { | |
83 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
84 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
85 | } |
86 | ||
a05829a7 JB |
87 | if (rdev) { |
88 | struct wireless_dev *wdev; | |
89 | ||
90 | lockdep_assert_held(&rdev->wiphy.mtx); | |
91 | ||
92 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { | |
93 | if (have_ifidx && wdev->netdev && | |
94 | wdev->netdev->ifindex == ifidx) { | |
95 | result = wdev; | |
96 | break; | |
97 | } | |
98 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
99 | result = wdev; | |
100 | break; | |
101 | } | |
102 | } | |
103 | ||
104 | return result ?: ERR_PTR(-ENODEV); | |
105 | } | |
106 | ||
107 | ASSERT_RTNL(); | |
108 | ||
89a54e48 JB |
109 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
110 | struct wireless_dev *wdev; | |
111 | ||
112 | if (wiphy_net(&rdev->wiphy) != netns) | |
113 | continue; | |
114 | ||
115 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
116 | continue; | |
117 | ||
53873f13 | 118 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
89a54e48 JB |
119 | if (have_ifidx && wdev->netdev && |
120 | wdev->netdev->ifindex == ifidx) { | |
121 | result = wdev; | |
122 | break; | |
123 | } | |
124 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
125 | result = wdev; | |
126 | break; | |
127 | } | |
128 | } | |
89a54e48 JB |
129 | |
130 | if (result) | |
131 | break; | |
132 | } | |
133 | ||
134 | if (result) | |
135 | return result; | |
136 | return ERR_PTR(-ENODEV); | |
55682965 JB |
137 | } |
138 | ||
a9455408 | 139 | static struct cfg80211_registered_device * |
878d9ec7 | 140 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 141 | { |
7fee4778 JB |
142 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
143 | struct net_device *netdev; | |
a9455408 | 144 | |
5fe231e8 | 145 | ASSERT_RTNL(); |
a9455408 | 146 | |
878d9ec7 | 147 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
148 | !attrs[NL80211_ATTR_IFINDEX] && |
149 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
150 | return ERR_PTR(-EINVAL); |
151 | ||
878d9ec7 | 152 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 153 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 154 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 155 | |
89a54e48 JB |
156 | if (attrs[NL80211_ATTR_WDEV]) { |
157 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
158 | struct wireless_dev *wdev; | |
159 | bool found = false; | |
160 | ||
161 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
162 | if (tmp) { | |
163 | /* make sure wdev exists */ | |
53873f13 | 164 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
89a54e48 JB |
165 | if (wdev->identifier != (u32)wdev_id) |
166 | continue; | |
167 | found = true; | |
168 | break; | |
169 | } | |
89a54e48 JB |
170 | |
171 | if (!found) | |
172 | tmp = NULL; | |
173 | ||
174 | if (rdev && tmp != rdev) | |
175 | return ERR_PTR(-EINVAL); | |
176 | rdev = tmp; | |
177 | } | |
178 | } | |
179 | ||
878d9ec7 JB |
180 | if (attrs[NL80211_ATTR_IFINDEX]) { |
181 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
7a087e74 | 182 | |
7f2b8562 | 183 | netdev = __dev_get_by_index(netns, ifindex); |
7fee4778 JB |
184 | if (netdev) { |
185 | if (netdev->ieee80211_ptr) | |
f26cbf40 ZG |
186 | tmp = wiphy_to_rdev( |
187 | netdev->ieee80211_ptr->wiphy); | |
7fee4778 JB |
188 | else |
189 | tmp = NULL; | |
190 | ||
7fee4778 JB |
191 | /* not wireless device -- return error */ |
192 | if (!tmp) | |
193 | return ERR_PTR(-EINVAL); | |
194 | ||
195 | /* mismatch -- return error */ | |
196 | if (rdev && tmp != rdev) | |
197 | return ERR_PTR(-EINVAL); | |
198 | ||
199 | rdev = tmp; | |
a9455408 | 200 | } |
a9455408 | 201 | } |
a9455408 | 202 | |
4f7eff10 JB |
203 | if (!rdev) |
204 | return ERR_PTR(-ENODEV); | |
a9455408 | 205 | |
4f7eff10 JB |
206 | if (netns != wiphy_net(&rdev->wiphy)) |
207 | return ERR_PTR(-ENODEV); | |
208 | ||
209 | return rdev; | |
a9455408 JB |
210 | } |
211 | ||
212 | /* | |
213 | * This function returns a pointer to the driver | |
214 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
215 | * |
216 | * The result of this can be a PTR_ERR and hence must | |
217 | * be checked with IS_ERR() for errors. | |
218 | */ | |
219 | static struct cfg80211_registered_device * | |
4f7eff10 | 220 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 221 | { |
5fe231e8 | 222 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
223 | } |
224 | ||
f88eb7c0 JB |
225 | static int validate_beacon_head(const struct nlattr *attr, |
226 | struct netlink_ext_ack *extack) | |
227 | { | |
228 | const u8 *data = nla_data(attr); | |
229 | unsigned int len = nla_len(attr); | |
230 | const struct element *elem; | |
231 | const struct ieee80211_mgmt *mgmt = (void *)data; | |
1d47f119 | 232 | unsigned int fixedlen, hdrlen; |
9a6847ba | 233 | bool s1g_bcn; |
1d47f119 | 234 | |
9a6847ba JB |
235 | if (len < offsetofend(typeof(*mgmt), frame_control)) |
236 | goto err; | |
237 | ||
238 | s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control); | |
1d47f119 TP |
239 | if (s1g_bcn) { |
240 | fixedlen = offsetof(struct ieee80211_ext, | |
241 | u.s1g_beacon.variable); | |
242 | hdrlen = offsetof(struct ieee80211_ext, u.s1g_beacon); | |
243 | } else { | |
244 | fixedlen = offsetof(struct ieee80211_mgmt, | |
245 | u.beacon.variable); | |
246 | hdrlen = offsetof(struct ieee80211_mgmt, u.beacon); | |
247 | } | |
f88eb7c0 JB |
248 | |
249 | if (len < fixedlen) | |
250 | goto err; | |
251 | ||
1d47f119 | 252 | if (ieee80211_hdrlen(mgmt->frame_control) != hdrlen) |
f88eb7c0 JB |
253 | goto err; |
254 | ||
255 | data += fixedlen; | |
256 | len -= fixedlen; | |
257 | ||
258 | for_each_element(elem, data, len) { | |
259 | /* nothing */ | |
260 | } | |
261 | ||
262 | if (for_each_element_completed(elem, data, len)) | |
263 | return 0; | |
264 | ||
265 | err: | |
266 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head"); | |
267 | return -EINVAL; | |
268 | } | |
269 | ||
3d7af878 JB |
270 | static int validate_ie_attr(const struct nlattr *attr, |
271 | struct netlink_ext_ack *extack) | |
272 | { | |
9f308616 JB |
273 | const u8 *data = nla_data(attr); |
274 | unsigned int len = nla_len(attr); | |
7388afe0 | 275 | const struct element *elem; |
3d7af878 | 276 | |
9f308616 JB |
277 | for_each_element(elem, data, len) { |
278 | /* nothing */ | |
3d7af878 JB |
279 | } |
280 | ||
9f308616 JB |
281 | if (for_each_element_completed(elem, data, len)) |
282 | return 0; | |
283 | ||
3d7af878 JB |
284 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements"); |
285 | return -EINVAL; | |
286 | } | |
287 | ||
a3a20feb JB |
288 | static int validate_he_capa(const struct nlattr *attr, |
289 | struct netlink_ext_ack *extack) | |
290 | { | |
291 | if (!ieee80211_he_capa_size_ok(nla_data(attr), nla_len(attr))) | |
292 | return -EINVAL; | |
293 | ||
294 | return 0; | |
295 | } | |
296 | ||
55682965 | 297 | /* policy for the attributes */ |
d15da2a2 JB |
298 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR]; |
299 | ||
81e54d08 PKC |
300 | static const struct nla_policy |
301 | nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = { | |
302 | [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, }, | |
303 | [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY, | |
304 | .len = U8_MAX }, | |
305 | [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY, | |
306 | .len = U8_MAX }, | |
307 | }; | |
308 | ||
9bb7e0f2 JB |
309 | static const struct nla_policy |
310 | nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = { | |
311 | [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG }, | |
312 | [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 }, | |
313 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] = | |
314 | NLA_POLICY_MAX(NLA_U8, 15), | |
315 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 }, | |
316 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] = | |
317 | NLA_POLICY_MAX(NLA_U8, 15), | |
318 | [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] = | |
ea18709a | 319 | NLA_POLICY_MAX(NLA_U8, 31), |
9bb7e0f2 JB |
320 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 }, |
321 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG }, | |
322 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG }, | |
efb5520d AS |
323 | [NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG }, |
324 | [NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG }, | |
73807523 | 325 | [NL80211_PMSR_FTM_REQ_ATTR_LMR_FEEDBACK] = { .type = NLA_FLAG }, |
9bb7e0f2 JB |
326 | }; |
327 | ||
328 | static const struct nla_policy | |
329 | nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = { | |
330 | [NL80211_PMSR_TYPE_FTM] = | |
23323289 | 331 | NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy), |
9bb7e0f2 JB |
332 | }; |
333 | ||
334 | static const struct nla_policy | |
335 | nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = { | |
336 | [NL80211_PMSR_REQ_ATTR_DATA] = | |
23323289 | 337 | NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy), |
9bb7e0f2 JB |
338 | [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG }, |
339 | }; | |
340 | ||
341 | static const struct nla_policy | |
aeddc05f | 342 | nl80211_pmsr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = { |
9bb7e0f2 | 343 | [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR, |
d15da2a2 | 344 | [NL80211_PMSR_PEER_ATTR_CHAN] = NLA_POLICY_NESTED(nl80211_policy), |
9bb7e0f2 | 345 | [NL80211_PMSR_PEER_ATTR_REQ] = |
23323289 | 346 | NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy), |
9bb7e0f2 JB |
347 | [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT }, |
348 | }; | |
349 | ||
350 | static const struct nla_policy | |
351 | nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = { | |
352 | [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT }, | |
353 | [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT }, | |
354 | [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT }, | |
355 | [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT }, | |
356 | [NL80211_PMSR_ATTR_PEERS] = | |
aeddc05f | 357 | NLA_POLICY_NESTED_ARRAY(nl80211_pmsr_peer_attr_policy), |
9bb7e0f2 JB |
358 | }; |
359 | ||
796e90f4 JC |
360 | static const struct nla_policy |
361 | he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = { | |
362 | [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] = | |
363 | NLA_POLICY_RANGE(NLA_U8, 1, 20), | |
364 | [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] = | |
365 | NLA_POLICY_RANGE(NLA_U8, 1, 20), | |
f5bec330 RM |
366 | [NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET] = |
367 | NLA_POLICY_RANGE(NLA_U8, 1, 20), | |
368 | [NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP] = | |
369 | NLA_POLICY_EXACT_LEN(8), | |
370 | [NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP] = | |
371 | NLA_POLICY_EXACT_LEN(8), | |
372 | [NL80211_HE_OBSS_PD_ATTR_SR_CTRL] = { .type = NLA_U8 }, | |
796e90f4 JC |
373 | }; |
374 | ||
5c5e52d1 JC |
375 | static const struct nla_policy |
376 | he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = { | |
377 | [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63), | |
378 | [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG }, | |
379 | [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG }, | |
380 | }; | |
381 | ||
9a5f6488 TC |
382 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
383 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, | |
384 | .len = NL80211_MAX_SUPP_RATES }, | |
385 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, | |
386 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
387 | [NL80211_TXRATE_VHT] = NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_txrate_vht)), | |
388 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, | |
eb89a6a6 MH |
389 | [NL80211_TXRATE_HE] = NLA_POLICY_EXACT_LEN(sizeof(struct nl80211_txrate_he)), |
390 | [NL80211_TXRATE_HE_GI] = NLA_POLICY_RANGE(NLA_U8, | |
391 | NL80211_RATE_INFO_HE_GI_0_8, | |
392 | NL80211_RATE_INFO_HE_GI_3_2), | |
393 | [NL80211_TXRATE_HE_LTF] = NLA_POLICY_RANGE(NLA_U8, | |
394 | NL80211_RATE_INFO_HE_1XLTF, | |
395 | NL80211_RATE_INFO_HE_4XLTF), | |
9a5f6488 TC |
396 | }; |
397 | ||
77f576de T |
398 | static const struct nla_policy |
399 | nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = { | |
3710a8a6 JB |
400 | [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 }, |
401 | [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 }, | |
77f576de | 402 | [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG }, |
3710a8a6 | 403 | [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff), |
77f576de T |
404 | [NL80211_TID_CONFIG_ATTR_NOACK] = |
405 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), | |
6a21d16c T |
406 | [NL80211_TID_CONFIG_ATTR_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), |
407 | [NL80211_TID_CONFIG_ATTR_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), | |
ade274b2 T |
408 | [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL] = |
409 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), | |
04f7d142 T |
410 | [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL] = |
411 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), | |
33462e68 SM |
412 | [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL] = |
413 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), | |
9a5f6488 TC |
414 | [NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE] = |
415 | NLA_POLICY_MAX(NLA_U8, NL80211_TX_RATE_FIXED), | |
416 | [NL80211_TID_CONFIG_ATTR_TX_RATE] = | |
417 | NLA_POLICY_NESTED(nl80211_txattr_policy), | |
77f576de T |
418 | }; |
419 | ||
291c49de AD |
420 | static const struct nla_policy |
421 | nl80211_fils_discovery_policy[NL80211_FILS_DISCOVERY_ATTR_MAX + 1] = { | |
422 | [NL80211_FILS_DISCOVERY_ATTR_INT_MIN] = NLA_POLICY_MAX(NLA_U32, 10000), | |
423 | [NL80211_FILS_DISCOVERY_ATTR_INT_MAX] = NLA_POLICY_MAX(NLA_U32, 10000), | |
272cd0e8 AD |
424 | [NL80211_FILS_DISCOVERY_ATTR_TMPL] = |
425 | NLA_POLICY_RANGE(NLA_BINARY, | |
426 | NL80211_FILS_DISCOVERY_TMPL_MIN_LEN, | |
427 | IEEE80211_MAX_DATA_LEN), | |
291c49de AD |
428 | }; |
429 | ||
7443dcd1 AD |
430 | static const struct nla_policy |
431 | nl80211_unsol_bcast_probe_resp_policy[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1] = { | |
432 | [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] = NLA_POLICY_MAX(NLA_U32, 20), | |
433 | [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL] = { .type = NLA_BINARY, | |
434 | .len = IEEE80211_MAX_DATA_LEN } | |
435 | }; | |
436 | ||
6bdb68ce CH |
437 | static const struct nla_policy |
438 | sar_specs_policy[NL80211_SAR_ATTR_SPECS_MAX + 1] = { | |
439 | [NL80211_SAR_ATTR_SPECS_POWER] = { .type = NLA_S32 }, | |
440 | [NL80211_SAR_ATTR_SPECS_RANGE_INDEX] = {.type = NLA_U32 }, | |
441 | }; | |
442 | ||
443 | static const struct nla_policy | |
444 | sar_policy[NL80211_SAR_ATTR_MAX + 1] = { | |
445 | [NL80211_SAR_ATTR_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_SAR_TYPE), | |
446 | [NL80211_SAR_ATTR_SPECS] = NLA_POLICY_NESTED_ARRAY(sar_specs_policy), | |
447 | }; | |
448 | ||
dc1e3cb8 JC |
449 | static const struct nla_policy |
450 | nl80211_mbssid_config_policy[NL80211_MBSSID_CONFIG_ATTR_MAX + 1] = { | |
451 | [NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES] = NLA_POLICY_MIN(NLA_U8, 2), | |
452 | [NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY] = | |
453 | NLA_POLICY_MIN(NLA_U8, 1), | |
454 | [NL80211_MBSSID_CONFIG_ATTR_INDEX] = { .type = NLA_U8 }, | |
455 | [NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX] = { .type = NLA_U32 }, | |
456 | [NL80211_MBSSID_CONFIG_ATTR_EMA] = { .type = NLA_FLAG }, | |
457 | }; | |
458 | ||
ff5c4dc4 JB |
459 | static const struct nla_policy |
460 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
461 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | |
462 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
463 | }; | |
464 | ||
d15da2a2 | 465 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
6d4dd4ef | 466 | [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD }, |
55682965 JB |
467 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
468 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 469 | .len = 20-1 }, |
31888487 | 470 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 471 | |
72bdcf34 | 472 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 473 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
2a38075c AAL |
474 | [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8, |
475 | NL80211_EDMG_CHANNELS_MIN, | |
476 | NL80211_EDMG_CHANNELS_MAX), | |
477 | [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8, | |
478 | NL80211_EDMG_BW_CONFIG_MIN, | |
479 | NL80211_EDMG_BW_CONFIG_MAX), | |
480 | ||
3d9d1d66 JB |
481 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
482 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
942ba88b | 483 | [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), |
3d9d1d66 JB |
484 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
485 | ||
ab0d76f6 JB |
486 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), |
487 | [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), | |
b9a5f8ca JM |
488 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
489 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 490 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
3057dbfd | 491 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
55682965 | 492 | |
ab0d76f6 | 493 | [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX), |
55682965 JB |
494 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
495 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 496 | |
c7721c05 JB |
497 | [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
498 | [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), | |
41ade00f | 499 | |
b9454e83 | 500 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
501 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
502 | .len = WLAN_MAX_KEY_LEN }, | |
56be393f | 503 | [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7), |
41ade00f JB |
504 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
505 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 506 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
ab0d76f6 JB |
507 | [NL80211_ATTR_KEY_TYPE] = |
508 | NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES), | |
ed1b6cc7 JB |
509 | |
510 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
511 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
f88eb7c0 JB |
512 | [NL80211_ATTR_BEACON_HEAD] = |
513 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head, | |
514 | IEEE80211_MAX_DATA_LEN), | |
3d7af878 JB |
515 | [NL80211_ATTR_BEACON_TAIL] = |
516 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, | |
517 | IEEE80211_MAX_DATA_LEN), | |
ab0d76f6 JB |
518 | [NL80211_ATTR_STA_AID] = |
519 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), | |
5727ef1b JB |
520 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
521 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
522 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
523 | .len = NL80211_MAX_SUPP_RATES }, | |
ab0d76f6 JB |
524 | [NL80211_ATTR_STA_PLINK_ACTION] = |
525 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1), | |
e96d1cd2 ARN |
526 | [NL80211_ATTR_STA_TX_POWER_SETTING] = |
527 | NLA_POLICY_RANGE(NLA_U8, | |
528 | NL80211_TX_POWER_AUTOMATIC, | |
529 | NL80211_TX_POWER_FIXED), | |
530 | [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 }, | |
5727ef1b | 531 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 532 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 533 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 534 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
1fab1b89 | 535 | [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT, |
9f1ba906 | 536 | |
6624bb34 JB |
537 | /* allow 3 for NUL-termination, we used to declare this NLA_STRING */ |
538 | [NL80211_ATTR_REG_ALPHA2] = NLA_POLICY_RANGE(NLA_BINARY, 2, 3), | |
b2e1b302 LR |
539 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
540 | ||
9f1ba906 JM |
541 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
542 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
543 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
544 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
545 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 546 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 547 | |
24bdd9f4 | 548 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 549 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 550 | |
c7721c05 | 551 | [NL80211_ATTR_HT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_HT_CAPABILITY_LEN), |
9aed3cc1 JM |
552 | |
553 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
3d7af878 JB |
554 | [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, |
555 | validate_ie_attr, | |
556 | IEEE80211_MAX_DATA_LEN), | |
2a519311 JB |
557 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
558 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
559 | |
560 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
561 | .len = IEEE80211_MAX_SSID_LEN }, | |
562 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
563 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 564 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 565 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
ab0d76f6 JB |
566 | [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32, |
567 | NL80211_MFP_NO, | |
568 | NL80211_MFP_OPTIONAL), | |
ff5c4dc4 JB |
569 | [NL80211_ATTR_STA_FLAGS2] = |
570 | NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_sta_flag_update)), | |
3f77316c | 571 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
572 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
573 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
64bf3d4b | 574 | [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG }, |
b23aa676 | 575 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
ea750801 | 576 | [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 }, |
b23aa676 SO |
577 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
578 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 579 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 580 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
c7721c05 | 581 | [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN), |
9588bbd5 JM |
582 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
583 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 584 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
585 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
586 | .len = IEEE80211_MAX_DATA_LEN }, | |
587 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ab0d76f6 JB |
588 | [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32, |
589 | NL80211_PS_DISABLED, | |
590 | NL80211_PS_ENABLED), | |
d6dc1a38 | 591 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 592 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 593 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
594 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
595 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 596 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
597 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
598 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 599 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 600 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 601 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 602 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
ab0d76f6 JB |
603 | [NL80211_ATTR_STA_PLINK_STATE] = |
604 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1), | |
056e9375 JK |
605 | [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 }, |
606 | [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG }, | |
ab0d76f6 JB |
607 | [NL80211_ATTR_MESH_PEER_AID] = |
608 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), | |
bbe6ad6d | 609 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 610 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 611 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
ab0d76f6 JB |
612 | [NL80211_ATTR_HIDDEN_SSID] = |
613 | NLA_POLICY_RANGE(NLA_U32, | |
614 | NL80211_HIDDEN_SSID_NOT_IN_USE, | |
615 | NL80211_HIDDEN_SSID_ZERO_CONTENTS), | |
3d7af878 JB |
616 | [NL80211_ATTR_IE_PROBE_RESP] = |
617 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, | |
618 | IEEE80211_MAX_DATA_LEN), | |
619 | [NL80211_ATTR_IE_ASSOC_RESP] = | |
620 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, | |
621 | IEEE80211_MAX_DATA_LEN), | |
f4b34b55 | 622 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
ff5c4dc4 | 623 | [NL80211_ATTR_STA_WME] = NLA_POLICY_NESTED(nl80211_sta_wme_policy), |
a1f1c21c | 624 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 625 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
626 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
627 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
628 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
629 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
630 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
31fa97c5 | 631 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
e247bd90 | 632 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
633 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
634 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 635 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
636 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
637 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
638 | .len = NL80211_HT_CAPABILITY_LEN | |
639 | }, | |
1d9d9213 | 640 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 641 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 642 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 643 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 644 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
cb9abd48 JB |
645 | |
646 | /* need to include at least Auth Transaction and Status Code */ | |
647 | [NL80211_ATTR_AUTH_DATA] = NLA_POLICY_MIN_LEN(4), | |
648 | ||
c7721c05 | 649 | [NL80211_ATTR_VHT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_VHT_CAPABILITY_LEN), |
ed473771 | 650 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
ab0d76f6 JB |
651 | [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127), |
652 | [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1), | |
653 | [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = | |
654 | NLA_POLICY_RANGE(NLA_U32, | |
655 | NL80211_MESH_POWER_UNKNOWN + 1, | |
656 | NL80211_MESH_POWER_MAX), | |
77765eaf VT |
657 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
658 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
659 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
660 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 661 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
662 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
663 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
664 | .len = NL80211_VHT_CAPABILITY_LEN, | |
665 | }, | |
355199e0 JM |
666 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
667 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
668 | .len = IEEE80211_MAX_DATA_LEN }, | |
0e1a1d85 | 669 | [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 }, |
cb9abd48 JB |
670 | [NL80211_ATTR_MAX_CRIT_PROT_DURATION] = |
671 | NLA_POLICY_MAX(NLA_U16, NL80211_CRIT_PROTO_MAX_DURATION), | |
ab0d76f6 JB |
672 | [NL80211_ATTR_PEER_AID] = |
673 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), | |
16ef1fe2 SW |
674 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
675 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
676 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
00c207ed JC |
677 | [NL80211_ATTR_CNTDWN_OFFS_BEACON] = { .type = NLA_BINARY }, |
678 | [NL80211_ATTR_CNTDWN_OFFS_PRESP] = { .type = NLA_BINARY }, | |
cb9abd48 | 679 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = NLA_POLICY_MIN_LEN(2), |
c8b82802 JB |
680 | /* |
681 | * The value of the Length field of the Supported Operating | |
682 | * Classes element is between 2 and 253. | |
683 | */ | |
684 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = | |
685 | NLA_POLICY_RANGE(NLA_BINARY, 2, 253), | |
5336fa88 | 686 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
60f4a7b1 | 687 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
ad7e718c JB |
688 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
689 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | |
690 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | |
c8b82802 JB |
691 | [NL80211_ATTR_QOS_MAP] = NLA_POLICY_RANGE(NLA_BINARY, |
692 | IEEE80211_QOS_MAP_LEN_MIN, | |
693 | IEEE80211_QOS_MAP_LEN_MAX), | |
c7721c05 | 694 | [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
1df4a510 | 695 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
df942e7b | 696 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
18e5ca65 | 697 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
34d22ce2 | 698 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
bab5ab7d | 699 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
ab0d76f6 JB |
700 | [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1), |
701 | [NL80211_ATTR_USER_PRIO] = | |
702 | NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1), | |
960d01ac | 703 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
18998c38 | 704 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
5cde05c6 | 705 | [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 }, |
c7721c05 | 706 | [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
1bdd716c | 707 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
4b681c82 | 708 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
9c748934 | 709 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
05050753 | 710 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
34d50519 | 711 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
38de03d2 | 712 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
ab0d76f6 JB |
713 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = |
714 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1), | |
c6e6a0c8 AE |
715 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
716 | .len = VHT_MUMIMO_GROUPS_DATA_LEN | |
717 | }, | |
c7721c05 | 718 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
ab0d76f6 | 719 | [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1), |
8585989d | 720 | [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, |
a442b761 | 721 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, |
348bd456 JM |
722 | [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, |
723 | .len = FILS_MAX_KEK_LEN }, | |
c7721c05 | 724 | [NL80211_ATTR_FILS_NONCES] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN), |
ce0ce13a | 725 | [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, |
c7721c05 | 726 | [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
bf95ecdb | 727 | [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, |
728 | [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { | |
729 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) | |
730 | }, | |
3093ebbe | 731 | [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, |
a3caf744 VK |
732 | [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, |
733 | .len = FILS_ERP_MAX_USERNAME_LEN }, | |
734 | [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, | |
735 | .len = FILS_ERP_MAX_REALM_LEN }, | |
736 | [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, | |
737 | [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, | |
738 | .len = FILS_ERP_MAX_RRK_LEN }, | |
c7721c05 | 739 | [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2), |
a3caf744 | 740 | [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, |
cb9abd48 | 741 | [NL80211_ATTR_PMKR0_NAME] = NLA_POLICY_EXACT_LEN(WLAN_PMK_NAME_LEN), |
ca986ad9 | 742 | [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, |
40cbfa90 | 743 | [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, |
52539ca8 THJ |
744 | |
745 | [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 }, | |
746 | [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 }, | |
747 | [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 }, | |
c8b82802 | 748 | [NL80211_ATTR_HE_CAPABILITY] = |
a3a20feb JB |
749 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_he_capa, |
750 | NL80211_HE_MAX_CAPABILITY_LEN), | |
0e012b4e JB |
751 | [NL80211_ATTR_FTM_RESPONDER] = |
752 | NLA_POLICY_NESTED(nl80211_ftm_responder_policy), | |
9bb7e0f2 JB |
753 | [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1), |
754 | [NL80211_ATTR_PEER_MEASUREMENTS] = | |
23323289 | 755 | NLA_POLICY_NESTED(nl80211_pmsr_attr_policy), |
36647055 | 756 | [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1), |
26f7044e CHH |
757 | [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY, |
758 | .len = SAE_PASSWORD_MAX_LEN }, | |
a0de1ca3 | 759 | [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG }, |
796e90f4 | 760 | [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy), |
14f34e36 | 761 | [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2), |
5c5e52d1 | 762 | [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy), |
77f576de T |
763 | [NL80211_ATTR_TID_CONFIG] = |
764 | NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy), | |
5631d96a | 765 | [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG }, |
7fc82af8 VJ |
766 | [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1), |
767 | [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100), | |
9dba48a6 | 768 | [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG }, |
942ba88b | 769 | [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), |
2032f3b2 | 770 | [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED }, |
8140860c JB |
771 | [NL80211_ATTR_HE_6GHZ_CAPABILITY] = |
772 | NLA_POLICY_EXACT_LEN(sizeof(struct ieee80211_he_6ghz_capa)), | |
291c49de AD |
773 | [NL80211_ATTR_FILS_DISCOVERY] = |
774 | NLA_POLICY_NESTED(nl80211_fils_discovery_policy), | |
7443dcd1 AD |
775 | [NL80211_ATTR_UNSOL_BCAST_PROBE_RESP] = |
776 | NLA_POLICY_NESTED(nl80211_unsol_bcast_probe_resp_policy), | |
d2b7588a TP |
777 | [NL80211_ATTR_S1G_CAPABILITY] = |
778 | NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN), | |
779 | [NL80211_ATTR_S1G_CAPABILITY_MASK] = | |
780 | NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN), | |
9f0ffa41 RD |
781 | [NL80211_ATTR_SAE_PWE] = |
782 | NLA_POLICY_RANGE(NLA_U8, NL80211_SAE_PWE_HUNT_AND_PECK, | |
783 | NL80211_SAE_PWE_BOTH), | |
3bb02143 | 784 | [NL80211_ATTR_RECONNECT_REQUESTED] = { .type = NLA_REJECT }, |
6bdb68ce | 785 | [NL80211_ATTR_SAR_SPEC] = NLA_POLICY_NESTED(sar_policy), |
b6db0f89 | 786 | [NL80211_ATTR_DISABLE_HE] = { .type = NLA_FLAG }, |
0d2ab3ae JC |
787 | [NL80211_ATTR_OBSS_COLOR_BITMAP] = { .type = NLA_U64 }, |
788 | [NL80211_ATTR_COLOR_CHANGE_COUNT] = { .type = NLA_U8 }, | |
789 | [NL80211_ATTR_COLOR_CHANGE_COLOR] = { .type = NLA_U8 }, | |
790 | [NL80211_ATTR_COLOR_CHANGE_ELEMS] = NLA_POLICY_NESTED(nl80211_policy), | |
dc1e3cb8 JC |
791 | [NL80211_ATTR_MBSSID_CONFIG] = |
792 | NLA_POLICY_NESTED(nl80211_mbssid_config_policy), | |
793 | [NL80211_ATTR_MBSSID_ELEMS] = { .type = NLA_NESTED }, | |
a95bfb87 | 794 | [NL80211_ATTR_RADAR_BACKGROUND] = { .type = NLA_FLAG }, |
47301a74 | 795 | [NL80211_ATTR_AP_SETTINGS_FLAGS] = { .type = NLA_U32 }, |
ea05fd35 IP |
796 | [NL80211_ATTR_EHT_CAPABILITY] = |
797 | NLA_POLICY_RANGE(NLA_BINARY, | |
798 | NL80211_EHT_MIN_CAPABILITY_LEN, | |
799 | NL80211_EHT_MAX_CAPABILITY_LEN), | |
36f84235 | 800 | [NL80211_ATTR_DISABLE_EHT] = { .type = NLA_FLAG }, |
7b0a0e3c JB |
801 | [NL80211_ATTR_MLO_LINKS] = |
802 | NLA_POLICY_NESTED_ARRAY(nl80211_policy), | |
803 | [NL80211_ATTR_MLO_LINK_ID] = | |
804 | NLA_POLICY_RANGE(NLA_U8, 0, IEEE80211_MLD_MAX_NUM_LINKS), | |
d648c230 | 805 | [NL80211_ATTR_MLD_ADDR] = NLA_POLICY_EXACT_LEN(ETH_ALEN), |
efbabc11 | 806 | [NL80211_ATTR_MLO_SUPPORT] = { .type = NLA_FLAG }, |
ecad3b0b | 807 | [NL80211_ATTR_MAX_NUM_AKM_SUITES] = { .type = NLA_REJECT }, |
55682965 JB |
808 | }; |
809 | ||
e31b8213 | 810 | /* policy for the key attributes */ |
b54452b0 | 811 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 812 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
813 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
814 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 815 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
816 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
817 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
ab0d76f6 | 818 | [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1), |
dbd2fd65 | 819 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
6cdd3979 | 820 | [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX), |
dbd2fd65 JB |
821 | }; |
822 | ||
823 | /* policy for the key default flags */ | |
824 | static const struct nla_policy | |
825 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
826 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
827 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
828 | }; |
829 | ||
f83ace3b | 830 | #ifdef CONFIG_PM |
ff1b6e69 JB |
831 | /* policy for WoWLAN attributes */ |
832 | static const struct nla_policy | |
833 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
834 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
835 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
836 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
837 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
838 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
839 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
840 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
841 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e | 842 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
8cd4d456 | 843 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
2a0e047e JB |
844 | }; |
845 | ||
846 | static const struct nla_policy | |
847 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
848 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
849 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
c7721c05 | 850 | [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
2a0e047e JB |
851 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
852 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
bc043585 | 853 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = NLA_POLICY_MIN_LEN(1), |
2a0e047e JB |
854 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
855 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
856 | }, | |
857 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
858 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
859 | }, | |
860 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
bc043585 JB |
861 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = NLA_POLICY_MIN_LEN(1), |
862 | [NL80211_WOWLAN_TCP_WAKE_MASK] = NLA_POLICY_MIN_LEN(1), | |
ff1b6e69 | 863 | }; |
f83ace3b | 864 | #endif /* CONFIG_PM */ |
ff1b6e69 | 865 | |
be29b99a AK |
866 | /* policy for coalesce rule attributes */ |
867 | static const struct nla_policy | |
868 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
869 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
ab0d76f6 JB |
870 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = |
871 | NLA_POLICY_RANGE(NLA_U32, | |
872 | NL80211_COALESCE_CONDITION_MATCH, | |
873 | NL80211_COALESCE_CONDITION_NO_MATCH), | |
be29b99a AK |
874 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
875 | }; | |
876 | ||
e5497d76 JB |
877 | /* policy for GTK rekey offload attributes */ |
878 | static const struct nla_policy | |
879 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
093a48d2 NE |
880 | [NL80211_REKEY_DATA_KEK] = { |
881 | .type = NLA_BINARY, | |
882 | .len = NL80211_KEK_EXT_LEN | |
883 | }, | |
884 | [NL80211_REKEY_DATA_KCK] = { | |
885 | .type = NLA_BINARY, | |
886 | .len = NL80211_KCK_EXT_LEN | |
887 | }, | |
cb9abd48 | 888 | [NL80211_REKEY_DATA_REPLAY_CTR] = NLA_POLICY_EXACT_LEN(NL80211_REPLAY_CTR_LEN), |
093a48d2 | 889 | [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 }, |
e5497d76 JB |
890 | }; |
891 | ||
1e1b11b6 | 892 | static const struct nla_policy |
893 | nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = { | |
894 | [NL80211_BAND_2GHZ] = { .type = NLA_S32 }, | |
895 | [NL80211_BAND_5GHZ] = { .type = NLA_S32 }, | |
e548a1c3 | 896 | [NL80211_BAND_6GHZ] = { .type = NLA_S32 }, |
1e1b11b6 | 897 | [NL80211_BAND_60GHZ] = { .type = NLA_S32 }, |
63fa0426 | 898 | [NL80211_BAND_LC] = { .type = NLA_S32 }, |
1e1b11b6 | 899 | }; |
900 | ||
a1f1c21c LC |
901 | static const struct nla_policy |
902 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 903 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 904 | .len = IEEE80211_MAX_SSID_LEN }, |
c7721c05 | 905 | [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
88e920b4 | 906 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
1e1b11b6 | 907 | [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] = |
908 | NLA_POLICY_NESTED(nl80211_match_band_rssi_policy), | |
a1f1c21c LC |
909 | }; |
910 | ||
3b06d277 AS |
911 | static const struct nla_policy |
912 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { | |
913 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, | |
914 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, | |
915 | }; | |
916 | ||
38de03d2 AS |
917 | static const struct nla_policy |
918 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { | |
919 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, | |
920 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, | |
921 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { | |
922 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) | |
923 | }, | |
924 | }; | |
925 | ||
a442b761 AB |
926 | /* policy for NAN function attributes */ |
927 | static const struct nla_policy | |
928 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { | |
cb9abd48 JB |
929 | [NL80211_NAN_FUNC_TYPE] = |
930 | NLA_POLICY_MAX(NLA_U8, NL80211_NAN_FUNC_MAX_TYPE), | |
0a27844c | 931 | [NL80211_NAN_FUNC_SERVICE_ID] = { |
a442b761 AB |
932 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, |
933 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, | |
934 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, | |
935 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, | |
936 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, | |
937 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, | |
c7721c05 | 938 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
a442b761 AB |
939 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, |
940 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, | |
941 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, | |
942 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, | |
943 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, | |
944 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, | |
945 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, | |
946 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, | |
947 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, | |
948 | }; | |
949 | ||
950 | /* policy for Service Response Filter attributes */ | |
951 | static const struct nla_policy | |
952 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { | |
953 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, | |
954 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, | |
955 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, | |
956 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, | |
957 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, | |
958 | }; | |
959 | ||
ad670233 PX |
960 | /* policy for packet pattern attributes */ |
961 | static const struct nla_policy | |
962 | nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { | |
963 | [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, | |
964 | [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, | |
965 | [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, | |
966 | }; | |
967 | ||
ce6b6974 JB |
968 | static int nl80211_prepare_wdev_dump(struct netlink_callback *cb, |
969 | struct cfg80211_registered_device **rdev, | |
970 | struct wireless_dev **wdev, | |
971 | struct nlattr **attrbuf) | |
a043897a | 972 | { |
97990a06 | 973 | int err; |
a043897a | 974 | |
97990a06 | 975 | if (!cb->args[0]) { |
ce6b6974 JB |
976 | struct nlattr **attrbuf_free = NULL; |
977 | ||
978 | if (!attrbuf) { | |
979 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), | |
980 | GFP_KERNEL); | |
981 | if (!attrbuf) | |
982 | return -ENOMEM; | |
983 | attrbuf_free = attrbuf; | |
984 | } | |
50508d94 | 985 | |
8cb08174 JB |
986 | err = nlmsg_parse_deprecated(cb->nlh, |
987 | GENL_HDRLEN + nl80211_fam.hdrsize, | |
50508d94 | 988 | attrbuf, nl80211_fam.maxattr, |
8cb08174 | 989 | nl80211_policy, NULL); |
50508d94 | 990 | if (err) { |
ce6b6974 | 991 | kfree(attrbuf_free); |
ea90e0dc | 992 | return err; |
50508d94 | 993 | } |
67748893 | 994 | |
a05829a7 JB |
995 | rtnl_lock(); |
996 | *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(cb->skb->sk), | |
50508d94 | 997 | attrbuf); |
ce6b6974 | 998 | kfree(attrbuf_free); |
a05829a7 JB |
999 | if (IS_ERR(*wdev)) { |
1000 | rtnl_unlock(); | |
ea90e0dc | 1001 | return PTR_ERR(*wdev); |
a05829a7 | 1002 | } |
f26cbf40 | 1003 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
a05829a7 JB |
1004 | mutex_lock(&(*rdev)->wiphy.mtx); |
1005 | rtnl_unlock(); | |
c319d50b JB |
1006 | /* 0 is the first index - add 1 to parse only once */ |
1007 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
1008 | cb->args[1] = (*wdev)->identifier; |
1009 | } else { | |
c319d50b | 1010 | /* subtract the 1 again here */ |
a05829a7 | 1011 | struct wiphy *wiphy; |
97990a06 | 1012 | struct wireless_dev *tmp; |
67748893 | 1013 | |
a05829a7 JB |
1014 | rtnl_lock(); |
1015 | wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
1016 | if (!wiphy) { | |
1017 | rtnl_unlock(); | |
ea90e0dc | 1018 | return -ENODEV; |
a05829a7 | 1019 | } |
f26cbf40 | 1020 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 1021 | *wdev = NULL; |
67748893 | 1022 | |
53873f13 | 1023 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
97990a06 JB |
1024 | if (tmp->identifier == cb->args[1]) { |
1025 | *wdev = tmp; | |
1026 | break; | |
1027 | } | |
1028 | } | |
67748893 | 1029 | |
a05829a7 JB |
1030 | if (!*wdev) { |
1031 | rtnl_unlock(); | |
ea90e0dc | 1032 | return -ENODEV; |
a05829a7 JB |
1033 | } |
1034 | mutex_lock(&(*rdev)->wiphy.mtx); | |
1035 | rtnl_unlock(); | |
67748893 JB |
1036 | } |
1037 | ||
67748893 | 1038 | return 0; |
67748893 JB |
1039 | } |
1040 | ||
55682965 | 1041 | /* message building helper */ |
9bb7e0f2 JB |
1042 | void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
1043 | int flags, u8 cmd) | |
55682965 JB |
1044 | { |
1045 | /* since there is no private header just add the generic one */ | |
15e47304 | 1046 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
1047 | } |
1048 | ||
50f32718 HD |
1049 | static int nl80211_msg_put_wmm_rules(struct sk_buff *msg, |
1050 | const struct ieee80211_reg_rule *rule) | |
1051 | { | |
1052 | int j; | |
1053 | struct nlattr *nl_wmm_rules = | |
ae0be8de | 1054 | nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM); |
50f32718 HD |
1055 | |
1056 | if (!nl_wmm_rules) | |
1057 | goto nla_put_failure; | |
1058 | ||
1059 | for (j = 0; j < IEEE80211_NUM_ACS; j++) { | |
ae0be8de | 1060 | struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j); |
50f32718 HD |
1061 | |
1062 | if (!nl_wmm_rule) | |
1063 | goto nla_put_failure; | |
1064 | ||
1065 | if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, | |
38cb87ee | 1066 | rule->wmm_rule.client[j].cw_min) || |
50f32718 | 1067 | nla_put_u16(msg, NL80211_WMMR_CW_MAX, |
38cb87ee | 1068 | rule->wmm_rule.client[j].cw_max) || |
50f32718 | 1069 | nla_put_u8(msg, NL80211_WMMR_AIFSN, |
38cb87ee | 1070 | rule->wmm_rule.client[j].aifsn) || |
d3c89bbc HD |
1071 | nla_put_u16(msg, NL80211_WMMR_TXOP, |
1072 | rule->wmm_rule.client[j].cot)) | |
50f32718 HD |
1073 | goto nla_put_failure; |
1074 | ||
1075 | nla_nest_end(msg, nl_wmm_rule); | |
1076 | } | |
1077 | nla_nest_end(msg, nl_wmm_rules); | |
1078 | ||
1079 | return 0; | |
1080 | ||
1081 | nla_put_failure: | |
1082 | return -ENOBUFS; | |
1083 | } | |
1084 | ||
1085 | static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy, | |
cdc89b97 JB |
1086 | struct ieee80211_channel *chan, |
1087 | bool large) | |
5dab3b8a | 1088 | { |
ea077c1c RL |
1089 | /* Some channels must be completely excluded from the |
1090 | * list to protect old user-space tools from breaking | |
1091 | */ | |
1092 | if (!large && chan->flags & | |
1093 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
1094 | return 0; | |
f8d504ca JB |
1095 | if (!large && chan->freq_offset) |
1096 | return 0; | |
ea077c1c | 1097 | |
9360ffd1 DM |
1098 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
1099 | chan->center_freq)) | |
1100 | goto nla_put_failure; | |
5dab3b8a | 1101 | |
942ba88b TP |
1102 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset)) |
1103 | goto nla_put_failure; | |
1104 | ||
9360ffd1 DM |
1105 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
1106 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
1107 | goto nla_put_failure; | |
8fe02e16 LR |
1108 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
1109 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
1110 | goto nla_put_failure; | |
1111 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
1112 | goto nla_put_failure; | |
1113 | } | |
cdc89b97 JB |
1114 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
1115 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
1116 | goto nla_put_failure; | |
1117 | if (large) { | |
1118 | u32 time; | |
1119 | ||
1120 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
1121 | ||
1122 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
1123 | chan->dfs_state)) | |
1124 | goto nla_put_failure; | |
1125 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
1126 | time)) | |
1127 | goto nla_put_failure; | |
089027e5 JD |
1128 | if (nla_put_u32(msg, |
1129 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
1130 | chan->dfs_cac_ms)) | |
1131 | goto nla_put_failure; | |
cdc89b97 JB |
1132 | } |
1133 | } | |
5dab3b8a | 1134 | |
fe1abafd JB |
1135 | if (large) { |
1136 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
1137 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
1138 | goto nla_put_failure; | |
1139 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
1140 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
1141 | goto nla_put_failure; | |
1142 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
1143 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
1144 | goto nla_put_failure; | |
1145 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
1146 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
1147 | goto nla_put_failure; | |
570dbde1 DS |
1148 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
1149 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
1150 | goto nla_put_failure; | |
06f207fc AN |
1151 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
1152 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) | |
570dbde1 | 1153 | goto nla_put_failure; |
ea077c1c RL |
1154 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
1155 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
1156 | goto nla_put_failure; | |
1157 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
1158 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
1159 | goto nla_put_failure; | |
1e61d82c HD |
1160 | if ((chan->flags & IEEE80211_CHAN_NO_HE) && |
1161 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE)) | |
1162 | goto nla_put_failure; | |
d65a9770 TP |
1163 | if ((chan->flags & IEEE80211_CHAN_1MHZ) && |
1164 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_1MHZ)) | |
1165 | goto nla_put_failure; | |
1166 | if ((chan->flags & IEEE80211_CHAN_2MHZ) && | |
1167 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_2MHZ)) | |
1168 | goto nla_put_failure; | |
1169 | if ((chan->flags & IEEE80211_CHAN_4MHZ) && | |
1170 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_4MHZ)) | |
1171 | goto nla_put_failure; | |
1172 | if ((chan->flags & IEEE80211_CHAN_8MHZ) && | |
1173 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_8MHZ)) | |
1174 | goto nla_put_failure; | |
1175 | if ((chan->flags & IEEE80211_CHAN_16MHZ) && | |
1176 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_16MHZ)) | |
1177 | goto nla_put_failure; | |
c2b3d769 S |
1178 | if ((chan->flags & IEEE80211_CHAN_NO_320MHZ) && |
1179 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_320MHZ)) | |
1180 | goto nla_put_failure; | |
31846b65 IP |
1181 | if ((chan->flags & IEEE80211_CHAN_NO_EHT) && |
1182 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_EHT)) | |
1183 | goto nla_put_failure; | |
fe1abafd JB |
1184 | } |
1185 | ||
9360ffd1 DM |
1186 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
1187 | DBM_TO_MBM(chan->max_power))) | |
1188 | goto nla_put_failure; | |
5dab3b8a | 1189 | |
50f32718 HD |
1190 | if (large) { |
1191 | const struct ieee80211_reg_rule *rule = | |
b88d26d9 | 1192 | freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); |
50f32718 | 1193 | |
38cb87ee | 1194 | if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { |
50f32718 HD |
1195 | if (nl80211_msg_put_wmm_rules(msg, rule)) |
1196 | goto nla_put_failure; | |
1197 | } | |
1198 | } | |
1199 | ||
5dab3b8a LR |
1200 | return 0; |
1201 | ||
1202 | nla_put_failure: | |
1203 | return -ENOBUFS; | |
1204 | } | |
1205 | ||
52539ca8 THJ |
1206 | static bool nl80211_put_txq_stats(struct sk_buff *msg, |
1207 | struct cfg80211_txq_stats *txqstats, | |
1208 | int attrtype) | |
1209 | { | |
1210 | struct nlattr *txqattr; | |
1211 | ||
1212 | #define PUT_TXQVAL_U32(attr, memb) do { \ | |
1213 | if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \ | |
1214 | nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ | |
1215 | return false; \ | |
1216 | } while (0) | |
1217 | ||
ae0be8de | 1218 | txqattr = nla_nest_start_noflag(msg, attrtype); |
52539ca8 THJ |
1219 | if (!txqattr) |
1220 | return false; | |
1221 | ||
1222 | PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); | |
1223 | PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); | |
1224 | PUT_TXQVAL_U32(FLOWS, flows); | |
1225 | PUT_TXQVAL_U32(DROPS, drops); | |
1226 | PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); | |
1227 | PUT_TXQVAL_U32(OVERLIMIT, overlimit); | |
1228 | PUT_TXQVAL_U32(OVERMEMORY, overmemory); | |
1229 | PUT_TXQVAL_U32(COLLISIONS, collisions); | |
1230 | PUT_TXQVAL_U32(TX_BYTES, tx_bytes); | |
1231 | PUT_TXQVAL_U32(TX_PACKETS, tx_packets); | |
1232 | PUT_TXQVAL_U32(MAX_FLOWS, max_flows); | |
1233 | nla_nest_end(msg, txqattr); | |
1234 | ||
1235 | #undef PUT_TXQVAL_U32 | |
1236 | return true; | |
1237 | } | |
1238 | ||
55682965 JB |
1239 | /* netlink command implementations */ |
1240 | ||
7b0a0e3c JB |
1241 | /** |
1242 | * nl80211_link_id - return link ID | |
1243 | * @attrs: attributes to look at | |
1244 | * | |
1245 | * Returns: the link ID or 0 if not given | |
1246 | * | |
1247 | * Note this function doesn't do any validation of the link | |
1248 | * ID validity wrt. links that were actually added, so it must | |
1249 | * be called only from ops with %NL80211_FLAG_MLO_VALID_LINK_ID | |
1250 | * or if additional validation is done. | |
1251 | */ | |
1252 | static unsigned int nl80211_link_id(struct nlattr **attrs) | |
1253 | { | |
1254 | struct nlattr *linkid = attrs[NL80211_ATTR_MLO_LINK_ID]; | |
1255 | ||
1256 | if (!linkid) | |
1257 | return 0; | |
1258 | ||
1259 | return nla_get_u8(linkid); | |
1260 | } | |
1261 | ||
1262 | static int nl80211_link_id_or_invalid(struct nlattr **attrs) | |
1263 | { | |
1264 | struct nlattr *linkid = attrs[NL80211_ATTR_MLO_LINK_ID]; | |
1265 | ||
1266 | if (!linkid) | |
1267 | return -1; | |
1268 | ||
1269 | return nla_get_u8(linkid); | |
1270 | } | |
1271 | ||
b9454e83 JB |
1272 | struct key_parse { |
1273 | struct key_params p; | |
1274 | int idx; | |
e31b8213 | 1275 | int type; |
56be393f | 1276 | bool def, defmgmt, defbeacon; |
dbd2fd65 | 1277 | bool def_uni, def_multi; |
b9454e83 JB |
1278 | }; |
1279 | ||
768075eb JB |
1280 | static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, |
1281 | struct key_parse *k) | |
b9454e83 JB |
1282 | { |
1283 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
8cb08174 JB |
1284 | int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key, |
1285 | nl80211_key_policy, | |
1286 | info->extack); | |
b9454e83 JB |
1287 | if (err) |
1288 | return err; | |
1289 | ||
1290 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
1291 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
56be393f | 1292 | k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON]; |
b9454e83 | 1293 | |
dbd2fd65 JB |
1294 | if (k->def) { |
1295 | k->def_uni = true; | |
1296 | k->def_multi = true; | |
1297 | } | |
56be393f | 1298 | if (k->defmgmt || k->defbeacon) |
dbd2fd65 JB |
1299 | k->def_multi = true; |
1300 | ||
b9454e83 JB |
1301 | if (tb[NL80211_KEY_IDX]) |
1302 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
1303 | ||
1304 | if (tb[NL80211_KEY_DATA]) { | |
1305 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
1306 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
1307 | } | |
1308 | ||
1309 | if (tb[NL80211_KEY_SEQ]) { | |
1310 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
1311 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
1312 | } | |
1313 | ||
1314 | if (tb[NL80211_KEY_CIPHER]) | |
1315 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
1316 | ||
ab0d76f6 | 1317 | if (tb[NL80211_KEY_TYPE]) |
e31b8213 | 1318 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
e31b8213 | 1319 | |
dbd2fd65 JB |
1320 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
1321 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
7a087e74 | 1322 | |
8cb08174 JB |
1323 | err = nla_parse_nested_deprecated(kdt, |
1324 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
1325 | tb[NL80211_KEY_DEFAULT_TYPES], | |
1326 | nl80211_key_default_policy, | |
1327 | info->extack); | |
dbd2fd65 JB |
1328 | if (err) |
1329 | return err; | |
1330 | ||
1331 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
1332 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
1333 | } | |
1334 | ||
6cdd3979 AW |
1335 | if (tb[NL80211_KEY_MODE]) |
1336 | k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]); | |
1337 | ||
b9454e83 JB |
1338 | return 0; |
1339 | } | |
1340 | ||
1341 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
1342 | { | |
1343 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
1344 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
1345 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
1346 | } | |
1347 | ||
1348 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
1349 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
1350 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
1351 | } | |
1352 | ||
1353 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
1354 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
1355 | ||
1356 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
1357 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
1358 | ||
1359 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
1360 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
1361 | ||
dbd2fd65 JB |
1362 | if (k->def) { |
1363 | k->def_uni = true; | |
1364 | k->def_multi = true; | |
1365 | } | |
1366 | if (k->defmgmt) | |
1367 | k->def_multi = true; | |
1368 | ||
ab0d76f6 | 1369 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) |
e31b8213 | 1370 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
e31b8213 | 1371 | |
dbd2fd65 JB |
1372 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
1373 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
8cb08174 JB |
1374 | int err = nla_parse_nested_deprecated(kdt, |
1375 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
1376 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
1377 | nl80211_key_default_policy, | |
1378 | info->extack); | |
dbd2fd65 JB |
1379 | if (err) |
1380 | return err; | |
1381 | ||
1382 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
1383 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
1384 | } | |
1385 | ||
b9454e83 JB |
1386 | return 0; |
1387 | } | |
1388 | ||
1389 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
1390 | { | |
1391 | int err; | |
1392 | ||
1393 | memset(k, 0, sizeof(*k)); | |
1394 | k->idx = -1; | |
e31b8213 | 1395 | k->type = -1; |
b9454e83 JB |
1396 | |
1397 | if (info->attrs[NL80211_ATTR_KEY]) | |
768075eb | 1398 | err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); |
b9454e83 JB |
1399 | else |
1400 | err = nl80211_parse_key_old(info, k); | |
1401 | ||
1402 | if (err) | |
1403 | return err; | |
1404 | ||
56be393f JM |
1405 | if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) + |
1406 | (k->defbeacon ? 1 : 0) > 1) { | |
1407 | GENL_SET_ERR_MSG(info, | |
1408 | "key with multiple default flags is invalid"); | |
b9454e83 | 1409 | return -EINVAL; |
768075eb | 1410 | } |
b9454e83 | 1411 | |
56be393f | 1412 | if (k->defmgmt || k->defbeacon) { |
768075eb | 1413 | if (k->def_uni || !k->def_multi) { |
56be393f JM |
1414 | GENL_SET_ERR_MSG(info, |
1415 | "defmgmt/defbeacon key must be mcast"); | |
dbd2fd65 | 1416 | return -EINVAL; |
768075eb | 1417 | } |
dbd2fd65 JB |
1418 | } |
1419 | ||
b9454e83 JB |
1420 | if (k->idx != -1) { |
1421 | if (k->defmgmt) { | |
768075eb JB |
1422 | if (k->idx < 4 || k->idx > 5) { |
1423 | GENL_SET_ERR_MSG(info, | |
1424 | "defmgmt key idx not 4 or 5"); | |
b9454e83 | 1425 | return -EINVAL; |
768075eb | 1426 | } |
56be393f JM |
1427 | } else if (k->defbeacon) { |
1428 | if (k->idx < 6 || k->idx > 7) { | |
1429 | GENL_SET_ERR_MSG(info, | |
1430 | "defbeacon key idx not 6 or 7"); | |
1431 | return -EINVAL; | |
1432 | } | |
b9454e83 | 1433 | } else if (k->def) { |
768075eb JB |
1434 | if (k->idx < 0 || k->idx > 3) { |
1435 | GENL_SET_ERR_MSG(info, "def key idx not 0-3"); | |
b9454e83 | 1436 | return -EINVAL; |
768075eb | 1437 | } |
b9454e83 | 1438 | } else { |
56be393f JM |
1439 | if (k->idx < 0 || k->idx > 7) { |
1440 | GENL_SET_ERR_MSG(info, "key idx not 0-7"); | |
b9454e83 | 1441 | return -EINVAL; |
768075eb | 1442 | } |
b9454e83 JB |
1443 | } |
1444 | } | |
1445 | ||
1446 | return 0; | |
1447 | } | |
1448 | ||
fffd0934 JB |
1449 | static struct cfg80211_cached_keys * |
1450 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
768075eb | 1451 | struct genl_info *info, bool *no_ht) |
fffd0934 | 1452 | { |
768075eb | 1453 | struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; |
fffd0934 JB |
1454 | struct key_parse parse; |
1455 | struct nlattr *key; | |
1456 | struct cfg80211_cached_keys *result; | |
1457 | int rem, err, def = 0; | |
f1c1f17a JB |
1458 | bool have_key = false; |
1459 | ||
1460 | nla_for_each_nested(key, keys, rem) { | |
1461 | have_key = true; | |
1462 | break; | |
1463 | } | |
1464 | ||
1465 | if (!have_key) | |
1466 | return NULL; | |
fffd0934 JB |
1467 | |
1468 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
1469 | if (!result) | |
1470 | return ERR_PTR(-ENOMEM); | |
1471 | ||
1472 | result->def = -1; | |
fffd0934 JB |
1473 | |
1474 | nla_for_each_nested(key, keys, rem) { | |
1475 | memset(&parse, 0, sizeof(parse)); | |
1476 | parse.idx = -1; | |
1477 | ||
768075eb | 1478 | err = nl80211_parse_key_new(info, key, &parse); |
fffd0934 JB |
1479 | if (err) |
1480 | goto error; | |
1481 | err = -EINVAL; | |
1482 | if (!parse.p.key) | |
1483 | goto error; | |
768075eb JB |
1484 | if (parse.idx < 0 || parse.idx > 3) { |
1485 | GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); | |
fffd0934 | 1486 | goto error; |
768075eb | 1487 | } |
fffd0934 | 1488 | if (parse.def) { |
768075eb JB |
1489 | if (def) { |
1490 | GENL_SET_ERR_MSG(info, | |
1491 | "only one key can be default"); | |
fffd0934 | 1492 | goto error; |
768075eb | 1493 | } |
fffd0934 JB |
1494 | def = 1; |
1495 | result->def = parse.idx; | |
dbd2fd65 JB |
1496 | if (!parse.def_uni || !parse.def_multi) |
1497 | goto error; | |
fffd0934 JB |
1498 | } else if (parse.defmgmt) |
1499 | goto error; | |
1500 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 1501 | parse.idx, false, NULL); |
fffd0934 JB |
1502 | if (err) |
1503 | goto error; | |
386b1f27 JB |
1504 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
1505 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { | |
768075eb | 1506 | GENL_SET_ERR_MSG(info, "connect key must be WEP"); |
386b1f27 JB |
1507 | err = -EINVAL; |
1508 | goto error; | |
1509 | } | |
fffd0934 JB |
1510 | result->params[parse.idx].cipher = parse.p.cipher; |
1511 | result->params[parse.idx].key_len = parse.p.key_len; | |
1512 | result->params[parse.idx].key = result->data[parse.idx]; | |
1513 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee | 1514 | |
386b1f27 JB |
1515 | /* must be WEP key if we got here */ |
1516 | if (no_ht) | |
1517 | *no_ht = true; | |
fffd0934 JB |
1518 | } |
1519 | ||
f1c1f17a JB |
1520 | if (result->def < 0) { |
1521 | err = -EINVAL; | |
768075eb | 1522 | GENL_SET_ERR_MSG(info, "need a default/TX key"); |
f1c1f17a JB |
1523 | goto error; |
1524 | } | |
1525 | ||
fffd0934 JB |
1526 | return result; |
1527 | error: | |
1528 | kfree(result); | |
1529 | return ERR_PTR(err); | |
1530 | } | |
1531 | ||
1532 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
1533 | { | |
1534 | ASSERT_WDEV_LOCK(wdev); | |
1535 | ||
fffd0934 JB |
1536 | switch (wdev->iftype) { |
1537 | case NL80211_IFTYPE_AP: | |
1538 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 1539 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 1540 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
1541 | break; |
1542 | case NL80211_IFTYPE_ADHOC: | |
7b0a0e3c JB |
1543 | if (wdev->u.ibss.current_bss) |
1544 | return 0; | |
1545 | return -ENOLINK; | |
fffd0934 | 1546 | case NL80211_IFTYPE_STATION: |
074ac8df | 1547 | case NL80211_IFTYPE_P2P_CLIENT: |
7b0a0e3c JB |
1548 | if (wdev->connected) |
1549 | return 0; | |
1550 | return -ENOLINK; | |
de4fcbad | 1551 | case NL80211_IFTYPE_UNSPECIFIED: |
6e0bd6c3 | 1552 | case NL80211_IFTYPE_OCB: |
de4fcbad | 1553 | case NL80211_IFTYPE_MONITOR: |
cb3b7d87 | 1554 | case NL80211_IFTYPE_NAN: |
de4fcbad JB |
1555 | case NL80211_IFTYPE_P2P_DEVICE: |
1556 | case NL80211_IFTYPE_WDS: | |
1557 | case NUM_NL80211_IFTYPES: | |
fffd0934 JB |
1558 | return -EINVAL; |
1559 | } | |
1560 | ||
1561 | return 0; | |
1562 | } | |
1563 | ||
664834de | 1564 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
942ba88b | 1565 | u32 freq) |
664834de JM |
1566 | { |
1567 | struct ieee80211_channel *chan; | |
1568 | ||
942ba88b | 1569 | chan = ieee80211_get_channel_khz(wiphy, freq); |
664834de JM |
1570 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
1571 | return NULL; | |
1572 | return chan; | |
1573 | } | |
1574 | ||
7527a782 JB |
1575 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
1576 | { | |
ae0be8de | 1577 | struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr); |
7527a782 JB |
1578 | int i; |
1579 | ||
1580 | if (!nl_modes) | |
1581 | goto nla_put_failure; | |
1582 | ||
1583 | i = 0; | |
1584 | while (ifmodes) { | |
9360ffd1 DM |
1585 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
1586 | goto nla_put_failure; | |
7527a782 JB |
1587 | ifmodes >>= 1; |
1588 | i++; | |
1589 | } | |
1590 | ||
1591 | nla_nest_end(msg, nl_modes); | |
1592 | return 0; | |
1593 | ||
1594 | nla_put_failure: | |
1595 | return -ENOBUFS; | |
1596 | } | |
1597 | ||
1598 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
1599 | struct sk_buff *msg, |
1600 | bool large) | |
7527a782 JB |
1601 | { |
1602 | struct nlattr *nl_combis; | |
1603 | int i, j; | |
1604 | ||
ae0be8de MK |
1605 | nl_combis = nla_nest_start_noflag(msg, |
1606 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
7527a782 JB |
1607 | if (!nl_combis) |
1608 | goto nla_put_failure; | |
1609 | ||
1610 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
1611 | const struct ieee80211_iface_combination *c; | |
1612 | struct nlattr *nl_combi, *nl_limits; | |
1613 | ||
1614 | c = &wiphy->iface_combinations[i]; | |
1615 | ||
ae0be8de | 1616 | nl_combi = nla_nest_start_noflag(msg, i + 1); |
7527a782 JB |
1617 | if (!nl_combi) |
1618 | goto nla_put_failure; | |
1619 | ||
ae0be8de MK |
1620 | nl_limits = nla_nest_start_noflag(msg, |
1621 | NL80211_IFACE_COMB_LIMITS); | |
7527a782 JB |
1622 | if (!nl_limits) |
1623 | goto nla_put_failure; | |
1624 | ||
1625 | for (j = 0; j < c->n_limits; j++) { | |
1626 | struct nlattr *nl_limit; | |
1627 | ||
ae0be8de | 1628 | nl_limit = nla_nest_start_noflag(msg, j + 1); |
7527a782 JB |
1629 | if (!nl_limit) |
1630 | goto nla_put_failure; | |
9360ffd1 DM |
1631 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
1632 | c->limits[j].max)) | |
1633 | goto nla_put_failure; | |
7527a782 JB |
1634 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
1635 | c->limits[j].types)) | |
1636 | goto nla_put_failure; | |
1637 | nla_nest_end(msg, nl_limit); | |
1638 | } | |
1639 | ||
1640 | nla_nest_end(msg, nl_limits); | |
1641 | ||
9360ffd1 DM |
1642 | if (c->beacon_int_infra_match && |
1643 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
1644 | goto nla_put_failure; | |
1645 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
1646 | c->num_different_channels) || | |
1647 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
1648 | c->max_interfaces)) | |
1649 | goto nla_put_failure; | |
cdc89b97 | 1650 | if (large && |
8c48b50a FF |
1651 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
1652 | c->radar_detect_widths) || | |
1653 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
1654 | c->radar_detect_regions))) | |
cdc89b97 | 1655 | goto nla_put_failure; |
0c317a02 PK |
1656 | if (c->beacon_int_min_gcd && |
1657 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, | |
1658 | c->beacon_int_min_gcd)) | |
1659 | goto nla_put_failure; | |
7527a782 JB |
1660 | |
1661 | nla_nest_end(msg, nl_combi); | |
1662 | } | |
1663 | ||
1664 | nla_nest_end(msg, nl_combis); | |
1665 | ||
1666 | return 0; | |
1667 | nla_put_failure: | |
1668 | return -ENOBUFS; | |
1669 | } | |
1670 | ||
3713b4e3 | 1671 | #ifdef CONFIG_PM |
b56cf720 JB |
1672 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
1673 | struct sk_buff *msg) | |
1674 | { | |
964dc9e2 | 1675 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
1676 | struct nlattr *nl_tcp; |
1677 | ||
1678 | if (!tcp) | |
1679 | return 0; | |
1680 | ||
ae0be8de MK |
1681 | nl_tcp = nla_nest_start_noflag(msg, |
1682 | NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
b56cf720 JB |
1683 | if (!nl_tcp) |
1684 | return -ENOBUFS; | |
1685 | ||
1686 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1687 | tcp->data_payload_max)) | |
1688 | return -ENOBUFS; | |
1689 | ||
1690 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1691 | tcp->data_payload_max)) | |
1692 | return -ENOBUFS; | |
1693 | ||
1694 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1695 | return -ENOBUFS; | |
1696 | ||
1697 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1698 | sizeof(*tcp->tok), tcp->tok)) | |
1699 | return -ENOBUFS; | |
1700 | ||
1701 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1702 | tcp->data_interval_max)) | |
1703 | return -ENOBUFS; | |
1704 | ||
1705 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1706 | tcp->wake_payload_max)) | |
1707 | return -ENOBUFS; | |
1708 | ||
1709 | nla_nest_end(msg, nl_tcp); | |
1710 | return 0; | |
1711 | } | |
1712 | ||
3713b4e3 | 1713 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1714 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1715 | bool large) |
55682965 | 1716 | { |
3713b4e3 | 1717 | struct nlattr *nl_wowlan; |
55682965 | 1718 | |
1b8ec87a | 1719 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1720 | return 0; |
55682965 | 1721 | |
ae0be8de MK |
1722 | nl_wowlan = nla_nest_start_noflag(msg, |
1723 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); | |
3713b4e3 JB |
1724 | if (!nl_wowlan) |
1725 | return -ENOBUFS; | |
9360ffd1 | 1726 | |
1b8ec87a | 1727 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1728 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1729 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1730 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1731 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1732 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1733 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1734 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1735 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1736 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1737 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1738 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1739 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1740 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1741 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1742 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1743 | return -ENOBUFS; | |
9360ffd1 | 1744 | |
1b8ec87a | 1745 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1746 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1747 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1748 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1749 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1750 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1751 | }; |
9360ffd1 | 1752 | |
3713b4e3 JB |
1753 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1754 | sizeof(pat), &pat)) | |
1755 | return -ENOBUFS; | |
1756 | } | |
9360ffd1 | 1757 | |
75453ccb LC |
1758 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
1759 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, | |
1760 | rdev->wiphy.wowlan->max_nd_match_sets)) | |
1761 | return -ENOBUFS; | |
1762 | ||
1b8ec87a | 1763 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1764 | return -ENOBUFS; |
1765 | ||
3713b4e3 | 1766 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1767 | |
3713b4e3 JB |
1768 | return 0; |
1769 | } | |
1770 | #endif | |
9360ffd1 | 1771 | |
be29b99a | 1772 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1773 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1774 | { |
1775 | struct nl80211_coalesce_rule_support rule; | |
1776 | ||
1b8ec87a | 1777 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1778 | return 0; |
1779 | ||
1b8ec87a ZG |
1780 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1781 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1782 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1783 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1784 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1785 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1786 | |
1787 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1788 | return -ENOBUFS; | |
1789 | ||
1790 | return 0; | |
1791 | } | |
1792 | ||
c4cbaf79 LC |
1793 | static int |
1794 | nl80211_send_iftype_data(struct sk_buff *msg, | |
22395217 | 1795 | const struct ieee80211_supported_band *sband, |
c4cbaf79 LC |
1796 | const struct ieee80211_sband_iftype_data *iftdata) |
1797 | { | |
1798 | const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; | |
5cd5a8a3 | 1799 | const struct ieee80211_sta_eht_cap *eht_cap = &iftdata->eht_cap; |
c4cbaf79 LC |
1800 | |
1801 | if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, | |
1802 | iftdata->types_mask)) | |
1803 | return -ENOBUFS; | |
1804 | ||
1805 | if (he_cap->has_he) { | |
1806 | if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, | |
1807 | sizeof(he_cap->he_cap_elem.mac_cap_info), | |
1808 | he_cap->he_cap_elem.mac_cap_info) || | |
1809 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, | |
1810 | sizeof(he_cap->he_cap_elem.phy_cap_info), | |
1811 | he_cap->he_cap_elem.phy_cap_info) || | |
1812 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, | |
1813 | sizeof(he_cap->he_mcs_nss_supp), | |
1814 | &he_cap->he_mcs_nss_supp) || | |
1815 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, | |
1816 | sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) | |
1817 | return -ENOBUFS; | |
1818 | } | |
1819 | ||
5cd5a8a3 IP |
1820 | if (eht_cap->has_eht && he_cap->has_he) { |
1821 | u8 mcs_nss_size, ppe_thresh_size; | |
1822 | u16 ppe_thres_hdr; | |
ea5cba26 JB |
1823 | bool is_ap; |
1824 | ||
1825 | is_ap = iftdata->types_mask & BIT(NL80211_IFTYPE_AP) || | |
1826 | iftdata->types_mask & BIT(NL80211_IFTYPE_P2P_GO); | |
5cd5a8a3 IP |
1827 | |
1828 | mcs_nss_size = | |
1829 | ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem, | |
ea5cba26 JB |
1830 | &eht_cap->eht_cap_elem, |
1831 | is_ap); | |
5cd5a8a3 IP |
1832 | |
1833 | ppe_thres_hdr = get_unaligned_le16(&eht_cap->eht_ppe_thres[0]); | |
1834 | ppe_thresh_size = | |
1835 | ieee80211_eht_ppe_size(ppe_thres_hdr, | |
1836 | eht_cap->eht_cap_elem.phy_cap_info); | |
1837 | ||
1838 | if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC, | |
1839 | sizeof(eht_cap->eht_cap_elem.mac_cap_info), | |
1840 | eht_cap->eht_cap_elem.mac_cap_info) || | |
1841 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY, | |
1842 | sizeof(eht_cap->eht_cap_elem.phy_cap_info), | |
1843 | eht_cap->eht_cap_elem.phy_cap_info) || | |
1844 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET, | |
1845 | mcs_nss_size, &eht_cap->eht_mcs_nss_supp) || | |
1846 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE, | |
1847 | ppe_thresh_size, eht_cap->eht_ppe_thres)) | |
1848 | return -ENOBUFS; | |
1849 | } | |
1850 | ||
22395217 JB |
1851 | if (sband->band == NL80211_BAND_6GHZ && |
1852 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA, | |
1853 | sizeof(iftdata->he_6ghz_capa), | |
1854 | &iftdata->he_6ghz_capa)) | |
1855 | return -ENOBUFS; | |
1856 | ||
f4f86505 JB |
1857 | if (iftdata->vendor_elems.data && iftdata->vendor_elems.len && |
1858 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_VENDOR_ELEMS, | |
1859 | iftdata->vendor_elems.len, iftdata->vendor_elems.data)) | |
1860 | return -ENOBUFS; | |
1861 | ||
c4cbaf79 LC |
1862 | return 0; |
1863 | } | |
1864 | ||
3713b4e3 | 1865 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
f8d504ca JB |
1866 | struct ieee80211_supported_band *sband, |
1867 | bool large) | |
3713b4e3 JB |
1868 | { |
1869 | struct nlattr *nl_rates, *nl_rate; | |
1870 | struct ieee80211_rate *rate; | |
1871 | int i; | |
87bbbe22 | 1872 | |
3713b4e3 JB |
1873 | /* add HT info */ |
1874 | if (sband->ht_cap.ht_supported && | |
1875 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1876 | sizeof(sband->ht_cap.mcs), | |
1877 | &sband->ht_cap.mcs) || | |
1878 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1879 | sband->ht_cap.cap) || | |
1880 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1881 | sband->ht_cap.ampdu_factor) || | |
1882 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1883 | sband->ht_cap.ampdu_density))) | |
1884 | return -ENOBUFS; | |
afe0cbf8 | 1885 | |
3713b4e3 JB |
1886 | /* add VHT info */ |
1887 | if (sband->vht_cap.vht_supported && | |
1888 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1889 | sizeof(sband->vht_cap.vht_mcs), | |
1890 | &sband->vht_cap.vht_mcs) || | |
1891 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1892 | sband->vht_cap.cap))) | |
1893 | return -ENOBUFS; | |
f59ac048 | 1894 | |
f8d504ca | 1895 | if (large && sband->n_iftype_data) { |
c4cbaf79 | 1896 | struct nlattr *nl_iftype_data = |
ae0be8de MK |
1897 | nla_nest_start_noflag(msg, |
1898 | NL80211_BAND_ATTR_IFTYPE_DATA); | |
c4cbaf79 LC |
1899 | int err; |
1900 | ||
1901 | if (!nl_iftype_data) | |
1902 | return -ENOBUFS; | |
1903 | ||
1904 | for (i = 0; i < sband->n_iftype_data; i++) { | |
1905 | struct nlattr *iftdata; | |
1906 | ||
ae0be8de | 1907 | iftdata = nla_nest_start_noflag(msg, i + 1); |
c4cbaf79 LC |
1908 | if (!iftdata) |
1909 | return -ENOBUFS; | |
1910 | ||
22395217 | 1911 | err = nl80211_send_iftype_data(msg, sband, |
c4cbaf79 LC |
1912 | &sband->iftype_data[i]); |
1913 | if (err) | |
1914 | return err; | |
1915 | ||
1916 | nla_nest_end(msg, iftdata); | |
1917 | } | |
1918 | ||
1919 | nla_nest_end(msg, nl_iftype_data); | |
1920 | } | |
1921 | ||
2a38075c | 1922 | /* add EDMG info */ |
f8d504ca | 1923 | if (large && sband->edmg_cap.channels && |
2a38075c AAL |
1924 | (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS, |
1925 | sband->edmg_cap.channels) || | |
1926 | nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG, | |
1927 | sband->edmg_cap.bw_config))) | |
1928 | ||
1929 | return -ENOBUFS; | |
1930 | ||
3713b4e3 | 1931 | /* add bitrates */ |
ae0be8de | 1932 | nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES); |
3713b4e3 JB |
1933 | if (!nl_rates) |
1934 | return -ENOBUFS; | |
ee688b00 | 1935 | |
3713b4e3 | 1936 | for (i = 0; i < sband->n_bitrates; i++) { |
ae0be8de | 1937 | nl_rate = nla_nest_start_noflag(msg, i); |
3713b4e3 JB |
1938 | if (!nl_rate) |
1939 | return -ENOBUFS; | |
ee688b00 | 1940 | |
3713b4e3 JB |
1941 | rate = &sband->bitrates[i]; |
1942 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1943 | rate->bitrate)) | |
1944 | return -ENOBUFS; | |
1945 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1946 | nla_put_flag(msg, | |
1947 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1948 | return -ENOBUFS; | |
ee688b00 | 1949 | |
3713b4e3 JB |
1950 | nla_nest_end(msg, nl_rate); |
1951 | } | |
d51626df | 1952 | |
3713b4e3 | 1953 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1954 | |
3713b4e3 JB |
1955 | return 0; |
1956 | } | |
ee688b00 | 1957 | |
3713b4e3 JB |
1958 | static int |
1959 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1960 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1961 | { | |
1962 | u16 stypes; | |
1963 | struct nlattr *nl_ftypes, *nl_ifs; | |
1964 | enum nl80211_iftype ift; | |
1965 | int i; | |
ee688b00 | 1966 | |
3713b4e3 JB |
1967 | if (!mgmt_stypes) |
1968 | return 0; | |
5dab3b8a | 1969 | |
ae0be8de | 1970 | nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES); |
3713b4e3 JB |
1971 | if (!nl_ifs) |
1972 | return -ENOBUFS; | |
e2f367f2 | 1973 | |
3713b4e3 | 1974 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
ae0be8de | 1975 | nl_ftypes = nla_nest_start_noflag(msg, ift); |
3713b4e3 JB |
1976 | if (!nl_ftypes) |
1977 | return -ENOBUFS; | |
1978 | i = 0; | |
1979 | stypes = mgmt_stypes[ift].tx; | |
1980 | while (stypes) { | |
1981 | if ((stypes & 1) && | |
1982 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1983 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1984 | return -ENOBUFS; | |
1985 | stypes >>= 1; | |
1986 | i++; | |
ee688b00 | 1987 | } |
3713b4e3 JB |
1988 | nla_nest_end(msg, nl_ftypes); |
1989 | } | |
ee688b00 | 1990 | |
3713b4e3 | 1991 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1992 | |
ae0be8de | 1993 | nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES); |
3713b4e3 JB |
1994 | if (!nl_ifs) |
1995 | return -ENOBUFS; | |
ee688b00 | 1996 | |
3713b4e3 | 1997 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
ae0be8de | 1998 | nl_ftypes = nla_nest_start_noflag(msg, ift); |
3713b4e3 JB |
1999 | if (!nl_ftypes) |
2000 | return -ENOBUFS; | |
2001 | i = 0; | |
2002 | stypes = mgmt_stypes[ift].rx; | |
2003 | while (stypes) { | |
2004 | if ((stypes & 1) && | |
2005 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
2006 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
2007 | return -ENOBUFS; | |
2008 | stypes >>= 1; | |
2009 | i++; | |
2010 | } | |
2011 | nla_nest_end(msg, nl_ftypes); | |
2012 | } | |
2013 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 2014 | |
3713b4e3 JB |
2015 | return 0; |
2016 | } | |
ee688b00 | 2017 | |
1794899e JB |
2018 | #define CMD(op, n) \ |
2019 | do { \ | |
2020 | if (rdev->ops->op) { \ | |
2021 | i++; \ | |
2022 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
2023 | goto nla_put_failure; \ | |
2024 | } \ | |
2025 | } while (0) | |
2026 | ||
2027 | static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, | |
2028 | struct sk_buff *msg) | |
2029 | { | |
2030 | int i = 0; | |
2031 | ||
2032 | /* | |
2033 | * do *NOT* add anything into this function, new things need to be | |
2034 | * advertised only to new versions of userspace that can deal with | |
2035 | * the split (and they can't possibly care about new features... | |
2036 | */ | |
2037 | CMD(add_virtual_intf, NEW_INTERFACE); | |
2038 | CMD(change_virtual_intf, SET_INTERFACE); | |
2039 | CMD(add_key, NEW_KEY); | |
2040 | CMD(start_ap, START_AP); | |
2041 | CMD(add_station, NEW_STATION); | |
2042 | CMD(add_mpath, NEW_MPATH); | |
2043 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
2044 | CMD(change_bss, SET_BSS); | |
2045 | CMD(auth, AUTHENTICATE); | |
2046 | CMD(assoc, ASSOCIATE); | |
2047 | CMD(deauth, DEAUTHENTICATE); | |
2048 | CMD(disassoc, DISASSOCIATE); | |
2049 | CMD(join_ibss, JOIN_IBSS); | |
2050 | CMD(join_mesh, JOIN_MESH); | |
2051 | CMD(set_pmksa, SET_PMKSA); | |
2052 | CMD(del_pmksa, DEL_PMKSA); | |
2053 | CMD(flush_pmksa, FLUSH_PMKSA); | |
2054 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) | |
2055 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
2056 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
2057 | CMD(mgmt_tx, FRAME); | |
2058 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
2059 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | |
2060 | i++; | |
2061 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2062 | goto nla_put_failure; | |
2063 | } | |
2064 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || | |
2065 | rdev->ops->join_mesh) { | |
2066 | i++; | |
2067 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
2068 | goto nla_put_failure; | |
2069 | } | |
1794899e JB |
2070 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
2071 | CMD(tdls_mgmt, TDLS_MGMT); | |
2072 | CMD(tdls_oper, TDLS_OPER); | |
2073 | } | |
ca986ad9 | 2074 | if (rdev->wiphy.max_sched_scan_reqs) |
1794899e JB |
2075 | CMD(sched_scan_start, START_SCHED_SCAN); |
2076 | CMD(probe_client, PROBE_CLIENT); | |
2077 | CMD(set_noack_map, SET_NOACK_MAP); | |
2078 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { | |
2079 | i++; | |
2080 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
2081 | goto nla_put_failure; | |
2082 | } | |
2083 | CMD(start_p2p_device, START_P2P_DEVICE); | |
2084 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
2085 | #ifdef CONFIG_NL80211_TESTMODE | |
2086 | CMD(testmode_cmd, TESTMODE); | |
2087 | #endif | |
2088 | ||
2089 | if (rdev->ops->connect || rdev->ops->auth) { | |
2090 | i++; | |
2091 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
2092 | goto nla_put_failure; | |
2093 | } | |
2094 | ||
2095 | if (rdev->ops->disconnect || rdev->ops->deauth) { | |
2096 | i++; | |
2097 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
2098 | goto nla_put_failure; | |
2099 | } | |
2100 | ||
2101 | return i; | |
2102 | nla_put_failure: | |
2103 | return -ENOBUFS; | |
2104 | } | |
2105 | ||
9bb7e0f2 JB |
2106 | static int |
2107 | nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, | |
2108 | struct sk_buff *msg) | |
2109 | { | |
2110 | struct nlattr *ftm; | |
2111 | ||
2112 | if (!cap->ftm.supported) | |
2113 | return 0; | |
2114 | ||
ae0be8de | 2115 | ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM); |
9bb7e0f2 JB |
2116 | if (!ftm) |
2117 | return -ENOBUFS; | |
2118 | ||
2119 | if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP)) | |
2120 | return -ENOBUFS; | |
2121 | if (cap->ftm.non_asap && | |
2122 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP)) | |
2123 | return -ENOBUFS; | |
2124 | if (cap->ftm.request_lci && | |
2125 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI)) | |
2126 | return -ENOBUFS; | |
2127 | if (cap->ftm.request_civicloc && | |
2128 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC)) | |
2129 | return -ENOBUFS; | |
2130 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES, | |
2131 | cap->ftm.preambles)) | |
2132 | return -ENOBUFS; | |
2133 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS, | |
2134 | cap->ftm.bandwidths)) | |
2135 | return -ENOBUFS; | |
2136 | if (cap->ftm.max_bursts_exponent >= 0 && | |
2137 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT, | |
2138 | cap->ftm.max_bursts_exponent)) | |
2139 | return -ENOBUFS; | |
2140 | if (cap->ftm.max_ftms_per_burst && | |
2141 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST, | |
2142 | cap->ftm.max_ftms_per_burst)) | |
2143 | return -ENOBUFS; | |
efb5520d AS |
2144 | if (cap->ftm.trigger_based && |
2145 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED)) | |
2146 | return -ENOBUFS; | |
2147 | if (cap->ftm.non_trigger_based && | |
2148 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED)) | |
2149 | return -ENOBUFS; | |
9bb7e0f2 JB |
2150 | |
2151 | nla_nest_end(msg, ftm); | |
2152 | return 0; | |
2153 | } | |
2154 | ||
2155 | static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev, | |
2156 | struct sk_buff *msg) | |
2157 | { | |
2158 | const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa; | |
2159 | struct nlattr *pmsr, *caps; | |
2160 | ||
2161 | if (!cap) | |
2162 | return 0; | |
2163 | ||
2164 | /* | |
2165 | * we don't need to clean up anything here since the caller | |
2166 | * will genlmsg_cancel() if we fail | |
2167 | */ | |
2168 | ||
ae0be8de | 2169 | pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS); |
9bb7e0f2 JB |
2170 | if (!pmsr) |
2171 | return -ENOBUFS; | |
2172 | ||
2173 | if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers)) | |
2174 | return -ENOBUFS; | |
2175 | ||
2176 | if (cap->report_ap_tsf && | |
2177 | nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF)) | |
2178 | return -ENOBUFS; | |
2179 | ||
2180 | if (cap->randomize_mac_addr && | |
2181 | nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR)) | |
2182 | return -ENOBUFS; | |
2183 | ||
ae0be8de | 2184 | caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA); |
9bb7e0f2 JB |
2185 | if (!caps) |
2186 | return -ENOBUFS; | |
2187 | ||
2188 | if (nl80211_send_pmsr_ftm_capa(cap, msg)) | |
2189 | return -ENOBUFS; | |
2190 | ||
2191 | nla_nest_end(msg, caps); | |
2192 | nla_nest_end(msg, pmsr); | |
2193 | ||
2194 | return 0; | |
2195 | } | |
2196 | ||
d6039a34 VJ |
2197 | static int |
2198 | nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev, | |
2199 | struct sk_buff *msg) | |
2200 | { | |
2201 | int i; | |
2202 | struct nlattr *nested, *nested_akms; | |
2203 | const struct wiphy_iftype_akm_suites *iftype_akms; | |
2204 | ||
2205 | if (!rdev->wiphy.num_iftype_akm_suites || | |
2206 | !rdev->wiphy.iftype_akm_suites) | |
2207 | return 0; | |
2208 | ||
2209 | nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES); | |
2210 | if (!nested) | |
2211 | return -ENOBUFS; | |
2212 | ||
2213 | for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) { | |
2214 | nested_akms = nla_nest_start(msg, i + 1); | |
2215 | if (!nested_akms) | |
2216 | return -ENOBUFS; | |
2217 | ||
2218 | iftype_akms = &rdev->wiphy.iftype_akm_suites[i]; | |
2219 | ||
2220 | if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES, | |
2221 | iftype_akms->iftypes_mask)) | |
2222 | return -ENOBUFS; | |
2223 | ||
2224 | if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES, | |
2225 | sizeof(u32) * iftype_akms->n_akm_suites, | |
2226 | iftype_akms->akm_suites)) { | |
2227 | return -ENOBUFS; | |
2228 | } | |
2229 | nla_nest_end(msg, nested_akms); | |
2230 | } | |
2231 | ||
2232 | nla_nest_end(msg, nested); | |
2233 | ||
2234 | return 0; | |
2235 | } | |
2236 | ||
3710a8a6 JB |
2237 | static int |
2238 | nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, | |
2239 | struct sk_buff *msg) | |
2240 | { | |
2241 | struct nlattr *supp; | |
2242 | ||
2243 | if (!rdev->wiphy.tid_config_support.vif && | |
2244 | !rdev->wiphy.tid_config_support.peer) | |
2245 | return 0; | |
2246 | ||
2247 | supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG); | |
2248 | if (!supp) | |
2249 | return -ENOSPC; | |
2250 | ||
2251 | if (rdev->wiphy.tid_config_support.vif && | |
2252 | nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP, | |
2253 | rdev->wiphy.tid_config_support.vif, | |
2254 | NL80211_TID_CONFIG_ATTR_PAD)) | |
2255 | goto fail; | |
2256 | ||
2257 | if (rdev->wiphy.tid_config_support.peer && | |
2258 | nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP, | |
2259 | rdev->wiphy.tid_config_support.peer, | |
2260 | NL80211_TID_CONFIG_ATTR_PAD)) | |
2261 | goto fail; | |
2262 | ||
6a21d16c T |
2263 | /* for now we just use the same value ... makes more sense */ |
2264 | if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT, | |
2265 | rdev->wiphy.tid_config_support.max_retry)) | |
2266 | goto fail; | |
2267 | if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG, | |
2268 | rdev->wiphy.tid_config_support.max_retry)) | |
2269 | goto fail; | |
2270 | ||
3710a8a6 JB |
2271 | nla_nest_end(msg, supp); |
2272 | ||
2273 | return 0; | |
2274 | fail: | |
2275 | nla_nest_cancel(msg, supp); | |
2276 | return -ENOBUFS; | |
2277 | } | |
2278 | ||
6bdb68ce CH |
2279 | static int |
2280 | nl80211_put_sar_specs(struct cfg80211_registered_device *rdev, | |
2281 | struct sk_buff *msg) | |
2282 | { | |
2283 | struct nlattr *sar_capa, *specs, *sub_freq_range; | |
2284 | u8 num_freq_ranges; | |
2285 | int i; | |
2286 | ||
2287 | if (!rdev->wiphy.sar_capa) | |
2288 | return 0; | |
2289 | ||
2290 | num_freq_ranges = rdev->wiphy.sar_capa->num_freq_ranges; | |
2291 | ||
2292 | sar_capa = nla_nest_start(msg, NL80211_ATTR_SAR_SPEC); | |
2293 | if (!sar_capa) | |
2294 | return -ENOSPC; | |
2295 | ||
2296 | if (nla_put_u32(msg, NL80211_SAR_ATTR_TYPE, rdev->wiphy.sar_capa->type)) | |
2297 | goto fail; | |
2298 | ||
2299 | specs = nla_nest_start(msg, NL80211_SAR_ATTR_SPECS); | |
2300 | if (!specs) | |
2301 | goto fail; | |
2302 | ||
2303 | /* report supported freq_ranges */ | |
2304 | for (i = 0; i < num_freq_ranges; i++) { | |
2305 | sub_freq_range = nla_nest_start(msg, i + 1); | |
2306 | if (!sub_freq_range) | |
2307 | goto fail; | |
2308 | ||
2309 | if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_START_FREQ, | |
2310 | rdev->wiphy.sar_capa->freq_ranges[i].start_freq)) | |
2311 | goto fail; | |
2312 | ||
2313 | if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_END_FREQ, | |
2314 | rdev->wiphy.sar_capa->freq_ranges[i].end_freq)) | |
2315 | goto fail; | |
2316 | ||
2317 | nla_nest_end(msg, sub_freq_range); | |
2318 | } | |
2319 | ||
2320 | nla_nest_end(msg, specs); | |
2321 | nla_nest_end(msg, sar_capa); | |
2322 | ||
2323 | return 0; | |
2324 | fail: | |
2325 | nla_nest_cancel(msg, sar_capa); | |
2326 | return -ENOBUFS; | |
2327 | } | |
2328 | ||
dc1e3cb8 JC |
2329 | static int nl80211_put_mbssid_support(struct wiphy *wiphy, struct sk_buff *msg) |
2330 | { | |
2331 | struct nlattr *config; | |
2332 | ||
2333 | if (!wiphy->mbssid_max_interfaces) | |
2334 | return 0; | |
2335 | ||
2336 | config = nla_nest_start(msg, NL80211_ATTR_MBSSID_CONFIG); | |
2337 | if (!config) | |
2338 | return -ENOBUFS; | |
2339 | ||
2340 | if (nla_put_u8(msg, NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES, | |
2341 | wiphy->mbssid_max_interfaces)) | |
2342 | goto fail; | |
2343 | ||
2344 | if (wiphy->ema_max_profile_periodicity && | |
2345 | nla_put_u8(msg, | |
2346 | NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY, | |
2347 | wiphy->ema_max_profile_periodicity)) | |
2348 | goto fail; | |
2349 | ||
2350 | nla_nest_end(msg, config); | |
2351 | return 0; | |
2352 | ||
2353 | fail: | |
2354 | nla_nest_cancel(msg, config); | |
2355 | return -ENOBUFS; | |
2356 | } | |
2357 | ||
86e8cf98 JB |
2358 | struct nl80211_dump_wiphy_state { |
2359 | s64 filter_wiphy; | |
2360 | long start; | |
019ae3a9 | 2361 | long split_start, band_start, chan_start, capa_start; |
86e8cf98 JB |
2362 | bool split; |
2363 | }; | |
2364 | ||
1b8ec87a | 2365 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 2366 | enum nl80211_commands cmd, |
3713b4e3 | 2367 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 2368 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
2369 | { |
2370 | void *hdr; | |
2371 | struct nlattr *nl_bands, *nl_band; | |
2372 | struct nlattr *nl_freqs, *nl_freq; | |
2373 | struct nlattr *nl_cmds; | |
57fbcce3 | 2374 | enum nl80211_band band; |
3713b4e3 JB |
2375 | struct ieee80211_channel *chan; |
2376 | int i; | |
2377 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 2378 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 2379 | u32 features; |
ee688b00 | 2380 | |
3bb20556 | 2381 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
2382 | if (!hdr) |
2383 | return -ENOBUFS; | |
ee688b00 | 2384 | |
86e8cf98 JB |
2385 | if (WARN_ON(!state)) |
2386 | return -EINVAL; | |
ee688b00 | 2387 | |
1b8ec87a | 2388 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 2389 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 2390 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
2391 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2392 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
2393 | goto nla_put_failure; |
2394 | ||
3bb20556 JB |
2395 | if (cmd != NL80211_CMD_NEW_WIPHY) |
2396 | goto finish; | |
2397 | ||
86e8cf98 | 2398 | switch (state->split_start) { |
3713b4e3 JB |
2399 | case 0: |
2400 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 2401 | rdev->wiphy.retry_short) || |
3713b4e3 | 2402 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 2403 | rdev->wiphy.retry_long) || |
3713b4e3 | 2404 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 2405 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 2406 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 2407 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 2408 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 2409 | rdev->wiphy.coverage_class) || |
3713b4e3 | 2410 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 2411 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 2412 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 2413 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 2414 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 2415 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 2416 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 2417 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 2418 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
f8d504ca | 2419 | rdev->wiphy.max_match_sets)) |
9360ffd1 | 2420 | goto nla_put_failure; |
3713b4e3 | 2421 | |
1b8ec87a | 2422 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 2423 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 2424 | goto nla_put_failure; |
1b8ec87a | 2425 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
2426 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
2427 | goto nla_put_failure; | |
1b8ec87a | 2428 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
2429 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
2430 | goto nla_put_failure; | |
1b8ec87a | 2431 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
2432 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
2433 | goto nla_put_failure; | |
1b8ec87a | 2434 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
2435 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
2436 | goto nla_put_failure; | |
1b8ec87a | 2437 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 2438 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 2439 | goto nla_put_failure; |
86e8cf98 JB |
2440 | state->split_start++; |
2441 | if (state->split) | |
3713b4e3 | 2442 | break; |
7b506ff6 | 2443 | fallthrough; |
3713b4e3 JB |
2444 | case 1: |
2445 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
2446 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
2447 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 2448 | goto nla_put_failure; |
4745fc09 | 2449 | |
3713b4e3 | 2450 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 2451 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 2452 | goto nla_put_failure; |
b23aa676 | 2453 | |
1b8ec87a | 2454 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 2455 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 2456 | goto nla_put_failure; |
b23aa676 | 2457 | |
3713b4e3 | 2458 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 2459 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 2460 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 2461 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 2462 | goto nla_put_failure; |
b23aa676 | 2463 | |
1b8ec87a | 2464 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 2465 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 2466 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 2467 | goto nla_put_failure; |
8fdc621d | 2468 | |
1b8ec87a ZG |
2469 | if ((rdev->wiphy.available_antennas_tx || |
2470 | rdev->wiphy.available_antennas_rx) && | |
2471 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
2472 | u32 tx_ant = 0, rx_ant = 0; |
2473 | int res; | |
7a087e74 | 2474 | |
1b8ec87a | 2475 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
2476 | if (!res) { |
2477 | if (nla_put_u32(msg, | |
2478 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
2479 | tx_ant) || | |
2480 | nla_put_u32(msg, | |
2481 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
2482 | rx_ant)) | |
2483 | goto nla_put_failure; | |
2484 | } | |
2485 | } | |
a293911d | 2486 | |
86e8cf98 JB |
2487 | state->split_start++; |
2488 | if (state->split) | |
3713b4e3 | 2489 | break; |
7b506ff6 | 2490 | fallthrough; |
3713b4e3 JB |
2491 | case 2: |
2492 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 2493 | rdev->wiphy.interface_modes)) |
3713b4e3 | 2494 | goto nla_put_failure; |
86e8cf98 JB |
2495 | state->split_start++; |
2496 | if (state->split) | |
3713b4e3 | 2497 | break; |
7b506ff6 | 2498 | fallthrough; |
3713b4e3 | 2499 | case 3: |
ae0be8de MK |
2500 | nl_bands = nla_nest_start_noflag(msg, |
2501 | NL80211_ATTR_WIPHY_BANDS); | |
3713b4e3 JB |
2502 | if (!nl_bands) |
2503 | goto nla_put_failure; | |
f7ca38df | 2504 | |
86e8cf98 | 2505 | for (band = state->band_start; |
0d059964 JB |
2506 | band < (state->split ? |
2507 | NUM_NL80211_BANDS : | |
2508 | NL80211_BAND_60GHZ + 1); | |
2509 | band++) { | |
3713b4e3 | 2510 | struct ieee80211_supported_band *sband; |
2e161f78 | 2511 | |
f8d504ca JB |
2512 | /* omit higher bands for ancient software */ |
2513 | if (band > NL80211_BAND_5GHZ && !state->split) | |
2514 | break; | |
2515 | ||
1b8ec87a | 2516 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 2517 | |
3713b4e3 JB |
2518 | if (!sband) |
2519 | continue; | |
2520 | ||
ae0be8de | 2521 | nl_band = nla_nest_start_noflag(msg, band); |
3713b4e3 | 2522 | if (!nl_band) |
2e161f78 | 2523 | goto nla_put_failure; |
3713b4e3 | 2524 | |
86e8cf98 | 2525 | switch (state->chan_start) { |
3713b4e3 | 2526 | case 0: |
f8d504ca JB |
2527 | if (nl80211_send_band_rateinfo(msg, sband, |
2528 | state->split)) | |
9360ffd1 | 2529 | goto nla_put_failure; |
86e8cf98 JB |
2530 | state->chan_start++; |
2531 | if (state->split) | |
3713b4e3 | 2532 | break; |
7b506ff6 | 2533 | fallthrough; |
3713b4e3 JB |
2534 | default: |
2535 | /* add frequencies */ | |
ae0be8de MK |
2536 | nl_freqs = nla_nest_start_noflag(msg, |
2537 | NL80211_BAND_ATTR_FREQS); | |
3713b4e3 JB |
2538 | if (!nl_freqs) |
2539 | goto nla_put_failure; | |
2540 | ||
86e8cf98 | 2541 | for (i = state->chan_start - 1; |
3713b4e3 JB |
2542 | i < sband->n_channels; |
2543 | i++) { | |
ae0be8de MK |
2544 | nl_freq = nla_nest_start_noflag(msg, |
2545 | i); | |
3713b4e3 JB |
2546 | if (!nl_freq) |
2547 | goto nla_put_failure; | |
2548 | ||
2549 | chan = &sband->channels[i]; | |
2550 | ||
86e8cf98 | 2551 | if (nl80211_msg_put_channel( |
50f32718 | 2552 | msg, &rdev->wiphy, chan, |
86e8cf98 | 2553 | state->split)) |
3713b4e3 JB |
2554 | goto nla_put_failure; |
2555 | ||
2556 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 2557 | if (state->split) |
3713b4e3 JB |
2558 | break; |
2559 | } | |
2560 | if (i < sband->n_channels) | |
86e8cf98 | 2561 | state->chan_start = i + 2; |
3713b4e3 | 2562 | else |
86e8cf98 | 2563 | state->chan_start = 0; |
3713b4e3 JB |
2564 | nla_nest_end(msg, nl_freqs); |
2565 | } | |
2566 | ||
2567 | nla_nest_end(msg, nl_band); | |
2568 | ||
86e8cf98 | 2569 | if (state->split) { |
3713b4e3 | 2570 | /* start again here */ |
86e8cf98 | 2571 | if (state->chan_start) |
3713b4e3 JB |
2572 | band--; |
2573 | break; | |
2e161f78 | 2574 | } |
2e161f78 | 2575 | } |
3713b4e3 | 2576 | nla_nest_end(msg, nl_bands); |
2e161f78 | 2577 | |
57fbcce3 | 2578 | if (band < NUM_NL80211_BANDS) |
86e8cf98 | 2579 | state->band_start = band + 1; |
3713b4e3 | 2580 | else |
86e8cf98 | 2581 | state->band_start = 0; |
74b70a4e | 2582 | |
3713b4e3 | 2583 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
2584 | if (state->band_start == 0 && state->chan_start == 0) |
2585 | state->split_start++; | |
2586 | if (state->split) | |
3713b4e3 | 2587 | break; |
7b506ff6 | 2588 | fallthrough; |
3713b4e3 | 2589 | case 4: |
ae0be8de MK |
2590 | nl_cmds = nla_nest_start_noflag(msg, |
2591 | NL80211_ATTR_SUPPORTED_COMMANDS); | |
3713b4e3 | 2592 | if (!nl_cmds) |
2e161f78 JB |
2593 | goto nla_put_failure; |
2594 | ||
1794899e JB |
2595 | i = nl80211_add_commands_unsplit(rdev, msg); |
2596 | if (i < 0) | |
2597 | goto nla_put_failure; | |
86e8cf98 | 2598 | if (state->split) { |
5de17984 AS |
2599 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
2600 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 2601 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 2602 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 2603 | CMD(set_qos_map, SET_QOS_MAP); |
723e73ac JB |
2604 | if (rdev->wiphy.features & |
2605 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | |
960d01ac | 2606 | CMD(add_tx_ts, ADD_TX_TS); |
ce0ce13a | 2607 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); |
088e8df8 | 2608 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); |
7010998c | 2609 | CMD(update_ft_ies, UPDATE_FT_IES); |
6bdb68ce CH |
2610 | if (rdev->wiphy.sar_capa) |
2611 | CMD(set_sar_specs, SET_SAR_SPECS); | |
5de17984 | 2612 | } |
3713b4e3 | 2613 | #undef CMD |
ff1b6e69 | 2614 | |
3713b4e3 | 2615 | nla_nest_end(msg, nl_cmds); |
86e8cf98 JB |
2616 | state->split_start++; |
2617 | if (state->split) | |
3713b4e3 | 2618 | break; |
7b506ff6 | 2619 | fallthrough; |
3713b4e3 | 2620 | case 5: |
1b8ec87a ZG |
2621 | if (rdev->ops->remain_on_channel && |
2622 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
2623 | nla_put_u32(msg, |
2624 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 2625 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
2626 | goto nla_put_failure; |
2627 | ||
1b8ec87a | 2628 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
2629 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
2630 | goto nla_put_failure; | |
2631 | ||
86e8cf98 JB |
2632 | state->split_start++; |
2633 | if (state->split) | |
3713b4e3 | 2634 | break; |
7b506ff6 | 2635 | fallthrough; |
3713b4e3 JB |
2636 | case 6: |
2637 | #ifdef CONFIG_PM | |
1b8ec87a | 2638 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 2639 | goto nla_put_failure; |
86e8cf98 JB |
2640 | state->split_start++; |
2641 | if (state->split) | |
3713b4e3 JB |
2642 | break; |
2643 | #else | |
86e8cf98 | 2644 | state->split_start++; |
dfb89c56 | 2645 | #endif |
7b506ff6 | 2646 | fallthrough; |
3713b4e3 JB |
2647 | case 7: |
2648 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 2649 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 2650 | goto nla_put_failure; |
ff1b6e69 | 2651 | |
1b8ec87a | 2652 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 2653 | state->split)) |
3713b4e3 | 2654 | goto nla_put_failure; |
7527a782 | 2655 | |
86e8cf98 JB |
2656 | state->split_start++; |
2657 | if (state->split) | |
3713b4e3 | 2658 | break; |
7b506ff6 | 2659 | fallthrough; |
3713b4e3 | 2660 | case 8: |
1b8ec87a | 2661 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 2662 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 2663 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 2664 | goto nla_put_failure; |
7527a782 | 2665 | |
1b8ec87a | 2666 | features = rdev->wiphy.features; |
fe1abafd JB |
2667 | /* |
2668 | * We can only add the per-channel limit information if the | |
2669 | * dump is split, otherwise it makes it too big. Therefore | |
2670 | * only advertise it in that case. | |
2671 | */ | |
86e8cf98 | 2672 | if (state->split) |
fe1abafd JB |
2673 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
2674 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 2675 | goto nla_put_failure; |
562a7480 | 2676 | |
1b8ec87a | 2677 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 2678 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
2679 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
2680 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 2681 | goto nla_put_failure; |
1f074bd8 | 2682 | |
1b8ec87a ZG |
2683 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
2684 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 2685 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 2686 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 2687 | goto nla_put_failure; |
7e7c8926 | 2688 | |
3713b4e3 JB |
2689 | /* |
2690 | * Any information below this point is only available to | |
2691 | * applications that can deal with it being split. This | |
2692 | * helps ensure that newly added capabilities don't break | |
2693 | * older tools by overrunning their buffers. | |
2694 | * | |
2695 | * We still increment split_start so that in the split | |
2696 | * case we'll continue with more data in the next round, | |
2697 | * but break unconditionally so unsplit data stops here. | |
2698 | */ | |
ab10c22b JB |
2699 | if (state->split) |
2700 | state->split_start++; | |
2701 | else | |
2702 | state->split_start = 0; | |
3713b4e3 JB |
2703 | break; |
2704 | case 9: | |
f8d504ca JB |
2705 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
2706 | goto nla_put_failure; | |
2707 | ||
2708 | if (nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, | |
2709 | rdev->wiphy.max_sched_scan_plans) || | |
2710 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, | |
2711 | rdev->wiphy.max_sched_scan_plan_interval) || | |
2712 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, | |
2713 | rdev->wiphy.max_sched_scan_plan_iterations)) | |
2714 | goto nla_put_failure; | |
2715 | ||
1b8ec87a | 2716 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 2717 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
2718 | rdev->wiphy.extended_capabilities_len, |
2719 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 2720 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
2721 | rdev->wiphy.extended_capabilities_len, |
2722 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 2723 | goto nla_put_failure; |
a50df0c4 | 2724 | |
1b8ec87a | 2725 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 2726 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
2727 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
2728 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
2729 | goto nla_put_failure; |
2730 | ||
ae6fa4d5 DK |
2731 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, |
2732 | rdev->wiphy.perm_addr)) | |
2733 | goto nla_put_failure; | |
2734 | ||
2735 | if (!is_zero_ether_addr(rdev->wiphy.addr_mask) && | |
2736 | nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN, | |
2737 | rdev->wiphy.addr_mask)) | |
2738 | goto nla_put_failure; | |
2739 | ||
2740 | if (rdev->wiphy.n_addresses > 1) { | |
2741 | void *attr; | |
2742 | ||
2743 | attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS); | |
2744 | if (!attr) | |
2745 | goto nla_put_failure; | |
2746 | ||
2747 | for (i = 0; i < rdev->wiphy.n_addresses; i++) | |
2748 | if (nla_put(msg, i + 1, ETH_ALEN, | |
2749 | rdev->wiphy.addresses[i].addr)) | |
2750 | goto nla_put_failure; | |
2751 | ||
2752 | nla_nest_end(msg, attr); | |
2753 | } | |
2754 | ||
be29b99a AK |
2755 | state->split_start++; |
2756 | break; | |
2757 | case 10: | |
1b8ec87a | 2758 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
2759 | goto nla_put_failure; |
2760 | ||
1b8ec87a | 2761 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
2762 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
2763 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
2764 | goto nla_put_failure; | |
b43504cf | 2765 | |
1b8ec87a | 2766 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 2767 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 2768 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
2769 | goto nla_put_failure; |
2770 | ||
ad7e718c JB |
2771 | state->split_start++; |
2772 | break; | |
2773 | case 11: | |
1b8ec87a | 2774 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
2775 | const struct nl80211_vendor_cmd_info *info; |
2776 | struct nlattr *nested; | |
2777 | ||
ae0be8de MK |
2778 | nested = nla_nest_start_noflag(msg, |
2779 | NL80211_ATTR_VENDOR_DATA); | |
567ffc35 JB |
2780 | if (!nested) |
2781 | goto nla_put_failure; | |
2782 | ||
1b8ec87a ZG |
2783 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
2784 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
2785 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
2786 | goto nla_put_failure; | |
2787 | } | |
2788 | nla_nest_end(msg, nested); | |
2789 | } | |
2790 | ||
1b8ec87a | 2791 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
2792 | const struct nl80211_vendor_cmd_info *info; |
2793 | struct nlattr *nested; | |
ad7e718c | 2794 | |
ae0be8de MK |
2795 | nested = nla_nest_start_noflag(msg, |
2796 | NL80211_ATTR_VENDOR_EVENTS); | |
567ffc35 | 2797 | if (!nested) |
ad7e718c | 2798 | goto nla_put_failure; |
567ffc35 | 2799 | |
1b8ec87a ZG |
2800 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
2801 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
2802 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
2803 | goto nla_put_failure; | |
2804 | } | |
2805 | nla_nest_end(msg, nested); | |
2806 | } | |
9a774c78 AO |
2807 | state->split_start++; |
2808 | break; | |
2809 | case 12: | |
2810 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
2811 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
2812 | rdev->wiphy.max_num_csa_counters)) | |
2813 | goto nla_put_failure; | |
01e0daa4 | 2814 | |
1bdd716c AN |
2815 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
2816 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
2817 | goto nla_put_failure; | |
2818 | ||
ca986ad9 AVS |
2819 | if (rdev->wiphy.max_sched_scan_reqs && |
2820 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, | |
2821 | rdev->wiphy.max_sched_scan_reqs)) | |
2822 | goto nla_put_failure; | |
2823 | ||
d75bb06b GKS |
2824 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
2825 | sizeof(rdev->wiphy.ext_features), | |
2826 | rdev->wiphy.ext_features)) | |
2827 | goto nla_put_failure; | |
2828 | ||
38de03d2 AS |
2829 | if (rdev->wiphy.bss_select_support) { |
2830 | struct nlattr *nested; | |
2831 | u32 bss_select_support = rdev->wiphy.bss_select_support; | |
2832 | ||
ae0be8de MK |
2833 | nested = nla_nest_start_noflag(msg, |
2834 | NL80211_ATTR_BSS_SELECT); | |
38de03d2 AS |
2835 | if (!nested) |
2836 | goto nla_put_failure; | |
2837 | ||
2838 | i = 0; | |
2839 | while (bss_select_support) { | |
2840 | if ((bss_select_support & 1) && | |
2841 | nla_put_flag(msg, i)) | |
2842 | goto nla_put_failure; | |
2843 | i++; | |
2844 | bss_select_support >>= 1; | |
2845 | } | |
2846 | nla_nest_end(msg, nested); | |
2847 | } | |
2848 | ||
019ae3a9 KV |
2849 | state->split_start++; |
2850 | break; | |
2851 | case 13: | |
2852 | if (rdev->wiphy.num_iftype_ext_capab && | |
2853 | rdev->wiphy.iftype_ext_capab) { | |
2854 | struct nlattr *nested_ext_capab, *nested; | |
2855 | ||
ae0be8de MK |
2856 | nested = nla_nest_start_noflag(msg, |
2857 | NL80211_ATTR_IFTYPE_EXT_CAPA); | |
019ae3a9 KV |
2858 | if (!nested) |
2859 | goto nla_put_failure; | |
2860 | ||
2861 | for (i = state->capa_start; | |
2862 | i < rdev->wiphy.num_iftype_ext_capab; i++) { | |
2863 | const struct wiphy_iftype_ext_capab *capab; | |
2864 | ||
2865 | capab = &rdev->wiphy.iftype_ext_capab[i]; | |
2866 | ||
ae0be8de MK |
2867 | nested_ext_capab = nla_nest_start_noflag(msg, |
2868 | i); | |
019ae3a9 KV |
2869 | if (!nested_ext_capab || |
2870 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, | |
2871 | capab->iftype) || | |
2872 | nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
2873 | capab->extended_capabilities_len, | |
2874 | capab->extended_capabilities) || | |
2875 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
2876 | capab->extended_capabilities_len, | |
2877 | capab->extended_capabilities_mask)) | |
2878 | goto nla_put_failure; | |
2879 | ||
4e9c3af3 JB |
2880 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO && |
2881 | (nla_put_u16(msg, | |
2882 | NL80211_ATTR_EML_CAPABILITY, | |
2883 | capab->eml_capabilities) || | |
2884 | nla_put_u16(msg, | |
2885 | NL80211_ATTR_MLD_CAPA_AND_OPS, | |
2886 | capab->mld_capa_and_ops))) | |
2887 | goto nla_put_failure; | |
2888 | ||
019ae3a9 KV |
2889 | nla_nest_end(msg, nested_ext_capab); |
2890 | if (state->split) | |
2891 | break; | |
2892 | } | |
2893 | nla_nest_end(msg, nested); | |
2894 | if (i < rdev->wiphy.num_iftype_ext_capab) { | |
2895 | state->capa_start = i + 1; | |
2896 | break; | |
2897 | } | |
2898 | } | |
2899 | ||
8585989d LC |
2900 | if (nla_put_u32(msg, NL80211_ATTR_BANDS, |
2901 | rdev->wiphy.nan_supported_bands)) | |
2902 | goto nla_put_failure; | |
2903 | ||
52539ca8 THJ |
2904 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
2905 | NL80211_EXT_FEATURE_TXQS)) { | |
2906 | struct cfg80211_txq_stats txqstats = {}; | |
2907 | int res; | |
2908 | ||
2909 | res = rdev_get_txq_stats(rdev, NULL, &txqstats); | |
2910 | if (!res && | |
2911 | !nl80211_put_txq_stats(msg, &txqstats, | |
2912 | NL80211_ATTR_TXQ_STATS)) | |
2913 | goto nla_put_failure; | |
2914 | ||
2915 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, | |
2916 | rdev->wiphy.txq_limit)) | |
2917 | goto nla_put_failure; | |
2918 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, | |
2919 | rdev->wiphy.txq_memory_limit)) | |
2920 | goto nla_put_failure; | |
2921 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, | |
2922 | rdev->wiphy.txq_quantum)) | |
2923 | goto nla_put_failure; | |
2924 | } | |
2925 | ||
9bb7e0f2 JB |
2926 | state->split_start++; |
2927 | break; | |
2928 | case 14: | |
2929 | if (nl80211_send_pmsr_capa(rdev, msg)) | |
2930 | goto nla_put_failure; | |
2931 | ||
ab4dfa20 VJ |
2932 | state->split_start++; |
2933 | break; | |
2934 | case 15: | |
2935 | if (rdev->wiphy.akm_suites && | |
2936 | nla_put(msg, NL80211_ATTR_AKM_SUITES, | |
2937 | sizeof(u32) * rdev->wiphy.n_akm_suites, | |
2938 | rdev->wiphy.akm_suites)) | |
2939 | goto nla_put_failure; | |
2940 | ||
d6039a34 VJ |
2941 | if (nl80211_put_iftype_akm_suites(rdev, msg)) |
2942 | goto nla_put_failure; | |
2943 | ||
3710a8a6 JB |
2944 | if (nl80211_put_tid_config_support(rdev, msg)) |
2945 | goto nla_put_failure; | |
6bdb68ce CH |
2946 | state->split_start++; |
2947 | break; | |
2948 | case 16: | |
2949 | if (nl80211_put_sar_specs(rdev, msg)) | |
2950 | goto nla_put_failure; | |
3710a8a6 | 2951 | |
dc1e3cb8 JC |
2952 | if (nl80211_put_mbssid_support(&rdev->wiphy, msg)) |
2953 | goto nla_put_failure; | |
2954 | ||
ecad3b0b VJ |
2955 | if (nla_put_u16(msg, NL80211_ATTR_MAX_NUM_AKM_SUITES, |
2956 | rdev->wiphy.max_num_akm_suites)) | |
2957 | goto nla_put_failure; | |
2958 | ||
fa2ca639 JB |
2959 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO) |
2960 | nla_put_flag(msg, NL80211_ATTR_MLO_SUPPORT); | |
2961 | ||
3713b4e3 | 2962 | /* done */ |
86e8cf98 | 2963 | state->split_start = 0; |
3713b4e3 JB |
2964 | break; |
2965 | } | |
3bb20556 | 2966 | finish: |
053c095a JB |
2967 | genlmsg_end(msg, hdr); |
2968 | return 0; | |
55682965 JB |
2969 | |
2970 | nla_put_failure: | |
bc3ed28c TG |
2971 | genlmsg_cancel(msg, hdr); |
2972 | return -EMSGSIZE; | |
55682965 JB |
2973 | } |
2974 | ||
86e8cf98 JB |
2975 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
2976 | struct netlink_callback *cb, | |
2977 | struct nl80211_dump_wiphy_state *state) | |
2978 | { | |
50508d94 JB |
2979 | struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
2980 | int ret; | |
2981 | ||
2982 | if (!tb) | |
2983 | return -ENOMEM; | |
2984 | ||
2985 | ret = nlmsg_parse_deprecated(cb->nlh, | |
2986 | GENL_HDRLEN + nl80211_fam.hdrsize, | |
2987 | tb, nl80211_fam.maxattr, | |
2988 | nl80211_policy, NULL); | |
86e8cf98 | 2989 | /* ignore parse errors for backward compatibility */ |
50508d94 JB |
2990 | if (ret) { |
2991 | ret = 0; | |
2992 | goto out; | |
2993 | } | |
86e8cf98 JB |
2994 | |
2995 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
2996 | if (tb[NL80211_ATTR_WIPHY]) | |
2997 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
2998 | if (tb[NL80211_ATTR_WDEV]) | |
2999 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
3000 | if (tb[NL80211_ATTR_IFINDEX]) { | |
3001 | struct net_device *netdev; | |
3002 | struct cfg80211_registered_device *rdev; | |
3003 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
3004 | ||
7f2b8562 | 3005 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
50508d94 JB |
3006 | if (!netdev) { |
3007 | ret = -ENODEV; | |
3008 | goto out; | |
3009 | } | |
86e8cf98 | 3010 | if (netdev->ieee80211_ptr) { |
f26cbf40 | 3011 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
3012 | netdev->ieee80211_ptr->wiphy); |
3013 | state->filter_wiphy = rdev->wiphy_idx; | |
3014 | } | |
86e8cf98 JB |
3015 | } |
3016 | ||
50508d94 JB |
3017 | ret = 0; |
3018 | out: | |
3019 | kfree(tb); | |
3020 | return ret; | |
86e8cf98 JB |
3021 | } |
3022 | ||
55682965 JB |
3023 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
3024 | { | |
645e77de | 3025 | int idx = 0, ret; |
86e8cf98 | 3026 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 3027 | struct cfg80211_registered_device *rdev; |
3a5a423b | 3028 | |
5fe231e8 | 3029 | rtnl_lock(); |
86e8cf98 JB |
3030 | if (!state) { |
3031 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
3032 | if (!state) { |
3033 | rtnl_unlock(); | |
86e8cf98 | 3034 | return -ENOMEM; |
3713b4e3 | 3035 | } |
86e8cf98 JB |
3036 | state->filter_wiphy = -1; |
3037 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
3038 | if (ret) { | |
3039 | kfree(state); | |
3040 | rtnl_unlock(); | |
3041 | return ret; | |
3713b4e3 | 3042 | } |
86e8cf98 | 3043 | cb->args[0] = (long)state; |
3713b4e3 JB |
3044 | } |
3045 | ||
1b8ec87a ZG |
3046 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
3047 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 3048 | continue; |
86e8cf98 | 3049 | if (++idx <= state->start) |
55682965 | 3050 | continue; |
86e8cf98 | 3051 | if (state->filter_wiphy != -1 && |
1b8ec87a | 3052 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
3053 | continue; |
3054 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
3055 | do { | |
3bb20556 JB |
3056 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
3057 | skb, | |
3713b4e3 JB |
3058 | NETLINK_CB(cb->skb).portid, |
3059 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 3060 | NLM_F_MULTI, state); |
3713b4e3 JB |
3061 | if (ret < 0) { |
3062 | /* | |
3063 | * If sending the wiphy data didn't fit (ENOBUFS | |
3064 | * or EMSGSIZE returned), this SKB is still | |
3065 | * empty (so it's not too big because another | |
3066 | * wiphy dataset is already in the skb) and | |
3067 | * we've not tried to adjust the dump allocation | |
3068 | * yet ... then adjust the alloc size to be | |
3069 | * bigger, and return 1 but with the empty skb. | |
3070 | * This results in an empty message being RX'ed | |
3071 | * in userspace, but that is ignored. | |
3072 | * | |
3073 | * We can then retry with the larger buffer. | |
3074 | */ | |
3075 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 3076 | !skb->len && !state->split && |
3713b4e3 JB |
3077 | cb->min_dump_alloc < 4096) { |
3078 | cb->min_dump_alloc = 4096; | |
f12cb289 | 3079 | state->split_start = 0; |
d98cae64 | 3080 | rtnl_unlock(); |
3713b4e3 JB |
3081 | return 1; |
3082 | } | |
3083 | idx--; | |
3084 | break; | |
645e77de | 3085 | } |
86e8cf98 | 3086 | } while (state->split_start > 0); |
3713b4e3 | 3087 | break; |
55682965 | 3088 | } |
5fe231e8 | 3089 | rtnl_unlock(); |
55682965 | 3090 | |
86e8cf98 | 3091 | state->start = idx; |
55682965 JB |
3092 | |
3093 | return skb->len; | |
3094 | } | |
3095 | ||
86e8cf98 JB |
3096 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
3097 | { | |
3098 | kfree((void *)cb->args[0]); | |
3099 | return 0; | |
3100 | } | |
3101 | ||
55682965 JB |
3102 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
3103 | { | |
3104 | struct sk_buff *msg; | |
1b8ec87a | 3105 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 3106 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 3107 | |
645e77de | 3108 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 3109 | if (!msg) |
4c476991 | 3110 | return -ENOMEM; |
55682965 | 3111 | |
3bb20556 JB |
3112 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
3113 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 3114 | &state) < 0) { |
4c476991 JB |
3115 | nlmsg_free(msg); |
3116 | return -ENOBUFS; | |
3117 | } | |
55682965 | 3118 | |
134e6375 | 3119 | return genlmsg_reply(msg, info); |
55682965 JB |
3120 | } |
3121 | ||
31888487 JM |
3122 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
3123 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
3124 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
3125 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
3126 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
3127 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
3128 | }; | |
3129 | ||
3130 | static int parse_txq_params(struct nlattr *tb[], | |
3131 | struct ieee80211_txq_params *txq_params) | |
3132 | { | |
259d8c1e DW |
3133 | u8 ac; |
3134 | ||
a3304b0a | 3135 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
3136 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
3137 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
3138 | return -EINVAL; | |
3139 | ||
259d8c1e | 3140 | ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
3141 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
3142 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
3143 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
3144 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
3145 | ||
259d8c1e | 3146 | if (ac >= NL80211_NUM_ACS) |
a3304b0a | 3147 | return -EINVAL; |
259d8c1e | 3148 | txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); |
31888487 JM |
3149 | return 0; |
3150 | } | |
3151 | ||
f444de05 JB |
3152 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
3153 | { | |
3154 | /* | |
e7e0517c JB |
3155 | * You can only set the channel explicitly for some interfaces, |
3156 | * most have their channel managed via their respective | |
cc1d2806 JB |
3157 | * "establish a connection" command (connect, join, ...) |
3158 | * | |
3159 | * For AP/GO and mesh mode, the channel can be set with the | |
3160 | * channel userspace API, but is only stored and passed to the | |
3161 | * low-level driver when the AP starts or the mesh is joined. | |
3162 | * This is for backward compatibility, userspace can also give | |
3163 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
3164 | * |
3165 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
3166 | * whatever else is going on, so they have their own special |
3167 | * operation to set the monitor channel if possible. | |
f444de05 JB |
3168 | */ |
3169 | return !wdev || | |
3170 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 3171 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
3172 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
3173 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
3174 | } |
3175 | ||
9bb7e0f2 JB |
3176 | int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
3177 | struct genl_info *info, | |
3178 | struct cfg80211_chan_def *chandef) | |
683b6d3b | 3179 | { |
49f9cf0e JB |
3180 | struct netlink_ext_ack *extack = info->extack; |
3181 | struct nlattr **attrs = info->attrs; | |
dbeca2ea | 3182 | u32 control_freq; |
683b6d3b | 3183 | |
49f9cf0e | 3184 | if (!attrs[NL80211_ATTR_WIPHY_FREQ]) |
683b6d3b JB |
3185 | return -EINVAL; |
3186 | ||
942ba88b TP |
3187 | control_freq = MHZ_TO_KHZ( |
3188 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
3189 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) | |
3190 | control_freq += | |
3191 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); | |
683b6d3b | 3192 | |
f43e5210 | 3193 | memset(chandef, 0, sizeof(*chandef)); |
942ba88b | 3194 | chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq); |
3d9d1d66 | 3195 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
942ba88b TP |
3196 | chandef->center_freq1 = KHZ_TO_MHZ(control_freq); |
3197 | chandef->freq1_offset = control_freq % 1000; | |
3d9d1d66 | 3198 | chandef->center_freq2 = 0; |
683b6d3b JB |
3199 | |
3200 | /* Primary channel not allowed */ | |
49f9cf0e JB |
3201 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) { |
3202 | NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], | |
3203 | "Channel is disabled"); | |
683b6d3b | 3204 | return -EINVAL; |
49f9cf0e | 3205 | } |
683b6d3b | 3206 | |
49f9cf0e | 3207 | if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
3d9d1d66 JB |
3208 | enum nl80211_channel_type chantype; |
3209 | ||
49f9cf0e | 3210 | chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
3d9d1d66 JB |
3211 | |
3212 | switch (chantype) { | |
3213 | case NL80211_CHAN_NO_HT: | |
3214 | case NL80211_CHAN_HT20: | |
3215 | case NL80211_CHAN_HT40PLUS: | |
3216 | case NL80211_CHAN_HT40MINUS: | |
3217 | cfg80211_chandef_create(chandef, chandef->chan, | |
3218 | chantype); | |
ffa4629e | 3219 | /* user input for center_freq is incorrect */ |
49f9cf0e JB |
3220 | if (attrs[NL80211_ATTR_CENTER_FREQ1] && |
3221 | chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) { | |
3222 | NL_SET_ERR_MSG_ATTR(extack, | |
3223 | attrs[NL80211_ATTR_CENTER_FREQ1], | |
3224 | "bad center frequency 1"); | |
ffa4629e | 3225 | return -EINVAL; |
49f9cf0e | 3226 | } |
ffa4629e | 3227 | /* center_freq2 must be zero */ |
49f9cf0e JB |
3228 | if (attrs[NL80211_ATTR_CENTER_FREQ2] && |
3229 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) { | |
3230 | NL_SET_ERR_MSG_ATTR(extack, | |
3231 | attrs[NL80211_ATTR_CENTER_FREQ2], | |
3232 | "center frequency 2 can't be used"); | |
ffa4629e | 3233 | return -EINVAL; |
49f9cf0e | 3234 | } |
3d9d1d66 JB |
3235 | break; |
3236 | default: | |
49f9cf0e JB |
3237 | NL_SET_ERR_MSG_ATTR(extack, |
3238 | attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE], | |
3239 | "invalid channel type"); | |
3d9d1d66 JB |
3240 | return -EINVAL; |
3241 | } | |
49f9cf0e | 3242 | } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
3d9d1d66 | 3243 | chandef->width = |
49f9cf0e | 3244 | nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
5d087aa7 KF |
3245 | if (chandef->chan->band == NL80211_BAND_S1GHZ) { |
3246 | /* User input error for channel width doesn't match channel */ | |
3247 | if (chandef->width != ieee80211_s1g_channel_width(chandef->chan)) { | |
3248 | NL_SET_ERR_MSG_ATTR(extack, | |
3249 | attrs[NL80211_ATTR_CHANNEL_WIDTH], | |
3250 | "bad channel width"); | |
3251 | return -EINVAL; | |
3252 | } | |
3253 | } | |
942ba88b | 3254 | if (attrs[NL80211_ATTR_CENTER_FREQ1]) { |
3d9d1d66 | 3255 | chandef->center_freq1 = |
49f9cf0e | 3256 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]); |
942ba88b TP |
3257 | if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]) |
3258 | chandef->freq1_offset = nla_get_u32( | |
3259 | attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]); | |
3260 | else | |
3261 | chandef->freq1_offset = 0; | |
3262 | } | |
49f9cf0e | 3263 | if (attrs[NL80211_ATTR_CENTER_FREQ2]) |
3d9d1d66 | 3264 | chandef->center_freq2 = |
49f9cf0e | 3265 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]); |
3d9d1d66 JB |
3266 | } |
3267 | ||
2a38075c AAL |
3268 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { |
3269 | chandef->edmg.channels = | |
3270 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); | |
3271 | ||
3272 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) | |
3273 | chandef->edmg.bw_config = | |
3274 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); | |
3275 | } else { | |
3276 | chandef->edmg.bw_config = 0; | |
3277 | chandef->edmg.channels = 0; | |
3278 | } | |
3279 | ||
49f9cf0e JB |
3280 | if (!cfg80211_chandef_valid(chandef)) { |
3281 | NL_SET_ERR_MSG(extack, "invalid channel definition"); | |
3d9d1d66 | 3282 | return -EINVAL; |
49f9cf0e | 3283 | } |
3d9d1d66 | 3284 | |
9f5e8f6e | 3285 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
49f9cf0e JB |
3286 | IEEE80211_CHAN_DISABLED)) { |
3287 | NL_SET_ERR_MSG(extack, "(extension) channel is disabled"); | |
3d9d1d66 | 3288 | return -EINVAL; |
49f9cf0e | 3289 | } |
3d9d1d66 | 3290 | |
2f301ab2 SW |
3291 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
3292 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
49f9cf0e JB |
3293 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) { |
3294 | NL_SET_ERR_MSG(extack, "5/10 MHz not supported"); | |
2f301ab2 | 3295 | return -EINVAL; |
49f9cf0e | 3296 | } |
2f301ab2 | 3297 | |
683b6d3b JB |
3298 | return 0; |
3299 | } | |
3300 | ||
f444de05 | 3301 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 3302 | struct net_device *dev, |
7b0a0e3c JB |
3303 | struct genl_info *info, |
3304 | int _link_id) | |
f444de05 | 3305 | { |
683b6d3b | 3306 | struct cfg80211_chan_def chandef; |
f444de05 | 3307 | int result; |
e8c9bd5b | 3308 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 3309 | struct wireless_dev *wdev = NULL; |
7b0a0e3c | 3310 | int link_id = _link_id; |
e8c9bd5b | 3311 | |
e16821bc JM |
3312 | if (dev) |
3313 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
3314 | if (!nl80211_can_set_dev_channel(wdev)) |
3315 | return -EOPNOTSUPP; | |
e16821bc JM |
3316 | if (wdev) |
3317 | iftype = wdev->iftype; | |
f444de05 | 3318 | |
7b0a0e3c JB |
3319 | if (link_id < 0) { |
3320 | if (wdev && wdev->valid_links) | |
3321 | return -EINVAL; | |
3322 | link_id = 0; | |
3323 | } | |
3324 | ||
683b6d3b JB |
3325 | result = nl80211_parse_chandef(rdev, info, &chandef); |
3326 | if (result) | |
3327 | return result; | |
f444de05 | 3328 | |
e8c9bd5b | 3329 | switch (iftype) { |
aa430da4 JB |
3330 | case NL80211_IFTYPE_AP: |
3331 | case NL80211_IFTYPE_P2P_GO: | |
923b352f | 3332 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
7b0a0e3c JB |
3333 | iftype)) |
3334 | return -EINVAL; | |
3335 | if (wdev->links[link_id].ap.beacon_interval) { | |
3336 | struct ieee80211_channel *cur_chan; | |
3337 | ||
e16821bc JM |
3338 | if (!dev || !rdev->ops->set_ap_chanwidth || |
3339 | !(rdev->wiphy.features & | |
7b0a0e3c JB |
3340 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) |
3341 | return -EBUSY; | |
e16821bc JM |
3342 | |
3343 | /* Only allow dynamic channel width changes */ | |
7b0a0e3c JB |
3344 | cur_chan = wdev->links[link_id].ap.chandef.chan; |
3345 | if (chandef.chan != cur_chan) | |
3346 | return -EBUSY; | |
3347 | ||
3348 | result = rdev_set_ap_chanwidth(rdev, dev, link_id, | |
3349 | &chandef); | |
e16821bc | 3350 | if (result) |
7b0a0e3c JB |
3351 | return result; |
3352 | wdev->links[link_id].ap.chandef = chandef; | |
3353 | } else { | |
3354 | wdev->u.ap.preset_chandef = chandef; | |
e16821bc | 3355 | } |
7b0a0e3c | 3356 | return 0; |
cc1d2806 | 3357 | case NL80211_IFTYPE_MESH_POINT: |
7b0a0e3c | 3358 | return cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
e8c9bd5b | 3359 | case NL80211_IFTYPE_MONITOR: |
7b0a0e3c | 3360 | return cfg80211_set_monitor_channel(rdev, &chandef); |
aa430da4 | 3361 | default: |
7b0a0e3c | 3362 | break; |
f444de05 | 3363 | } |
f444de05 | 3364 | |
7b0a0e3c | 3365 | return -EINVAL; |
f444de05 JB |
3366 | } |
3367 | ||
3368 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
3369 | { | |
4c476991 | 3370 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7b0a0e3c | 3371 | int link_id = nl80211_link_id_or_invalid(info->attrs); |
4c476991 | 3372 | struct net_device *netdev = info->user_ptr[1]; |
4e2f3d67 JB |
3373 | int ret; |
3374 | ||
3375 | wdev_lock(netdev->ieee80211_ptr); | |
3376 | ret = __nl80211_set_channel(rdev, netdev, info, link_id); | |
3377 | wdev_unlock(netdev->ieee80211_ptr); | |
f444de05 | 3378 | |
4e2f3d67 | 3379 | return ret; |
f444de05 JB |
3380 | } |
3381 | ||
55682965 JB |
3382 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
3383 | { | |
a05829a7 | 3384 | struct cfg80211_registered_device *rdev = NULL; |
f444de05 JB |
3385 | struct net_device *netdev = NULL; |
3386 | struct wireless_dev *wdev; | |
a1e567c8 | 3387 | int result = 0, rem_txq_params = 0; |
31888487 | 3388 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
3389 | u32 changed; |
3390 | u8 retry_short = 0, retry_long = 0; | |
3391 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 3392 | u8 coverage_class = 0; |
52539ca8 | 3393 | u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; |
55682965 | 3394 | |
a05829a7 | 3395 | rtnl_lock(); |
f444de05 JB |
3396 | /* |
3397 | * Try to find the wiphy and netdev. Normally this | |
3398 | * function shouldn't need the netdev, but this is | |
3399 | * done for backward compatibility -- previously | |
3400 | * setting the channel was done per wiphy, but now | |
3401 | * it is per netdev. Previous userland like hostapd | |
3402 | * also passed a netdev to set_wiphy, so that it is | |
3403 | * possible to let that go to the right netdev! | |
3404 | */ | |
4bbf4d56 | 3405 | |
f444de05 JB |
3406 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
3407 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
3408 | ||
7f2b8562 | 3409 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 3410 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 3411 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 3412 | else |
f444de05 | 3413 | netdev = NULL; |
4bbf4d56 JB |
3414 | } |
3415 | ||
f444de05 | 3416 | if (!netdev) { |
878d9ec7 JB |
3417 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
3418 | info->attrs); | |
a05829a7 JB |
3419 | if (IS_ERR(rdev)) { |
3420 | rtnl_unlock(); | |
4c476991 | 3421 | return PTR_ERR(rdev); |
a05829a7 | 3422 | } |
f444de05 JB |
3423 | wdev = NULL; |
3424 | netdev = NULL; | |
3425 | result = 0; | |
71fe96bf | 3426 | } else |
f444de05 | 3427 | wdev = netdev->ieee80211_ptr; |
f444de05 | 3428 | |
a05829a7 | 3429 | wiphy_lock(&rdev->wiphy); |
a05829a7 | 3430 | |
f444de05 JB |
3431 | /* |
3432 | * end workaround code, by now the rdev is available | |
3433 | * and locked, and wdev may or may not be NULL. | |
3434 | */ | |
4bbf4d56 JB |
3435 | |
3436 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
3437 | result = cfg80211_dev_rename( |
3438 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
0391a45c | 3439 | rtnl_unlock(); |
4bbf4d56 | 3440 | |
4bbf4d56 | 3441 | if (result) |
a05829a7 | 3442 | goto out; |
31888487 JM |
3443 | |
3444 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
3445 | struct ieee80211_txq_params txq_params; | |
3446 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
3447 | ||
a05829a7 JB |
3448 | if (!rdev->ops->set_txq_params) { |
3449 | result = -EOPNOTSUPP; | |
3450 | goto out; | |
3451 | } | |
31888487 | 3452 | |
a05829a7 JB |
3453 | if (!netdev) { |
3454 | result = -EINVAL; | |
3455 | goto out; | |
3456 | } | |
f70f01c2 | 3457 | |
133a3ff2 | 3458 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
a05829a7 JB |
3459 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
3460 | result = -EINVAL; | |
3461 | goto out; | |
3462 | } | |
133a3ff2 | 3463 | |
a05829a7 JB |
3464 | if (!netif_running(netdev)) { |
3465 | result = -ENETDOWN; | |
3466 | goto out; | |
3467 | } | |
2b5f8b0b | 3468 | |
31888487 JM |
3469 | nla_for_each_nested(nl_txq_params, |
3470 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
3471 | rem_txq_params) { | |
8cb08174 JB |
3472 | result = nla_parse_nested_deprecated(tb, |
3473 | NL80211_TXQ_ATTR_MAX, | |
3474 | nl_txq_params, | |
3475 | txq_params_policy, | |
3476 | info->extack); | |
ae811e21 | 3477 | if (result) |
a05829a7 | 3478 | goto out; |
31888487 JM |
3479 | result = parse_txq_params(tb, &txq_params); |
3480 | if (result) | |
a05829a7 | 3481 | goto out; |
31888487 | 3482 | |
9d2bb84d ST |
3483 | txq_params.link_id = |
3484 | nl80211_link_id_or_invalid(info->attrs); | |
3485 | ||
3486 | wdev_lock(netdev->ieee80211_ptr); | |
3487 | if (txq_params.link_id >= 0 && | |
3488 | !(netdev->ieee80211_ptr->valid_links & | |
3489 | BIT(txq_params.link_id))) | |
3490 | result = -ENOLINK; | |
3491 | else if (txq_params.link_id >= 0 && | |
3492 | !netdev->ieee80211_ptr->valid_links) | |
3493 | result = -EINVAL; | |
3494 | else | |
3495 | result = rdev_set_txq_params(rdev, netdev, | |
3496 | &txq_params); | |
3497 | wdev_unlock(netdev->ieee80211_ptr); | |
31888487 | 3498 | if (result) |
a05829a7 | 3499 | goto out; |
31888487 JM |
3500 | } |
3501 | } | |
55682965 | 3502 | |
72bdcf34 | 3503 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
69c3f2d3 IP |
3504 | int link_id = nl80211_link_id_or_invalid(info->attrs); |
3505 | ||
4e2f3d67 JB |
3506 | if (wdev) { |
3507 | wdev_lock(wdev); | |
3508 | result = __nl80211_set_channel( | |
3509 | rdev, | |
3510 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
69c3f2d3 | 3511 | info, link_id); |
4e2f3d67 JB |
3512 | wdev_unlock(wdev); |
3513 | } else { | |
69c3f2d3 | 3514 | result = __nl80211_set_channel(rdev, netdev, info, link_id); |
4e2f3d67 | 3515 | } |
69c3f2d3 | 3516 | |
72bdcf34 | 3517 | if (result) |
a05829a7 | 3518 | goto out; |
72bdcf34 JM |
3519 | } |
3520 | ||
98d2ff8b | 3521 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 3522 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
3523 | enum nl80211_tx_power_setting type; |
3524 | int idx, mbm = 0; | |
3525 | ||
c8442118 JB |
3526 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
3527 | txp_wdev = NULL; | |
3528 | ||
a05829a7 JB |
3529 | if (!rdev->ops->set_tx_power) { |
3530 | result = -EOPNOTSUPP; | |
3531 | goto out; | |
3532 | } | |
98d2ff8b JO |
3533 | |
3534 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
3535 | type = nla_get_u32(info->attrs[idx]); | |
3536 | ||
3537 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
a05829a7 JB |
3538 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
3539 | result = -EINVAL; | |
3540 | goto out; | |
3541 | } | |
98d2ff8b JO |
3542 | |
3543 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
3544 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
3545 | mbm = nla_get_u32(info->attrs[idx]); | |
3546 | } | |
3547 | ||
c8442118 | 3548 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 3549 | if (result) |
a05829a7 | 3550 | goto out; |
98d2ff8b JO |
3551 | } |
3552 | ||
afe0cbf8 BR |
3553 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
3554 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
3555 | u32 tx_ant, rx_ant; | |
7a087e74 | 3556 | |
7f531e03 BR |
3557 | if ((!rdev->wiphy.available_antennas_tx && |
3558 | !rdev->wiphy.available_antennas_rx) || | |
a05829a7 JB |
3559 | !rdev->ops->set_antenna) { |
3560 | result = -EOPNOTSUPP; | |
3561 | goto out; | |
3562 | } | |
afe0cbf8 BR |
3563 | |
3564 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
3565 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
3566 | ||
a7ffac95 | 3567 | /* reject antenna configurations which don't match the |
7f531e03 BR |
3568 | * available antenna masks, except for the "all" mask */ |
3569 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
a05829a7 JB |
3570 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
3571 | result = -EINVAL; | |
3572 | goto out; | |
3573 | } | |
a7ffac95 | 3574 | |
7f531e03 BR |
3575 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
3576 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 3577 | |
e35e4d28 | 3578 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 3579 | if (result) |
a05829a7 | 3580 | goto out; |
afe0cbf8 BR |
3581 | } |
3582 | ||
b9a5f8ca JM |
3583 | changed = 0; |
3584 | ||
3585 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
3586 | retry_short = nla_get_u8( | |
3587 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 | 3588 | |
b9a5f8ca JM |
3589 | changed |= WIPHY_PARAM_RETRY_SHORT; |
3590 | } | |
3591 | ||
3592 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
3593 | retry_long = nla_get_u8( | |
3594 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 | 3595 | |
b9a5f8ca JM |
3596 | changed |= WIPHY_PARAM_RETRY_LONG; |
3597 | } | |
3598 | ||
3599 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
3600 | frag_threshold = nla_get_u32( | |
3601 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
a05829a7 JB |
3602 | if (frag_threshold < 256) { |
3603 | result = -EINVAL; | |
3604 | goto out; | |
3605 | } | |
7f2b8562 | 3606 | |
b9a5f8ca JM |
3607 | if (frag_threshold != (u32) -1) { |
3608 | /* | |
3609 | * Fragments (apart from the last one) are required to | |
3610 | * have even length. Make the fragmentation code | |
3611 | * simpler by stripping LSB should someone try to use | |
3612 | * odd threshold value. | |
3613 | */ | |
3614 | frag_threshold &= ~0x1; | |
3615 | } | |
3616 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
3617 | } | |
3618 | ||
3619 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
3620 | rts_threshold = nla_get_u32( | |
3621 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
3622 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
3623 | } | |
3624 | ||
81077e82 | 3625 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
a05829a7 JB |
3626 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
3627 | result = -EINVAL; | |
3628 | goto out; | |
3629 | } | |
3057dbfd | 3630 | |
81077e82 LT |
3631 | coverage_class = nla_get_u8( |
3632 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
3633 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
3634 | } | |
3635 | ||
3057dbfd | 3636 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
a05829a7 JB |
3637 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) { |
3638 | result = -EOPNOTSUPP; | |
3639 | goto out; | |
3640 | } | |
3057dbfd LB |
3641 | |
3642 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
3643 | } |
3644 | ||
52539ca8 THJ |
3645 | if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { |
3646 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
a05829a7 JB |
3647 | NL80211_EXT_FEATURE_TXQS)) { |
3648 | result = -EOPNOTSUPP; | |
3649 | goto out; | |
3650 | } | |
52539ca8 THJ |
3651 | txq_limit = nla_get_u32( |
3652 | info->attrs[NL80211_ATTR_TXQ_LIMIT]); | |
3653 | changed |= WIPHY_PARAM_TXQ_LIMIT; | |
3654 | } | |
3655 | ||
3656 | if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { | |
3657 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
a05829a7 JB |
3658 | NL80211_EXT_FEATURE_TXQS)) { |
3659 | result = -EOPNOTSUPP; | |
3660 | goto out; | |
3661 | } | |
52539ca8 THJ |
3662 | txq_memory_limit = nla_get_u32( |
3663 | info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); | |
3664 | changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; | |
3665 | } | |
3666 | ||
3667 | if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { | |
3668 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
a05829a7 JB |
3669 | NL80211_EXT_FEATURE_TXQS)) { |
3670 | result = -EOPNOTSUPP; | |
3671 | goto out; | |
3672 | } | |
52539ca8 THJ |
3673 | txq_quantum = nla_get_u32( |
3674 | info->attrs[NL80211_ATTR_TXQ_QUANTUM]); | |
3675 | changed |= WIPHY_PARAM_TXQ_QUANTUM; | |
3676 | } | |
3677 | ||
b9a5f8ca JM |
3678 | if (changed) { |
3679 | u8 old_retry_short, old_retry_long; | |
3680 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 3681 | u8 old_coverage_class; |
52539ca8 | 3682 | u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; |
b9a5f8ca | 3683 | |
a05829a7 JB |
3684 | if (!rdev->ops->set_wiphy_params) { |
3685 | result = -EOPNOTSUPP; | |
3686 | goto out; | |
3687 | } | |
b9a5f8ca JM |
3688 | |
3689 | old_retry_short = rdev->wiphy.retry_short; | |
3690 | old_retry_long = rdev->wiphy.retry_long; | |
3691 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
3692 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 3693 | old_coverage_class = rdev->wiphy.coverage_class; |
52539ca8 THJ |
3694 | old_txq_limit = rdev->wiphy.txq_limit; |
3695 | old_txq_memory_limit = rdev->wiphy.txq_memory_limit; | |
3696 | old_txq_quantum = rdev->wiphy.txq_quantum; | |
b9a5f8ca JM |
3697 | |
3698 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
3699 | rdev->wiphy.retry_short = retry_short; | |
3700 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
3701 | rdev->wiphy.retry_long = retry_long; | |
3702 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
3703 | rdev->wiphy.frag_threshold = frag_threshold; | |
3704 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
3705 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
3706 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
3707 | rdev->wiphy.coverage_class = coverage_class; | |
52539ca8 THJ |
3708 | if (changed & WIPHY_PARAM_TXQ_LIMIT) |
3709 | rdev->wiphy.txq_limit = txq_limit; | |
3710 | if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) | |
3711 | rdev->wiphy.txq_memory_limit = txq_memory_limit; | |
3712 | if (changed & WIPHY_PARAM_TXQ_QUANTUM) | |
3713 | rdev->wiphy.txq_quantum = txq_quantum; | |
b9a5f8ca | 3714 | |
e35e4d28 | 3715 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
3716 | if (result) { |
3717 | rdev->wiphy.retry_short = old_retry_short; | |
3718 | rdev->wiphy.retry_long = old_retry_long; | |
3719 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
3720 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 3721 | rdev->wiphy.coverage_class = old_coverage_class; |
52539ca8 THJ |
3722 | rdev->wiphy.txq_limit = old_txq_limit; |
3723 | rdev->wiphy.txq_memory_limit = old_txq_memory_limit; | |
3724 | rdev->wiphy.txq_quantum = old_txq_quantum; | |
a05829a7 | 3725 | goto out; |
b9a5f8ca JM |
3726 | } |
3727 | } | |
a05829a7 JB |
3728 | |
3729 | result = 0; | |
3730 | ||
3731 | out: | |
3732 | wiphy_unlock(&rdev->wiphy); | |
3733 | return result; | |
55682965 JB |
3734 | } |
3735 | ||
683b6d3b | 3736 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 3737 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 3738 | { |
601555cd JB |
3739 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
3740 | return -EINVAL; | |
3d9d1d66 | 3741 | |
683b6d3b JB |
3742 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
3743 | chandef->chan->center_freq)) | |
3744 | return -ENOBUFS; | |
942ba88b TP |
3745 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, |
3746 | chandef->chan->freq_offset)) | |
3747 | return -ENOBUFS; | |
3d9d1d66 JB |
3748 | switch (chandef->width) { |
3749 | case NL80211_CHAN_WIDTH_20_NOHT: | |
3750 | case NL80211_CHAN_WIDTH_20: | |
3751 | case NL80211_CHAN_WIDTH_40: | |
3752 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
3753 | cfg80211_get_chandef_type(chandef))) | |
3754 | return -ENOBUFS; | |
3755 | break; | |
3756 | default: | |
3757 | break; | |
3758 | } | |
3759 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
3760 | return -ENOBUFS; | |
3761 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
3762 | return -ENOBUFS; | |
3763 | if (chandef->center_freq2 && | |
3764 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
3765 | return -ENOBUFS; |
3766 | return 0; | |
3767 | } | |
3768 | ||
15e47304 | 3769 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 3770 | struct cfg80211_registered_device *rdev, |
3d1a5bbf AZ |
3771 | struct wireless_dev *wdev, |
3772 | enum nl80211_commands cmd) | |
55682965 | 3773 | { |
72fb2abc | 3774 | struct net_device *dev = wdev->netdev; |
55682965 JB |
3775 | void *hdr; |
3776 | ||
3d1a5bbf AZ |
3777 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
3778 | cmd != NL80211_CMD_DEL_INTERFACE && | |
3779 | cmd != NL80211_CMD_SET_INTERFACE); | |
8f894be2 TB |
3780 | |
3781 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | |
55682965 JB |
3782 | if (!hdr) |
3783 | return -1; | |
3784 | ||
72fb2abc JB |
3785 | if (dev && |
3786 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 3787 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
3788 | goto nla_put_failure; |
3789 | ||
3790 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
3791 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
2dad624e ND |
3792 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
3793 | NL80211_ATTR_PAD) || | |
98104fde | 3794 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
3795 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
3796 | rdev->devlist_generation ^ | |
446faa15 AQ |
3797 | (cfg80211_rdev_list_generation << 2)) || |
3798 | nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) | |
9360ffd1 | 3799 | goto nla_put_failure; |
f5ea9120 | 3800 | |
7b0a0e3c | 3801 | if (rdev->ops->get_channel && !wdev->valid_links) { |
f43e5210 | 3802 | struct cfg80211_chan_def chandef = {}; |
7b0a0e3c | 3803 | int ret; |
683b6d3b | 3804 | |
7b0a0e3c JB |
3805 | ret = rdev_get_channel(rdev, wdev, 0, &chandef); |
3806 | if (ret == 0 && nl80211_send_chandef(msg, &chandef)) | |
3807 | goto nla_put_failure; | |
d91df0e3 PF |
3808 | } |
3809 | ||
d55d0d59 RM |
3810 | if (rdev->ops->get_tx_power) { |
3811 | int dbm, ret; | |
3812 | ||
3813 | ret = rdev_get_tx_power(rdev, wdev, &dbm); | |
3814 | if (ret == 0 && | |
3815 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, | |
3816 | DBM_TO_MBM(dbm))) | |
3817 | goto nla_put_failure; | |
3818 | } | |
3819 | ||
44905265 JB |
3820 | wdev_lock(wdev); |
3821 | switch (wdev->iftype) { | |
3822 | case NL80211_IFTYPE_AP: | |
a75971bc | 3823 | case NL80211_IFTYPE_P2P_GO: |
7b0a0e3c JB |
3824 | if (wdev->u.ap.ssid_len && |
3825 | nla_put(msg, NL80211_ATTR_SSID, wdev->u.ap.ssid_len, | |
3826 | wdev->u.ap.ssid)) | |
4564b187 | 3827 | goto nla_put_failure_locked; |
44905265 JB |
3828 | break; |
3829 | case NL80211_IFTYPE_STATION: | |
3830 | case NL80211_IFTYPE_P2P_CLIENT: | |
7b0a0e3c JB |
3831 | if (wdev->u.client.ssid_len && |
3832 | nla_put(msg, NL80211_ATTR_SSID, wdev->u.client.ssid_len, | |
3833 | wdev->u.client.ssid)) | |
3834 | goto nla_put_failure_locked; | |
3835 | break; | |
3836 | case NL80211_IFTYPE_ADHOC: | |
3837 | if (wdev->u.ibss.ssid_len && | |
3838 | nla_put(msg, NL80211_ATTR_SSID, wdev->u.ibss.ssid_len, | |
3839 | wdev->u.ibss.ssid)) | |
3840 | goto nla_put_failure_locked; | |
44905265 | 3841 | break; |
44905265 JB |
3842 | default: |
3843 | /* nothing */ | |
3844 | break; | |
b84e7a05 | 3845 | } |
44905265 | 3846 | wdev_unlock(wdev); |
b84e7a05 | 3847 | |
52539ca8 THJ |
3848 | if (rdev->ops->get_txq_stats) { |
3849 | struct cfg80211_txq_stats txqstats = {}; | |
3850 | int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); | |
3851 | ||
3852 | if (ret == 0 && | |
3853 | !nl80211_put_txq_stats(msg, &txqstats, | |
3854 | NL80211_ATTR_TXQ_STATS)) | |
3855 | goto nla_put_failure; | |
3856 | } | |
3857 | ||
ce08cd34 JB |
3858 | if (wdev->valid_links) { |
3859 | unsigned int link_id; | |
3860 | struct nlattr *links = nla_nest_start(msg, | |
3861 | NL80211_ATTR_MLO_LINKS); | |
3862 | ||
3863 | if (!links) | |
3864 | goto nla_put_failure; | |
3865 | ||
3866 | for_each_valid_link(wdev, link_id) { | |
3867 | struct nlattr *link = nla_nest_start(msg, link_id + 1); | |
7a77cd47 VJ |
3868 | struct cfg80211_chan_def chandef = {}; |
3869 | int ret; | |
ce08cd34 | 3870 | |
5cc58b37 YC |
3871 | if (!link) |
3872 | goto nla_put_failure; | |
3873 | ||
ce08cd34 JB |
3874 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) |
3875 | goto nla_put_failure; | |
3876 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, | |
3877 | wdev->links[link_id].addr)) | |
3878 | goto nla_put_failure; | |
7a77cd47 VJ |
3879 | |
3880 | ret = rdev_get_channel(rdev, wdev, link_id, &chandef); | |
3881 | if (ret == 0 && nl80211_send_chandef(msg, &chandef)) | |
3882 | goto nla_put_failure; | |
3883 | ||
ce08cd34 JB |
3884 | nla_nest_end(msg, link); |
3885 | } | |
3886 | ||
3887 | nla_nest_end(msg, links); | |
3888 | } | |
3889 | ||
053c095a JB |
3890 | genlmsg_end(msg, hdr); |
3891 | return 0; | |
55682965 | 3892 | |
4564b187 JB |
3893 | nla_put_failure_locked: |
3894 | wdev_unlock(wdev); | |
55682965 | 3895 | nla_put_failure: |
bc3ed28c TG |
3896 | genlmsg_cancel(msg, hdr); |
3897 | return -EMSGSIZE; | |
55682965 JB |
3898 | } |
3899 | ||
3900 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
3901 | { | |
3902 | int wp_idx = 0; | |
3903 | int if_idx = 0; | |
3904 | int wp_start = cb->args[0]; | |
3905 | int if_start = cb->args[1]; | |
b7fb44da | 3906 | int filter_wiphy = -1; |
f5ea9120 | 3907 | struct cfg80211_registered_device *rdev; |
55682965 | 3908 | struct wireless_dev *wdev; |
ea90e0dc | 3909 | int ret; |
55682965 | 3910 | |
5fe231e8 | 3911 | rtnl_lock(); |
b7fb44da DK |
3912 | if (!cb->args[2]) { |
3913 | struct nl80211_dump_wiphy_state state = { | |
3914 | .filter_wiphy = -1, | |
3915 | }; | |
b7fb44da DK |
3916 | |
3917 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); | |
3918 | if (ret) | |
ea90e0dc | 3919 | goto out_unlock; |
b7fb44da DK |
3920 | |
3921 | filter_wiphy = state.filter_wiphy; | |
3922 | ||
3923 | /* | |
3924 | * if filtering, set cb->args[2] to +1 since 0 is the default | |
3925 | * value needed to determine that parsing is necessary. | |
3926 | */ | |
3927 | if (filter_wiphy >= 0) | |
3928 | cb->args[2] = filter_wiphy + 1; | |
3929 | else | |
3930 | cb->args[2] = -1; | |
3931 | } else if (cb->args[2] > 0) { | |
3932 | filter_wiphy = cb->args[2] - 1; | |
3933 | } | |
3934 | ||
f5ea9120 JB |
3935 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
3936 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 3937 | continue; |
bba95fef JB |
3938 | if (wp_idx < wp_start) { |
3939 | wp_idx++; | |
55682965 | 3940 | continue; |
bba95fef | 3941 | } |
b7fb44da DK |
3942 | |
3943 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) | |
3944 | continue; | |
3945 | ||
55682965 JB |
3946 | if_idx = 0; |
3947 | ||
53873f13 | 3948 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
bba95fef JB |
3949 | if (if_idx < if_start) { |
3950 | if_idx++; | |
55682965 | 3951 | continue; |
bba95fef | 3952 | } |
15e47304 | 3953 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 3954 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
3d1a5bbf AZ |
3955 | rdev, wdev, |
3956 | NL80211_CMD_NEW_INTERFACE) < 0) { | |
bba95fef JB |
3957 | goto out; |
3958 | } | |
3959 | if_idx++; | |
55682965 | 3960 | } |
bba95fef JB |
3961 | |
3962 | wp_idx++; | |
55682965 | 3963 | } |
bba95fef | 3964 | out: |
55682965 JB |
3965 | cb->args[0] = wp_idx; |
3966 | cb->args[1] = if_idx; | |
3967 | ||
ea90e0dc JB |
3968 | ret = skb->len; |
3969 | out_unlock: | |
3970 | rtnl_unlock(); | |
3971 | ||
3972 | return ret; | |
55682965 JB |
3973 | } |
3974 | ||
3975 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
3976 | { | |
3977 | struct sk_buff *msg; | |
1b8ec87a | 3978 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 3979 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 3980 | |
fd2120ca | 3981 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 3982 | if (!msg) |
4c476991 | 3983 | return -ENOMEM; |
55682965 | 3984 | |
15e47304 | 3985 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
3d1a5bbf | 3986 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
4c476991 JB |
3987 | nlmsg_free(msg); |
3988 | return -ENOBUFS; | |
3989 | } | |
55682965 | 3990 | |
134e6375 | 3991 | return genlmsg_reply(msg, info); |
55682965 JB |
3992 | } |
3993 | ||
66f7ac50 MW |
3994 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
3995 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
3996 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
3997 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
3998 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
3999 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 4000 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
4001 | }; |
4002 | ||
4003 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
4004 | { | |
4005 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
4006 | int flag; | |
4007 | ||
4008 | *mntrflags = 0; | |
4009 | ||
4010 | if (!nla) | |
4011 | return -EINVAL; | |
4012 | ||
8cb08174 | 4013 | if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL)) |
66f7ac50 MW |
4014 | return -EINVAL; |
4015 | ||
4016 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
4017 | if (flags[flag]) | |
4018 | *mntrflags |= (1<<flag); | |
4019 | ||
818a986e JB |
4020 | *mntrflags |= MONITOR_FLAG_CHANGED; |
4021 | ||
66f7ac50 MW |
4022 | return 0; |
4023 | } | |
4024 | ||
1db77596 JB |
4025 | static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, |
4026 | enum nl80211_iftype type, | |
4027 | struct genl_info *info, | |
4028 | struct vif_params *params) | |
4029 | { | |
4030 | bool change = false; | |
4031 | int err; | |
4032 | ||
4033 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { | |
4034 | if (type != NL80211_IFTYPE_MONITOR) | |
4035 | return -EINVAL; | |
4036 | ||
4037 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], | |
4038 | ¶ms->flags); | |
4039 | if (err) | |
4040 | return err; | |
4041 | ||
4042 | change = true; | |
4043 | } | |
4044 | ||
4045 | if (params->flags & MONITOR_FLAG_ACTIVE && | |
4046 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) | |
4047 | return -EOPNOTSUPP; | |
4048 | ||
4049 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { | |
4050 | const u8 *mumimo_groups; | |
4051 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; | |
4052 | ||
4053 | if (type != NL80211_IFTYPE_MONITOR) | |
4054 | return -EINVAL; | |
4055 | ||
4056 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) | |
4057 | return -EOPNOTSUPP; | |
4058 | ||
4059 | mumimo_groups = | |
4060 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); | |
4061 | ||
4062 | /* bits 0 and 63 are reserved and must be zero */ | |
4954601f JB |
4063 | if ((mumimo_groups[0] & BIT(0)) || |
4064 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) | |
1db77596 JB |
4065 | return -EINVAL; |
4066 | ||
4067 | params->vht_mumimo_groups = mumimo_groups; | |
4068 | change = true; | |
4069 | } | |
4070 | ||
4071 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { | |
4072 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; | |
4073 | ||
4074 | if (type != NL80211_IFTYPE_MONITOR) | |
4075 | return -EINVAL; | |
4076 | ||
4077 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) | |
4078 | return -EOPNOTSUPP; | |
4079 | ||
4080 | params->vht_mumimo_follow_addr = | |
4081 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); | |
4082 | change = true; | |
4083 | } | |
4084 | ||
4085 | return change ? 1 : 0; | |
4086 | } | |
4087 | ||
9bc383de | 4088 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
4089 | struct net_device *netdev, u8 use_4addr, |
4090 | enum nl80211_iftype iftype) | |
9bc383de | 4091 | { |
ad4bb6f8 | 4092 | if (!use_4addr) { |
2e92a2d0 | 4093 | if (netdev && netif_is_bridge_port(netdev)) |
ad4bb6f8 | 4094 | return -EBUSY; |
9bc383de | 4095 | return 0; |
ad4bb6f8 | 4096 | } |
9bc383de JB |
4097 | |
4098 | switch (iftype) { | |
4099 | case NL80211_IFTYPE_AP_VLAN: | |
4100 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
4101 | return 0; | |
4102 | break; | |
4103 | case NL80211_IFTYPE_STATION: | |
4104 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
4105 | return 0; | |
4106 | break; | |
4107 | default: | |
4108 | break; | |
4109 | } | |
4110 | ||
4111 | return -EOPNOTSUPP; | |
4112 | } | |
4113 | ||
55682965 JB |
4114 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
4115 | { | |
4c476991 | 4116 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4117 | struct vif_params params; |
e36d56b6 | 4118 | int err; |
04a773ad | 4119 | enum nl80211_iftype otype, ntype; |
4c476991 | 4120 | struct net_device *dev = info->user_ptr[1]; |
ac7f9cfa | 4121 | bool change = false; |
55682965 | 4122 | |
2ec600d6 LCC |
4123 | memset(¶ms, 0, sizeof(params)); |
4124 | ||
04a773ad | 4125 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 4126 | |
723b038d | 4127 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 4128 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 4129 | if (otype != ntype) |
ac7f9cfa | 4130 | change = true; |
723b038d JB |
4131 | } |
4132 | ||
92ffe055 | 4133 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
4134 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4135 | ||
4c476991 JB |
4136 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
4137 | return -EINVAL; | |
29cbe68c JB |
4138 | if (netif_running(dev)) |
4139 | return -EBUSY; | |
4140 | ||
4141 | wdev_lock(wdev); | |
4142 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
4143 | IEEE80211_MAX_MESH_ID_LEN); | |
7b0a0e3c | 4144 | wdev->u.mesh.id_up_len = |
29cbe68c | 4145 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
7b0a0e3c JB |
4146 | memcpy(wdev->u.mesh.id, |
4147 | nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
4148 | wdev->u.mesh.id_up_len); | |
29cbe68c | 4149 | wdev_unlock(wdev); |
2ec600d6 LCC |
4150 | } |
4151 | ||
8b787643 FF |
4152 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
4153 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
4154 | change = true; | |
ad4bb6f8 | 4155 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 4156 | if (err) |
4c476991 | 4157 | return err; |
8b787643 FF |
4158 | } else { |
4159 | params.use_4addr = -1; | |
4160 | } | |
4161 | ||
1db77596 JB |
4162 | err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); |
4163 | if (err < 0) | |
4164 | return err; | |
4165 | if (err > 0) | |
c6e6a0c8 | 4166 | change = true; |
e057d3c3 | 4167 | |
ac7f9cfa | 4168 | if (change) |
818a986e | 4169 | err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); |
ac7f9cfa JB |
4170 | else |
4171 | err = 0; | |
60719ffd | 4172 | |
9bc383de JB |
4173 | if (!err && params.use_4addr != -1) |
4174 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
4175 | ||
3d1a5bbf AZ |
4176 | if (change && !err) { |
4177 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
4178 | ||
4179 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE); | |
4180 | } | |
4181 | ||
55682965 JB |
4182 | return err; |
4183 | } | |
4184 | ||
ea6b2098 | 4185 | static int _nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
55682965 | 4186 | { |
4c476991 | 4187 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4188 | struct vif_params params; |
84efbb84 | 4189 | struct wireless_dev *wdev; |
896ff063 | 4190 | struct sk_buff *msg; |
55682965 JB |
4191 | int err; |
4192 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
4193 | ||
2ec600d6 LCC |
4194 | memset(¶ms, 0, sizeof(params)); |
4195 | ||
55682965 JB |
4196 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
4197 | return -EINVAL; | |
4198 | ||
ab0d76f6 | 4199 | if (info->attrs[NL80211_ATTR_IFTYPE]) |
55682965 | 4200 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
55682965 | 4201 | |
33d915d9 | 4202 | if (!rdev->ops->add_virtual_intf) |
4c476991 | 4203 | return -EOPNOTSUPP; |
55682965 | 4204 | |
cb3b7d87 | 4205 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
e8f479b1 BG |
4206 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
4207 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
4208 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
4209 | ETH_ALEN); | |
4210 | if (!is_valid_ether_addr(params.macaddr)) | |
4211 | return -EADDRNOTAVAIL; | |
4212 | } | |
4213 | ||
9bc383de | 4214 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 4215 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 4216 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 4217 | if (err) |
4c476991 | 4218 | return err; |
9bc383de | 4219 | } |
8b787643 | 4220 | |
e6f40511 | 4221 | if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0)) |
33d915d9 MP |
4222 | return -EOPNOTSUPP; |
4223 | ||
1db77596 JB |
4224 | err = nl80211_parse_mon_options(rdev, type, info, ¶ms); |
4225 | if (err < 0) | |
4226 | return err; | |
e057d3c3 | 4227 | |
a18c7192 JB |
4228 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4229 | if (!msg) | |
4230 | return -ENOMEM; | |
4231 | ||
e35e4d28 HG |
4232 | wdev = rdev_add_virtual_intf(rdev, |
4233 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
818a986e | 4234 | NET_NAME_USER, type, ¶ms); |
d687cbb7 RM |
4235 | if (WARN_ON(!wdev)) { |
4236 | nlmsg_free(msg); | |
4237 | return -EPROTO; | |
4238 | } else if (IS_ERR(wdev)) { | |
1c90f9d4 | 4239 | nlmsg_free(msg); |
84efbb84 | 4240 | return PTR_ERR(wdev); |
1c90f9d4 | 4241 | } |
2ec600d6 | 4242 | |
18e5ca65 | 4243 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
78f22b6a JB |
4244 | wdev->owner_nlportid = info->snd_portid; |
4245 | ||
98104fde JB |
4246 | switch (type) { |
4247 | case NL80211_IFTYPE_MESH_POINT: | |
4248 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
4249 | break; | |
29cbe68c JB |
4250 | wdev_lock(wdev); |
4251 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
4252 | IEEE80211_MAX_MESH_ID_LEN); | |
7b0a0e3c | 4253 | wdev->u.mesh.id_up_len = |
29cbe68c | 4254 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
7b0a0e3c JB |
4255 | memcpy(wdev->u.mesh.id, |
4256 | nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
4257 | wdev->u.mesh.id_up_len); | |
29cbe68c | 4258 | wdev_unlock(wdev); |
98104fde | 4259 | break; |
cb3b7d87 | 4260 | case NL80211_IFTYPE_NAN: |
98104fde JB |
4261 | case NL80211_IFTYPE_P2P_DEVICE: |
4262 | /* | |
cb3b7d87 | 4263 | * P2P Device and NAN do not have a netdev, so don't go |
98104fde JB |
4264 | * through the netdev notifier and must be added here |
4265 | */ | |
9bdaf3b9 JB |
4266 | cfg80211_init_wdev(wdev); |
4267 | cfg80211_register_wdev(rdev, wdev); | |
98104fde JB |
4268 | break; |
4269 | default: | |
4270 | break; | |
29cbe68c JB |
4271 | } |
4272 | ||
15e47304 | 4273 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
3d1a5bbf | 4274 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
1c90f9d4 JB |
4275 | nlmsg_free(msg); |
4276 | return -ENOBUFS; | |
4277 | } | |
4278 | ||
4279 | return genlmsg_reply(msg, info); | |
55682965 JB |
4280 | } |
4281 | ||
ea6b2098 JB |
4282 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
4283 | { | |
4284 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4285 | int ret; | |
4286 | ||
4287 | /* to avoid failing a new interface creation due to pending removal */ | |
4288 | cfg80211_destroy_ifaces(rdev); | |
4289 | ||
4290 | wiphy_lock(&rdev->wiphy); | |
4291 | ret = _nl80211_new_interface(skb, info); | |
4292 | wiphy_unlock(&rdev->wiphy); | |
4293 | ||
4294 | return ret; | |
4295 | } | |
4296 | ||
55682965 JB |
4297 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
4298 | { | |
4c476991 | 4299 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 4300 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 4301 | |
4c476991 JB |
4302 | if (!rdev->ops->del_virtual_intf) |
4303 | return -EOPNOTSUPP; | |
55682965 | 4304 | |
a05829a7 JB |
4305 | /* |
4306 | * We hold RTNL, so this is safe, without RTNL opencount cannot | |
4307 | * reach 0, and thus the rdev cannot be deleted. | |
4308 | * | |
4309 | * We need to do it for the dev_close(), since that will call | |
4310 | * the netdev notifiers, and we need to acquire the mutex there | |
4311 | * but don't know if we get there from here or from some other | |
4312 | * place (e.g. "ip link set ... down"). | |
4313 | */ | |
4314 | mutex_unlock(&rdev->wiphy.mtx); | |
4315 | ||
84efbb84 JB |
4316 | /* |
4317 | * If we remove a wireless device without a netdev then clear | |
4318 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
4319 | * to check if it needs to do dev_put(). Otherwise it crashes | |
4320 | * since the wdev has been freed, unlike with a netdev where | |
4321 | * we need the dev_put() for the netdev to really be freed. | |
4322 | */ | |
4323 | if (!wdev->netdev) | |
4324 | info->user_ptr[1] = NULL; | |
a05829a7 JB |
4325 | else |
4326 | dev_close(wdev->netdev); | |
4327 | ||
4328 | mutex_lock(&rdev->wiphy.mtx); | |
84efbb84 | 4329 | |
cdf0a0a8 | 4330 | return cfg80211_remove_virtual_intf(rdev, wdev); |
55682965 JB |
4331 | } |
4332 | ||
1d9d9213 SW |
4333 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
4334 | { | |
4335 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4336 | struct net_device *dev = info->user_ptr[1]; | |
4337 | u16 noack_map; | |
4338 | ||
4339 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
4340 | return -EINVAL; | |
4341 | ||
4342 | if (!rdev->ops->set_noack_map) | |
4343 | return -EOPNOTSUPP; | |
4344 | ||
4345 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
4346 | ||
e35e4d28 | 4347 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
4348 | } |
4349 | ||
e7a7b84e VJ |
4350 | static int nl80211_validate_key_link_id(struct genl_info *info, |
4351 | struct wireless_dev *wdev, | |
4352 | int link_id, bool pairwise) | |
4353 | { | |
4354 | if (pairwise) { | |
4355 | if (link_id != -1) { | |
4356 | GENL_SET_ERR_MSG(info, | |
4357 | "link ID not allowed for pairwise key"); | |
4358 | return -EINVAL; | |
4359 | } | |
4360 | ||
4361 | return 0; | |
4362 | } | |
4363 | ||
4364 | if (wdev->valid_links) { | |
4365 | if (link_id == -1) { | |
4366 | GENL_SET_ERR_MSG(info, | |
4367 | "link ID must for MLO group key"); | |
4368 | return -EINVAL; | |
4369 | } | |
4370 | if (!(wdev->valid_links & BIT(link_id))) { | |
4371 | GENL_SET_ERR_MSG(info, "invalid link ID for MLO group key"); | |
4372 | return -EINVAL; | |
4373 | } | |
4374 | } else if (link_id != -1) { | |
4375 | GENL_SET_ERR_MSG(info, "link ID not allowed for non-MLO group key"); | |
4376 | return -EINVAL; | |
4377 | } | |
4378 | ||
4379 | return 0; | |
4380 | } | |
4381 | ||
41ade00f JB |
4382 | struct get_key_cookie { |
4383 | struct sk_buff *msg; | |
4384 | int error; | |
b9454e83 | 4385 | int idx; |
41ade00f JB |
4386 | }; |
4387 | ||
4388 | static void get_key_callback(void *c, struct key_params *params) | |
4389 | { | |
b9454e83 | 4390 | struct nlattr *key; |
41ade00f JB |
4391 | struct get_key_cookie *cookie = c; |
4392 | ||
9360ffd1 DM |
4393 | if ((params->key && |
4394 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
4395 | params->key_len, params->key)) || | |
4396 | (params->seq && | |
4397 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
4398 | params->seq_len, params->seq)) || | |
4399 | (params->cipher && | |
4400 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
4401 | params->cipher))) | |
4402 | goto nla_put_failure; | |
41ade00f | 4403 | |
ae0be8de | 4404 | key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY); |
b9454e83 JB |
4405 | if (!key) |
4406 | goto nla_put_failure; | |
4407 | ||
9360ffd1 DM |
4408 | if ((params->key && |
4409 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
4410 | params->key_len, params->key)) || | |
4411 | (params->seq && | |
4412 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
4413 | params->seq_len, params->seq)) || | |
4414 | (params->cipher && | |
4415 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
4416 | params->cipher))) | |
4417 | goto nla_put_failure; | |
b9454e83 | 4418 | |
efdfce72 | 4419 | if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx)) |
9360ffd1 | 4420 | goto nla_put_failure; |
b9454e83 JB |
4421 | |
4422 | nla_nest_end(cookie->msg, key); | |
4423 | ||
41ade00f JB |
4424 | return; |
4425 | nla_put_failure: | |
4426 | cookie->error = 1; | |
4427 | } | |
4428 | ||
4429 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
4430 | { | |
4c476991 | 4431 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 4432 | int err; |
4c476991 | 4433 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 4434 | u8 key_idx = 0; |
e31b8213 JB |
4435 | const u8 *mac_addr = NULL; |
4436 | bool pairwise; | |
41ade00f JB |
4437 | struct get_key_cookie cookie = { |
4438 | .error = 0, | |
4439 | }; | |
4440 | void *hdr; | |
4441 | struct sk_buff *msg; | |
155d7c73 | 4442 | bool bigtk_support = false; |
e7a7b84e VJ |
4443 | int link_id = nl80211_link_id_or_invalid(info->attrs); |
4444 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
155d7c73 JB |
4445 | |
4446 | if (wiphy_ext_feature_isset(&rdev->wiphy, | |
4447 | NL80211_EXT_FEATURE_BEACON_PROTECTION)) | |
4448 | bigtk_support = true; | |
4449 | ||
e7a7b84e VJ |
4450 | if ((wdev->iftype == NL80211_IFTYPE_STATION || |
4451 | wdev->iftype == NL80211_IFTYPE_P2P_CLIENT) && | |
155d7c73 JB |
4452 | wiphy_ext_feature_isset(&rdev->wiphy, |
4453 | NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT)) | |
4454 | bigtk_support = true; | |
41ade00f | 4455 | |
56be393f | 4456 | if (info->attrs[NL80211_ATTR_KEY_IDX]) { |
41ade00f | 4457 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
155d7c73 JB |
4458 | |
4459 | if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) { | |
4460 | GENL_SET_ERR_MSG(info, "BIGTK not supported"); | |
56be393f | 4461 | return -EINVAL; |
155d7c73 | 4462 | } |
56be393f | 4463 | } |
41ade00f | 4464 | |
41ade00f JB |
4465 | if (info->attrs[NL80211_ATTR_MAC]) |
4466 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4467 | ||
e31b8213 JB |
4468 | pairwise = !!mac_addr; |
4469 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
4470 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
7a087e74 | 4471 | |
e31b8213 JB |
4472 | if (kt != NL80211_KEYTYPE_GROUP && |
4473 | kt != NL80211_KEYTYPE_PAIRWISE) | |
4474 | return -EINVAL; | |
4475 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
4476 | } | |
4477 | ||
4c476991 JB |
4478 | if (!rdev->ops->get_key) |
4479 | return -EOPNOTSUPP; | |
41ade00f | 4480 | |
0fa7b391 JB |
4481 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
4482 | return -ENOENT; | |
4483 | ||
fd2120ca | 4484 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4485 | if (!msg) |
4486 | return -ENOMEM; | |
41ade00f | 4487 | |
15e47304 | 4488 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 4489 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 4490 | if (!hdr) |
9fe271af | 4491 | goto nla_put_failure; |
41ade00f JB |
4492 | |
4493 | cookie.msg = msg; | |
b9454e83 | 4494 | cookie.idx = key_idx; |
41ade00f | 4495 | |
9360ffd1 DM |
4496 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4497 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
4498 | goto nla_put_failure; | |
4499 | if (mac_addr && | |
4500 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
4501 | goto nla_put_failure; | |
41ade00f | 4502 | |
e7a7b84e VJ |
4503 | err = nl80211_validate_key_link_id(info, wdev, link_id, pairwise); |
4504 | if (err) | |
4505 | goto free_msg; | |
4506 | ||
4507 | err = rdev_get_key(rdev, dev, link_id, key_idx, pairwise, mac_addr, | |
4508 | &cookie, get_key_callback); | |
41ade00f JB |
4509 | |
4510 | if (err) | |
6c95e2a2 | 4511 | goto free_msg; |
41ade00f JB |
4512 | |
4513 | if (cookie.error) | |
4514 | goto nla_put_failure; | |
4515 | ||
4516 | genlmsg_end(msg, hdr); | |
4c476991 | 4517 | return genlmsg_reply(msg, info); |
41ade00f JB |
4518 | |
4519 | nla_put_failure: | |
4520 | err = -ENOBUFS; | |
6c95e2a2 | 4521 | free_msg: |
41ade00f | 4522 | nlmsg_free(msg); |
41ade00f JB |
4523 | return err; |
4524 | } | |
4525 | ||
4526 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
4527 | { | |
4c476991 | 4528 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 4529 | struct key_parse key; |
41ade00f | 4530 | int err; |
4c476991 | 4531 | struct net_device *dev = info->user_ptr[1]; |
e7a7b84e VJ |
4532 | int link_id = nl80211_link_id_or_invalid(info->attrs); |
4533 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
41ade00f | 4534 | |
b9454e83 JB |
4535 | err = nl80211_parse_key(info, &key); |
4536 | if (err) | |
4537 | return err; | |
41ade00f | 4538 | |
b9454e83 | 4539 | if (key.idx < 0) |
41ade00f JB |
4540 | return -EINVAL; |
4541 | ||
6cdd3979 AW |
4542 | /* Only support setting default key and |
4543 | * Extended Key ID action NL80211_KEY_SET_TX. | |
4544 | */ | |
56be393f | 4545 | if (!key.def && !key.defmgmt && !key.defbeacon && |
6cdd3979 | 4546 | !(key.p.mode == NL80211_KEY_SET_TX)) |
41ade00f JB |
4547 | return -EINVAL; |
4548 | ||
e7a7b84e | 4549 | wdev_lock(wdev); |
3cfcf6ac | 4550 | |
dbd2fd65 JB |
4551 | if (key.def) { |
4552 | if (!rdev->ops->set_default_key) { | |
4553 | err = -EOPNOTSUPP; | |
4554 | goto out; | |
4555 | } | |
41ade00f | 4556 | |
e7a7b84e VJ |
4557 | err = nl80211_key_allowed(wdev); |
4558 | if (err) | |
4559 | goto out; | |
4560 | ||
4561 | err = nl80211_validate_key_link_id(info, wdev, link_id, false); | |
dbd2fd65 JB |
4562 | if (err) |
4563 | goto out; | |
4564 | ||
e7a7b84e VJ |
4565 | err = rdev_set_default_key(rdev, dev, link_id, key.idx, |
4566 | key.def_uni, key.def_multi); | |
dbd2fd65 JB |
4567 | |
4568 | if (err) | |
4569 | goto out; | |
fffd0934 | 4570 | |
3d23e349 | 4571 | #ifdef CONFIG_CFG80211_WEXT |
e7a7b84e | 4572 | wdev->wext.default_key = key.idx; |
dbd2fd65 | 4573 | #endif |
6cdd3979 | 4574 | } else if (key.defmgmt) { |
dbd2fd65 JB |
4575 | if (key.def_uni || !key.def_multi) { |
4576 | err = -EINVAL; | |
4577 | goto out; | |
4578 | } | |
4579 | ||
4580 | if (!rdev->ops->set_default_mgmt_key) { | |
4581 | err = -EOPNOTSUPP; | |
4582 | goto out; | |
4583 | } | |
4584 | ||
e7a7b84e VJ |
4585 | err = nl80211_key_allowed(wdev); |
4586 | if (err) | |
4587 | goto out; | |
4588 | ||
4589 | err = nl80211_validate_key_link_id(info, wdev, link_id, false); | |
dbd2fd65 JB |
4590 | if (err) |
4591 | goto out; | |
4592 | ||
e7a7b84e | 4593 | err = rdev_set_default_mgmt_key(rdev, dev, link_id, key.idx); |
dbd2fd65 JB |
4594 | if (err) |
4595 | goto out; | |
4596 | ||
4597 | #ifdef CONFIG_CFG80211_WEXT | |
e7a7b84e | 4598 | wdev->wext.default_mgmt_key = key.idx; |
08645126 | 4599 | #endif |
56be393f JM |
4600 | } else if (key.defbeacon) { |
4601 | if (key.def_uni || !key.def_multi) { | |
4602 | err = -EINVAL; | |
4603 | goto out; | |
4604 | } | |
4605 | ||
4606 | if (!rdev->ops->set_default_beacon_key) { | |
4607 | err = -EOPNOTSUPP; | |
4608 | goto out; | |
4609 | } | |
4610 | ||
e7a7b84e | 4611 | err = nl80211_key_allowed(wdev); |
56be393f JM |
4612 | if (err) |
4613 | goto out; | |
4614 | ||
e7a7b84e VJ |
4615 | err = nl80211_validate_key_link_id(info, wdev, link_id, false); |
4616 | if (err) | |
4617 | goto out; | |
4618 | ||
4619 | err = rdev_set_default_beacon_key(rdev, dev, link_id, key.idx); | |
56be393f JM |
4620 | if (err) |
4621 | goto out; | |
6cdd3979 AW |
4622 | } else if (key.p.mode == NL80211_KEY_SET_TX && |
4623 | wiphy_ext_feature_isset(&rdev->wiphy, | |
4624 | NL80211_EXT_FEATURE_EXT_KEY_ID)) { | |
4625 | u8 *mac_addr = NULL; | |
4626 | ||
4627 | if (info->attrs[NL80211_ATTR_MAC]) | |
4628 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4629 | ||
4630 | if (!mac_addr || key.idx < 0 || key.idx > 1) { | |
4631 | err = -EINVAL; | |
4632 | goto out; | |
4633 | } | |
dbd2fd65 | 4634 | |
e7a7b84e VJ |
4635 | err = nl80211_validate_key_link_id(info, wdev, link_id, true); |
4636 | if (err) | |
4637 | goto out; | |
4638 | ||
4639 | err = rdev_add_key(rdev, dev, link_id, key.idx, | |
6cdd3979 AW |
4640 | NL80211_KEYTYPE_PAIRWISE, |
4641 | mac_addr, &key.p); | |
4642 | } else { | |
4643 | err = -EINVAL; | |
4644 | } | |
dbd2fd65 | 4645 | out: |
e7a7b84e | 4646 | wdev_unlock(wdev); |
41ade00f | 4647 | |
41ade00f JB |
4648 | return err; |
4649 | } | |
4650 | ||
4651 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
4652 | { | |
4c476991 | 4653 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 4654 | int err; |
4c476991 | 4655 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 4656 | struct key_parse key; |
e31b8213 | 4657 | const u8 *mac_addr = NULL; |
e7a7b84e VJ |
4658 | int link_id = nl80211_link_id_or_invalid(info->attrs); |
4659 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
41ade00f | 4660 | |
b9454e83 JB |
4661 | err = nl80211_parse_key(info, &key); |
4662 | if (err) | |
4663 | return err; | |
41ade00f | 4664 | |
f8af764b JM |
4665 | if (!key.p.key) { |
4666 | GENL_SET_ERR_MSG(info, "no key"); | |
41ade00f | 4667 | return -EINVAL; |
f8af764b | 4668 | } |
41ade00f | 4669 | |
41ade00f JB |
4670 | if (info->attrs[NL80211_ATTR_MAC]) |
4671 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4672 | ||
e31b8213 JB |
4673 | if (key.type == -1) { |
4674 | if (mac_addr) | |
4675 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
4676 | else | |
4677 | key.type = NL80211_KEYTYPE_GROUP; | |
4678 | } | |
4679 | ||
4680 | /* for now */ | |
4681 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
f8af764b JM |
4682 | key.type != NL80211_KEYTYPE_GROUP) { |
4683 | GENL_SET_ERR_MSG(info, "key type not pairwise or group"); | |
e31b8213 | 4684 | return -EINVAL; |
f8af764b | 4685 | } |
e31b8213 | 4686 | |
14f34e36 GG |
4687 | if (key.type == NL80211_KEYTYPE_GROUP && |
4688 | info->attrs[NL80211_ATTR_VLAN_ID]) | |
4689 | key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); | |
4690 | ||
4c476991 JB |
4691 | if (!rdev->ops->add_key) |
4692 | return -EOPNOTSUPP; | |
25e47c18 | 4693 | |
e31b8213 JB |
4694 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
4695 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
f8af764b JM |
4696 | mac_addr)) { |
4697 | GENL_SET_ERR_MSG(info, "key setting validation failed"); | |
4c476991 | 4698 | return -EINVAL; |
f8af764b | 4699 | } |
41ade00f | 4700 | |
e7a7b84e VJ |
4701 | wdev_lock(wdev); |
4702 | err = nl80211_key_allowed(wdev); | |
f8af764b JM |
4703 | if (err) |
4704 | GENL_SET_ERR_MSG(info, "key not allowed"); | |
e7a7b84e VJ |
4705 | |
4706 | if (!err) | |
4707 | err = nl80211_validate_key_link_id(info, wdev, link_id, | |
4708 | key.type == NL80211_KEYTYPE_PAIRWISE); | |
4709 | ||
f8af764b | 4710 | if (!err) { |
e7a7b84e | 4711 | err = rdev_add_key(rdev, dev, link_id, key.idx, |
e35e4d28 HG |
4712 | key.type == NL80211_KEYTYPE_PAIRWISE, |
4713 | mac_addr, &key.p); | |
f8af764b JM |
4714 | if (err) |
4715 | GENL_SET_ERR_MSG(info, "key addition failed"); | |
4716 | } | |
e7a7b84e | 4717 | wdev_unlock(wdev); |
41ade00f | 4718 | |
41ade00f JB |
4719 | return err; |
4720 | } | |
4721 | ||
4722 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
4723 | { | |
4c476991 | 4724 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 4725 | int err; |
4c476991 | 4726 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 4727 | u8 *mac_addr = NULL; |
b9454e83 | 4728 | struct key_parse key; |
e7a7b84e VJ |
4729 | int link_id = nl80211_link_id_or_invalid(info->attrs); |
4730 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
41ade00f | 4731 | |
b9454e83 JB |
4732 | err = nl80211_parse_key(info, &key); |
4733 | if (err) | |
4734 | return err; | |
41ade00f JB |
4735 | |
4736 | if (info->attrs[NL80211_ATTR_MAC]) | |
4737 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4738 | ||
e31b8213 JB |
4739 | if (key.type == -1) { |
4740 | if (mac_addr) | |
4741 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
4742 | else | |
4743 | key.type = NL80211_KEYTYPE_GROUP; | |
4744 | } | |
4745 | ||
4746 | /* for now */ | |
4747 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
4748 | key.type != NL80211_KEYTYPE_GROUP) | |
4749 | return -EINVAL; | |
4750 | ||
2d946308 AT |
4751 | if (!cfg80211_valid_key_idx(rdev, key.idx, |
4752 | key.type == NL80211_KEYTYPE_PAIRWISE)) | |
4753 | return -EINVAL; | |
4754 | ||
4c476991 JB |
4755 | if (!rdev->ops->del_key) |
4756 | return -EOPNOTSUPP; | |
41ade00f | 4757 | |
e7a7b84e VJ |
4758 | wdev_lock(wdev); |
4759 | err = nl80211_key_allowed(wdev); | |
e31b8213 | 4760 | |
0fa7b391 | 4761 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
e31b8213 JB |
4762 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
4763 | err = -ENOENT; | |
4764 | ||
fffd0934 | 4765 | if (!err) |
e7a7b84e VJ |
4766 | err = nl80211_validate_key_link_id(info, wdev, link_id, |
4767 | key.type == NL80211_KEYTYPE_PAIRWISE); | |
4768 | ||
4769 | if (!err) | |
4770 | err = rdev_del_key(rdev, dev, link_id, key.idx, | |
e35e4d28 HG |
4771 | key.type == NL80211_KEYTYPE_PAIRWISE, |
4772 | mac_addr); | |
41ade00f | 4773 | |
3d23e349 | 4774 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 4775 | if (!err) { |
e7a7b84e VJ |
4776 | if (key.idx == wdev->wext.default_key) |
4777 | wdev->wext.default_key = -1; | |
4778 | else if (key.idx == wdev->wext.default_mgmt_key) | |
4779 | wdev->wext.default_mgmt_key = -1; | |
08645126 JB |
4780 | } |
4781 | #endif | |
e7a7b84e | 4782 | wdev_unlock(wdev); |
08645126 | 4783 | |
41ade00f JB |
4784 | return err; |
4785 | } | |
4786 | ||
77765eaf VT |
4787 | /* This function returns an error or the number of nested attributes */ |
4788 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
4789 | { | |
4790 | struct nlattr *attr; | |
4791 | int n_entries = 0, tmp; | |
4792 | ||
4793 | nla_for_each_nested(attr, nl_attr, tmp) { | |
4794 | if (nla_len(attr) != ETH_ALEN) | |
4795 | return -EINVAL; | |
4796 | ||
4797 | n_entries++; | |
4798 | } | |
4799 | ||
4800 | return n_entries; | |
4801 | } | |
4802 | ||
4803 | /* | |
4804 | * This function parses ACL information and allocates memory for ACL data. | |
4805 | * On successful return, the calling function is responsible to free the | |
4806 | * ACL buffer returned by this function. | |
4807 | */ | |
4808 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
4809 | struct genl_info *info) | |
4810 | { | |
4811 | enum nl80211_acl_policy acl_policy; | |
4812 | struct nlattr *attr; | |
4813 | struct cfg80211_acl_data *acl; | |
4814 | int i = 0, n_entries, tmp; | |
4815 | ||
4816 | if (!wiphy->max_acl_mac_addrs) | |
4817 | return ERR_PTR(-EOPNOTSUPP); | |
4818 | ||
4819 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
4820 | return ERR_PTR(-EINVAL); | |
4821 | ||
4822 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
4823 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
4824 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
4825 | return ERR_PTR(-EINVAL); | |
4826 | ||
4827 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
4828 | return ERR_PTR(-EINVAL); | |
4829 | ||
4830 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
4831 | if (n_entries < 0) | |
4832 | return ERR_PTR(n_entries); | |
4833 | ||
4834 | if (n_entries > wiphy->max_acl_mac_addrs) | |
4835 | return ERR_PTR(-ENOTSUPP); | |
4836 | ||
391d132c | 4837 | acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL); |
77765eaf VT |
4838 | if (!acl) |
4839 | return ERR_PTR(-ENOMEM); | |
4840 | ||
4841 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
4842 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
4843 | i++; | |
4844 | } | |
4845 | ||
4846 | acl->n_acl_entries = n_entries; | |
4847 | acl->acl_policy = acl_policy; | |
4848 | ||
4849 | return acl; | |
4850 | } | |
4851 | ||
4852 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
4853 | { | |
4854 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4855 | struct net_device *dev = info->user_ptr[1]; | |
4856 | struct cfg80211_acl_data *acl; | |
4857 | int err; | |
4858 | ||
4859 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4860 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4861 | return -EOPNOTSUPP; | |
4862 | ||
7b0a0e3c | 4863 | if (!dev->ieee80211_ptr->links[0].ap.beacon_interval) |
77765eaf VT |
4864 | return -EINVAL; |
4865 | ||
4866 | acl = parse_acl_data(&rdev->wiphy, info); | |
4867 | if (IS_ERR(acl)) | |
4868 | return PTR_ERR(acl); | |
4869 | ||
4870 | err = rdev_set_mac_acl(rdev, dev, acl); | |
4871 | ||
4872 | kfree(acl); | |
4873 | ||
4874 | return err; | |
4875 | } | |
4876 | ||
a7c7fbff PK |
4877 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
4878 | u8 *rates, u8 rates_len) | |
4879 | { | |
4880 | u8 i; | |
4881 | u32 mask = 0; | |
4882 | ||
4883 | for (i = 0; i < rates_len; i++) { | |
4884 | int rate = (rates[i] & 0x7f) * 5; | |
4885 | int ridx; | |
4886 | ||
4887 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
4888 | struct ieee80211_rate *srate = | |
4889 | &sband->bitrates[ridx]; | |
4890 | if (rate == srate->bitrate) { | |
4891 | mask |= 1 << ridx; | |
4892 | break; | |
4893 | } | |
4894 | } | |
4895 | if (ridx == sband->n_bitrates) | |
4896 | return 0; /* rate not found */ | |
4897 | } | |
4898 | ||
4899 | return mask; | |
4900 | } | |
4901 | ||
4902 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, | |
4903 | u8 *rates, u8 rates_len, | |
4904 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
4905 | { | |
4906 | u8 i; | |
4907 | ||
4908 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
4909 | ||
4910 | for (i = 0; i < rates_len; i++) { | |
4911 | int ridx, rbit; | |
4912 | ||
4913 | ridx = rates[i] / 8; | |
4914 | rbit = BIT(rates[i] % 8); | |
4915 | ||
4916 | /* check validity */ | |
4917 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) | |
4918 | return false; | |
4919 | ||
4920 | /* check availability */ | |
30fe6d50 | 4921 | ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); |
a7c7fbff PK |
4922 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
4923 | mcs[ridx] |= rbit; | |
4924 | else | |
4925 | return false; | |
4926 | } | |
4927 | ||
4928 | return true; | |
4929 | } | |
4930 | ||
4931 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) | |
4932 | { | |
4933 | u16 mcs_mask = 0; | |
4934 | ||
4935 | switch (vht_mcs_map) { | |
4936 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
4937 | break; | |
4938 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
4939 | mcs_mask = 0x00FF; | |
4940 | break; | |
4941 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
4942 | mcs_mask = 0x01FF; | |
4943 | break; | |
4944 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
4945 | mcs_mask = 0x03FF; | |
4946 | break; | |
4947 | default: | |
4948 | break; | |
4949 | } | |
4950 | ||
4951 | return mcs_mask; | |
4952 | } | |
4953 | ||
4954 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
4955 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
4956 | { | |
4957 | u8 nss; | |
4958 | ||
4959 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
4960 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
4961 | vht_mcs_map >>= 2; | |
4962 | } | |
4963 | } | |
4964 | ||
4965 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
4966 | struct nl80211_txrate_vht *txrate, | |
4967 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
4968 | { | |
4969 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
4970 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
4971 | u8 i; | |
4972 | ||
4973 | if (!sband->vht_cap.vht_supported) | |
4974 | return false; | |
4975 | ||
4976 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
4977 | ||
4978 | /* Build vht_mcs_mask from VHT capabilities */ | |
4979 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
4980 | ||
4981 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
4982 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
4983 | mcs[i] = txrate->mcs[i]; | |
4984 | else | |
4985 | return false; | |
4986 | } | |
4987 | ||
4988 | return true; | |
4989 | } | |
4990 | ||
eb89a6a6 MH |
4991 | static u16 he_mcs_map_to_mcs_mask(u8 he_mcs_map) |
4992 | { | |
4993 | switch (he_mcs_map) { | |
4994 | case IEEE80211_HE_MCS_NOT_SUPPORTED: | |
4995 | return 0; | |
4996 | case IEEE80211_HE_MCS_SUPPORT_0_7: | |
4997 | return 0x00FF; | |
4998 | case IEEE80211_HE_MCS_SUPPORT_0_9: | |
4999 | return 0x03FF; | |
5000 | case IEEE80211_HE_MCS_SUPPORT_0_11: | |
5001 | return 0xFFF; | |
5002 | default: | |
5003 | break; | |
5004 | } | |
5005 | return 0; | |
5006 | } | |
5007 | ||
5008 | static void he_build_mcs_mask(u16 he_mcs_map, | |
5009 | u16 he_mcs_mask[NL80211_HE_NSS_MAX]) | |
5010 | { | |
5011 | u8 nss; | |
5012 | ||
5013 | for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) { | |
5014 | he_mcs_mask[nss] = he_mcs_map_to_mcs_mask(he_mcs_map & 0x03); | |
5015 | he_mcs_map >>= 2; | |
5016 | } | |
5017 | } | |
5018 | ||
7b0a0e3c | 5019 | static u16 he_get_txmcsmap(struct genl_info *info, unsigned int link_id, |
eb89a6a6 MH |
5020 | const struct ieee80211_sta_he_cap *he_cap) |
5021 | { | |
5022 | struct net_device *dev = info->user_ptr[1]; | |
5023 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7b0a0e3c JB |
5024 | struct cfg80211_chan_def *chandef; |
5025 | __le16 tx_mcs; | |
eb89a6a6 | 5026 | |
7b0a0e3c JB |
5027 | chandef = wdev_chandef(wdev, link_id); |
5028 | if (!chandef) { | |
5029 | /* | |
5030 | * This is probably broken, but we never maintained | |
5031 | * a chandef in these cases, so it always was. | |
5032 | */ | |
5033 | return le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80); | |
5034 | } | |
5035 | ||
5036 | switch (chandef->width) { | |
eb89a6a6 MH |
5037 | case NL80211_CHAN_WIDTH_80P80: |
5038 | tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80p80; | |
5039 | break; | |
5040 | case NL80211_CHAN_WIDTH_160: | |
5041 | tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_160; | |
5042 | break; | |
5043 | default: | |
5044 | tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80; | |
5045 | break; | |
5046 | } | |
7b0a0e3c | 5047 | |
eb89a6a6 MH |
5048 | return le16_to_cpu(tx_mcs); |
5049 | } | |
5050 | ||
5051 | static bool he_set_mcs_mask(struct genl_info *info, | |
5052 | struct wireless_dev *wdev, | |
5053 | struct ieee80211_supported_band *sband, | |
5054 | struct nl80211_txrate_he *txrate, | |
7b0a0e3c JB |
5055 | u16 mcs[NL80211_HE_NSS_MAX], |
5056 | unsigned int link_id) | |
eb89a6a6 MH |
5057 | { |
5058 | const struct ieee80211_sta_he_cap *he_cap; | |
5059 | u16 tx_mcs_mask[NL80211_HE_NSS_MAX] = {}; | |
5060 | u16 tx_mcs_map = 0; | |
5061 | u8 i; | |
5062 | ||
5063 | he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); | |
5064 | if (!he_cap) | |
5065 | return false; | |
5066 | ||
5067 | memset(mcs, 0, sizeof(u16) * NL80211_HE_NSS_MAX); | |
5068 | ||
7b0a0e3c | 5069 | tx_mcs_map = he_get_txmcsmap(info, link_id, he_cap); |
eb89a6a6 MH |
5070 | |
5071 | /* Build he_mcs_mask from HE capabilities */ | |
5072 | he_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
5073 | ||
5074 | for (i = 0; i < NL80211_HE_NSS_MAX; i++) { | |
5075 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
5076 | mcs[i] = txrate->mcs[i]; | |
5077 | else | |
5078 | return false; | |
5079 | } | |
5080 | ||
5081 | return true; | |
5082 | } | |
5083 | ||
a7c7fbff | 5084 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, |
9a5f6488 TC |
5085 | struct nlattr *attrs[], |
5086 | enum nl80211_attrs attr, | |
eb89a6a6 | 5087 | struct cfg80211_bitrate_mask *mask, |
857b34c4 | 5088 | struct net_device *dev, |
7b0a0e3c JB |
5089 | bool default_all_enabled, |
5090 | unsigned int link_id) | |
a7c7fbff PK |
5091 | { |
5092 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
5093 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
eb89a6a6 | 5094 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
a7c7fbff PK |
5095 | int rem, i; |
5096 | struct nlattr *tx_rates; | |
5097 | struct ieee80211_supported_band *sband; | |
eb89a6a6 | 5098 | u16 vht_tx_mcs_map, he_tx_mcs_map; |
a7c7fbff PK |
5099 | |
5100 | memset(mask, 0, sizeof(*mask)); | |
5101 | /* Default to all rates enabled */ | |
5102 | for (i = 0; i < NUM_NL80211_BANDS; i++) { | |
eb89a6a6 MH |
5103 | const struct ieee80211_sta_he_cap *he_cap; |
5104 | ||
857b34c4 RM |
5105 | if (!default_all_enabled) |
5106 | break; | |
5107 | ||
a7c7fbff PK |
5108 | sband = rdev->wiphy.bands[i]; |
5109 | ||
5110 | if (!sband) | |
5111 | continue; | |
5112 | ||
5113 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; | |
5114 | memcpy(mask->control[i].ht_mcs, | |
5115 | sband->ht_cap.mcs.rx_mask, | |
5116 | sizeof(mask->control[i].ht_mcs)); | |
5117 | ||
9df66d5b PKS |
5118 | if (sband->vht_cap.vht_supported) { |
5119 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
5120 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); | |
5121 | } | |
eb89a6a6 MH |
5122 | |
5123 | he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); | |
5124 | if (!he_cap) | |
5125 | continue; | |
5126 | ||
7b0a0e3c | 5127 | he_tx_mcs_map = he_get_txmcsmap(info, link_id, he_cap); |
eb89a6a6 MH |
5128 | he_build_mcs_mask(he_tx_mcs_map, mask->control[i].he_mcs); |
5129 | ||
5130 | mask->control[i].he_gi = 0xFF; | |
5131 | mask->control[i].he_ltf = 0xFF; | |
a7c7fbff PK |
5132 | } |
5133 | ||
5134 | /* if no rates are given set it back to the defaults */ | |
9a5f6488 | 5135 | if (!attrs[attr]) |
a7c7fbff PK |
5136 | goto out; |
5137 | ||
5138 | /* The nested attribute uses enum nl80211_band as the index. This maps | |
5139 | * directly to the enum nl80211_band values used in cfg80211. | |
5140 | */ | |
5141 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); | |
9a5f6488 | 5142 | nla_for_each_nested(tx_rates, attrs[attr], rem) { |
a7c7fbff PK |
5143 | enum nl80211_band band = nla_type(tx_rates); |
5144 | int err; | |
5145 | ||
5146 | if (band < 0 || band >= NUM_NL80211_BANDS) | |
5147 | return -EINVAL; | |
5148 | sband = rdev->wiphy.bands[band]; | |
5149 | if (sband == NULL) | |
5150 | return -EINVAL; | |
8cb08174 JB |
5151 | err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX, |
5152 | tx_rates, | |
5153 | nl80211_txattr_policy, | |
5154 | info->extack); | |
a7c7fbff PK |
5155 | if (err) |
5156 | return err; | |
5157 | if (tb[NL80211_TXRATE_LEGACY]) { | |
5158 | mask->control[band].legacy = rateset_to_mask( | |
5159 | sband, | |
5160 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
5161 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
5162 | if ((mask->control[band].legacy == 0) && | |
5163 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
5164 | return -EINVAL; | |
5165 | } | |
5166 | if (tb[NL80211_TXRATE_HT]) { | |
5167 | if (!ht_rateset_to_mask( | |
5168 | sband, | |
5169 | nla_data(tb[NL80211_TXRATE_HT]), | |
5170 | nla_len(tb[NL80211_TXRATE_HT]), | |
5171 | mask->control[band].ht_mcs)) | |
5172 | return -EINVAL; | |
5173 | } | |
c4a30446 | 5174 | |
a7c7fbff PK |
5175 | if (tb[NL80211_TXRATE_VHT]) { |
5176 | if (!vht_set_mcs_mask( | |
5177 | sband, | |
5178 | nla_data(tb[NL80211_TXRATE_VHT]), | |
5179 | mask->control[band].vht_mcs)) | |
5180 | return -EINVAL; | |
5181 | } | |
c4a30446 | 5182 | |
a7c7fbff PK |
5183 | if (tb[NL80211_TXRATE_GI]) { |
5184 | mask->control[band].gi = | |
5185 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
5186 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
5187 | return -EINVAL; | |
5188 | } | |
eb89a6a6 MH |
5189 | if (tb[NL80211_TXRATE_HE] && |
5190 | !he_set_mcs_mask(info, wdev, sband, | |
5191 | nla_data(tb[NL80211_TXRATE_HE]), | |
7b0a0e3c JB |
5192 | mask->control[band].he_mcs, |
5193 | link_id)) | |
eb89a6a6 | 5194 | return -EINVAL; |
c4a30446 | 5195 | |
eb89a6a6 MH |
5196 | if (tb[NL80211_TXRATE_HE_GI]) |
5197 | mask->control[band].he_gi = | |
5198 | nla_get_u8(tb[NL80211_TXRATE_HE_GI]); | |
5199 | if (tb[NL80211_TXRATE_HE_LTF]) | |
5200 | mask->control[band].he_ltf = | |
5201 | nla_get_u8(tb[NL80211_TXRATE_HE_LTF]); | |
a7c7fbff PK |
5202 | |
5203 | if (mask->control[band].legacy == 0) { | |
eb89a6a6 | 5204 | /* don't allow empty legacy rates if HT, VHT or HE |
a7c7fbff PK |
5205 | * are not even supported. |
5206 | */ | |
5207 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
eb89a6a6 MH |
5208 | rdev->wiphy.bands[band]->vht_cap.vht_supported || |
5209 | ieee80211_get_he_iftype_cap(sband, wdev->iftype))) | |
a7c7fbff PK |
5210 | return -EINVAL; |
5211 | ||
5212 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
5213 | if (mask->control[band].ht_mcs[i]) | |
5214 | goto out; | |
5215 | ||
5216 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
5217 | if (mask->control[band].vht_mcs[i]) | |
5218 | goto out; | |
5219 | ||
eb89a6a6 MH |
5220 | for (i = 0; i < NL80211_HE_NSS_MAX; i++) |
5221 | if (mask->control[band].he_mcs[i]) | |
5222 | goto out; | |
5223 | ||
a7c7fbff PK |
5224 | /* legacy and mcs rates may not be both empty */ |
5225 | return -EINVAL; | |
5226 | } | |
5227 | } | |
5228 | ||
5229 | out: | |
5230 | return 0; | |
5231 | } | |
5232 | ||
8564e382 JB |
5233 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
5234 | enum nl80211_band band, | |
5235 | struct cfg80211_bitrate_mask *beacon_rate) | |
a7c7fbff | 5236 | { |
c4a30446 | 5237 | u32 count_ht, count_vht, count_he, i; |
8564e382 | 5238 | u32 rate = beacon_rate->control[band].legacy; |
a7c7fbff PK |
5239 | |
5240 | /* Allow only one rate */ | |
5241 | if (hweight32(rate) > 1) | |
5242 | return -EINVAL; | |
5243 | ||
5244 | count_ht = 0; | |
5245 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { | |
8564e382 | 5246 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
a7c7fbff | 5247 | return -EINVAL; |
8564e382 | 5248 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
a7c7fbff PK |
5249 | count_ht++; |
5250 | if (count_ht > 1) | |
5251 | return -EINVAL; | |
5252 | } | |
5253 | if (count_ht && rate) | |
5254 | return -EINVAL; | |
5255 | } | |
5256 | ||
5257 | count_vht = 0; | |
5258 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
8564e382 | 5259 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
a7c7fbff | 5260 | return -EINVAL; |
8564e382 | 5261 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
a7c7fbff PK |
5262 | count_vht++; |
5263 | if (count_vht > 1) | |
5264 | return -EINVAL; | |
5265 | } | |
5266 | if (count_vht && rate) | |
5267 | return -EINVAL; | |
5268 | } | |
5269 | ||
c4a30446 RM |
5270 | count_he = 0; |
5271 | for (i = 0; i < NL80211_HE_NSS_MAX; i++) { | |
5272 | if (hweight16(beacon_rate->control[band].he_mcs[i]) > 1) { | |
5273 | return -EINVAL; | |
5274 | } else if (beacon_rate->control[band].he_mcs[i]) { | |
5275 | count_he++; | |
5276 | if (count_he > 1) | |
5277 | return -EINVAL; | |
5278 | } | |
5279 | if (count_he && rate) | |
5280 | return -EINVAL; | |
5281 | } | |
5282 | ||
5283 | if ((count_ht && count_vht && count_he) || | |
5284 | (!rate && !count_ht && !count_vht && !count_he)) | |
a7c7fbff PK |
5285 | return -EINVAL; |
5286 | ||
8564e382 JB |
5287 | if (rate && |
5288 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
5289 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) | |
5290 | return -EINVAL; | |
5291 | if (count_ht && | |
5292 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
5293 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) | |
5294 | return -EINVAL; | |
5295 | if (count_vht && | |
5296 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
5297 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) | |
5298 | return -EINVAL; | |
c4a30446 RM |
5299 | if (count_he && |
5300 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
5301 | NL80211_EXT_FEATURE_BEACON_RATE_HE)) | |
5302 | return -EINVAL; | |
8564e382 | 5303 | |
a7c7fbff PK |
5304 | return 0; |
5305 | } | |
5306 | ||
dc1e3cb8 JC |
5307 | static int nl80211_parse_mbssid_config(struct wiphy *wiphy, |
5308 | struct net_device *dev, | |
5309 | struct nlattr *attrs, | |
5310 | struct cfg80211_mbssid_config *config, | |
5311 | u8 num_elems) | |
5312 | { | |
5313 | struct nlattr *tb[NL80211_MBSSID_CONFIG_ATTR_MAX + 1]; | |
5314 | ||
5315 | if (!wiphy->mbssid_max_interfaces) | |
5316 | return -EOPNOTSUPP; | |
5317 | ||
5318 | if (nla_parse_nested(tb, NL80211_MBSSID_CONFIG_ATTR_MAX, attrs, NULL, | |
5319 | NULL) || | |
5320 | !tb[NL80211_MBSSID_CONFIG_ATTR_INDEX]) | |
5321 | return -EINVAL; | |
5322 | ||
5323 | config->ema = nla_get_flag(tb[NL80211_MBSSID_CONFIG_ATTR_EMA]); | |
5324 | if (config->ema) { | |
5325 | if (!wiphy->ema_max_profile_periodicity) | |
5326 | return -EOPNOTSUPP; | |
5327 | ||
5328 | if (num_elems > wiphy->ema_max_profile_periodicity) | |
5329 | return -EINVAL; | |
5330 | } | |
5331 | ||
5332 | config->index = nla_get_u8(tb[NL80211_MBSSID_CONFIG_ATTR_INDEX]); | |
5333 | if (config->index >= wiphy->mbssid_max_interfaces || | |
5334 | (!config->index && !num_elems)) | |
5335 | return -EINVAL; | |
5336 | ||
5337 | if (tb[NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX]) { | |
5338 | u32 tx_ifindex = | |
5339 | nla_get_u32(tb[NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX]); | |
5340 | ||
5341 | if ((!config->index && tx_ifindex != dev->ifindex) || | |
5342 | (config->index && tx_ifindex == dev->ifindex)) | |
5343 | return -EINVAL; | |
5344 | ||
5345 | if (tx_ifindex != dev->ifindex) { | |
5346 | struct net_device *tx_netdev = | |
5347 | dev_get_by_index(wiphy_net(wiphy), tx_ifindex); | |
5348 | ||
5349 | if (!tx_netdev || !tx_netdev->ieee80211_ptr || | |
5350 | tx_netdev->ieee80211_ptr->wiphy != wiphy || | |
5351 | tx_netdev->ieee80211_ptr->iftype != | |
5352 | NL80211_IFTYPE_AP) { | |
5353 | dev_put(tx_netdev); | |
5354 | return -EINVAL; | |
5355 | } | |
5356 | ||
5357 | config->tx_wdev = tx_netdev->ieee80211_ptr; | |
5358 | } else { | |
5359 | config->tx_wdev = dev->ieee80211_ptr; | |
5360 | } | |
5361 | } else if (!config->index) { | |
5362 | config->tx_wdev = dev->ieee80211_ptr; | |
5363 | } else { | |
5364 | return -EINVAL; | |
5365 | } | |
5366 | ||
5367 | return 0; | |
5368 | } | |
5369 | ||
5370 | static struct cfg80211_mbssid_elems * | |
5371 | nl80211_parse_mbssid_elems(struct wiphy *wiphy, struct nlattr *attrs) | |
5372 | { | |
5373 | struct nlattr *nl_elems; | |
5374 | struct cfg80211_mbssid_elems *elems; | |
5375 | int rem_elems; | |
5376 | u8 i = 0, num_elems = 0; | |
5377 | ||
5378 | if (!wiphy->mbssid_max_interfaces) | |
5379 | return ERR_PTR(-EINVAL); | |
5380 | ||
5381 | nla_for_each_nested(nl_elems, attrs, rem_elems) | |
5382 | num_elems++; | |
5383 | ||
5384 | elems = kzalloc(struct_size(elems, elem, num_elems), GFP_KERNEL); | |
5385 | if (!elems) | |
5386 | return ERR_PTR(-ENOMEM); | |
5387 | ||
5388 | nla_for_each_nested(nl_elems, attrs, rem_elems) { | |
5389 | elems->elem[i].data = nla_data(nl_elems); | |
5390 | elems->elem[i].len = nla_len(nl_elems); | |
5391 | i++; | |
5392 | } | |
5393 | elems->cnt = num_elems; | |
5394 | return elems; | |
5395 | } | |
5396 | ||
3d48cb74 RS |
5397 | static int nl80211_parse_he_bss_color(struct nlattr *attrs, |
5398 | struct cfg80211_he_bss_color *he_bss_color) | |
5399 | { | |
5400 | struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1]; | |
5401 | int err; | |
5402 | ||
5403 | err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs, | |
5404 | he_bss_color_policy, NULL); | |
5405 | if (err) | |
5406 | return err; | |
5407 | ||
5408 | if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]) | |
5409 | return -EINVAL; | |
5410 | ||
5411 | he_bss_color->color = | |
5412 | nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]); | |
5413 | he_bss_color->enabled = | |
5414 | !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]); | |
5415 | he_bss_color->partial = | |
5416 | nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]); | |
5417 | ||
5418 | return 0; | |
5419 | } | |
5420 | ||
81e54d08 PKC |
5421 | static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev, |
5422 | struct nlattr *attrs[], | |
8860020e | 5423 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 5424 | { |
8860020e | 5425 | bool haveinfo = false; |
81e54d08 | 5426 | int err; |
ed1b6cc7 | 5427 | |
8860020e | 5428 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 5429 | |
7b0a0e3c JB |
5430 | bcn->link_id = nl80211_link_id(attrs); |
5431 | ||
a1193be8 SW |
5432 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
5433 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
5434 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
5435 | if (!bcn->head_len) |
5436 | return -EINVAL; | |
5437 | haveinfo = true; | |
ed1b6cc7 JB |
5438 | } |
5439 | ||
a1193be8 SW |
5440 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
5441 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
5442 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 5443 | haveinfo = true; |
ed1b6cc7 JB |
5444 | } |
5445 | ||
4c476991 JB |
5446 | if (!haveinfo) |
5447 | return -EINVAL; | |
3b85875a | 5448 | |
a1193be8 SW |
5449 | if (attrs[NL80211_ATTR_IE]) { |
5450 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
5451 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
5452 | } |
5453 | ||
a1193be8 | 5454 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 5455 | bcn->proberesp_ies = |
a1193be8 | 5456 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 5457 | bcn->proberesp_ies_len = |
a1193be8 | 5458 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
5459 | } |
5460 | ||
a1193be8 | 5461 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 5462 | bcn->assocresp_ies = |
a1193be8 | 5463 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 5464 | bcn->assocresp_ies_len = |
a1193be8 | 5465 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
5466 | } |
5467 | ||
a1193be8 SW |
5468 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
5469 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
5470 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
5471 | } |
5472 | ||
81e54d08 PKC |
5473 | if (attrs[NL80211_ATTR_FTM_RESPONDER]) { |
5474 | struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1]; | |
5475 | ||
8cb08174 JB |
5476 | err = nla_parse_nested_deprecated(tb, |
5477 | NL80211_FTM_RESP_ATTR_MAX, | |
5478 | attrs[NL80211_ATTR_FTM_RESPONDER], | |
5479 | NULL, NULL); | |
81e54d08 PKC |
5480 | if (err) |
5481 | return err; | |
5482 | ||
5483 | if (tb[NL80211_FTM_RESP_ATTR_ENABLED] && | |
5484 | wiphy_ext_feature_isset(&rdev->wiphy, | |
5485 | NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER)) | |
5486 | bcn->ftm_responder = 1; | |
5487 | else | |
5488 | return -EOPNOTSUPP; | |
5489 | ||
5490 | if (tb[NL80211_FTM_RESP_ATTR_LCI]) { | |
5491 | bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]); | |
5492 | bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]); | |
5493 | } | |
5494 | ||
5495 | if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) { | |
5496 | bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); | |
5497 | bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); | |
5498 | } | |
5499 | } else { | |
5500 | bcn->ftm_responder = -1; | |
5501 | } | |
5502 | ||
3d48cb74 RS |
5503 | if (attrs[NL80211_ATTR_HE_BSS_COLOR]) { |
5504 | err = nl80211_parse_he_bss_color(attrs[NL80211_ATTR_HE_BSS_COLOR], | |
5505 | &bcn->he_bss_color); | |
5506 | if (err) | |
5507 | return err; | |
5508 | bcn->he_bss_color_valid = true; | |
5509 | } | |
5510 | ||
dc1e3cb8 JC |
5511 | if (attrs[NL80211_ATTR_MBSSID_ELEMS]) { |
5512 | struct cfg80211_mbssid_elems *mbssid = | |
5513 | nl80211_parse_mbssid_elems(&rdev->wiphy, | |
5514 | attrs[NL80211_ATTR_MBSSID_ELEMS]); | |
5515 | ||
5516 | if (IS_ERR(mbssid)) | |
5517 | return PTR_ERR(mbssid); | |
5518 | ||
5519 | bcn->mbssid_ies = mbssid; | |
5520 | } | |
5521 | ||
8860020e JB |
5522 | return 0; |
5523 | } | |
5524 | ||
796e90f4 JC |
5525 | static int nl80211_parse_he_obss_pd(struct nlattr *attrs, |
5526 | struct ieee80211_he_obss_pd *he_obss_pd) | |
5527 | { | |
5528 | struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1]; | |
5529 | int err; | |
5530 | ||
5531 | err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs, | |
5532 | he_obss_pd_policy, NULL); | |
5533 | if (err) | |
5534 | return err; | |
5535 | ||
f5bec330 RM |
5536 | if (!tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]) |
5537 | return -EINVAL; | |
5538 | ||
5539 | he_obss_pd->sr_ctrl = nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]); | |
5540 | ||
6c8b6e4a RM |
5541 | if (tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]) |
5542 | he_obss_pd->min_offset = | |
5543 | nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]); | |
5544 | if (tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]) | |
5545 | he_obss_pd->max_offset = | |
5546 | nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]); | |
f5bec330 RM |
5547 | if (tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]) |
5548 | he_obss_pd->non_srg_max_offset = | |
5549 | nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]); | |
6c8b6e4a RM |
5550 | |
5551 | if (he_obss_pd->min_offset > he_obss_pd->max_offset) | |
796e90f4 JC |
5552 | return -EINVAL; |
5553 | ||
f5bec330 RM |
5554 | if (tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]) |
5555 | memcpy(he_obss_pd->bss_color_bitmap, | |
5556 | nla_data(tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]), | |
5557 | sizeof(he_obss_pd->bss_color_bitmap)); | |
5558 | ||
5559 | if (tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]) | |
5560 | memcpy(he_obss_pd->partial_bssid_bitmap, | |
5561 | nla_data(tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]), | |
5562 | sizeof(he_obss_pd->partial_bssid_bitmap)); | |
5563 | ||
796e90f4 JC |
5564 | he_obss_pd->enable = true; |
5565 | ||
5566 | return 0; | |
5567 | } | |
5568 | ||
291c49de AD |
5569 | static int nl80211_parse_fils_discovery(struct cfg80211_registered_device *rdev, |
5570 | struct nlattr *attrs, | |
5571 | struct cfg80211_ap_settings *params) | |
5572 | { | |
5573 | struct nlattr *tb[NL80211_FILS_DISCOVERY_ATTR_MAX + 1]; | |
5574 | int ret; | |
5575 | struct cfg80211_fils_discovery *fd = ¶ms->fils_discovery; | |
5576 | ||
5577 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
5578 | NL80211_EXT_FEATURE_FILS_DISCOVERY)) | |
5579 | return -EINVAL; | |
5580 | ||
5581 | ret = nla_parse_nested(tb, NL80211_FILS_DISCOVERY_ATTR_MAX, attrs, | |
5582 | NULL, NULL); | |
5583 | if (ret) | |
5584 | return ret; | |
5585 | ||
5586 | if (!tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN] || | |
5587 | !tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX] || | |
5588 | !tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]) | |
5589 | return -EINVAL; | |
5590 | ||
5591 | fd->tmpl_len = nla_len(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); | |
5592 | fd->tmpl = nla_data(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); | |
5593 | fd->min_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN]); | |
5594 | fd->max_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX]); | |
5595 | ||
5596 | return 0; | |
5597 | } | |
5598 | ||
7443dcd1 AD |
5599 | static int |
5600 | nl80211_parse_unsol_bcast_probe_resp(struct cfg80211_registered_device *rdev, | |
5601 | struct nlattr *attrs, | |
5602 | struct cfg80211_ap_settings *params) | |
5603 | { | |
5604 | struct nlattr *tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1]; | |
5605 | int ret; | |
5606 | struct cfg80211_unsol_bcast_probe_resp *presp = | |
5607 | ¶ms->unsol_bcast_probe_resp; | |
5608 | ||
5609 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
5610 | NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP)) | |
5611 | return -EINVAL; | |
5612 | ||
5613 | ret = nla_parse_nested(tb, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX, | |
5614 | attrs, NULL, NULL); | |
5615 | if (ret) | |
5616 | return ret; | |
5617 | ||
5618 | if (!tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] || | |
5619 | !tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]) | |
5620 | return -EINVAL; | |
5621 | ||
5622 | presp->tmpl = nla_data(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]); | |
5623 | presp->tmpl_len = nla_len(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]); | |
5624 | presp->interval = nla_get_u32(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT]); | |
5625 | return 0; | |
5626 | } | |
5627 | ||
66cd794e | 5628 | static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, |
153e2a11 | 5629 | const struct element *rates) |
66cd794e JB |
5630 | { |
5631 | int i; | |
5632 | ||
5633 | if (!rates) | |
5634 | return; | |
5635 | ||
153e2a11 JB |
5636 | for (i = 0; i < rates->datalen; i++) { |
5637 | if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) | |
66cd794e | 5638 | params->ht_required = true; |
153e2a11 | 5639 | if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) |
66cd794e | 5640 | params->vht_required = true; |
153e2a11 | 5641 | if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY) |
2a392596 | 5642 | params->he_required = true; |
153e2a11 | 5643 | if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_SAE_H2E) |
d6587602 | 5644 | params->sae_h2e_required = true; |
66cd794e JB |
5645 | } |
5646 | } | |
5647 | ||
5648 | /* | |
5649 | * Since the nl80211 API didn't include, from the beginning, attributes about | |
5650 | * HT/VHT requirements/capabilities, we parse them out of the IEs for the | |
5651 | * benefit of drivers that rebuild IEs in the firmware. | |
5652 | */ | |
8bc65d38 | 5653 | static int nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) |
66cd794e JB |
5654 | { |
5655 | const struct cfg80211_beacon_data *bcn = ¶ms->beacon; | |
ba83bfb1 IM |
5656 | size_t ies_len = bcn->tail_len; |
5657 | const u8 *ies = bcn->tail; | |
153e2a11 JB |
5658 | const struct element *rates; |
5659 | const struct element *cap; | |
66cd794e | 5660 | |
153e2a11 | 5661 | rates = cfg80211_find_elem(WLAN_EID_SUPP_RATES, ies, ies_len); |
66cd794e JB |
5662 | nl80211_check_ap_rate_selectors(params, rates); |
5663 | ||
153e2a11 | 5664 | rates = cfg80211_find_elem(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); |
66cd794e JB |
5665 | nl80211_check_ap_rate_selectors(params, rates); |
5666 | ||
153e2a11 JB |
5667 | cap = cfg80211_find_elem(WLAN_EID_HT_CAPABILITY, ies, ies_len); |
5668 | if (cap && cap->datalen >= sizeof(*params->ht_cap)) | |
5669 | params->ht_cap = (void *)cap->data; | |
5670 | cap = cfg80211_find_elem(WLAN_EID_VHT_CAPABILITY, ies, ies_len); | |
5671 | if (cap && cap->datalen >= sizeof(*params->vht_cap)) | |
5672 | params->vht_cap = (void *)cap->data; | |
5673 | cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len); | |
5674 | if (cap && cap->datalen >= sizeof(*params->he_cap) + 1) | |
5675 | params->he_cap = (void *)(cap->data + 1); | |
5676 | cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_OPERATION, ies, ies_len); | |
5677 | if (cap && cap->datalen >= sizeof(*params->he_oper) + 1) | |
5678 | params->he_oper = (void *)(cap->data + 1); | |
8bc65d38 AD |
5679 | cap = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_CAPABILITY, ies, ies_len); |
5680 | if (cap) { | |
5681 | if (!cap->datalen) | |
5682 | return -EINVAL; | |
5683 | params->eht_cap = (void *)(cap->data + 1); | |
5684 | if (!ieee80211_eht_capa_size_ok((const u8 *)params->he_cap, | |
5685 | (const u8 *)params->eht_cap, | |
ea5cba26 | 5686 | cap->datalen - 1, true)) |
8bc65d38 AD |
5687 | return -EINVAL; |
5688 | } | |
5689 | cap = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_OPERATION, ies, ies_len); | |
5690 | if (cap) { | |
5691 | if (!cap->datalen) | |
5692 | return -EINVAL; | |
5693 | params->eht_oper = (void *)(cap->data + 1); | |
5694 | if (!ieee80211_eht_oper_size_ok((const u8 *)params->eht_oper, | |
5695 | cap->datalen - 1)) | |
5696 | return -EINVAL; | |
5697 | } | |
5698 | return 0; | |
66cd794e JB |
5699 | } |
5700 | ||
46c1dd0c FF |
5701 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
5702 | struct cfg80211_ap_settings *params) | |
5703 | { | |
5704 | struct wireless_dev *wdev; | |
46c1dd0c | 5705 | |
53873f13 | 5706 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
46c1dd0c FF |
5707 | if (wdev->iftype != NL80211_IFTYPE_AP && |
5708 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
5709 | continue; | |
5710 | ||
7b0a0e3c | 5711 | if (!wdev->u.ap.preset_chandef.chan) |
46c1dd0c FF |
5712 | continue; |
5713 | ||
7b0a0e3c JB |
5714 | params->chandef = wdev->u.ap.preset_chandef; |
5715 | return true; | |
46c1dd0c FF |
5716 | } |
5717 | ||
7b0a0e3c | 5718 | return false; |
46c1dd0c FF |
5719 | } |
5720 | ||
e39e5b5e JM |
5721 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
5722 | enum nl80211_auth_type auth_type, | |
5723 | enum nl80211_commands cmd) | |
5724 | { | |
5725 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
5726 | return false; | |
5727 | ||
5728 | switch (cmd) { | |
5729 | case NL80211_CMD_AUTHENTICATE: | |
5730 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
5731 | auth_type == NL80211_AUTHTYPE_SAE) | |
5732 | return false; | |
63181060 JM |
5733 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
5734 | NL80211_EXT_FEATURE_FILS_STA) && | |
5735 | (auth_type == NL80211_AUTHTYPE_FILS_SK || | |
5736 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || | |
5737 | auth_type == NL80211_AUTHTYPE_FILS_PK)) | |
5738 | return false; | |
e39e5b5e JM |
5739 | return true; |
5740 | case NL80211_CMD_CONNECT: | |
10773a7c | 5741 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
26f7044e CHH |
5742 | !wiphy_ext_feature_isset(&rdev->wiphy, |
5743 | NL80211_EXT_FEATURE_SAE_OFFLOAD) && | |
10773a7c | 5744 | auth_type == NL80211_AUTHTYPE_SAE) |
a3caf744 | 5745 | return false; |
10773a7c | 5746 | |
a3caf744 VK |
5747 | /* FILS with SK PFS or PK not supported yet */ |
5748 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || | |
5749 | auth_type == NL80211_AUTHTYPE_FILS_PK) | |
5750 | return false; | |
5751 | if (!wiphy_ext_feature_isset( | |
5752 | &rdev->wiphy, | |
5753 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && | |
5754 | auth_type == NL80211_AUTHTYPE_FILS_SK) | |
5755 | return false; | |
5756 | return true; | |
e39e5b5e | 5757 | case NL80211_CMD_START_AP: |
2831a631 CHH |
5758 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
5759 | NL80211_EXT_FEATURE_SAE_OFFLOAD_AP) && | |
5760 | auth_type == NL80211_AUTHTYPE_SAE) | |
e39e5b5e | 5761 | return false; |
63181060 JM |
5762 | /* FILS not supported yet */ |
5763 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || | |
5764 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || | |
5765 | auth_type == NL80211_AUTHTYPE_FILS_PK) | |
5766 | return false; | |
e39e5b5e JM |
5767 | return true; |
5768 | default: | |
5769 | return false; | |
5770 | } | |
5771 | } | |
5772 | ||
8860020e JB |
5773 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
5774 | { | |
5775 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7b0a0e3c | 5776 | unsigned int link_id = nl80211_link_id(info->attrs); |
8860020e JB |
5777 | struct net_device *dev = info->user_ptr[1]; |
5778 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9e263e19 | 5779 | struct cfg80211_ap_settings *params; |
8860020e JB |
5780 | int err; |
5781 | ||
5782 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
5783 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
5784 | return -EOPNOTSUPP; | |
5785 | ||
5786 | if (!rdev->ops->start_ap) | |
5787 | return -EOPNOTSUPP; | |
5788 | ||
7b0a0e3c | 5789 | if (wdev->links[link_id].ap.beacon_interval) |
8860020e JB |
5790 | return -EALREADY; |
5791 | ||
8860020e JB |
5792 | /* these are required for START_AP */ |
5793 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
5794 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
5795 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
5796 | return -EINVAL; | |
5797 | ||
9e263e19 JB |
5798 | params = kzalloc(sizeof(*params), GFP_KERNEL); |
5799 | if (!params) | |
5800 | return -ENOMEM; | |
5801 | ||
5802 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms->beacon); | |
8860020e | 5803 | if (err) |
9e263e19 | 5804 | goto out; |
8860020e | 5805 | |
9e263e19 | 5806 | params->beacon_interval = |
8860020e | 5807 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
9e263e19 | 5808 | params->dtim_period = |
8860020e JB |
5809 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
5810 | ||
0c317a02 | 5811 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
9e263e19 | 5812 | params->beacon_interval); |
8860020e | 5813 | if (err) |
9e263e19 | 5814 | goto out; |
8860020e JB |
5815 | |
5816 | /* | |
5817 | * In theory, some of these attributes should be required here | |
5818 | * but since they were not used when the command was originally | |
5819 | * added, keep them optional for old user space programs to let | |
5820 | * them continue to work with drivers that do not need the | |
5821 | * additional information -- drivers must check! | |
5822 | */ | |
5823 | if (info->attrs[NL80211_ATTR_SSID]) { | |
9e263e19 JB |
5824 | params->ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
5825 | params->ssid_len = | |
8860020e | 5826 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
9e263e19 JB |
5827 | if (params->ssid_len == 0) { |
5828 | err = -EINVAL; | |
5829 | goto out; | |
5830 | } | |
7b0a0e3c JB |
5831 | |
5832 | if (wdev->u.ap.ssid_len && | |
5833 | (wdev->u.ap.ssid_len != params->ssid_len || | |
5834 | memcmp(wdev->u.ap.ssid, params->ssid, params->ssid_len))) { | |
5835 | /* require identical SSID for MLO */ | |
5836 | err = -EINVAL; | |
5837 | goto out; | |
5838 | } | |
5839 | } else if (wdev->valid_links) { | |
5840 | /* require SSID for MLO */ | |
5841 | err = -EINVAL; | |
5842 | goto out; | |
8860020e JB |
5843 | } |
5844 | ||
ab0d76f6 | 5845 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) |
9e263e19 | 5846 | params->hidden_ssid = nla_get_u32( |
8860020e | 5847 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
8860020e | 5848 | |
9e263e19 | 5849 | params->privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
8860020e JB |
5850 | |
5851 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
9e263e19 | 5852 | params->auth_type = nla_get_u32( |
8860020e | 5853 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
9e263e19 JB |
5854 | if (!nl80211_valid_auth_type(rdev, params->auth_type, |
5855 | NL80211_CMD_START_AP)) { | |
5856 | err = -EINVAL; | |
5857 | goto out; | |
5858 | } | |
8860020e | 5859 | } else |
9e263e19 | 5860 | params->auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
8860020e | 5861 | |
9e263e19 | 5862 | err = nl80211_crypto_settings(rdev, info, ¶ms->crypto, |
8860020e JB |
5863 | NL80211_MAX_NR_CIPHER_SUITES); |
5864 | if (err) | |
9e263e19 | 5865 | goto out; |
8860020e | 5866 | |
1b658f11 | 5867 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
9e263e19 JB |
5868 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) { |
5869 | err = -EOPNOTSUPP; | |
5870 | goto out; | |
5871 | } | |
5872 | params->inactivity_timeout = nla_get_u16( | |
1b658f11 VT |
5873 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
5874 | } | |
5875 | ||
53cabad7 | 5876 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
9e263e19 JB |
5877 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
5878 | err = -EINVAL; | |
5879 | goto out; | |
5880 | } | |
5881 | params->p2p_ctwindow = | |
53cabad7 | 5882 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
9e263e19 JB |
5883 | if (params->p2p_ctwindow != 0 && |
5884 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) { | |
5885 | err = -EINVAL; | |
5886 | goto out; | |
5887 | } | |
53cabad7 JB |
5888 | } |
5889 | ||
5890 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
5891 | u8 tmp; | |
5892 | ||
9e263e19 JB |
5893 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
5894 | err = -EINVAL; | |
5895 | goto out; | |
5896 | } | |
53cabad7 | 5897 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
9e263e19 JB |
5898 | params->p2p_opp_ps = tmp; |
5899 | if (params->p2p_opp_ps != 0 && | |
5900 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) { | |
5901 | err = -EINVAL; | |
5902 | goto out; | |
5903 | } | |
53cabad7 JB |
5904 | } |
5905 | ||
aa430da4 | 5906 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
9e263e19 | 5907 | err = nl80211_parse_chandef(rdev, info, ¶ms->chandef); |
683b6d3b | 5908 | if (err) |
9e263e19 | 5909 | goto out; |
7b0a0e3c JB |
5910 | } else if (wdev->valid_links) { |
5911 | /* with MLD need to specify the channel configuration */ | |
5912 | err = -EINVAL; | |
5913 | goto out; | |
5914 | } else if (wdev->u.ap.preset_chandef.chan) { | |
5915 | params->chandef = wdev->u.ap.preset_chandef; | |
9e263e19 JB |
5916 | } else if (!nl80211_get_ap_channel(rdev, params)) { |
5917 | err = -EINVAL; | |
5918 | goto out; | |
5919 | } | |
aa430da4 | 5920 | |
9e263e19 JB |
5921 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms->chandef, |
5922 | wdev->iftype)) { | |
5923 | err = -EINVAL; | |
5924 | goto out; | |
5925 | } | |
aa430da4 | 5926 | |
c2653990 JB |
5927 | wdev_lock(wdev); |
5928 | ||
a7c7fbff | 5929 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
9a5f6488 TC |
5930 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
5931 | NL80211_ATTR_TX_RATES, | |
9e263e19 | 5932 | ¶ms->beacon_rate, |
7b0a0e3c | 5933 | dev, false, link_id); |
a7c7fbff | 5934 | if (err) |
c2653990 | 5935 | goto out_unlock; |
a7c7fbff | 5936 | |
9e263e19 JB |
5937 | err = validate_beacon_tx_rate(rdev, params->chandef.chan->band, |
5938 | ¶ms->beacon_rate); | |
a7c7fbff | 5939 | if (err) |
c2653990 | 5940 | goto out_unlock; |
a7c7fbff PK |
5941 | } |
5942 | ||
18998c38 | 5943 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
9e263e19 | 5944 | params->smps_mode = |
18998c38 | 5945 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
9e263e19 | 5946 | switch (params->smps_mode) { |
18998c38 EP |
5947 | case NL80211_SMPS_OFF: |
5948 | break; | |
5949 | case NL80211_SMPS_STATIC: | |
5950 | if (!(rdev->wiphy.features & | |
9e263e19 JB |
5951 | NL80211_FEATURE_STATIC_SMPS)) { |
5952 | err = -EINVAL; | |
c2653990 | 5953 | goto out_unlock; |
9e263e19 | 5954 | } |
18998c38 EP |
5955 | break; |
5956 | case NL80211_SMPS_DYNAMIC: | |
5957 | if (!(rdev->wiphy.features & | |
9e263e19 JB |
5958 | NL80211_FEATURE_DYNAMIC_SMPS)) { |
5959 | err = -EINVAL; | |
c2653990 | 5960 | goto out_unlock; |
9e263e19 | 5961 | } |
18998c38 EP |
5962 | break; |
5963 | default: | |
9e263e19 | 5964 | err = -EINVAL; |
c2653990 | 5965 | goto out_unlock; |
18998c38 EP |
5966 | } |
5967 | } else { | |
9e263e19 | 5968 | params->smps_mode = NL80211_SMPS_OFF; |
18998c38 EP |
5969 | } |
5970 | ||
9e263e19 JB |
5971 | params->pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
5972 | if (params->pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { | |
5973 | err = -EOPNOTSUPP; | |
c2653990 | 5974 | goto out_unlock; |
9e263e19 | 5975 | } |
6e8ef842 | 5976 | |
4baf6bea | 5977 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
9e263e19 JB |
5978 | params->acl = parse_acl_data(&rdev->wiphy, info); |
5979 | if (IS_ERR(params->acl)) { | |
5980 | err = PTR_ERR(params->acl); | |
05075fe7 | 5981 | params->acl = NULL; |
c2653990 | 5982 | goto out_unlock; |
9e263e19 | 5983 | } |
4baf6bea OO |
5984 | } |
5985 | ||
9e263e19 | 5986 | params->twt_responder = |
a0de1ca3 JC |
5987 | nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]); |
5988 | ||
796e90f4 JC |
5989 | if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) { |
5990 | err = nl80211_parse_he_obss_pd( | |
5991 | info->attrs[NL80211_ATTR_HE_OBSS_PD], | |
9e263e19 | 5992 | ¶ms->he_obss_pd); |
bc7a39b4 | 5993 | if (err) |
c2653990 | 5994 | goto out_unlock; |
796e90f4 JC |
5995 | } |
5996 | ||
291c49de AD |
5997 | if (info->attrs[NL80211_ATTR_FILS_DISCOVERY]) { |
5998 | err = nl80211_parse_fils_discovery(rdev, | |
5999 | info->attrs[NL80211_ATTR_FILS_DISCOVERY], | |
9e263e19 | 6000 | params); |
291c49de | 6001 | if (err) |
c2653990 | 6002 | goto out_unlock; |
291c49de AD |
6003 | } |
6004 | ||
7443dcd1 AD |
6005 | if (info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP]) { |
6006 | err = nl80211_parse_unsol_bcast_probe_resp( | |
6007 | rdev, info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP], | |
9e263e19 | 6008 | params); |
7443dcd1 | 6009 | if (err) |
c2653990 | 6010 | goto out_unlock; |
7443dcd1 AD |
6011 | } |
6012 | ||
dc1e3cb8 JC |
6013 | if (info->attrs[NL80211_ATTR_MBSSID_CONFIG]) { |
6014 | err = nl80211_parse_mbssid_config(&rdev->wiphy, dev, | |
6015 | info->attrs[NL80211_ATTR_MBSSID_CONFIG], | |
6016 | ¶ms->mbssid_config, | |
6017 | params->beacon.mbssid_ies ? | |
6018 | params->beacon.mbssid_ies->cnt : | |
6019 | 0); | |
6020 | if (err) | |
c2653990 | 6021 | goto out_unlock; |
dc1e3cb8 JC |
6022 | } |
6023 | ||
8bc65d38 AD |
6024 | err = nl80211_calculate_ap_params(params); |
6025 | if (err) | |
6026 | goto out_unlock; | |
66cd794e | 6027 | |
47301a74 VJ |
6028 | if (info->attrs[NL80211_ATTR_AP_SETTINGS_FLAGS]) |
6029 | params->flags = nla_get_u32( | |
6030 | info->attrs[NL80211_ATTR_AP_SETTINGS_FLAGS]); | |
6031 | else if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT]) | |
6032 | params->flags |= NL80211_AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; | |
fe494370 | 6033 | |
7b0a0e3c JB |
6034 | if (wdev->conn_owner_nlportid && |
6035 | info->attrs[NL80211_ATTR_SOCKET_OWNER] && | |
6036 | wdev->conn_owner_nlportid != info->snd_portid) { | |
6037 | err = -EINVAL; | |
6038 | goto out_unlock; | |
6039 | } | |
6040 | ||
6041 | /* FIXME: validate MLO/link-id against driver capabilities */ | |
6042 | ||
9e263e19 | 6043 | err = rdev_start_ap(rdev, dev, params); |
46c1dd0c | 6044 | if (!err) { |
7b0a0e3c JB |
6045 | wdev->links[link_id].ap.beacon_interval = params->beacon_interval; |
6046 | wdev->links[link_id].ap.chandef = params->chandef; | |
6047 | wdev->u.ap.ssid_len = params->ssid_len; | |
6048 | memcpy(wdev->u.ap.ssid, params->ssid, | |
6049 | params->ssid_len); | |
466a3061 DK |
6050 | |
6051 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) | |
6052 | wdev->conn_owner_nlportid = info->snd_portid; | |
46c1dd0c | 6053 | } |
7b0a0e3c | 6054 | out_unlock: |
c56589ed | 6055 | wdev_unlock(wdev); |
9951ebfc | 6056 | out: |
9e263e19 | 6057 | kfree(params->acl); |
dc1e3cb8 JC |
6058 | kfree(params->beacon.mbssid_ies); |
6059 | if (params->mbssid_config.tx_wdev && | |
6060 | params->mbssid_config.tx_wdev->netdev && | |
6061 | params->mbssid_config.tx_wdev->netdev != dev) | |
6062 | dev_put(params->mbssid_config.tx_wdev->netdev); | |
9e263e19 | 6063 | kfree(params); |
77765eaf | 6064 | |
56d1893d | 6065 | return err; |
ed1b6cc7 JB |
6066 | } |
6067 | ||
8860020e JB |
6068 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
6069 | { | |
6070 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7b0a0e3c | 6071 | unsigned int link_id = nl80211_link_id(info->attrs); |
8860020e JB |
6072 | struct net_device *dev = info->user_ptr[1]; |
6073 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6074 | struct cfg80211_beacon_data params; | |
6075 | int err; | |
6076 | ||
6077 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
6078 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
6079 | return -EOPNOTSUPP; | |
6080 | ||
6081 | if (!rdev->ops->change_beacon) | |
6082 | return -EOPNOTSUPP; | |
6083 | ||
7b0a0e3c | 6084 | if (!wdev->links[link_id].ap.beacon_interval) |
8860020e JB |
6085 | return -EINVAL; |
6086 | ||
81e54d08 | 6087 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms); |
8860020e | 6088 | if (err) |
dc1e3cb8 | 6089 | goto out; |
8860020e | 6090 | |
c56589ed SW |
6091 | wdev_lock(wdev); |
6092 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
6093 | wdev_unlock(wdev); | |
6094 | ||
dc1e3cb8 JC |
6095 | out: |
6096 | kfree(params.mbssid_ies); | |
c56589ed | 6097 | return err; |
8860020e JB |
6098 | } |
6099 | ||
6100 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 6101 | { |
4c476991 | 6102 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7b0a0e3c | 6103 | unsigned int link_id = nl80211_link_id(info->attrs); |
4c476991 | 6104 | struct net_device *dev = info->user_ptr[1]; |
ed1b6cc7 | 6105 | |
7b0a0e3c | 6106 | return cfg80211_stop_ap(rdev, dev, link_id, false); |
ed1b6cc7 JB |
6107 | } |
6108 | ||
5727ef1b JB |
6109 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
6110 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
6111 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
6112 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 6113 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 6114 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 6115 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
6116 | }; |
6117 | ||
eccb8e8f | 6118 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 6119 | enum nl80211_iftype iftype, |
eccb8e8f | 6120 | struct station_parameters *params) |
5727ef1b JB |
6121 | { |
6122 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 6123 | struct nlattr *nla; |
5727ef1b JB |
6124 | int flag; |
6125 | ||
eccb8e8f JB |
6126 | /* |
6127 | * Try parsing the new attribute first so userspace | |
6128 | * can specify both for older kernels. | |
6129 | */ | |
6130 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
6131 | if (nla) { | |
6132 | struct nl80211_sta_flag_update *sta_flags; | |
6133 | ||
6134 | sta_flags = nla_data(nla); | |
6135 | params->sta_flags_mask = sta_flags->mask; | |
6136 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 6137 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
6138 | if ((params->sta_flags_mask | |
6139 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
6140 | return -EINVAL; | |
6141 | return 0; | |
6142 | } | |
6143 | ||
6144 | /* if present, parse the old attribute */ | |
5727ef1b | 6145 | |
eccb8e8f | 6146 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
6147 | if (!nla) |
6148 | return 0; | |
6149 | ||
8cb08174 | 6150 | if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack)) |
5727ef1b JB |
6151 | return -EINVAL; |
6152 | ||
bdd3ae3d JB |
6153 | /* |
6154 | * Only allow certain flags for interface types so that | |
6155 | * other attributes are silently ignored. Remember that | |
6156 | * this is backward compatibility code with old userspace | |
6157 | * and shouldn't be hit in other cases anyway. | |
6158 | */ | |
6159 | switch (iftype) { | |
6160 | case NL80211_IFTYPE_AP: | |
6161 | case NL80211_IFTYPE_AP_VLAN: | |
6162 | case NL80211_IFTYPE_P2P_GO: | |
6163 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
6164 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
6165 | BIT(NL80211_STA_FLAG_WME) | | |
6166 | BIT(NL80211_STA_FLAG_MFP); | |
6167 | break; | |
6168 | case NL80211_IFTYPE_P2P_CLIENT: | |
6169 | case NL80211_IFTYPE_STATION: | |
6170 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
6171 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
6172 | break; | |
6173 | case NL80211_IFTYPE_MESH_POINT: | |
6174 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
6175 | BIT(NL80211_STA_FLAG_MFP) | | |
6176 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
5cf3006c | 6177 | break; |
bdd3ae3d JB |
6178 | default: |
6179 | return -EINVAL; | |
6180 | } | |
5727ef1b | 6181 | |
3383b5a6 JB |
6182 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
6183 | if (flags[flag]) { | |
eccb8e8f | 6184 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 6185 | |
3383b5a6 JB |
6186 | /* no longer support new API additions in old API */ |
6187 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
6188 | return -EINVAL; | |
6189 | } | |
6190 | } | |
6191 | ||
5727ef1b JB |
6192 | return 0; |
6193 | } | |
6194 | ||
9bb7e0f2 | 6195 | bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr) |
c8dcfd8a FF |
6196 | { |
6197 | struct nlattr *rate; | |
8eb41c8d VK |
6198 | u32 bitrate; |
6199 | u16 bitrate_compat; | |
bbf67e45 | 6200 | enum nl80211_rate_info rate_flg; |
c8dcfd8a | 6201 | |
ae0be8de | 6202 | rate = nla_nest_start_noflag(msg, attr); |
c8dcfd8a | 6203 | if (!rate) |
db9c64cf | 6204 | return false; |
c8dcfd8a FF |
6205 | |
6206 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
6207 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
6208 | /* report 16-bit bitrate only if we can */ |
6209 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
6210 | if (bitrate > 0 && |
6211 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
6212 | return false; | |
6213 | if (bitrate_compat > 0 && | |
6214 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
6215 | return false; | |
6216 | ||
b51f3bee JB |
6217 | switch (info->bw) { |
6218 | case RATE_INFO_BW_5: | |
6219 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; | |
6220 | break; | |
6221 | case RATE_INFO_BW_10: | |
6222 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; | |
6223 | break; | |
6224 | default: | |
6225 | WARN_ON(1); | |
7b506ff6 | 6226 | fallthrough; |
b51f3bee JB |
6227 | case RATE_INFO_BW_20: |
6228 | rate_flg = 0; | |
6229 | break; | |
6230 | case RATE_INFO_BW_40: | |
6231 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; | |
6232 | break; | |
6233 | case RATE_INFO_BW_80: | |
6234 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; | |
6235 | break; | |
6236 | case RATE_INFO_BW_160: | |
6237 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; | |
6238 | break; | |
c4cbaf79 LC |
6239 | case RATE_INFO_BW_HE_RU: |
6240 | rate_flg = 0; | |
6241 | WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); | |
cfb14110 VJ |
6242 | break; |
6243 | case RATE_INFO_BW_320: | |
6244 | rate_flg = NL80211_RATE_INFO_320_MHZ_WIDTH; | |
6245 | break; | |
6246 | case RATE_INFO_BW_EHT_RU: | |
6247 | rate_flg = 0; | |
6248 | WARN_ON(!(info->flags & RATE_INFO_FLAGS_EHT_MCS)); | |
6249 | break; | |
b51f3bee JB |
6250 | } |
6251 | ||
6252 | if (rate_flg && nla_put_flag(msg, rate_flg)) | |
6253 | return false; | |
6254 | ||
db9c64cf JB |
6255 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
6256 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
6257 | return false; | |
db9c64cf JB |
6258 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
6259 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
6260 | return false; | |
6261 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
6262 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
6263 | return false; | |
6264 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
6265 | return false; | |
db9c64cf JB |
6266 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
6267 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
6268 | return false; | |
c4cbaf79 LC |
6269 | } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { |
6270 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) | |
6271 | return false; | |
6272 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) | |
6273 | return false; | |
6274 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) | |
6275 | return false; | |
6276 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) | |
6277 | return false; | |
6278 | if (info->bw == RATE_INFO_BW_HE_RU && | |
6279 | nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, | |
6280 | info->he_ru_alloc)) | |
6281 | return false; | |
cfb14110 VJ |
6282 | } else if (info->flags & RATE_INFO_FLAGS_EHT_MCS) { |
6283 | if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_MCS, info->mcs)) | |
6284 | return false; | |
6285 | if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_NSS, info->nss)) | |
6286 | return false; | |
6287 | if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_GI, info->eht_gi)) | |
6288 | return false; | |
6289 | if (info->bw == RATE_INFO_BW_EHT_RU && | |
6290 | nla_put_u8(msg, NL80211_RATE_INFO_EHT_RU_ALLOC, | |
6291 | info->eht_ru_alloc)) | |
6292 | return false; | |
db9c64cf | 6293 | } |
c8dcfd8a FF |
6294 | |
6295 | nla_nest_end(msg, rate); | |
6296 | return true; | |
c8dcfd8a FF |
6297 | } |
6298 | ||
119363c7 FF |
6299 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
6300 | int id) | |
6301 | { | |
6302 | void *attr; | |
6303 | int i = 0; | |
6304 | ||
6305 | if (!mask) | |
6306 | return true; | |
6307 | ||
ae0be8de | 6308 | attr = nla_nest_start_noflag(msg, id); |
119363c7 FF |
6309 | if (!attr) |
6310 | return false; | |
6311 | ||
6312 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
6313 | if (!(mask & BIT(i))) | |
6314 | continue; | |
6315 | ||
6316 | if (nla_put_u8(msg, i, signal[i])) | |
6317 | return false; | |
6318 | } | |
6319 | ||
6320 | nla_nest_end(msg, attr); | |
6321 | ||
6322 | return true; | |
6323 | } | |
6324 | ||
cf5ead82 JB |
6325 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
6326 | u32 seq, int flags, | |
66266b3a JL |
6327 | struct cfg80211_registered_device *rdev, |
6328 | struct net_device *dev, | |
98b62183 | 6329 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
6330 | { |
6331 | void *hdr; | |
f4263c98 | 6332 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 6333 | |
cf5ead82 | 6334 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
f77bf486 AS |
6335 | if (!hdr) { |
6336 | cfg80211_sinfo_release_content(sinfo); | |
fd5b74dc | 6337 | return -1; |
f77bf486 | 6338 | } |
fd5b74dc | 6339 | |
9360ffd1 DM |
6340 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
6341 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
6342 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
6343 | goto nla_put_failure; | |
f5ea9120 | 6344 | |
ae0be8de | 6345 | sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO); |
2ec600d6 | 6346 | if (!sinfoattr) |
fd5b74dc | 6347 | goto nla_put_failure; |
319090bf JB |
6348 | |
6349 | #define PUT_SINFO(attr, memb, type) do { \ | |
d686b920 | 6350 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
397c657a | 6351 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
319090bf JB |
6352 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
6353 | sinfo->memb)) \ | |
6354 | goto nla_put_failure; \ | |
6355 | } while (0) | |
d686b920 | 6356 | #define PUT_SINFO_U64(attr, memb) do { \ |
397c657a | 6357 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
d686b920 JB |
6358 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
6359 | sinfo->memb, NL80211_STA_INFO_PAD)) \ | |
6360 | goto nla_put_failure; \ | |
6361 | } while (0) | |
319090bf JB |
6362 | |
6363 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); | |
6364 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); | |
6c7a0033 | 6365 | PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at); |
319090bf | 6366 | |
397c657a OE |
6367 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | |
6368 | BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && | |
9360ffd1 | 6369 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 6370 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 6371 | goto nla_put_failure; |
319090bf | 6372 | |
397c657a OE |
6373 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | |
6374 | BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 6375 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
6376 | (u32)sinfo->tx_bytes)) |
6377 | goto nla_put_failure; | |
319090bf | 6378 | |
d686b920 JB |
6379 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
6380 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); | |
319090bf JB |
6381 | PUT_SINFO(LLID, llid, u16); |
6382 | PUT_SINFO(PLID, plid, u16); | |
6383 | PUT_SINFO(PLINK_STATE, plink_state, u8); | |
d686b920 | 6384 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
36647055 THJ |
6385 | PUT_SINFO_U64(TX_DURATION, tx_duration); |
6386 | ||
6387 | if (wiphy_ext_feature_isset(&rdev->wiphy, | |
6388 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) | |
6389 | PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16); | |
319090bf | 6390 | |
66266b3a JL |
6391 | switch (rdev->wiphy.signal_type) { |
6392 | case CFG80211_SIGNAL_TYPE_MBM: | |
319090bf JB |
6393 | PUT_SINFO(SIGNAL, signal, u8); |
6394 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); | |
66266b3a JL |
6395 | break; |
6396 | default: | |
6397 | break; | |
6398 | } | |
397c657a | 6399 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
119363c7 FF |
6400 | if (!nl80211_put_signal(msg, sinfo->chains, |
6401 | sinfo->chain_signal, | |
6402 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
6403 | goto nla_put_failure; | |
6404 | } | |
397c657a | 6405 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
119363c7 FF |
6406 | if (!nl80211_put_signal(msg, sinfo->chains, |
6407 | sinfo->chain_signal_avg, | |
6408 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
6409 | goto nla_put_failure; | |
6410 | } | |
397c657a | 6411 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { |
c8dcfd8a FF |
6412 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
6413 | NL80211_STA_INFO_TX_BITRATE)) | |
6414 | goto nla_put_failure; | |
6415 | } | |
397c657a | 6416 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { |
c8dcfd8a FF |
6417 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
6418 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 6419 | goto nla_put_failure; |
420e7fab | 6420 | } |
319090bf JB |
6421 | |
6422 | PUT_SINFO(RX_PACKETS, rx_packets, u32); | |
6423 | PUT_SINFO(TX_PACKETS, tx_packets, u32); | |
6424 | PUT_SINFO(TX_RETRIES, tx_retries, u32); | |
6425 | PUT_SINFO(TX_FAILED, tx_failed, u32); | |
6426 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); | |
ab60633c | 6427 | PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32); |
319090bf JB |
6428 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
6429 | PUT_SINFO(LOCAL_PM, local_pm, u32); | |
6430 | PUT_SINFO(PEER_PM, peer_pm, u32); | |
6431 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); | |
dbdaee7a | 6432 | PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8); |
1303a51c | 6433 | PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8); |
319090bf | 6434 | |
397c657a | 6435 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { |
ae0be8de MK |
6436 | bss_param = nla_nest_start_noflag(msg, |
6437 | NL80211_STA_INFO_BSS_PARAM); | |
f4263c98 PS |
6438 | if (!bss_param) |
6439 | goto nla_put_failure; | |
6440 | ||
9360ffd1 DM |
6441 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
6442 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
6443 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
6444 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
6445 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
6446 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
6447 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
6448 | sinfo->bss_param.dtim_period) || | |
6449 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
6450 | sinfo->bss_param.beacon_interval)) | |
6451 | goto nla_put_failure; | |
f4263c98 PS |
6452 | |
6453 | nla_nest_end(msg, bss_param); | |
6454 | } | |
397c657a | 6455 | if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && |
9360ffd1 DM |
6456 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
6457 | sizeof(struct nl80211_sta_flag_update), | |
6458 | &sinfo->sta_flags)) | |
6459 | goto nla_put_failure; | |
319090bf | 6460 | |
d686b920 JB |
6461 | PUT_SINFO_U64(T_OFFSET, t_offset); |
6462 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); | |
6463 | PUT_SINFO_U64(BEACON_RX, rx_beacon); | |
a76b1942 | 6464 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
0d4e14a3 AB |
6465 | PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32); |
6466 | PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32); | |
81d5439d | 6467 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
9c06602b BP |
6468 | NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) { |
6469 | PUT_SINFO(ACK_SIGNAL, ack_signal, u8); | |
6470 | PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8); | |
6471 | } | |
319090bf JB |
6472 | |
6473 | #undef PUT_SINFO | |
d686b920 | 6474 | #undef PUT_SINFO_U64 |
6de39808 | 6475 | |
8689c051 | 6476 | if (sinfo->pertid) { |
6de39808 JB |
6477 | struct nlattr *tidsattr; |
6478 | int tid; | |
6479 | ||
ae0be8de MK |
6480 | tidsattr = nla_nest_start_noflag(msg, |
6481 | NL80211_STA_INFO_TID_STATS); | |
6de39808 JB |
6482 | if (!tidsattr) |
6483 | goto nla_put_failure; | |
6484 | ||
6485 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { | |
6486 | struct cfg80211_tid_stats *tidstats; | |
6487 | struct nlattr *tidattr; | |
6488 | ||
6489 | tidstats = &sinfo->pertid[tid]; | |
6490 | ||
6491 | if (!tidstats->filled) | |
6492 | continue; | |
6493 | ||
ae0be8de | 6494 | tidattr = nla_nest_start_noflag(msg, tid + 1); |
6de39808 JB |
6495 | if (!tidattr) |
6496 | goto nla_put_failure; | |
6497 | ||
d686b920 | 6498 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
6de39808 | 6499 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
d686b920 JB |
6500 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
6501 | tidstats->memb, NL80211_TID_STATS_PAD)) \ | |
6de39808 JB |
6502 | goto nla_put_failure; \ |
6503 | } while (0) | |
6504 | ||
d686b920 JB |
6505 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
6506 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); | |
6507 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); | |
6508 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); | |
6de39808 | 6509 | |
d686b920 | 6510 | #undef PUT_TIDVAL_U64 |
52539ca8 THJ |
6511 | if ((tidstats->filled & |
6512 | BIT(NL80211_TID_STATS_TXQ_STATS)) && | |
6513 | !nl80211_put_txq_stats(msg, &tidstats->txq_stats, | |
6514 | NL80211_TID_STATS_TXQ_STATS)) | |
6515 | goto nla_put_failure; | |
6516 | ||
6de39808 JB |
6517 | nla_nest_end(msg, tidattr); |
6518 | } | |
6519 | ||
6520 | nla_nest_end(msg, tidsattr); | |
6521 | } | |
6522 | ||
2ec600d6 | 6523 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 6524 | |
319090bf | 6525 | if (sinfo->assoc_req_ies_len && |
9360ffd1 DM |
6526 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
6527 | sinfo->assoc_req_ies)) | |
6528 | goto nla_put_failure; | |
50d3dfb7 | 6529 | |
7ea3e110 | 6530 | cfg80211_sinfo_release_content(sinfo); |
053c095a JB |
6531 | genlmsg_end(msg, hdr); |
6532 | return 0; | |
fd5b74dc JB |
6533 | |
6534 | nla_put_failure: | |
7ea3e110 | 6535 | cfg80211_sinfo_release_content(sinfo); |
bc3ed28c TG |
6536 | genlmsg_cancel(msg, hdr); |
6537 | return -EMSGSIZE; | |
fd5b74dc JB |
6538 | } |
6539 | ||
2ec600d6 | 6540 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 6541 | struct netlink_callback *cb) |
2ec600d6 | 6542 | { |
73887fd9 | 6543 | struct station_info sinfo; |
1b8ec87a | 6544 | struct cfg80211_registered_device *rdev; |
97990a06 | 6545 | struct wireless_dev *wdev; |
2ec600d6 | 6546 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 6547 | int sta_idx = cb->args[2]; |
2ec600d6 | 6548 | int err; |
2ec600d6 | 6549 | |
ce6b6974 | 6550 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL); |
67748893 | 6551 | if (err) |
a05829a7 JB |
6552 | return err; |
6553 | /* nl80211_prepare_wdev_dump acquired it in the successful case */ | |
6554 | __acquire(&rdev->wiphy.mtx); | |
bba95fef | 6555 | |
97990a06 JB |
6556 | if (!wdev->netdev) { |
6557 | err = -EINVAL; | |
6558 | goto out_err; | |
6559 | } | |
6560 | ||
1b8ec87a | 6561 | if (!rdev->ops->dump_station) { |
eec60b03 | 6562 | err = -EOPNOTSUPP; |
bba95fef JB |
6563 | goto out_err; |
6564 | } | |
6565 | ||
bba95fef | 6566 | while (1) { |
73887fd9 | 6567 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 6568 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
73887fd9 | 6569 | mac_addr, &sinfo); |
bba95fef JB |
6570 | if (err == -ENOENT) |
6571 | break; | |
6572 | if (err) | |
3b85875a | 6573 | goto out_err; |
bba95fef | 6574 | |
cf5ead82 | 6575 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
15e47304 | 6576 | NETLINK_CB(cb->skb).portid, |
bba95fef | 6577 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 6578 | rdev, wdev->netdev, mac_addr, |
73887fd9 | 6579 | &sinfo) < 0) |
bba95fef JB |
6580 | goto out; |
6581 | ||
6582 | sta_idx++; | |
6583 | } | |
6584 | ||
bba95fef | 6585 | out: |
97990a06 | 6586 | cb->args[2] = sta_idx; |
bba95fef | 6587 | err = skb->len; |
bba95fef | 6588 | out_err: |
a05829a7 | 6589 | wiphy_unlock(&rdev->wiphy); |
bba95fef JB |
6590 | |
6591 | return err; | |
2ec600d6 | 6592 | } |
fd5b74dc | 6593 | |
5727ef1b JB |
6594 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
6595 | { | |
4c476991 JB |
6596 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6597 | struct net_device *dev = info->user_ptr[1]; | |
73887fd9 | 6598 | struct station_info sinfo; |
fd5b74dc JB |
6599 | struct sk_buff *msg; |
6600 | u8 *mac_addr = NULL; | |
4c476991 | 6601 | int err; |
fd5b74dc | 6602 | |
73887fd9 | 6603 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc | 6604 | |
73887fd9 JB |
6605 | if (!info->attrs[NL80211_ATTR_MAC]) |
6606 | return -EINVAL; | |
fd5b74dc JB |
6607 | |
6608 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6609 | ||
73887fd9 JB |
6610 | if (!rdev->ops->get_station) |
6611 | return -EOPNOTSUPP; | |
3b85875a | 6612 | |
73887fd9 | 6613 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 6614 | if (err) |
73887fd9 | 6615 | return err; |
2ec600d6 | 6616 | |
fd2120ca | 6617 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
7ea3e110 | 6618 | if (!msg) { |
ba8f566a | 6619 | cfg80211_sinfo_release_content(&sinfo); |
73887fd9 | 6620 | return -ENOMEM; |
7ea3e110 | 6621 | } |
fd5b74dc | 6622 | |
cf5ead82 JB |
6623 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
6624 | info->snd_portid, info->snd_seq, 0, | |
73887fd9 | 6625 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 | 6626 | nlmsg_free(msg); |
73887fd9 | 6627 | return -ENOBUFS; |
4c476991 | 6628 | } |
3b85875a | 6629 | |
73887fd9 | 6630 | return genlmsg_reply(msg, info); |
5727ef1b JB |
6631 | } |
6632 | ||
77ee7c89 JB |
6633 | int cfg80211_check_station_change(struct wiphy *wiphy, |
6634 | struct station_parameters *params, | |
6635 | enum cfg80211_station_type statype) | |
6636 | { | |
e4208427 AB |
6637 | if (params->listen_interval != -1 && |
6638 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
77ee7c89 | 6639 | return -EINVAL; |
e4208427 | 6640 | |
17b94247 AB |
6641 | if (params->support_p2p_ps != -1 && |
6642 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
6643 | return -EINVAL; | |
6644 | ||
c72e1140 | 6645 | if (params->aid && |
e4208427 AB |
6646 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
6647 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
77ee7c89 JB |
6648 | return -EINVAL; |
6649 | ||
6650 | /* When you run into this, adjust the code below for the new flag */ | |
6651 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
6652 | ||
6653 | switch (statype) { | |
eef941e6 TP |
6654 | case CFG80211_STA_MESH_PEER_KERNEL: |
6655 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
6656 | /* |
6657 | * No ignoring the TDLS flag here -- the userspace mesh | |
6658 | * code doesn't have the bug of including TDLS in the | |
6659 | * mask everywhere. | |
6660 | */ | |
6661 | if (params->sta_flags_mask & | |
6662 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
6663 | BIT(NL80211_STA_FLAG_MFP) | | |
6664 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
6665 | return -EINVAL; | |
6666 | break; | |
6667 | case CFG80211_STA_TDLS_PEER_SETUP: | |
6668 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
6669 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
6670 | return -EINVAL; | |
6671 | /* ignore since it can't change */ | |
6672 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
6673 | break; | |
6674 | default: | |
6675 | /* disallow mesh-specific things */ | |
6676 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
6677 | return -EINVAL; | |
6678 | if (params->local_pm) | |
6679 | return -EINVAL; | |
6680 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
6681 | return -EINVAL; | |
6682 | } | |
6683 | ||
6684 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
6685 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
6686 | /* TDLS can't be set, ... */ | |
6687 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
6688 | return -EINVAL; | |
6689 | /* | |
6690 | * ... but don't bother the driver with it. This works around | |
6691 | * a hostapd/wpa_supplicant issue -- it always includes the | |
6692 | * TLDS_PEER flag in the mask even for AP mode. | |
6693 | */ | |
6694 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
6695 | } | |
6696 | ||
47edb11b AB |
6697 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
6698 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { | |
77ee7c89 JB |
6699 | /* reject other things that can't change */ |
6700 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
6701 | return -EINVAL; | |
6702 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
6703 | return -EINVAL; | |
b95eb7f0 | 6704 | if (params->link_sta_params.supported_rates) |
77ee7c89 | 6705 | return -EINVAL; |
b95eb7f0 ST |
6706 | if (params->ext_capab || params->link_sta_params.ht_capa || |
6707 | params->link_sta_params.vht_capa || | |
6708 | params->link_sta_params.he_capa || | |
6709 | params->link_sta_params.eht_capa) | |
77ee7c89 JB |
6710 | return -EINVAL; |
6711 | } | |
6712 | ||
47edb11b AB |
6713 | if (statype != CFG80211_STA_AP_CLIENT && |
6714 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { | |
77ee7c89 JB |
6715 | if (params->vlan) |
6716 | return -EINVAL; | |
6717 | } | |
6718 | ||
6719 | switch (statype) { | |
6720 | case CFG80211_STA_AP_MLME_CLIENT: | |
6721 | /* Use this only for authorizing/unauthorizing a station */ | |
6722 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
6723 | return -EOPNOTSUPP; | |
6724 | break; | |
6725 | case CFG80211_STA_AP_CLIENT: | |
47edb11b | 6726 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
77ee7c89 JB |
6727 | /* accept only the listed bits */ |
6728 | if (params->sta_flags_mask & | |
6729 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
6730 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
6731 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
6732 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
6733 | BIT(NL80211_STA_FLAG_WME) | | |
6734 | BIT(NL80211_STA_FLAG_MFP))) | |
6735 | return -EINVAL; | |
6736 | ||
6737 | /* but authenticated/associated only if driver handles it */ | |
6738 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
6739 | params->sta_flags_mask & | |
6740 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
6741 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
6742 | return -EINVAL; | |
6743 | break; | |
6744 | case CFG80211_STA_IBSS: | |
6745 | case CFG80211_STA_AP_STA: | |
6746 | /* reject any changes other than AUTHORIZED */ | |
6747 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
6748 | return -EINVAL; | |
6749 | break; | |
6750 | case CFG80211_STA_TDLS_PEER_SETUP: | |
6751 | /* reject any changes other than AUTHORIZED or WME */ | |
6752 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
6753 | BIT(NL80211_STA_FLAG_WME))) | |
6754 | return -EINVAL; | |
6755 | /* force (at least) rates when authorizing */ | |
6756 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
b95eb7f0 | 6757 | !params->link_sta_params.supported_rates) |
77ee7c89 JB |
6758 | return -EINVAL; |
6759 | break; | |
6760 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
6761 | /* reject any changes */ | |
6762 | return -EINVAL; | |
eef941e6 | 6763 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
6764 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
6765 | return -EINVAL; | |
6766 | break; | |
eef941e6 | 6767 | case CFG80211_STA_MESH_PEER_USER: |
42925040 CYY |
6768 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
6769 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) | |
77ee7c89 JB |
6770 | return -EINVAL; |
6771 | break; | |
6772 | } | |
6773 | ||
06f7c88c BL |
6774 | /* |
6775 | * Older kernel versions ignored this attribute entirely, so don't | |
6776 | * reject attempts to update it but mark it as unused instead so the | |
6777 | * driver won't look at the data. | |
6778 | */ | |
6779 | if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && | |
6780 | statype != CFG80211_STA_TDLS_PEER_SETUP) | |
b95eb7f0 | 6781 | params->link_sta_params.opmode_notif_used = false; |
06f7c88c | 6782 | |
77ee7c89 JB |
6783 | return 0; |
6784 | } | |
6785 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
6786 | ||
5727ef1b | 6787 | /* |
c258d2de | 6788 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 6789 | */ |
80b99899 JB |
6790 | static struct net_device *get_vlan(struct genl_info *info, |
6791 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 6792 | { |
463d0183 | 6793 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
6794 | struct net_device *v; |
6795 | int ret; | |
6796 | ||
6797 | if (!vlanattr) | |
6798 | return NULL; | |
6799 | ||
6800 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
6801 | if (!v) | |
6802 | return ERR_PTR(-ENODEV); | |
6803 | ||
6804 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
6805 | ret = -EINVAL; | |
6806 | goto error; | |
5727ef1b | 6807 | } |
80b99899 | 6808 | |
77ee7c89 JB |
6809 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
6810 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
6811 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
6812 | ret = -EINVAL; | |
6813 | goto error; | |
6814 | } | |
6815 | ||
80b99899 JB |
6816 | if (!netif_running(v)) { |
6817 | ret = -ENETDOWN; | |
6818 | goto error; | |
6819 | } | |
6820 | ||
6821 | return v; | |
6822 | error: | |
6823 | dev_put(v); | |
6824 | return ERR_PTR(ret); | |
5727ef1b JB |
6825 | } |
6826 | ||
ff276691 JB |
6827 | static int nl80211_parse_sta_wme(struct genl_info *info, |
6828 | struct station_parameters *params) | |
df881293 | 6829 | { |
df881293 JM |
6830 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
6831 | struct nlattr *nla; | |
6832 | int err; | |
6833 | ||
df881293 JM |
6834 | /* parse WME attributes if present */ |
6835 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
6836 | return 0; | |
6837 | ||
6838 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
8cb08174 JB |
6839 | err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla, |
6840 | nl80211_sta_wme_policy, | |
6841 | info->extack); | |
df881293 JM |
6842 | if (err) |
6843 | return err; | |
6844 | ||
6845 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
6846 | params->uapsd_queues = nla_get_u8( | |
6847 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
6848 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
6849 | return -EINVAL; | |
6850 | ||
6851 | if (tb[NL80211_STA_WME_MAX_SP]) | |
6852 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
6853 | ||
6854 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
6855 | return -EINVAL; | |
6856 | ||
6857 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
6858 | ||
6859 | return 0; | |
6860 | } | |
6861 | ||
c01fc9ad SD |
6862 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
6863 | struct station_parameters *params) | |
6864 | { | |
6865 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
6866 | params->supported_channels = | |
6867 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
6868 | params->supported_channels_len = | |
6869 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
6870 | /* | |
6871 | * Need to include at least one (first channel, number of | |
cb9abd48 JB |
6872 | * channels) tuple for each subband (checked in policy), |
6873 | * and must have proper tuples for the rest of the data as well. | |
c01fc9ad | 6874 | */ |
c01fc9ad SD |
6875 | if (params->supported_channels_len % 2) |
6876 | return -EINVAL; | |
6877 | } | |
6878 | ||
6879 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
6880 | params->supported_oper_classes = | |
6881 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
6882 | params->supported_oper_classes_len = | |
6883 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
c01fc9ad SD |
6884 | } |
6885 | return 0; | |
6886 | } | |
6887 | ||
ff276691 JB |
6888 | static int nl80211_set_station_tdls(struct genl_info *info, |
6889 | struct station_parameters *params) | |
6890 | { | |
c01fc9ad | 6891 | int err; |
ff276691 | 6892 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
6893 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
6894 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 | 6895 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
b95eb7f0 | 6896 | params->link_sta_params.ht_capa = |
ff276691 JB |
6897 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
6898 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
b95eb7f0 | 6899 | params->link_sta_params.vht_capa = |
ff276691 | 6900 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
c4cbaf79 | 6901 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
b95eb7f0 | 6902 | params->link_sta_params.he_capa = |
c4cbaf79 | 6903 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
b95eb7f0 | 6904 | params->link_sta_params.he_capa_len = |
c4cbaf79 | 6905 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
ea05fd35 IP |
6906 | |
6907 | if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) { | |
b95eb7f0 | 6908 | params->link_sta_params.eht_capa = |
ea05fd35 | 6909 | nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); |
b95eb7f0 | 6910 | params->link_sta_params.eht_capa_len = |
ea05fd35 IP |
6911 | nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); |
6912 | ||
b95eb7f0 ST |
6913 | if (!ieee80211_eht_capa_size_ok((const u8 *)params->link_sta_params.he_capa, |
6914 | (const u8 *)params->link_sta_params.eht_capa, | |
ea5cba26 JB |
6915 | params->link_sta_params.eht_capa_len, |
6916 | false)) | |
ea05fd35 IP |
6917 | return -EINVAL; |
6918 | } | |
c4cbaf79 | 6919 | } |
ff276691 | 6920 | |
c01fc9ad SD |
6921 | err = nl80211_parse_sta_channel_info(info, params); |
6922 | if (err) | |
6923 | return err; | |
6924 | ||
ff276691 JB |
6925 | return nl80211_parse_sta_wme(info, params); |
6926 | } | |
6927 | ||
e96d1cd2 | 6928 | static int nl80211_parse_sta_txpower_setting(struct genl_info *info, |
577e5b8c ST |
6929 | struct sta_txpwr *txpwr, |
6930 | bool *txpwr_set) | |
e96d1cd2 ARN |
6931 | { |
6932 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6933 | int idx; | |
6934 | ||
6935 | if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) { | |
6936 | if (!rdev->ops->set_tx_power || | |
6937 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
6938 | NL80211_EXT_FEATURE_STA_TX_PWR)) | |
6939 | return -EOPNOTSUPP; | |
6940 | ||
6941 | idx = NL80211_ATTR_STA_TX_POWER_SETTING; | |
577e5b8c | 6942 | txpwr->type = nla_get_u8(info->attrs[idx]); |
e96d1cd2 | 6943 | |
577e5b8c | 6944 | if (txpwr->type == NL80211_TX_POWER_LIMITED) { |
e96d1cd2 ARN |
6945 | idx = NL80211_ATTR_STA_TX_POWER; |
6946 | ||
6947 | if (info->attrs[idx]) | |
577e5b8c | 6948 | txpwr->power = nla_get_s16(info->attrs[idx]); |
e96d1cd2 ARN |
6949 | else |
6950 | return -EINVAL; | |
6951 | } | |
577e5b8c ST |
6952 | |
6953 | *txpwr_set = true; | |
6954 | } else { | |
6955 | *txpwr_set = false; | |
e96d1cd2 ARN |
6956 | } |
6957 | ||
6958 | return 0; | |
6959 | } | |
6960 | ||
5727ef1b JB |
6961 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
6962 | { | |
4c476991 | 6963 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 6964 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 6965 | struct station_parameters params; |
77ee7c89 JB |
6966 | u8 *mac_addr; |
6967 | int err; | |
5727ef1b JB |
6968 | |
6969 | memset(¶ms, 0, sizeof(params)); | |
6970 | ||
77ee7c89 JB |
6971 | if (!rdev->ops->change_station) |
6972 | return -EOPNOTSUPP; | |
6973 | ||
e4208427 AB |
6974 | /* |
6975 | * AID and listen_interval properties can be set only for unassociated | |
6976 | * station. Include these parameters here and will check them in | |
6977 | * cfg80211_check_station_change(). | |
6978 | */ | |
a9bc31e4 AB |
6979 | if (info->attrs[NL80211_ATTR_STA_AID]) |
6980 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
e4208427 | 6981 | |
14f34e36 GG |
6982 | if (info->attrs[NL80211_ATTR_VLAN_ID]) |
6983 | params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); | |
6984 | ||
e4208427 AB |
6985 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
6986 | params.listen_interval = | |
6987 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
6988 | else | |
6989 | params.listen_interval = -1; | |
5727ef1b | 6990 | |
ab0d76f6 JB |
6991 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) |
6992 | params.support_p2p_ps = | |
6993 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); | |
6994 | else | |
17b94247 | 6995 | params.support_p2p_ps = -1; |
17b94247 | 6996 | |
5727ef1b JB |
6997 | if (!info->attrs[NL80211_ATTR_MAC]) |
6998 | return -EINVAL; | |
6999 | ||
d2bc5249 AO |
7000 | params.link_sta_params.link_id = |
7001 | nl80211_link_id_or_invalid(info->attrs); | |
7002 | ||
7003 | if (info->attrs[NL80211_ATTR_MLD_ADDR]) { | |
7004 | /* If MLD_ADDR attribute is set then this is an MLD station | |
7005 | * and the MLD_ADDR attribute holds the MLD address and the | |
7006 | * MAC attribute holds for the LINK address. | |
7007 | * In that case, the link_id is also expected to be valid. | |
7008 | */ | |
7009 | if (params.link_sta_params.link_id < 0) | |
7010 | return -EINVAL; | |
7011 | ||
7012 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); | |
7013 | params.link_sta_params.mld_mac = mac_addr; | |
7014 | params.link_sta_params.link_mac = | |
7015 | nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7016 | if (!is_valid_ether_addr(params.link_sta_params.link_mac)) | |
7017 | return -EINVAL; | |
7018 | } else { | |
7019 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7020 | } | |
7021 | ||
5727ef1b JB |
7022 | |
7023 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
b95eb7f0 | 7024 | params.link_sta_params.supported_rates = |
5727ef1b | 7025 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
b95eb7f0 | 7026 | params.link_sta_params.supported_rates_len = |
5727ef1b JB |
7027 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
7028 | } | |
7029 | ||
9d62a986 JM |
7030 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
7031 | params.capability = | |
7032 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
7033 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
7034 | } | |
7035 | ||
7036 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
7037 | params.ext_capab = | |
7038 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
7039 | params.ext_capab_len = | |
7040 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
7041 | } | |
7042 | ||
bdd3ae3d | 7043 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
7044 | return -EINVAL; |
7045 | ||
ab0d76f6 | 7046 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
2ec600d6 | 7047 | params.plink_action = |
f8bacc21 | 7048 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
2ec600d6 | 7049 | |
f8bacc21 | 7050 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 7051 | params.plink_state = |
f8bacc21 | 7052 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
ab0d76f6 | 7053 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) |
7d27a0ba MH |
7054 | params.peer_aid = nla_get_u16( |
7055 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); | |
f8bacc21 JB |
7056 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
7057 | } | |
9c3990aa | 7058 | |
ab0d76f6 JB |
7059 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) |
7060 | params.local_pm = nla_get_u32( | |
3b1c5a53 MP |
7061 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
7062 | ||
06f7c88c | 7063 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
b95eb7f0 ST |
7064 | params.link_sta_params.opmode_notif_used = true; |
7065 | params.link_sta_params.opmode_notif = | |
06f7c88c BL |
7066 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
7067 | } | |
7068 | ||
43e64bf3 | 7069 | if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) |
b95eb7f0 | 7070 | params.link_sta_params.he_6ghz_capa = |
fce2ff72 | 7071 | nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); |
43e64bf3 | 7072 | |
36647055 THJ |
7073 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
7074 | params.airtime_weight = | |
7075 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); | |
7076 | ||
7077 | if (params.airtime_weight && | |
7078 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
7079 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) | |
7080 | return -EOPNOTSUPP; | |
7081 | ||
b95eb7f0 ST |
7082 | err = nl80211_parse_sta_txpower_setting(info, |
7083 | ¶ms.link_sta_params.txpwr, | |
7084 | ¶ms.link_sta_params.txpwr_set); | |
e96d1cd2 ARN |
7085 | if (err) |
7086 | return err; | |
7087 | ||
77ee7c89 JB |
7088 | /* Include parameters for TDLS peer (will check later) */ |
7089 | err = nl80211_set_station_tdls(info, ¶ms); | |
7090 | if (err) | |
7091 | return err; | |
7092 | ||
7093 | params.vlan = get_vlan(info, rdev); | |
7094 | if (IS_ERR(params.vlan)) | |
7095 | return PTR_ERR(params.vlan); | |
7096 | ||
a97f4424 JB |
7097 | switch (dev->ieee80211_ptr->iftype) { |
7098 | case NL80211_IFTYPE_AP: | |
7099 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 7100 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 7101 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 7102 | case NL80211_IFTYPE_STATION: |
267335d6 | 7103 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 7104 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
7105 | break; |
7106 | default: | |
77ee7c89 JB |
7107 | err = -EOPNOTSUPP; |
7108 | goto out_put_vlan; | |
034d655e JB |
7109 | } |
7110 | ||
77ee7c89 | 7111 | /* driver will call cfg80211_check_station_change() */ |
3d1cc7cd | 7112 | wdev_lock(dev->ieee80211_ptr); |
e35e4d28 | 7113 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
3d1cc7cd | 7114 | wdev_unlock(dev->ieee80211_ptr); |
5727ef1b | 7115 | |
77ee7c89 | 7116 | out_put_vlan: |
1160dfa1 | 7117 | dev_put(params.vlan); |
3b85875a | 7118 | |
5727ef1b JB |
7119 | return err; |
7120 | } | |
7121 | ||
7122 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
7123 | { | |
4c476991 | 7124 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 7125 | int err; |
4c476991 | 7126 | struct net_device *dev = info->user_ptr[1]; |
efbfe516 | 7127 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5727ef1b JB |
7128 | struct station_parameters params; |
7129 | u8 *mac_addr = NULL; | |
bda95eb1 JB |
7130 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
7131 | BIT(NL80211_STA_FLAG_ASSOCIATED); | |
5727ef1b JB |
7132 | |
7133 | memset(¶ms, 0, sizeof(params)); | |
7134 | ||
984c311b JB |
7135 | if (!rdev->ops->add_station) |
7136 | return -EOPNOTSUPP; | |
7137 | ||
5727ef1b JB |
7138 | if (!info->attrs[NL80211_ATTR_MAC]) |
7139 | return -EINVAL; | |
7140 | ||
5727ef1b JB |
7141 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
7142 | return -EINVAL; | |
7143 | ||
7144 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
7145 | return -EINVAL; | |
7146 | ||
5e4b6f56 JM |
7147 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
7148 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
7149 | return -EINVAL; |
7150 | ||
b95eb7f0 ST |
7151 | params.link_sta_params.link_id = |
7152 | nl80211_link_id_or_invalid(info->attrs); | |
7153 | ||
c0d67012 | 7154 | if (info->attrs[NL80211_ATTR_MLD_ADDR]) { |
c0d67012 ST |
7155 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); |
7156 | params.link_sta_params.mld_mac = mac_addr; | |
7157 | params.link_sta_params.link_mac = | |
7158 | nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7159 | if (!is_valid_ether_addr(params.link_sta_params.link_mac)) | |
7160 | return -EINVAL; | |
7161 | } else { | |
7162 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7163 | } | |
7164 | ||
b95eb7f0 | 7165 | params.link_sta_params.supported_rates = |
5727ef1b | 7166 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
b95eb7f0 | 7167 | params.link_sta_params.supported_rates_len = |
5727ef1b JB |
7168 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
7169 | params.listen_interval = | |
7170 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 7171 | |
14f34e36 GG |
7172 | if (info->attrs[NL80211_ATTR_VLAN_ID]) |
7173 | params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); | |
7174 | ||
17b94247 | 7175 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
ab0d76f6 JB |
7176 | params.support_p2p_ps = |
7177 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); | |
17b94247 AB |
7178 | } else { |
7179 | /* | |
7180 | * if not specified, assume it's supported for P2P GO interface, | |
7181 | * and is NOT supported for AP interface | |
7182 | */ | |
7183 | params.support_p2p_ps = | |
7184 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; | |
7185 | } | |
7186 | ||
3d124ea2 | 7187 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 7188 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
7189 | else |
7190 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
51b50fbe | 7191 | |
9d62a986 JM |
7192 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
7193 | params.capability = | |
7194 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
7195 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
7196 | } | |
7197 | ||
7198 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
7199 | params.ext_capab = | |
7200 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
7201 | params.ext_capab_len = | |
7202 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
7203 | } | |
7204 | ||
36aedc90 | 7205 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
b95eb7f0 | 7206 | params.link_sta_params.ht_capa = |
36aedc90 | 7207 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
5727ef1b | 7208 | |
f461be3e | 7209 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
b95eb7f0 | 7210 | params.link_sta_params.vht_capa = |
f461be3e MP |
7211 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
7212 | ||
c4cbaf79 | 7213 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
b95eb7f0 | 7214 | params.link_sta_params.he_capa = |
c4cbaf79 | 7215 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
b95eb7f0 | 7216 | params.link_sta_params.he_capa_len = |
c4cbaf79 | 7217 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
ea05fd35 IP |
7218 | |
7219 | if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) { | |
b95eb7f0 | 7220 | params.link_sta_params.eht_capa = |
ea05fd35 | 7221 | nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); |
b95eb7f0 | 7222 | params.link_sta_params.eht_capa_len = |
ea05fd35 IP |
7223 | nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); |
7224 | ||
b95eb7f0 ST |
7225 | if (!ieee80211_eht_capa_size_ok((const u8 *)params.link_sta_params.he_capa, |
7226 | (const u8 *)params.link_sta_params.eht_capa, | |
ea5cba26 JB |
7227 | params.link_sta_params.eht_capa_len, |
7228 | false)) | |
ea05fd35 IP |
7229 | return -EINVAL; |
7230 | } | |
c4cbaf79 LC |
7231 | } |
7232 | ||
43e64bf3 | 7233 | if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) |
b95eb7f0 | 7234 | params.link_sta_params.he_6ghz_capa = |
43e64bf3 RM |
7235 | nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); |
7236 | ||
60f4a7b1 | 7237 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
b95eb7f0 ST |
7238 | params.link_sta_params.opmode_notif_used = true; |
7239 | params.link_sta_params.opmode_notif = | |
60f4a7b1 MK |
7240 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
7241 | } | |
7242 | ||
ab0d76f6 | 7243 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
96b78dff | 7244 | params.plink_action = |
f8bacc21 | 7245 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
96b78dff | 7246 | |
36647055 THJ |
7247 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
7248 | params.airtime_weight = | |
7249 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); | |
7250 | ||
7251 | if (params.airtime_weight && | |
7252 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
7253 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) | |
7254 | return -EOPNOTSUPP; | |
7255 | ||
b95eb7f0 ST |
7256 | err = nl80211_parse_sta_txpower_setting(info, |
7257 | ¶ms.link_sta_params.txpwr, | |
7258 | ¶ms.link_sta_params.txpwr_set); | |
e96d1cd2 ARN |
7259 | if (err) |
7260 | return err; | |
7261 | ||
c01fc9ad SD |
7262 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
7263 | if (err) | |
7264 | return err; | |
7265 | ||
ff276691 JB |
7266 | err = nl80211_parse_sta_wme(info, ¶ms); |
7267 | if (err) | |
7268 | return err; | |
bdd90d5e | 7269 | |
bdd3ae3d | 7270 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
7271 | return -EINVAL; |
7272 | ||
496fcc29 JB |
7273 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
7274 | * as userspace might just pass through the capabilities from the IEs | |
7275 | * directly, rather than enforcing this restriction and returning an | |
7276 | * error in this case. | |
7277 | */ | |
7278 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { | |
b95eb7f0 ST |
7279 | params.link_sta_params.ht_capa = NULL; |
7280 | params.link_sta_params.vht_capa = NULL; | |
c4cbaf79 | 7281 | |
ea05fd35 | 7282 | /* HE and EHT require WME */ |
b95eb7f0 ST |
7283 | if (params.link_sta_params.he_capa_len || |
7284 | params.link_sta_params.he_6ghz_capa || | |
7285 | params.link_sta_params.eht_capa_len) | |
c4cbaf79 | 7286 | return -EINVAL; |
496fcc29 JB |
7287 | } |
7288 | ||
43e64bf3 | 7289 | /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */ |
b95eb7f0 ST |
7290 | if (params.link_sta_params.he_6ghz_capa && |
7291 | (params.link_sta_params.ht_capa || params.link_sta_params.vht_capa)) | |
43e64bf3 RM |
7292 | return -EINVAL; |
7293 | ||
77ee7c89 JB |
7294 | /* When you run into this, adjust the code below for the new flag */ |
7295 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
7296 | ||
bdd90d5e JB |
7297 | switch (dev->ieee80211_ptr->iftype) { |
7298 | case NL80211_IFTYPE_AP: | |
7299 | case NL80211_IFTYPE_AP_VLAN: | |
7300 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
7301 | /* ignore WME attributes if iface/sta is not capable */ |
7302 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
7303 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
7304 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 7305 | |
bdd90d5e | 7306 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
7307 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
7308 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 7309 | return -EINVAL; |
bdd90d5e JB |
7310 | /* but don't bother the driver with it */ |
7311 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 7312 | |
d582cffb JB |
7313 | /* allow authenticated/associated only if driver handles it */ |
7314 | if (!(rdev->wiphy.features & | |
7315 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
bda95eb1 | 7316 | params.sta_flags_mask & auth_assoc) |
d582cffb JB |
7317 | return -EINVAL; |
7318 | ||
bda95eb1 JB |
7319 | /* Older userspace, or userspace wanting to be compatible with |
7320 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth | |
7321 | * and assoc flags in the mask, but assumes the station will be | |
7322 | * added as associated anyway since this was the required driver | |
7323 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was | |
7324 | * introduced. | |
7325 | * In order to not bother drivers with this quirk in the API | |
7326 | * set the flags in both the mask and set for new stations in | |
7327 | * this case. | |
7328 | */ | |
7329 | if (!(params.sta_flags_mask & auth_assoc)) { | |
7330 | params.sta_flags_mask |= auth_assoc; | |
7331 | params.sta_flags_set |= auth_assoc; | |
7332 | } | |
7333 | ||
bdd90d5e JB |
7334 | /* must be last in here for error handling */ |
7335 | params.vlan = get_vlan(info, rdev); | |
7336 | if (IS_ERR(params.vlan)) | |
7337 | return PTR_ERR(params.vlan); | |
7338 | break; | |
7339 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
7340 | /* ignore uAPSD data */ |
7341 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
7342 | ||
d582cffb JB |
7343 | /* associated is disallowed */ |
7344 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
7345 | return -EINVAL; | |
bdd90d5e | 7346 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
7347 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
7348 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
7349 | return -EINVAL; |
7350 | break; | |
7351 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 7352 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
7353 | /* ignore uAPSD data */ |
7354 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
7355 | ||
77ee7c89 JB |
7356 | /* these are disallowed */ |
7357 | if (params.sta_flags_mask & | |
7358 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
7359 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 7360 | return -EINVAL; |
bdd90d5e JB |
7361 | /* Only TDLS peers can be added */ |
7362 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
7363 | return -EINVAL; | |
7364 | /* Can only add if TDLS ... */ | |
7365 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
7366 | return -EOPNOTSUPP; | |
7367 | /* ... with external setup is supported */ | |
7368 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
7369 | return -EOPNOTSUPP; | |
77ee7c89 JB |
7370 | /* |
7371 | * Older wpa_supplicant versions always mark the TDLS peer | |
7372 | * as authorized, but it shouldn't yet be. | |
7373 | */ | |
7374 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
7375 | break; |
7376 | default: | |
7377 | return -EOPNOTSUPP; | |
c75786c9 EP |
7378 | } |
7379 | ||
bdd90d5e | 7380 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 7381 | |
3d1cc7cd | 7382 | wdev_lock(dev->ieee80211_ptr); |
efbfe516 JB |
7383 | if (wdev->valid_links) { |
7384 | if (params.link_sta_params.link_id < 0) { | |
7385 | err = -EINVAL; | |
7386 | goto out; | |
7387 | } | |
7388 | if (!(wdev->valid_links & BIT(params.link_sta_params.link_id))) { | |
7389 | err = -ENOLINK; | |
7390 | goto out; | |
7391 | } | |
7392 | } else { | |
7393 | if (params.link_sta_params.link_id >= 0) { | |
7394 | err = -EINVAL; | |
7395 | goto out; | |
7396 | } | |
7397 | } | |
e35e4d28 | 7398 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
efbfe516 | 7399 | out: |
3d1cc7cd | 7400 | wdev_unlock(dev->ieee80211_ptr); |
1160dfa1 | 7401 | dev_put(params.vlan); |
5727ef1b JB |
7402 | return err; |
7403 | } | |
7404 | ||
7405 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
7406 | { | |
4c476991 JB |
7407 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7408 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 | 7409 | struct station_del_parameters params; |
3d1cc7cd | 7410 | int ret; |
89c771e5 JM |
7411 | |
7412 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
7413 | |
7414 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 7415 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 7416 | |
306b79ea JB |
7417 | switch (dev->ieee80211_ptr->iftype) { |
7418 | case NL80211_IFTYPE_AP: | |
7419 | case NL80211_IFTYPE_AP_VLAN: | |
7420 | case NL80211_IFTYPE_MESH_POINT: | |
7421 | case NL80211_IFTYPE_P2P_GO: | |
7422 | /* always accept these */ | |
7423 | break; | |
7424 | case NL80211_IFTYPE_ADHOC: | |
7425 | /* conditionally accept */ | |
7426 | if (wiphy_ext_feature_isset(&rdev->wiphy, | |
7427 | NL80211_EXT_FEATURE_DEL_IBSS_STA)) | |
7428 | break; | |
edafcf42 | 7429 | return -EINVAL; |
306b79ea | 7430 | default: |
4c476991 | 7431 | return -EINVAL; |
306b79ea | 7432 | } |
5727ef1b | 7433 | |
4c476991 JB |
7434 | if (!rdev->ops->del_station) |
7435 | return -EOPNOTSUPP; | |
3b85875a | 7436 | |
98856866 JM |
7437 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
7438 | params.subtype = | |
7439 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
7440 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
7441 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
7442 | return -EINVAL; | |
7443 | } else { | |
7444 | /* Default to Deauthentication frame */ | |
7445 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
7446 | } | |
7447 | ||
7448 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
7449 | params.reason_code = | |
7450 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7451 | if (params.reason_code == 0) | |
7452 | return -EINVAL; /* 0 is reserved */ | |
7453 | } else { | |
7454 | /* Default to reason code 2 */ | |
7455 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
7456 | } | |
7457 | ||
3d1cc7cd JB |
7458 | wdev_lock(dev->ieee80211_ptr); |
7459 | ret = rdev_del_station(rdev, dev, ¶ms); | |
7460 | wdev_unlock(dev->ieee80211_ptr); | |
7461 | ||
7462 | return ret; | |
5727ef1b JB |
7463 | } |
7464 | ||
15e47304 | 7465 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
7466 | int flags, struct net_device *dev, |
7467 | u8 *dst, u8 *next_hop, | |
7468 | struct mpath_info *pinfo) | |
7469 | { | |
7470 | void *hdr; | |
7471 | struct nlattr *pinfoattr; | |
7472 | ||
1ef4c850 | 7473 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
2ec600d6 LCC |
7474 | if (!hdr) |
7475 | return -1; | |
7476 | ||
9360ffd1 DM |
7477 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
7478 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
7479 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
7480 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
7481 | goto nla_put_failure; | |
f5ea9120 | 7482 | |
ae0be8de | 7483 | pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO); |
2ec600d6 LCC |
7484 | if (!pinfoattr) |
7485 | goto nla_put_failure; | |
9360ffd1 DM |
7486 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
7487 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
7488 | pinfo->frame_qlen)) | |
7489 | goto nla_put_failure; | |
7490 | if (((pinfo->filled & MPATH_INFO_SN) && | |
7491 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
7492 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
7493 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
7494 | pinfo->metric)) || | |
7495 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
7496 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
7497 | pinfo->exptime)) || | |
7498 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
7499 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
7500 | pinfo->flags)) || | |
7501 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
7502 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
7503 | pinfo->discovery_timeout)) || | |
7504 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
7505 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
cc241636 JH |
7506 | pinfo->discovery_retries)) || |
7507 | ((pinfo->filled & MPATH_INFO_HOP_COUNT) && | |
7508 | nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT, | |
540bbcb9 JH |
7509 | pinfo->hop_count)) || |
7510 | ((pinfo->filled & MPATH_INFO_PATH_CHANGE) && | |
7511 | nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE, | |
7512 | pinfo->path_change_count))) | |
9360ffd1 | 7513 | goto nla_put_failure; |
2ec600d6 LCC |
7514 | |
7515 | nla_nest_end(msg, pinfoattr); | |
7516 | ||
053c095a JB |
7517 | genlmsg_end(msg, hdr); |
7518 | return 0; | |
2ec600d6 LCC |
7519 | |
7520 | nla_put_failure: | |
bc3ed28c TG |
7521 | genlmsg_cancel(msg, hdr); |
7522 | return -EMSGSIZE; | |
2ec600d6 LCC |
7523 | } |
7524 | ||
7525 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 7526 | struct netlink_callback *cb) |
2ec600d6 | 7527 | { |
2ec600d6 | 7528 | struct mpath_info pinfo; |
1b8ec87a | 7529 | struct cfg80211_registered_device *rdev; |
97990a06 | 7530 | struct wireless_dev *wdev; |
2ec600d6 LCC |
7531 | u8 dst[ETH_ALEN]; |
7532 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 7533 | int path_idx = cb->args[2]; |
2ec600d6 | 7534 | int err; |
2ec600d6 | 7535 | |
ce6b6974 | 7536 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL); |
67748893 | 7537 | if (err) |
a05829a7 JB |
7538 | return err; |
7539 | /* nl80211_prepare_wdev_dump acquired it in the successful case */ | |
7540 | __acquire(&rdev->wiphy.mtx); | |
bba95fef | 7541 | |
1b8ec87a | 7542 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 7543 | err = -EOPNOTSUPP; |
bba95fef JB |
7544 | goto out_err; |
7545 | } | |
7546 | ||
97990a06 | 7547 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 7548 | err = -EOPNOTSUPP; |
0448b5fc | 7549 | goto out_err; |
eec60b03 JM |
7550 | } |
7551 | ||
bba95fef | 7552 | while (1) { |
1b8ec87a | 7553 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 7554 | next_hop, &pinfo); |
bba95fef | 7555 | if (err == -ENOENT) |
2ec600d6 | 7556 | break; |
bba95fef | 7557 | if (err) |
3b85875a | 7558 | goto out_err; |
2ec600d6 | 7559 | |
15e47304 | 7560 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 7561 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 7562 | wdev->netdev, dst, next_hop, |
bba95fef JB |
7563 | &pinfo) < 0) |
7564 | goto out; | |
2ec600d6 | 7565 | |
bba95fef | 7566 | path_idx++; |
2ec600d6 | 7567 | } |
2ec600d6 | 7568 | |
bba95fef | 7569 | out: |
97990a06 | 7570 | cb->args[2] = path_idx; |
bba95fef | 7571 | err = skb->len; |
bba95fef | 7572 | out_err: |
a05829a7 | 7573 | wiphy_unlock(&rdev->wiphy); |
bba95fef | 7574 | return err; |
2ec600d6 LCC |
7575 | } |
7576 | ||
7577 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
7578 | { | |
4c476991 | 7579 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 7580 | int err; |
4c476991 | 7581 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
7582 | struct mpath_info pinfo; |
7583 | struct sk_buff *msg; | |
7584 | u8 *dst = NULL; | |
7585 | u8 next_hop[ETH_ALEN]; | |
7586 | ||
7587 | memset(&pinfo, 0, sizeof(pinfo)); | |
7588 | ||
7589 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7590 | return -EINVAL; | |
7591 | ||
7592 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7593 | ||
4c476991 JB |
7594 | if (!rdev->ops->get_mpath) |
7595 | return -EOPNOTSUPP; | |
2ec600d6 | 7596 | |
4c476991 JB |
7597 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
7598 | return -EOPNOTSUPP; | |
eec60b03 | 7599 | |
e35e4d28 | 7600 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 7601 | if (err) |
4c476991 | 7602 | return err; |
2ec600d6 | 7603 | |
fd2120ca | 7604 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 7605 | if (!msg) |
4c476991 | 7606 | return -ENOMEM; |
2ec600d6 | 7607 | |
15e47304 | 7608 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
7609 | dev, dst, next_hop, &pinfo) < 0) { |
7610 | nlmsg_free(msg); | |
7611 | return -ENOBUFS; | |
7612 | } | |
3b85875a | 7613 | |
4c476991 | 7614 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
7615 | } |
7616 | ||
7617 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
7618 | { | |
4c476991 JB |
7619 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7620 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
7621 | u8 *dst = NULL; |
7622 | u8 *next_hop = NULL; | |
7623 | ||
7624 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7625 | return -EINVAL; | |
7626 | ||
7627 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
7628 | return -EINVAL; | |
7629 | ||
7630 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7631 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
7632 | ||
4c476991 JB |
7633 | if (!rdev->ops->change_mpath) |
7634 | return -EOPNOTSUPP; | |
35a8efe1 | 7635 | |
4c476991 JB |
7636 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
7637 | return -EOPNOTSUPP; | |
2ec600d6 | 7638 | |
e35e4d28 | 7639 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 7640 | } |
4c476991 | 7641 | |
2ec600d6 LCC |
7642 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
7643 | { | |
4c476991 JB |
7644 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7645 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
7646 | u8 *dst = NULL; |
7647 | u8 *next_hop = NULL; | |
7648 | ||
7649 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7650 | return -EINVAL; | |
7651 | ||
7652 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
7653 | return -EINVAL; | |
7654 | ||
7655 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7656 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
7657 | ||
4c476991 JB |
7658 | if (!rdev->ops->add_mpath) |
7659 | return -EOPNOTSUPP; | |
35a8efe1 | 7660 | |
4c476991 JB |
7661 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
7662 | return -EOPNOTSUPP; | |
2ec600d6 | 7663 | |
e35e4d28 | 7664 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
7665 | } |
7666 | ||
7667 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
7668 | { | |
4c476991 JB |
7669 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7670 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
7671 | u8 *dst = NULL; |
7672 | ||
7673 | if (info->attrs[NL80211_ATTR_MAC]) | |
7674 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7675 | ||
4c476991 JB |
7676 | if (!rdev->ops->del_mpath) |
7677 | return -EOPNOTSUPP; | |
3b85875a | 7678 | |
b501426c MP |
7679 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
7680 | return -EOPNOTSUPP; | |
7681 | ||
e35e4d28 | 7682 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
7683 | } |
7684 | ||
66be7d2b HR |
7685 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
7686 | { | |
7687 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7688 | int err; | |
7689 | struct net_device *dev = info->user_ptr[1]; | |
7690 | struct mpath_info pinfo; | |
7691 | struct sk_buff *msg; | |
7692 | u8 *dst = NULL; | |
7693 | u8 mpp[ETH_ALEN]; | |
7694 | ||
7695 | memset(&pinfo, 0, sizeof(pinfo)); | |
7696 | ||
7697 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7698 | return -EINVAL; | |
7699 | ||
7700 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7701 | ||
7702 | if (!rdev->ops->get_mpp) | |
7703 | return -EOPNOTSUPP; | |
7704 | ||
7705 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
7706 | return -EOPNOTSUPP; | |
7707 | ||
7708 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
7709 | if (err) | |
7710 | return err; | |
7711 | ||
7712 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
7713 | if (!msg) | |
7714 | return -ENOMEM; | |
7715 | ||
7716 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
7717 | dev, dst, mpp, &pinfo) < 0) { | |
7718 | nlmsg_free(msg); | |
7719 | return -ENOBUFS; | |
7720 | } | |
7721 | ||
7722 | return genlmsg_reply(msg, info); | |
7723 | } | |
7724 | ||
7725 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
7726 | struct netlink_callback *cb) | |
7727 | { | |
7728 | struct mpath_info pinfo; | |
7729 | struct cfg80211_registered_device *rdev; | |
7730 | struct wireless_dev *wdev; | |
7731 | u8 dst[ETH_ALEN]; | |
7732 | u8 mpp[ETH_ALEN]; | |
7733 | int path_idx = cb->args[2]; | |
7734 | int err; | |
7735 | ||
ce6b6974 | 7736 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL); |
66be7d2b | 7737 | if (err) |
a05829a7 JB |
7738 | return err; |
7739 | /* nl80211_prepare_wdev_dump acquired it in the successful case */ | |
7740 | __acquire(&rdev->wiphy.mtx); | |
66be7d2b HR |
7741 | |
7742 | if (!rdev->ops->dump_mpp) { | |
7743 | err = -EOPNOTSUPP; | |
7744 | goto out_err; | |
7745 | } | |
7746 | ||
7747 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
7748 | err = -EOPNOTSUPP; | |
7749 | goto out_err; | |
7750 | } | |
7751 | ||
7752 | while (1) { | |
7753 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
7754 | mpp, &pinfo); | |
7755 | if (err == -ENOENT) | |
7756 | break; | |
7757 | if (err) | |
7758 | goto out_err; | |
7759 | ||
7760 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
7761 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
7762 | wdev->netdev, dst, mpp, | |
7763 | &pinfo) < 0) | |
7764 | goto out; | |
7765 | ||
7766 | path_idx++; | |
7767 | } | |
7768 | ||
7769 | out: | |
7770 | cb->args[2] = path_idx; | |
7771 | err = skb->len; | |
7772 | out_err: | |
a05829a7 | 7773 | wiphy_unlock(&rdev->wiphy); |
66be7d2b HR |
7774 | return err; |
7775 | } | |
7776 | ||
9f1ba906 JM |
7777 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
7778 | { | |
4c476991 JB |
7779 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7780 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 7781 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 7782 | struct bss_parameters params; |
c56589ed | 7783 | int err; |
9f1ba906 JM |
7784 | |
7785 | memset(¶ms, 0, sizeof(params)); | |
1e0f8cc9 | 7786 | params.link_id = nl80211_link_id_or_invalid(info->attrs); |
9f1ba906 JM |
7787 | /* default to not changing parameters */ |
7788 | params.use_cts_prot = -1; | |
7789 | params.use_short_preamble = -1; | |
7790 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 7791 | params.ap_isolate = -1; |
50b12f59 | 7792 | params.ht_opmode = -1; |
53cabad7 JB |
7793 | params.p2p_ctwindow = -1; |
7794 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
7795 | |
7796 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
7797 | params.use_cts_prot = | |
7798 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
7799 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
7800 | params.use_short_preamble = | |
7801 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
7802 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
7803 | params.use_short_slot_time = | |
7804 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
7805 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
7806 | params.basic_rates = | |
7807 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7808 | params.basic_rates_len = | |
7809 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7810 | } | |
fd8aaaf3 FF |
7811 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
7812 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
7813 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
7814 | params.ht_opmode = | |
7815 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 7816 | |
53cabad7 JB |
7817 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
7818 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
7819 | return -EINVAL; | |
7820 | params.p2p_ctwindow = | |
ab0d76f6 | 7821 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
53cabad7 JB |
7822 | if (params.p2p_ctwindow != 0 && |
7823 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
7824 | return -EINVAL; | |
7825 | } | |
7826 | ||
7827 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
7828 | u8 tmp; | |
7829 | ||
7830 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
7831 | return -EINVAL; | |
7832 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
53cabad7 JB |
7833 | params.p2p_opp_ps = tmp; |
7834 | if (params.p2p_opp_ps && | |
7835 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
7836 | return -EINVAL; | |
7837 | } | |
7838 | ||
4c476991 JB |
7839 | if (!rdev->ops->change_bss) |
7840 | return -EOPNOTSUPP; | |
9f1ba906 | 7841 | |
074ac8df | 7842 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
7843 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
7844 | return -EOPNOTSUPP; | |
3b85875a | 7845 | |
c56589ed SW |
7846 | wdev_lock(wdev); |
7847 | err = rdev_change_bss(rdev, dev, ¶ms); | |
7848 | wdev_unlock(wdev); | |
7849 | ||
7850 | return err; | |
9f1ba906 JM |
7851 | } |
7852 | ||
b2e1b302 LR |
7853 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
7854 | { | |
b2e1b302 | 7855 | char *data = NULL; |
05050753 | 7856 | bool is_indoor; |
57b5ce07 | 7857 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
05050753 I |
7858 | u32 owner_nlportid; |
7859 | ||
80778f18 LR |
7860 | /* |
7861 | * You should only get this when cfg80211 hasn't yet initialized | |
7862 | * completely when built-in to the kernel right between the time | |
7863 | * window between nl80211_init() and regulatory_init(), if that is | |
7864 | * even possible. | |
7865 | */ | |
458f4f9e | 7866 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 7867 | return -EINPROGRESS; |
80778f18 | 7868 | |
57b5ce07 LR |
7869 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
7870 | user_reg_hint_type = | |
7871 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
7872 | else | |
7873 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
7874 | ||
7875 | switch (user_reg_hint_type) { | |
7876 | case NL80211_USER_REG_HINT_USER: | |
7877 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
7878 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
7879 | return -EINVAL; | |
7880 | ||
7881 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
7882 | return regulatory_hint_user(data, user_reg_hint_type); | |
7883 | case NL80211_USER_REG_HINT_INDOOR: | |
05050753 I |
7884 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
7885 | owner_nlportid = info->snd_portid; | |
7886 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; | |
7887 | } else { | |
7888 | owner_nlportid = 0; | |
7889 | is_indoor = true; | |
7890 | } | |
7891 | ||
7892 | return regulatory_hint_indoor(is_indoor, owner_nlportid); | |
57b5ce07 LR |
7893 | default: |
7894 | return -EINVAL; | |
7895 | } | |
b2e1b302 LR |
7896 | } |
7897 | ||
1ea4ff3e JB |
7898 | static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) |
7899 | { | |
7900 | return reg_reload_regdb(); | |
7901 | } | |
7902 | ||
24bdd9f4 | 7903 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 7904 | struct genl_info *info) |
93da9cc1 | 7905 | { |
4c476991 | 7906 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 7907 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
7908 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
7909 | struct mesh_config cur_params; | |
7910 | int err = 0; | |
93da9cc1 | 7911 | void *hdr; |
7912 | struct nlattr *pinfoattr; | |
7913 | struct sk_buff *msg; | |
7914 | ||
29cbe68c JB |
7915 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
7916 | return -EOPNOTSUPP; | |
7917 | ||
24bdd9f4 | 7918 | if (!rdev->ops->get_mesh_config) |
4c476991 | 7919 | return -EOPNOTSUPP; |
f3f92586 | 7920 | |
29cbe68c JB |
7921 | wdev_lock(wdev); |
7922 | /* If not connected, get default parameters */ | |
7b0a0e3c | 7923 | if (!wdev->u.mesh.id_len) |
29cbe68c JB |
7924 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
7925 | else | |
e35e4d28 | 7926 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
7927 | wdev_unlock(wdev); |
7928 | ||
93da9cc1 | 7929 | if (err) |
4c476991 | 7930 | return err; |
93da9cc1 | 7931 | |
7932 | /* Draw up a netlink message to send back */ | |
fd2120ca | 7933 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
7934 | if (!msg) |
7935 | return -ENOMEM; | |
15e47304 | 7936 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 7937 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 7938 | if (!hdr) |
efe1cf0c | 7939 | goto out; |
ae0be8de | 7940 | pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 7941 | if (!pinfoattr) |
7942 | goto nla_put_failure; | |
9360ffd1 DM |
7943 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
7944 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
7945 | cur_params.dot11MeshRetryTimeout) || | |
7946 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
7947 | cur_params.dot11MeshConfirmTimeout) || | |
7948 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
7949 | cur_params.dot11MeshHoldingTimeout) || | |
7950 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
7951 | cur_params.dot11MeshMaxPeerLinks) || | |
7952 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
7953 | cur_params.dot11MeshMaxRetries) || | |
7954 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
7955 | cur_params.dot11MeshTTL) || | |
7956 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
7957 | cur_params.element_ttl) || | |
7958 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
7959 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
7960 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
7961 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
7962 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
7963 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
7964 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
7965 | cur_params.path_refresh_time) || | |
7966 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
7967 | cur_params.min_discovery_timeout) || | |
7968 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
7969 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
7970 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
7971 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
7972 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
7973 | cur_params.dot11MeshHWMPperrMinInterval) || | |
7974 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
7975 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
7976 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
7977 | cur_params.dot11MeshHWMPRootMode) || | |
7978 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
7979 | cur_params.dot11MeshHWMPRannInterval) || | |
7980 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
7981 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
7982 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
7983 | cur_params.dot11MeshForwarding) || | |
335d5349 | 7984 | nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
70c33eaa AN |
7985 | cur_params.rssi_threshold) || |
7986 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
7987 | cur_params.ht_opmode) || |
7988 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
7989 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
7990 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
7991 | cur_params.dot11MeshHWMProotInterval) || |
7992 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
7993 | cur_params.dot11MeshHWMPconfirmationInterval) || |
7994 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
7995 | cur_params.power_mode) || | |
7996 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
7997 | cur_params.dot11MeshAwakeWindowDuration) || |
7998 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
01d66fbd BC |
7999 | cur_params.plink_timeout) || |
8000 | nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE, | |
e3718a61 LL |
8001 | cur_params.dot11MeshConnectedToMeshGate) || |
8002 | nla_put_u8(msg, NL80211_MESHCONF_NOLEARN, | |
184eebe6 MT |
8003 | cur_params.dot11MeshNolearn) || |
8004 | nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS, | |
8005 | cur_params.dot11MeshConnectedToAuthServer)) | |
9360ffd1 | 8006 | goto nla_put_failure; |
93da9cc1 | 8007 | nla_nest_end(msg, pinfoattr); |
8008 | genlmsg_end(msg, hdr); | |
4c476991 | 8009 | return genlmsg_reply(msg, info); |
93da9cc1 | 8010 | |
3b85875a | 8011 | nla_put_failure: |
efe1cf0c | 8012 | out: |
d080e275 | 8013 | nlmsg_free(msg); |
4c476991 | 8014 | return -ENOBUFS; |
93da9cc1 | 8015 | } |
8016 | ||
ab0d76f6 JB |
8017 | static const struct nla_policy |
8018 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { | |
8019 | [NL80211_MESHCONF_RETRY_TIMEOUT] = | |
8020 | NLA_POLICY_RANGE(NLA_U16, 1, 255), | |
8021 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = | |
8022 | NLA_POLICY_RANGE(NLA_U16, 1, 255), | |
8023 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = | |
8024 | NLA_POLICY_RANGE(NLA_U16, 1, 255), | |
8025 | [NL80211_MESHCONF_MAX_PEER_LINKS] = | |
8026 | NLA_POLICY_RANGE(NLA_U16, 0, 255), | |
8027 | [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16), | |
8028 | [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1), | |
8029 | [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1), | |
8030 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1), | |
8031 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = | |
8032 | NLA_POLICY_RANGE(NLA_U32, 1, 255), | |
93da9cc1 | 8033 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
8034 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
ab0d76f6 | 8035 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1), |
93da9cc1 | 8036 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
ab0d76f6 JB |
8037 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = |
8038 | NLA_POLICY_MIN(NLA_U16, 1), | |
8039 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = | |
8040 | NLA_POLICY_MIN(NLA_U16, 1), | |
8041 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = | |
8042 | NLA_POLICY_MIN(NLA_U16, 1), | |
8043 | [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4), | |
8044 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = | |
8045 | NLA_POLICY_MIN(NLA_U16, 1), | |
8046 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1), | |
8047 | [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1), | |
8048 | [NL80211_MESHCONF_RSSI_THRESHOLD] = | |
8049 | NLA_POLICY_RANGE(NLA_S32, -255, 0), | |
a4f606ea | 8050 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
ac1073a6 | 8051 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
ab0d76f6 JB |
8052 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = |
8053 | NLA_POLICY_MIN(NLA_U16, 1), | |
8054 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = | |
8055 | NLA_POLICY_MIN(NLA_U16, 1), | |
8056 | [NL80211_MESHCONF_POWER_MODE] = | |
8057 | NLA_POLICY_RANGE(NLA_U32, | |
8058 | NL80211_MESH_POWER_ACTIVE, | |
8059 | NL80211_MESH_POWER_MAX), | |
3b1c5a53 | 8060 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
8e7c0538 | 8061 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
01d66fbd | 8062 | [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1), |
e3718a61 | 8063 | [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1), |
184eebe6 | 8064 | [NL80211_MESHCONF_CONNECTED_TO_AS] = NLA_POLICY_RANGE(NLA_U8, 0, 1), |
93da9cc1 | 8065 | }; |
8066 | ||
c80d545d JC |
8067 | static const struct nla_policy |
8068 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 8069 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
8070 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
8071 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 8072 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 8073 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 8074 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
3d7af878 JB |
8075 | [NL80211_MESH_SETUP_IE] = |
8076 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, | |
8077 | IEEE80211_MAX_DATA_LEN), | |
b130e5ce | 8078 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
8079 | }; |
8080 | ||
24bdd9f4 | 8081 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
8082 | struct mesh_config *cfg, |
8083 | u32 *mask_out) | |
93da9cc1 | 8084 | { |
93da9cc1 | 8085 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 8086 | u32 mask = 0; |
9757235f | 8087 | u16 ht_opmode; |
93da9cc1 | 8088 | |
ab0d76f6 JB |
8089 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \ |
8090 | do { \ | |
8091 | if (tb[attr]) { \ | |
8092 | cfg->param = fn(tb[attr]); \ | |
8093 | mask |= BIT((attr) - 1); \ | |
8094 | } \ | |
ea54fba2 | 8095 | } while (0) |
bd90fdcc | 8096 | |
24bdd9f4 | 8097 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 8098 | return -EINVAL; |
8cb08174 | 8099 | if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack)) |
93da9cc1 | 8100 | return -EINVAL; |
8101 | ||
93da9cc1 | 8102 | /* This makes sure that there aren't more than 32 mesh config |
8103 | * parameters (otherwise our bitfield scheme would not work.) */ | |
8104 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
8105 | ||
8106 | /* Fill in the params struct */ | |
ab0d76f6 JB |
8107 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask, |
8108 | NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); | |
8109 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask, | |
8110 | NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
8111 | nla_get_u16); | |
8112 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask, | |
8113 | NL80211_MESHCONF_HOLDING_TIMEOUT, | |
8114 | nla_get_u16); | |
8115 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask, | |
8116 | NL80211_MESHCONF_MAX_PEER_LINKS, | |
8117 | nla_get_u16); | |
8118 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask, | |
8119 | NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); | |
8120 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask, | |
8121 | NL80211_MESHCONF_TTL, nla_get_u8); | |
8122 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask, | |
8123 | NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); | |
8124 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask, | |
8125 | NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
8126 | nla_get_u8); | |
ea54fba2 | 8127 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
ab0d76f6 | 8128 | mask, |
a4f606ea | 8129 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
ab0d76f6 JB |
8130 | nla_get_u32); |
8131 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask, | |
8132 | NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | |
8133 | nla_get_u8); | |
8134 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask, | |
8135 | NL80211_MESHCONF_PATH_REFRESH_TIME, | |
8136 | nla_get_u32); | |
8137 | if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) && | |
8138 | (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535)) | |
8139 | return -EINVAL; | |
8140 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask, | |
8141 | NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
8142 | nla_get_u16); | |
ea54fba2 | 8143 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
ab0d76f6 | 8144 | mask, |
a4f606ea | 8145 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
ab0d76f6 JB |
8146 | nla_get_u32); |
8147 | if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) && | |
8148 | (cfg->dot11MeshHWMPactivePathTimeout < 1 || | |
8149 | cfg->dot11MeshHWMPactivePathTimeout > 65535)) | |
8150 | return -EINVAL; | |
8151 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask, | |
ea54fba2 | 8152 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
ab0d76f6 JB |
8153 | nla_get_u16); |
8154 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask, | |
ea54fba2 | 8155 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
ab0d76f6 | 8156 | nla_get_u16); |
93da9cc1 | 8157 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ab0d76f6 | 8158 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
a4f606ea | 8159 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
ab0d76f6 JB |
8160 | nla_get_u16); |
8161 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, | |
8162 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); | |
8163 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, | |
8164 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
8165 | nla_get_u16); | |
8166 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol, | |
ea54fba2 | 8167 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
ab0d76f6 JB |
8168 | nla_get_u8); |
8169 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask, | |
8170 | NL80211_MESHCONF_FORWARDING, nla_get_u8); | |
8171 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask, | |
8172 | NL80211_MESHCONF_RSSI_THRESHOLD, | |
8173 | nla_get_s32); | |
01d66fbd BC |
8174 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask, |
8175 | NL80211_MESHCONF_CONNECTED_TO_GATE, | |
8176 | nla_get_u8); | |
184eebe6 MT |
8177 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask, |
8178 | NL80211_MESHCONF_CONNECTED_TO_AS, | |
8179 | nla_get_u8); | |
9757235f MH |
8180 | /* |
8181 | * Check HT operation mode based on | |
188f60ab | 8182 | * IEEE 802.11-2016 9.4.2.57 HT Operation element. |
9757235f MH |
8183 | */ |
8184 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { | |
8185 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); | |
8186 | ||
8187 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | | |
8188 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | | |
8189 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) | |
8190 | return -EINVAL; | |
8191 | ||
188f60ab BC |
8192 | /* NON_HT_STA bit is reserved, but some programs set it */ |
8193 | ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; | |
9757235f | 8194 | |
9757235f | 8195 | cfg->ht_opmode = ht_opmode; |
fd551bac | 8196 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
9757235f | 8197 | } |
728b19e5 | 8198 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ab0d76f6 JB |
8199 | dot11MeshHWMPactivePathToRootTimeout, mask, |
8200 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
8201 | nla_get_u32); | |
8202 | if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) && | |
8203 | (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 || | |
8204 | cfg->dot11MeshHWMPactivePathToRootTimeout > 65535)) | |
8205 | return -EINVAL; | |
8206 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask, | |
8207 | NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
8208 | nla_get_u16); | |
8209 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval, | |
8210 | mask, | |
728b19e5 | 8211 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
ab0d76f6 JB |
8212 | nla_get_u16); |
8213 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask, | |
8214 | NL80211_MESHCONF_POWER_MODE, nla_get_u32); | |
8215 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask, | |
8216 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8217 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask, | |
8218 | NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32); | |
e3718a61 LL |
8219 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask, |
8220 | NL80211_MESHCONF_NOLEARN, nla_get_u8); | |
bd90fdcc JB |
8221 | if (mask_out) |
8222 | *mask_out = mask; | |
c80d545d | 8223 | |
bd90fdcc JB |
8224 | return 0; |
8225 | ||
8226 | #undef FILL_IN_MESH_PARAM_IF_SET | |
8227 | } | |
8228 | ||
c80d545d JC |
8229 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
8230 | struct mesh_setup *setup) | |
8231 | { | |
bb2798d4 | 8232 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
8233 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
8234 | ||
8235 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
8236 | return -EINVAL; | |
8cb08174 | 8237 | 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 |
8238 | return -EINVAL; |
8239 | ||
d299a1f2 JC |
8240 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
8241 | setup->sync_method = | |
8242 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
8243 | IEEE80211_SYNC_METHOD_VENDOR : | |
8244 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
8245 | ||
c80d545d JC |
8246 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
8247 | setup->path_sel_proto = | |
8248 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
8249 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
8250 | IEEE80211_PATH_PROTOCOL_HWMP; | |
8251 | ||
8252 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
8253 | setup->path_metric = | |
8254 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
8255 | IEEE80211_PATH_METRIC_VENDOR : | |
8256 | IEEE80211_PATH_METRIC_AIRTIME; | |
8257 | ||
581a8b0f | 8258 | if (tb[NL80211_MESH_SETUP_IE]) { |
c80d545d | 8259 | struct nlattr *ieattr = |
581a8b0f | 8260 | tb[NL80211_MESH_SETUP_IE]; |
581a8b0f JC |
8261 | setup->ie = nla_data(ieattr); |
8262 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 8263 | } |
bb2798d4 TP |
8264 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
8265 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
8266 | return -EINVAL; | |
8267 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
8268 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
8269 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
8270 | if (setup->is_secure) |
8271 | setup->user_mpm = true; | |
c80d545d | 8272 | |
6e16d90b CT |
8273 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
8274 | if (!setup->user_mpm) | |
8275 | return -EINVAL; | |
8276 | setup->auth_id = | |
8277 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
8278 | } | |
8279 | ||
c80d545d JC |
8280 | return 0; |
8281 | } | |
8282 | ||
24bdd9f4 | 8283 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 8284 | struct genl_info *info) |
bd90fdcc JB |
8285 | { |
8286 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8287 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 8288 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
8289 | struct mesh_config cfg; |
8290 | u32 mask; | |
8291 | int err; | |
8292 | ||
29cbe68c JB |
8293 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
8294 | return -EOPNOTSUPP; | |
8295 | ||
24bdd9f4 | 8296 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
8297 | return -EOPNOTSUPP; |
8298 | ||
24bdd9f4 | 8299 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
8300 | if (err) |
8301 | return err; | |
8302 | ||
29cbe68c | 8303 | wdev_lock(wdev); |
7b0a0e3c | 8304 | if (!wdev->u.mesh.id_len) |
29cbe68c JB |
8305 | err = -ENOLINK; |
8306 | ||
8307 | if (!err) | |
e35e4d28 | 8308 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
8309 | |
8310 | wdev_unlock(wdev); | |
8311 | ||
8312 | return err; | |
93da9cc1 | 8313 | } |
8314 | ||
ad30ca2c AN |
8315 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
8316 | struct sk_buff *msg) | |
f130347c | 8317 | { |
f130347c LR |
8318 | struct nlattr *nl_reg_rules; |
8319 | unsigned int i; | |
f130347c | 8320 | |
458f4f9e JB |
8321 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
8322 | (regdom->dfs_region && | |
8323 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
ad30ca2c | 8324 | goto nla_put_failure; |
458f4f9e | 8325 | |
ae0be8de | 8326 | nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES); |
f130347c | 8327 | if (!nl_reg_rules) |
ad30ca2c | 8328 | goto nla_put_failure; |
f130347c | 8329 | |
458f4f9e | 8330 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
8331 | struct nlattr *nl_reg_rule; |
8332 | const struct ieee80211_reg_rule *reg_rule; | |
8333 | const struct ieee80211_freq_range *freq_range; | |
8334 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 8335 | unsigned int max_bandwidth_khz; |
f130347c | 8336 | |
458f4f9e | 8337 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
8338 | freq_range = ®_rule->freq_range; |
8339 | power_rule = ®_rule->power_rule; | |
8340 | ||
ae0be8de | 8341 | nl_reg_rule = nla_nest_start_noflag(msg, i); |
f130347c | 8342 | if (!nl_reg_rule) |
ad30ca2c | 8343 | goto nla_put_failure; |
f130347c | 8344 | |
97524820 JD |
8345 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
8346 | if (!max_bandwidth_khz) | |
8347 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
8348 | reg_rule); | |
8349 | ||
9360ffd1 DM |
8350 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
8351 | reg_rule->flags) || | |
8352 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
8353 | freq_range->start_freq_khz) || | |
8354 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
8355 | freq_range->end_freq_khz) || | |
8356 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 8357 | max_bandwidth_khz) || |
9360ffd1 DM |
8358 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
8359 | power_rule->max_antenna_gain) || | |
8360 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
8361 | power_rule->max_eirp) || |
8362 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
8363 | reg_rule->dfs_cac_ms)) | |
ad30ca2c | 8364 | goto nla_put_failure; |
f130347c LR |
8365 | |
8366 | nla_nest_end(msg, nl_reg_rule); | |
8367 | } | |
8368 | ||
8369 | nla_nest_end(msg, nl_reg_rules); | |
ad30ca2c AN |
8370 | return 0; |
8371 | ||
8372 | nla_put_failure: | |
8373 | return -EMSGSIZE; | |
8374 | } | |
8375 | ||
8376 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | |
8377 | { | |
8378 | const struct ieee80211_regdomain *regdom = NULL; | |
8379 | struct cfg80211_registered_device *rdev; | |
8380 | struct wiphy *wiphy = NULL; | |
8381 | struct sk_buff *msg; | |
024fcf5e | 8382 | int err = -EMSGSIZE; |
ad30ca2c AN |
8383 | void *hdr; |
8384 | ||
8385 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8386 | if (!msg) | |
8387 | return -ENOBUFS; | |
8388 | ||
8389 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8390 | NL80211_CMD_GET_REG); | |
8391 | if (!hdr) | |
8392 | goto put_failure; | |
8393 | ||
a05829a7 JB |
8394 | rtnl_lock(); |
8395 | ||
ad30ca2c | 8396 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
1bdd716c AN |
8397 | bool self_managed; |
8398 | ||
ad30ca2c AN |
8399 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
8400 | if (IS_ERR(rdev)) { | |
024fcf5e JB |
8401 | err = PTR_ERR(rdev); |
8402 | goto nla_put_failure; | |
ad30ca2c AN |
8403 | } |
8404 | ||
8405 | wiphy = &rdev->wiphy; | |
1bdd716c AN |
8406 | self_managed = wiphy->regulatory_flags & |
8407 | REGULATORY_WIPHY_SELF_MANAGED; | |
024fcf5e JB |
8408 | |
8409 | rcu_read_lock(); | |
8410 | ||
ad30ca2c AN |
8411 | regdom = get_wiphy_regdom(wiphy); |
8412 | ||
1bdd716c AN |
8413 | /* a self-managed-reg device must have a private regdom */ |
8414 | if (WARN_ON(!regdom && self_managed)) { | |
024fcf5e JB |
8415 | err = -EINVAL; |
8416 | goto nla_put_failure_rcu; | |
1bdd716c AN |
8417 | } |
8418 | ||
ad30ca2c AN |
8419 | if (regdom && |
8420 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
024fcf5e JB |
8421 | goto nla_put_failure_rcu; |
8422 | } else { | |
8423 | rcu_read_lock(); | |
ad30ca2c AN |
8424 | } |
8425 | ||
8426 | if (!wiphy && reg_last_request_cell_base() && | |
8427 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
8428 | NL80211_USER_REG_HINT_CELL_BASE)) | |
024fcf5e | 8429 | goto nla_put_failure_rcu; |
ad30ca2c AN |
8430 | |
8431 | if (!regdom) | |
8432 | regdom = rcu_dereference(cfg80211_regdomain); | |
8433 | ||
8434 | if (nl80211_put_regdom(regdom, msg)) | |
8435 | goto nla_put_failure_rcu; | |
8436 | ||
8437 | rcu_read_unlock(); | |
f130347c LR |
8438 | |
8439 | genlmsg_end(msg, hdr); | |
a05829a7 | 8440 | rtnl_unlock(); |
5fe231e8 | 8441 | return genlmsg_reply(msg, info); |
f130347c | 8442 | |
458f4f9e JB |
8443 | nla_put_failure_rcu: |
8444 | rcu_read_unlock(); | |
f130347c | 8445 | nla_put_failure: |
a05829a7 | 8446 | rtnl_unlock(); |
efe1cf0c | 8447 | put_failure: |
d080e275 | 8448 | nlmsg_free(msg); |
024fcf5e | 8449 | return err; |
f130347c LR |
8450 | } |
8451 | ||
ad30ca2c AN |
8452 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
8453 | u32 seq, int flags, struct wiphy *wiphy, | |
8454 | const struct ieee80211_regdomain *regdom) | |
8455 | { | |
8456 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | |
8457 | NL80211_CMD_GET_REG); | |
8458 | ||
8459 | if (!hdr) | |
8460 | return -1; | |
8461 | ||
0a833c29 | 8462 | genl_dump_check_consistent(cb, hdr); |
ad30ca2c AN |
8463 | |
8464 | if (nl80211_put_regdom(regdom, msg)) | |
8465 | goto nla_put_failure; | |
8466 | ||
8467 | if (!wiphy && reg_last_request_cell_base() && | |
8468 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
8469 | NL80211_USER_REG_HINT_CELL_BASE)) | |
8470 | goto nla_put_failure; | |
8471 | ||
8472 | if (wiphy && | |
8473 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
8474 | goto nla_put_failure; | |
8475 | ||
1bdd716c AN |
8476 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
8477 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
8478 | goto nla_put_failure; | |
8479 | ||
053c095a JB |
8480 | genlmsg_end(msg, hdr); |
8481 | return 0; | |
ad30ca2c AN |
8482 | |
8483 | nla_put_failure: | |
8484 | genlmsg_cancel(msg, hdr); | |
8485 | return -EMSGSIZE; | |
8486 | } | |
8487 | ||
8488 | static int nl80211_get_reg_dump(struct sk_buff *skb, | |
8489 | struct netlink_callback *cb) | |
8490 | { | |
8491 | const struct ieee80211_regdomain *regdom = NULL; | |
8492 | struct cfg80211_registered_device *rdev; | |
8493 | int err, reg_idx, start = cb->args[2]; | |
8494 | ||
024fcf5e | 8495 | rcu_read_lock(); |
ad30ca2c AN |
8496 | |
8497 | if (cfg80211_regdomain && start == 0) { | |
8498 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
8499 | NLM_F_MULTI, NULL, | |
024fcf5e | 8500 | rcu_dereference(cfg80211_regdomain)); |
ad30ca2c AN |
8501 | if (err < 0) |
8502 | goto out_err; | |
8503 | } | |
8504 | ||
8505 | /* the global regdom is idx 0 */ | |
8506 | reg_idx = 1; | |
024fcf5e | 8507 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
ad30ca2c AN |
8508 | regdom = get_wiphy_regdom(&rdev->wiphy); |
8509 | if (!regdom) | |
8510 | continue; | |
8511 | ||
8512 | if (++reg_idx <= start) | |
8513 | continue; | |
8514 | ||
8515 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
8516 | NLM_F_MULTI, &rdev->wiphy, regdom); | |
8517 | if (err < 0) { | |
8518 | reg_idx--; | |
8519 | break; | |
8520 | } | |
8521 | } | |
8522 | ||
8523 | cb->args[2] = reg_idx; | |
8524 | err = skb->len; | |
8525 | out_err: | |
024fcf5e | 8526 | rcu_read_unlock(); |
ad30ca2c AN |
8527 | return err; |
8528 | } | |
8529 | ||
b6863036 JB |
8530 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
8531 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { | |
8532 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, | |
8533 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
8534 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
8535 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
8536 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
8537 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
8538 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, | |
8539 | }; | |
8540 | ||
8541 | static int parse_reg_rule(struct nlattr *tb[], | |
8542 | struct ieee80211_reg_rule *reg_rule) | |
8543 | { | |
8544 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
8545 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
8546 | ||
8547 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
8548 | return -EINVAL; | |
8549 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
8550 | return -EINVAL; | |
8551 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
8552 | return -EINVAL; | |
8553 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
8554 | return -EINVAL; | |
8555 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
8556 | return -EINVAL; | |
8557 | ||
8558 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
8559 | ||
8560 | freq_range->start_freq_khz = | |
8561 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
8562 | freq_range->end_freq_khz = | |
8563 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
8564 | freq_range->max_bandwidth_khz = | |
8565 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
8566 | ||
8567 | power_rule->max_eirp = | |
8568 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
8569 | ||
8570 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
8571 | power_rule->max_antenna_gain = | |
8572 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
8573 | ||
8574 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) | |
8575 | reg_rule->dfs_cac_ms = | |
8576 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
8577 | ||
8578 | return 0; | |
8579 | } | |
8580 | ||
b2e1b302 LR |
8581 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
8582 | { | |
8583 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
8584 | struct nlattr *nl_reg_rule; | |
ea372c54 JB |
8585 | char *alpha2; |
8586 | int rem_reg_rules, r; | |
391d132c | 8587 | u32 num_rules = 0, rule_idx = 0; |
4c7d3982 | 8588 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
ea372c54 | 8589 | struct ieee80211_regdomain *rd; |
b2e1b302 LR |
8590 | |
8591 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
8592 | return -EINVAL; | |
8593 | ||
8594 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
8595 | return -EINVAL; | |
8596 | ||
8597 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
8598 | ||
8b60b078 LR |
8599 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
8600 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
8601 | ||
b2e1b302 | 8602 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 8603 | rem_reg_rules) { |
b2e1b302 LR |
8604 | num_rules++; |
8605 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 8606 | return -EINVAL; |
b2e1b302 LR |
8607 | } |
8608 | ||
a05829a7 JB |
8609 | rtnl_lock(); |
8610 | if (!reg_is_valid_request(alpha2)) { | |
8611 | r = -EINVAL; | |
8612 | goto out; | |
8613 | } | |
e438768f | 8614 | |
391d132c | 8615 | rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL); |
a05829a7 JB |
8616 | if (!rd) { |
8617 | r = -ENOMEM; | |
8618 | goto out; | |
8619 | } | |
b2e1b302 LR |
8620 | |
8621 | rd->n_reg_rules = num_rules; | |
8622 | rd->alpha2[0] = alpha2[0]; | |
8623 | rd->alpha2[1] = alpha2[1]; | |
8624 | ||
8b60b078 LR |
8625 | /* |
8626 | * Disable DFS master mode if the DFS region was | |
8627 | * not supported or known on this kernel. | |
8628 | */ | |
8629 | if (reg_supported_dfs_region(dfs_region)) | |
8630 | rd->dfs_region = dfs_region; | |
8631 | ||
b2e1b302 | 8632 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 8633 | rem_reg_rules) { |
8cb08174 JB |
8634 | r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX, |
8635 | nl_reg_rule, reg_rule_policy, | |
8636 | info->extack); | |
ae811e21 JB |
8637 | if (r) |
8638 | goto bad_reg; | |
b2e1b302 LR |
8639 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
8640 | if (r) | |
8641 | goto bad_reg; | |
8642 | ||
8643 | rule_idx++; | |
8644 | ||
d0e18f83 LR |
8645 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
8646 | r = -EINVAL; | |
b2e1b302 | 8647 | goto bad_reg; |
d0e18f83 | 8648 | } |
b2e1b302 LR |
8649 | } |
8650 | ||
a05829a7 | 8651 | r = set_regdom(rd, REGD_SOURCE_CRDA); |
06627990 | 8652 | /* set_regdom takes ownership of rd */ |
a05829a7 | 8653 | rd = NULL; |
d2372b31 | 8654 | bad_reg: |
b2e1b302 | 8655 | kfree(rd); |
a05829a7 JB |
8656 | out: |
8657 | rtnl_unlock(); | |
d0e18f83 | 8658 | return r; |
b2e1b302 | 8659 | } |
b6863036 | 8660 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
b2e1b302 | 8661 | |
83f5e2cf JB |
8662 | static int validate_scan_freqs(struct nlattr *freqs) |
8663 | { | |
8664 | struct nlattr *attr1, *attr2; | |
8665 | int n_channels = 0, tmp1, tmp2; | |
8666 | ||
d7f13f74 SD |
8667 | nla_for_each_nested(attr1, freqs, tmp1) |
8668 | if (nla_len(attr1) != sizeof(u32)) | |
8669 | return 0; | |
8670 | ||
83f5e2cf JB |
8671 | nla_for_each_nested(attr1, freqs, tmp1) { |
8672 | n_channels++; | |
8673 | /* | |
8674 | * Some hardware has a limited channel list for | |
8675 | * scanning, and it is pretty much nonsensical | |
8676 | * to scan for a channel twice, so disallow that | |
8677 | * and don't require drivers to check that the | |
8678 | * channel list they get isn't longer than what | |
8679 | * they can scan, as long as they can scan all | |
8680 | * the channels they registered at once. | |
8681 | */ | |
8682 | nla_for_each_nested(attr2, freqs, tmp2) | |
8683 | if (attr1 != attr2 && | |
8684 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
8685 | return 0; | |
8686 | } | |
8687 | ||
8688 | return n_channels; | |
8689 | } | |
8690 | ||
57fbcce3 | 8691 | static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) |
38de03d2 | 8692 | { |
57fbcce3 | 8693 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
38de03d2 AS |
8694 | } |
8695 | ||
8696 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, | |
8697 | struct cfg80211_bss_selection *bss_select) | |
8698 | { | |
8699 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; | |
8700 | struct nlattr *nest; | |
8701 | int err; | |
8702 | bool found = false; | |
8703 | int i; | |
8704 | ||
8705 | /* only process one nested attribute */ | |
8706 | nest = nla_data(nla); | |
8707 | if (!nla_ok(nest, nla_len(nest))) | |
8708 | return -EINVAL; | |
8709 | ||
8cb08174 JB |
8710 | err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX, |
8711 | nest, nl80211_bss_select_policy, | |
8712 | NULL); | |
38de03d2 AS |
8713 | if (err) |
8714 | return err; | |
8715 | ||
8716 | /* only one attribute may be given */ | |
8717 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { | |
8718 | if (attr[i]) { | |
8719 | if (found) | |
8720 | return -EINVAL; | |
8721 | found = true; | |
8722 | } | |
8723 | } | |
8724 | ||
8725 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; | |
8726 | ||
8727 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) | |
8728 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; | |
8729 | ||
8730 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { | |
8731 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; | |
8732 | bss_select->param.band_pref = | |
8733 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); | |
8734 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) | |
8735 | return -EINVAL; | |
8736 | } | |
8737 | ||
8738 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { | |
8739 | struct nl80211_bss_select_rssi_adjust *adj_param; | |
8740 | ||
8741 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); | |
8742 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; | |
8743 | bss_select->param.adjust.band = adj_param->band; | |
8744 | bss_select->param.adjust.delta = adj_param->delta; | |
8745 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) | |
8746 | return -EINVAL; | |
8747 | } | |
8748 | ||
8749 | /* user-space did not provide behaviour attribute */ | |
8750 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) | |
8751 | return -EINVAL; | |
8752 | ||
8753 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) | |
8754 | return -EINVAL; | |
8755 | ||
8756 | return 0; | |
8757 | } | |
8758 | ||
9bb7e0f2 JB |
8759 | int nl80211_parse_random_mac(struct nlattr **attrs, |
8760 | u8 *mac_addr, u8 *mac_addr_mask) | |
ad2b26ab JB |
8761 | { |
8762 | int i; | |
8763 | ||
8764 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | |
d2beae10 JP |
8765 | eth_zero_addr(mac_addr); |
8766 | eth_zero_addr(mac_addr_mask); | |
ad2b26ab JB |
8767 | mac_addr[0] = 0x2; |
8768 | mac_addr_mask[0] = 0x3; | |
8769 | ||
8770 | return 0; | |
8771 | } | |
8772 | ||
8773 | /* need both or none */ | |
8774 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | |
8775 | return -EINVAL; | |
8776 | ||
8777 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | |
8778 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | |
8779 | ||
8780 | /* don't allow or configure an mcast address */ | |
8781 | if (!is_multicast_ether_addr(mac_addr_mask) || | |
8782 | is_multicast_ether_addr(mac_addr)) | |
8783 | return -EINVAL; | |
8784 | ||
8785 | /* | |
8786 | * allow users to pass a MAC address that has bits set outside | |
8787 | * of the mask, but don't bother drivers with having to deal | |
8788 | * with such bits | |
8789 | */ | |
8790 | for (i = 0; i < ETH_ALEN; i++) | |
8791 | mac_addr[i] &= mac_addr_mask[i]; | |
8792 | ||
8793 | return 0; | |
8794 | } | |
8795 | ||
7b0a0e3c JB |
8796 | static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev, |
8797 | struct ieee80211_channel *chan) | |
34373d12 | 8798 | { |
7b0a0e3c JB |
8799 | unsigned int link_id; |
8800 | bool all_ok = true; | |
8801 | ||
34373d12 VT |
8802 | ASSERT_WDEV_LOCK(wdev); |
8803 | ||
8804 | if (!cfg80211_beaconing_iface_active(wdev)) | |
8805 | return true; | |
8806 | ||
7b0a0e3c JB |
8807 | /* |
8808 | * FIXME: check if we have a free HW resource/link for chan | |
8809 | * | |
8810 | * This, as well as the FIXME below, requires knowing the link | |
8811 | * capabilities of the hardware. | |
8812 | */ | |
8813 | ||
8814 | /* we cannot leave radar channels */ | |
8815 | for_each_valid_link(wdev, link_id) { | |
8816 | struct cfg80211_chan_def *chandef; | |
8817 | ||
8818 | chandef = wdev_chandef(wdev, link_id); | |
8819 | if (!chandef) | |
8820 | continue; | |
8821 | ||
8822 | /* | |
8823 | * FIXME: don't require all_ok, but rather check only the | |
8824 | * correct HW resource/link onto which 'chan' falls, | |
8825 | * as only that link leaves the channel for doing | |
8826 | * the off-channel operation. | |
8827 | */ | |
8828 | ||
8829 | if (chandef->chan->flags & IEEE80211_CHAN_RADAR) | |
8830 | all_ok = false; | |
8831 | } | |
8832 | ||
8833 | if (all_ok) | |
34373d12 VT |
8834 | return true; |
8835 | ||
8836 | return regulatory_pre_cac_allowed(wdev->wiphy); | |
8837 | } | |
8838 | ||
db0a4ad8 JB |
8839 | static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, |
8840 | enum nl80211_ext_feature_index feat) | |
8841 | { | |
8842 | if (!(flags & flag)) | |
8843 | return true; | |
8844 | if (wiphy_ext_feature_isset(wiphy, feat)) | |
8845 | return true; | |
8846 | return false; | |
8847 | } | |
8848 | ||
2d23d073 RZ |
8849 | static int |
8850 | nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, | |
8851 | void *request, struct nlattr **attrs, | |
8852 | bool is_sched_scan) | |
8853 | { | |
8854 | u8 *mac_addr, *mac_addr_mask; | |
8855 | u32 *flags; | |
8856 | enum nl80211_feature_flags randomness_flag; | |
8857 | ||
8858 | if (!attrs[NL80211_ATTR_SCAN_FLAGS]) | |
8859 | return 0; | |
8860 | ||
8861 | if (is_sched_scan) { | |
8862 | struct cfg80211_sched_scan_request *req = request; | |
8863 | ||
8864 | randomness_flag = wdev ? | |
8865 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : | |
8866 | NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
8867 | flags = &req->flags; | |
8868 | mac_addr = req->mac_addr; | |
8869 | mac_addr_mask = req->mac_addr_mask; | |
8870 | } else { | |
8871 | struct cfg80211_scan_request *req = request; | |
8872 | ||
8873 | randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; | |
8874 | flags = &req->flags; | |
8875 | mac_addr = req->mac_addr; | |
8876 | mac_addr_mask = req->mac_addr_mask; | |
8877 | } | |
8878 | ||
8879 | *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); | |
8880 | ||
5037a009 SD |
8881 | if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
8882 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | |
db0a4ad8 JB |
8883 | !nl80211_check_scan_feat(wiphy, *flags, |
8884 | NL80211_SCAN_FLAG_LOW_SPAN, | |
8885 | NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || | |
8886 | !nl80211_check_scan_feat(wiphy, *flags, | |
8887 | NL80211_SCAN_FLAG_LOW_POWER, | |
8888 | NL80211_EXT_FEATURE_LOW_POWER_SCAN) || | |
8889 | !nl80211_check_scan_feat(wiphy, *flags, | |
8890 | NL80211_SCAN_FLAG_HIGH_ACCURACY, | |
8891 | NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || | |
8892 | !nl80211_check_scan_feat(wiphy, *flags, | |
8893 | NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, | |
8894 | NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || | |
8895 | !nl80211_check_scan_feat(wiphy, *flags, | |
8896 | NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, | |
8897 | NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || | |
8898 | !nl80211_check_scan_feat(wiphy, *flags, | |
8899 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, | |
8900 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || | |
8901 | !nl80211_check_scan_feat(wiphy, *flags, | |
8902 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, | |
2e076f19 JB |
8903 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || |
8904 | !nl80211_check_scan_feat(wiphy, *flags, | |
8905 | NL80211_SCAN_FLAG_RANDOM_SN, | |
8906 | NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || | |
8907 | !nl80211_check_scan_feat(wiphy, *flags, | |
8908 | NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, | |
8909 | NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) | |
2d23d073 RZ |
8910 | return -EOPNOTSUPP; |
8911 | ||
8912 | if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
8913 | int err; | |
8914 | ||
8915 | if (!(wiphy->features & randomness_flag) || | |
7b0a0e3c | 8916 | (wdev && wdev->connected)) |
2d23d073 RZ |
8917 | return -EOPNOTSUPP; |
8918 | ||
8919 | err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); | |
8920 | if (err) | |
8921 | return err; | |
8922 | } | |
8923 | ||
2d23d073 RZ |
8924 | return 0; |
8925 | } | |
8926 | ||
2a519311 JB |
8927 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
8928 | { | |
4c476991 | 8929 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 8930 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 8931 | struct cfg80211_scan_request *request; |
2032f3b2 TP |
8932 | struct nlattr *scan_freqs = NULL; |
8933 | bool scan_freqs_khz = false; | |
2a519311 JB |
8934 | struct nlattr *attr; |
8935 | struct wiphy *wiphy; | |
83f5e2cf | 8936 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 8937 | size_t ie_len; |
2a519311 | 8938 | |
79c97e97 | 8939 | wiphy = &rdev->wiphy; |
2a519311 | 8940 | |
cb3b7d87 AB |
8941 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
8942 | return -EOPNOTSUPP; | |
8943 | ||
4c476991 JB |
8944 | if (!rdev->ops->scan) |
8945 | return -EOPNOTSUPP; | |
2a519311 | 8946 | |
83286856 CJ |
8947 | if (rdev->scan_req || rdev->scan_msg) |
8948 | return -EBUSY; | |
2a519311 | 8949 | |
2032f3b2 TP |
8950 | if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) { |
8951 | if (!wiphy_ext_feature_isset(wiphy, | |
8952 | NL80211_EXT_FEATURE_SCAN_FREQ_KHZ)) | |
8953 | return -EOPNOTSUPP; | |
8954 | scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]; | |
8955 | scan_freqs_khz = true; | |
8956 | } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) | |
8957 | scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]; | |
8958 | ||
8959 | if (scan_freqs) { | |
8960 | n_channels = validate_scan_freqs(scan_freqs); | |
83286856 CJ |
8961 | if (!n_channels) |
8962 | return -EINVAL; | |
2a519311 | 8963 | } else { |
bdfbec2d | 8964 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
8965 | } |
8966 | ||
8967 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
8968 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
8969 | n_ssids++; | |
8970 | ||
83286856 CJ |
8971 | if (n_ssids > wiphy->max_scan_ssids) |
8972 | return -EINVAL; | |
2a519311 | 8973 | |
70692ad2 JM |
8974 | if (info->attrs[NL80211_ATTR_IE]) |
8975 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8976 | else | |
8977 | ie_len = 0; | |
8978 | ||
83286856 CJ |
8979 | if (ie_len > wiphy->max_scan_ie_len) |
8980 | return -EINVAL; | |
18a83659 | 8981 | |
2a519311 | 8982 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
8983 | + sizeof(*request->ssids) * n_ssids |
8984 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 8985 | + ie_len, GFP_KERNEL); |
83286856 CJ |
8986 | if (!request) |
8987 | return -ENOMEM; | |
2a519311 | 8988 | |
2a519311 | 8989 | if (n_ssids) |
5ba63533 | 8990 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 8991 | request->n_ssids = n_ssids; |
70692ad2 | 8992 | if (ie_len) { |
13874e4b | 8993 | if (n_ssids) |
70692ad2 JM |
8994 | request->ie = (void *)(request->ssids + n_ssids); |
8995 | else | |
8996 | request->ie = (void *)(request->channels + n_channels); | |
8997 | } | |
2a519311 | 8998 | |
584991dc | 8999 | i = 0; |
2032f3b2 | 9000 | if (scan_freqs) { |
2a519311 | 9001 | /* user specified, bail out if channel not found */ |
2032f3b2 | 9002 | nla_for_each_nested(attr, scan_freqs, tmp) { |
584991dc | 9003 | struct ieee80211_channel *chan; |
2032f3b2 | 9004 | int freq = nla_get_u32(attr); |
584991dc | 9005 | |
2032f3b2 TP |
9006 | if (!scan_freqs_khz) |
9007 | freq = MHZ_TO_KHZ(freq); | |
584991dc | 9008 | |
2032f3b2 | 9009 | chan = ieee80211_get_channel_khz(wiphy, freq); |
584991dc | 9010 | if (!chan) { |
2a519311 JB |
9011 | err = -EINVAL; |
9012 | goto out_free; | |
9013 | } | |
584991dc JB |
9014 | |
9015 | /* ignore disabled channels */ | |
9016 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
9017 | continue; | |
9018 | ||
9019 | request->channels[i] = chan; | |
2a519311 JB |
9020 | i++; |
9021 | } | |
9022 | } else { | |
57fbcce3 | 9023 | enum nl80211_band band; |
34850ab2 | 9024 | |
2a519311 | 9025 | /* all channels */ |
57fbcce3 | 9026 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
2a519311 | 9027 | int j; |
7a087e74 | 9028 | |
2a519311 JB |
9029 | if (!wiphy->bands[band]) |
9030 | continue; | |
9031 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
9032 | struct ieee80211_channel *chan; |
9033 | ||
9034 | chan = &wiphy->bands[band]->channels[j]; | |
9035 | ||
9036 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
9037 | continue; | |
9038 | ||
9039 | request->channels[i] = chan; | |
2a519311 JB |
9040 | i++; |
9041 | } | |
9042 | } | |
9043 | } | |
9044 | ||
584991dc JB |
9045 | if (!i) { |
9046 | err = -EINVAL; | |
9047 | goto out_free; | |
9048 | } | |
9049 | ||
9050 | request->n_channels = i; | |
9051 | ||
34373d12 | 9052 | wdev_lock(wdev); |
7b0a0e3c JB |
9053 | for (i = 0; i < request->n_channels; i++) { |
9054 | struct ieee80211_channel *chan = request->channels[i]; | |
34373d12 | 9055 | |
7b0a0e3c JB |
9056 | /* if we can go off-channel to the target channel we're good */ |
9057 | if (cfg80211_off_channel_oper_allowed(wdev, chan)) | |
9058 | continue; | |
34373d12 | 9059 | |
7b0a0e3c | 9060 | if (!cfg80211_wdev_on_sub_chan(wdev, chan, true)) { |
34373d12 VT |
9061 | wdev_unlock(wdev); |
9062 | err = -EBUSY; | |
9063 | goto out_free; | |
9064 | } | |
9065 | } | |
9066 | wdev_unlock(wdev); | |
9067 | ||
2a519311 | 9068 | i = 0; |
13874e4b | 9069 | if (n_ssids) { |
2a519311 | 9070 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
57a27e1d | 9071 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
9072 | err = -EINVAL; |
9073 | goto out_free; | |
9074 | } | |
57a27e1d | 9075 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 9076 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
9077 | i++; |
9078 | } | |
9079 | } | |
9080 | ||
70692ad2 JM |
9081 | if (info->attrs[NL80211_ATTR_IE]) { |
9082 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
9083 | memcpy((void *)request->ie, |
9084 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
9085 | request->ie_len); |
9086 | } | |
9087 | ||
57fbcce3 | 9088 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
a401d2bb JB |
9089 | if (wiphy->bands[i]) |
9090 | request->rates[i] = | |
9091 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
9092 | |
9093 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
9094 | nla_for_each_nested(attr, | |
9095 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
9096 | tmp) { | |
57fbcce3 | 9097 | enum nl80211_band band = nla_type(attr); |
34850ab2 | 9098 | |
57fbcce3 | 9099 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
34850ab2 JB |
9100 | err = -EINVAL; |
9101 | goto out_free; | |
9102 | } | |
1b09cd82 FF |
9103 | |
9104 | if (!wiphy->bands[band]) | |
9105 | continue; | |
9106 | ||
34850ab2 JB |
9107 | err = ieee80211_get_ratemask(wiphy->bands[band], |
9108 | nla_data(attr), | |
9109 | nla_len(attr), | |
9110 | &request->rates[band]); | |
9111 | if (err) | |
9112 | goto out_free; | |
9113 | } | |
9114 | } | |
9115 | ||
1d76250b | 9116 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
1d76250b AS |
9117 | request->duration = |
9118 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); | |
9119 | request->duration_mandatory = | |
9120 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); | |
9121 | } | |
9122 | ||
2d23d073 RZ |
9123 | err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, |
9124 | false); | |
9125 | if (err) | |
9126 | goto out_free; | |
ed473771 | 9127 | |
e9f935e3 RM |
9128 | request->no_cck = |
9129 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
9130 | ||
2fa436b3 VK |
9131 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
9132 | * BSSID to scan for. This was problematic because that same attribute | |
9133 | * was already used for another purpose (local random MAC address). The | |
9134 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards | |
9135 | * compatibility with older userspace components, also use the | |
9136 | * NL80211_ATTR_MAC value here if it can be determined to be used for | |
9137 | * the specific BSSID use case instead of the random MAC address | |
9138 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). | |
9139 | */ | |
9140 | if (info->attrs[NL80211_ATTR_BSSID]) | |
9141 | memcpy(request->bssid, | |
9142 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); | |
9143 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && | |
9144 | info->attrs[NL80211_ATTR_MAC]) | |
818965d3 JM |
9145 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
9146 | ETH_ALEN); | |
9147 | else | |
9148 | eth_broadcast_addr(request->bssid); | |
9149 | ||
fd014284 | 9150 | request->wdev = wdev; |
79c97e97 | 9151 | request->wiphy = &rdev->wiphy; |
15d6030b | 9152 | request->scan_start = jiffies; |
2a519311 | 9153 | |
79c97e97 | 9154 | rdev->scan_req = request; |
c8cb5b85 | 9155 | err = cfg80211_scan(rdev); |
2a519311 | 9156 | |
504776be CJ |
9157 | if (err) |
9158 | goto out_free; | |
9159 | ||
9160 | nl80211_send_scan_start(rdev, wdev); | |
1160dfa1 | 9161 | dev_hold(wdev->netdev); |
504776be CJ |
9162 | |
9163 | return 0; | |
9164 | ||
2a519311 | 9165 | out_free: |
504776be CJ |
9166 | rdev->scan_req = NULL; |
9167 | kfree(request); | |
3b85875a | 9168 | |
2a519311 JB |
9169 | return err; |
9170 | } | |
9171 | ||
91d3ab46 VK |
9172 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
9173 | { | |
9174 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9175 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9176 | ||
9177 | if (!rdev->ops->abort_scan) | |
9178 | return -EOPNOTSUPP; | |
9179 | ||
9180 | if (rdev->scan_msg) | |
9181 | return 0; | |
9182 | ||
9183 | if (!rdev->scan_req) | |
9184 | return -ENOENT; | |
9185 | ||
9186 | rdev_abort_scan(rdev, wdev); | |
9187 | return 0; | |
9188 | } | |
9189 | ||
3b06d277 AS |
9190 | static int |
9191 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, | |
9192 | struct cfg80211_sched_scan_request *request, | |
9193 | struct nlattr **attrs) | |
9194 | { | |
9195 | int tmp, err, i = 0; | |
9196 | struct nlattr *attr; | |
9197 | ||
9198 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { | |
9199 | u32 interval; | |
9200 | ||
9201 | /* | |
9202 | * If scan plans are not specified, | |
5a88de53 | 9203 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this |
3b06d277 AS |
9204 | * case one scan plan will be set with the specified scan |
9205 | * interval and infinite number of iterations. | |
9206 | */ | |
3b06d277 AS |
9207 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
9208 | if (!interval) | |
9209 | return -EINVAL; | |
9210 | ||
9211 | request->scan_plans[0].interval = | |
9212 | DIV_ROUND_UP(interval, MSEC_PER_SEC); | |
9213 | if (!request->scan_plans[0].interval) | |
9214 | return -EINVAL; | |
9215 | ||
9216 | if (request->scan_plans[0].interval > | |
9217 | wiphy->max_sched_scan_plan_interval) | |
9218 | request->scan_plans[0].interval = | |
9219 | wiphy->max_sched_scan_plan_interval; | |
9220 | ||
9221 | return 0; | |
9222 | } | |
9223 | ||
9224 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { | |
9225 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; | |
9226 | ||
9227 | if (WARN_ON(i >= n_plans)) | |
9228 | return -EINVAL; | |
9229 | ||
8cb08174 JB |
9230 | err = nla_parse_nested_deprecated(plan, |
9231 | NL80211_SCHED_SCAN_PLAN_MAX, | |
9232 | attr, nl80211_plan_policy, | |
9233 | NULL); | |
3b06d277 AS |
9234 | if (err) |
9235 | return err; | |
9236 | ||
9237 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) | |
9238 | return -EINVAL; | |
9239 | ||
9240 | request->scan_plans[i].interval = | |
9241 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); | |
9242 | if (!request->scan_plans[i].interval || | |
9243 | request->scan_plans[i].interval > | |
9244 | wiphy->max_sched_scan_plan_interval) | |
9245 | return -EINVAL; | |
9246 | ||
9247 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { | |
9248 | request->scan_plans[i].iterations = | |
9249 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); | |
9250 | if (!request->scan_plans[i].iterations || | |
9251 | (request->scan_plans[i].iterations > | |
9252 | wiphy->max_sched_scan_plan_iterations)) | |
9253 | return -EINVAL; | |
9254 | } else if (i < n_plans - 1) { | |
9255 | /* | |
9256 | * All scan plans but the last one must specify | |
9257 | * a finite number of iterations | |
9258 | */ | |
9259 | return -EINVAL; | |
9260 | } | |
9261 | ||
9262 | i++; | |
9263 | } | |
9264 | ||
9265 | /* | |
9266 | * The last scan plan must not specify the number of | |
9267 | * iterations, it is supposed to run infinitely | |
9268 | */ | |
9269 | if (request->scan_plans[n_plans - 1].iterations) | |
9270 | return -EINVAL; | |
9271 | ||
9272 | return 0; | |
9273 | } | |
9274 | ||
1e1b11b6 | 9275 | static int |
9276 | nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy, | |
9277 | struct cfg80211_match_set *match_sets, | |
9278 | struct nlattr *tb_band_rssi, | |
9279 | s32 rssi_thold) | |
9280 | { | |
9281 | struct nlattr *attr; | |
9282 | int i, tmp, ret = 0; | |
9283 | ||
9284 | if (!wiphy_ext_feature_isset(wiphy, | |
9285 | NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) { | |
9286 | if (tb_band_rssi) | |
9287 | ret = -EOPNOTSUPP; | |
9288 | else | |
9289 | for (i = 0; i < NUM_NL80211_BANDS; i++) | |
9290 | match_sets->per_band_rssi_thold[i] = | |
9291 | NL80211_SCAN_RSSI_THOLD_OFF; | |
9292 | return ret; | |
9293 | } | |
9294 | ||
9295 | for (i = 0; i < NUM_NL80211_BANDS; i++) | |
9296 | match_sets->per_band_rssi_thold[i] = rssi_thold; | |
9297 | ||
9298 | nla_for_each_nested(attr, tb_band_rssi, tmp) { | |
9299 | enum nl80211_band band = nla_type(attr); | |
9300 | ||
9301 | if (band < 0 || band >= NUM_NL80211_BANDS) | |
9302 | return -EINVAL; | |
9303 | ||
9304 | match_sets->per_band_rssi_thold[band] = nla_get_s32(attr); | |
9305 | } | |
9306 | ||
9307 | return 0; | |
9308 | } | |
9309 | ||
256da02d | 9310 | static struct cfg80211_sched_scan_request * |
ad2b26ab | 9311 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
aad1e812 | 9312 | struct nlattr **attrs, int max_match_sets) |
807f8a8c LC |
9313 | { |
9314 | struct cfg80211_sched_scan_request *request; | |
807f8a8c | 9315 | struct nlattr *attr; |
3b06d277 | 9316 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; |
57fbcce3 | 9317 | enum nl80211_band band; |
807f8a8c | 9318 | size_t ie_len; |
a1f1c21c | 9319 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 9320 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c | 9321 | |
256da02d | 9322 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c | 9323 | n_channels = validate_scan_freqs( |
256da02d | 9324 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
807f8a8c | 9325 | if (!n_channels) |
256da02d | 9326 | return ERR_PTR(-EINVAL); |
807f8a8c | 9327 | } else { |
bdfbec2d | 9328 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
9329 | } |
9330 | ||
256da02d LC |
9331 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
9332 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c LC |
9333 | tmp) |
9334 | n_ssids++; | |
9335 | ||
93b6aa69 | 9336 | if (n_ssids > wiphy->max_sched_scan_ssids) |
256da02d | 9337 | return ERR_PTR(-EINVAL); |
807f8a8c | 9338 | |
ea73cbce JB |
9339 | /* |
9340 | * First, count the number of 'real' matchsets. Due to an issue with | |
9341 | * the old implementation, matchsets containing only the RSSI attribute | |
9342 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
9343 | * RSSI for all matchsets, rather than their own matchset for reporting | |
9344 | * all APs with a strong RSSI. This is needed to be compatible with | |
9345 | * older userspace that treated a matchset with only the RSSI as the | |
9346 | * global RSSI for all other matchsets - if there are other matchsets. | |
9347 | */ | |
256da02d | 9348 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 9349 | nla_for_each_nested(attr, |
256da02d | 9350 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
ea73cbce JB |
9351 | tmp) { |
9352 | struct nlattr *rssi; | |
9353 | ||
8cb08174 JB |
9354 | err = nla_parse_nested_deprecated(tb, |
9355 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
9356 | attr, | |
9357 | nl80211_match_policy, | |
9358 | NULL); | |
ea73cbce | 9359 | if (err) |
256da02d | 9360 | return ERR_PTR(err); |
3007e352 AVS |
9361 | |
9362 | /* SSID and BSSID are mutually exclusive */ | |
9363 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && | |
9364 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) | |
9365 | return ERR_PTR(-EINVAL); | |
9366 | ||
ea73cbce | 9367 | /* add other standalone attributes here */ |
3007e352 AVS |
9368 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || |
9369 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { | |
ea73cbce JB |
9370 | n_match_sets++; |
9371 | continue; | |
9372 | } | |
9373 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
9374 | if (rssi) | |
9375 | default_match_rssi = nla_get_s32(rssi); | |
9376 | } | |
9377 | } | |
9378 | ||
9379 | /* However, if there's no other matchset, add the RSSI one */ | |
9380 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
9381 | n_match_sets = 1; | |
a1f1c21c | 9382 | |
aad1e812 | 9383 | if (n_match_sets > max_match_sets) |
256da02d | 9384 | return ERR_PTR(-EINVAL); |
a1f1c21c | 9385 | |
256da02d LC |
9386 | if (attrs[NL80211_ATTR_IE]) |
9387 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | |
807f8a8c LC |
9388 | else |
9389 | ie_len = 0; | |
9390 | ||
5a865bad | 9391 | if (ie_len > wiphy->max_sched_scan_ie_len) |
256da02d | 9392 | return ERR_PTR(-EINVAL); |
c10841ca | 9393 | |
3b06d277 AS |
9394 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
9395 | /* | |
9396 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since | |
9397 | * each scan plan already specifies its own interval | |
9398 | */ | |
9399 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
9400 | return ERR_PTR(-EINVAL); | |
9401 | ||
9402 | nla_for_each_nested(attr, | |
9403 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) | |
9404 | n_plans++; | |
9405 | } else { | |
9406 | /* | |
9407 | * The scan interval attribute is kept for backward | |
9408 | * compatibility. If no scan plans are specified and sched scan | |
9409 | * interval is specified, one scan plan will be set with this | |
9410 | * scan interval and infinite number of iterations. | |
9411 | */ | |
9412 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
9413 | return ERR_PTR(-EINVAL); | |
9414 | ||
9415 | n_plans = 1; | |
9416 | } | |
9417 | ||
9418 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) | |
9419 | return ERR_PTR(-EINVAL); | |
9420 | ||
bf95ecdb | 9421 | if (!wiphy_ext_feature_isset( |
9422 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && | |
9423 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || | |
9424 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) | |
9425 | return ERR_PTR(-EINVAL); | |
9426 | ||
807f8a8c | 9427 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 9428 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 9429 | + sizeof(*request->match_sets) * n_match_sets |
3b06d277 | 9430 | + sizeof(*request->scan_plans) * n_plans |
a2cd43c5 | 9431 | + sizeof(*request->channels) * n_channels |
807f8a8c | 9432 | + ie_len, GFP_KERNEL); |
256da02d LC |
9433 | if (!request) |
9434 | return ERR_PTR(-ENOMEM); | |
807f8a8c LC |
9435 | |
9436 | if (n_ssids) | |
9437 | request->ssids = (void *)&request->channels[n_channels]; | |
9438 | request->n_ssids = n_ssids; | |
9439 | if (ie_len) { | |
13874e4b | 9440 | if (n_ssids) |
807f8a8c LC |
9441 | request->ie = (void *)(request->ssids + n_ssids); |
9442 | else | |
9443 | request->ie = (void *)(request->channels + n_channels); | |
9444 | } | |
9445 | ||
a1f1c21c LC |
9446 | if (n_match_sets) { |
9447 | if (request->ie) | |
9448 | request->match_sets = (void *)(request->ie + ie_len); | |
13874e4b | 9449 | else if (n_ssids) |
a1f1c21c LC |
9450 | request->match_sets = |
9451 | (void *)(request->ssids + n_ssids); | |
9452 | else | |
9453 | request->match_sets = | |
9454 | (void *)(request->channels + n_channels); | |
9455 | } | |
9456 | request->n_match_sets = n_match_sets; | |
9457 | ||
3b06d277 AS |
9458 | if (n_match_sets) |
9459 | request->scan_plans = (void *)(request->match_sets + | |
9460 | n_match_sets); | |
9461 | else if (request->ie) | |
9462 | request->scan_plans = (void *)(request->ie + ie_len); | |
9463 | else if (n_ssids) | |
9464 | request->scan_plans = (void *)(request->ssids + n_ssids); | |
9465 | else | |
9466 | request->scan_plans = (void *)(request->channels + n_channels); | |
9467 | ||
9468 | request->n_scan_plans = n_plans; | |
9469 | ||
807f8a8c | 9470 | i = 0; |
256da02d | 9471 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c LC |
9472 | /* user specified, bail out if channel not found */ |
9473 | nla_for_each_nested(attr, | |
256da02d | 9474 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
807f8a8c LC |
9475 | tmp) { |
9476 | struct ieee80211_channel *chan; | |
9477 | ||
9478 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
9479 | ||
9480 | if (!chan) { | |
9481 | err = -EINVAL; | |
9482 | goto out_free; | |
9483 | } | |
9484 | ||
9485 | /* ignore disabled channels */ | |
9486 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
9487 | continue; | |
9488 | ||
9489 | request->channels[i] = chan; | |
9490 | i++; | |
9491 | } | |
9492 | } else { | |
9493 | /* all channels */ | |
57fbcce3 | 9494 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
807f8a8c | 9495 | int j; |
7a087e74 | 9496 | |
807f8a8c LC |
9497 | if (!wiphy->bands[band]) |
9498 | continue; | |
9499 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
9500 | struct ieee80211_channel *chan; | |
9501 | ||
9502 | chan = &wiphy->bands[band]->channels[j]; | |
9503 | ||
9504 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
9505 | continue; | |
9506 | ||
9507 | request->channels[i] = chan; | |
9508 | i++; | |
9509 | } | |
9510 | } | |
9511 | } | |
9512 | ||
9513 | if (!i) { | |
9514 | err = -EINVAL; | |
9515 | goto out_free; | |
9516 | } | |
9517 | ||
9518 | request->n_channels = i; | |
9519 | ||
9520 | i = 0; | |
13874e4b | 9521 | if (n_ssids) { |
256da02d | 9522 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
807f8a8c | 9523 | tmp) { |
57a27e1d | 9524 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
9525 | err = -EINVAL; |
9526 | goto out_free; | |
9527 | } | |
57a27e1d | 9528 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
9529 | memcpy(request->ssids[i].ssid, nla_data(attr), |
9530 | nla_len(attr)); | |
807f8a8c LC |
9531 | i++; |
9532 | } | |
9533 | } | |
9534 | ||
a1f1c21c | 9535 | i = 0; |
256da02d | 9536 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 9537 | nla_for_each_nested(attr, |
256da02d | 9538 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
a1f1c21c | 9539 | tmp) { |
3007e352 | 9540 | struct nlattr *ssid, *bssid, *rssi; |
a1f1c21c | 9541 | |
8cb08174 JB |
9542 | err = nla_parse_nested_deprecated(tb, |
9543 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
9544 | attr, | |
9545 | nl80211_match_policy, | |
9546 | NULL); | |
ae811e21 JB |
9547 | if (err) |
9548 | goto out_free; | |
4a4ab0d7 | 9549 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
3007e352 | 9550 | bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; |
d39f3b4f JB |
9551 | |
9552 | if (!ssid && !bssid) { | |
9553 | i++; | |
9554 | continue; | |
9555 | } | |
9556 | ||
9557 | if (WARN_ON(i >= n_match_sets)) { | |
9558 | /* this indicates a programming error, | |
9559 | * the loop above should have verified | |
9560 | * things properly | |
9561 | */ | |
9562 | err = -EINVAL; | |
9563 | goto out_free; | |
9564 | } | |
9565 | ||
9566 | if (ssid) { | |
d39f3b4f JB |
9567 | memcpy(request->match_sets[i].ssid.ssid, |
9568 | nla_data(ssid), nla_len(ssid)); | |
9569 | request->match_sets[i].ssid.ssid_len = | |
9570 | nla_len(ssid); | |
9571 | } | |
cb9abd48 | 9572 | if (bssid) |
d39f3b4f JB |
9573 | memcpy(request->match_sets[i].bssid, |
9574 | nla_data(bssid), ETH_ALEN); | |
3007e352 | 9575 | |
d39f3b4f JB |
9576 | /* special attribute - old implementation w/a */ |
9577 | request->match_sets[i].rssi_thold = default_match_rssi; | |
9578 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
9579 | if (rssi) | |
ea73cbce | 9580 | request->match_sets[i].rssi_thold = |
d39f3b4f | 9581 | nla_get_s32(rssi); |
1e1b11b6 | 9582 | |
9583 | /* Parse per band RSSI attribute */ | |
9584 | err = nl80211_parse_sched_scan_per_band_rssi(wiphy, | |
9585 | &request->match_sets[i], | |
9586 | tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI], | |
9587 | request->match_sets[i].rssi_thold); | |
9588 | if (err) | |
9589 | goto out_free; | |
9590 | ||
a1f1c21c LC |
9591 | i++; |
9592 | } | |
ea73cbce JB |
9593 | |
9594 | /* there was no other matchset, so the RSSI one is alone */ | |
f89f46cf | 9595 | if (i == 0 && n_match_sets) |
ea73cbce JB |
9596 | request->match_sets[0].rssi_thold = default_match_rssi; |
9597 | ||
9598 | request->min_rssi_thold = INT_MAX; | |
9599 | for (i = 0; i < n_match_sets; i++) | |
9600 | request->min_rssi_thold = | |
9601 | min(request->match_sets[i].rssi_thold, | |
9602 | request->min_rssi_thold); | |
9603 | } else { | |
9604 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
9605 | } |
9606 | ||
9900e484 JB |
9607 | if (ie_len) { |
9608 | request->ie_len = ie_len; | |
807f8a8c | 9609 | memcpy((void *)request->ie, |
256da02d | 9610 | nla_data(attrs[NL80211_ATTR_IE]), |
807f8a8c LC |
9611 | request->ie_len); |
9612 | } | |
9613 | ||
2d23d073 RZ |
9614 | err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); |
9615 | if (err) | |
9616 | goto out_free; | |
ed473771 | 9617 | |
9c748934 LC |
9618 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
9619 | request->delay = | |
9620 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); | |
9621 | ||
bf95ecdb | 9622 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { |
9623 | request->relative_rssi = nla_get_s8( | |
9624 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); | |
9625 | request->relative_rssi_set = true; | |
9626 | } | |
9627 | ||
9628 | if (request->relative_rssi_set && | |
9629 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { | |
9630 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; | |
9631 | ||
9632 | rssi_adjust = nla_data( | |
9633 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); | |
9634 | request->rssi_adjust.band = rssi_adjust->band; | |
9635 | request->rssi_adjust.delta = rssi_adjust->delta; | |
9636 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { | |
9637 | err = -EINVAL; | |
9638 | goto out_free; | |
9639 | } | |
9640 | } | |
9641 | ||
3b06d277 AS |
9642 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
9643 | if (err) | |
9644 | goto out_free; | |
9645 | ||
15d6030b | 9646 | request->scan_start = jiffies; |
807f8a8c | 9647 | |
256da02d | 9648 | return request; |
807f8a8c LC |
9649 | |
9650 | out_free: | |
9651 | kfree(request); | |
256da02d LC |
9652 | return ERR_PTR(err); |
9653 | } | |
9654 | ||
9655 | static int nl80211_start_sched_scan(struct sk_buff *skb, | |
9656 | struct genl_info *info) | |
9657 | { | |
9658 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9659 | struct net_device *dev = info->user_ptr[1]; | |
ad2b26ab | 9660 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
31a60ed1 | 9661 | struct cfg80211_sched_scan_request *sched_scan_req; |
ca986ad9 | 9662 | bool want_multi; |
256da02d LC |
9663 | int err; |
9664 | ||
ca986ad9 | 9665 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) |
256da02d LC |
9666 | return -EOPNOTSUPP; |
9667 | ||
ca986ad9 AVS |
9668 | want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; |
9669 | err = cfg80211_sched_scan_req_possible(rdev, want_multi); | |
9670 | if (err) | |
9671 | return err; | |
256da02d | 9672 | |
31a60ed1 | 9673 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
aad1e812 AVS |
9674 | info->attrs, |
9675 | rdev->wiphy.max_match_sets); | |
31a60ed1 JR |
9676 | |
9677 | err = PTR_ERR_OR_ZERO(sched_scan_req); | |
256da02d LC |
9678 | if (err) |
9679 | goto out_err; | |
9680 | ||
ca986ad9 AVS |
9681 | /* leave request id zero for legacy request |
9682 | * or if driver does not support multi-scheduled scan | |
9683 | */ | |
2fd351a8 DK |
9684 | if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) |
9685 | sched_scan_req->reqid = cfg80211_assign_cookie(rdev); | |
ca986ad9 | 9686 | |
31a60ed1 | 9687 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
256da02d LC |
9688 | if (err) |
9689 | goto out_free; | |
9690 | ||
31a60ed1 JR |
9691 | sched_scan_req->dev = dev; |
9692 | sched_scan_req->wiphy = &rdev->wiphy; | |
9693 | ||
93a1e86c JR |
9694 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
9695 | sched_scan_req->owner_nlportid = info->snd_portid; | |
9696 | ||
ca986ad9 | 9697 | cfg80211_add_sched_scan_req(rdev, sched_scan_req); |
256da02d | 9698 | |
96b08fd6 | 9699 | nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); |
256da02d LC |
9700 | return 0; |
9701 | ||
9702 | out_free: | |
31a60ed1 | 9703 | kfree(sched_scan_req); |
256da02d | 9704 | out_err: |
807f8a8c LC |
9705 | return err; |
9706 | } | |
9707 | ||
9708 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
9709 | struct genl_info *info) | |
9710 | { | |
ca986ad9 | 9711 | struct cfg80211_sched_scan_request *req; |
807f8a8c | 9712 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ca986ad9 | 9713 | u64 cookie; |
807f8a8c | 9714 | |
ca986ad9 | 9715 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) |
807f8a8c LC |
9716 | return -EOPNOTSUPP; |
9717 | ||
ca986ad9 AVS |
9718 | if (info->attrs[NL80211_ATTR_COOKIE]) { |
9719 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
9720 | return __cfg80211_stop_sched_scan(rdev, cookie, false); | |
9721 | } | |
9722 | ||
9723 | req = list_first_or_null_rcu(&rdev->sched_scan_req_list, | |
9724 | struct cfg80211_sched_scan_request, | |
9725 | list); | |
9726 | if (!req || req->reqid || | |
9727 | (req->owner_nlportid && | |
9728 | req->owner_nlportid != info->snd_portid)) | |
9729 | return -ENOENT; | |
9730 | ||
9731 | return cfg80211_stop_sched_scan_req(rdev, req, false); | |
807f8a8c LC |
9732 | } |
9733 | ||
04f39047 SW |
9734 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
9735 | struct genl_info *info) | |
9736 | { | |
9737 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9738 | struct net_device *dev = info->user_ptr[1]; | |
9739 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13cf6dec | 9740 | struct wiphy *wiphy = wdev->wiphy; |
04f39047 | 9741 | struct cfg80211_chan_def chandef; |
55f7435c | 9742 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 9743 | unsigned int cac_time_ms; |
84158164 LB |
9744 | int err = -EINVAL; |
9745 | ||
9746 | flush_delayed_work(&rdev->dfs_update_channels_wk); | |
9747 | ||
9748 | wiphy_lock(wiphy); | |
04f39047 | 9749 | |
13cf6dec | 9750 | dfs_region = reg_get_dfs_region(wiphy); |
55f7435c | 9751 | if (dfs_region == NL80211_DFS_UNSET) |
84158164 | 9752 | goto unlock; |
55f7435c | 9753 | |
04f39047 SW |
9754 | err = nl80211_parse_chandef(rdev, info, &chandef); |
9755 | if (err) | |
84158164 | 9756 | goto unlock; |
04f39047 | 9757 | |
13cf6dec | 9758 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
04f39047 | 9759 | if (err < 0) |
84158164 | 9760 | goto unlock; |
04f39047 | 9761 | |
84158164 LB |
9762 | if (err == 0) { |
9763 | err = -EINVAL; | |
9764 | goto unlock; | |
9765 | } | |
04f39047 | 9766 | |
84158164 LB |
9767 | if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) { |
9768 | err = -EINVAL; | |
9769 | goto unlock; | |
9770 | } | |
04f39047 | 9771 | |
a95bfb87 LB |
9772 | if (nla_get_flag(info->attrs[NL80211_ATTR_RADAR_BACKGROUND])) { |
9773 | err = cfg80211_start_background_radar_detection(rdev, wdev, | |
9774 | &chandef); | |
84158164 LB |
9775 | goto unlock; |
9776 | } | |
bc2dfc02 | 9777 | |
84158164 LB |
9778 | if (netif_carrier_ok(dev)) { |
9779 | err = -EBUSY; | |
9780 | goto unlock; | |
9781 | } | |
bc2dfc02 | 9782 | |
84158164 LB |
9783 | if (wdev->cac_started) { |
9784 | err = -EBUSY; | |
9785 | goto unlock; | |
9786 | } | |
bc2dfc02 | 9787 | |
13cf6dec | 9788 | /* CAC start is offloaded to HW and can't be started manually */ |
84158164 LB |
9789 | if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) { |
9790 | err = -EOPNOTSUPP; | |
9791 | goto unlock; | |
9792 | } | |
13cf6dec | 9793 | |
84158164 LB |
9794 | if (!rdev->ops->start_radar_detection) { |
9795 | err = -EOPNOTSUPP; | |
9796 | goto unlock; | |
9797 | } | |
04f39047 | 9798 | |
31559f35 JD |
9799 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
9800 | if (WARN_ON(!cac_time_ms)) | |
9801 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
9802 | ||
a1056b1b | 9803 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
04f39047 | 9804 | if (!err) { |
7b0a0e3c | 9805 | wdev->links[0].ap.chandef = chandef; |
04f39047 SW |
9806 | wdev->cac_started = true; |
9807 | wdev->cac_start_time = jiffies; | |
31559f35 | 9808 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 9809 | } |
84158164 LB |
9810 | unlock: |
9811 | wiphy_unlock(wiphy); | |
9812 | ||
04f39047 SW |
9813 | return err; |
9814 | } | |
9815 | ||
30c63115 S |
9816 | static int nl80211_notify_radar_detection(struct sk_buff *skb, |
9817 | struct genl_info *info) | |
9818 | { | |
9819 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9820 | struct net_device *dev = info->user_ptr[1]; | |
9821 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9822 | struct wiphy *wiphy = wdev->wiphy; | |
9823 | struct cfg80211_chan_def chandef; | |
9824 | enum nl80211_dfs_regions dfs_region; | |
9825 | int err; | |
9826 | ||
9827 | dfs_region = reg_get_dfs_region(wiphy); | |
9828 | if (dfs_region == NL80211_DFS_UNSET) { | |
9829 | GENL_SET_ERR_MSG(info, | |
9830 | "DFS Region is not set. Unexpected Radar indication"); | |
9831 | return -EINVAL; | |
9832 | } | |
9833 | ||
9834 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
9835 | if (err) { | |
9836 | GENL_SET_ERR_MSG(info, "Unable to extract chandef info"); | |
9837 | return err; | |
9838 | } | |
9839 | ||
9840 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); | |
9841 | if (err < 0) { | |
9842 | GENL_SET_ERR_MSG(info, "chandef is invalid"); | |
9843 | return err; | |
9844 | } | |
9845 | ||
9846 | if (err == 0) { | |
9847 | GENL_SET_ERR_MSG(info, | |
9848 | "Unexpected Radar indication for chandef/iftype"); | |
9849 | return -EINVAL; | |
9850 | } | |
9851 | ||
9852 | /* Do not process this notification if radar is already detected | |
9853 | * by kernel on this channel, and return success. | |
9854 | */ | |
9855 | if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE) | |
9856 | return 0; | |
9857 | ||
9858 | cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE); | |
9859 | ||
9860 | cfg80211_sched_dfs_chan_update(rdev); | |
9861 | ||
a680fe46 | 9862 | rdev->radar_chandef = chandef; |
30c63115 S |
9863 | |
9864 | /* Propagate this notification to other radios as well */ | |
9865 | queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk); | |
9866 | ||
9867 | return 0; | |
9868 | } | |
9869 | ||
16ef1fe2 SW |
9870 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
9871 | { | |
9872 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7b0a0e3c | 9873 | unsigned int link_id = nl80211_link_id(info->attrs); |
16ef1fe2 SW |
9874 | struct net_device *dev = info->user_ptr[1]; |
9875 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9876 | struct cfg80211_csa_settings params; | |
a05829a7 | 9877 | struct nlattr **csa_attrs = NULL; |
16ef1fe2 | 9878 | int err; |
ee4bc9e7 | 9879 | bool need_new_beacon = false; |
8d9de16f | 9880 | bool need_handle_dfs_flag = true; |
9a774c78 | 9881 | int len, i; |
252e07ca | 9882 | u32 cs_count; |
16ef1fe2 SW |
9883 | |
9884 | if (!rdev->ops->channel_switch || | |
9885 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
9886 | return -EOPNOTSUPP; | |
9887 | ||
ee4bc9e7 SW |
9888 | switch (dev->ieee80211_ptr->iftype) { |
9889 | case NL80211_IFTYPE_AP: | |
9890 | case NL80211_IFTYPE_P2P_GO: | |
9891 | need_new_beacon = true; | |
8d9de16f BB |
9892 | /* For all modes except AP the handle_dfs flag needs to be |
9893 | * supplied to tell the kernel that userspace will handle radar | |
9894 | * events when they happen. Otherwise a switch to a channel | |
9895 | * requiring DFS will be rejected. | |
9896 | */ | |
9897 | need_handle_dfs_flag = false; | |
ee4bc9e7 SW |
9898 | |
9899 | /* useless if AP is not running */ | |
7b0a0e3c | 9900 | if (!wdev->links[link_id].ap.beacon_interval) |
1ff79dfa | 9901 | return -ENOTCONN; |
ee4bc9e7 SW |
9902 | break; |
9903 | case NL80211_IFTYPE_ADHOC: | |
7b0a0e3c | 9904 | if (!wdev->u.ibss.ssid_len) |
1ff79dfa JB |
9905 | return -ENOTCONN; |
9906 | break; | |
c6da674a | 9907 | case NL80211_IFTYPE_MESH_POINT: |
7b0a0e3c | 9908 | if (!wdev->u.mesh.id_len) |
1ff79dfa | 9909 | return -ENOTCONN; |
ee4bc9e7 SW |
9910 | break; |
9911 | default: | |
16ef1fe2 | 9912 | return -EOPNOTSUPP; |
ee4bc9e7 | 9913 | } |
16ef1fe2 SW |
9914 | |
9915 | memset(¶ms, 0, sizeof(params)); | |
c177db2d | 9916 | params.beacon_csa.ftm_responder = -1; |
16ef1fe2 SW |
9917 | |
9918 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
9919 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
9920 | return -EINVAL; | |
9921 | ||
9922 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 9923 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
9924 | return -EINVAL; |
9925 | ||
252e07ca LC |
9926 | /* Even though the attribute is u32, the specification says |
9927 | * u8, so let's make sure we don't overflow. | |
9928 | */ | |
9929 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
9930 | if (cs_count > 255) | |
9931 | return -EINVAL; | |
9932 | ||
9933 | params.count = cs_count; | |
16ef1fe2 | 9934 | |
ee4bc9e7 SW |
9935 | if (!need_new_beacon) |
9936 | goto skip_beacons; | |
9937 | ||
81e54d08 | 9938 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after); |
16ef1fe2 | 9939 | if (err) |
dc1e3cb8 | 9940 | goto free; |
16ef1fe2 | 9941 | |
a05829a7 JB |
9942 | csa_attrs = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*csa_attrs), |
9943 | GFP_KERNEL); | |
dc1e3cb8 JC |
9944 | if (!csa_attrs) { |
9945 | err = -ENOMEM; | |
9946 | goto free; | |
9947 | } | |
a05829a7 | 9948 | |
8cb08174 JB |
9949 | err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX, |
9950 | info->attrs[NL80211_ATTR_CSA_IES], | |
9951 | nl80211_policy, info->extack); | |
16ef1fe2 | 9952 | if (err) |
a05829a7 | 9953 | goto free; |
16ef1fe2 | 9954 | |
81e54d08 | 9955 | err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa); |
16ef1fe2 | 9956 | if (err) |
a05829a7 | 9957 | goto free; |
16ef1fe2 | 9958 | |
a05829a7 JB |
9959 | if (!csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]) { |
9960 | err = -EINVAL; | |
9961 | goto free; | |
9962 | } | |
16ef1fe2 | 9963 | |
00c207ed | 9964 | len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); |
a05829a7 JB |
9965 | if (!len || (len % sizeof(u16))) { |
9966 | err = -EINVAL; | |
9967 | goto free; | |
9968 | } | |
16ef1fe2 | 9969 | |
9a774c78 AO |
9970 | params.n_counter_offsets_beacon = len / sizeof(u16); |
9971 | if (rdev->wiphy.max_num_csa_counters && | |
9972 | (params.n_counter_offsets_beacon > | |
a05829a7 JB |
9973 | rdev->wiphy.max_num_csa_counters)) { |
9974 | err = -EINVAL; | |
9975 | goto free; | |
9976 | } | |
16ef1fe2 | 9977 | |
9a774c78 | 9978 | params.counter_offsets_beacon = |
00c207ed | 9979 | nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); |
9a774c78 AO |
9980 | |
9981 | /* sanity checks - counters should fit and be the same */ | |
9982 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
9983 | u16 offset = params.counter_offsets_beacon[i]; | |
9984 | ||
a05829a7 JB |
9985 | if (offset >= params.beacon_csa.tail_len) { |
9986 | err = -EINVAL; | |
9987 | goto free; | |
9988 | } | |
9a774c78 | 9989 | |
a05829a7 JB |
9990 | if (params.beacon_csa.tail[offset] != params.count) { |
9991 | err = -EINVAL; | |
9992 | goto free; | |
9993 | } | |
9a774c78 AO |
9994 | } |
9995 | ||
00c207ed JC |
9996 | if (csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]) { |
9997 | len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); | |
a05829a7 JB |
9998 | if (!len || (len % sizeof(u16))) { |
9999 | err = -EINVAL; | |
10000 | goto free; | |
10001 | } | |
16ef1fe2 | 10002 | |
9a774c78 AO |
10003 | params.n_counter_offsets_presp = len / sizeof(u16); |
10004 | if (rdev->wiphy.max_num_csa_counters && | |
ad5987b4 | 10005 | (params.n_counter_offsets_presp > |
a05829a7 JB |
10006 | rdev->wiphy.max_num_csa_counters)) { |
10007 | err = -EINVAL; | |
10008 | goto free; | |
10009 | } | |
9a774c78 AO |
10010 | |
10011 | params.counter_offsets_presp = | |
00c207ed | 10012 | nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); |
9a774c78 AO |
10013 | |
10014 | /* sanity checks - counters should fit and be the same */ | |
10015 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
10016 | u16 offset = params.counter_offsets_presp[i]; | |
10017 | ||
a05829a7 JB |
10018 | if (offset >= params.beacon_csa.probe_resp_len) { |
10019 | err = -EINVAL; | |
10020 | goto free; | |
10021 | } | |
9a774c78 AO |
10022 | |
10023 | if (params.beacon_csa.probe_resp[offset] != | |
a05829a7 JB |
10024 | params.count) { |
10025 | err = -EINVAL; | |
10026 | goto free; | |
10027 | } | |
9a774c78 | 10028 | } |
16ef1fe2 SW |
10029 | } |
10030 | ||
ee4bc9e7 | 10031 | skip_beacons: |
16ef1fe2 SW |
10032 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
10033 | if (err) | |
a05829a7 | 10034 | goto free; |
16ef1fe2 | 10035 | |
923b352f | 10036 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
a05829a7 JB |
10037 | wdev->iftype)) { |
10038 | err = -EINVAL; | |
10039 | goto free; | |
10040 | } | |
16ef1fe2 | 10041 | |
2beb6dab LC |
10042 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
10043 | ¶ms.chandef, | |
10044 | wdev->iftype); | |
10045 | if (err < 0) | |
a05829a7 | 10046 | goto free; |
2beb6dab | 10047 | |
8d9de16f | 10048 | if (err > 0) { |
2beb6dab | 10049 | params.radar_required = true; |
8d9de16f BB |
10050 | if (need_handle_dfs_flag && |
10051 | !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { | |
a05829a7 JB |
10052 | err = -EINVAL; |
10053 | goto free; | |
8d9de16f BB |
10054 | } |
10055 | } | |
16ef1fe2 | 10056 | |
16ef1fe2 SW |
10057 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
10058 | params.block_tx = true; | |
10059 | ||
c56589ed SW |
10060 | wdev_lock(wdev); |
10061 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
10062 | wdev_unlock(wdev); | |
10063 | ||
a05829a7 | 10064 | free: |
dc1e3cb8 JC |
10065 | kfree(params.beacon_after.mbssid_ies); |
10066 | kfree(params.beacon_csa.mbssid_ies); | |
a05829a7 | 10067 | kfree(csa_attrs); |
c56589ed | 10068 | return err; |
16ef1fe2 SW |
10069 | } |
10070 | ||
9720bb3a JB |
10071 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
10072 | u32 seq, int flags, | |
2a519311 | 10073 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
10074 | struct wireless_dev *wdev, |
10075 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 10076 | { |
48ab905d | 10077 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 10078 | const struct cfg80211_bss_ies *ies; |
7b0a0e3c | 10079 | unsigned int link_id; |
2a519311 JB |
10080 | void *hdr; |
10081 | struct nlattr *bss; | |
48ab905d JB |
10082 | |
10083 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 10084 | |
15e47304 | 10085 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
10086 | NL80211_CMD_NEW_SCAN_RESULTS); |
10087 | if (!hdr) | |
10088 | return -1; | |
10089 | ||
0a833c29 | 10090 | genl_dump_check_consistent(cb, hdr); |
9720bb3a | 10091 | |
97990a06 JB |
10092 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
10093 | goto nla_put_failure; | |
10094 | if (wdev->netdev && | |
9360ffd1 DM |
10095 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
10096 | goto nla_put_failure; | |
2dad624e ND |
10097 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
10098 | NL80211_ATTR_PAD)) | |
97990a06 | 10099 | goto nla_put_failure; |
2a519311 | 10100 | |
ae0be8de | 10101 | bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS); |
2a519311 JB |
10102 | if (!bss) |
10103 | goto nla_put_failure; | |
9360ffd1 | 10104 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 10105 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 10106 | goto nla_put_failure; |
9caf0364 JB |
10107 | |
10108 | rcu_read_lock(); | |
0e227084 JB |
10109 | /* indicate whether we have probe response data or not */ |
10110 | if (rcu_access_pointer(res->proberesp_ies) && | |
10111 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
10112 | goto fail_unlock_rcu; | |
10113 | ||
10114 | /* this pointer prefers to be pointed to probe response data | |
10115 | * but is always valid | |
10116 | */ | |
9caf0364 | 10117 | ies = rcu_dereference(res->ies); |
8cef2c9d | 10118 | if (ies) { |
2dad624e ND |
10119 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
10120 | NL80211_BSS_PAD)) | |
8cef2c9d | 10121 | goto fail_unlock_rcu; |
8cef2c9d JB |
10122 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
10123 | ies->len, ies->data)) | |
10124 | goto fail_unlock_rcu; | |
9caf0364 | 10125 | } |
0e227084 JB |
10126 | |
10127 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 10128 | ies = rcu_dereference(res->beacon_ies); |
0e227084 | 10129 | if (ies && ies->from_beacon) { |
2dad624e ND |
10130 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
10131 | NL80211_BSS_PAD)) | |
8cef2c9d JB |
10132 | goto fail_unlock_rcu; |
10133 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
10134 | ies->len, ies->data)) | |
10135 | goto fail_unlock_rcu; | |
9caf0364 JB |
10136 | } |
10137 | rcu_read_unlock(); | |
10138 | ||
9360ffd1 DM |
10139 | if (res->beacon_interval && |
10140 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
10141 | goto nla_put_failure; | |
10142 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
10143 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
942ba88b TP |
10144 | nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET, |
10145 | res->channel->freq_offset) || | |
dcd6eac1 | 10146 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
10147 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
10148 | jiffies_to_msecs(jiffies - intbss->ts))) | |
10149 | goto nla_put_failure; | |
2a519311 | 10150 | |
1d76250b AS |
10151 | if (intbss->parent_tsf && |
10152 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, | |
10153 | intbss->parent_tsf, NL80211_BSS_PAD) || | |
10154 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, | |
10155 | intbss->parent_bssid))) | |
10156 | goto nla_put_failure; | |
10157 | ||
6e19bc4b | 10158 | if (intbss->ts_boottime && |
2dad624e ND |
10159 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
10160 | intbss->ts_boottime, NL80211_BSS_PAD)) | |
6e19bc4b DS |
10161 | goto nla_put_failure; |
10162 | ||
983dafaa SD |
10163 | if (!nl80211_put_signal(msg, intbss->pub.chains, |
10164 | intbss->pub.chain_signal, | |
10165 | NL80211_BSS_CHAIN_SIGNAL)) | |
10166 | goto nla_put_failure; | |
10167 | ||
77965c97 | 10168 | switch (rdev->wiphy.signal_type) { |
2a519311 | 10169 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
10170 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
10171 | goto nla_put_failure; | |
2a519311 JB |
10172 | break; |
10173 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
10174 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
10175 | goto nla_put_failure; | |
2a519311 JB |
10176 | break; |
10177 | default: | |
10178 | break; | |
10179 | } | |
10180 | ||
48ab905d | 10181 | switch (wdev->iftype) { |
074ac8df | 10182 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 10183 | case NL80211_IFTYPE_STATION: |
7b0a0e3c JB |
10184 | for_each_valid_link(wdev, link_id) { |
10185 | if (intbss == wdev->links[link_id].client.current_bss && | |
dd374f84 JB |
10186 | (nla_put_u32(msg, NL80211_BSS_STATUS, |
10187 | NL80211_BSS_STATUS_ASSOCIATED) || | |
10188 | (wdev->valid_links && | |
6522047c JB |
10189 | (nla_put_u8(msg, NL80211_BSS_MLO_LINK_ID, |
10190 | link_id) || | |
10191 | nla_put(msg, NL80211_BSS_MLD_ADDR, ETH_ALEN, | |
10192 | wdev->u.client.connected_addr))))) | |
7b0a0e3c JB |
10193 | goto nla_put_failure; |
10194 | } | |
48ab905d JB |
10195 | break; |
10196 | case NL80211_IFTYPE_ADHOC: | |
7b0a0e3c | 10197 | if (intbss == wdev->u.ibss.current_bss && |
9360ffd1 DM |
10198 | nla_put_u32(msg, NL80211_BSS_STATUS, |
10199 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
10200 | goto nla_put_failure; | |
48ab905d JB |
10201 | break; |
10202 | default: | |
10203 | break; | |
10204 | } | |
10205 | ||
2a519311 JB |
10206 | nla_nest_end(msg, bss); |
10207 | ||
053c095a JB |
10208 | genlmsg_end(msg, hdr); |
10209 | return 0; | |
2a519311 | 10210 | |
8cef2c9d JB |
10211 | fail_unlock_rcu: |
10212 | rcu_read_unlock(); | |
2a519311 JB |
10213 | nla_put_failure: |
10214 | genlmsg_cancel(msg, hdr); | |
10215 | return -EMSGSIZE; | |
10216 | } | |
10217 | ||
97990a06 | 10218 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 10219 | { |
48ab905d | 10220 | struct cfg80211_registered_device *rdev; |
2a519311 | 10221 | struct cfg80211_internal_bss *scan; |
48ab905d | 10222 | struct wireless_dev *wdev; |
97990a06 | 10223 | int start = cb->args[2], idx = 0; |
2a519311 JB |
10224 | int err; |
10225 | ||
ce6b6974 | 10226 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL); |
a05829a7 | 10227 | if (err) |
67748893 | 10228 | return err; |
a05829a7 JB |
10229 | /* nl80211_prepare_wdev_dump acquired it in the successful case */ |
10230 | __acquire(&rdev->wiphy.mtx); | |
2a519311 | 10231 | |
48ab905d JB |
10232 | wdev_lock(wdev); |
10233 | spin_lock_bh(&rdev->bss_lock); | |
d1e23c94 DK |
10234 | |
10235 | /* | |
10236 | * dump_scan will be called multiple times to break up the scan results | |
10237 | * into multiple messages. It is unlikely that any more bss-es will be | |
10238 | * expired after the first call, so only call only call this on the | |
10239 | * first dump_scan invocation. | |
10240 | */ | |
10241 | if (start == 0) | |
10242 | cfg80211_bss_expire(rdev); | |
48ab905d | 10243 | |
9720bb3a JB |
10244 | cb->seq = rdev->bss_generation; |
10245 | ||
48ab905d | 10246 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
10247 | if (++idx <= start) |
10248 | continue; | |
9720bb3a | 10249 | if (nl80211_send_bss(skb, cb, |
2a519311 | 10250 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 10251 | rdev, wdev, scan) < 0) { |
2a519311 | 10252 | idx--; |
67748893 | 10253 | break; |
2a519311 JB |
10254 | } |
10255 | } | |
10256 | ||
48ab905d JB |
10257 | spin_unlock_bh(&rdev->bss_lock); |
10258 | wdev_unlock(wdev); | |
2a519311 | 10259 | |
97990a06 | 10260 | cb->args[2] = idx; |
a05829a7 | 10261 | wiphy_unlock(&rdev->wiphy); |
2a519311 | 10262 | |
67748893 | 10263 | return skb->len; |
2a519311 JB |
10264 | } |
10265 | ||
15e47304 | 10266 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
11f78ac3 JB |
10267 | int flags, struct net_device *dev, |
10268 | bool allow_radio_stats, | |
10269 | struct survey_info *survey) | |
61fa713c HS |
10270 | { |
10271 | void *hdr; | |
10272 | struct nlattr *infoattr; | |
10273 | ||
11f78ac3 JB |
10274 | /* skip radio stats if userspace didn't request them */ |
10275 | if (!survey->channel && !allow_radio_stats) | |
10276 | return 0; | |
10277 | ||
15e47304 | 10278 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
10279 | NL80211_CMD_NEW_SURVEY_RESULTS); |
10280 | if (!hdr) | |
10281 | return -ENOMEM; | |
10282 | ||
9360ffd1 DM |
10283 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
10284 | goto nla_put_failure; | |
61fa713c | 10285 | |
ae0be8de | 10286 | infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO); |
61fa713c HS |
10287 | if (!infoattr) |
10288 | goto nla_put_failure; | |
10289 | ||
11f78ac3 JB |
10290 | if (survey->channel && |
10291 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
9360ffd1 DM |
10292 | survey->channel->center_freq)) |
10293 | goto nla_put_failure; | |
58ef7c1b TP |
10294 | |
10295 | if (survey->channel && survey->channel->freq_offset && | |
10296 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY_OFFSET, | |
10297 | survey->channel->freq_offset)) | |
10298 | goto nla_put_failure; | |
9360ffd1 DM |
10299 | |
10300 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
10301 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
10302 | goto nla_put_failure; | |
10303 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
10304 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
10305 | goto nla_put_failure; | |
4ed20beb | 10306 | if ((survey->filled & SURVEY_INFO_TIME) && |
2dad624e ND |
10307 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
10308 | survey->time, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 10309 | goto nla_put_failure; |
4ed20beb | 10310 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
2dad624e ND |
10311 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
10312 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 10313 | goto nla_put_failure; |
4ed20beb | 10314 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
2dad624e ND |
10315 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
10316 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 10317 | goto nla_put_failure; |
4ed20beb | 10318 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
2dad624e ND |
10319 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
10320 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 10321 | goto nla_put_failure; |
4ed20beb | 10322 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
2dad624e ND |
10323 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
10324 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 10325 | goto nla_put_failure; |
052536ab | 10326 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
2dad624e ND |
10327 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
10328 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) | |
052536ab | 10329 | goto nla_put_failure; |
c8cd6e7f FF |
10330 | if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) && |
10331 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX, | |
10332 | survey->time_bss_rx, NL80211_SURVEY_INFO_PAD)) | |
10333 | goto nla_put_failure; | |
61fa713c HS |
10334 | |
10335 | nla_nest_end(msg, infoattr); | |
10336 | ||
053c095a JB |
10337 | genlmsg_end(msg, hdr); |
10338 | return 0; | |
61fa713c HS |
10339 | |
10340 | nla_put_failure: | |
10341 | genlmsg_cancel(msg, hdr); | |
10342 | return -EMSGSIZE; | |
10343 | } | |
10344 | ||
11f78ac3 | 10345 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
61fa713c | 10346 | { |
50508d94 | 10347 | struct nlattr **attrbuf; |
61fa713c | 10348 | struct survey_info survey; |
1b8ec87a | 10349 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
10350 | struct wireless_dev *wdev; |
10351 | int survey_idx = cb->args[2]; | |
61fa713c | 10352 | int res; |
11f78ac3 | 10353 | bool radio_stats; |
61fa713c | 10354 | |
50508d94 JB |
10355 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); |
10356 | if (!attrbuf) | |
10357 | return -ENOMEM; | |
10358 | ||
ce6b6974 | 10359 | res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, attrbuf); |
a05829a7 JB |
10360 | if (res) { |
10361 | kfree(attrbuf); | |
10362 | return res; | |
10363 | } | |
10364 | /* nl80211_prepare_wdev_dump acquired it in the successful case */ | |
10365 | __acquire(&rdev->wiphy.mtx); | |
61fa713c | 10366 | |
11f78ac3 | 10367 | /* prepare_wdev_dump parsed the attributes */ |
c90c39da | 10368 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
11f78ac3 | 10369 | |
97990a06 JB |
10370 | if (!wdev->netdev) { |
10371 | res = -EINVAL; | |
10372 | goto out_err; | |
10373 | } | |
10374 | ||
1b8ec87a | 10375 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
10376 | res = -EOPNOTSUPP; |
10377 | goto out_err; | |
10378 | } | |
10379 | ||
10380 | while (1) { | |
284b38b6 | 10381 | wdev_lock(wdev); |
1b8ec87a | 10382 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
284b38b6 | 10383 | wdev_unlock(wdev); |
61fa713c HS |
10384 | if (res == -ENOENT) |
10385 | break; | |
10386 | if (res) | |
10387 | goto out_err; | |
10388 | ||
11f78ac3 JB |
10389 | /* don't send disabled channels, but do send non-channel data */ |
10390 | if (survey.channel && | |
10391 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { | |
180cdc79 LR |
10392 | survey_idx++; |
10393 | continue; | |
10394 | } | |
10395 | ||
61fa713c | 10396 | if (nl80211_send_survey(skb, |
15e47304 | 10397 | NETLINK_CB(cb->skb).portid, |
61fa713c | 10398 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
11f78ac3 | 10399 | wdev->netdev, radio_stats, &survey) < 0) |
61fa713c HS |
10400 | goto out; |
10401 | survey_idx++; | |
10402 | } | |
10403 | ||
10404 | out: | |
97990a06 | 10405 | cb->args[2] = survey_idx; |
61fa713c HS |
10406 | res = skb->len; |
10407 | out_err: | |
50508d94 | 10408 | kfree(attrbuf); |
a05829a7 | 10409 | wiphy_unlock(&rdev->wiphy); |
61fa713c HS |
10410 | return res; |
10411 | } | |
10412 | ||
b23aa676 SO |
10413 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
10414 | { | |
10415 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
cc3e14c2 CHH |
10416 | NL80211_WPA_VERSION_2 | |
10417 | NL80211_WPA_VERSION_3)); | |
b23aa676 SO |
10418 | } |
10419 | ||
636a5d36 JM |
10420 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
10421 | { | |
4c476991 JB |
10422 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
10423 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 10424 | struct ieee80211_channel *chan; |
325839da JB |
10425 | const u8 *bssid, *ssid; |
10426 | int err, ssid_len; | |
19957bb3 | 10427 | enum nl80211_auth_type auth_type; |
fffd0934 | 10428 | struct key_parse key; |
d5cdfacb | 10429 | bool local_state_change; |
325839da | 10430 | struct cfg80211_auth_request req = {}; |
942ba88b | 10431 | u32 freq; |
636a5d36 | 10432 | |
f4a11bb0 JB |
10433 | if (!info->attrs[NL80211_ATTR_MAC]) |
10434 | return -EINVAL; | |
10435 | ||
1778092e JM |
10436 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
10437 | return -EINVAL; | |
10438 | ||
19957bb3 JB |
10439 | if (!info->attrs[NL80211_ATTR_SSID]) |
10440 | return -EINVAL; | |
10441 | ||
10442 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
10443 | return -EINVAL; | |
10444 | ||
fffd0934 JB |
10445 | err = nl80211_parse_key(info, &key); |
10446 | if (err) | |
10447 | return err; | |
10448 | ||
10449 | if (key.idx >= 0) { | |
e31b8213 JB |
10450 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
10451 | return -EINVAL; | |
fffd0934 JB |
10452 | if (!key.p.key || !key.p.key_len) |
10453 | return -EINVAL; | |
10454 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
10455 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
10456 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
10457 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
10458 | return -EINVAL; | |
b6b5555b | 10459 | if (key.idx > 3) |
fffd0934 JB |
10460 | return -EINVAL; |
10461 | } else { | |
10462 | key.p.key_len = 0; | |
10463 | key.p.key = NULL; | |
10464 | } | |
10465 | ||
afea0b7a JB |
10466 | if (key.idx >= 0) { |
10467 | int i; | |
10468 | bool ok = false; | |
7a087e74 | 10469 | |
afea0b7a JB |
10470 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
10471 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
10472 | ok = true; | |
10473 | break; | |
10474 | } | |
10475 | } | |
4c476991 JB |
10476 | if (!ok) |
10477 | return -EINVAL; | |
afea0b7a JB |
10478 | } |
10479 | ||
4c476991 JB |
10480 | if (!rdev->ops->auth) |
10481 | return -EOPNOTSUPP; | |
636a5d36 | 10482 | |
074ac8df | 10483 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
10484 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
10485 | return -EOPNOTSUPP; | |
eec60b03 | 10486 | |
19957bb3 | 10487 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
942ba88b TP |
10488 | freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
10489 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) | |
10490 | freq += | |
10491 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); | |
10492 | ||
10493 | chan = nl80211_get_valid_chan(&rdev->wiphy, freq); | |
664834de | 10494 | if (!chan) |
4c476991 | 10495 | return -EINVAL; |
636a5d36 | 10496 | |
19957bb3 JB |
10497 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
10498 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
10499 | |
10500 | if (info->attrs[NL80211_ATTR_IE]) { | |
325839da JB |
10501 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
10502 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
10503 | } |
10504 | ||
19957bb3 | 10505 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 10506 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 10507 | return -EINVAL; |
636a5d36 | 10508 | |
63181060 JM |
10509 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
10510 | auth_type == NL80211_AUTHTYPE_FILS_SK || | |
10511 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || | |
10512 | auth_type == NL80211_AUTHTYPE_FILS_PK) && | |
11b6b5a4 | 10513 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
e39e5b5e JM |
10514 | return -EINVAL; |
10515 | ||
11b6b5a4 | 10516 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
63181060 JM |
10517 | if (auth_type != NL80211_AUTHTYPE_SAE && |
10518 | auth_type != NL80211_AUTHTYPE_FILS_SK && | |
10519 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && | |
10520 | auth_type != NL80211_AUTHTYPE_FILS_PK) | |
e39e5b5e | 10521 | return -EINVAL; |
325839da JB |
10522 | req.auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
10523 | req.auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); | |
e39e5b5e JM |
10524 | } |
10525 | ||
d5cdfacb JM |
10526 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
10527 | ||
95de817b JB |
10528 | /* |
10529 | * Since we no longer track auth state, ignore | |
10530 | * requests to only change local state. | |
10531 | */ | |
10532 | if (local_state_change) | |
10533 | return 0; | |
10534 | ||
325839da JB |
10535 | req.auth_type = auth_type; |
10536 | req.key = key.p.key; | |
10537 | req.key_len = key.p.key_len; | |
10538 | req.key_idx = key.idx; | |
d648c230 JB |
10539 | req.link_id = nl80211_link_id_or_invalid(info->attrs); |
10540 | if (req.link_id >= 0) { | |
45aaf17c JB |
10541 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO)) |
10542 | return -EINVAL; | |
d648c230 JB |
10543 | if (!info->attrs[NL80211_ATTR_MLD_ADDR]) |
10544 | return -EINVAL; | |
10545 | req.ap_mld_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); | |
10546 | } | |
325839da JB |
10547 | |
10548 | req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, | |
10549 | IEEE80211_BSS_TYPE_ESS, | |
10550 | IEEE80211_PRIVACY_ANY); | |
10551 | if (!req.bss) | |
10552 | return -ENOENT; | |
10553 | ||
91bf9b26 | 10554 | wdev_lock(dev->ieee80211_ptr); |
325839da | 10555 | err = cfg80211_mlme_auth(rdev, dev, &req); |
91bf9b26 | 10556 | wdev_unlock(dev->ieee80211_ptr); |
325839da JB |
10557 | |
10558 | cfg80211_put_bss(&rdev->wiphy, req.bss); | |
10559 | ||
91bf9b26 | 10560 | return err; |
636a5d36 JM |
10561 | } |
10562 | ||
64bf3d4b DK |
10563 | static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, |
10564 | struct genl_info *info) | |
10565 | { | |
10566 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { | |
10567 | GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); | |
10568 | return -EINVAL; | |
10569 | } | |
10570 | ||
10571 | if (!rdev->ops->tx_control_port || | |
10572 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
10573 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) | |
10574 | return -EOPNOTSUPP; | |
10575 | ||
10576 | return 0; | |
10577 | } | |
10578 | ||
c0692b8f JB |
10579 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
10580 | struct genl_info *info, | |
3dc27d25 JB |
10581 | struct cfg80211_crypto_settings *settings, |
10582 | int cipher_limit) | |
b23aa676 | 10583 | { |
c0b2bbd8 JB |
10584 | memset(settings, 0, sizeof(*settings)); |
10585 | ||
b23aa676 SO |
10586 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
10587 | ||
c0692b8f JB |
10588 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
10589 | u16 proto; | |
7a087e74 | 10590 | |
c0692b8f JB |
10591 | proto = nla_get_u16( |
10592 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
10593 | settings->control_port_ethertype = cpu_to_be16(proto); | |
10594 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
10595 | proto != ETH_P_PAE) | |
10596 | return -EINVAL; | |
10597 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
10598 | settings->control_port_no_encrypt = true; | |
10599 | } else | |
10600 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
10601 | ||
64bf3d4b DK |
10602 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
10603 | int r = validate_pae_over_nl80211(rdev, info); | |
10604 | ||
10605 | if (r < 0) | |
10606 | return r; | |
10607 | ||
10608 | settings->control_port_over_nl80211 = true; | |
7f3f96ce MT |
10609 | |
10610 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH]) | |
10611 | settings->control_port_no_preauth = true; | |
64bf3d4b DK |
10612 | } |
10613 | ||
b23aa676 SO |
10614 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
10615 | void *data; | |
10616 | int len, i; | |
10617 | ||
10618 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
10619 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
10620 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
10621 | ||
10622 | if (len % sizeof(u32)) | |
10623 | return -EINVAL; | |
10624 | ||
3dc27d25 | 10625 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
10626 | return -EINVAL; |
10627 | ||
10628 | memcpy(settings->ciphers_pairwise, data, len); | |
10629 | ||
10630 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
10631 | if (!cfg80211_supported_cipher_suite( |
10632 | &rdev->wiphy, | |
b23aa676 SO |
10633 | settings->ciphers_pairwise[i])) |
10634 | return -EINVAL; | |
10635 | } | |
10636 | ||
10637 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
10638 | settings->cipher_group = | |
10639 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
10640 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
10641 | settings->cipher_group)) | |
b23aa676 SO |
10642 | return -EINVAL; |
10643 | } | |
10644 | ||
10645 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
10646 | settings->wpa_versions = | |
10647 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
10648 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
10649 | return -EINVAL; | |
10650 | } | |
10651 | ||
10652 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
10653 | void *data; | |
6d30240e | 10654 | int len; |
b23aa676 SO |
10655 | |
10656 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
10657 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
10658 | settings->n_akm_suites = len / sizeof(u32); | |
10659 | ||
10660 | if (len % sizeof(u32)) | |
10661 | return -EINVAL; | |
10662 | ||
ecad3b0b | 10663 | if (settings->n_akm_suites > rdev->wiphy.max_num_akm_suites) |
1b9ca027 JM |
10664 | return -EINVAL; |
10665 | ||
b23aa676 | 10666 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
10667 | } |
10668 | ||
91b5ab62 EP |
10669 | if (info->attrs[NL80211_ATTR_PMK]) { |
10670 | if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) | |
10671 | return -EINVAL; | |
10672 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
f9662274 CHH |
10673 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) && |
10674 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
10675 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK)) | |
91b5ab62 EP |
10676 | return -EINVAL; |
10677 | settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); | |
10678 | } | |
10679 | ||
26f7044e CHH |
10680 | if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) { |
10681 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
2831a631 CHH |
10682 | NL80211_EXT_FEATURE_SAE_OFFLOAD) && |
10683 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
10684 | NL80211_EXT_FEATURE_SAE_OFFLOAD_AP)) | |
26f7044e CHH |
10685 | return -EINVAL; |
10686 | settings->sae_pwd = | |
10687 | nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]); | |
10688 | settings->sae_pwd_len = | |
10689 | nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]); | |
10690 | } | |
10691 | ||
9f0ffa41 RD |
10692 | if (info->attrs[NL80211_ATTR_SAE_PWE]) |
10693 | settings->sae_pwe = | |
10694 | nla_get_u8(info->attrs[NL80211_ATTR_SAE_PWE]); | |
10695 | else | |
10696 | settings->sae_pwe = NL80211_SAE_PWE_UNSPECIFIED; | |
10697 | ||
b23aa676 SO |
10698 | return 0; |
10699 | } | |
10700 | ||
9ecff10e JB |
10701 | static struct cfg80211_bss *nl80211_assoc_bss(struct cfg80211_registered_device *rdev, |
10702 | const u8 *ssid, int ssid_len, | |
10703 | struct nlattr **attrs, | |
10704 | const u8 **bssid_out) | |
10705 | { | |
10706 | struct ieee80211_channel *chan; | |
10707 | struct cfg80211_bss *bss; | |
10708 | const u8 *bssid; | |
10709 | u32 freq; | |
10710 | ||
10711 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_WIPHY_FREQ]) | |
10712 | return ERR_PTR(-EINVAL); | |
10713 | ||
10714 | bssid = nla_data(attrs[NL80211_ATTR_MAC]); | |
10715 | ||
10716 | freq = MHZ_TO_KHZ(nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ])); | |
10717 | if (attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) | |
10718 | freq += nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); | |
10719 | ||
10720 | chan = nl80211_get_valid_chan(&rdev->wiphy, freq); | |
10721 | if (!chan) | |
10722 | return ERR_PTR(-EINVAL); | |
10723 | ||
10724 | bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, | |
10725 | ssid, ssid_len, | |
10726 | IEEE80211_BSS_TYPE_ESS, | |
10727 | IEEE80211_PRIVACY_ANY); | |
10728 | if (!bss) | |
10729 | return ERR_PTR(-ENOENT); | |
10730 | ||
10731 | *bssid_out = bssid; | |
10732 | return bss; | |
10733 | } | |
10734 | ||
636a5d36 JM |
10735 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
10736 | { | |
4c476991 JB |
10737 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
10738 | struct net_device *dev = info->user_ptr[1]; | |
f62fab73 | 10739 | struct cfg80211_assoc_request req = {}; |
d648c230 | 10740 | struct nlattr **attrs = NULL; |
f62fab73 | 10741 | const u8 *bssid, *ssid; |
d648c230 | 10742 | unsigned int link_id; |
0f759448 | 10743 | int err, ssid_len; |
636a5d36 | 10744 | |
bad29297 AZ |
10745 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
10746 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) | |
10747 | return -EPERM; | |
10748 | ||
9ecff10e | 10749 | if (!info->attrs[NL80211_ATTR_SSID]) |
f4a11bb0 JB |
10750 | return -EINVAL; |
10751 | ||
4c476991 JB |
10752 | if (!rdev->ops->assoc) |
10753 | return -EOPNOTSUPP; | |
636a5d36 | 10754 | |
074ac8df | 10755 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
10756 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
10757 | return -EOPNOTSUPP; | |
eec60b03 | 10758 | |
19957bb3 JB |
10759 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
10760 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
10761 | |
10762 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
10763 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
10764 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
df35f316 JB |
10765 | |
10766 | if (cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE, | |
10767 | req.ie, req.ie_len)) { | |
10768 | GENL_SET_ERR_MSG(info, | |
10769 | "non-inheritance makes no sense"); | |
10770 | return -EINVAL; | |
10771 | } | |
636a5d36 JM |
10772 | } |
10773 | ||
dc6382ce | 10774 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 10775 | enum nl80211_mfp mfp = |
dc6382ce | 10776 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 10777 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 10778 | req.use_mfp = true; |
4c476991 JB |
10779 | else if (mfp != NL80211_MFP_NO) |
10780 | return -EINVAL; | |
dc6382ce JM |
10781 | } |
10782 | ||
3e5d7649 | 10783 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 10784 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 10785 | |
7e7c8926 | 10786 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 10787 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
10788 | |
10789 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
10790 | memcpy(&req.ht_capa_mask, |
10791 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
10792 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
10793 | |
10794 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 10795 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 10796 | return -EINVAL; |
f62fab73 JB |
10797 | memcpy(&req.ht_capa, |
10798 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
10799 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
10800 | } |
10801 | ||
ee2aca34 | 10802 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 10803 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 | 10804 | |
b6db0f89 BG |
10805 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE])) |
10806 | req.flags |= ASSOC_REQ_DISABLE_HE; | |
10807 | ||
36f84235 MS |
10808 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_EHT])) |
10809 | req.flags |= ASSOC_REQ_DISABLE_EHT; | |
10810 | ||
ee2aca34 | 10811 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
f62fab73 JB |
10812 | memcpy(&req.vht_capa_mask, |
10813 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
10814 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
10815 | |
10816 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 10817 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 10818 | return -EINVAL; |
f62fab73 JB |
10819 | memcpy(&req.vht_capa, |
10820 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
10821 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
10822 | } |
10823 | ||
bab5ab7d | 10824 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
0c9ca11b BL |
10825 | if (!((rdev->wiphy.features & |
10826 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && | |
10827 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && | |
10828 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
10829 | NL80211_EXT_FEATURE_RRM)) | |
bab5ab7d AK |
10830 | return -EINVAL; |
10831 | req.flags |= ASSOC_REQ_USE_RRM; | |
10832 | } | |
10833 | ||
348bd456 JM |
10834 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
10835 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); | |
10836 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); | |
10837 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) | |
10838 | return -EINVAL; | |
10839 | req.fils_nonces = | |
10840 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); | |
10841 | } | |
10842 | ||
d2b7588a TP |
10843 | if (info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) { |
10844 | if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY]) | |
10845 | return -EINVAL; | |
10846 | memcpy(&req.s1g_capa_mask, | |
10847 | nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]), | |
10848 | sizeof(req.s1g_capa_mask)); | |
10849 | } | |
10850 | ||
10851 | if (info->attrs[NL80211_ATTR_S1G_CAPABILITY]) { | |
10852 | if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) | |
10853 | return -EINVAL; | |
10854 | memcpy(&req.s1g_capa, | |
10855 | nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY]), | |
10856 | sizeof(req.s1g_capa)); | |
10857 | } | |
10858 | ||
d648c230 JB |
10859 | req.link_id = nl80211_link_id_or_invalid(info->attrs); |
10860 | ||
10861 | if (info->attrs[NL80211_ATTR_MLO_LINKS]) { | |
10862 | unsigned int attrsize = NUM_NL80211_ATTR * sizeof(*attrs); | |
10863 | struct nlattr *link; | |
10864 | int rem = 0; | |
10865 | ||
10866 | if (req.link_id < 0) | |
10867 | return -EINVAL; | |
10868 | ||
10869 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO)) | |
10870 | return -EINVAL; | |
10871 | ||
10872 | if (info->attrs[NL80211_ATTR_MAC] || | |
10873 | info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
10874 | !info->attrs[NL80211_ATTR_MLD_ADDR]) | |
10875 | return -EINVAL; | |
10876 | ||
10877 | req.ap_mld_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); | |
10878 | ||
10879 | attrs = kzalloc(attrsize, GFP_KERNEL); | |
10880 | if (!attrs) | |
10881 | return -ENOMEM; | |
10882 | ||
10883 | nla_for_each_nested(link, | |
10884 | info->attrs[NL80211_ATTR_MLO_LINKS], | |
10885 | rem) { | |
10886 | memset(attrs, 0, attrsize); | |
10887 | ||
10888 | nla_parse_nested(attrs, NL80211_ATTR_MAX, | |
10889 | link, NULL, NULL); | |
10890 | ||
10891 | if (!attrs[NL80211_ATTR_MLO_LINK_ID]) { | |
10892 | err = -EINVAL; | |
10893 | goto free; | |
10894 | } | |
10895 | ||
10896 | link_id = nla_get_u8(attrs[NL80211_ATTR_MLO_LINK_ID]); | |
10897 | /* cannot use the same link ID again */ | |
10898 | if (req.links[link_id].bss) { | |
10899 | err = -EINVAL; | |
10900 | goto free; | |
10901 | } | |
10902 | req.links[link_id].bss = | |
10903 | nl80211_assoc_bss(rdev, ssid, ssid_len, attrs, | |
10904 | &bssid); | |
10905 | if (IS_ERR(req.links[link_id].bss)) { | |
10906 | err = PTR_ERR(req.links[link_id].bss); | |
9b6bf4d6 | 10907 | req.links[link_id].bss = NULL; |
d648c230 JB |
10908 | goto free; |
10909 | } | |
10910 | ||
10911 | if (attrs[NL80211_ATTR_IE]) { | |
10912 | req.links[link_id].elems = | |
10913 | nla_data(attrs[NL80211_ATTR_IE]); | |
10914 | req.links[link_id].elems_len = | |
10915 | nla_len(attrs[NL80211_ATTR_IE]); | |
df35f316 JB |
10916 | |
10917 | if (cfg80211_find_elem(WLAN_EID_FRAGMENT, | |
10918 | req.links[link_id].elems, | |
10919 | req.links[link_id].elems_len)) { | |
10920 | GENL_SET_ERR_MSG(info, | |
10921 | "cannot deal with fragmentation"); | |
10922 | err = -EINVAL; | |
10923 | goto free; | |
10924 | } | |
10925 | ||
10926 | if (cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE, | |
10927 | req.links[link_id].elems, | |
10928 | req.links[link_id].elems_len)) { | |
10929 | GENL_SET_ERR_MSG(info, | |
10930 | "cannot deal with non-inheritance"); | |
10931 | err = -EINVAL; | |
10932 | goto free; | |
10933 | } | |
d648c230 JB |
10934 | } |
10935 | } | |
10936 | ||
10937 | if (!req.links[req.link_id].bss) { | |
10938 | err = -EINVAL; | |
10939 | goto free; | |
10940 | } | |
10941 | ||
34d76a14 JB |
10942 | if (req.links[req.link_id].elems_len) { |
10943 | GENL_SET_ERR_MSG(info, | |
10944 | "cannot have per-link elems on assoc link"); | |
10945 | err = -EINVAL; | |
10946 | goto free; | |
10947 | } | |
10948 | ||
d648c230 JB |
10949 | kfree(attrs); |
10950 | attrs = NULL; | |
10951 | } else { | |
10952 | if (req.link_id >= 0) | |
10953 | return -EINVAL; | |
10954 | ||
10955 | req.bss = nl80211_assoc_bss(rdev, ssid, ssid_len, info->attrs, | |
10956 | &bssid); | |
10957 | if (IS_ERR(req.bss)) | |
10958 | return PTR_ERR(req.bss); | |
10959 | } | |
0f759448 | 10960 | |
f62fab73 | 10961 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
10962 | if (!err) { |
10963 | wdev_lock(dev->ieee80211_ptr); | |
bd2522b1 | 10964 | |
0f759448 | 10965 | err = cfg80211_mlme_assoc(rdev, dev, &req); |
bd2522b1 AZ |
10966 | |
10967 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { | |
10968 | dev->ieee80211_ptr->conn_owner_nlportid = | |
10969 | info->snd_portid; | |
10970 | memcpy(dev->ieee80211_ptr->disconnect_bssid, | |
10971 | bssid, ETH_ALEN); | |
10972 | } | |
10973 | ||
91bf9b26 JB |
10974 | wdev_unlock(dev->ieee80211_ptr); |
10975 | } | |
636a5d36 | 10976 | |
d648c230 JB |
10977 | free: |
10978 | for (link_id = 0; link_id < ARRAY_SIZE(req.links); link_id++) | |
10979 | cfg80211_put_bss(&rdev->wiphy, req.links[link_id].bss); | |
0f759448 | 10980 | cfg80211_put_bss(&rdev->wiphy, req.bss); |
d648c230 | 10981 | kfree(attrs); |
0f759448 | 10982 | |
636a5d36 JM |
10983 | return err; |
10984 | } | |
10985 | ||
10986 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
10987 | { | |
4c476991 JB |
10988 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
10989 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 10990 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 10991 | int ie_len = 0, err; |
19957bb3 | 10992 | u16 reason_code; |
d5cdfacb | 10993 | bool local_state_change; |
636a5d36 | 10994 | |
bad29297 AZ |
10995 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
10996 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) | |
10997 | return -EPERM; | |
10998 | ||
f4a11bb0 JB |
10999 | if (!info->attrs[NL80211_ATTR_MAC]) |
11000 | return -EINVAL; | |
11001 | ||
11002 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
11003 | return -EINVAL; | |
11004 | ||
4c476991 JB |
11005 | if (!rdev->ops->deauth) |
11006 | return -EOPNOTSUPP; | |
636a5d36 | 11007 | |
074ac8df | 11008 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
11009 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
11010 | return -EOPNOTSUPP; | |
eec60b03 | 11011 | |
19957bb3 | 11012 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 11013 | |
19957bb3 JB |
11014 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
11015 | if (reason_code == 0) { | |
f4a11bb0 | 11016 | /* Reason Code 0 is reserved */ |
4c476991 | 11017 | return -EINVAL; |
255e737e | 11018 | } |
636a5d36 JM |
11019 | |
11020 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
11021 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
11022 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
11023 | } |
11024 | ||
d5cdfacb JM |
11025 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
11026 | ||
91bf9b26 JB |
11027 | wdev_lock(dev->ieee80211_ptr); |
11028 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
11029 | local_state_change); | |
11030 | wdev_unlock(dev->ieee80211_ptr); | |
11031 | return err; | |
636a5d36 JM |
11032 | } |
11033 | ||
11034 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
11035 | { | |
4c476991 JB |
11036 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
11037 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 11038 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 11039 | int ie_len = 0, err; |
19957bb3 | 11040 | u16 reason_code; |
d5cdfacb | 11041 | bool local_state_change; |
636a5d36 | 11042 | |
bad29297 AZ |
11043 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
11044 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) | |
11045 | return -EPERM; | |
11046 | ||
f4a11bb0 JB |
11047 | if (!info->attrs[NL80211_ATTR_MAC]) |
11048 | return -EINVAL; | |
11049 | ||
11050 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
11051 | return -EINVAL; | |
11052 | ||
4c476991 JB |
11053 | if (!rdev->ops->disassoc) |
11054 | return -EOPNOTSUPP; | |
636a5d36 | 11055 | |
074ac8df | 11056 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
11057 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
11058 | return -EOPNOTSUPP; | |
eec60b03 | 11059 | |
19957bb3 | 11060 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 11061 | |
19957bb3 JB |
11062 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
11063 | if (reason_code == 0) { | |
f4a11bb0 | 11064 | /* Reason Code 0 is reserved */ |
4c476991 | 11065 | return -EINVAL; |
255e737e | 11066 | } |
636a5d36 JM |
11067 | |
11068 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
11069 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
11070 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
11071 | } |
11072 | ||
d5cdfacb JM |
11073 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
11074 | ||
91bf9b26 JB |
11075 | wdev_lock(dev->ieee80211_ptr); |
11076 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
11077 | local_state_change); | |
11078 | wdev_unlock(dev->ieee80211_ptr); | |
11079 | return err; | |
636a5d36 JM |
11080 | } |
11081 | ||
dd5b4cc7 FF |
11082 | static bool |
11083 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
57fbcce3 | 11084 | int mcast_rate[NUM_NL80211_BANDS], |
dd5b4cc7 FF |
11085 | int rateval) |
11086 | { | |
11087 | struct wiphy *wiphy = &rdev->wiphy; | |
11088 | bool found = false; | |
11089 | int band, i; | |
11090 | ||
57fbcce3 | 11091 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
dd5b4cc7 FF |
11092 | struct ieee80211_supported_band *sband; |
11093 | ||
11094 | sband = wiphy->bands[band]; | |
11095 | if (!sband) | |
11096 | continue; | |
11097 | ||
11098 | for (i = 0; i < sband->n_bitrates; i++) { | |
11099 | if (sband->bitrates[i].bitrate == rateval) { | |
11100 | mcast_rate[band] = i + 1; | |
11101 | found = true; | |
11102 | break; | |
11103 | } | |
11104 | } | |
11105 | } | |
11106 | ||
11107 | return found; | |
11108 | } | |
11109 | ||
04a773ad JB |
11110 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
11111 | { | |
4c476991 JB |
11112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
11113 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
11114 | struct cfg80211_ibss_params ibss; |
11115 | struct wiphy *wiphy; | |
fffd0934 | 11116 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
11117 | int err; |
11118 | ||
8e30bc55 JB |
11119 | memset(&ibss, 0, sizeof(ibss)); |
11120 | ||
683b6d3b | 11121 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
11122 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
11123 | return -EINVAL; | |
11124 | ||
8e30bc55 JB |
11125 | ibss.beacon_interval = 100; |
11126 | ||
12d20fc9 | 11127 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
8e30bc55 JB |
11128 | ibss.beacon_interval = |
11129 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
12d20fc9 | 11130 | |
0c317a02 PK |
11131 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
11132 | ibss.beacon_interval); | |
12d20fc9 PK |
11133 | if (err) |
11134 | return err; | |
8e30bc55 | 11135 | |
4c476991 JB |
11136 | if (!rdev->ops->join_ibss) |
11137 | return -EOPNOTSUPP; | |
04a773ad | 11138 | |
4c476991 JB |
11139 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
11140 | return -EOPNOTSUPP; | |
04a773ad | 11141 | |
79c97e97 | 11142 | wiphy = &rdev->wiphy; |
04a773ad | 11143 | |
39193498 | 11144 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 11145 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
11146 | |
11147 | if (!is_valid_ether_addr(ibss.bssid)) | |
11148 | return -EINVAL; | |
11149 | } | |
04a773ad JB |
11150 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
11151 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
11152 | ||
11153 | if (info->attrs[NL80211_ATTR_IE]) { | |
11154 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
11155 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
11156 | } | |
11157 | ||
683b6d3b JB |
11158 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
11159 | if (err) | |
11160 | return err; | |
04a773ad | 11161 | |
174e0cd2 IP |
11162 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
11163 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
11164 | return -EINVAL; |
11165 | ||
2f301ab2 | 11166 | switch (ibss.chandef.width) { |
bf372645 SW |
11167 | case NL80211_CHAN_WIDTH_5: |
11168 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
11169 | case NL80211_CHAN_WIDTH_20_NOHT: |
11170 | break; | |
11171 | case NL80211_CHAN_WIDTH_20: | |
11172 | case NL80211_CHAN_WIDTH_40: | |
ffc11991 JD |
11173 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
11174 | return -EINVAL; | |
11175 | break; | |
11176 | case NL80211_CHAN_WIDTH_80: | |
11177 | case NL80211_CHAN_WIDTH_80P80: | |
11178 | case NL80211_CHAN_WIDTH_160: | |
11179 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | |
11180 | return -EINVAL; | |
11181 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
11182 | NL80211_EXT_FEATURE_VHT_IBSS)) | |
11183 | return -EINVAL; | |
11184 | break; | |
3743bec6 JD |
11185 | case NL80211_CHAN_WIDTH_320: |
11186 | return -EINVAL; | |
2f301ab2 | 11187 | default: |
c04d6150 | 11188 | return -EINVAL; |
2f301ab2 | 11189 | } |
db9c64cf | 11190 | |
04a773ad | 11191 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
11192 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
11193 | ||
fbd2c8dc TP |
11194 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
11195 | u8 *rates = | |
11196 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
11197 | int n_rates = | |
11198 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
11199 | struct ieee80211_supported_band *sband = | |
683b6d3b | 11200 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 11201 | |
34850ab2 JB |
11202 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
11203 | &ibss.basic_rates); | |
11204 | if (err) | |
11205 | return err; | |
fbd2c8dc | 11206 | } |
dd5b4cc7 | 11207 | |
803768f5 SW |
11208 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
11209 | memcpy(&ibss.ht_capa_mask, | |
11210 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
11211 | sizeof(ibss.ht_capa_mask)); | |
11212 | ||
11213 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
11214 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
11215 | return -EINVAL; | |
11216 | memcpy(&ibss.ht_capa, | |
11217 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
11218 | sizeof(ibss.ht_capa)); | |
11219 | } | |
11220 | ||
dd5b4cc7 FF |
11221 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
11222 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
11223 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
11224 | return -EINVAL; | |
fbd2c8dc | 11225 | |
4c476991 | 11226 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
11227 | bool no_ht = false; |
11228 | ||
768075eb | 11229 | connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); |
4c476991 JB |
11230 | if (IS_ERR(connkeys)) |
11231 | return PTR_ERR(connkeys); | |
de7044ee | 11232 | |
3d9d1d66 JB |
11233 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
11234 | no_ht) { | |
453431a5 | 11235 | kfree_sensitive(connkeys); |
de7044ee SM |
11236 | return -EINVAL; |
11237 | } | |
4c476991 | 11238 | } |
04a773ad | 11239 | |
267335d6 AQ |
11240 | ibss.control_port = |
11241 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
11242 | ||
c3bfe1f6 DK |
11243 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
11244 | int r = validate_pae_over_nl80211(rdev, info); | |
11245 | ||
d350a0f4 | 11246 | if (r < 0) { |
453431a5 | 11247 | kfree_sensitive(connkeys); |
c3bfe1f6 | 11248 | return r; |
d350a0f4 | 11249 | } |
c3bfe1f6 DK |
11250 | |
11251 | ibss.control_port_over_nl80211 = true; | |
11252 | } | |
11253 | ||
5336fa88 SW |
11254 | ibss.userspace_handles_dfs = |
11255 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
11256 | ||
f8d16d3e DK |
11257 | wdev_lock(dev->ieee80211_ptr); |
11258 | err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); | |
fffd0934 | 11259 | if (err) |
453431a5 | 11260 | kfree_sensitive(connkeys); |
f8d16d3e DK |
11261 | else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
11262 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; | |
11263 | wdev_unlock(dev->ieee80211_ptr); | |
11264 | ||
04a773ad JB |
11265 | return err; |
11266 | } | |
11267 | ||
11268 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
11269 | { | |
4c476991 JB |
11270 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
11271 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 11272 | |
4c476991 JB |
11273 | if (!rdev->ops->leave_ibss) |
11274 | return -EOPNOTSUPP; | |
04a773ad | 11275 | |
4c476991 JB |
11276 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
11277 | return -EOPNOTSUPP; | |
04a773ad | 11278 | |
4c476991 | 11279 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
11280 | } |
11281 | ||
f4e583c8 AQ |
11282 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
11283 | { | |
11284 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11285 | struct net_device *dev = info->user_ptr[1]; | |
57fbcce3 | 11286 | int mcast_rate[NUM_NL80211_BANDS]; |
f4e583c8 | 11287 | u32 nla_rate; |
f4e583c8 AQ |
11288 | |
11289 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
876dc930 BVB |
11290 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
11291 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) | |
f4e583c8 AQ |
11292 | return -EOPNOTSUPP; |
11293 | ||
11294 | if (!rdev->ops->set_mcast_rate) | |
11295 | return -EOPNOTSUPP; | |
11296 | ||
11297 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
11298 | ||
11299 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
11300 | return -EINVAL; | |
11301 | ||
11302 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
11303 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
11304 | return -EINVAL; | |
11305 | ||
a21cd7d6 | 11306 | return rdev_set_mcast_rate(rdev, dev, mcast_rate); |
f4e583c8 AQ |
11307 | } |
11308 | ||
ad7e718c JB |
11309 | static struct sk_buff * |
11310 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
6c09e791 AK |
11311 | struct wireless_dev *wdev, int approxlen, |
11312 | u32 portid, u32 seq, enum nl80211_commands cmd, | |
567ffc35 JB |
11313 | enum nl80211_attrs attr, |
11314 | const struct nl80211_vendor_cmd_info *info, | |
11315 | gfp_t gfp) | |
ad7e718c JB |
11316 | { |
11317 | struct sk_buff *skb; | |
11318 | void *hdr; | |
11319 | struct nlattr *data; | |
11320 | ||
11321 | skb = nlmsg_new(approxlen + 100, gfp); | |
11322 | if (!skb) | |
11323 | return NULL; | |
11324 | ||
11325 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
11326 | if (!hdr) { | |
11327 | kfree_skb(skb); | |
11328 | return NULL; | |
11329 | } | |
11330 | ||
11331 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
11332 | goto nla_put_failure; | |
567ffc35 JB |
11333 | |
11334 | if (info) { | |
11335 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
11336 | info->vendor_id)) | |
11337 | goto nla_put_failure; | |
11338 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
11339 | info->subcmd)) | |
11340 | goto nla_put_failure; | |
11341 | } | |
11342 | ||
6c09e791 | 11343 | if (wdev) { |
2dad624e ND |
11344 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
11345 | wdev_id(wdev), NL80211_ATTR_PAD)) | |
6c09e791 AK |
11346 | goto nla_put_failure; |
11347 | if (wdev->netdev && | |
11348 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, | |
11349 | wdev->netdev->ifindex)) | |
11350 | goto nla_put_failure; | |
11351 | } | |
11352 | ||
ae0be8de | 11353 | data = nla_nest_start_noflag(skb, attr); |
76e1fb4b JB |
11354 | if (!data) |
11355 | goto nla_put_failure; | |
ad7e718c JB |
11356 | |
11357 | ((void **)skb->cb)[0] = rdev; | |
11358 | ((void **)skb->cb)[1] = hdr; | |
11359 | ((void **)skb->cb)[2] = data; | |
11360 | ||
11361 | return skb; | |
11362 | ||
11363 | nla_put_failure: | |
11364 | kfree_skb(skb); | |
11365 | return NULL; | |
11366 | } | |
f4e583c8 | 11367 | |
e03ad6ea | 11368 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
6c09e791 | 11369 | struct wireless_dev *wdev, |
e03ad6ea JB |
11370 | enum nl80211_commands cmd, |
11371 | enum nl80211_attrs attr, | |
55c1fdf0 | 11372 | unsigned int portid, |
e03ad6ea JB |
11373 | int vendor_event_idx, |
11374 | int approxlen, gfp_t gfp) | |
11375 | { | |
f26cbf40 | 11376 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
11377 | const struct nl80211_vendor_cmd_info *info; |
11378 | ||
11379 | switch (cmd) { | |
11380 | case NL80211_CMD_TESTMODE: | |
11381 | if (WARN_ON(vendor_event_idx != -1)) | |
11382 | return NULL; | |
11383 | info = NULL; | |
11384 | break; | |
11385 | case NL80211_CMD_VENDOR: | |
11386 | if (WARN_ON(vendor_event_idx < 0 || | |
11387 | vendor_event_idx >= wiphy->n_vendor_events)) | |
11388 | return NULL; | |
11389 | info = &wiphy->vendor_events[vendor_event_idx]; | |
11390 | break; | |
11391 | default: | |
11392 | WARN_ON(1); | |
11393 | return NULL; | |
11394 | } | |
11395 | ||
55c1fdf0 | 11396 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0, |
e03ad6ea JB |
11397 | cmd, attr, info, gfp); |
11398 | } | |
11399 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
11400 | ||
11401 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
11402 | { | |
11403 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
11404 | void *hdr = ((void **)skb->cb)[1]; | |
55c1fdf0 | 11405 | struct nlmsghdr *nlhdr = nlmsg_hdr(skb); |
e03ad6ea JB |
11406 | struct nlattr *data = ((void **)skb->cb)[2]; |
11407 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
11408 | ||
bd8c78e7 JB |
11409 | /* clear CB data for netlink core to own from now on */ |
11410 | memset(skb->cb, 0, sizeof(skb->cb)); | |
11411 | ||
e03ad6ea JB |
11412 | nla_nest_end(skb, data); |
11413 | genlmsg_end(skb, hdr); | |
11414 | ||
55c1fdf0 JB |
11415 | if (nlhdr->nlmsg_pid) { |
11416 | genlmsg_unicast(wiphy_net(&rdev->wiphy), skb, | |
11417 | nlhdr->nlmsg_pid); | |
11418 | } else { | |
11419 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
11420 | mcgrp = NL80211_MCGRP_VENDOR; | |
e03ad6ea | 11421 | |
55c1fdf0 JB |
11422 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
11423 | skb, 0, mcgrp, gfp); | |
11424 | } | |
e03ad6ea JB |
11425 | } |
11426 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
11427 | ||
aff89a9b | 11428 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
11429 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
11430 | { | |
4c476991 | 11431 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
a05829a7 | 11432 | struct wireless_dev *wdev; |
aff89a9b JB |
11433 | int err; |
11434 | ||
a05829a7 JB |
11435 | lockdep_assert_held(&rdev->wiphy.mtx); |
11436 | ||
11437 | wdev = __cfg80211_wdev_from_attrs(rdev, genl_info_net(info), | |
11438 | info->attrs); | |
11439 | ||
fc73f11f DS |
11440 | if (!rdev->ops->testmode_cmd) |
11441 | return -EOPNOTSUPP; | |
11442 | ||
11443 | if (IS_ERR(wdev)) { | |
11444 | err = PTR_ERR(wdev); | |
11445 | if (err != -EINVAL) | |
11446 | return err; | |
11447 | wdev = NULL; | |
11448 | } else if (wdev->wiphy != &rdev->wiphy) { | |
11449 | return -EINVAL; | |
11450 | } | |
11451 | ||
aff89a9b JB |
11452 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
11453 | return -EINVAL; | |
11454 | ||
ad7e718c | 11455 | rdev->cur_cmd_info = info; |
fc73f11f | 11456 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
11457 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
11458 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 11459 | rdev->cur_cmd_info = NULL; |
aff89a9b | 11460 | |
aff89a9b JB |
11461 | return err; |
11462 | } | |
11463 | ||
71063f0e WYG |
11464 | static int nl80211_testmode_dump(struct sk_buff *skb, |
11465 | struct netlink_callback *cb) | |
11466 | { | |
00918d33 | 11467 | struct cfg80211_registered_device *rdev; |
50508d94 | 11468 | struct nlattr **attrbuf = NULL; |
71063f0e WYG |
11469 | int err; |
11470 | long phy_idx; | |
11471 | void *data = NULL; | |
11472 | int data_len = 0; | |
11473 | ||
5fe231e8 JB |
11474 | rtnl_lock(); |
11475 | ||
71063f0e WYG |
11476 | if (cb->args[0]) { |
11477 | /* | |
11478 | * 0 is a valid index, but not valid for args[0], | |
11479 | * so we need to offset by 1. | |
11480 | */ | |
11481 | phy_idx = cb->args[0] - 1; | |
a4956dca LC |
11482 | |
11483 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); | |
11484 | if (!rdev) { | |
11485 | err = -ENOENT; | |
11486 | goto out_err; | |
11487 | } | |
71063f0e | 11488 | } else { |
50508d94 JB |
11489 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), |
11490 | GFP_KERNEL); | |
11491 | if (!attrbuf) { | |
11492 | err = -ENOMEM; | |
11493 | goto out_err; | |
11494 | } | |
c90c39da | 11495 | |
8cb08174 JB |
11496 | err = nlmsg_parse_deprecated(cb->nlh, |
11497 | GENL_HDRLEN + nl80211_fam.hdrsize, | |
11498 | attrbuf, nl80211_fam.maxattr, | |
11499 | nl80211_policy, NULL); | |
71063f0e | 11500 | if (err) |
5fe231e8 | 11501 | goto out_err; |
00918d33 | 11502 | |
c90c39da | 11503 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
2bd7e35d | 11504 | if (IS_ERR(rdev)) { |
5fe231e8 JB |
11505 | err = PTR_ERR(rdev); |
11506 | goto out_err; | |
00918d33 | 11507 | } |
2bd7e35d | 11508 | phy_idx = rdev->wiphy_idx; |
2bd7e35d | 11509 | |
c90c39da JB |
11510 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
11511 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; | |
71063f0e WYG |
11512 | } |
11513 | ||
11514 | if (cb->args[1]) { | |
11515 | data = nla_data((void *)cb->args[1]); | |
11516 | data_len = nla_len((void *)cb->args[1]); | |
11517 | } | |
11518 | ||
00918d33 | 11519 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
11520 | err = -EOPNOTSUPP; |
11521 | goto out_err; | |
11522 | } | |
11523 | ||
11524 | while (1) { | |
15e47304 | 11525 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
11526 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
11527 | NL80211_CMD_TESTMODE); | |
11528 | struct nlattr *tmdata; | |
11529 | ||
cb35fba3 DC |
11530 | if (!hdr) |
11531 | break; | |
11532 | ||
9360ffd1 | 11533 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
11534 | genlmsg_cancel(skb, hdr); |
11535 | break; | |
11536 | } | |
11537 | ||
ae0be8de | 11538 | tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA); |
71063f0e WYG |
11539 | if (!tmdata) { |
11540 | genlmsg_cancel(skb, hdr); | |
11541 | break; | |
11542 | } | |
e35e4d28 | 11543 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
11544 | nla_nest_end(skb, tmdata); |
11545 | ||
11546 | if (err == -ENOBUFS || err == -ENOENT) { | |
11547 | genlmsg_cancel(skb, hdr); | |
11548 | break; | |
11549 | } else if (err) { | |
11550 | genlmsg_cancel(skb, hdr); | |
11551 | goto out_err; | |
11552 | } | |
11553 | ||
11554 | genlmsg_end(skb, hdr); | |
11555 | } | |
11556 | ||
11557 | err = skb->len; | |
11558 | /* see above */ | |
11559 | cb->args[0] = phy_idx + 1; | |
11560 | out_err: | |
50508d94 | 11561 | kfree(attrbuf); |
5fe231e8 | 11562 | rtnl_unlock(); |
71063f0e WYG |
11563 | return err; |
11564 | } | |
aff89a9b JB |
11565 | #endif |
11566 | ||
b23aa676 SO |
11567 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
11568 | { | |
4c476991 JB |
11569 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
11570 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
11571 | struct cfg80211_connect_params connect; |
11572 | struct wiphy *wiphy; | |
fffd0934 | 11573 | struct cfg80211_cached_keys *connkeys = NULL; |
942ba88b | 11574 | u32 freq = 0; |
b23aa676 SO |
11575 | int err; |
11576 | ||
11577 | memset(&connect, 0, sizeof(connect)); | |
11578 | ||
b23aa676 SO |
11579 | if (!info->attrs[NL80211_ATTR_SSID] || |
11580 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
11581 | return -EINVAL; | |
11582 | ||
11583 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
11584 | connect.auth_type = | |
11585 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
11586 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
11587 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
11588 | return -EINVAL; |
11589 | } else | |
11590 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
11591 | ||
11592 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
11593 | ||
3a00df57 AS |
11594 | if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && |
11595 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
11596 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) | |
11597 | return -EINVAL; | |
11598 | connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; | |
11599 | ||
c0692b8f | 11600 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 11601 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
11602 | if (err) |
11603 | return err; | |
b23aa676 | 11604 | |
074ac8df | 11605 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
11606 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
11607 | return -EOPNOTSUPP; | |
b23aa676 | 11608 | |
79c97e97 | 11609 | wiphy = &rdev->wiphy; |
b23aa676 | 11610 | |
4486ea98 BS |
11611 | connect.bg_scan_period = -1; |
11612 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
11613 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
11614 | connect.bg_scan_period = | |
11615 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
11616 | } | |
11617 | ||
b23aa676 SO |
11618 | if (info->attrs[NL80211_ATTR_MAC]) |
11619 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
11620 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
11621 | connect.bssid_hint = | |
11622 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
11623 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
11624 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
11625 | ||
11626 | if (info->attrs[NL80211_ATTR_IE]) { | |
11627 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
11628 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
11629 | } | |
11630 | ||
cee00a95 JM |
11631 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
11632 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
65026002 EG |
11633 | if (connect.mfp == NL80211_MFP_OPTIONAL && |
11634 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
11635 | NL80211_EXT_FEATURE_MFP_OPTIONAL)) | |
11636 | return -EOPNOTSUPP; | |
cee00a95 JM |
11637 | } else { |
11638 | connect.mfp = NL80211_MFP_NO; | |
11639 | } | |
11640 | ||
ba6fbacf JM |
11641 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
11642 | connect.prev_bssid = | |
11643 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | |
11644 | ||
942ba88b TP |
11645 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
11646 | freq = MHZ_TO_KHZ(nla_get_u32( | |
11647 | info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
11648 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) | |
11649 | freq += | |
11650 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); | |
11651 | ||
11652 | if (freq) { | |
11653 | connect.channel = nl80211_get_valid_chan(wiphy, freq); | |
664834de | 11654 | if (!connect.channel) |
1df4a510 JM |
11655 | return -EINVAL; |
11656 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
942ba88b TP |
11657 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
11658 | freq = MHZ_TO_KHZ(freq); | |
11659 | connect.channel_hint = nl80211_get_valid_chan(wiphy, freq); | |
664834de | 11660 | if (!connect.channel_hint) |
4c476991 | 11661 | return -EINVAL; |
b23aa676 SO |
11662 | } |
11663 | ||
2a38075c AAL |
11664 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { |
11665 | connect.edmg.channels = | |
11666 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); | |
11667 | ||
11668 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) | |
11669 | connect.edmg.bw_config = | |
11670 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); | |
11671 | } | |
11672 | ||
fffd0934 | 11673 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
768075eb | 11674 | connkeys = nl80211_parse_connkeys(rdev, info, NULL); |
4c476991 JB |
11675 | if (IS_ERR(connkeys)) |
11676 | return PTR_ERR(connkeys); | |
fffd0934 JB |
11677 | } |
11678 | ||
7e7c8926 BG |
11679 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
11680 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
11681 | ||
11682 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
11683 | memcpy(&connect.ht_capa_mask, | |
11684 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
11685 | sizeof(connect.ht_capa_mask)); | |
11686 | ||
11687 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 11688 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
453431a5 | 11689 | kfree_sensitive(connkeys); |
7e7c8926 | 11690 | return -EINVAL; |
b4e4f47e | 11691 | } |
7e7c8926 BG |
11692 | memcpy(&connect.ht_capa, |
11693 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
11694 | sizeof(connect.ht_capa)); | |
11695 | } | |
11696 | ||
ee2aca34 JB |
11697 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
11698 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
11699 | ||
b6db0f89 BG |
11700 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE])) |
11701 | connect.flags |= ASSOC_REQ_DISABLE_HE; | |
11702 | ||
36f84235 MS |
11703 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_EHT])) |
11704 | connect.flags |= ASSOC_REQ_DISABLE_EHT; | |
11705 | ||
ee2aca34 JB |
11706 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
11707 | memcpy(&connect.vht_capa_mask, | |
11708 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
11709 | sizeof(connect.vht_capa_mask)); | |
11710 | ||
11711 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
11712 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
453431a5 | 11713 | kfree_sensitive(connkeys); |
ee2aca34 JB |
11714 | return -EINVAL; |
11715 | } | |
11716 | memcpy(&connect.vht_capa, | |
11717 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
11718 | sizeof(connect.vht_capa)); | |
11719 | } | |
11720 | ||
bab5ab7d | 11721 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
0c9ca11b BL |
11722 | if (!((rdev->wiphy.features & |
11723 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && | |
11724 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && | |
11725 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
11726 | NL80211_EXT_FEATURE_RRM)) { | |
453431a5 | 11727 | kfree_sensitive(connkeys); |
bab5ab7d | 11728 | return -EINVAL; |
707554b4 | 11729 | } |
bab5ab7d AK |
11730 | connect.flags |= ASSOC_REQ_USE_RRM; |
11731 | } | |
11732 | ||
34d50519 | 11733 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
57fbcce3 | 11734 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
453431a5 | 11735 | kfree_sensitive(connkeys); |
34d50519 LD |
11736 | return -EOPNOTSUPP; |
11737 | } | |
11738 | ||
38de03d2 AS |
11739 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
11740 | /* bss selection makes no sense if bssid is set */ | |
11741 | if (connect.bssid) { | |
453431a5 | 11742 | kfree_sensitive(connkeys); |
38de03d2 AS |
11743 | return -EINVAL; |
11744 | } | |
11745 | ||
11746 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], | |
11747 | wiphy, &connect.bss_select); | |
11748 | if (err) { | |
453431a5 | 11749 | kfree_sensitive(connkeys); |
38de03d2 AS |
11750 | return err; |
11751 | } | |
11752 | } | |
11753 | ||
a3caf744 VK |
11754 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
11755 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && | |
11756 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && | |
11757 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && | |
11758 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && | |
11759 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { | |
11760 | connect.fils_erp_username = | |
11761 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); | |
11762 | connect.fils_erp_username_len = | |
11763 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); | |
11764 | connect.fils_erp_realm = | |
11765 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); | |
11766 | connect.fils_erp_realm_len = | |
11767 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); | |
11768 | connect.fils_erp_next_seq_num = | |
11769 | nla_get_u16( | |
11770 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); | |
11771 | connect.fils_erp_rrk = | |
11772 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); | |
11773 | connect.fils_erp_rrk_len = | |
11774 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); | |
11775 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || | |
11776 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || | |
11777 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || | |
11778 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { | |
453431a5 | 11779 | kfree_sensitive(connkeys); |
a3caf744 VK |
11780 | return -EINVAL; |
11781 | } | |
11782 | ||
40cbfa90 SD |
11783 | if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { |
11784 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { | |
453431a5 | 11785 | kfree_sensitive(connkeys); |
40cbfa90 SD |
11786 | GENL_SET_ERR_MSG(info, |
11787 | "external auth requires connection ownership"); | |
11788 | return -EINVAL; | |
11789 | } | |
11790 | connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; | |
11791 | } | |
11792 | ||
efbabc11 VJ |
11793 | if (nla_get_flag(info->attrs[NL80211_ATTR_MLO_SUPPORT])) |
11794 | connect.flags |= CONNECT_REQ_MLO_SUPPORT; | |
11795 | ||
83739b03 | 11796 | wdev_lock(dev->ieee80211_ptr); |
bd2522b1 | 11797 | |
4ce2bd9c JM |
11798 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
11799 | connect.prev_bssid); | |
fffd0934 | 11800 | if (err) |
453431a5 | 11801 | kfree_sensitive(connkeys); |
bd2522b1 AZ |
11802 | |
11803 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { | |
11804 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; | |
11805 | if (connect.bssid) | |
11806 | memcpy(dev->ieee80211_ptr->disconnect_bssid, | |
11807 | connect.bssid, ETH_ALEN); | |
11808 | else | |
3b1648f1 | 11809 | eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid); |
bd2522b1 AZ |
11810 | } |
11811 | ||
11812 | wdev_unlock(dev->ieee80211_ptr); | |
11813 | ||
b23aa676 SO |
11814 | return err; |
11815 | } | |
11816 | ||
088e8df8 | 11817 | static int nl80211_update_connect_params(struct sk_buff *skb, |
11818 | struct genl_info *info) | |
11819 | { | |
11820 | struct cfg80211_connect_params connect = {}; | |
11821 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11822 | struct net_device *dev = info->user_ptr[1]; | |
11823 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7f9a3e15 VK |
11824 | bool fils_sk_offload; |
11825 | u32 auth_type; | |
088e8df8 | 11826 | u32 changed = 0; |
11827 | int ret; | |
11828 | ||
11829 | if (!rdev->ops->update_connect_params) | |
11830 | return -EOPNOTSUPP; | |
11831 | ||
11832 | if (info->attrs[NL80211_ATTR_IE]) { | |
088e8df8 | 11833 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
11834 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
11835 | changed |= UPDATE_ASSOC_IES; | |
11836 | } | |
11837 | ||
7f9a3e15 VK |
11838 | fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, |
11839 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); | |
11840 | ||
11841 | /* | |
11842 | * when driver supports fils-sk offload all attributes must be | |
11843 | * provided. So the else covers "fils-sk-not-all" and | |
11844 | * "no-fils-sk-any". | |
11845 | */ | |
11846 | if (fils_sk_offload && | |
11847 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && | |
11848 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && | |
11849 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && | |
11850 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { | |
11851 | connect.fils_erp_username = | |
11852 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); | |
11853 | connect.fils_erp_username_len = | |
11854 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); | |
11855 | connect.fils_erp_realm = | |
11856 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); | |
11857 | connect.fils_erp_realm_len = | |
11858 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); | |
11859 | connect.fils_erp_next_seq_num = | |
11860 | nla_get_u16( | |
11861 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); | |
11862 | connect.fils_erp_rrk = | |
11863 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); | |
11864 | connect.fils_erp_rrk_len = | |
11865 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); | |
11866 | changed |= UPDATE_FILS_ERP_INFO; | |
11867 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || | |
11868 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || | |
11869 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || | |
11870 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { | |
11871 | return -EINVAL; | |
11872 | } | |
11873 | ||
11874 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
11875 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
11876 | if (!nl80211_valid_auth_type(rdev, auth_type, | |
11877 | NL80211_CMD_CONNECT)) | |
11878 | return -EINVAL; | |
11879 | ||
11880 | if (auth_type == NL80211_AUTHTYPE_FILS_SK && | |
11881 | fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) | |
11882 | return -EINVAL; | |
11883 | ||
11884 | connect.auth_type = auth_type; | |
11885 | changed |= UPDATE_AUTH_TYPE; | |
11886 | } | |
11887 | ||
088e8df8 | 11888 | wdev_lock(dev->ieee80211_ptr); |
7b0a0e3c | 11889 | if (!wdev->connected) |
088e8df8 | 11890 | ret = -ENOLINK; |
11891 | else | |
11892 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); | |
11893 | wdev_unlock(dev->ieee80211_ptr); | |
11894 | ||
11895 | return ret; | |
11896 | } | |
11897 | ||
b23aa676 SO |
11898 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
11899 | { | |
4c476991 JB |
11900 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
11901 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 11902 | u16 reason; |
83739b03 | 11903 | int ret; |
b23aa676 | 11904 | |
bad29297 AZ |
11905 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
11906 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) | |
11907 | return -EPERM; | |
11908 | ||
b23aa676 SO |
11909 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
11910 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
11911 | else | |
11912 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
11913 | ||
11914 | if (reason == 0) | |
11915 | return -EINVAL; | |
11916 | ||
074ac8df | 11917 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
11918 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
11919 | return -EOPNOTSUPP; | |
b23aa676 | 11920 | |
83739b03 JB |
11921 | wdev_lock(dev->ieee80211_ptr); |
11922 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
11923 | wdev_unlock(dev->ieee80211_ptr); | |
11924 | return ret; | |
b23aa676 SO |
11925 | } |
11926 | ||
463d0183 JB |
11927 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
11928 | { | |
4c476991 | 11929 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
11930 | struct net *net; |
11931 | int err; | |
463d0183 | 11932 | |
4b681c82 VK |
11933 | if (info->attrs[NL80211_ATTR_PID]) { |
11934 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
11935 | ||
11936 | net = get_net_ns_by_pid(pid); | |
11937 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { | |
11938 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); | |
463d0183 | 11939 | |
4b681c82 VK |
11940 | net = get_net_ns_by_fd(fd); |
11941 | } else { | |
11942 | return -EINVAL; | |
11943 | } | |
463d0183 | 11944 | |
4c476991 JB |
11945 | if (IS_ERR(net)) |
11946 | return PTR_ERR(net); | |
463d0183 JB |
11947 | |
11948 | err = 0; | |
11949 | ||
11950 | /* check if anything to do */ | |
4c476991 JB |
11951 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
11952 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 11953 | |
463d0183 | 11954 | put_net(net); |
463d0183 JB |
11955 | return err; |
11956 | } | |
11957 | ||
67fbb16b SO |
11958 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
11959 | { | |
4c476991 | 11960 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
11961 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
11962 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 11963 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
11964 | struct cfg80211_pmksa pmksa; |
11965 | ||
11966 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
11967 | ||
67fbb16b SO |
11968 | if (!info->attrs[NL80211_ATTR_PMKID]) |
11969 | return -EINVAL; | |
11970 | ||
67fbb16b | 11971 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
a3caf744 VK |
11972 | |
11973 | if (info->attrs[NL80211_ATTR_MAC]) { | |
11974 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
11975 | } else if (info->attrs[NL80211_ATTR_SSID] && | |
11976 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && | |
11977 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || | |
11978 | info->attrs[NL80211_ATTR_PMK])) { | |
11979 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
11980 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
11981 | pmksa.cache_id = | |
11982 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); | |
11983 | } else { | |
11984 | return -EINVAL; | |
11985 | } | |
11986 | if (info->attrs[NL80211_ATTR_PMK]) { | |
11987 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); | |
11988 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); | |
11989 | } | |
67fbb16b | 11990 | |
7fc82af8 VJ |
11991 | if (info->attrs[NL80211_ATTR_PMK_LIFETIME]) |
11992 | pmksa.pmk_lifetime = | |
11993 | nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]); | |
11994 | ||
11995 | if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]) | |
11996 | pmksa.pmk_reauth_threshold = | |
11997 | nla_get_u8( | |
11998 | info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]); | |
11999 | ||
074ac8df | 12000 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
6c900360 LD |
12001 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
12002 | !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP && | |
12003 | wiphy_ext_feature_isset(&rdev->wiphy, | |
12004 | NL80211_EXT_FEATURE_AP_PMKSA_CACHING))) | |
4c476991 | 12005 | return -EOPNOTSUPP; |
67fbb16b SO |
12006 | |
12007 | switch (info->genlhdr->cmd) { | |
12008 | case NL80211_CMD_SET_PMKSA: | |
12009 | rdev_ops = rdev->ops->set_pmksa; | |
12010 | break; | |
12011 | case NL80211_CMD_DEL_PMKSA: | |
12012 | rdev_ops = rdev->ops->del_pmksa; | |
12013 | break; | |
12014 | default: | |
12015 | WARN_ON(1); | |
12016 | break; | |
12017 | } | |
12018 | ||
4c476991 JB |
12019 | if (!rdev_ops) |
12020 | return -EOPNOTSUPP; | |
67fbb16b | 12021 | |
4c476991 | 12022 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
12023 | } |
12024 | ||
12025 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
12026 | { | |
4c476991 JB |
12027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
12028 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 12029 | |
074ac8df | 12030 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
12031 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
12032 | return -EOPNOTSUPP; | |
67fbb16b | 12033 | |
4c476991 JB |
12034 | if (!rdev->ops->flush_pmksa) |
12035 | return -EOPNOTSUPP; | |
67fbb16b | 12036 | |
e35e4d28 | 12037 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
12038 | } |
12039 | ||
109086ce AN |
12040 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
12041 | { | |
12042 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12043 | struct net_device *dev = info->user_ptr[1]; | |
12044 | u8 action_code, dialog_token; | |
df942e7b | 12045 | u32 peer_capability = 0; |
109086ce AN |
12046 | u16 status_code; |
12047 | u8 *peer; | |
31fa97c5 | 12048 | bool initiator; |
109086ce AN |
12049 | |
12050 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
12051 | !rdev->ops->tdls_mgmt) | |
12052 | return -EOPNOTSUPP; | |
12053 | ||
12054 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
12055 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
12056 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
12057 | !info->attrs[NL80211_ATTR_IE] || | |
12058 | !info->attrs[NL80211_ATTR_MAC]) | |
12059 | return -EINVAL; | |
12060 | ||
12061 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
12062 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
12063 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
12064 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 12065 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
12066 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
12067 | peer_capability = | |
12068 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 12069 | |
e35e4d28 | 12070 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 12071 | dialog_token, status_code, peer_capability, |
31fa97c5 | 12072 | initiator, |
e35e4d28 HG |
12073 | nla_data(info->attrs[NL80211_ATTR_IE]), |
12074 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
12075 | } |
12076 | ||
12077 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
12078 | { | |
12079 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12080 | struct net_device *dev = info->user_ptr[1]; | |
12081 | enum nl80211_tdls_operation operation; | |
12082 | u8 *peer; | |
12083 | ||
12084 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
12085 | !rdev->ops->tdls_oper) | |
12086 | return -EOPNOTSUPP; | |
12087 | ||
12088 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
12089 | !info->attrs[NL80211_ATTR_MAC]) | |
12090 | return -EINVAL; | |
12091 | ||
12092 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
12093 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
12094 | ||
e35e4d28 | 12095 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
12096 | } |
12097 | ||
9588bbd5 JM |
12098 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
12099 | struct genl_info *info) | |
12100 | { | |
4c476991 | 12101 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7b0a0e3c | 12102 | unsigned int link_id = nl80211_link_id(info->attrs); |
71bbc994 | 12103 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 12104 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
12105 | struct sk_buff *msg; |
12106 | void *hdr; | |
12107 | u64 cookie; | |
683b6d3b | 12108 | u32 duration; |
9588bbd5 JM |
12109 | int err; |
12110 | ||
12111 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
12112 | !info->attrs[NL80211_ATTR_DURATION]) | |
12113 | return -EINVAL; | |
12114 | ||
12115 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
12116 | ||
ebf348fc JB |
12117 | if (!rdev->ops->remain_on_channel || |
12118 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
12119 | return -EOPNOTSUPP; | |
12120 | ||
9588bbd5 | 12121 | /* |
ebf348fc JB |
12122 | * We should be on that channel for at least a minimum amount of |
12123 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 12124 | */ |
ebf348fc | 12125 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 12126 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
12127 | return -EINVAL; |
12128 | ||
683b6d3b JB |
12129 | err = nl80211_parse_chandef(rdev, info, &chandef); |
12130 | if (err) | |
12131 | return err; | |
9588bbd5 | 12132 | |
34373d12 | 12133 | wdev_lock(wdev); |
7b0a0e3c JB |
12134 | if (!cfg80211_off_channel_oper_allowed(wdev, chandef.chan)) { |
12135 | const struct cfg80211_chan_def *oper_chandef, *compat_chandef; | |
12136 | ||
12137 | oper_chandef = wdev_chandef(wdev, link_id); | |
12138 | ||
12139 | if (WARN_ON(!oper_chandef)) { | |
12140 | /* cannot happen since we must beacon to get here */ | |
12141 | WARN_ON(1); | |
12142 | wdev_unlock(wdev); | |
12143 | return -EBUSY; | |
12144 | } | |
12145 | ||
12146 | /* note: returns first one if identical chandefs */ | |
12147 | compat_chandef = cfg80211_chandef_compatible(&chandef, | |
12148 | oper_chandef); | |
12149 | ||
34373d12 VT |
12150 | if (compat_chandef != &chandef) { |
12151 | wdev_unlock(wdev); | |
12152 | return -EBUSY; | |
12153 | } | |
12154 | } | |
12155 | wdev_unlock(wdev); | |
12156 | ||
9588bbd5 | 12157 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
12158 | if (!msg) |
12159 | return -ENOMEM; | |
9588bbd5 | 12160 | |
15e47304 | 12161 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 12162 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
12163 | if (!hdr) { |
12164 | err = -ENOBUFS; | |
9588bbd5 JM |
12165 | goto free_msg; |
12166 | } | |
12167 | ||
683b6d3b JB |
12168 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
12169 | duration, &cookie); | |
9588bbd5 JM |
12170 | |
12171 | if (err) | |
12172 | goto free_msg; | |
12173 | ||
2dad624e ND |
12174 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
12175 | NL80211_ATTR_PAD)) | |
9360ffd1 | 12176 | goto nla_put_failure; |
9588bbd5 JM |
12177 | |
12178 | genlmsg_end(msg, hdr); | |
4c476991 JB |
12179 | |
12180 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
12181 | |
12182 | nla_put_failure: | |
12183 | err = -ENOBUFS; | |
12184 | free_msg: | |
12185 | nlmsg_free(msg); | |
9588bbd5 JM |
12186 | return err; |
12187 | } | |
12188 | ||
12189 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
12190 | struct genl_info *info) | |
12191 | { | |
4c476991 | 12192 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 12193 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 12194 | u64 cookie; |
9588bbd5 JM |
12195 | |
12196 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
12197 | return -EINVAL; | |
12198 | ||
4c476991 JB |
12199 | if (!rdev->ops->cancel_remain_on_channel) |
12200 | return -EOPNOTSUPP; | |
9588bbd5 | 12201 | |
9588bbd5 JM |
12202 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
12203 | ||
e35e4d28 | 12204 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
12205 | } |
12206 | ||
13ae75b1 JM |
12207 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
12208 | struct genl_info *info) | |
12209 | { | |
13ae75b1 | 12210 | struct cfg80211_bitrate_mask mask; |
7b0a0e3c | 12211 | unsigned int link_id = nl80211_link_id(info->attrs); |
a7c7fbff | 12212 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 12213 | struct net_device *dev = info->user_ptr[1]; |
f971e188 | 12214 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
a7c7fbff | 12215 | int err; |
13ae75b1 | 12216 | |
4c476991 JB |
12217 | if (!rdev->ops->set_bitrate_mask) |
12218 | return -EOPNOTSUPP; | |
13ae75b1 | 12219 | |
f971e188 | 12220 | wdev_lock(wdev); |
9a5f6488 | 12221 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
eb89a6a6 | 12222 | NL80211_ATTR_TX_RATES, &mask, |
7b0a0e3c | 12223 | dev, true, link_id); |
a7c7fbff | 12224 | if (err) |
f971e188 | 12225 | goto out; |
13ae75b1 | 12226 | |
7b0a0e3c | 12227 | err = rdev_set_bitrate_mask(rdev, dev, link_id, NULL, &mask); |
f971e188 JB |
12228 | out: |
12229 | wdev_unlock(wdev); | |
12230 | return err; | |
13ae75b1 JM |
12231 | } |
12232 | ||
2e161f78 | 12233 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 12234 | { |
4c476991 | 12235 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 12236 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 12237 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
12238 | |
12239 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
12240 | return -EINVAL; | |
12241 | ||
2e161f78 JB |
12242 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
12243 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 12244 | |
71bbc994 JB |
12245 | switch (wdev->iftype) { |
12246 | case NL80211_IFTYPE_STATION: | |
12247 | case NL80211_IFTYPE_ADHOC: | |
12248 | case NL80211_IFTYPE_P2P_CLIENT: | |
12249 | case NL80211_IFTYPE_AP: | |
12250 | case NL80211_IFTYPE_AP_VLAN: | |
12251 | case NL80211_IFTYPE_MESH_POINT: | |
12252 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 12253 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 | 12254 | break; |
cb3b7d87 | 12255 | case NL80211_IFTYPE_NAN: |
71bbc994 | 12256 | default: |
4c476991 | 12257 | return -EOPNOTSUPP; |
71bbc994 | 12258 | } |
026331c4 JM |
12259 | |
12260 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
12261 | if (!rdev->ops->mgmt_tx) |
12262 | return -EOPNOTSUPP; | |
026331c4 | 12263 | |
9dba48a6 JB |
12264 | if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] && |
12265 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
12266 | NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) { | |
12267 | GENL_SET_ERR_MSG(info, | |
12268 | "multicast RX registrations are not supported"); | |
12269 | return -EOPNOTSUPP; | |
12270 | } | |
12271 | ||
15e47304 | 12272 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
ff74c51e IP |
12273 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
12274 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]), | |
9dba48a6 | 12275 | info->attrs[NL80211_ATTR_RECEIVE_MULTICAST], |
ff74c51e | 12276 | info->extack); |
026331c4 JM |
12277 | } |
12278 | ||
2e161f78 | 12279 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 12280 | { |
4c476991 | 12281 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 12282 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 12283 | struct cfg80211_chan_def chandef; |
026331c4 | 12284 | int err; |
d64d373f | 12285 | void *hdr = NULL; |
026331c4 | 12286 | u64 cookie; |
e247bd90 | 12287 | struct sk_buff *msg = NULL; |
b176e629 AO |
12288 | struct cfg80211_mgmt_tx_params params = { |
12289 | .dont_wait_for_ack = | |
12290 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
12291 | }; | |
026331c4 | 12292 | |
683b6d3b | 12293 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
12294 | return -EINVAL; |
12295 | ||
4c476991 JB |
12296 | if (!rdev->ops->mgmt_tx) |
12297 | return -EOPNOTSUPP; | |
026331c4 | 12298 | |
71bbc994 | 12299 | switch (wdev->iftype) { |
ea141b75 AQ |
12300 | case NL80211_IFTYPE_P2P_DEVICE: |
12301 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
12302 | return -EINVAL; | |
d7832c71 | 12303 | break; |
71bbc994 JB |
12304 | case NL80211_IFTYPE_STATION: |
12305 | case NL80211_IFTYPE_ADHOC: | |
12306 | case NL80211_IFTYPE_P2P_CLIENT: | |
12307 | case NL80211_IFTYPE_AP: | |
12308 | case NL80211_IFTYPE_AP_VLAN: | |
12309 | case NL80211_IFTYPE_MESH_POINT: | |
12310 | case NL80211_IFTYPE_P2P_GO: | |
12311 | break; | |
cb3b7d87 | 12312 | case NL80211_IFTYPE_NAN: |
71bbc994 | 12313 | default: |
4c476991 | 12314 | return -EOPNOTSUPP; |
71bbc994 | 12315 | } |
026331c4 | 12316 | |
f7ca38df | 12317 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 12318 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 12319 | return -EINVAL; |
b176e629 | 12320 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
12321 | |
12322 | /* | |
12323 | * We should wait on the channel for at least a minimum amount | |
12324 | * of time (10ms) but no longer than the driver supports. | |
12325 | */ | |
b176e629 AO |
12326 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
12327 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc | 12328 | return -EINVAL; |
f7ca38df JB |
12329 | } |
12330 | ||
b176e629 | 12331 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 12332 | |
b176e629 | 12333 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
12334 | return -EINVAL; |
12335 | ||
b176e629 | 12336 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 12337 | |
ea141b75 AQ |
12338 | /* get the channel if any has been specified, otherwise pass NULL to |
12339 | * the driver. The latter will use the current one | |
12340 | */ | |
12341 | chandef.chan = NULL; | |
12342 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
12343 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
12344 | if (err) | |
12345 | return err; | |
12346 | } | |
12347 | ||
b176e629 | 12348 | if (!chandef.chan && params.offchan) |
ea141b75 | 12349 | return -EINVAL; |
026331c4 | 12350 | |
34373d12 | 12351 | wdev_lock(wdev); |
7b0a0e3c JB |
12352 | if (params.offchan && |
12353 | !cfg80211_off_channel_oper_allowed(wdev, chandef.chan)) { | |
34373d12 VT |
12354 | wdev_unlock(wdev); |
12355 | return -EBUSY; | |
12356 | } | |
95f498bb JB |
12357 | |
12358 | params.link_id = nl80211_link_id_or_invalid(info->attrs); | |
12359 | /* | |
12360 | * This now races due to the unlock, but we cannot check | |
12361 | * the valid links for the _station_ anyway, so that's up | |
12362 | * to the driver. | |
12363 | */ | |
12364 | if (params.link_id >= 0 && | |
12365 | !(wdev->valid_links & BIT(params.link_id))) { | |
12366 | wdev_unlock(wdev); | |
12367 | return -EINVAL; | |
12368 | } | |
34373d12 VT |
12369 | wdev_unlock(wdev); |
12370 | ||
34d22ce2 AO |
12371 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
12372 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
12373 | ||
12374 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
12375 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
12376 | int i; | |
12377 | ||
12378 | if (len % sizeof(u16)) | |
12379 | return -EINVAL; | |
12380 | ||
12381 | params.n_csa_offsets = len / sizeof(u16); | |
12382 | params.csa_offsets = | |
12383 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
12384 | ||
12385 | /* check that all the offsets fit the frame */ | |
12386 | for (i = 0; i < params.n_csa_offsets; i++) { | |
12387 | if (params.csa_offsets[i] >= params.len) | |
12388 | return -EINVAL; | |
12389 | } | |
12390 | } | |
12391 | ||
b176e629 | 12392 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
12393 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
12394 | if (!msg) | |
12395 | return -ENOMEM; | |
026331c4 | 12396 | |
15e47304 | 12397 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 12398 | NL80211_CMD_FRAME); |
cb35fba3 DC |
12399 | if (!hdr) { |
12400 | err = -ENOBUFS; | |
e247bd90 JB |
12401 | goto free_msg; |
12402 | } | |
026331c4 | 12403 | } |
e247bd90 | 12404 | |
b176e629 AO |
12405 | params.chan = chandef.chan; |
12406 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
12407 | if (err) |
12408 | goto free_msg; | |
12409 | ||
e247bd90 | 12410 | if (msg) { |
2dad624e ND |
12411 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
12412 | NL80211_ATTR_PAD)) | |
9360ffd1 | 12413 | goto nla_put_failure; |
026331c4 | 12414 | |
e247bd90 JB |
12415 | genlmsg_end(msg, hdr); |
12416 | return genlmsg_reply(msg, info); | |
12417 | } | |
12418 | ||
12419 | return 0; | |
026331c4 JM |
12420 | |
12421 | nla_put_failure: | |
12422 | err = -ENOBUFS; | |
12423 | free_msg: | |
12424 | nlmsg_free(msg); | |
026331c4 JM |
12425 | return err; |
12426 | } | |
12427 | ||
f7ca38df JB |
12428 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
12429 | { | |
12430 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 12431 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
12432 | u64 cookie; |
12433 | ||
12434 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
12435 | return -EINVAL; | |
12436 | ||
12437 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
12438 | return -EOPNOTSUPP; | |
12439 | ||
71bbc994 JB |
12440 | switch (wdev->iftype) { |
12441 | case NL80211_IFTYPE_STATION: | |
12442 | case NL80211_IFTYPE_ADHOC: | |
12443 | case NL80211_IFTYPE_P2P_CLIENT: | |
12444 | case NL80211_IFTYPE_AP: | |
12445 | case NL80211_IFTYPE_AP_VLAN: | |
12446 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 12447 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 | 12448 | break; |
cb3b7d87 | 12449 | case NL80211_IFTYPE_NAN: |
71bbc994 | 12450 | default: |
f7ca38df | 12451 | return -EOPNOTSUPP; |
71bbc994 | 12452 | } |
f7ca38df JB |
12453 | |
12454 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
12455 | ||
e35e4d28 | 12456 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
12457 | } |
12458 | ||
ffb9eb3d KV |
12459 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
12460 | { | |
4c476991 | 12461 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 12462 | struct wireless_dev *wdev; |
4c476991 | 12463 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
12464 | u8 ps_state; |
12465 | bool state; | |
12466 | int err; | |
12467 | ||
4c476991 JB |
12468 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
12469 | return -EINVAL; | |
ffb9eb3d KV |
12470 | |
12471 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
12472 | ||
ffb9eb3d KV |
12473 | wdev = dev->ieee80211_ptr; |
12474 | ||
4c476991 JB |
12475 | if (!rdev->ops->set_power_mgmt) |
12476 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
12477 | |
12478 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
12479 | ||
12480 | if (state == wdev->ps) | |
4c476991 | 12481 | return 0; |
ffb9eb3d | 12482 | |
e35e4d28 | 12483 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
12484 | if (!err) |
12485 | wdev->ps = state; | |
ffb9eb3d KV |
12486 | return err; |
12487 | } | |
12488 | ||
12489 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
12490 | { | |
4c476991 | 12491 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
12492 | enum nl80211_ps_state ps_state; |
12493 | struct wireless_dev *wdev; | |
4c476991 | 12494 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
12495 | struct sk_buff *msg; |
12496 | void *hdr; | |
12497 | int err; | |
12498 | ||
ffb9eb3d KV |
12499 | wdev = dev->ieee80211_ptr; |
12500 | ||
4c476991 JB |
12501 | if (!rdev->ops->set_power_mgmt) |
12502 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
12503 | |
12504 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
12505 | if (!msg) |
12506 | return -ENOMEM; | |
ffb9eb3d | 12507 | |
15e47304 | 12508 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
12509 | NL80211_CMD_GET_POWER_SAVE); |
12510 | if (!hdr) { | |
4c476991 | 12511 | err = -ENOBUFS; |
ffb9eb3d KV |
12512 | goto free_msg; |
12513 | } | |
12514 | ||
12515 | if (wdev->ps) | |
12516 | ps_state = NL80211_PS_ENABLED; | |
12517 | else | |
12518 | ps_state = NL80211_PS_DISABLED; | |
12519 | ||
9360ffd1 DM |
12520 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
12521 | goto nla_put_failure; | |
ffb9eb3d KV |
12522 | |
12523 | genlmsg_end(msg, hdr); | |
4c476991 | 12524 | return genlmsg_reply(msg, info); |
ffb9eb3d | 12525 | |
4c476991 | 12526 | nla_put_failure: |
ffb9eb3d | 12527 | err = -ENOBUFS; |
4c476991 | 12528 | free_msg: |
ffb9eb3d | 12529 | nlmsg_free(msg); |
ffb9eb3d KV |
12530 | return err; |
12531 | } | |
12532 | ||
94e860f1 JB |
12533 | static const struct nla_policy |
12534 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
4a4b8169 | 12535 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, |
d6dc1a38 JO |
12536 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
12537 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
12538 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
12539 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
12540 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
bee427b8 | 12541 | [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, |
d6dc1a38 JO |
12542 | }; |
12543 | ||
84f10708 | 12544 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 12545 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
12546 | { |
12547 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 12548 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 12549 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 12550 | |
d9d8b019 | 12551 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
12552 | return -EINVAL; |
12553 | ||
84f10708 TP |
12554 | if (!rdev->ops->set_cqm_txe_config) |
12555 | return -EOPNOTSUPP; | |
12556 | ||
12557 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
12558 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
12559 | return -EOPNOTSUPP; | |
12560 | ||
e35e4d28 | 12561 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
12562 | } |
12563 | ||
4a4b8169 AZ |
12564 | static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, |
12565 | struct net_device *dev) | |
12566 | { | |
12567 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12568 | s32 last, low, high; | |
12569 | u32 hyst; | |
1222a160 | 12570 | int i, n, low_index; |
4a4b8169 AZ |
12571 | int err; |
12572 | ||
12573 | /* RSSI reporting disabled? */ | |
12574 | if (!wdev->cqm_config) | |
12575 | return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); | |
12576 | ||
12577 | /* | |
12578 | * Obtain current RSSI value if possible, if not and no RSSI threshold | |
12579 | * event has been received yet, we should receive an event after a | |
12580 | * connection is established and enough beacons received to calculate | |
12581 | * the average. | |
12582 | */ | |
7b0a0e3c JB |
12583 | if (!wdev->cqm_config->last_rssi_event_value && |
12584 | wdev->links[0].client.current_bss && | |
4a4b8169 | 12585 | rdev->ops->get_station) { |
73887fd9 | 12586 | struct station_info sinfo = {}; |
4a4b8169 AZ |
12587 | u8 *mac_addr; |
12588 | ||
7b0a0e3c | 12589 | mac_addr = wdev->links[0].client.current_bss->pub.bssid; |
4a4b8169 | 12590 | |
73887fd9 JB |
12591 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
12592 | if (err) | |
4a4b8169 AZ |
12593 | return err; |
12594 | ||
df16737d | 12595 | cfg80211_sinfo_release_content(&sinfo); |
397c657a | 12596 | if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) |
4a4b8169 | 12597 | wdev->cqm_config->last_rssi_event_value = |
73887fd9 | 12598 | (s8) sinfo.rx_beacon_signal_avg; |
4a4b8169 AZ |
12599 | } |
12600 | ||
12601 | last = wdev->cqm_config->last_rssi_event_value; | |
12602 | hyst = wdev->cqm_config->rssi_hyst; | |
12603 | n = wdev->cqm_config->n_rssi_thresholds; | |
12604 | ||
4b2c5a14 MH |
12605 | for (i = 0; i < n; i++) { |
12606 | i = array_index_nospec(i, n); | |
4a4b8169 AZ |
12607 | if (last < wdev->cqm_config->rssi_thresholds[i]) |
12608 | break; | |
4b2c5a14 | 12609 | } |
4a4b8169 | 12610 | |
1222a160 MH |
12611 | low_index = i - 1; |
12612 | if (low_index >= 0) { | |
12613 | low_index = array_index_nospec(low_index, n); | |
12614 | low = wdev->cqm_config->rssi_thresholds[low_index] - hyst; | |
12615 | } else { | |
12616 | low = S32_MIN; | |
12617 | } | |
12618 | if (i < n) { | |
12619 | i = array_index_nospec(i, n); | |
12620 | high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1; | |
12621 | } else { | |
12622 | high = S32_MAX; | |
12623 | } | |
4a4b8169 AZ |
12624 | |
12625 | return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); | |
12626 | } | |
12627 | ||
d6dc1a38 | 12628 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
4a4b8169 AZ |
12629 | const s32 *thresholds, int n_thresholds, |
12630 | u32 hysteresis) | |
d6dc1a38 | 12631 | { |
4c476991 | 12632 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 12633 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 12634 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4a4b8169 AZ |
12635 | int i, err; |
12636 | s32 prev = S32_MIN; | |
d6dc1a38 | 12637 | |
4a4b8169 AZ |
12638 | /* Check all values negative and sorted */ |
12639 | for (i = 0; i < n_thresholds; i++) { | |
12640 | if (thresholds[i] > 0 || thresholds[i] <= prev) | |
12641 | return -EINVAL; | |
d6dc1a38 | 12642 | |
4a4b8169 AZ |
12643 | prev = thresholds[i]; |
12644 | } | |
d6dc1a38 | 12645 | |
074ac8df | 12646 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
12647 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
12648 | return -EOPNOTSUPP; | |
d6dc1a38 | 12649 | |
4a4b8169 AZ |
12650 | wdev_lock(wdev); |
12651 | cfg80211_cqm_config_free(wdev); | |
12652 | wdev_unlock(wdev); | |
12653 | ||
12654 | if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { | |
12655 | if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ | |
12656 | return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); | |
12657 | ||
12658 | return rdev_set_cqm_rssi_config(rdev, dev, | |
12659 | thresholds[0], hysteresis); | |
12660 | } | |
12661 | ||
12662 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
12663 | NL80211_EXT_FEATURE_CQM_RSSI_LIST)) | |
12664 | return -EOPNOTSUPP; | |
12665 | ||
12666 | if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ | |
12667 | n_thresholds = 0; | |
12668 | ||
12669 | wdev_lock(wdev); | |
12670 | if (n_thresholds) { | |
12671 | struct cfg80211_cqm_config *cqm_config; | |
12672 | ||
40f231e7 LB |
12673 | cqm_config = kzalloc(struct_size(cqm_config, rssi_thresholds, |
12674 | n_thresholds), | |
12675 | GFP_KERNEL); | |
4a4b8169 AZ |
12676 | if (!cqm_config) { |
12677 | err = -ENOMEM; | |
12678 | goto unlock; | |
12679 | } | |
12680 | ||
12681 | cqm_config->rssi_hyst = hysteresis; | |
12682 | cqm_config->n_rssi_thresholds = n_thresholds; | |
12683 | memcpy(cqm_config->rssi_thresholds, thresholds, | |
40f231e7 LB |
12684 | flex_array_size(cqm_config, rssi_thresholds, |
12685 | n_thresholds)); | |
4a4b8169 AZ |
12686 | |
12687 | wdev->cqm_config = cqm_config; | |
12688 | } | |
12689 | ||
12690 | err = cfg80211_cqm_rssi_update(rdev, dev); | |
12691 | ||
12692 | unlock: | |
12693 | wdev_unlock(wdev); | |
12694 | ||
12695 | return err; | |
d6dc1a38 JO |
12696 | } |
12697 | ||
12698 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
12699 | { | |
12700 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
12701 | struct nlattr *cqm; | |
12702 | int err; | |
12703 | ||
12704 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
12705 | if (!cqm) |
12706 | return -EINVAL; | |
d6dc1a38 | 12707 | |
8cb08174 JB |
12708 | err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm, |
12709 | nl80211_attr_cqm_policy, | |
12710 | info->extack); | |
d6dc1a38 | 12711 | if (err) |
1da5fcc8 | 12712 | return err; |
d6dc1a38 JO |
12713 | |
12714 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
12715 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
4a4b8169 AZ |
12716 | const s32 *thresholds = |
12717 | nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
12718 | int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
1da5fcc8 | 12719 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
d6dc1a38 | 12720 | |
4a4b8169 AZ |
12721 | if (len % 4) |
12722 | return -EINVAL; | |
12723 | ||
12724 | return nl80211_set_cqm_rssi(info, thresholds, len / 4, | |
12725 | hysteresis); | |
1da5fcc8 JB |
12726 | } |
12727 | ||
12728 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
12729 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
12730 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
12731 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
12732 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
12733 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
12734 | ||
12735 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
12736 | } | |
12737 | ||
12738 | return -EINVAL; | |
d6dc1a38 JO |
12739 | } |
12740 | ||
6e0bd6c3 RL |
12741 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
12742 | { | |
12743 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12744 | struct net_device *dev = info->user_ptr[1]; | |
12745 | struct ocb_setup setup = {}; | |
12746 | int err; | |
12747 | ||
12748 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | |
12749 | if (err) | |
12750 | return err; | |
12751 | ||
12752 | return cfg80211_join_ocb(rdev, dev, &setup); | |
12753 | } | |
12754 | ||
12755 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | |
12756 | { | |
12757 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12758 | struct net_device *dev = info->user_ptr[1]; | |
12759 | ||
12760 | return cfg80211_leave_ocb(rdev, dev); | |
12761 | } | |
12762 | ||
29cbe68c JB |
12763 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
12764 | { | |
12765 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12766 | struct net_device *dev = info->user_ptr[1]; | |
12767 | struct mesh_config cfg; | |
c80d545d | 12768 | struct mesh_setup setup; |
29cbe68c JB |
12769 | int err; |
12770 | ||
12771 | /* start with default */ | |
12772 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 12773 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 12774 | |
24bdd9f4 | 12775 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 12776 | /* and parse parameters if given */ |
24bdd9f4 | 12777 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
12778 | if (err) |
12779 | return err; | |
12780 | } | |
12781 | ||
12782 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
12783 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
12784 | return -EINVAL; | |
12785 | ||
c80d545d JC |
12786 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
12787 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
12788 | ||
4bb62344 CYY |
12789 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
12790 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
12791 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
12792 | return -EINVAL; | |
12793 | ||
9bdbf04d MP |
12794 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
12795 | setup.beacon_interval = | |
12796 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
12d20fc9 | 12797 | |
0c317a02 PK |
12798 | err = cfg80211_validate_beacon_int(rdev, |
12799 | NL80211_IFTYPE_MESH_POINT, | |
12800 | setup.beacon_interval); | |
12d20fc9 PK |
12801 | if (err) |
12802 | return err; | |
9bdbf04d MP |
12803 | } |
12804 | ||
12805 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
12806 | setup.dtim_period = | |
12807 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
12808 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
12809 | return -EINVAL; | |
12810 | } | |
12811 | ||
c80d545d JC |
12812 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
12813 | /* parse additional setup parameters if given */ | |
12814 | err = nl80211_parse_mesh_setup(info, &setup); | |
12815 | if (err) | |
12816 | return err; | |
12817 | } | |
12818 | ||
d37bb18a TP |
12819 | if (setup.user_mpm) |
12820 | cfg.auto_open_plinks = false; | |
12821 | ||
cc1d2806 | 12822 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
12823 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
12824 | if (err) | |
12825 | return err; | |
cc1d2806 | 12826 | } else { |
188c1b3c | 12827 | /* __cfg80211_join_mesh() will sort it out */ |
683b6d3b | 12828 | setup.chandef.chan = NULL; |
cc1d2806 JB |
12829 | } |
12830 | ||
ffb3cf30 AN |
12831 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
12832 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
12833 | int n_rates = | |
12834 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
12835 | struct ieee80211_supported_band *sband; | |
12836 | ||
12837 | if (!setup.chandef.chan) | |
12838 | return -EINVAL; | |
12839 | ||
12840 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
12841 | ||
12842 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
12843 | &setup.basic_rates); | |
12844 | if (err) | |
12845 | return err; | |
12846 | } | |
12847 | ||
8564e382 | 12848 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
9a5f6488 TC |
12849 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
12850 | NL80211_ATTR_TX_RATES, | |
eb89a6a6 | 12851 | &setup.beacon_rate, |
7b0a0e3c | 12852 | dev, false, 0); |
8564e382 JB |
12853 | if (err) |
12854 | return err; | |
12855 | ||
265698d7 JB |
12856 | if (!setup.chandef.chan) |
12857 | return -EINVAL; | |
12858 | ||
8564e382 JB |
12859 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
12860 | &setup.beacon_rate); | |
12861 | if (err) | |
12862 | return err; | |
12863 | } | |
12864 | ||
d37d49c2 BB |
12865 | setup.userspace_handles_dfs = |
12866 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
12867 | ||
1224f583 DK |
12868 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
12869 | int r = validate_pae_over_nl80211(rdev, info); | |
12870 | ||
12871 | if (r < 0) | |
12872 | return r; | |
12873 | ||
12874 | setup.control_port_over_nl80211 = true; | |
12875 | } | |
12876 | ||
188c1b3c DK |
12877 | wdev_lock(dev->ieee80211_ptr); |
12878 | err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); | |
12879 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) | |
12880 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; | |
12881 | wdev_unlock(dev->ieee80211_ptr); | |
12882 | ||
12883 | return err; | |
29cbe68c JB |
12884 | } |
12885 | ||
12886 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
12887 | { | |
12888 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12889 | struct net_device *dev = info->user_ptr[1]; | |
12890 | ||
12891 | return cfg80211_leave_mesh(rdev, dev); | |
12892 | } | |
12893 | ||
dfb89c56 | 12894 | #ifdef CONFIG_PM |
bb92d199 AK |
12895 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
12896 | struct cfg80211_registered_device *rdev) | |
12897 | { | |
6abb9cb9 | 12898 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
12899 | struct nlattr *nl_pats, *nl_pat; |
12900 | int i, pat_len; | |
12901 | ||
6abb9cb9 | 12902 | if (!wowlan->n_patterns) |
bb92d199 AK |
12903 | return 0; |
12904 | ||
ae0be8de | 12905 | nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
bb92d199 AK |
12906 | if (!nl_pats) |
12907 | return -ENOBUFS; | |
12908 | ||
6abb9cb9 | 12909 | for (i = 0; i < wowlan->n_patterns; i++) { |
ae0be8de | 12910 | nl_pat = nla_nest_start_noflag(msg, i + 1); |
bb92d199 AK |
12911 | if (!nl_pat) |
12912 | return -ENOBUFS; | |
6abb9cb9 | 12913 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 12914 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 12915 | wowlan->patterns[i].mask) || |
50ac6607 AK |
12916 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
12917 | wowlan->patterns[i].pattern) || | |
12918 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 12919 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
12920 | return -ENOBUFS; |
12921 | nla_nest_end(msg, nl_pat); | |
12922 | } | |
12923 | nla_nest_end(msg, nl_pats); | |
12924 | ||
12925 | return 0; | |
12926 | } | |
12927 | ||
2a0e047e JB |
12928 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
12929 | struct cfg80211_wowlan_tcp *tcp) | |
12930 | { | |
12931 | struct nlattr *nl_tcp; | |
12932 | ||
12933 | if (!tcp) | |
12934 | return 0; | |
12935 | ||
ae0be8de MK |
12936 | nl_tcp = nla_nest_start_noflag(msg, |
12937 | NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
2a0e047e JB |
12938 | if (!nl_tcp) |
12939 | return -ENOBUFS; | |
12940 | ||
930345ea JB |
12941 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
12942 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
2a0e047e JB |
12943 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
12944 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
12945 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
12946 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
12947 | tcp->payload_len, tcp->payload) || | |
12948 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
12949 | tcp->data_interval) || | |
12950 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
12951 | tcp->wake_len, tcp->wake_data) || | |
12952 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
12953 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
12954 | return -ENOBUFS; | |
12955 | ||
12956 | if (tcp->payload_seq.len && | |
12957 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
12958 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
12959 | return -ENOBUFS; | |
12960 | ||
12961 | if (tcp->payload_tok.len && | |
12962 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
12963 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
12964 | &tcp->payload_tok)) | |
12965 | return -ENOBUFS; | |
12966 | ||
e248ad30 JB |
12967 | nla_nest_end(msg, nl_tcp); |
12968 | ||
2a0e047e JB |
12969 | return 0; |
12970 | } | |
12971 | ||
75453ccb LC |
12972 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
12973 | struct cfg80211_sched_scan_request *req) | |
12974 | { | |
3b06d277 | 12975 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
75453ccb LC |
12976 | int i; |
12977 | ||
12978 | if (!req) | |
12979 | return 0; | |
12980 | ||
ae0be8de | 12981 | nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
75453ccb LC |
12982 | if (!nd) |
12983 | return -ENOBUFS; | |
12984 | ||
3b06d277 AS |
12985 | if (req->n_scan_plans == 1 && |
12986 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, | |
12987 | req->scan_plans[0].interval * 1000)) | |
75453ccb LC |
12988 | return -ENOBUFS; |
12989 | ||
21fea567 LC |
12990 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
12991 | return -ENOBUFS; | |
12992 | ||
bf95ecdb | 12993 | if (req->relative_rssi_set) { |
12994 | struct nl80211_bss_select_rssi_adjust rssi_adjust; | |
12995 | ||
12996 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, | |
12997 | req->relative_rssi)) | |
12998 | return -ENOBUFS; | |
12999 | ||
13000 | rssi_adjust.band = req->rssi_adjust.band; | |
13001 | rssi_adjust.delta = req->rssi_adjust.delta; | |
13002 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, | |
13003 | sizeof(rssi_adjust), &rssi_adjust)) | |
13004 | return -ENOBUFS; | |
13005 | } | |
13006 | ||
ae0be8de | 13007 | freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
75453ccb LC |
13008 | if (!freqs) |
13009 | return -ENOBUFS; | |
13010 | ||
53b18980 JB |
13011 | for (i = 0; i < req->n_channels; i++) { |
13012 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
13013 | return -ENOBUFS; | |
13014 | } | |
75453ccb LC |
13015 | |
13016 | nla_nest_end(msg, freqs); | |
13017 | ||
13018 | if (req->n_match_sets) { | |
ae0be8de MK |
13019 | matches = nla_nest_start_noflag(msg, |
13020 | NL80211_ATTR_SCHED_SCAN_MATCH); | |
76e1fb4b JB |
13021 | if (!matches) |
13022 | return -ENOBUFS; | |
13023 | ||
75453ccb | 13024 | for (i = 0; i < req->n_match_sets; i++) { |
ae0be8de | 13025 | match = nla_nest_start_noflag(msg, i); |
76e1fb4b JB |
13026 | if (!match) |
13027 | return -ENOBUFS; | |
13028 | ||
53b18980 JB |
13029 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
13030 | req->match_sets[i].ssid.ssid_len, | |
13031 | req->match_sets[i].ssid.ssid)) | |
13032 | return -ENOBUFS; | |
75453ccb LC |
13033 | nla_nest_end(msg, match); |
13034 | } | |
13035 | nla_nest_end(msg, matches); | |
13036 | } | |
13037 | ||
ae0be8de | 13038 | scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
3b06d277 AS |
13039 | if (!scan_plans) |
13040 | return -ENOBUFS; | |
13041 | ||
13042 | for (i = 0; i < req->n_scan_plans; i++) { | |
ae0be8de | 13043 | scan_plan = nla_nest_start_noflag(msg, i + 1); |
76e1fb4b JB |
13044 | if (!scan_plan) |
13045 | return -ENOBUFS; | |
13046 | ||
67626964 | 13047 | if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
3b06d277 AS |
13048 | req->scan_plans[i].interval) || |
13049 | (req->scan_plans[i].iterations && | |
13050 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, | |
13051 | req->scan_plans[i].iterations))) | |
13052 | return -ENOBUFS; | |
13053 | nla_nest_end(msg, scan_plan); | |
13054 | } | |
13055 | nla_nest_end(msg, scan_plans); | |
13056 | ||
75453ccb LC |
13057 | nla_nest_end(msg, nd); |
13058 | ||
13059 | return 0; | |
13060 | } | |
13061 | ||
ff1b6e69 JB |
13062 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
13063 | { | |
13064 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13065 | struct sk_buff *msg; | |
13066 | void *hdr; | |
2a0e047e | 13067 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 13068 | |
964dc9e2 | 13069 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
13070 | return -EOPNOTSUPP; |
13071 | ||
6abb9cb9 | 13072 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 13073 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
13074 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
13075 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
13076 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
13077 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
13078 | } |
13079 | ||
13080 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
13081 | if (!msg) |
13082 | return -ENOMEM; | |
13083 | ||
15e47304 | 13084 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
13085 | NL80211_CMD_GET_WOWLAN); |
13086 | if (!hdr) | |
13087 | goto nla_put_failure; | |
13088 | ||
6abb9cb9 | 13089 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
13090 | struct nlattr *nl_wowlan; |
13091 | ||
ae0be8de MK |
13092 | nl_wowlan = nla_nest_start_noflag(msg, |
13093 | NL80211_ATTR_WOWLAN_TRIGGERS); | |
ff1b6e69 JB |
13094 | if (!nl_wowlan) |
13095 | goto nla_put_failure; | |
13096 | ||
6abb9cb9 | 13097 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 13098 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 13099 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 13100 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 13101 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 13102 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 13103 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 13104 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 13105 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 13106 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 13107 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 13108 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 13109 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
13110 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
13111 | goto nla_put_failure; | |
2a0e047e | 13112 | |
bb92d199 AK |
13113 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
13114 | goto nla_put_failure; | |
2a0e047e | 13115 | |
6abb9cb9 JB |
13116 | if (nl80211_send_wowlan_tcp(msg, |
13117 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e | 13118 | goto nla_put_failure; |
75453ccb LC |
13119 | |
13120 | if (nl80211_send_wowlan_nd( | |
13121 | msg, | |
13122 | rdev->wiphy.wowlan_config->nd_config)) | |
13123 | goto nla_put_failure; | |
2a0e047e | 13124 | |
ff1b6e69 JB |
13125 | nla_nest_end(msg, nl_wowlan); |
13126 | } | |
13127 | ||
13128 | genlmsg_end(msg, hdr); | |
13129 | return genlmsg_reply(msg, info); | |
13130 | ||
13131 | nla_put_failure: | |
13132 | nlmsg_free(msg); | |
13133 | return -ENOBUFS; | |
13134 | } | |
13135 | ||
2a0e047e JB |
13136 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
13137 | struct nlattr *attr, | |
13138 | struct cfg80211_wowlan *trig) | |
13139 | { | |
13140 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
13141 | struct cfg80211_wowlan_tcp *cfg; | |
13142 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
13143 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
13144 | u32 size; | |
13145 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
13146 | int err, port; | |
13147 | ||
964dc9e2 | 13148 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
13149 | return -EINVAL; |
13150 | ||
8cb08174 JB |
13151 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr, |
13152 | nl80211_wowlan_tcp_policy, NULL); | |
2a0e047e JB |
13153 | if (err) |
13154 | return err; | |
13155 | ||
13156 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
13157 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
13158 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
13159 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
13160 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
13161 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
13162 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
13163 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
13164 | return -EINVAL; | |
13165 | ||
13166 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 13167 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
13168 | return -EINVAL; |
13169 | ||
13170 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 13171 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 13172 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
13173 | return -EINVAL; |
13174 | ||
13175 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 13176 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
13177 | return -EINVAL; |
13178 | ||
13179 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
13180 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
13181 | return -EINVAL; | |
13182 | ||
13183 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
13184 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
13185 | ||
13186 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
13187 | tokens_size = tokln - sizeof(*tok); | |
13188 | ||
13189 | if (!tok->len || tokens_size % tok->len) | |
13190 | return -EINVAL; | |
964dc9e2 | 13191 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 13192 | return -EINVAL; |
964dc9e2 | 13193 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 13194 | return -EINVAL; |
964dc9e2 | 13195 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 13196 | return -EINVAL; |
964dc9e2 | 13197 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
13198 | return -EINVAL; |
13199 | if (tok->offset + tok->len > data_size) | |
13200 | return -EINVAL; | |
13201 | } | |
13202 | ||
13203 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
13204 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 13205 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
13206 | return -EINVAL; |
13207 | if (seq->len == 0 || seq->len > 4) | |
13208 | return -EINVAL; | |
13209 | if (seq->len + seq->offset > data_size) | |
13210 | return -EINVAL; | |
13211 | } | |
13212 | ||
13213 | size = sizeof(*cfg); | |
13214 | size += data_size; | |
13215 | size += wake_size + wake_mask_size; | |
13216 | size += tokens_size; | |
13217 | ||
13218 | cfg = kzalloc(size, GFP_KERNEL); | |
13219 | if (!cfg) | |
13220 | return -ENOMEM; | |
67b61f6c JB |
13221 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
13222 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
2a0e047e JB |
13223 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
13224 | ETH_ALEN); | |
13225 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
13226 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
13227 | else | |
13228 | port = 0; | |
13229 | #ifdef CONFIG_INET | |
13230 | /* allocate a socket and port for it and use it */ | |
13231 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
13232 | IPPROTO_TCP, &cfg->sock, 1); | |
13233 | if (err) { | |
13234 | kfree(cfg); | |
13235 | return err; | |
13236 | } | |
13237 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
13238 | sock_release(cfg->sock); | |
13239 | kfree(cfg); | |
13240 | return -EADDRINUSE; | |
13241 | } | |
13242 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
13243 | #else | |
13244 | if (!port) { | |
13245 | kfree(cfg); | |
13246 | return -EINVAL; | |
13247 | } | |
13248 | cfg->src_port = port; | |
13249 | #endif | |
13250 | ||
13251 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
13252 | cfg->payload_len = data_size; | |
13253 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
13254 | memcpy((void *)cfg->payload, | |
13255 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
13256 | data_size); | |
13257 | if (seq) | |
13258 | cfg->payload_seq = *seq; | |
13259 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
13260 | cfg->wake_len = wake_size; | |
13261 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
13262 | memcpy((void *)cfg->wake_data, | |
13263 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
13264 | wake_size); | |
13265 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
13266 | data_size + wake_size; | |
13267 | memcpy((void *)cfg->wake_mask, | |
13268 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
13269 | wake_mask_size); | |
13270 | if (tok) { | |
13271 | cfg->tokens_size = tokens_size; | |
10d5ea5a KC |
13272 | cfg->payload_tok = *tok; |
13273 | memcpy(cfg->payload_tok.token_stream, tok->token_stream, | |
13274 | tokens_size); | |
2a0e047e JB |
13275 | } |
13276 | ||
13277 | trig->tcp = cfg; | |
13278 | ||
13279 | return 0; | |
13280 | } | |
13281 | ||
8cd4d456 LC |
13282 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
13283 | const struct wiphy_wowlan_support *wowlan, | |
13284 | struct nlattr *attr, | |
13285 | struct cfg80211_wowlan *trig) | |
13286 | { | |
13287 | struct nlattr **tb; | |
13288 | int err; | |
13289 | ||
6396bb22 | 13290 | tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
8cd4d456 LC |
13291 | if (!tb) |
13292 | return -ENOMEM; | |
13293 | ||
13294 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | |
13295 | err = -EOPNOTSUPP; | |
13296 | goto out; | |
13297 | } | |
13298 | ||
8cb08174 JB |
13299 | err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr, |
13300 | nl80211_policy, NULL); | |
8cd4d456 LC |
13301 | if (err) |
13302 | goto out; | |
13303 | ||
aad1e812 AVS |
13304 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, |
13305 | wowlan->max_nd_match_sets); | |
8cd4d456 LC |
13306 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
13307 | if (err) | |
13308 | trig->nd_config = NULL; | |
13309 | ||
13310 | out: | |
13311 | kfree(tb); | |
13312 | return err; | |
13313 | } | |
13314 | ||
ff1b6e69 JB |
13315 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
13316 | { | |
13317 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13318 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 13319 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 13320 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 13321 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 13322 | int err, i; |
6abb9cb9 | 13323 | bool prev_enabled = rdev->wiphy.wowlan_config; |
98fc4386 | 13324 | bool regular = false; |
ff1b6e69 | 13325 | |
964dc9e2 | 13326 | if (!wowlan) |
ff1b6e69 JB |
13327 | return -EOPNOTSUPP; |
13328 | ||
ae33bd81 JB |
13329 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
13330 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 13331 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
13332 | goto set_wakeup; |
13333 | } | |
ff1b6e69 | 13334 | |
8cb08174 JB |
13335 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG, |
13336 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], | |
13337 | nl80211_wowlan_policy, info->extack); | |
ff1b6e69 JB |
13338 | if (err) |
13339 | return err; | |
13340 | ||
13341 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
13342 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
13343 | return -EINVAL; | |
13344 | new_triggers.any = true; | |
13345 | } | |
13346 | ||
13347 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
13348 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
13349 | return -EINVAL; | |
13350 | new_triggers.disconnect = true; | |
98fc4386 | 13351 | regular = true; |
ff1b6e69 JB |
13352 | } |
13353 | ||
13354 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
13355 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
13356 | return -EINVAL; | |
13357 | new_triggers.magic_pkt = true; | |
98fc4386 | 13358 | regular = true; |
ff1b6e69 JB |
13359 | } |
13360 | ||
77dbbb13 JB |
13361 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
13362 | return -EINVAL; | |
13363 | ||
13364 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
13365 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
13366 | return -EINVAL; | |
13367 | new_triggers.gtk_rekey_failure = true; | |
98fc4386 | 13368 | regular = true; |
77dbbb13 JB |
13369 | } |
13370 | ||
13371 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
13372 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
13373 | return -EINVAL; | |
13374 | new_triggers.eap_identity_req = true; | |
98fc4386 | 13375 | regular = true; |
77dbbb13 JB |
13376 | } |
13377 | ||
13378 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
13379 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
13380 | return -EINVAL; | |
13381 | new_triggers.four_way_handshake = true; | |
98fc4386 | 13382 | regular = true; |
77dbbb13 JB |
13383 | } |
13384 | ||
13385 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
13386 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
13387 | return -EINVAL; | |
13388 | new_triggers.rfkill_release = true; | |
98fc4386 | 13389 | regular = true; |
77dbbb13 JB |
13390 | } |
13391 | ||
ff1b6e69 JB |
13392 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
13393 | struct nlattr *pat; | |
13394 | int n_patterns = 0; | |
bb92d199 | 13395 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 13396 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 | 13397 | |
98fc4386 JB |
13398 | regular = true; |
13399 | ||
ff1b6e69 JB |
13400 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
13401 | rem) | |
13402 | n_patterns++; | |
13403 | if (n_patterns > wowlan->n_patterns) | |
13404 | return -EINVAL; | |
13405 | ||
13406 | new_triggers.patterns = kcalloc(n_patterns, | |
13407 | sizeof(new_triggers.patterns[0]), | |
13408 | GFP_KERNEL); | |
13409 | if (!new_triggers.patterns) | |
13410 | return -ENOMEM; | |
13411 | ||
13412 | new_triggers.n_patterns = n_patterns; | |
13413 | i = 0; | |
13414 | ||
13415 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
13416 | rem) { | |
922bd80f JB |
13417 | u8 *mask_pat; |
13418 | ||
8cb08174 JB |
13419 | err = nla_parse_nested_deprecated(pat_tb, |
13420 | MAX_NL80211_PKTPAT, | |
13421 | pat, | |
13422 | nl80211_packet_pattern_policy, | |
13423 | info->extack); | |
95bca62f JB |
13424 | if (err) |
13425 | goto error; | |
13426 | ||
ff1b6e69 | 13427 | err = -EINVAL; |
50ac6607 AK |
13428 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
13429 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 13430 | goto error; |
50ac6607 | 13431 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 13432 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 13433 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
13434 | goto error; |
13435 | if (pat_len > wowlan->pattern_max_len || | |
13436 | pat_len < wowlan->pattern_min_len) | |
13437 | goto error; | |
13438 | ||
50ac6607 | 13439 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
13440 | pkt_offset = 0; |
13441 | else | |
13442 | pkt_offset = nla_get_u32( | |
50ac6607 | 13443 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
13444 | if (pkt_offset > wowlan->max_pkt_offset) |
13445 | goto error; | |
13446 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
13447 | ||
922bd80f JB |
13448 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
13449 | if (!mask_pat) { | |
ff1b6e69 JB |
13450 | err = -ENOMEM; |
13451 | goto error; | |
13452 | } | |
922bd80f JB |
13453 | new_triggers.patterns[i].mask = mask_pat; |
13454 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 13455 | mask_len); |
922bd80f JB |
13456 | mask_pat += mask_len; |
13457 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 13458 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 13459 | memcpy(mask_pat, |
50ac6607 | 13460 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
13461 | pat_len); |
13462 | i++; | |
13463 | } | |
13464 | } | |
13465 | ||
2a0e047e | 13466 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
98fc4386 | 13467 | regular = true; |
2a0e047e JB |
13468 | err = nl80211_parse_wowlan_tcp( |
13469 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
13470 | &new_triggers); | |
13471 | if (err) | |
13472 | goto error; | |
13473 | } | |
13474 | ||
8cd4d456 | 13475 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
98fc4386 | 13476 | regular = true; |
8cd4d456 LC |
13477 | err = nl80211_parse_wowlan_nd( |
13478 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | |
13479 | &new_triggers); | |
13480 | if (err) | |
13481 | goto error; | |
13482 | } | |
13483 | ||
98fc4386 JB |
13484 | /* The 'any' trigger means the device continues operating more or less |
13485 | * as in its normal operation mode and wakes up the host on most of the | |
13486 | * normal interrupts (like packet RX, ...) | |
13487 | * It therefore makes little sense to combine with the more constrained | |
13488 | * wakeup trigger modes. | |
13489 | */ | |
13490 | if (new_triggers.any && regular) { | |
13491 | err = -EINVAL; | |
13492 | goto error; | |
13493 | } | |
13494 | ||
ae33bd81 JB |
13495 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
13496 | if (!ntrig) { | |
13497 | err = -ENOMEM; | |
13498 | goto error; | |
ff1b6e69 | 13499 | } |
ae33bd81 | 13500 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 13501 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 13502 | |
ae33bd81 | 13503 | set_wakeup: |
6abb9cb9 JB |
13504 | if (rdev->ops->set_wakeup && |
13505 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
13506 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 13507 | |
ff1b6e69 JB |
13508 | return 0; |
13509 | error: | |
13510 | for (i = 0; i < new_triggers.n_patterns; i++) | |
13511 | kfree(new_triggers.patterns[i].mask); | |
13512 | kfree(new_triggers.patterns); | |
2a0e047e JB |
13513 | if (new_triggers.tcp && new_triggers.tcp->sock) |
13514 | sock_release(new_triggers.tcp->sock); | |
13515 | kfree(new_triggers.tcp); | |
e5dbe070 | 13516 | kfree(new_triggers.nd_config); |
ff1b6e69 JB |
13517 | return err; |
13518 | } | |
dfb89c56 | 13519 | #endif |
ff1b6e69 | 13520 | |
be29b99a AK |
13521 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
13522 | struct cfg80211_registered_device *rdev) | |
13523 | { | |
13524 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
13525 | int i, j, pat_len; | |
13526 | struct cfg80211_coalesce_rules *rule; | |
13527 | ||
13528 | if (!rdev->coalesce->n_rules) | |
13529 | return 0; | |
13530 | ||
ae0be8de | 13531 | nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE); |
be29b99a AK |
13532 | if (!nl_rules) |
13533 | return -ENOBUFS; | |
13534 | ||
13535 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
ae0be8de | 13536 | nl_rule = nla_nest_start_noflag(msg, i + 1); |
be29b99a AK |
13537 | if (!nl_rule) |
13538 | return -ENOBUFS; | |
13539 | ||
13540 | rule = &rdev->coalesce->rules[i]; | |
13541 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
13542 | rule->delay)) | |
13543 | return -ENOBUFS; | |
13544 | ||
13545 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
13546 | rule->condition)) | |
13547 | return -ENOBUFS; | |
13548 | ||
ae0be8de MK |
13549 | nl_pats = nla_nest_start_noflag(msg, |
13550 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
be29b99a AK |
13551 | if (!nl_pats) |
13552 | return -ENOBUFS; | |
13553 | ||
13554 | for (j = 0; j < rule->n_patterns; j++) { | |
ae0be8de | 13555 | nl_pat = nla_nest_start_noflag(msg, j + 1); |
be29b99a AK |
13556 | if (!nl_pat) |
13557 | return -ENOBUFS; | |
13558 | pat_len = rule->patterns[j].pattern_len; | |
13559 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
13560 | DIV_ROUND_UP(pat_len, 8), | |
13561 | rule->patterns[j].mask) || | |
13562 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
13563 | rule->patterns[j].pattern) || | |
13564 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
13565 | rule->patterns[j].pkt_offset)) | |
13566 | return -ENOBUFS; | |
13567 | nla_nest_end(msg, nl_pat); | |
13568 | } | |
13569 | nla_nest_end(msg, nl_pats); | |
13570 | nla_nest_end(msg, nl_rule); | |
13571 | } | |
13572 | nla_nest_end(msg, nl_rules); | |
13573 | ||
13574 | return 0; | |
13575 | } | |
13576 | ||
13577 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
13578 | { | |
13579 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13580 | struct sk_buff *msg; | |
13581 | void *hdr; | |
13582 | ||
13583 | if (!rdev->wiphy.coalesce) | |
13584 | return -EOPNOTSUPP; | |
13585 | ||
13586 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
13587 | if (!msg) | |
13588 | return -ENOMEM; | |
13589 | ||
13590 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
13591 | NL80211_CMD_GET_COALESCE); | |
13592 | if (!hdr) | |
13593 | goto nla_put_failure; | |
13594 | ||
13595 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
13596 | goto nla_put_failure; | |
13597 | ||
13598 | genlmsg_end(msg, hdr); | |
13599 | return genlmsg_reply(msg, info); | |
13600 | ||
13601 | nla_put_failure: | |
13602 | nlmsg_free(msg); | |
13603 | return -ENOBUFS; | |
13604 | } | |
13605 | ||
13606 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
13607 | { | |
13608 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
13609 | int i, j; | |
13610 | struct cfg80211_coalesce_rules *rule; | |
13611 | ||
13612 | if (!coalesce) | |
13613 | return; | |
13614 | ||
13615 | for (i = 0; i < coalesce->n_rules; i++) { | |
13616 | rule = &coalesce->rules[i]; | |
13617 | for (j = 0; j < rule->n_patterns; j++) | |
13618 | kfree(rule->patterns[j].mask); | |
13619 | kfree(rule->patterns); | |
13620 | } | |
13621 | kfree(coalesce->rules); | |
13622 | kfree(coalesce); | |
13623 | rdev->coalesce = NULL; | |
13624 | } | |
13625 | ||
13626 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
13627 | struct nlattr *rule, | |
13628 | struct cfg80211_coalesce_rules *new_rule) | |
13629 | { | |
13630 | int err, i; | |
13631 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
13632 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
13633 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
13634 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
13635 | ||
8cb08174 JB |
13636 | err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX, |
13637 | rule, nl80211_coalesce_policy, NULL); | |
be29b99a AK |
13638 | if (err) |
13639 | return err; | |
13640 | ||
13641 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
13642 | new_rule->delay = | |
13643 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
13644 | if (new_rule->delay > coalesce->max_delay) | |
13645 | return -EINVAL; | |
13646 | ||
13647 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
13648 | new_rule->condition = | |
13649 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
be29b99a AK |
13650 | |
13651 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
13652 | return -EINVAL; | |
13653 | ||
13654 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
13655 | rem) | |
13656 | n_patterns++; | |
13657 | if (n_patterns > coalesce->n_patterns) | |
13658 | return -EINVAL; | |
13659 | ||
13660 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
13661 | GFP_KERNEL); | |
13662 | if (!new_rule->patterns) | |
13663 | return -ENOMEM; | |
13664 | ||
13665 | new_rule->n_patterns = n_patterns; | |
13666 | i = 0; | |
13667 | ||
13668 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
13669 | rem) { | |
922bd80f JB |
13670 | u8 *mask_pat; |
13671 | ||
8cb08174 JB |
13672 | err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT, |
13673 | pat, | |
13674 | nl80211_packet_pattern_policy, | |
13675 | NULL); | |
95bca62f JB |
13676 | if (err) |
13677 | return err; | |
13678 | ||
be29b99a AK |
13679 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
13680 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
13681 | return -EINVAL; | |
13682 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
13683 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
13684 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
13685 | return -EINVAL; | |
13686 | if (pat_len > coalesce->pattern_max_len || | |
13687 | pat_len < coalesce->pattern_min_len) | |
13688 | return -EINVAL; | |
13689 | ||
13690 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
13691 | pkt_offset = 0; | |
13692 | else | |
13693 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
13694 | if (pkt_offset > coalesce->max_pkt_offset) | |
13695 | return -EINVAL; | |
13696 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
13697 | ||
922bd80f JB |
13698 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
13699 | if (!mask_pat) | |
be29b99a | 13700 | return -ENOMEM; |
922bd80f JB |
13701 | |
13702 | new_rule->patterns[i].mask = mask_pat; | |
13703 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
13704 | mask_len); | |
13705 | ||
13706 | mask_pat += mask_len; | |
13707 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 13708 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
13709 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
13710 | pat_len); | |
be29b99a AK |
13711 | i++; |
13712 | } | |
13713 | ||
13714 | return 0; | |
13715 | } | |
13716 | ||
13717 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
13718 | { | |
13719 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13720 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
13721 | struct cfg80211_coalesce new_coalesce = {}; | |
13722 | struct cfg80211_coalesce *n_coalesce; | |
13723 | int err, rem_rule, n_rules = 0, i, j; | |
13724 | struct nlattr *rule; | |
13725 | struct cfg80211_coalesce_rules *tmp_rule; | |
13726 | ||
13727 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
13728 | return -EOPNOTSUPP; | |
13729 | ||
13730 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
13731 | cfg80211_rdev_free_coalesce(rdev); | |
a1056b1b | 13732 | rdev_set_coalesce(rdev, NULL); |
be29b99a AK |
13733 | return 0; |
13734 | } | |
13735 | ||
13736 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
13737 | rem_rule) | |
13738 | n_rules++; | |
13739 | if (n_rules > coalesce->n_rules) | |
13740 | return -EINVAL; | |
13741 | ||
13742 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
13743 | GFP_KERNEL); | |
13744 | if (!new_coalesce.rules) | |
13745 | return -ENOMEM; | |
13746 | ||
13747 | new_coalesce.n_rules = n_rules; | |
13748 | i = 0; | |
13749 | ||
13750 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
13751 | rem_rule) { | |
13752 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
13753 | &new_coalesce.rules[i]); | |
13754 | if (err) | |
13755 | goto error; | |
13756 | ||
13757 | i++; | |
13758 | } | |
13759 | ||
a1056b1b | 13760 | err = rdev_set_coalesce(rdev, &new_coalesce); |
be29b99a AK |
13761 | if (err) |
13762 | goto error; | |
13763 | ||
13764 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
13765 | if (!n_coalesce) { | |
13766 | err = -ENOMEM; | |
13767 | goto error; | |
13768 | } | |
13769 | cfg80211_rdev_free_coalesce(rdev); | |
13770 | rdev->coalesce = n_coalesce; | |
13771 | ||
13772 | return 0; | |
13773 | error: | |
13774 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
13775 | tmp_rule = &new_coalesce.rules[i]; | |
13776 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
13777 | kfree(tmp_rule->patterns[j].mask); | |
13778 | kfree(tmp_rule->patterns); | |
13779 | } | |
13780 | kfree(new_coalesce.rules); | |
13781 | ||
13782 | return err; | |
13783 | } | |
13784 | ||
e5497d76 JB |
13785 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
13786 | { | |
13787 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13788 | struct net_device *dev = info->user_ptr[1]; | |
13789 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13790 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
f495acd8 | 13791 | struct cfg80211_gtk_rekey_data rekey_data = {}; |
e5497d76 JB |
13792 | int err; |
13793 | ||
13794 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
13795 | return -EINVAL; | |
13796 | ||
8cb08174 JB |
13797 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA, |
13798 | info->attrs[NL80211_ATTR_REKEY_DATA], | |
13799 | nl80211_rekey_policy, info->extack); | |
e5497d76 JB |
13800 | if (err) |
13801 | return err; | |
13802 | ||
e785fa0a VD |
13803 | if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || |
13804 | !tb[NL80211_REKEY_DATA_KCK]) | |
13805 | return -EINVAL; | |
093a48d2 NE |
13806 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN && |
13807 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && | |
13808 | nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN)) | |
e5497d76 | 13809 | return -ERANGE; |
093a48d2 NE |
13810 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN && |
13811 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && | |
13812 | nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KCK_EXT_LEN)) | |
e5497d76 JB |
13813 | return -ERANGE; |
13814 | ||
78f686ca JB |
13815 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
13816 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
13817 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
093a48d2 NE |
13818 | rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]); |
13819 | rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]); | |
13820 | if (tb[NL80211_REKEY_DATA_AKM]) | |
13821 | rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]); | |
e5497d76 JB |
13822 | |
13823 | wdev_lock(wdev); | |
7b0a0e3c | 13824 | if (!wdev->connected) { |
e5497d76 JB |
13825 | err = -ENOTCONN; |
13826 | goto out; | |
13827 | } | |
13828 | ||
13829 | if (!rdev->ops->set_rekey_data) { | |
13830 | err = -EOPNOTSUPP; | |
13831 | goto out; | |
13832 | } | |
13833 | ||
e35e4d28 | 13834 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
13835 | out: |
13836 | wdev_unlock(wdev); | |
13837 | return err; | |
13838 | } | |
13839 | ||
28946da7 JB |
13840 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
13841 | struct genl_info *info) | |
13842 | { | |
13843 | struct net_device *dev = info->user_ptr[1]; | |
13844 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13845 | ||
13846 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
13847 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
13848 | return -EINVAL; | |
13849 | ||
15e47304 | 13850 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
13851 | return -EBUSY; |
13852 | ||
15e47304 | 13853 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
13854 | return 0; |
13855 | } | |
13856 | ||
7f6cf311 JB |
13857 | static int nl80211_probe_client(struct sk_buff *skb, |
13858 | struct genl_info *info) | |
13859 | { | |
13860 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13861 | struct net_device *dev = info->user_ptr[1]; | |
13862 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13863 | struct sk_buff *msg; | |
13864 | void *hdr; | |
13865 | const u8 *addr; | |
13866 | u64 cookie; | |
13867 | int err; | |
13868 | ||
13869 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
13870 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
13871 | return -EOPNOTSUPP; | |
13872 | ||
13873 | if (!info->attrs[NL80211_ATTR_MAC]) | |
13874 | return -EINVAL; | |
13875 | ||
13876 | if (!rdev->ops->probe_client) | |
13877 | return -EOPNOTSUPP; | |
13878 | ||
13879 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
13880 | if (!msg) | |
13881 | return -ENOMEM; | |
13882 | ||
15e47304 | 13883 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 13884 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
13885 | if (!hdr) { |
13886 | err = -ENOBUFS; | |
7f6cf311 JB |
13887 | goto free_msg; |
13888 | } | |
13889 | ||
13890 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
13891 | ||
e35e4d28 | 13892 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
13893 | if (err) |
13894 | goto free_msg; | |
13895 | ||
2dad624e ND |
13896 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
13897 | NL80211_ATTR_PAD)) | |
9360ffd1 | 13898 | goto nla_put_failure; |
7f6cf311 JB |
13899 | |
13900 | genlmsg_end(msg, hdr); | |
13901 | ||
13902 | return genlmsg_reply(msg, info); | |
13903 | ||
13904 | nla_put_failure: | |
13905 | err = -ENOBUFS; | |
13906 | free_msg: | |
13907 | nlmsg_free(msg); | |
13908 | return err; | |
13909 | } | |
13910 | ||
5e760230 JB |
13911 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
13912 | { | |
13913 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
13914 | struct cfg80211_beacon_registration *reg, *nreg; |
13915 | int rv; | |
5e760230 JB |
13916 | |
13917 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
13918 | return -EOPNOTSUPP; | |
13919 | ||
37c73b5f BG |
13920 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
13921 | if (!nreg) | |
13922 | return -ENOMEM; | |
13923 | ||
13924 | /* First, check if already registered. */ | |
13925 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
13926 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
13927 | if (reg->nlportid == info->snd_portid) { | |
13928 | rv = -EALREADY; | |
13929 | goto out_err; | |
13930 | } | |
13931 | } | |
13932 | /* Add it to the list */ | |
13933 | nreg->nlportid = info->snd_portid; | |
13934 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 13935 | |
37c73b5f | 13936 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
13937 | |
13938 | return 0; | |
37c73b5f BG |
13939 | out_err: |
13940 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
13941 | kfree(nreg); | |
13942 | return rv; | |
5e760230 JB |
13943 | } |
13944 | ||
98104fde JB |
13945 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
13946 | { | |
13947 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13948 | struct wireless_dev *wdev = info->user_ptr[1]; | |
13949 | int err; | |
13950 | ||
13951 | if (!rdev->ops->start_p2p_device) | |
13952 | return -EOPNOTSUPP; | |
13953 | ||
13954 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
13955 | return -EOPNOTSUPP; | |
13956 | ||
73c7da3d | 13957 | if (wdev_running(wdev)) |
98104fde JB |
13958 | return 0; |
13959 | ||
358ae888 | 13960 | if (rfkill_blocked(rdev->wiphy.rfkill)) |
b6a55015 | 13961 | return -ERFKILL; |
98104fde | 13962 | |
eeb126e9 | 13963 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
13964 | if (err) |
13965 | return err; | |
13966 | ||
73c7da3d | 13967 | wdev->is_running = true; |
98104fde | 13968 | rdev->opencount++; |
98104fde JB |
13969 | |
13970 | return 0; | |
13971 | } | |
13972 | ||
13973 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
13974 | { | |
13975 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13976 | struct wireless_dev *wdev = info->user_ptr[1]; | |
13977 | ||
13978 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
13979 | return -EOPNOTSUPP; | |
13980 | ||
13981 | if (!rdev->ops->stop_p2p_device) | |
13982 | return -EOPNOTSUPP; | |
13983 | ||
f9f47529 | 13984 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
13985 | |
13986 | return 0; | |
13987 | } | |
13988 | ||
cb3b7d87 AB |
13989 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
13990 | { | |
13991 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
13992 | struct wireless_dev *wdev = info->user_ptr[1]; | |
13993 | struct cfg80211_nan_conf conf = {}; | |
13994 | int err; | |
13995 | ||
13996 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
13997 | return -EOPNOTSUPP; | |
13998 | ||
eeb04a96 | 13999 | if (wdev_running(wdev)) |
cb3b7d87 AB |
14000 | return -EEXIST; |
14001 | ||
358ae888 | 14002 | if (rfkill_blocked(rdev->wiphy.rfkill)) |
cb3b7d87 AB |
14003 | return -ERFKILL; |
14004 | ||
14005 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) | |
14006 | return -EINVAL; | |
14007 | ||
cb3b7d87 AB |
14008 | conf.master_pref = |
14009 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); | |
cb3b7d87 | 14010 | |
8585989d LC |
14011 | if (info->attrs[NL80211_ATTR_BANDS]) { |
14012 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); | |
14013 | ||
14014 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) | |
14015 | return -EOPNOTSUPP; | |
14016 | ||
14017 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) | |
14018 | return -EINVAL; | |
14019 | ||
14020 | conf.bands = bands; | |
14021 | } | |
cb3b7d87 AB |
14022 | |
14023 | err = rdev_start_nan(rdev, wdev, &conf); | |
14024 | if (err) | |
14025 | return err; | |
14026 | ||
73c7da3d | 14027 | wdev->is_running = true; |
cb3b7d87 AB |
14028 | rdev->opencount++; |
14029 | ||
14030 | return 0; | |
14031 | } | |
14032 | ||
14033 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) | |
14034 | { | |
14035 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
14036 | struct wireless_dev *wdev = info->user_ptr[1]; | |
14037 | ||
14038 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
14039 | return -EOPNOTSUPP; | |
14040 | ||
14041 | cfg80211_stop_nan(rdev, wdev); | |
14042 | ||
14043 | return 0; | |
14044 | } | |
14045 | ||
a442b761 AB |
14046 | static int validate_nan_filter(struct nlattr *filter_attr) |
14047 | { | |
14048 | struct nlattr *attr; | |
14049 | int len = 0, n_entries = 0, rem; | |
14050 | ||
14051 | nla_for_each_nested(attr, filter_attr, rem) { | |
14052 | len += nla_len(attr); | |
14053 | n_entries++; | |
14054 | } | |
14055 | ||
14056 | if (len >= U8_MAX) | |
14057 | return -EINVAL; | |
14058 | ||
14059 | return n_entries; | |
14060 | } | |
14061 | ||
14062 | static int handle_nan_filter(struct nlattr *attr_filter, | |
14063 | struct cfg80211_nan_func *func, | |
14064 | bool tx) | |
14065 | { | |
14066 | struct nlattr *attr; | |
14067 | int n_entries, rem, i; | |
14068 | struct cfg80211_nan_func_filter *filter; | |
14069 | ||
14070 | n_entries = validate_nan_filter(attr_filter); | |
14071 | if (n_entries < 0) | |
14072 | return n_entries; | |
14073 | ||
14074 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); | |
14075 | ||
14076 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); | |
14077 | if (!filter) | |
14078 | return -ENOMEM; | |
14079 | ||
14080 | i = 0; | |
14081 | nla_for_each_nested(attr, attr_filter, rem) { | |
b15ca182 | 14082 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); |
6ad27f52 JJ |
14083 | if (!filter[i].filter) |
14084 | goto err; | |
14085 | ||
a442b761 AB |
14086 | filter[i].len = nla_len(attr); |
14087 | i++; | |
14088 | } | |
14089 | if (tx) { | |
14090 | func->num_tx_filters = n_entries; | |
14091 | func->tx_filters = filter; | |
14092 | } else { | |
14093 | func->num_rx_filters = n_entries; | |
14094 | func->rx_filters = filter; | |
14095 | } | |
14096 | ||
14097 | return 0; | |
6ad27f52 JJ |
14098 | |
14099 | err: | |
14100 | i = 0; | |
14101 | nla_for_each_nested(attr, attr_filter, rem) { | |
14102 | kfree(filter[i].filter); | |
14103 | i++; | |
14104 | } | |
14105 | kfree(filter); | |
14106 | return -ENOMEM; | |
a442b761 AB |
14107 | } |
14108 | ||
14109 | static int nl80211_nan_add_func(struct sk_buff *skb, | |
14110 | struct genl_info *info) | |
14111 | { | |
14112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
14113 | struct wireless_dev *wdev = info->user_ptr[1]; | |
14114 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; | |
14115 | struct cfg80211_nan_func *func; | |
14116 | struct sk_buff *msg = NULL; | |
14117 | void *hdr = NULL; | |
14118 | int err = 0; | |
14119 | ||
14120 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
14121 | return -EOPNOTSUPP; | |
14122 | ||
73c7da3d | 14123 | if (!wdev_running(wdev)) |
a442b761 AB |
14124 | return -ENOTCONN; |
14125 | ||
14126 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) | |
14127 | return -EINVAL; | |
14128 | ||
8cb08174 JB |
14129 | err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX, |
14130 | info->attrs[NL80211_ATTR_NAN_FUNC], | |
14131 | nl80211_nan_func_policy, | |
14132 | info->extack); | |
a442b761 AB |
14133 | if (err) |
14134 | return err; | |
14135 | ||
14136 | func = kzalloc(sizeof(*func), GFP_KERNEL); | |
14137 | if (!func) | |
14138 | return -ENOMEM; | |
14139 | ||
b60ad348 | 14140 | func->cookie = cfg80211_assign_cookie(rdev); |
a442b761 | 14141 | |
cb9abd48 | 14142 | if (!tb[NL80211_NAN_FUNC_TYPE]) { |
a442b761 AB |
14143 | err = -EINVAL; |
14144 | goto out; | |
14145 | } | |
14146 | ||
14147 | ||
14148 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); | |
14149 | ||
14150 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { | |
14151 | err = -EINVAL; | |
14152 | goto out; | |
14153 | } | |
14154 | ||
14155 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), | |
14156 | sizeof(func->service_id)); | |
14157 | ||
14158 | func->close_range = | |
14159 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); | |
14160 | ||
14161 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { | |
14162 | func->serv_spec_info_len = | |
14163 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); | |
14164 | func->serv_spec_info = | |
14165 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), | |
14166 | func->serv_spec_info_len, | |
14167 | GFP_KERNEL); | |
14168 | if (!func->serv_spec_info) { | |
14169 | err = -ENOMEM; | |
14170 | goto out; | |
14171 | } | |
14172 | } | |
14173 | ||
14174 | if (tb[NL80211_NAN_FUNC_TTL]) | |
14175 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); | |
14176 | ||
14177 | switch (func->type) { | |
14178 | case NL80211_NAN_FUNC_PUBLISH: | |
14179 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { | |
14180 | err = -EINVAL; | |
14181 | goto out; | |
14182 | } | |
14183 | ||
14184 | func->publish_type = | |
14185 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); | |
14186 | func->publish_bcast = | |
14187 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); | |
14188 | ||
14189 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && | |
14190 | func->publish_bcast) { | |
14191 | err = -EINVAL; | |
14192 | goto out; | |
14193 | } | |
14194 | break; | |
14195 | case NL80211_NAN_FUNC_SUBSCRIBE: | |
14196 | func->subscribe_active = | |
14197 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); | |
14198 | break; | |
14199 | case NL80211_NAN_FUNC_FOLLOW_UP: | |
14200 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || | |
3ea15452 HC |
14201 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || |
14202 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { | |
a442b761 AB |
14203 | err = -EINVAL; |
14204 | goto out; | |
14205 | } | |
14206 | ||
14207 | func->followup_id = | |
14208 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); | |
14209 | func->followup_reqid = | |
14210 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); | |
14211 | memcpy(func->followup_dest.addr, | |
14212 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), | |
14213 | sizeof(func->followup_dest.addr)); | |
14214 | if (func->ttl) { | |
14215 | err = -EINVAL; | |
14216 | goto out; | |
14217 | } | |
14218 | break; | |
14219 | default: | |
14220 | err = -EINVAL; | |
14221 | goto out; | |
14222 | } | |
14223 | ||
14224 | if (tb[NL80211_NAN_FUNC_SRF]) { | |
14225 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; | |
14226 | ||
8cb08174 JB |
14227 | err = nla_parse_nested_deprecated(srf_tb, |
14228 | NL80211_NAN_SRF_ATTR_MAX, | |
14229 | tb[NL80211_NAN_FUNC_SRF], | |
14230 | nl80211_nan_srf_policy, | |
14231 | info->extack); | |
a442b761 AB |
14232 | if (err) |
14233 | goto out; | |
14234 | ||
14235 | func->srf_include = | |
14236 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); | |
14237 | ||
14238 | if (srf_tb[NL80211_NAN_SRF_BF]) { | |
14239 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || | |
14240 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { | |
14241 | err = -EINVAL; | |
14242 | goto out; | |
14243 | } | |
14244 | ||
14245 | func->srf_bf_len = | |
14246 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); | |
14247 | func->srf_bf = | |
14248 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), | |
14249 | func->srf_bf_len, GFP_KERNEL); | |
14250 | if (!func->srf_bf) { | |
14251 | err = -ENOMEM; | |
14252 | goto out; | |
14253 | } | |
14254 | ||
14255 | func->srf_bf_idx = | |
14256 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); | |
14257 | } else { | |
14258 | struct nlattr *attr, *mac_attr = | |
14259 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; | |
14260 | int n_entries, rem, i = 0; | |
14261 | ||
14262 | if (!mac_attr) { | |
14263 | err = -EINVAL; | |
14264 | goto out; | |
14265 | } | |
14266 | ||
14267 | n_entries = validate_acl_mac_addrs(mac_attr); | |
14268 | if (n_entries <= 0) { | |
14269 | err = -EINVAL; | |
14270 | goto out; | |
14271 | } | |
14272 | ||
14273 | func->srf_num_macs = n_entries; | |
14274 | func->srf_macs = | |
6396bb22 | 14275 | kcalloc(n_entries, sizeof(*func->srf_macs), |
a442b761 AB |
14276 | GFP_KERNEL); |
14277 | if (!func->srf_macs) { | |
14278 | err = -ENOMEM; | |
14279 | goto out; | |
14280 | } | |
14281 | ||
14282 | nla_for_each_nested(attr, mac_attr, rem) | |
14283 | memcpy(func->srf_macs[i++].addr, nla_data(attr), | |
14284 | sizeof(*func->srf_macs)); | |
14285 | } | |
14286 | } | |
14287 | ||
14288 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { | |
14289 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], | |
14290 | func, true); | |
14291 | if (err) | |
14292 | goto out; | |
14293 | } | |
14294 | ||
14295 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { | |
14296 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], | |
14297 | func, false); | |
14298 | if (err) | |
14299 | goto out; | |
14300 | } | |
14301 | ||
14302 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
14303 | if (!msg) { | |
14304 | err = -ENOMEM; | |
14305 | goto out; | |
14306 | } | |
14307 | ||
14308 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
14309 | NL80211_CMD_ADD_NAN_FUNCTION); | |
14310 | /* This can't really happen - we just allocated 4KB */ | |
14311 | if (WARN_ON(!hdr)) { | |
14312 | err = -ENOMEM; | |
14313 | goto out; | |
14314 | } | |
14315 | ||
14316 | err = rdev_add_nan_func(rdev, wdev, func); | |
14317 | out: | |
14318 | if (err < 0) { | |
14319 | cfg80211_free_nan_func(func); | |
14320 | nlmsg_free(msg); | |
14321 | return err; | |
14322 | } | |
14323 | ||
14324 | /* propagate the instance id and cookie to userspace */ | |
14325 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, | |
14326 | NL80211_ATTR_PAD)) | |
14327 | goto nla_put_failure; | |
14328 | ||
ae0be8de | 14329 | func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); |
a442b761 AB |
14330 | if (!func_attr) |
14331 | goto nla_put_failure; | |
14332 | ||
14333 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, | |
14334 | func->instance_id)) | |
14335 | goto nla_put_failure; | |
14336 | ||
14337 | nla_nest_end(msg, func_attr); | |
14338 | ||
14339 | genlmsg_end(msg, hdr); | |
14340 | return genlmsg_reply(msg, info); | |
14341 | ||
14342 | nla_put_failure: | |
14343 | nlmsg_free(msg); | |
14344 | return -ENOBUFS; | |
14345 | } | |
14346 | ||
14347 | static int nl80211_nan_del_func(struct sk_buff *skb, | |
14348 | struct genl_info *info) | |
14349 | { | |
14350 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
14351 | struct wireless_dev *wdev = info->user_ptr[1]; | |
14352 | u64 cookie; | |
14353 | ||
14354 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
14355 | return -EOPNOTSUPP; | |
14356 | ||
73c7da3d | 14357 | if (!wdev_running(wdev)) |
a442b761 AB |
14358 | return -ENOTCONN; |
14359 | ||
14360 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
14361 | return -EINVAL; | |
14362 | ||
a442b761 AB |
14363 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
14364 | ||
14365 | rdev_del_nan_func(rdev, wdev, cookie); | |
14366 | ||
14367 | return 0; | |
14368 | } | |
14369 | ||
a5a9dcf2 AB |
14370 | static int nl80211_nan_change_config(struct sk_buff *skb, |
14371 | struct genl_info *info) | |
14372 | { | |
14373 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
14374 | struct wireless_dev *wdev = info->user_ptr[1]; | |
14375 | struct cfg80211_nan_conf conf = {}; | |
14376 | u32 changed = 0; | |
14377 | ||
14378 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
14379 | return -EOPNOTSUPP; | |
14380 | ||
73c7da3d | 14381 | if (!wdev_running(wdev)) |
a5a9dcf2 AB |
14382 | return -ENOTCONN; |
14383 | ||
14384 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { | |
14385 | conf.master_pref = | |
14386 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); | |
14387 | if (conf.master_pref <= 1 || conf.master_pref == 255) | |
14388 | return -EINVAL; | |
14389 | ||
14390 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; | |
14391 | } | |
14392 | ||
8585989d LC |
14393 | if (info->attrs[NL80211_ATTR_BANDS]) { |
14394 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); | |
14395 | ||
14396 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) | |
14397 | return -EOPNOTSUPP; | |
14398 | ||
14399 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) | |
14400 | return -EINVAL; | |
14401 | ||
14402 | conf.bands = bands; | |
14403 | changed |= CFG80211_NAN_CONF_CHANGED_BANDS; | |
a5a9dcf2 AB |
14404 | } |
14405 | ||
14406 | if (!changed) | |
14407 | return -EINVAL; | |
14408 | ||
14409 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); | |
14410 | } | |
14411 | ||
50bcd31d AB |
14412 | void cfg80211_nan_match(struct wireless_dev *wdev, |
14413 | struct cfg80211_nan_match_params *match, gfp_t gfp) | |
14414 | { | |
14415 | struct wiphy *wiphy = wdev->wiphy; | |
14416 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
14417 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; | |
14418 | struct sk_buff *msg; | |
14419 | void *hdr; | |
14420 | ||
14421 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) | |
14422 | return; | |
14423 | ||
14424 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
14425 | if (!msg) | |
14426 | return; | |
14427 | ||
14428 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); | |
14429 | if (!hdr) { | |
14430 | nlmsg_free(msg); | |
14431 | return; | |
14432 | } | |
14433 | ||
14434 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
14435 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
14436 | wdev->netdev->ifindex)) || | |
14437 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | |
14438 | NL80211_ATTR_PAD)) | |
14439 | goto nla_put_failure; | |
14440 | ||
14441 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, | |
14442 | NL80211_ATTR_PAD) || | |
14443 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) | |
14444 | goto nla_put_failure; | |
14445 | ||
ae0be8de | 14446 | match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH); |
50bcd31d AB |
14447 | if (!match_attr) |
14448 | goto nla_put_failure; | |
14449 | ||
ae0be8de MK |
14450 | local_func_attr = nla_nest_start_noflag(msg, |
14451 | NL80211_NAN_MATCH_FUNC_LOCAL); | |
50bcd31d AB |
14452 | if (!local_func_attr) |
14453 | goto nla_put_failure; | |
14454 | ||
14455 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) | |
14456 | goto nla_put_failure; | |
14457 | ||
14458 | nla_nest_end(msg, local_func_attr); | |
14459 | ||
ae0be8de MK |
14460 | peer_func_attr = nla_nest_start_noflag(msg, |
14461 | NL80211_NAN_MATCH_FUNC_PEER); | |
50bcd31d AB |
14462 | if (!peer_func_attr) |
14463 | goto nla_put_failure; | |
14464 | ||
14465 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || | |
14466 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) | |
14467 | goto nla_put_failure; | |
14468 | ||
14469 | if (match->info && match->info_len && | |
14470 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, | |
14471 | match->info)) | |
14472 | goto nla_put_failure; | |
14473 | ||
14474 | nla_nest_end(msg, peer_func_attr); | |
14475 | nla_nest_end(msg, match_attr); | |
14476 | genlmsg_end(msg, hdr); | |
14477 | ||
14478 | if (!wdev->owner_nlportid) | |
14479 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
14480 | msg, 0, NL80211_MCGRP_NAN, gfp); | |
14481 | else | |
14482 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, | |
14483 | wdev->owner_nlportid); | |
14484 | ||
14485 | return; | |
14486 | ||
14487 | nla_put_failure: | |
14488 | nlmsg_free(msg); | |
14489 | } | |
14490 | EXPORT_SYMBOL(cfg80211_nan_match); | |
14491 | ||
368e5a7b AB |
14492 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
14493 | u8 inst_id, | |
14494 | enum nl80211_nan_func_term_reason reason, | |
14495 | u64 cookie, gfp_t gfp) | |
14496 | { | |
14497 | struct wiphy *wiphy = wdev->wiphy; | |
14498 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
14499 | struct sk_buff *msg; | |
14500 | struct nlattr *func_attr; | |
14501 | void *hdr; | |
14502 | ||
14503 | if (WARN_ON(!inst_id)) | |
14504 | return; | |
14505 | ||
14506 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
14507 | if (!msg) | |
14508 | return; | |
14509 | ||
14510 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); | |
14511 | if (!hdr) { | |
14512 | nlmsg_free(msg); | |
14513 | return; | |
14514 | } | |
14515 | ||
14516 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
14517 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
14518 | wdev->netdev->ifindex)) || | |
14519 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | |
14520 | NL80211_ATTR_PAD)) | |
14521 | goto nla_put_failure; | |
14522 | ||
14523 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, | |
14524 | NL80211_ATTR_PAD)) | |
14525 | goto nla_put_failure; | |
14526 | ||
ae0be8de | 14527 | func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); |
368e5a7b AB |
14528 | if (!func_attr) |
14529 | goto nla_put_failure; | |
14530 | ||
14531 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || | |
14532 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) | |
14533 | goto nla_put_failure; | |
14534 | ||
14535 | nla_nest_end(msg, func_attr); | |
14536 | genlmsg_end(msg, hdr); | |
14537 | ||
14538 | if (!wdev->owner_nlportid) | |
14539 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
14540 | msg, 0, NL80211_MCGRP_NAN, gfp); | |
14541 | else | |
14542 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, | |
14543 | wdev->owner_nlportid); | |
14544 | ||
14545 | return; | |
14546 | ||
14547 | nla_put_failure: | |
14548 | nlmsg_free(msg); | |
14549 | } | |
14550 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); | |
14551 | ||
3713b4e3 JB |
14552 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
14553 | struct genl_info *info) | |
14554 | { | |
14555 | void *hdr; | |
14556 | struct sk_buff *msg; | |
14557 | ||
14558 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
14559 | if (!msg) | |
14560 | return -ENOMEM; | |
14561 | ||
14562 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
14563 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
14564 | if (!hdr) | |
14565 | goto nla_put_failure; | |
14566 | ||
14567 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
14568 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
14569 | goto nla_put_failure; | |
14570 | ||
14571 | genlmsg_end(msg, hdr); | |
14572 | return genlmsg_reply(msg, info); | |
14573 | ||
14574 | nla_put_failure: | |
14575 | kfree_skb(msg); | |
14576 | return -ENOBUFS; | |
14577 | } | |
14578 | ||
355199e0 JM |
14579 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
14580 | { | |
14581 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
14582 | struct cfg80211_update_ft_ies_params ft_params; | |
14583 | struct net_device *dev = info->user_ptr[1]; | |
14584 | ||
14585 | if (!rdev->ops->update_ft_ies) | |
14586 | return -EOPNOTSUPP; | |
14587 | ||
14588 | if (!info->attrs[NL80211_ATTR_MDID] || | |
3d7af878 | 14589 | !info->attrs[NL80211_ATTR_IE]) |
355199e0 JM |
14590 | return -EINVAL; |
14591 | ||
14592 | memset(&ft_params, 0, sizeof(ft_params)); | |
14593 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
14594 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
14595 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
14596 | ||
14597 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
14598 | } | |
14599 | ||
5de17984 AS |
14600 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
14601 | struct genl_info *info) | |
14602 | { | |
14603 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
14604 | struct wireless_dev *wdev = info->user_ptr[1]; | |
14605 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
14606 | u16 duration; | |
14607 | int ret; | |
14608 | ||
14609 | if (!rdev->ops->crit_proto_start) | |
14610 | return -EOPNOTSUPP; | |
14611 | ||
14612 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
14613 | return -EINVAL; | |
14614 | ||
14615 | if (rdev->crit_proto_nlportid) | |
14616 | return -EBUSY; | |
14617 | ||
14618 | /* determine protocol if provided */ | |
14619 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
14620 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
14621 | ||
14622 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
14623 | return -EINVAL; | |
14624 | ||
14625 | /* timeout must be provided */ | |
14626 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
14627 | return -EINVAL; | |
14628 | ||
14629 | duration = | |
14630 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
14631 | ||
5de17984 AS |
14632 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
14633 | if (!ret) | |
14634 | rdev->crit_proto_nlportid = info->snd_portid; | |
14635 | ||
14636 | return ret; | |
14637 | } | |
14638 | ||
14639 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
14640 | struct genl_info *info) | |
14641 | { | |
14642 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
14643 | struct wireless_dev *wdev = info->user_ptr[1]; | |
14644 | ||
14645 | if (!rdev->ops->crit_proto_stop) | |
14646 | return -EOPNOTSUPP; | |
14647 | ||
14648 | if (rdev->crit_proto_nlportid) { | |
14649 | rdev->crit_proto_nlportid = 0; | |
14650 | rdev_crit_proto_stop(rdev, wdev); | |
14651 | } | |
14652 | return 0; | |
14653 | } | |
14654 | ||
901bb989 JB |
14655 | static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd, |
14656 | struct nlattr *attr, | |
14657 | struct netlink_ext_ack *extack) | |
14658 | { | |
14659 | if (vcmd->policy == VENDOR_CMD_RAW_DATA) { | |
14660 | if (attr->nla_type & NLA_F_NESTED) { | |
14661 | NL_SET_ERR_MSG_ATTR(extack, attr, | |
14662 | "unexpected nested data"); | |
14663 | return -EINVAL; | |
14664 | } | |
14665 | ||
14666 | return 0; | |
14667 | } | |
14668 | ||
14669 | if (!(attr->nla_type & NLA_F_NESTED)) { | |
14670 | NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data"); | |
14671 | return -EINVAL; | |
14672 | } | |
14673 | ||
32d5109a | 14674 | return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack); |
901bb989 JB |
14675 | } |
14676 | ||
ad7e718c JB |
14677 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
14678 | { | |
14679 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
14680 | struct wireless_dev *wdev = | |
a05829a7 JB |
14681 | __cfg80211_wdev_from_attrs(rdev, genl_info_net(info), |
14682 | info->attrs); | |
ad7e718c JB |
14683 | int i, err; |
14684 | u32 vid, subcmd; | |
14685 | ||
14686 | if (!rdev->wiphy.vendor_commands) | |
14687 | return -EOPNOTSUPP; | |
14688 | ||
14689 | if (IS_ERR(wdev)) { | |
14690 | err = PTR_ERR(wdev); | |
14691 | if (err != -EINVAL) | |
14692 | return err; | |
14693 | wdev = NULL; | |
14694 | } else if (wdev->wiphy != &rdev->wiphy) { | |
14695 | return -EINVAL; | |
14696 | } | |
14697 | ||
14698 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
14699 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
14700 | return -EINVAL; | |
14701 | ||
14702 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
14703 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
14704 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
14705 | const struct wiphy_vendor_command *vcmd; | |
14706 | void *data = NULL; | |
14707 | int len = 0; | |
14708 | ||
14709 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
14710 | ||
14711 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
14712 | continue; | |
14713 | ||
14714 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
14715 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
14716 | if (!wdev) | |
14717 | return -EINVAL; | |
14718 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
14719 | !wdev->netdev) | |
14720 | return -EINVAL; | |
14721 | ||
14722 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
73c7da3d | 14723 | if (!wdev_running(wdev)) |
ad7e718c JB |
14724 | return -ENETDOWN; |
14725 | } | |
14726 | } else { | |
14727 | wdev = NULL; | |
14728 | } | |
14729 | ||
4052d3d2 JS |
14730 | if (!vcmd->doit) |
14731 | return -EOPNOTSUPP; | |
14732 | ||
ad7e718c JB |
14733 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
14734 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
14735 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
901bb989 JB |
14736 | |
14737 | err = nl80211_vendor_check_policy(vcmd, | |
14738 | info->attrs[NL80211_ATTR_VENDOR_DATA], | |
14739 | info->extack); | |
14740 | if (err) | |
14741 | return err; | |
ad7e718c JB |
14742 | } |
14743 | ||
14744 | rdev->cur_cmd_info = info; | |
901bb989 | 14745 | err = vcmd->doit(&rdev->wiphy, wdev, data, len); |
ad7e718c JB |
14746 | rdev->cur_cmd_info = NULL; |
14747 | return err; | |
14748 | } | |
14749 | ||
14750 | return -EOPNOTSUPP; | |
14751 | } | |
14752 | ||
7bdbe400 JB |
14753 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
14754 | struct netlink_callback *cb, | |
14755 | struct cfg80211_registered_device **rdev, | |
14756 | struct wireless_dev **wdev) | |
14757 | { | |
50508d94 | 14758 | struct nlattr **attrbuf; |
7bdbe400 JB |
14759 | u32 vid, subcmd; |
14760 | unsigned int i; | |
14761 | int vcmd_idx = -1; | |
14762 | int err; | |
14763 | void *data = NULL; | |
14764 | unsigned int data_len = 0; | |
14765 | ||
7bdbe400 JB |
14766 | if (cb->args[0]) { |
14767 | /* subtract the 1 again here */ | |
14768 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
14769 | struct wireless_dev *tmp; | |
14770 | ||
ea90e0dc JB |
14771 | if (!wiphy) |
14772 | return -ENODEV; | |
7bdbe400 JB |
14773 | *rdev = wiphy_to_rdev(wiphy); |
14774 | *wdev = NULL; | |
14775 | ||
14776 | if (cb->args[1]) { | |
53873f13 | 14777 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
7bdbe400 JB |
14778 | if (tmp->identifier == cb->args[1] - 1) { |
14779 | *wdev = tmp; | |
14780 | break; | |
14781 | } | |
14782 | } | |
14783 | } | |
14784 | ||
14785 | /* keep rtnl locked in successful case */ | |
14786 | return 0; | |
14787 | } | |
14788 | ||
50508d94 JB |
14789 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); |
14790 | if (!attrbuf) | |
14791 | return -ENOMEM; | |
14792 | ||
8cb08174 JB |
14793 | err = nlmsg_parse_deprecated(cb->nlh, |
14794 | GENL_HDRLEN + nl80211_fam.hdrsize, | |
14795 | attrbuf, nl80211_fam.maxattr, | |
14796 | nl80211_policy, NULL); | |
7bdbe400 | 14797 | if (err) |
50508d94 | 14798 | goto out; |
7bdbe400 | 14799 | |
c90c39da | 14800 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
50508d94 JB |
14801 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { |
14802 | err = -EINVAL; | |
14803 | goto out; | |
14804 | } | |
7bdbe400 | 14805 | |
a05829a7 | 14806 | *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(skb->sk), attrbuf); |
7bdbe400 JB |
14807 | if (IS_ERR(*wdev)) |
14808 | *wdev = NULL; | |
14809 | ||
c90c39da | 14810 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
50508d94 JB |
14811 | if (IS_ERR(*rdev)) { |
14812 | err = PTR_ERR(*rdev); | |
14813 | goto out; | |
14814 | } | |
7bdbe400 | 14815 | |
c90c39da JB |
14816 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
14817 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); | |
7bdbe400 JB |
14818 | |
14819 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { | |
14820 | const struct wiphy_vendor_command *vcmd; | |
14821 | ||
14822 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; | |
14823 | ||
14824 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
14825 | continue; | |
14826 | ||
50508d94 JB |
14827 | if (!vcmd->dumpit) { |
14828 | err = -EOPNOTSUPP; | |
14829 | goto out; | |
14830 | } | |
7bdbe400 JB |
14831 | |
14832 | vcmd_idx = i; | |
14833 | break; | |
14834 | } | |
14835 | ||
50508d94 JB |
14836 | if (vcmd_idx < 0) { |
14837 | err = -EOPNOTSUPP; | |
14838 | goto out; | |
14839 | } | |
7bdbe400 | 14840 | |
c90c39da JB |
14841 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
14842 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); | |
14843 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); | |
901bb989 JB |
14844 | |
14845 | err = nl80211_vendor_check_policy( | |
14846 | &(*rdev)->wiphy.vendor_commands[vcmd_idx], | |
14847 | attrbuf[NL80211_ATTR_VENDOR_DATA], | |
14848 | cb->extack); | |
14849 | if (err) | |
50508d94 | 14850 | goto out; |
7bdbe400 JB |
14851 | } |
14852 | ||
14853 | /* 0 is the first index - add 1 to parse only once */ | |
14854 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
14855 | /* add 1 to know if it was NULL */ | |
14856 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; | |
14857 | cb->args[2] = vcmd_idx; | |
14858 | cb->args[3] = (unsigned long)data; | |
14859 | cb->args[4] = data_len; | |
14860 | ||
14861 | /* keep rtnl locked in successful case */ | |
50508d94 JB |
14862 | err = 0; |
14863 | out: | |
14864 | kfree(attrbuf); | |
14865 | return err; | |
7bdbe400 JB |
14866 | } |
14867 | ||
14868 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, | |
14869 | struct netlink_callback *cb) | |
14870 | { | |
14871 | struct cfg80211_registered_device *rdev; | |
14872 | struct wireless_dev *wdev; | |
14873 | unsigned int vcmd_idx; | |
14874 | const struct wiphy_vendor_command *vcmd; | |
14875 | void *data; | |
14876 | int data_len; | |
14877 | int err; | |
14878 | struct nlattr *vendor_data; | |
14879 | ||
ea90e0dc | 14880 | rtnl_lock(); |
7bdbe400 JB |
14881 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
14882 | if (err) | |
ea90e0dc | 14883 | goto out; |
7bdbe400 JB |
14884 | |
14885 | vcmd_idx = cb->args[2]; | |
14886 | data = (void *)cb->args[3]; | |
14887 | data_len = cb->args[4]; | |
14888 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; | |
14889 | ||
14890 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
14891 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
ea90e0dc JB |
14892 | if (!wdev) { |
14893 | err = -EINVAL; | |
14894 | goto out; | |
14895 | } | |
7bdbe400 | 14896 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
ea90e0dc JB |
14897 | !wdev->netdev) { |
14898 | err = -EINVAL; | |
14899 | goto out; | |
14900 | } | |
7bdbe400 JB |
14901 | |
14902 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
ea90e0dc JB |
14903 | if (!wdev_running(wdev)) { |
14904 | err = -ENETDOWN; | |
14905 | goto out; | |
14906 | } | |
7bdbe400 JB |
14907 | } |
14908 | } | |
14909 | ||
14910 | while (1) { | |
14911 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, | |
14912 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
14913 | NL80211_CMD_VENDOR); | |
14914 | if (!hdr) | |
14915 | break; | |
14916 | ||
14917 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
14918 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
14919 | wdev_id(wdev), | |
14920 | NL80211_ATTR_PAD))) { | |
7bdbe400 JB |
14921 | genlmsg_cancel(skb, hdr); |
14922 | break; | |
14923 | } | |
14924 | ||
ae0be8de MK |
14925 | vendor_data = nla_nest_start_noflag(skb, |
14926 | NL80211_ATTR_VENDOR_DATA); | |
7bdbe400 JB |
14927 | if (!vendor_data) { |
14928 | genlmsg_cancel(skb, hdr); | |
14929 | break; | |
14930 | } | |
14931 | ||
14932 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, | |
14933 | (unsigned long *)&cb->args[5]); | |
14934 | nla_nest_end(skb, vendor_data); | |
14935 | ||
14936 | if (err == -ENOBUFS || err == -ENOENT) { | |
14937 | genlmsg_cancel(skb, hdr); | |
14938 | break; | |
9c167b2d | 14939 | } else if (err <= 0) { |
7bdbe400 JB |
14940 | genlmsg_cancel(skb, hdr); |
14941 | goto out; | |
14942 | } | |
14943 | ||
14944 | genlmsg_end(skb, hdr); | |
14945 | } | |
14946 | ||
14947 | err = skb->len; | |
14948 | out: | |
14949 | rtnl_unlock(); | |
14950 | return err; | |
14951 | } | |
14952 | ||
ad7e718c JB |
14953 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
14954 | enum nl80211_commands cmd, | |
14955 | enum nl80211_attrs attr, | |
14956 | int approxlen) | |
14957 | { | |
f26cbf40 | 14958 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
14959 | |
14960 | if (WARN_ON(!rdev->cur_cmd_info)) | |
14961 | return NULL; | |
14962 | ||
6c09e791 | 14963 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
ad7e718c JB |
14964 | rdev->cur_cmd_info->snd_portid, |
14965 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 14966 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
14967 | } |
14968 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
14969 | ||
14970 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
14971 | { | |
14972 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
14973 | void *hdr = ((void **)skb->cb)[1]; | |
14974 | struct nlattr *data = ((void **)skb->cb)[2]; | |
14975 | ||
bd8c78e7 JB |
14976 | /* clear CB data for netlink core to own from now on */ |
14977 | memset(skb->cb, 0, sizeof(skb->cb)); | |
14978 | ||
ad7e718c JB |
14979 | if (WARN_ON(!rdev->cur_cmd_info)) { |
14980 | kfree_skb(skb); | |
14981 | return -EINVAL; | |
14982 | } | |
14983 | ||
14984 | nla_nest_end(skb, data); | |
14985 | genlmsg_end(skb, hdr); | |
14986 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
14987 | } | |
14988 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
14989 | ||
55c1fdf0 JB |
14990 | unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy) |
14991 | { | |
14992 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
14993 | ||
14994 | if (WARN_ON(!rdev->cur_cmd_info)) | |
14995 | return 0; | |
14996 | ||
14997 | return rdev->cur_cmd_info->snd_portid; | |
14998 | } | |
14999 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender); | |
15000 | ||
fa9ffc74 KP |
15001 | static int nl80211_set_qos_map(struct sk_buff *skb, |
15002 | struct genl_info *info) | |
15003 | { | |
15004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
15005 | struct cfg80211_qos_map *qos_map = NULL; | |
15006 | struct net_device *dev = info->user_ptr[1]; | |
15007 | u8 *pos, len, num_des, des_len, des; | |
15008 | int ret; | |
15009 | ||
15010 | if (!rdev->ops->set_qos_map) | |
15011 | return -EOPNOTSUPP; | |
15012 | ||
15013 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
15014 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
15015 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
15016 | ||
c8b82802 | 15017 | if (len % 2) |
fa9ffc74 KP |
15018 | return -EINVAL; |
15019 | ||
15020 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
15021 | if (!qos_map) | |
15022 | return -ENOMEM; | |
15023 | ||
15024 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
15025 | if (num_des) { | |
15026 | des_len = num_des * | |
15027 | sizeof(struct cfg80211_dscp_exception); | |
15028 | memcpy(qos_map->dscp_exception, pos, des_len); | |
15029 | qos_map->num_des = num_des; | |
15030 | for (des = 0; des < num_des; des++) { | |
15031 | if (qos_map->dscp_exception[des].up > 7) { | |
15032 | kfree(qos_map); | |
15033 | return -EINVAL; | |
15034 | } | |
15035 | } | |
15036 | pos += des_len; | |
15037 | } | |
15038 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
15039 | } | |
15040 | ||
15041 | wdev_lock(dev->ieee80211_ptr); | |
15042 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
15043 | if (!ret) | |
15044 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
15045 | wdev_unlock(dev->ieee80211_ptr); | |
15046 | ||
15047 | kfree(qos_map); | |
15048 | return ret; | |
15049 | } | |
15050 | ||
960d01ac JB |
15051 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
15052 | { | |
15053 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
15054 | struct net_device *dev = info->user_ptr[1]; | |
15055 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
15056 | const u8 *peer; | |
15057 | u8 tsid, up; | |
15058 | u16 admitted_time = 0; | |
15059 | int err; | |
15060 | ||
723e73ac | 15061 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
15062 | return -EOPNOTSUPP; |
15063 | ||
15064 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
15065 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
15066 | return -EINVAL; | |
15067 | ||
15068 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
960d01ac | 15069 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
960d01ac JB |
15070 | |
15071 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 15072 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 15073 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
15074 | * need more attributes for that (e.g. BA session requirement); |
15075 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
15076 | */ |
15077 | return -EINVAL; | |
15078 | } | |
15079 | ||
15080 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
15081 | ||
15082 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
15083 | admitted_time = | |
15084 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
15085 | if (!admitted_time) | |
15086 | return -EINVAL; | |
15087 | } | |
15088 | ||
15089 | wdev_lock(wdev); | |
15090 | switch (wdev->iftype) { | |
15091 | case NL80211_IFTYPE_STATION: | |
15092 | case NL80211_IFTYPE_P2P_CLIENT: | |
7b0a0e3c | 15093 | if (wdev->connected) |
960d01ac JB |
15094 | break; |
15095 | err = -ENOTCONN; | |
15096 | goto out; | |
15097 | default: | |
15098 | err = -EOPNOTSUPP; | |
15099 | goto out; | |
15100 | } | |
15101 | ||
15102 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
15103 | ||
15104 | out: | |
15105 | wdev_unlock(wdev); | |
15106 | return err; | |
15107 | } | |
15108 | ||
15109 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
15110 | { | |
15111 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
15112 | struct net_device *dev = info->user_ptr[1]; | |
15113 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
15114 | const u8 *peer; | |
15115 | u8 tsid; | |
15116 | int err; | |
15117 | ||
15118 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
15119 | return -EINVAL; | |
15120 | ||
15121 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
15122 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
15123 | ||
15124 | wdev_lock(wdev); | |
15125 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
15126 | wdev_unlock(wdev); | |
15127 | ||
15128 | return err; | |
15129 | } | |
15130 | ||
1057d35e AN |
15131 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
15132 | struct genl_info *info) | |
15133 | { | |
15134 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
15135 | struct net_device *dev = info->user_ptr[1]; | |
15136 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
15137 | struct cfg80211_chan_def chandef = {}; | |
15138 | const u8 *addr; | |
15139 | u8 oper_class; | |
15140 | int err; | |
15141 | ||
15142 | if (!rdev->ops->tdls_channel_switch || | |
15143 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
15144 | return -EOPNOTSUPP; | |
15145 | ||
15146 | switch (dev->ieee80211_ptr->iftype) { | |
15147 | case NL80211_IFTYPE_STATION: | |
15148 | case NL80211_IFTYPE_P2P_CLIENT: | |
15149 | break; | |
15150 | default: | |
15151 | return -EOPNOTSUPP; | |
15152 | } | |
15153 | ||
15154 | if (!info->attrs[NL80211_ATTR_MAC] || | |
15155 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | |
15156 | return -EINVAL; | |
15157 | ||
15158 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
15159 | if (err) | |
15160 | return err; | |
15161 | ||
15162 | /* | |
15163 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | |
15164 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | |
15165 | * specification is not defined for them. | |
15166 | */ | |
57fbcce3 | 15167 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
1057d35e AN |
15168 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
15169 | chandef.width != NL80211_CHAN_WIDTH_20) | |
15170 | return -EINVAL; | |
15171 | ||
15172 | /* we will be active on the TDLS link */ | |
923b352f AN |
15173 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
15174 | wdev->iftype)) | |
1057d35e AN |
15175 | return -EINVAL; |
15176 | ||
15177 | /* don't allow switching to DFS channels */ | |
15178 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | |
15179 | return -EINVAL; | |
15180 | ||
15181 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
15182 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | |
15183 | ||
15184 | wdev_lock(wdev); | |
15185 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | |
15186 | wdev_unlock(wdev); | |
15187 | ||
15188 | return err; | |
15189 | } | |
15190 | ||
15191 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | |
15192 | struct genl_info *info) | |
15193 | { | |
15194 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
15195 | struct net_device *dev = info->user_ptr[1]; | |
15196 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
15197 | const u8 *addr; | |
15198 | ||
15199 | if (!rdev->ops->tdls_channel_switch || | |
15200 | !rdev->ops->tdls_cancel_channel_switch || | |
15201 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
15202 | return -EOPNOTSUPP; | |
15203 | ||
15204 | switch (dev->ieee80211_ptr->iftype) { | |
15205 | case NL80211_IFTYPE_STATION: | |
15206 | case NL80211_IFTYPE_P2P_CLIENT: | |
15207 | break; | |
15208 | default: | |
15209 | return -EOPNOTSUPP; | |
15210 | } | |
15211 | ||
15212 | if (!info->attrs[NL80211_ATTR_MAC]) | |
15213 | return -EINVAL; | |
15214 | ||
15215 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
15216 | ||
15217 | wdev_lock(wdev); | |
15218 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | |
15219 | wdev_unlock(wdev); | |
15220 | ||
15221 | return 0; | |
15222 | } | |
15223 | ||
ce0ce13a MB |
15224 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
15225 | struct genl_info *info) | |
15226 | { | |
15227 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
15228 | struct net_device *dev = info->user_ptr[1]; | |
15229 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
15230 | const struct nlattr *nla; | |
15231 | bool enabled; | |
15232 | ||
ce0ce13a MB |
15233 | if (!rdev->ops->set_multicast_to_unicast) |
15234 | return -EOPNOTSUPP; | |
15235 | ||
15236 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
15237 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
15238 | return -EOPNOTSUPP; | |
15239 | ||
15240 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; | |
15241 | enabled = nla_get_flag(nla); | |
15242 | ||
15243 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); | |
15244 | } | |
15245 | ||
3a00df57 AS |
15246 | static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) |
15247 | { | |
15248 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
15249 | struct net_device *dev = info->user_ptr[1]; | |
15250 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
15251 | struct cfg80211_pmk_conf pmk_conf = {}; | |
15252 | int ret; | |
15253 | ||
15254 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
15255 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
15256 | return -EOPNOTSUPP; | |
15257 | ||
15258 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
15259 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) | |
15260 | return -EOPNOTSUPP; | |
15261 | ||
15262 | if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) | |
15263 | return -EINVAL; | |
15264 | ||
15265 | wdev_lock(wdev); | |
7b0a0e3c | 15266 | if (!wdev->connected) { |
3a00df57 AS |
15267 | ret = -ENOTCONN; |
15268 | goto out; | |
15269 | } | |
15270 | ||
15271 | pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7b0a0e3c | 15272 | if (memcmp(pmk_conf.aa, wdev->u.client.connected_addr, ETH_ALEN)) { |
3a00df57 AS |
15273 | ret = -EINVAL; |
15274 | goto out; | |
15275 | } | |
15276 | ||
15277 | pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); | |
15278 | pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); | |
15279 | if (pmk_conf.pmk_len != WLAN_PMK_LEN && | |
15280 | pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { | |
15281 | ret = -EINVAL; | |
15282 | goto out; | |
15283 | } | |
15284 | ||
cb9abd48 | 15285 | if (info->attrs[NL80211_ATTR_PMKR0_NAME]) |
3a00df57 AS |
15286 | pmk_conf.pmk_r0_name = |
15287 | nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); | |
3a00df57 AS |
15288 | |
15289 | ret = rdev_set_pmk(rdev, dev, &pmk_conf); | |
15290 | out: | |
15291 | wdev_unlock(wdev); | |
15292 | return ret; | |
15293 | } | |
15294 | ||
15295 | static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) | |
15296 | { | |
15297 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
15298 | struct net_device *dev = info->user_ptr[1]; | |
15299 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
15300 | const u8 *aa; | |
15301 | int ret; | |
15302 | ||
15303 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
15304 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
15305 | return -EOPNOTSUPP; | |
15306 | ||
15307 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
15308 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) | |
15309 | return -EOPNOTSUPP; | |
15310 | ||
15311 | if (!info->attrs[NL80211_ATTR_MAC]) | |
15312 | return -EINVAL; | |
15313 | ||
15314 | wdev_lock(wdev); | |
15315 | aa = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
15316 | ret = rdev_del_pmk(rdev, dev, aa); | |
15317 | wdev_unlock(wdev); | |
15318 | ||
15319 | return ret; | |
15320 | } | |
15321 | ||
40cbfa90 SD |
15322 | static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) |
15323 | { | |
15324 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
15325 | struct net_device *dev = info->user_ptr[1]; | |
15326 | struct cfg80211_external_auth_params params; | |
15327 | ||
db8d93a7 | 15328 | if (!rdev->ops->external_auth) |
40cbfa90 SD |
15329 | return -EOPNOTSUPP; |
15330 | ||
fe494370 SD |
15331 | if (!info->attrs[NL80211_ATTR_SSID] && |
15332 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
15333 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
40cbfa90 SD |
15334 | return -EINVAL; |
15335 | ||
15336 | if (!info->attrs[NL80211_ATTR_BSSID]) | |
15337 | return -EINVAL; | |
15338 | ||
15339 | if (!info->attrs[NL80211_ATTR_STATUS_CODE]) | |
15340 | return -EINVAL; | |
15341 | ||
15342 | memset(¶ms, 0, sizeof(params)); | |
15343 | ||
fe494370 SD |
15344 | if (info->attrs[NL80211_ATTR_SSID]) { |
15345 | params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
cb9abd48 | 15346 | if (params.ssid.ssid_len == 0) |
fe494370 SD |
15347 | return -EINVAL; |
15348 | memcpy(params.ssid.ssid, | |
15349 | nla_data(info->attrs[NL80211_ATTR_SSID]), | |
15350 | params.ssid.ssid_len); | |
15351 | } | |
40cbfa90 SD |
15352 | |
15353 | memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), | |
15354 | ETH_ALEN); | |
15355 | ||
15356 | params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
15357 | ||
fe494370 SD |
15358 | if (info->attrs[NL80211_ATTR_PMKID]) |
15359 | params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); | |
15360 | ||
40cbfa90 SD |
15361 | return rdev_external_auth(rdev, dev, ¶ms); |
15362 | } | |
15363 | ||
2576a9ac DK |
15364 | static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) |
15365 | { | |
dca9ca2d | 15366 | bool dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
2576a9ac DK |
15367 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
15368 | struct net_device *dev = info->user_ptr[1]; | |
15369 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
15370 | const u8 *buf; | |
15371 | size_t len; | |
15372 | u8 *dest; | |
15373 | u16 proto; | |
15374 | bool noencrypt; | |
dca9ca2d | 15375 | u64 cookie = 0; |
67207bab | 15376 | int link_id; |
2576a9ac DK |
15377 | int err; |
15378 | ||
15379 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
15380 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) | |
15381 | return -EOPNOTSUPP; | |
15382 | ||
15383 | if (!rdev->ops->tx_control_port) | |
15384 | return -EOPNOTSUPP; | |
15385 | ||
15386 | if (!info->attrs[NL80211_ATTR_FRAME] || | |
15387 | !info->attrs[NL80211_ATTR_MAC] || | |
15388 | !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { | |
15389 | GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); | |
15390 | return -EINVAL; | |
15391 | } | |
15392 | ||
15393 | wdev_lock(wdev); | |
15394 | ||
15395 | switch (wdev->iftype) { | |
15396 | case NL80211_IFTYPE_AP: | |
15397 | case NL80211_IFTYPE_P2P_GO: | |
15398 | case NL80211_IFTYPE_MESH_POINT: | |
15399 | break; | |
15400 | case NL80211_IFTYPE_ADHOC: | |
7b0a0e3c JB |
15401 | if (wdev->u.ibss.current_bss) |
15402 | break; | |
15403 | err = -ENOTCONN; | |
15404 | goto out; | |
2576a9ac DK |
15405 | case NL80211_IFTYPE_STATION: |
15406 | case NL80211_IFTYPE_P2P_CLIENT: | |
7b0a0e3c | 15407 | if (wdev->connected) |
2576a9ac DK |
15408 | break; |
15409 | err = -ENOTCONN; | |
15410 | goto out; | |
15411 | default: | |
15412 | err = -EOPNOTSUPP; | |
15413 | goto out; | |
15414 | } | |
15415 | ||
15416 | wdev_unlock(wdev); | |
15417 | ||
15418 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); | |
15419 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
15420 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
15421 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
15422 | noencrypt = | |
15423 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); | |
15424 | ||
67207bab AO |
15425 | link_id = nl80211_link_id_or_invalid(info->attrs); |
15426 | ||
dca9ca2d | 15427 | err = rdev_tx_control_port(rdev, dev, buf, len, |
67207bab | 15428 | dest, cpu_to_be16(proto), noencrypt, link_id, |
dca9ca2d MT |
15429 | dont_wait_for_ack ? NULL : &cookie); |
15430 | if (!err && !dont_wait_for_ack) | |
15431 | nl_set_extack_cookie_u64(info->extack, cookie); | |
15432 | return err; | |
2576a9ac DK |
15433 | out: |
15434 | wdev_unlock(wdev); | |
15435 | return err; | |
15436 | } | |
15437 | ||
81e54d08 PKC |
15438 | static int nl80211_get_ftm_responder_stats(struct sk_buff *skb, |
15439 | struct genl_info *info) | |
15440 | { | |
15441 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
15442 | struct net_device *dev = info->user_ptr[1]; | |
15443 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
15444 | struct cfg80211_ftm_responder_stats ftm_stats = {}; | |
7b0a0e3c | 15445 | unsigned int link_id = nl80211_link_id(info->attrs); |
81e54d08 PKC |
15446 | struct sk_buff *msg; |
15447 | void *hdr; | |
15448 | struct nlattr *ftm_stats_attr; | |
15449 | int err; | |
15450 | ||
7b0a0e3c JB |
15451 | if (wdev->iftype != NL80211_IFTYPE_AP || |
15452 | !wdev->links[link_id].ap.beacon_interval) | |
81e54d08 PKC |
15453 | return -EOPNOTSUPP; |
15454 | ||
15455 | err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats); | |
15456 | if (err) | |
15457 | return err; | |
15458 | ||
15459 | if (!ftm_stats.filled) | |
15460 | return -ENODATA; | |
15461 | ||
15462 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
15463 | if (!msg) | |
15464 | return -ENOMEM; | |
15465 | ||
15466 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
15467 | NL80211_CMD_GET_FTM_RESPONDER_STATS); | |
15468 | if (!hdr) | |
1399c59f | 15469 | goto nla_put_failure; |
81e54d08 PKC |
15470 | |
15471 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) | |
15472 | goto nla_put_failure; | |
15473 | ||
ae0be8de MK |
15474 | ftm_stats_attr = nla_nest_start_noflag(msg, |
15475 | NL80211_ATTR_FTM_RESPONDER_STATS); | |
81e54d08 PKC |
15476 | if (!ftm_stats_attr) |
15477 | goto nla_put_failure; | |
15478 | ||
15479 | #define SET_FTM(field, name, type) \ | |
15480 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ | |
15481 | nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \ | |
15482 | ftm_stats.field)) \ | |
15483 | goto nla_put_failure; } while (0) | |
15484 | #define SET_FTM_U64(field, name) \ | |
15485 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ | |
15486 | nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \ | |
15487 | ftm_stats.field, NL80211_FTM_STATS_PAD)) \ | |
15488 | goto nla_put_failure; } while (0) | |
15489 | ||
15490 | SET_FTM(success_num, SUCCESS_NUM, u32); | |
15491 | SET_FTM(partial_num, PARTIAL_NUM, u32); | |
15492 | SET_FTM(failed_num, FAILED_NUM, u32); | |
15493 | SET_FTM(asap_num, ASAP_NUM, u32); | |
15494 | SET_FTM(non_asap_num, NON_ASAP_NUM, u32); | |
15495 | SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC); | |
15496 | SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32); | |
15497 | SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32); | |
15498 | SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32); | |
15499 | #undef SET_FTM | |
15500 | ||
15501 | nla_nest_end(msg, ftm_stats_attr); | |
15502 | ||
15503 | genlmsg_end(msg, hdr); | |
15504 | return genlmsg_reply(msg, info); | |
15505 | ||
15506 | nla_put_failure: | |
15507 | nlmsg_free(msg); | |
15508 | return -ENOBUFS; | |
15509 | } | |
15510 | ||
cb74e977 SD |
15511 | static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info) |
15512 | { | |
15513 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
15514 | struct cfg80211_update_owe_info owe_info; | |
15515 | struct net_device *dev = info->user_ptr[1]; | |
15516 | ||
15517 | if (!rdev->ops->update_owe_info) | |
15518 | return -EOPNOTSUPP; | |
15519 | ||
15520 | if (!info->attrs[NL80211_ATTR_STATUS_CODE] || | |
15521 | !info->attrs[NL80211_ATTR_MAC]) | |
15522 | return -EINVAL; | |
15523 | ||
15524 | memset(&owe_info, 0, sizeof(owe_info)); | |
15525 | owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
15526 | nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN); | |
15527 | ||
15528 | if (info->attrs[NL80211_ATTR_IE]) { | |
15529 | owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
15530 | owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
15531 | } | |
15532 | ||
15533 | return rdev_update_owe_info(rdev, dev, &owe_info); | |
15534 | } | |
15535 | ||
5ab92e7f RM |
15536 | static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info) |
15537 | { | |
15538 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
15539 | struct net_device *dev = info->user_ptr[1]; | |
15540 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
15541 | struct station_info sinfo = {}; | |
15542 | const u8 *buf; | |
15543 | size_t len; | |
15544 | u8 *dest; | |
15545 | int err; | |
15546 | ||
15547 | if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station) | |
15548 | return -EOPNOTSUPP; | |
15549 | ||
15550 | if (!info->attrs[NL80211_ATTR_MAC] || | |
15551 | !info->attrs[NL80211_ATTR_FRAME]) { | |
15552 | GENL_SET_ERR_MSG(info, "Frame or MAC missing"); | |
15553 | return -EINVAL; | |
15554 | } | |
15555 | ||
15556 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) | |
15557 | return -EOPNOTSUPP; | |
15558 | ||
15559 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
15560 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); | |
15561 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
15562 | ||
15563 | if (len < sizeof(struct ethhdr)) | |
15564 | return -EINVAL; | |
15565 | ||
15566 | if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) || | |
15567 | !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr)) | |
15568 | return -EINVAL; | |
15569 | ||
15570 | err = rdev_get_station(rdev, dev, dest, &sinfo); | |
15571 | if (err) | |
15572 | return err; | |
15573 | ||
2a279b34 FF |
15574 | cfg80211_sinfo_release_content(&sinfo); |
15575 | ||
5ab92e7f RM |
15576 | return rdev_probe_mesh_link(rdev, dev, dest, buf, len); |
15577 | } | |
15578 | ||
77f576de T |
15579 | static int parse_tid_conf(struct cfg80211_registered_device *rdev, |
15580 | struct nlattr *attrs[], struct net_device *dev, | |
3710a8a6 | 15581 | struct cfg80211_tid_cfg *tid_conf, |
7b0a0e3c JB |
15582 | struct genl_info *info, const u8 *peer, |
15583 | unsigned int link_id) | |
77f576de T |
15584 | { |
15585 | struct netlink_ext_ack *extack = info->extack; | |
3710a8a6 | 15586 | u64 mask; |
77f576de T |
15587 | int err; |
15588 | ||
15589 | if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS]) | |
15590 | return -EINVAL; | |
15591 | ||
15592 | tid_conf->config_override = | |
15593 | nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]); | |
3710a8a6 | 15594 | tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]); |
77f576de T |
15595 | |
15596 | if (tid_conf->config_override) { | |
15597 | if (rdev->ops->reset_tid_config) { | |
15598 | err = rdev_reset_tid_config(rdev, dev, peer, | |
3710a8a6 | 15599 | tid_conf->tids); |
c0336955 | 15600 | if (err) |
77f576de T |
15601 | return err; |
15602 | } else { | |
15603 | return -EINVAL; | |
15604 | } | |
15605 | } | |
15606 | ||
15607 | if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) { | |
3710a8a6 | 15608 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK); |
77f576de T |
15609 | tid_conf->noack = |
15610 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]); | |
15611 | } | |
15612 | ||
6a21d16c T |
15613 | if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) { |
15614 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT); | |
15615 | tid_conf->retry_short = | |
15616 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]); | |
15617 | ||
15618 | if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count) | |
15619 | return -EINVAL; | |
15620 | } | |
15621 | ||
15622 | if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) { | |
15623 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG); | |
15624 | tid_conf->retry_long = | |
15625 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]); | |
15626 | ||
15627 | if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count) | |
15628 | return -EINVAL; | |
15629 | } | |
15630 | ||
ade274b2 T |
15631 | if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) { |
15632 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL); | |
15633 | tid_conf->ampdu = | |
15634 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]); | |
15635 | } | |
15636 | ||
04f7d142 T |
15637 | if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) { |
15638 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL); | |
15639 | tid_conf->rtscts = | |
15640 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]); | |
15641 | } | |
15642 | ||
33462e68 SM |
15643 | if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) { |
15644 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL); | |
15645 | tid_conf->amsdu = | |
15646 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]); | |
15647 | } | |
15648 | ||
9a5f6488 TC |
15649 | if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) { |
15650 | u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr; | |
15651 | ||
15652 | tid_conf->txrate_type = nla_get_u8(attrs[idx]); | |
15653 | ||
15654 | if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) { | |
15655 | attr = NL80211_TID_CONFIG_ATTR_TX_RATE; | |
15656 | err = nl80211_parse_tx_bitrate_mask(info, attrs, attr, | |
857b34c4 | 15657 | &tid_conf->txrate_mask, dev, |
7b0a0e3c | 15658 | true, link_id); |
9a5f6488 TC |
15659 | if (err) |
15660 | return err; | |
15661 | ||
15662 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE); | |
15663 | } | |
15664 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE); | |
15665 | } | |
15666 | ||
3710a8a6 JB |
15667 | if (peer) |
15668 | mask = rdev->wiphy.tid_config_support.peer; | |
15669 | else | |
15670 | mask = rdev->wiphy.tid_config_support.vif; | |
15671 | ||
15672 | if (tid_conf->mask & ~mask) { | |
15673 | NL_SET_ERR_MSG(extack, "unsupported TID configuration"); | |
15674 | return -ENOTSUPP; | |
15675 | } | |
15676 | ||
77f576de T |
15677 | return 0; |
15678 | } | |
15679 | ||
15680 | static int nl80211_set_tid_config(struct sk_buff *skb, | |
15681 | struct genl_info *info) | |
15682 | { | |
15683 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
15684 | struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1]; | |
7b0a0e3c | 15685 | unsigned int link_id = nl80211_link_id(info->attrs); |
77f576de | 15686 | struct net_device *dev = info->user_ptr[1]; |
3710a8a6 | 15687 | struct cfg80211_tid_config *tid_config; |
77f576de T |
15688 | struct nlattr *tid; |
15689 | int conf_idx = 0, rem_conf; | |
15690 | int ret = -EINVAL; | |
15691 | u32 num_conf = 0; | |
15692 | ||
15693 | if (!info->attrs[NL80211_ATTR_TID_CONFIG]) | |
15694 | return -EINVAL; | |
15695 | ||
15696 | if (!rdev->ops->set_tid_config) | |
15697 | return -EOPNOTSUPP; | |
15698 | ||
15699 | nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], | |
15700 | rem_conf) | |
15701 | num_conf++; | |
15702 | ||
15703 | tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf), | |
15704 | GFP_KERNEL); | |
15705 | if (!tid_config) | |
15706 | return -ENOMEM; | |
15707 | ||
15708 | tid_config->n_tid_conf = num_conf; | |
15709 | ||
15710 | if (info->attrs[NL80211_ATTR_MAC]) | |
15711 | tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
15712 | ||
206bbcf7 JB |
15713 | wdev_lock(dev->ieee80211_ptr); |
15714 | ||
77f576de T |
15715 | nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], |
15716 | rem_conf) { | |
15717 | ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX, | |
15718 | tid, NULL, NULL); | |
15719 | ||
15720 | if (ret) | |
15721 | goto bad_tid_conf; | |
15722 | ||
15723 | ret = parse_tid_conf(rdev, attrs, dev, | |
15724 | &tid_config->tid_conf[conf_idx], | |
7b0a0e3c | 15725 | info, tid_config->peer, link_id); |
77f576de T |
15726 | if (ret) |
15727 | goto bad_tid_conf; | |
15728 | ||
15729 | conf_idx++; | |
15730 | } | |
15731 | ||
15732 | ret = rdev_set_tid_config(rdev, dev, tid_config); | |
15733 | ||
15734 | bad_tid_conf: | |
15735 | kfree(tid_config); | |
206bbcf7 | 15736 | wdev_unlock(dev->ieee80211_ptr); |
77f576de T |
15737 | return ret; |
15738 | } | |
15739 | ||
0d2ab3ae JC |
15740 | static int nl80211_color_change(struct sk_buff *skb, struct genl_info *info) |
15741 | { | |
15742 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
15743 | struct cfg80211_color_change_settings params = {}; | |
15744 | struct net_device *dev = info->user_ptr[1]; | |
15745 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
15746 | struct nlattr **tb; | |
15747 | u16 offset; | |
15748 | int err; | |
15749 | ||
15750 | if (!rdev->ops->color_change) | |
15751 | return -EOPNOTSUPP; | |
15752 | ||
15753 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
15754 | NL80211_EXT_FEATURE_BSS_COLOR)) | |
15755 | return -EOPNOTSUPP; | |
15756 | ||
15757 | if (wdev->iftype != NL80211_IFTYPE_AP) | |
15758 | return -EOPNOTSUPP; | |
15759 | ||
15760 | if (!info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT] || | |
15761 | !info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR] || | |
15762 | !info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS]) | |
15763 | return -EINVAL; | |
15764 | ||
15765 | params.count = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT]); | |
15766 | params.color = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR]); | |
15767 | ||
15768 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_next); | |
15769 | if (err) | |
15770 | return err; | |
15771 | ||
15772 | tb = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*tb), GFP_KERNEL); | |
15773 | if (!tb) | |
15774 | return -ENOMEM; | |
15775 | ||
15776 | err = nla_parse_nested(tb, NL80211_ATTR_MAX, | |
15777 | info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS], | |
15778 | nl80211_policy, info->extack); | |
15779 | if (err) | |
15780 | goto out; | |
15781 | ||
15782 | err = nl80211_parse_beacon(rdev, tb, ¶ms.beacon_color_change); | |
15783 | if (err) | |
15784 | goto out; | |
15785 | ||
15786 | if (!tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]) { | |
15787 | err = -EINVAL; | |
15788 | goto out; | |
15789 | } | |
15790 | ||
15791 | if (nla_len(tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]) != sizeof(u16)) { | |
15792 | err = -EINVAL; | |
15793 | goto out; | |
15794 | } | |
15795 | ||
15796 | offset = nla_get_u16(tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]); | |
15797 | if (offset >= params.beacon_color_change.tail_len) { | |
15798 | err = -EINVAL; | |
15799 | goto out; | |
15800 | } | |
15801 | ||
15802 | if (params.beacon_color_change.tail[offset] != params.count) { | |
15803 | err = -EINVAL; | |
15804 | goto out; | |
15805 | } | |
15806 | ||
15807 | params.counter_offset_beacon = offset; | |
15808 | ||
15809 | if (tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]) { | |
15810 | if (nla_len(tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]) != | |
15811 | sizeof(u16)) { | |
15812 | err = -EINVAL; | |
15813 | goto out; | |
15814 | } | |
15815 | ||
15816 | offset = nla_get_u16(tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]); | |
15817 | if (offset >= params.beacon_color_change.probe_resp_len) { | |
15818 | err = -EINVAL; | |
15819 | goto out; | |
15820 | } | |
15821 | ||
15822 | if (params.beacon_color_change.probe_resp[offset] != | |
15823 | params.count) { | |
15824 | err = -EINVAL; | |
15825 | goto out; | |
15826 | } | |
15827 | ||
15828 | params.counter_offset_presp = offset; | |
15829 | } | |
15830 | ||
15831 | wdev_lock(wdev); | |
15832 | err = rdev_color_change(rdev, dev, ¶ms); | |
15833 | wdev_unlock(wdev); | |
15834 | ||
15835 | out: | |
dc1e3cb8 JC |
15836 | kfree(params.beacon_next.mbssid_ies); |
15837 | kfree(params.beacon_color_change.mbssid_ies); | |
0d2ab3ae JC |
15838 | kfree(tb); |
15839 | return err; | |
15840 | } | |
15841 | ||
e306784a SM |
15842 | static int nl80211_set_fils_aad(struct sk_buff *skb, |
15843 | struct genl_info *info) | |
15844 | { | |
15845 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
15846 | struct net_device *dev = info->user_ptr[1]; | |
15847 | struct cfg80211_fils_aad fils_aad = {}; | |
15848 | u8 *nonces; | |
15849 | ||
15850 | if (!info->attrs[NL80211_ATTR_MAC] || | |
15851 | !info->attrs[NL80211_ATTR_FILS_KEK] || | |
15852 | !info->attrs[NL80211_ATTR_FILS_NONCES]) | |
15853 | return -EINVAL; | |
15854 | ||
15855 | fils_aad.macaddr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
15856 | fils_aad.kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); | |
15857 | fils_aad.kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); | |
15858 | nonces = nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); | |
15859 | fils_aad.snonce = nonces; | |
15860 | fils_aad.anonce = nonces + FILS_NONCE_LEN; | |
15861 | ||
15862 | return rdev_set_fils_aad(rdev, dev, &fils_aad); | |
15863 | } | |
15864 | ||
7b0a0e3c JB |
15865 | static int nl80211_add_link(struct sk_buff *skb, struct genl_info *info) |
15866 | { | |
f2a0290b | 15867 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7b0a0e3c JB |
15868 | unsigned int link_id = nl80211_link_id(info->attrs); |
15869 | struct net_device *dev = info->user_ptr[1]; | |
15870 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f2a0290b | 15871 | int ret; |
7b0a0e3c JB |
15872 | |
15873 | if (!(wdev->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO)) | |
15874 | return -EINVAL; | |
15875 | ||
15876 | switch (wdev->iftype) { | |
15877 | case NL80211_IFTYPE_AP: | |
15878 | break; | |
15879 | default: | |
15880 | return -EINVAL; | |
15881 | } | |
15882 | ||
15883 | if (!info->attrs[NL80211_ATTR_MAC] || | |
15884 | !is_valid_ether_addr(nla_data(info->attrs[NL80211_ATTR_MAC]))) | |
15885 | return -EINVAL; | |
15886 | ||
15887 | wdev_lock(wdev); | |
15888 | wdev->valid_links |= BIT(link_id); | |
15889 | ether_addr_copy(wdev->links[link_id].addr, | |
15890 | nla_data(info->attrs[NL80211_ATTR_MAC])); | |
f2a0290b JB |
15891 | |
15892 | ret = rdev_add_intf_link(rdev, wdev, link_id); | |
15893 | if (ret) { | |
15894 | wdev->valid_links &= ~BIT(link_id); | |
15895 | eth_zero_addr(wdev->links[link_id].addr); | |
15896 | } | |
7b0a0e3c JB |
15897 | wdev_unlock(wdev); |
15898 | ||
f2a0290b | 15899 | return ret; |
7b0a0e3c JB |
15900 | } |
15901 | ||
15902 | static int nl80211_remove_link(struct sk_buff *skb, struct genl_info *info) | |
15903 | { | |
15904 | unsigned int link_id = nl80211_link_id(info->attrs); | |
15905 | struct net_device *dev = info->user_ptr[1]; | |
15906 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
15907 | ||
15908 | /* cannot remove if there's no link */ | |
15909 | if (!info->attrs[NL80211_ATTR_MLO_LINK_ID]) | |
15910 | return -EINVAL; | |
15911 | ||
15912 | switch (wdev->iftype) { | |
15913 | case NL80211_IFTYPE_AP: | |
15914 | break; | |
15915 | default: | |
15916 | return -EINVAL; | |
15917 | } | |
15918 | ||
7b0a0e3c | 15919 | wdev_lock(wdev); |
cdf0a0a8 | 15920 | cfg80211_remove_link(wdev, link_id); |
7b0a0e3c JB |
15921 | wdev_unlock(wdev); |
15922 | ||
15923 | return 0; | |
15924 | } | |
15925 | ||
577e5b8c ST |
15926 | static int |
15927 | nl80211_add_mod_link_station(struct sk_buff *skb, struct genl_info *info, | |
15928 | bool add) | |
15929 | { | |
15930 | struct link_station_parameters params = {}; | |
15931 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
15932 | struct net_device *dev = info->user_ptr[1]; | |
15933 | int err; | |
15934 | ||
15935 | if ((add && !rdev->ops->add_link_station) || | |
15936 | (!add && !rdev->ops->mod_link_station)) | |
15937 | return -EOPNOTSUPP; | |
15938 | ||
15939 | if (add && !info->attrs[NL80211_ATTR_MAC]) | |
15940 | return -EINVAL; | |
15941 | ||
8876c67e | 15942 | if (!info->attrs[NL80211_ATTR_MLD_ADDR]) |
577e5b8c ST |
15943 | return -EINVAL; |
15944 | ||
15945 | if (add && !info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
15946 | return -EINVAL; | |
15947 | ||
8876c67e | 15948 | params.mld_mac = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); |
577e5b8c ST |
15949 | |
15950 | if (info->attrs[NL80211_ATTR_MAC]) { | |
15951 | params.link_mac = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
15952 | if (!is_valid_ether_addr(params.link_mac)) | |
15953 | return -EINVAL; | |
15954 | } | |
15955 | ||
15956 | if (!info->attrs[NL80211_ATTR_MLO_LINK_ID]) | |
15957 | return -EINVAL; | |
15958 | ||
15959 | params.link_id = nla_get_u8(info->attrs[NL80211_ATTR_MLO_LINK_ID]); | |
15960 | ||
15961 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
15962 | params.supported_rates = | |
15963 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
15964 | params.supported_rates_len = | |
15965 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
15966 | } | |
15967 | ||
15968 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) | |
15969 | params.ht_capa = | |
15970 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
15971 | ||
15972 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
15973 | params.vht_capa = | |
15974 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
15975 | ||
15976 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { | |
15977 | params.he_capa = | |
15978 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); | |
15979 | params.he_capa_len = | |
15980 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); | |
15981 | ||
15982 | if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) { | |
15983 | params.eht_capa = | |
15984 | nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); | |
15985 | params.eht_capa_len = | |
15986 | nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); | |
15987 | ||
15988 | if (!ieee80211_eht_capa_size_ok((const u8 *)params.he_capa, | |
15989 | (const u8 *)params.eht_capa, | |
ea5cba26 JB |
15990 | params.eht_capa_len, |
15991 | false)) | |
577e5b8c ST |
15992 | return -EINVAL; |
15993 | } | |
15994 | } | |
15995 | ||
15996 | if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) | |
15997 | params.he_6ghz_capa = | |
15998 | nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); | |
15999 | ||
16000 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { | |
16001 | params.opmode_notif_used = true; | |
16002 | params.opmode_notif = | |
16003 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
16004 | } | |
16005 | ||
16006 | err = nl80211_parse_sta_txpower_setting(info, ¶ms.txpwr, | |
16007 | ¶ms.txpwr_set); | |
16008 | if (err) | |
16009 | return err; | |
16010 | ||
858fd188 | 16011 | wdev_lock(dev->ieee80211_ptr); |
577e5b8c | 16012 | if (add) |
858fd188 JB |
16013 | err = rdev_add_link_station(rdev, dev, ¶ms); |
16014 | else | |
16015 | err = rdev_mod_link_station(rdev, dev, ¶ms); | |
16016 | wdev_unlock(dev->ieee80211_ptr); | |
16017 | ||
16018 | return err; | |
577e5b8c ST |
16019 | } |
16020 | ||
16021 | static int | |
16022 | nl80211_add_link_station(struct sk_buff *skb, struct genl_info *info) | |
16023 | { | |
16024 | return nl80211_add_mod_link_station(skb, info, true); | |
16025 | } | |
16026 | ||
16027 | static int | |
16028 | nl80211_modify_link_station(struct sk_buff *skb, struct genl_info *info) | |
16029 | { | |
16030 | return nl80211_add_mod_link_station(skb, info, false); | |
16031 | } | |
16032 | ||
16033 | static int | |
16034 | nl80211_remove_link_station(struct sk_buff *skb, struct genl_info *info) | |
16035 | { | |
16036 | struct link_station_del_parameters params = {}; | |
16037 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
16038 | struct net_device *dev = info->user_ptr[1]; | |
858fd188 | 16039 | int ret; |
577e5b8c ST |
16040 | |
16041 | if (!rdev->ops->del_link_station) | |
16042 | return -EOPNOTSUPP; | |
16043 | ||
16044 | if (!info->attrs[NL80211_ATTR_MLD_ADDR] || | |
16045 | !info->attrs[NL80211_ATTR_MLO_LINK_ID]) | |
16046 | return -EINVAL; | |
16047 | ||
16048 | params.mld_mac = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); | |
16049 | params.link_id = nla_get_u8(info->attrs[NL80211_ATTR_MLO_LINK_ID]); | |
16050 | ||
858fd188 JB |
16051 | wdev_lock(dev->ieee80211_ptr); |
16052 | ret = rdev_del_link_station(rdev, dev, ¶ms); | |
16053 | wdev_unlock(dev->ieee80211_ptr); | |
16054 | ||
16055 | return ret; | |
577e5b8c ST |
16056 | } |
16057 | ||
4c476991 JB |
16058 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
16059 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
16060 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
16061 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
16062 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
16063 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 16064 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 16065 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
16066 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
16067 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 16068 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
77cbf790 | 16069 | #define NL80211_FLAG_NO_WIPHY_MTX 0x40 |
7b0a0e3c JB |
16070 | #define NL80211_FLAG_MLO_VALID_LINK_ID 0x80 |
16071 | #define NL80211_FLAG_MLO_UNSUPPORTED 0x100 | |
4c476991 | 16072 | |
2182db91 JB |
16073 | #define INTERNAL_FLAG_SELECTORS(__sel) \ |
16074 | SELECTOR(__sel, NONE, 0) /* must be first */ \ | |
16075 | SELECTOR(__sel, WIPHY, \ | |
16076 | NL80211_FLAG_NEED_WIPHY) \ | |
16077 | SELECTOR(__sel, WDEV, \ | |
16078 | NL80211_FLAG_NEED_WDEV) \ | |
16079 | SELECTOR(__sel, NETDEV, \ | |
16080 | NL80211_FLAG_NEED_NETDEV) \ | |
7b0a0e3c JB |
16081 | SELECTOR(__sel, NETDEV_LINK, \ |
16082 | NL80211_FLAG_NEED_NETDEV | \ | |
16083 | NL80211_FLAG_MLO_VALID_LINK_ID) \ | |
16084 | SELECTOR(__sel, NETDEV_NO_MLO, \ | |
16085 | NL80211_FLAG_NEED_NETDEV | \ | |
16086 | NL80211_FLAG_MLO_UNSUPPORTED) \ | |
2182db91 JB |
16087 | SELECTOR(__sel, WIPHY_RTNL, \ |
16088 | NL80211_FLAG_NEED_WIPHY | \ | |
16089 | NL80211_FLAG_NEED_RTNL) \ | |
16090 | SELECTOR(__sel, WIPHY_RTNL_NOMTX, \ | |
16091 | NL80211_FLAG_NEED_WIPHY | \ | |
16092 | NL80211_FLAG_NEED_RTNL | \ | |
16093 | NL80211_FLAG_NO_WIPHY_MTX) \ | |
16094 | SELECTOR(__sel, WDEV_RTNL, \ | |
16095 | NL80211_FLAG_NEED_WDEV | \ | |
16096 | NL80211_FLAG_NEED_RTNL) \ | |
16097 | SELECTOR(__sel, NETDEV_RTNL, \ | |
16098 | NL80211_FLAG_NEED_NETDEV | \ | |
16099 | NL80211_FLAG_NEED_RTNL) \ | |
16100 | SELECTOR(__sel, NETDEV_UP, \ | |
16101 | NL80211_FLAG_NEED_NETDEV_UP) \ | |
7b0a0e3c JB |
16102 | SELECTOR(__sel, NETDEV_UP_LINK, \ |
16103 | NL80211_FLAG_NEED_NETDEV_UP | \ | |
16104 | NL80211_FLAG_MLO_VALID_LINK_ID) \ | |
16105 | SELECTOR(__sel, NETDEV_UP_NO_MLO, \ | |
16106 | NL80211_FLAG_NEED_NETDEV_UP | \ | |
16107 | NL80211_FLAG_MLO_UNSUPPORTED) \ | |
16108 | SELECTOR(__sel, NETDEV_UP_NO_MLO_CLEAR, \ | |
16109 | NL80211_FLAG_NEED_NETDEV_UP | \ | |
16110 | NL80211_FLAG_CLEAR_SKB | \ | |
16111 | NL80211_FLAG_MLO_UNSUPPORTED) \ | |
2182db91 JB |
16112 | SELECTOR(__sel, NETDEV_UP_NOTMX, \ |
16113 | NL80211_FLAG_NEED_NETDEV_UP | \ | |
16114 | NL80211_FLAG_NO_WIPHY_MTX) \ | |
7b0a0e3c JB |
16115 | SELECTOR(__sel, NETDEV_UP_NOTMX_NOMLO, \ |
16116 | NL80211_FLAG_NEED_NETDEV_UP | \ | |
16117 | NL80211_FLAG_NO_WIPHY_MTX | \ | |
16118 | NL80211_FLAG_MLO_UNSUPPORTED) \ | |
2182db91 JB |
16119 | SELECTOR(__sel, NETDEV_UP_CLEAR, \ |
16120 | NL80211_FLAG_NEED_NETDEV_UP | \ | |
16121 | NL80211_FLAG_CLEAR_SKB) \ | |
16122 | SELECTOR(__sel, WDEV_UP, \ | |
16123 | NL80211_FLAG_NEED_WDEV_UP) \ | |
7b0a0e3c JB |
16124 | SELECTOR(__sel, WDEV_UP_LINK, \ |
16125 | NL80211_FLAG_NEED_WDEV_UP | \ | |
16126 | NL80211_FLAG_MLO_VALID_LINK_ID) \ | |
2182db91 JB |
16127 | SELECTOR(__sel, WDEV_UP_RTNL, \ |
16128 | NL80211_FLAG_NEED_WDEV_UP | \ | |
16129 | NL80211_FLAG_NEED_RTNL) \ | |
16130 | SELECTOR(__sel, WIPHY_CLEAR, \ | |
16131 | NL80211_FLAG_NEED_WIPHY | \ | |
16132 | NL80211_FLAG_CLEAR_SKB) | |
16133 | ||
16134 | enum nl80211_internal_flags_selector { | |
16135 | #define SELECTOR(_, name, value) NL80211_IFL_SEL_##name, | |
16136 | INTERNAL_FLAG_SELECTORS(_) | |
16137 | #undef SELECTOR | |
16138 | }; | |
16139 | ||
16140 | static u32 nl80211_internal_flags[] = { | |
16141 | #define SELECTOR(_, name, value) [NL80211_IFL_SEL_##name] = value, | |
16142 | INTERNAL_FLAG_SELECTORS(_) | |
16143 | #undef SELECTOR | |
16144 | }; | |
16145 | ||
20b0b53a JK |
16146 | static int nl80211_pre_doit(const struct genl_split_ops *ops, |
16147 | struct sk_buff *skb, | |
4c476991 JB |
16148 | struct genl_info *info) |
16149 | { | |
a05829a7 | 16150 | struct cfg80211_registered_device *rdev = NULL; |
7b0a0e3c JB |
16151 | struct wireless_dev *wdev = NULL; |
16152 | struct net_device *dev = NULL; | |
2182db91 | 16153 | u32 internal_flags; |
7b0a0e3c | 16154 | int err; |
2182db91 JB |
16155 | |
16156 | if (WARN_ON(ops->internal_flags >= ARRAY_SIZE(nl80211_internal_flags))) | |
16157 | return -EINVAL; | |
16158 | ||
16159 | internal_flags = nl80211_internal_flags[ops->internal_flags]; | |
4c476991 | 16160 | |
a05829a7 | 16161 | rtnl_lock(); |
2182db91 | 16162 | if (internal_flags & NL80211_FLAG_NEED_WIPHY) { |
4f7eff10 | 16163 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 | 16164 | if (IS_ERR(rdev)) { |
7b0a0e3c JB |
16165 | err = PTR_ERR(rdev); |
16166 | goto out_unlock; | |
4c476991 JB |
16167 | } |
16168 | info->user_ptr[0] = rdev; | |
2182db91 JB |
16169 | } else if (internal_flags & NL80211_FLAG_NEED_NETDEV || |
16170 | internal_flags & NL80211_FLAG_NEED_WDEV) { | |
a05829a7 | 16171 | wdev = __cfg80211_wdev_from_attrs(NULL, genl_info_net(info), |
89a54e48 JB |
16172 | info->attrs); |
16173 | if (IS_ERR(wdev)) { | |
7b0a0e3c JB |
16174 | err = PTR_ERR(wdev); |
16175 | goto out_unlock; | |
4c476991 | 16176 | } |
89a54e48 | 16177 | |
89a54e48 | 16178 | dev = wdev->netdev; |
7b0a0e3c | 16179 | dev_hold(dev); |
f26cbf40 | 16180 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 16181 | |
2182db91 | 16182 | if (internal_flags & NL80211_FLAG_NEED_NETDEV) { |
1bf614ef | 16183 | if (!dev) { |
7b0a0e3c JB |
16184 | err = -EINVAL; |
16185 | goto out_unlock; | |
1bf614ef JB |
16186 | } |
16187 | ||
16188 | info->user_ptr[1] = dev; | |
16189 | } else { | |
16190 | info->user_ptr[1] = wdev; | |
41265714 | 16191 | } |
1bf614ef | 16192 | |
2182db91 | 16193 | if (internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
73c7da3d | 16194 | !wdev_running(wdev)) { |
7b0a0e3c JB |
16195 | err = -ENETDOWN; |
16196 | goto out_unlock; | |
73c7da3d | 16197 | } |
1bf614ef | 16198 | |
4c476991 | 16199 | info->user_ptr[0] = rdev; |
4c476991 JB |
16200 | } |
16201 | ||
7b0a0e3c JB |
16202 | if (internal_flags & NL80211_FLAG_MLO_VALID_LINK_ID) { |
16203 | struct nlattr *link_id = info->attrs[NL80211_ATTR_MLO_LINK_ID]; | |
16204 | ||
16205 | if (!wdev) { | |
16206 | err = -EINVAL; | |
16207 | goto out_unlock; | |
16208 | } | |
16209 | ||
16210 | /* MLO -> require valid link ID */ | |
16211 | if (wdev->valid_links && | |
16212 | (!link_id || | |
ff3821bc | 16213 | !(wdev->valid_links & BIT(nla_get_u8(link_id))))) { |
7b0a0e3c JB |
16214 | err = -EINVAL; |
16215 | goto out_unlock; | |
16216 | } | |
16217 | ||
16218 | /* non-MLO -> no link ID attribute accepted */ | |
16219 | if (!wdev->valid_links && link_id) { | |
16220 | err = -EINVAL; | |
16221 | goto out_unlock; | |
16222 | } | |
16223 | } | |
16224 | ||
16225 | if (internal_flags & NL80211_FLAG_MLO_UNSUPPORTED) { | |
16226 | if (info->attrs[NL80211_ATTR_MLO_LINK_ID] || | |
16227 | (wdev && wdev->valid_links)) { | |
16228 | err = -EINVAL; | |
16229 | goto out_unlock; | |
16230 | } | |
16231 | } | |
16232 | ||
2182db91 | 16233 | if (rdev && !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) { |
a05829a7 JB |
16234 | wiphy_lock(&rdev->wiphy); |
16235 | /* we keep the mutex locked until post_doit */ | |
16236 | __release(&rdev->wiphy.mtx); | |
16237 | } | |
2182db91 | 16238 | if (!(internal_flags & NL80211_FLAG_NEED_RTNL)) |
a05829a7 JB |
16239 | rtnl_unlock(); |
16240 | ||
4c476991 | 16241 | return 0; |
7b0a0e3c JB |
16242 | out_unlock: |
16243 | rtnl_unlock(); | |
16244 | dev_put(dev); | |
16245 | return err; | |
4c476991 JB |
16246 | } |
16247 | ||
20b0b53a JK |
16248 | static void nl80211_post_doit(const struct genl_split_ops *ops, |
16249 | struct sk_buff *skb, | |
4c476991 JB |
16250 | struct genl_info *info) |
16251 | { | |
2182db91 JB |
16252 | u32 internal_flags = nl80211_internal_flags[ops->internal_flags]; |
16253 | ||
1bf614ef | 16254 | if (info->user_ptr[1]) { |
2182db91 | 16255 | if (internal_flags & NL80211_FLAG_NEED_WDEV) { |
1bf614ef JB |
16256 | struct wireless_dev *wdev = info->user_ptr[1]; |
16257 | ||
1160dfa1 | 16258 | dev_put(wdev->netdev); |
1bf614ef JB |
16259 | } else { |
16260 | dev_put(info->user_ptr[1]); | |
16261 | } | |
16262 | } | |
5393b917 | 16263 | |
77cbf790 | 16264 | if (info->user_ptr[0] && |
2182db91 | 16265 | !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) { |
a05829a7 JB |
16266 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
16267 | ||
16268 | /* we kept the mutex locked since pre_doit */ | |
16269 | __acquire(&rdev->wiphy.mtx); | |
16270 | wiphy_unlock(&rdev->wiphy); | |
16271 | } | |
16272 | ||
2182db91 | 16273 | if (internal_flags & NL80211_FLAG_NEED_RTNL) |
4c476991 | 16274 | rtnl_unlock(); |
5393b917 JB |
16275 | |
16276 | /* If needed, clear the netlink message payload from the SKB | |
16277 | * as it might contain key data that shouldn't stick around on | |
16278 | * the heap after the SKB is freed. The netlink message header | |
16279 | * is still needed for further processing, so leave it intact. | |
16280 | */ | |
2182db91 | 16281 | if (internal_flags & NL80211_FLAG_CLEAR_SKB) { |
5393b917 JB |
16282 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
16283 | ||
16284 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
16285 | } | |
4c476991 JB |
16286 | } |
16287 | ||
6bdb68ce CH |
16288 | static int nl80211_set_sar_sub_specs(struct cfg80211_registered_device *rdev, |
16289 | struct cfg80211_sar_specs *sar_specs, | |
16290 | struct nlattr *spec[], int index) | |
16291 | { | |
16292 | u32 range_index, i; | |
16293 | ||
16294 | if (!sar_specs || !spec) | |
16295 | return -EINVAL; | |
16296 | ||
16297 | if (!spec[NL80211_SAR_ATTR_SPECS_POWER] || | |
16298 | !spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX]) | |
16299 | return -EINVAL; | |
16300 | ||
16301 | range_index = nla_get_u32(spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX]); | |
16302 | ||
16303 | /* check if range_index exceeds num_freq_ranges */ | |
16304 | if (range_index >= rdev->wiphy.sar_capa->num_freq_ranges) | |
16305 | return -EINVAL; | |
16306 | ||
16307 | /* check if range_index duplicates */ | |
16308 | for (i = 0; i < index; i++) { | |
16309 | if (sar_specs->sub_specs[i].freq_range_index == range_index) | |
16310 | return -EINVAL; | |
16311 | } | |
16312 | ||
16313 | sar_specs->sub_specs[index].power = | |
16314 | nla_get_s32(spec[NL80211_SAR_ATTR_SPECS_POWER]); | |
16315 | ||
16316 | sar_specs->sub_specs[index].freq_range_index = range_index; | |
16317 | ||
16318 | return 0; | |
16319 | } | |
16320 | ||
16321 | static int nl80211_set_sar_specs(struct sk_buff *skb, struct genl_info *info) | |
16322 | { | |
16323 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
16324 | struct nlattr *spec[NL80211_SAR_ATTR_SPECS_MAX + 1]; | |
16325 | struct nlattr *tb[NL80211_SAR_ATTR_MAX + 1]; | |
16326 | struct cfg80211_sar_specs *sar_spec; | |
16327 | enum nl80211_sar_type type; | |
16328 | struct nlattr *spec_list; | |
16329 | u32 specs; | |
16330 | int rem, err; | |
16331 | ||
16332 | if (!rdev->wiphy.sar_capa || !rdev->ops->set_sar_specs) | |
16333 | return -EOPNOTSUPP; | |
16334 | ||
16335 | if (!info->attrs[NL80211_ATTR_SAR_SPEC]) | |
16336 | return -EINVAL; | |
16337 | ||
16338 | nla_parse_nested(tb, NL80211_SAR_ATTR_MAX, | |
16339 | info->attrs[NL80211_ATTR_SAR_SPEC], | |
16340 | NULL, NULL); | |
16341 | ||
16342 | if (!tb[NL80211_SAR_ATTR_TYPE] || !tb[NL80211_SAR_ATTR_SPECS]) | |
16343 | return -EINVAL; | |
16344 | ||
16345 | type = nla_get_u32(tb[NL80211_SAR_ATTR_TYPE]); | |
16346 | if (type != rdev->wiphy.sar_capa->type) | |
16347 | return -EINVAL; | |
16348 | ||
16349 | specs = 0; | |
16350 | nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) | |
16351 | specs++; | |
16352 | ||
16353 | if (specs > rdev->wiphy.sar_capa->num_freq_ranges) | |
16354 | return -EINVAL; | |
16355 | ||
40f231e7 | 16356 | sar_spec = kzalloc(struct_size(sar_spec, sub_specs, specs), GFP_KERNEL); |
6bdb68ce CH |
16357 | if (!sar_spec) |
16358 | return -ENOMEM; | |
16359 | ||
16360 | sar_spec->type = type; | |
16361 | specs = 0; | |
16362 | nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) { | |
16363 | nla_parse_nested(spec, NL80211_SAR_ATTR_SPECS_MAX, | |
16364 | spec_list, NULL, NULL); | |
16365 | ||
16366 | switch (type) { | |
16367 | case NL80211_SAR_TYPE_POWER: | |
16368 | if (nl80211_set_sar_sub_specs(rdev, sar_spec, | |
16369 | spec, specs)) { | |
16370 | err = -EINVAL; | |
16371 | goto error; | |
16372 | } | |
16373 | break; | |
16374 | default: | |
16375 | err = -EINVAL; | |
16376 | goto error; | |
16377 | } | |
16378 | specs++; | |
16379 | } | |
16380 | ||
16381 | sar_spec->num_sub_specs = specs; | |
16382 | ||
16383 | rdev->cur_cmd_info = info; | |
16384 | err = rdev_set_sar_specs(rdev, sar_spec); | |
16385 | rdev->cur_cmd_info = NULL; | |
16386 | error: | |
16387 | kfree(sar_spec); | |
16388 | return err; | |
16389 | } | |
16390 | ||
2182db91 JB |
16391 | #define SELECTOR(__sel, name, value) \ |
16392 | ((__sel) == (value)) ? NL80211_IFL_SEL_##name : | |
16393 | int __missing_selector(void); | |
16394 | #define IFLAGS(__val) INTERNAL_FLAG_SELECTORS(__val) __missing_selector() | |
16395 | ||
4534de83 | 16396 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
16397 | { |
16398 | .cmd = NL80211_CMD_GET_WIPHY, | |
ef6243ac | 16399 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
55682965 JB |
16400 | .doit = nl80211_get_wiphy, |
16401 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 16402 | .done = nl80211_dump_wiphy_done, |
55682965 | 16403 | /* can be retrieved by unprivileged users */ |
2182db91 | 16404 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), |
55682965 | 16405 | }, |
66a9b928 JK |
16406 | }; |
16407 | ||
16408 | static const struct genl_small_ops nl80211_small_ops[] = { | |
55682965 JB |
16409 | { |
16410 | .cmd = NL80211_CMD_SET_WIPHY, | |
ef6243ac | 16411 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
55682965 | 16412 | .doit = nl80211_set_wiphy, |
5617c6cd | 16413 | .flags = GENL_UNS_ADMIN_PERM, |
55682965 JB |
16414 | }, |
16415 | { | |
16416 | .cmd = NL80211_CMD_GET_INTERFACE, | |
ef6243ac | 16417 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
55682965 JB |
16418 | .doit = nl80211_get_interface, |
16419 | .dumpit = nl80211_dump_interface, | |
55682965 | 16420 | /* can be retrieved by unprivileged users */ |
2182db91 | 16421 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV), |
55682965 JB |
16422 | }, |
16423 | { | |
16424 | .cmd = NL80211_CMD_SET_INTERFACE, | |
ef6243ac | 16425 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
55682965 | 16426 | .doit = nl80211_set_interface, |
5617c6cd | 16427 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 JB |
16428 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | |
16429 | NL80211_FLAG_NEED_RTNL), | |
55682965 JB |
16430 | }, |
16431 | { | |
16432 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
ef6243ac | 16433 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
55682965 | 16434 | .doit = nl80211_new_interface, |
5617c6cd | 16435 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 JB |
16436 | .internal_flags = |
16437 | IFLAGS(NL80211_FLAG_NEED_WIPHY | | |
16438 | NL80211_FLAG_NEED_RTNL | | |
16439 | /* we take the wiphy mutex later ourselves */ | |
16440 | NL80211_FLAG_NO_WIPHY_MTX), | |
55682965 JB |
16441 | }, |
16442 | { | |
16443 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
ef6243ac | 16444 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
55682965 | 16445 | .doit = nl80211_del_interface, |
5617c6cd | 16446 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 JB |
16447 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV | |
16448 | NL80211_FLAG_NEED_RTNL), | |
41ade00f JB |
16449 | }, |
16450 | { | |
16451 | .cmd = NL80211_CMD_GET_KEY, | |
ef6243ac | 16452 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
41ade00f | 16453 | .doit = nl80211_get_key, |
5617c6cd | 16454 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16455 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
41ade00f JB |
16456 | }, |
16457 | { | |
16458 | .cmd = NL80211_CMD_SET_KEY, | |
ef6243ac | 16459 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
41ade00f | 16460 | .doit = nl80211_set_key, |
5617c6cd | 16461 | .flags = GENL_UNS_ADMIN_PERM, |
7b0a0e3c | 16462 | /* cannot use NL80211_FLAG_MLO_VALID_LINK_ID, depends on key */ |
2182db91 JB |
16463 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
16464 | NL80211_FLAG_CLEAR_SKB), | |
41ade00f JB |
16465 | }, |
16466 | { | |
16467 | .cmd = NL80211_CMD_NEW_KEY, | |
ef6243ac | 16468 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
41ade00f | 16469 | .doit = nl80211_new_key, |
5617c6cd | 16470 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 JB |
16471 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
16472 | NL80211_FLAG_CLEAR_SKB), | |
41ade00f JB |
16473 | }, |
16474 | { | |
16475 | .cmd = NL80211_CMD_DEL_KEY, | |
ef6243ac | 16476 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
41ade00f | 16477 | .doit = nl80211_del_key, |
5617c6cd | 16478 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16479 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
55682965 | 16480 | }, |
ed1b6cc7 JB |
16481 | { |
16482 | .cmd = NL80211_CMD_SET_BEACON, | |
ef6243ac | 16483 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5617c6cd | 16484 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 16485 | .doit = nl80211_set_beacon, |
7b0a0e3c JB |
16486 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
16487 | NL80211_FLAG_MLO_VALID_LINK_ID), | |
ed1b6cc7 JB |
16488 | }, |
16489 | { | |
8860020e | 16490 | .cmd = NL80211_CMD_START_AP, |
ef6243ac | 16491 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5617c6cd | 16492 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 16493 | .doit = nl80211_start_ap, |
7b0a0e3c JB |
16494 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
16495 | NL80211_FLAG_MLO_VALID_LINK_ID), | |
ed1b6cc7 JB |
16496 | }, |
16497 | { | |
8860020e | 16498 | .cmd = NL80211_CMD_STOP_AP, |
ef6243ac | 16499 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5617c6cd | 16500 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 16501 | .doit = nl80211_stop_ap, |
7b0a0e3c JB |
16502 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
16503 | NL80211_FLAG_MLO_VALID_LINK_ID), | |
ed1b6cc7 | 16504 | }, |
5727ef1b JB |
16505 | { |
16506 | .cmd = NL80211_CMD_GET_STATION, | |
ef6243ac | 16507 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5727ef1b | 16508 | .doit = nl80211_get_station, |
2ec600d6 | 16509 | .dumpit = nl80211_dump_station, |
2182db91 | 16510 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), |
5727ef1b JB |
16511 | }, |
16512 | { | |
16513 | .cmd = NL80211_CMD_SET_STATION, | |
ef6243ac | 16514 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5727ef1b | 16515 | .doit = nl80211_set_station, |
5617c6cd | 16516 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16517 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
5727ef1b JB |
16518 | }, |
16519 | { | |
16520 | .cmd = NL80211_CMD_NEW_STATION, | |
ef6243ac | 16521 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5727ef1b | 16522 | .doit = nl80211_new_station, |
5617c6cd | 16523 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16524 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
5727ef1b JB |
16525 | }, |
16526 | { | |
16527 | .cmd = NL80211_CMD_DEL_STATION, | |
ef6243ac | 16528 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5727ef1b | 16529 | .doit = nl80211_del_station, |
5617c6cd | 16530 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16531 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
2ec600d6 LCC |
16532 | }, |
16533 | { | |
16534 | .cmd = NL80211_CMD_GET_MPATH, | |
ef6243ac | 16535 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2ec600d6 LCC |
16536 | .doit = nl80211_get_mpath, |
16537 | .dumpit = nl80211_dump_mpath, | |
5617c6cd | 16538 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16539 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
2ec600d6 | 16540 | }, |
66be7d2b HR |
16541 | { |
16542 | .cmd = NL80211_CMD_GET_MPP, | |
ef6243ac | 16543 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
66be7d2b HR |
16544 | .doit = nl80211_get_mpp, |
16545 | .dumpit = nl80211_dump_mpp, | |
5617c6cd | 16546 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16547 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
66be7d2b | 16548 | }, |
2ec600d6 LCC |
16549 | { |
16550 | .cmd = NL80211_CMD_SET_MPATH, | |
ef6243ac | 16551 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2ec600d6 | 16552 | .doit = nl80211_set_mpath, |
5617c6cd | 16553 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16554 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
2ec600d6 LCC |
16555 | }, |
16556 | { | |
16557 | .cmd = NL80211_CMD_NEW_MPATH, | |
ef6243ac | 16558 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2ec600d6 | 16559 | .doit = nl80211_new_mpath, |
5617c6cd | 16560 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16561 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
2ec600d6 LCC |
16562 | }, |
16563 | { | |
16564 | .cmd = NL80211_CMD_DEL_MPATH, | |
ef6243ac | 16565 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2ec600d6 | 16566 | .doit = nl80211_del_mpath, |
5617c6cd | 16567 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16568 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
9f1ba906 JM |
16569 | }, |
16570 | { | |
16571 | .cmd = NL80211_CMD_SET_BSS, | |
ef6243ac | 16572 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
9f1ba906 | 16573 | .doit = nl80211_set_bss, |
5617c6cd | 16574 | .flags = GENL_UNS_ADMIN_PERM, |
1e0f8cc9 JB |
16575 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
16576 | NL80211_FLAG_MLO_VALID_LINK_ID), | |
b2e1b302 | 16577 | }, |
f130347c LR |
16578 | { |
16579 | .cmd = NL80211_CMD_GET_REG, | |
ef6243ac | 16580 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
ad30ca2c AN |
16581 | .doit = nl80211_get_reg_do, |
16582 | .dumpit = nl80211_get_reg_dump, | |
f130347c LR |
16583 | /* can be retrieved by unprivileged users */ |
16584 | }, | |
b6863036 | 16585 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
b2e1b302 LR |
16586 | { |
16587 | .cmd = NL80211_CMD_SET_REG, | |
ef6243ac | 16588 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
b2e1b302 | 16589 | .doit = nl80211_set_reg, |
b2e1b302 LR |
16590 | .flags = GENL_ADMIN_PERM, |
16591 | }, | |
b6863036 | 16592 | #endif |
b2e1b302 LR |
16593 | { |
16594 | .cmd = NL80211_CMD_REQ_SET_REG, | |
ef6243ac | 16595 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
b2e1b302 | 16596 | .doit = nl80211_req_set_reg, |
93da9cc1 | 16597 | .flags = GENL_ADMIN_PERM, |
16598 | }, | |
1ea4ff3e JB |
16599 | { |
16600 | .cmd = NL80211_CMD_RELOAD_REGDB, | |
ef6243ac | 16601 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
1ea4ff3e | 16602 | .doit = nl80211_reload_regdb, |
1ea4ff3e JB |
16603 | .flags = GENL_ADMIN_PERM, |
16604 | }, | |
93da9cc1 | 16605 | { |
24bdd9f4 | 16606 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
ef6243ac | 16607 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
24bdd9f4 | 16608 | .doit = nl80211_get_mesh_config, |
93da9cc1 | 16609 | /* can be retrieved by unprivileged users */ |
2182db91 | 16610 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
93da9cc1 | 16611 | }, |
16612 | { | |
24bdd9f4 | 16613 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
ef6243ac | 16614 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
24bdd9f4 | 16615 | .doit = nl80211_update_mesh_config, |
5617c6cd | 16616 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16617 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
9aed3cc1 | 16618 | }, |
2a519311 JB |
16619 | { |
16620 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
ef6243ac | 16621 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2a519311 | 16622 | .doit = nl80211_trigger_scan, |
5617c6cd | 16623 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16624 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), |
2a519311 | 16625 | }, |
91d3ab46 VK |
16626 | { |
16627 | .cmd = NL80211_CMD_ABORT_SCAN, | |
ef6243ac | 16628 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
91d3ab46 | 16629 | .doit = nl80211_abort_scan, |
5617c6cd | 16630 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16631 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), |
91d3ab46 | 16632 | }, |
2a519311 JB |
16633 | { |
16634 | .cmd = NL80211_CMD_GET_SCAN, | |
ef6243ac | 16635 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2a519311 JB |
16636 | .dumpit = nl80211_dump_scan, |
16637 | }, | |
807f8a8c LC |
16638 | { |
16639 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
ef6243ac | 16640 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
807f8a8c | 16641 | .doit = nl80211_start_sched_scan, |
5617c6cd | 16642 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16643 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
807f8a8c LC |
16644 | }, |
16645 | { | |
16646 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
ef6243ac | 16647 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
807f8a8c | 16648 | .doit = nl80211_stop_sched_scan, |
5617c6cd | 16649 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16650 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
807f8a8c | 16651 | }, |
636a5d36 JM |
16652 | { |
16653 | .cmd = NL80211_CMD_AUTHENTICATE, | |
ef6243ac | 16654 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
636a5d36 | 16655 | .doit = nl80211_authenticate, |
5617c6cd | 16656 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 JB |
16657 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
16658 | NL80211_FLAG_CLEAR_SKB), | |
636a5d36 JM |
16659 | }, |
16660 | { | |
16661 | .cmd = NL80211_CMD_ASSOCIATE, | |
ef6243ac | 16662 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
636a5d36 | 16663 | .doit = nl80211_associate, |
5617c6cd | 16664 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 JB |
16665 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
16666 | NL80211_FLAG_CLEAR_SKB), | |
636a5d36 JM |
16667 | }, |
16668 | { | |
16669 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
ef6243ac | 16670 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
636a5d36 | 16671 | .doit = nl80211_deauthenticate, |
5617c6cd | 16672 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16673 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
636a5d36 JM |
16674 | }, |
16675 | { | |
16676 | .cmd = NL80211_CMD_DISASSOCIATE, | |
ef6243ac | 16677 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
636a5d36 | 16678 | .doit = nl80211_disassociate, |
5617c6cd | 16679 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16680 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
636a5d36 | 16681 | }, |
04a773ad JB |
16682 | { |
16683 | .cmd = NL80211_CMD_JOIN_IBSS, | |
ef6243ac | 16684 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
04a773ad | 16685 | .doit = nl80211_join_ibss, |
5617c6cd | 16686 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16687 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
04a773ad JB |
16688 | }, |
16689 | { | |
16690 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
ef6243ac | 16691 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
04a773ad | 16692 | .doit = nl80211_leave_ibss, |
5617c6cd | 16693 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16694 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
04a773ad | 16695 | }, |
aff89a9b JB |
16696 | #ifdef CONFIG_NL80211_TESTMODE |
16697 | { | |
16698 | .cmd = NL80211_CMD_TESTMODE, | |
ef6243ac | 16699 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
aff89a9b | 16700 | .doit = nl80211_testmode_do, |
71063f0e | 16701 | .dumpit = nl80211_testmode_dump, |
5617c6cd | 16702 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16703 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), |
aff89a9b JB |
16704 | }, |
16705 | #endif | |
b23aa676 SO |
16706 | { |
16707 | .cmd = NL80211_CMD_CONNECT, | |
ef6243ac | 16708 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
b23aa676 | 16709 | .doit = nl80211_connect, |
5617c6cd | 16710 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 JB |
16711 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
16712 | NL80211_FLAG_CLEAR_SKB), | |
b23aa676 | 16713 | }, |
088e8df8 | 16714 | { |
16715 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, | |
ef6243ac | 16716 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
088e8df8 | 16717 | .doit = nl80211_update_connect_params, |
088e8df8 | 16718 | .flags = GENL_ADMIN_PERM, |
2182db91 JB |
16719 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
16720 | NL80211_FLAG_CLEAR_SKB), | |
088e8df8 | 16721 | }, |
b23aa676 SO |
16722 | { |
16723 | .cmd = NL80211_CMD_DISCONNECT, | |
ef6243ac | 16724 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
b23aa676 | 16725 | .doit = nl80211_disconnect, |
5617c6cd | 16726 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16727 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
b23aa676 | 16728 | }, |
463d0183 JB |
16729 | { |
16730 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
ef6243ac | 16731 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
463d0183 | 16732 | .doit = nl80211_wiphy_netns, |
5617c6cd | 16733 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 JB |
16734 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY | |
16735 | NL80211_FLAG_NEED_RTNL | | |
16736 | NL80211_FLAG_NO_WIPHY_MTX), | |
463d0183 | 16737 | }, |
61fa713c HS |
16738 | { |
16739 | .cmd = NL80211_CMD_GET_SURVEY, | |
ef6243ac | 16740 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
61fa713c HS |
16741 | .dumpit = nl80211_dump_survey, |
16742 | }, | |
67fbb16b SO |
16743 | { |
16744 | .cmd = NL80211_CMD_SET_PMKSA, | |
ef6243ac | 16745 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
67fbb16b | 16746 | .doit = nl80211_setdel_pmksa, |
5617c6cd | 16747 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 JB |
16748 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
16749 | NL80211_FLAG_CLEAR_SKB), | |
67fbb16b SO |
16750 | }, |
16751 | { | |
16752 | .cmd = NL80211_CMD_DEL_PMKSA, | |
ef6243ac | 16753 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
67fbb16b | 16754 | .doit = nl80211_setdel_pmksa, |
5617c6cd | 16755 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16756 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
67fbb16b SO |
16757 | }, |
16758 | { | |
16759 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
ef6243ac | 16760 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
67fbb16b | 16761 | .doit = nl80211_flush_pmksa, |
5617c6cd | 16762 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16763 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
67fbb16b | 16764 | }, |
9588bbd5 JM |
16765 | { |
16766 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
ef6243ac | 16767 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
9588bbd5 | 16768 | .doit = nl80211_remain_on_channel, |
5617c6cd | 16769 | .flags = GENL_UNS_ADMIN_PERM, |
7b0a0e3c JB |
16770 | /* FIXME: requiring a link ID here is probably not good */ |
16771 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | | |
16772 | NL80211_FLAG_MLO_VALID_LINK_ID), | |
9588bbd5 JM |
16773 | }, |
16774 | { | |
16775 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
ef6243ac | 16776 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
9588bbd5 | 16777 | .doit = nl80211_cancel_remain_on_channel, |
5617c6cd | 16778 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16779 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), |
9588bbd5 | 16780 | }, |
13ae75b1 JM |
16781 | { |
16782 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
ef6243ac | 16783 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
13ae75b1 | 16784 | .doit = nl80211_set_tx_bitrate_mask, |
5617c6cd | 16785 | .flags = GENL_UNS_ADMIN_PERM, |
7b0a0e3c JB |
16786 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | |
16787 | NL80211_FLAG_MLO_VALID_LINK_ID), | |
13ae75b1 | 16788 | }, |
026331c4 | 16789 | { |
2e161f78 | 16790 | .cmd = NL80211_CMD_REGISTER_FRAME, |
ef6243ac | 16791 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2e161f78 | 16792 | .doit = nl80211_register_mgmt, |
5617c6cd | 16793 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16794 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV), |
026331c4 JM |
16795 | }, |
16796 | { | |
2e161f78 | 16797 | .cmd = NL80211_CMD_FRAME, |
ef6243ac | 16798 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2e161f78 | 16799 | .doit = nl80211_tx_mgmt, |
5617c6cd | 16800 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16801 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), |
f7ca38df JB |
16802 | }, |
16803 | { | |
16804 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
ef6243ac | 16805 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
f7ca38df | 16806 | .doit = nl80211_tx_mgmt_cancel_wait, |
5617c6cd | 16807 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16808 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), |
026331c4 | 16809 | }, |
ffb9eb3d KV |
16810 | { |
16811 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
ef6243ac | 16812 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
ffb9eb3d | 16813 | .doit = nl80211_set_power_save, |
5617c6cd | 16814 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16815 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), |
ffb9eb3d KV |
16816 | }, |
16817 | { | |
16818 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
ef6243ac | 16819 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
ffb9eb3d | 16820 | .doit = nl80211_get_power_save, |
ffb9eb3d | 16821 | /* can be retrieved by unprivileged users */ |
2182db91 | 16822 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), |
ffb9eb3d | 16823 | }, |
d6dc1a38 JO |
16824 | { |
16825 | .cmd = NL80211_CMD_SET_CQM, | |
ef6243ac | 16826 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
d6dc1a38 | 16827 | .doit = nl80211_set_cqm, |
5617c6cd | 16828 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16829 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), |
d6dc1a38 | 16830 | }, |
f444de05 JB |
16831 | { |
16832 | .cmd = NL80211_CMD_SET_CHANNEL, | |
ef6243ac | 16833 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
f444de05 | 16834 | .doit = nl80211_set_channel, |
5617c6cd | 16835 | .flags = GENL_UNS_ADMIN_PERM, |
7b0a0e3c JB |
16836 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | |
16837 | NL80211_FLAG_MLO_VALID_LINK_ID), | |
f444de05 | 16838 | }, |
29cbe68c JB |
16839 | { |
16840 | .cmd = NL80211_CMD_JOIN_MESH, | |
ef6243ac | 16841 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
29cbe68c | 16842 | .doit = nl80211_join_mesh, |
5617c6cd | 16843 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16844 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
29cbe68c JB |
16845 | }, |
16846 | { | |
16847 | .cmd = NL80211_CMD_LEAVE_MESH, | |
ef6243ac | 16848 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
29cbe68c | 16849 | .doit = nl80211_leave_mesh, |
5617c6cd | 16850 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16851 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
29cbe68c | 16852 | }, |
6e0bd6c3 RL |
16853 | { |
16854 | .cmd = NL80211_CMD_JOIN_OCB, | |
ef6243ac | 16855 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
6e0bd6c3 | 16856 | .doit = nl80211_join_ocb, |
5617c6cd | 16857 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16858 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
6e0bd6c3 RL |
16859 | }, |
16860 | { | |
16861 | .cmd = NL80211_CMD_LEAVE_OCB, | |
ef6243ac | 16862 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
6e0bd6c3 | 16863 | .doit = nl80211_leave_ocb, |
5617c6cd | 16864 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16865 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
6e0bd6c3 | 16866 | }, |
dfb89c56 | 16867 | #ifdef CONFIG_PM |
ff1b6e69 JB |
16868 | { |
16869 | .cmd = NL80211_CMD_GET_WOWLAN, | |
ef6243ac | 16870 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
ff1b6e69 | 16871 | .doit = nl80211_get_wowlan, |
ff1b6e69 | 16872 | /* can be retrieved by unprivileged users */ |
2182db91 | 16873 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), |
ff1b6e69 JB |
16874 | }, |
16875 | { | |
16876 | .cmd = NL80211_CMD_SET_WOWLAN, | |
ef6243ac | 16877 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
ff1b6e69 | 16878 | .doit = nl80211_set_wowlan, |
5617c6cd | 16879 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16880 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), |
ff1b6e69 | 16881 | }, |
dfb89c56 | 16882 | #endif |
e5497d76 JB |
16883 | { |
16884 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
ef6243ac | 16885 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
e5497d76 | 16886 | .doit = nl80211_set_rekey_data, |
5617c6cd | 16887 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 JB |
16888 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
16889 | NL80211_FLAG_CLEAR_SKB), | |
e5497d76 | 16890 | }, |
109086ce AN |
16891 | { |
16892 | .cmd = NL80211_CMD_TDLS_MGMT, | |
ef6243ac | 16893 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
109086ce | 16894 | .doit = nl80211_tdls_mgmt, |
5617c6cd | 16895 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16896 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
109086ce AN |
16897 | }, |
16898 | { | |
16899 | .cmd = NL80211_CMD_TDLS_OPER, | |
ef6243ac | 16900 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
109086ce | 16901 | .doit = nl80211_tdls_oper, |
5617c6cd | 16902 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16903 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
109086ce | 16904 | }, |
28946da7 JB |
16905 | { |
16906 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
ef6243ac | 16907 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
28946da7 | 16908 | .doit = nl80211_register_unexpected_frame, |
5617c6cd | 16909 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16910 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), |
28946da7 | 16911 | }, |
7f6cf311 JB |
16912 | { |
16913 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
ef6243ac | 16914 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
7f6cf311 | 16915 | .doit = nl80211_probe_client, |
5617c6cd | 16916 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16917 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
7f6cf311 | 16918 | }, |
5e760230 JB |
16919 | { |
16920 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
ef6243ac | 16921 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5e760230 | 16922 | .doit = nl80211_register_beacons, |
5617c6cd | 16923 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16924 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), |
5e760230 | 16925 | }, |
1d9d9213 SW |
16926 | { |
16927 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
ef6243ac | 16928 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
1d9d9213 | 16929 | .doit = nl80211_set_noack_map, |
5617c6cd | 16930 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16931 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), |
1d9d9213 | 16932 | }, |
98104fde JB |
16933 | { |
16934 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
ef6243ac | 16935 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
98104fde | 16936 | .doit = nl80211_start_p2p_device, |
5617c6cd | 16937 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 JB |
16938 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV | |
16939 | NL80211_FLAG_NEED_RTNL), | |
98104fde JB |
16940 | }, |
16941 | { | |
16942 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
ef6243ac | 16943 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
98104fde | 16944 | .doit = nl80211_stop_p2p_device, |
5617c6cd | 16945 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 JB |
16946 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | |
16947 | NL80211_FLAG_NEED_RTNL), | |
cb3b7d87 AB |
16948 | }, |
16949 | { | |
16950 | .cmd = NL80211_CMD_START_NAN, | |
ef6243ac | 16951 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
cb3b7d87 | 16952 | .doit = nl80211_start_nan, |
cb3b7d87 | 16953 | .flags = GENL_ADMIN_PERM, |
2182db91 JB |
16954 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV | |
16955 | NL80211_FLAG_NEED_RTNL), | |
cb3b7d87 AB |
16956 | }, |
16957 | { | |
16958 | .cmd = NL80211_CMD_STOP_NAN, | |
ef6243ac | 16959 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
cb3b7d87 | 16960 | .doit = nl80211_stop_nan, |
cb3b7d87 | 16961 | .flags = GENL_ADMIN_PERM, |
2182db91 JB |
16962 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | |
16963 | NL80211_FLAG_NEED_RTNL), | |
a442b761 AB |
16964 | }, |
16965 | { | |
16966 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, | |
ef6243ac | 16967 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
a442b761 | 16968 | .doit = nl80211_nan_add_func, |
a442b761 | 16969 | .flags = GENL_ADMIN_PERM, |
2182db91 | 16970 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), |
a442b761 AB |
16971 | }, |
16972 | { | |
16973 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, | |
ef6243ac | 16974 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
a442b761 | 16975 | .doit = nl80211_nan_del_func, |
a442b761 | 16976 | .flags = GENL_ADMIN_PERM, |
2182db91 | 16977 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), |
a5a9dcf2 AB |
16978 | }, |
16979 | { | |
16980 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, | |
ef6243ac | 16981 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
a5a9dcf2 | 16982 | .doit = nl80211_nan_change_config, |
a5a9dcf2 | 16983 | .flags = GENL_ADMIN_PERM, |
2182db91 | 16984 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), |
98104fde | 16985 | }, |
f4e583c8 AQ |
16986 | { |
16987 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
ef6243ac | 16988 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
f4e583c8 | 16989 | .doit = nl80211_set_mcast_rate, |
5617c6cd | 16990 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 16991 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), |
77765eaf VT |
16992 | }, |
16993 | { | |
16994 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
ef6243ac | 16995 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
77765eaf | 16996 | .doit = nl80211_set_mac_acl, |
5617c6cd | 16997 | .flags = GENL_UNS_ADMIN_PERM, |
7b0a0e3c JB |
16998 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | |
16999 | NL80211_FLAG_MLO_UNSUPPORTED), | |
f4e583c8 | 17000 | }, |
04f39047 SW |
17001 | { |
17002 | .cmd = NL80211_CMD_RADAR_DETECT, | |
ef6243ac | 17003 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
04f39047 | 17004 | .doit = nl80211_start_radar_detection, |
5617c6cd | 17005 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 17006 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
7b0a0e3c JB |
17007 | NL80211_FLAG_NO_WIPHY_MTX | |
17008 | NL80211_FLAG_MLO_UNSUPPORTED), | |
04f39047 | 17009 | }, |
3713b4e3 JB |
17010 | { |
17011 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
ef6243ac | 17012 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
3713b4e3 | 17013 | .doit = nl80211_get_protocol_features, |
3713b4e3 | 17014 | }, |
355199e0 JM |
17015 | { |
17016 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
ef6243ac | 17017 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
355199e0 | 17018 | .doit = nl80211_update_ft_ies, |
5617c6cd | 17019 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 17020 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
355199e0 | 17021 | }, |
5de17984 AS |
17022 | { |
17023 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
ef6243ac | 17024 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5de17984 | 17025 | .doit = nl80211_crit_protocol_start, |
5617c6cd | 17026 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 17027 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), |
5de17984 AS |
17028 | }, |
17029 | { | |
17030 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
ef6243ac | 17031 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
5de17984 | 17032 | .doit = nl80211_crit_protocol_stop, |
5617c6cd | 17033 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 17034 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), |
be29b99a AK |
17035 | }, |
17036 | { | |
17037 | .cmd = NL80211_CMD_GET_COALESCE, | |
ef6243ac | 17038 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
be29b99a | 17039 | .doit = nl80211_get_coalesce, |
2182db91 | 17040 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), |
be29b99a AK |
17041 | }, |
17042 | { | |
17043 | .cmd = NL80211_CMD_SET_COALESCE, | |
ef6243ac | 17044 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
be29b99a | 17045 | .doit = nl80211_set_coalesce, |
5617c6cd | 17046 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 17047 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), |
16ef1fe2 SW |
17048 | }, |
17049 | { | |
17050 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
ef6243ac | 17051 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
16ef1fe2 | 17052 | .doit = nl80211_channel_switch, |
5617c6cd | 17053 | .flags = GENL_UNS_ADMIN_PERM, |
7b0a0e3c JB |
17054 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
17055 | NL80211_FLAG_MLO_VALID_LINK_ID), | |
16ef1fe2 | 17056 | }, |
ad7e718c JB |
17057 | { |
17058 | .cmd = NL80211_CMD_VENDOR, | |
ef6243ac | 17059 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
ad7e718c | 17060 | .doit = nl80211_vendor_cmd, |
7bdbe400 | 17061 | .dumpit = nl80211_vendor_cmd_dump, |
5617c6cd | 17062 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 JB |
17063 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY | |
17064 | NL80211_FLAG_CLEAR_SKB), | |
ad7e718c | 17065 | }, |
fa9ffc74 KP |
17066 | { |
17067 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
ef6243ac | 17068 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
fa9ffc74 | 17069 | .doit = nl80211_set_qos_map, |
5617c6cd | 17070 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 17071 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
fa9ffc74 | 17072 | }, |
960d01ac JB |
17073 | { |
17074 | .cmd = NL80211_CMD_ADD_TX_TS, | |
ef6243ac | 17075 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
960d01ac | 17076 | .doit = nl80211_add_tx_ts, |
5617c6cd | 17077 | .flags = GENL_UNS_ADMIN_PERM, |
7b0a0e3c JB |
17078 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
17079 | NL80211_FLAG_MLO_UNSUPPORTED), | |
960d01ac JB |
17080 | }, |
17081 | { | |
17082 | .cmd = NL80211_CMD_DEL_TX_TS, | |
ef6243ac | 17083 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
960d01ac | 17084 | .doit = nl80211_del_tx_ts, |
5617c6cd | 17085 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 17086 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
960d01ac | 17087 | }, |
1057d35e AN |
17088 | { |
17089 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | |
ef6243ac | 17090 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
1057d35e | 17091 | .doit = nl80211_tdls_channel_switch, |
5617c6cd | 17092 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 17093 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
1057d35e AN |
17094 | }, |
17095 | { | |
17096 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | |
ef6243ac | 17097 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
1057d35e | 17098 | .doit = nl80211_tdls_cancel_channel_switch, |
5617c6cd | 17099 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 17100 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
1057d35e | 17101 | }, |
ce0ce13a MB |
17102 | { |
17103 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, | |
ef6243ac | 17104 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
ce0ce13a | 17105 | .doit = nl80211_set_multicast_to_unicast, |
ce0ce13a | 17106 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 17107 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), |
ce0ce13a | 17108 | }, |
3a00df57 AS |
17109 | { |
17110 | .cmd = NL80211_CMD_SET_PMK, | |
ef6243ac | 17111 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
3a00df57 | 17112 | .doit = nl80211_set_pmk, |
2182db91 JB |
17113 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
17114 | NL80211_FLAG_CLEAR_SKB), | |
3a00df57 AS |
17115 | }, |
17116 | { | |
17117 | .cmd = NL80211_CMD_DEL_PMK, | |
ef6243ac | 17118 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
3a00df57 | 17119 | .doit = nl80211_del_pmk, |
2182db91 | 17120 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
3a00df57 | 17121 | }, |
40cbfa90 SD |
17122 | { |
17123 | .cmd = NL80211_CMD_EXTERNAL_AUTH, | |
ef6243ac | 17124 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
40cbfa90 | 17125 | .doit = nl80211_external_auth, |
40cbfa90 | 17126 | .flags = GENL_ADMIN_PERM, |
2182db91 | 17127 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
40cbfa90 | 17128 | }, |
2576a9ac DK |
17129 | { |
17130 | .cmd = NL80211_CMD_CONTROL_PORT_FRAME, | |
ef6243ac | 17131 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
2576a9ac | 17132 | .doit = nl80211_tx_control_port, |
2576a9ac | 17133 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 17134 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
2576a9ac | 17135 | }, |
81e54d08 PKC |
17136 | { |
17137 | .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, | |
ef6243ac | 17138 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
81e54d08 | 17139 | .doit = nl80211_get_ftm_responder_stats, |
7b0a0e3c JB |
17140 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | |
17141 | NL80211_FLAG_MLO_VALID_LINK_ID), | |
81e54d08 | 17142 | }, |
9bb7e0f2 JB |
17143 | { |
17144 | .cmd = NL80211_CMD_PEER_MEASUREMENT_START, | |
ef6243ac | 17145 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
9bb7e0f2 | 17146 | .doit = nl80211_pmsr_start, |
9bb7e0f2 | 17147 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 17148 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), |
9bb7e0f2 | 17149 | }, |
30c63115 S |
17150 | { |
17151 | .cmd = NL80211_CMD_NOTIFY_RADAR, | |
ef6243ac | 17152 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
30c63115 | 17153 | .doit = nl80211_notify_radar_detection, |
30c63115 | 17154 | .flags = GENL_UNS_ADMIN_PERM, |
2182db91 | 17155 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
30c63115 | 17156 | }, |
cb74e977 SD |
17157 | { |
17158 | .cmd = NL80211_CMD_UPDATE_OWE_INFO, | |
17159 | .doit = nl80211_update_owe_info, | |
17160 | .flags = GENL_ADMIN_PERM, | |
2182db91 | 17161 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
5ab92e7f RM |
17162 | }, |
17163 | { | |
17164 | .cmd = NL80211_CMD_PROBE_MESH_LINK, | |
17165 | .doit = nl80211_probe_mesh_link, | |
17166 | .flags = GENL_UNS_ADMIN_PERM, | |
2182db91 | 17167 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
cb74e977 | 17168 | }, |
77f576de T |
17169 | { |
17170 | .cmd = NL80211_CMD_SET_TID_CONFIG, | |
17171 | .doit = nl80211_set_tid_config, | |
17172 | .flags = GENL_UNS_ADMIN_PERM, | |
7b0a0e3c JB |
17173 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | |
17174 | NL80211_FLAG_MLO_VALID_LINK_ID), | |
77f576de | 17175 | }, |
6bdb68ce CH |
17176 | { |
17177 | .cmd = NL80211_CMD_SET_SAR_SPECS, | |
17178 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, | |
17179 | .doit = nl80211_set_sar_specs, | |
17180 | .flags = GENL_UNS_ADMIN_PERM, | |
2182db91 JB |
17181 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY | |
17182 | NL80211_FLAG_NEED_RTNL), | |
6bdb68ce | 17183 | }, |
0d2ab3ae JC |
17184 | { |
17185 | .cmd = NL80211_CMD_COLOR_CHANGE_REQUEST, | |
17186 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, | |
17187 | .doit = nl80211_color_change, | |
17188 | .flags = GENL_UNS_ADMIN_PERM, | |
2182db91 | 17189 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
0d2ab3ae | 17190 | }, |
e306784a SM |
17191 | { |
17192 | .cmd = NL80211_CMD_SET_FILS_AAD, | |
17193 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, | |
17194 | .doit = nl80211_set_fils_aad, | |
17195 | .flags = GENL_UNS_ADMIN_PERM, | |
2182db91 | 17196 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), |
e306784a | 17197 | }, |
7b0a0e3c JB |
17198 | { |
17199 | .cmd = NL80211_CMD_ADD_LINK, | |
17200 | .doit = nl80211_add_link, | |
17201 | .flags = GENL_UNS_ADMIN_PERM, | |
17202 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), | |
17203 | }, | |
17204 | { | |
17205 | .cmd = NL80211_CMD_REMOVE_LINK, | |
17206 | .doit = nl80211_remove_link, | |
17207 | .flags = GENL_UNS_ADMIN_PERM, | |
577e5b8c ST |
17208 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
17209 | NL80211_FLAG_MLO_VALID_LINK_ID), | |
17210 | }, | |
17211 | { | |
17212 | .cmd = NL80211_CMD_ADD_LINK_STA, | |
17213 | .doit = nl80211_add_link_station, | |
17214 | .flags = GENL_UNS_ADMIN_PERM, | |
17215 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | | |
17216 | NL80211_FLAG_MLO_VALID_LINK_ID), | |
17217 | }, | |
17218 | { | |
17219 | .cmd = NL80211_CMD_MODIFY_LINK_STA, | |
17220 | .doit = nl80211_modify_link_station, | |
17221 | .flags = GENL_UNS_ADMIN_PERM, | |
17222 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | | |
17223 | NL80211_FLAG_MLO_VALID_LINK_ID), | |
17224 | }, | |
17225 | { | |
17226 | .cmd = NL80211_CMD_REMOVE_LINK_STA, | |
17227 | .doit = nl80211_remove_link_station, | |
17228 | .flags = GENL_UNS_ADMIN_PERM, | |
7b0a0e3c JB |
17229 | .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | |
17230 | NL80211_FLAG_MLO_VALID_LINK_ID), | |
17231 | }, | |
55682965 | 17232 | }; |
9588bbd5 | 17233 | |
56989f6d | 17234 | static struct genl_family nl80211_fam __ro_after_init = { |
489111e5 JB |
17235 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
17236 | .hdrsize = 0, /* no private header */ | |
17237 | .version = 1, /* no particular meaning now */ | |
17238 | .maxattr = NL80211_ATTR_MAX, | |
3b0f31f2 | 17239 | .policy = nl80211_policy, |
489111e5 JB |
17240 | .netnsok = true, |
17241 | .pre_doit = nl80211_pre_doit, | |
17242 | .post_doit = nl80211_post_doit, | |
17243 | .module = THIS_MODULE, | |
17244 | .ops = nl80211_ops, | |
17245 | .n_ops = ARRAY_SIZE(nl80211_ops), | |
66a9b928 JK |
17246 | .small_ops = nl80211_small_ops, |
17247 | .n_small_ops = ARRAY_SIZE(nl80211_small_ops), | |
9c5d03d3 | 17248 | .resv_start_op = NL80211_CMD_REMOVE_LINK_STA + 1, |
489111e5 JB |
17249 | .mcgrps = nl80211_mcgrps, |
17250 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), | |
50508d94 | 17251 | .parallel_ops = true, |
489111e5 JB |
17252 | }; |
17253 | ||
55682965 JB |
17254 | /* notification functions */ |
17255 | ||
3bb20556 JB |
17256 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
17257 | enum nl80211_commands cmd) | |
55682965 JB |
17258 | { |
17259 | struct sk_buff *msg; | |
86e8cf98 | 17260 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 17261 | |
3bb20556 JB |
17262 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
17263 | cmd != NL80211_CMD_DEL_WIPHY); | |
17264 | ||
fd2120ca | 17265 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
17266 | if (!msg) |
17267 | return; | |
17268 | ||
3bb20556 | 17269 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
17270 | nlmsg_free(msg); |
17271 | return; | |
17272 | } | |
17273 | ||
68eb5503 | 17274 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 17275 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
17276 | } |
17277 | ||
896ff063 DK |
17278 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
17279 | struct wireless_dev *wdev, | |
17280 | enum nl80211_commands cmd) | |
17281 | { | |
17282 | struct sk_buff *msg; | |
17283 | ||
896ff063 DK |
17284 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
17285 | if (!msg) | |
17286 | return; | |
17287 | ||
3d1a5bbf | 17288 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) { |
896ff063 DK |
17289 | nlmsg_free(msg); |
17290 | return; | |
17291 | } | |
17292 | ||
17293 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | |
17294 | NL80211_MCGRP_CONFIG, GFP_KERNEL); | |
17295 | } | |
17296 | ||
362a415d JB |
17297 | static int nl80211_add_scan_req(struct sk_buff *msg, |
17298 | struct cfg80211_registered_device *rdev) | |
17299 | { | |
17300 | struct cfg80211_scan_request *req = rdev->scan_req; | |
17301 | struct nlattr *nest; | |
17302 | int i; | |
c8cb5b85 | 17303 | struct cfg80211_scan_info *info; |
362a415d JB |
17304 | |
17305 | if (WARN_ON(!req)) | |
17306 | return 0; | |
17307 | ||
ae0be8de | 17308 | nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS); |
362a415d JB |
17309 | if (!nest) |
17310 | goto nla_put_failure; | |
9360ffd1 DM |
17311 | for (i = 0; i < req->n_ssids; i++) { |
17312 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
17313 | goto nla_put_failure; | |
17314 | } | |
362a415d JB |
17315 | nla_nest_end(msg, nest); |
17316 | ||
2032f3b2 TP |
17317 | if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) { |
17318 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ); | |
17319 | if (!nest) | |
17320 | goto nla_put_failure; | |
17321 | for (i = 0; i < req->n_channels; i++) { | |
17322 | if (nla_put_u32(msg, i, | |
17323 | ieee80211_channel_to_khz(req->channels[i]))) | |
17324 | goto nla_put_failure; | |
17325 | } | |
17326 | nla_nest_end(msg, nest); | |
17327 | } else { | |
17328 | nest = nla_nest_start_noflag(msg, | |
17329 | NL80211_ATTR_SCAN_FREQUENCIES); | |
17330 | if (!nest) | |
9360ffd1 | 17331 | goto nla_put_failure; |
2032f3b2 TP |
17332 | for (i = 0; i < req->n_channels; i++) { |
17333 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
17334 | goto nla_put_failure; | |
17335 | } | |
17336 | nla_nest_end(msg, nest); | |
9360ffd1 | 17337 | } |
362a415d | 17338 | |
9360ffd1 DM |
17339 | if (req->ie && |
17340 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
17341 | goto nla_put_failure; | |
362a415d | 17342 | |
ae917c9f JB |
17343 | if (req->flags && |
17344 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
17345 | goto nla_put_failure; | |
ed473771 | 17346 | |
c8cb5b85 TM |
17347 | info = rdev->int_scan_req ? &rdev->int_scan_req->info : |
17348 | &rdev->scan_req->info; | |
17349 | if (info->scan_start_tsf && | |
1d76250b | 17350 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
c8cb5b85 | 17351 | info->scan_start_tsf, NL80211_BSS_PAD) || |
1d76250b | 17352 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
c8cb5b85 | 17353 | info->tsf_bssid))) |
1d76250b AS |
17354 | goto nla_put_failure; |
17355 | ||
362a415d JB |
17356 | return 0; |
17357 | nla_put_failure: | |
17358 | return -ENOBUFS; | |
17359 | } | |
17360 | ||
505a2e88 | 17361 | static int nl80211_prep_scan_msg(struct sk_buff *msg, |
a538e2d5 | 17362 | struct cfg80211_registered_device *rdev, |
fd014284 | 17363 | struct wireless_dev *wdev, |
15e47304 | 17364 | u32 portid, u32 seq, int flags, |
a538e2d5 | 17365 | u32 cmd) |
2a519311 JB |
17366 | { |
17367 | void *hdr; | |
17368 | ||
15e47304 | 17369 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
17370 | if (!hdr) |
17371 | return -1; | |
17372 | ||
9360ffd1 | 17373 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
17374 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
17375 | wdev->netdev->ifindex)) || | |
2dad624e ND |
17376 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
17377 | NL80211_ATTR_PAD)) | |
9360ffd1 | 17378 | goto nla_put_failure; |
2a519311 | 17379 | |
362a415d JB |
17380 | /* ignore errors and send incomplete event anyway */ |
17381 | nl80211_add_scan_req(msg, rdev); | |
2a519311 | 17382 | |
053c095a JB |
17383 | genlmsg_end(msg, hdr); |
17384 | return 0; | |
2a519311 JB |
17385 | |
17386 | nla_put_failure: | |
17387 | genlmsg_cancel(msg, hdr); | |
17388 | return -EMSGSIZE; | |
17389 | } | |
17390 | ||
807f8a8c | 17391 | static int |
505a2e88 | 17392 | nl80211_prep_sched_scan_msg(struct sk_buff *msg, |
96b08fd6 | 17393 | struct cfg80211_sched_scan_request *req, u32 cmd) |
807f8a8c LC |
17394 | { |
17395 | void *hdr; | |
17396 | ||
96b08fd6 | 17397 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
807f8a8c LC |
17398 | if (!hdr) |
17399 | return -1; | |
17400 | ||
96b08fd6 AVS |
17401 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, |
17402 | wiphy_to_rdev(req->wiphy)->wiphy_idx) || | |
17403 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || | |
17404 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, | |
17405 | NL80211_ATTR_PAD)) | |
9360ffd1 | 17406 | goto nla_put_failure; |
807f8a8c | 17407 | |
053c095a JB |
17408 | genlmsg_end(msg, hdr); |
17409 | return 0; | |
807f8a8c LC |
17410 | |
17411 | nla_put_failure: | |
17412 | genlmsg_cancel(msg, hdr); | |
17413 | return -EMSGSIZE; | |
17414 | } | |
17415 | ||
a538e2d5 | 17416 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 17417 | struct wireless_dev *wdev) |
a538e2d5 JB |
17418 | { |
17419 | struct sk_buff *msg; | |
17420 | ||
58050fce | 17421 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
17422 | if (!msg) |
17423 | return; | |
17424 | ||
505a2e88 | 17425 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
17426 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
17427 | nlmsg_free(msg); | |
17428 | return; | |
17429 | } | |
17430 | ||
68eb5503 | 17431 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 17432 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
17433 | } |
17434 | ||
f9d15d16 JB |
17435 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
17436 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
17437 | { |
17438 | struct sk_buff *msg; | |
17439 | ||
fd2120ca | 17440 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 17441 | if (!msg) |
f9d15d16 | 17442 | return NULL; |
2a519311 | 17443 | |
505a2e88 | 17444 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
17445 | aborted ? NL80211_CMD_SCAN_ABORTED : |
17446 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 17447 | nlmsg_free(msg); |
f9d15d16 | 17448 | return NULL; |
2a519311 JB |
17449 | } |
17450 | ||
f9d15d16 | 17451 | return msg; |
2a519311 JB |
17452 | } |
17453 | ||
505a2e88 AVS |
17454 | /* send message created by nl80211_build_scan_msg() */ |
17455 | void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, | |
17456 | struct sk_buff *msg) | |
807f8a8c | 17457 | { |
807f8a8c LC |
17458 | if (!msg) |
17459 | return; | |
17460 | ||
68eb5503 | 17461 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 17462 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
17463 | } |
17464 | ||
96b08fd6 | 17465 | void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd) |
807f8a8c LC |
17466 | { |
17467 | struct sk_buff *msg; | |
17468 | ||
58050fce | 17469 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
17470 | if (!msg) |
17471 | return; | |
17472 | ||
96b08fd6 | 17473 | if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { |
807f8a8c LC |
17474 | nlmsg_free(msg); |
17475 | return; | |
17476 | } | |
17477 | ||
96b08fd6 | 17478 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, |
2a94fe48 | 17479 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
17480 | } |
17481 | ||
b0d7aa59 JD |
17482 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
17483 | struct regulatory_request *request) | |
73d54c9e | 17484 | { |
73d54c9e | 17485 | /* Userspace can always count this one always being set */ |
9360ffd1 DM |
17486 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
17487 | goto nla_put_failure; | |
17488 | ||
17489 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
17490 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
17491 | NL80211_REGDOM_TYPE_WORLD)) | |
17492 | goto nla_put_failure; | |
17493 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
17494 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
17495 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
17496 | goto nla_put_failure; | |
17497 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
17498 | request->intersect) { | |
17499 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
17500 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
17501 | goto nla_put_failure; | |
17502 | } else { | |
17503 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
17504 | NL80211_REGDOM_TYPE_COUNTRY) || | |
17505 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
17506 | request->alpha2)) | |
17507 | goto nla_put_failure; | |
17508 | } | |
17509 | ||
ad30ca2c AN |
17510 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
17511 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | |
17512 | ||
17513 | if (wiphy && | |
17514 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
17515 | goto nla_put_failure; | |
1bdd716c AN |
17516 | |
17517 | if (wiphy && | |
17518 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | |
17519 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
17520 | goto nla_put_failure; | |
ad30ca2c | 17521 | } |
73d54c9e | 17522 | |
b0d7aa59 JD |
17523 | return true; |
17524 | ||
17525 | nla_put_failure: | |
17526 | return false; | |
17527 | } | |
17528 | ||
17529 | /* | |
17530 | * This can happen on global regulatory changes or device specific settings | |
17531 | * based on custom regulatory domains. | |
17532 | */ | |
17533 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | |
17534 | struct regulatory_request *request) | |
17535 | { | |
17536 | struct sk_buff *msg; | |
17537 | void *hdr; | |
17538 | ||
17539 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
17540 | if (!msg) | |
17541 | return; | |
17542 | ||
17543 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | |
24f6d765 | 17544 | if (!hdr) |
17545 | goto nla_put_failure; | |
b0d7aa59 | 17546 | |
24f6d765 | 17547 | if (!nl80211_reg_change_event_fill(msg, request)) |
b0d7aa59 JD |
17548 | goto nla_put_failure; |
17549 | ||
3b7b72ee | 17550 | genlmsg_end(msg, hdr); |
73d54c9e | 17551 | |
bc43b28c | 17552 | rcu_read_lock(); |
68eb5503 | 17553 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 17554 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 17555 | rcu_read_unlock(); |
73d54c9e LR |
17556 | |
17557 | return; | |
17558 | ||
17559 | nla_put_failure: | |
73d54c9e LR |
17560 | nlmsg_free(msg); |
17561 | } | |
17562 | ||
6039f6d2 JM |
17563 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
17564 | struct net_device *netdev, | |
17565 | const u8 *buf, size_t len, | |
b0b6aa2c | 17566 | enum nl80211_commands cmd, gfp_t gfp, |
4d9ec73d | 17567 | int uapsd_queues, const u8 *req_ies, |
3bb02143 | 17568 | size_t req_ies_len, bool reconnect) |
6039f6d2 JM |
17569 | { |
17570 | struct sk_buff *msg; | |
17571 | void *hdr; | |
17572 | ||
4d9ec73d | 17573 | msg = nlmsg_new(100 + len + req_ies_len, gfp); |
6039f6d2 JM |
17574 | if (!msg) |
17575 | return; | |
17576 | ||
17577 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
17578 | if (!hdr) { | |
17579 | nlmsg_free(msg); | |
17580 | return; | |
17581 | } | |
17582 | ||
9360ffd1 DM |
17583 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
17584 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
4d9ec73d JM |
17585 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
17586 | (req_ies && | |
17587 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies))) | |
9360ffd1 | 17588 | goto nla_put_failure; |
6039f6d2 | 17589 | |
3bb02143 JB |
17590 | if (reconnect && nla_put_flag(msg, NL80211_ATTR_RECONNECT_REQUESTED)) |
17591 | goto nla_put_failure; | |
17592 | ||
b0b6aa2c EP |
17593 | if (uapsd_queues >= 0) { |
17594 | struct nlattr *nla_wmm = | |
ae0be8de | 17595 | nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME); |
b0b6aa2c EP |
17596 | if (!nla_wmm) |
17597 | goto nla_put_failure; | |
17598 | ||
17599 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
17600 | uapsd_queues)) | |
17601 | goto nla_put_failure; | |
17602 | ||
17603 | nla_nest_end(msg, nla_wmm); | |
17604 | } | |
17605 | ||
3b7b72ee | 17606 | genlmsg_end(msg, hdr); |
6039f6d2 | 17607 | |
68eb5503 | 17608 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 17609 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
17610 | return; |
17611 | ||
17612 | nla_put_failure: | |
6039f6d2 JM |
17613 | nlmsg_free(msg); |
17614 | } | |
17615 | ||
17616 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
17617 | struct net_device *netdev, const u8 *buf, |
17618 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
17619 | { |
17620 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
3bb02143 JB |
17621 | NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0, |
17622 | false); | |
6039f6d2 JM |
17623 | } |
17624 | ||
17625 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
cd47c0f5 JB |
17626 | struct net_device *netdev, |
17627 | struct cfg80211_rx_assoc_resp *data) | |
6039f6d2 | 17628 | { |
cd47c0f5 JB |
17629 | nl80211_send_mlme_event(rdev, netdev, data->buf, data->len, |
17630 | NL80211_CMD_ASSOCIATE, GFP_KERNEL, | |
17631 | data->uapsd_queues, | |
17632 | data->req_ies, data->req_ies_len, false); | |
6039f6d2 JM |
17633 | } |
17634 | ||
53b46b84 | 17635 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 | 17636 | struct net_device *netdev, const u8 *buf, |
3bb02143 | 17637 | size_t len, bool reconnect, gfp_t gfp) |
6039f6d2 JM |
17638 | { |
17639 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
3bb02143 JB |
17640 | NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0, |
17641 | reconnect); | |
6039f6d2 JM |
17642 | } |
17643 | ||
53b46b84 JM |
17644 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
17645 | struct net_device *netdev, const u8 *buf, | |
3bb02143 | 17646 | size_t len, bool reconnect, gfp_t gfp) |
6039f6d2 JM |
17647 | { |
17648 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
3bb02143 JB |
17649 | NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0, |
17650 | reconnect); | |
6039f6d2 JM |
17651 | } |
17652 | ||
6ff57cf8 JB |
17653 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
17654 | size_t len) | |
cf4e594e | 17655 | { |
947add36 JB |
17656 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
17657 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 17658 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
17659 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
17660 | u32 cmd; | |
947add36 | 17661 | |
6ff57cf8 JB |
17662 | if (WARN_ON(len < 2)) |
17663 | return; | |
cf4e594e | 17664 | |
4d797fce | 17665 | if (ieee80211_is_deauth(mgmt->frame_control)) { |
6ff57cf8 | 17666 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
4d797fce | 17667 | } else if (ieee80211_is_disassoc(mgmt->frame_control)) { |
6ff57cf8 | 17668 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
4d797fce JM |
17669 | } else if (ieee80211_is_beacon(mgmt->frame_control)) { |
17670 | if (wdev->unprot_beacon_reported && | |
17671 | elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000) | |
17672 | return; | |
17673 | cmd = NL80211_CMD_UNPROT_BEACON; | |
17674 | wdev->unprot_beacon_reported = jiffies; | |
17675 | } else { | |
17676 | return; | |
17677 | } | |
947add36 | 17678 | |
6ff57cf8 | 17679 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
4d9ec73d | 17680 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1, |
3bb02143 | 17681 | NULL, 0, false); |
cf4e594e | 17682 | } |
6ff57cf8 | 17683 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 17684 | |
1b06bb40 LR |
17685 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
17686 | struct net_device *netdev, int cmd, | |
e6d6e342 | 17687 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
17688 | { |
17689 | struct sk_buff *msg; | |
17690 | void *hdr; | |
17691 | ||
e6d6e342 | 17692 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
17693 | if (!msg) |
17694 | return; | |
17695 | ||
17696 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
17697 | if (!hdr) { | |
17698 | nlmsg_free(msg); | |
17699 | return; | |
17700 | } | |
17701 | ||
9360ffd1 DM |
17702 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
17703 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
17704 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
17705 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
17706 | goto nla_put_failure; | |
1965c853 | 17707 | |
3b7b72ee | 17708 | genlmsg_end(msg, hdr); |
1965c853 | 17709 | |
68eb5503 | 17710 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 17711 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
17712 | return; |
17713 | ||
17714 | nla_put_failure: | |
1965c853 JM |
17715 | nlmsg_free(msg); |
17716 | } | |
17717 | ||
17718 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
17719 | struct net_device *netdev, const u8 *addr, |
17720 | gfp_t gfp) | |
1965c853 JM |
17721 | { |
17722 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 17723 | addr, gfp); |
1965c853 JM |
17724 | } |
17725 | ||
17726 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
17727 | struct net_device *netdev, const u8 *addr, |
17728 | gfp_t gfp) | |
1965c853 | 17729 | { |
e6d6e342 JB |
17730 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
17731 | addr, gfp); | |
1965c853 JM |
17732 | } |
17733 | ||
b23aa676 | 17734 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
5349a0f7 VK |
17735 | struct net_device *netdev, |
17736 | struct cfg80211_connect_resp_params *cr, | |
3093ebbe | 17737 | gfp_t gfp) |
b23aa676 SO |
17738 | { |
17739 | struct sk_buff *msg; | |
17740 | void *hdr; | |
efbabc11 VJ |
17741 | unsigned int link; |
17742 | size_t link_info_size = 0; | |
17743 | const u8 *connected_addr = cr->valid_links ? | |
17744 | cr->ap_mld_addr : cr->links[0].bssid; | |
17745 | ||
17746 | if (cr->valid_links) { | |
17747 | for_each_valid_link(cr, link) { | |
17748 | /* Nested attribute header */ | |
17749 | link_info_size += NLA_HDRLEN; | |
17750 | /* Link ID */ | |
17751 | link_info_size += nla_total_size(sizeof(u8)); | |
17752 | link_info_size += cr->links[link].addr ? | |
17753 | nla_total_size(ETH_ALEN) : 0; | |
17754 | link_info_size += (cr->links[link].bssid || | |
17755 | cr->links[link].bss) ? | |
17756 | nla_total_size(ETH_ALEN) : 0; | |
53ad07e9 | 17757 | link_info_size += nla_total_size(sizeof(u16)); |
efbabc11 VJ |
17758 | } |
17759 | } | |
b23aa676 | 17760 | |
a3caf744 | 17761 | msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + |
76804d28 | 17762 | cr->fils.kek_len + cr->fils.pmk_len + |
efbabc11 VJ |
17763 | (cr->fils.pmkid ? WLAN_PMKID_LEN : 0) + link_info_size, |
17764 | gfp); | |
b23aa676 SO |
17765 | if (!msg) |
17766 | return; | |
17767 | ||
17768 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
17769 | if (!hdr) { | |
17770 | nlmsg_free(msg); | |
17771 | return; | |
17772 | } | |
17773 | ||
9360ffd1 DM |
17774 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
17775 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
efbabc11 VJ |
17776 | (connected_addr && |
17777 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr)) || | |
bf1ecd21 | 17778 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
5349a0f7 VK |
17779 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
17780 | cr->status) || | |
17781 | (cr->status < 0 && | |
3093ebbe | 17782 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
5349a0f7 VK |
17783 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, |
17784 | cr->timeout_reason))) || | |
17785 | (cr->req_ie && | |
17786 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || | |
17787 | (cr->resp_ie && | |
17788 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, | |
a3caf744 | 17789 | cr->resp_ie)) || |
76804d28 | 17790 | (cr->fils.update_erp_next_seq_num && |
a3caf744 | 17791 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
76804d28 | 17792 | cr->fils.erp_next_seq_num)) || |
a3caf744 | 17793 | (cr->status == WLAN_STATUS_SUCCESS && |
76804d28 AVS |
17794 | ((cr->fils.kek && |
17795 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, | |
17796 | cr->fils.kek)) || | |
17797 | (cr->fils.pmk && | |
17798 | nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || | |
17799 | (cr->fils.pmkid && | |
17800 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid))))) | |
9360ffd1 | 17801 | goto nla_put_failure; |
b23aa676 | 17802 | |
efbabc11 VJ |
17803 | if (cr->valid_links) { |
17804 | int i = 1; | |
17805 | struct nlattr *nested; | |
17806 | ||
17807 | nested = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS); | |
17808 | if (!nested) | |
17809 | goto nla_put_failure; | |
17810 | ||
17811 | for_each_valid_link(cr, link) { | |
17812 | struct nlattr *nested_mlo_links; | |
17813 | const u8 *bssid = cr->links[link].bss ? | |
17814 | cr->links[link].bss->bssid : | |
17815 | cr->links[link].bssid; | |
17816 | ||
17817 | nested_mlo_links = nla_nest_start(msg, i); | |
17818 | if (!nested_mlo_links) | |
17819 | goto nla_put_failure; | |
17820 | ||
17821 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link) || | |
17822 | (bssid && | |
17823 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, bssid)) || | |
17824 | (cr->links[link].addr && | |
17825 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, | |
53ad07e9 JB |
17826 | cr->links[link].addr)) || |
17827 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, | |
17828 | cr->links[link].status)) | |
efbabc11 VJ |
17829 | goto nla_put_failure; |
17830 | ||
17831 | nla_nest_end(msg, nested_mlo_links); | |
17832 | i++; | |
17833 | } | |
17834 | nla_nest_end(msg, nested); | |
17835 | } | |
17836 | ||
3b7b72ee | 17837 | genlmsg_end(msg, hdr); |
b23aa676 | 17838 | |
68eb5503 | 17839 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 17840 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
17841 | return; |
17842 | ||
17843 | nla_put_failure: | |
b23aa676 | 17844 | nlmsg_free(msg); |
b23aa676 SO |
17845 | } |
17846 | ||
17847 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
29ce6ecb AS |
17848 | struct net_device *netdev, |
17849 | struct cfg80211_roam_info *info, gfp_t gfp) | |
b23aa676 SO |
17850 | { |
17851 | struct sk_buff *msg; | |
17852 | void *hdr; | |
efbabc11 VJ |
17853 | size_t link_info_size = 0; |
17854 | unsigned int link; | |
17855 | const u8 *connected_addr = info->ap_mld_addr ? | |
17856 | info->ap_mld_addr : | |
17857 | (info->links[0].bss ? | |
17858 | info->links[0].bss->bssid : | |
17859 | info->links[0].bssid); | |
17860 | ||
17861 | if (info->valid_links) { | |
17862 | for_each_valid_link(info, link) { | |
17863 | /* Nested attribute header */ | |
17864 | link_info_size += NLA_HDRLEN; | |
17865 | /* Link ID */ | |
17866 | link_info_size += nla_total_size(sizeof(u8)); | |
17867 | link_info_size += info->links[link].addr ? | |
17868 | nla_total_size(ETH_ALEN) : 0; | |
17869 | link_info_size += (info->links[link].bssid || | |
17870 | info->links[link].bss) ? | |
17871 | nla_total_size(ETH_ALEN) : 0; | |
17872 | } | |
17873 | } | |
b23aa676 | 17874 | |
e841b7b1 AVS |
17875 | msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + |
17876 | info->fils.kek_len + info->fils.pmk_len + | |
efbabc11 VJ |
17877 | (info->fils.pmkid ? WLAN_PMKID_LEN : 0) + |
17878 | link_info_size, gfp); | |
b23aa676 SO |
17879 | if (!msg) |
17880 | return; | |
17881 | ||
17882 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
17883 | if (!hdr) { | |
17884 | nlmsg_free(msg); | |
17885 | return; | |
17886 | } | |
17887 | ||
9360ffd1 DM |
17888 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
17889 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
efbabc11 | 17890 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr) || |
29ce6ecb AS |
17891 | (info->req_ie && |
17892 | nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, | |
17893 | info->req_ie)) || | |
17894 | (info->resp_ie && | |
17895 | nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, | |
e841b7b1 AVS |
17896 | info->resp_ie)) || |
17897 | (info->fils.update_erp_next_seq_num && | |
17898 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, | |
17899 | info->fils.erp_next_seq_num)) || | |
17900 | (info->fils.kek && | |
17901 | nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, | |
17902 | info->fils.kek)) || | |
17903 | (info->fils.pmk && | |
17904 | nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || | |
17905 | (info->fils.pmkid && | |
17906 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid))) | |
9360ffd1 | 17907 | goto nla_put_failure; |
b23aa676 | 17908 | |
efbabc11 VJ |
17909 | if (info->valid_links) { |
17910 | int i = 1; | |
17911 | struct nlattr *nested; | |
17912 | ||
17913 | nested = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS); | |
17914 | if (!nested) | |
17915 | goto nla_put_failure; | |
17916 | ||
17917 | for_each_valid_link(info, link) { | |
17918 | struct nlattr *nested_mlo_links; | |
17919 | const u8 *bssid = info->links[link].bss ? | |
17920 | info->links[link].bss->bssid : | |
17921 | info->links[link].bssid; | |
17922 | ||
17923 | nested_mlo_links = nla_nest_start(msg, i); | |
17924 | if (!nested_mlo_links) | |
17925 | goto nla_put_failure; | |
17926 | ||
17927 | if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link) || | |
17928 | (bssid && | |
17929 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, bssid)) || | |
17930 | (info->links[link].addr && | |
17931 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, | |
17932 | info->links[link].addr))) | |
17933 | goto nla_put_failure; | |
17934 | ||
17935 | nla_nest_end(msg, nested_mlo_links); | |
17936 | i++; | |
17937 | } | |
17938 | nla_nest_end(msg, nested); | |
17939 | } | |
17940 | ||
3b7b72ee | 17941 | genlmsg_end(msg, hdr); |
b23aa676 | 17942 | |
68eb5503 | 17943 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 17944 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
17945 | return; |
17946 | ||
503c1fb9 | 17947 | nla_put_failure: |
503c1fb9 AS |
17948 | nlmsg_free(msg); |
17949 | } | |
17950 | ||
17951 | void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, | |
0ff57171 VY |
17952 | struct net_device *netdev, const u8 *bssid, |
17953 | const u8 *td_bitmap, u8 td_bitmap_len) | |
503c1fb9 AS |
17954 | { |
17955 | struct sk_buff *msg; | |
17956 | void *hdr; | |
17957 | ||
17958 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
17959 | if (!msg) | |
17960 | return; | |
17961 | ||
17962 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); | |
17963 | if (!hdr) { | |
17964 | nlmsg_free(msg); | |
17965 | return; | |
17966 | } | |
17967 | ||
f4d75993 CHH |
17968 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
17969 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
17970 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
503c1fb9 AS |
17971 | goto nla_put_failure; |
17972 | ||
0ff57171 VY |
17973 | if ((td_bitmap_len > 0) && td_bitmap) |
17974 | if (nla_put(msg, NL80211_ATTR_TD_BITMAP, | |
17975 | td_bitmap_len, td_bitmap)) | |
17976 | goto nla_put_failure; | |
17977 | ||
503c1fb9 AS |
17978 | genlmsg_end(msg, hdr); |
17979 | ||
17980 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | |
17981 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
17982 | return; | |
17983 | ||
b23aa676 | 17984 | nla_put_failure: |
b23aa676 | 17985 | nlmsg_free(msg); |
b23aa676 SO |
17986 | } |
17987 | ||
17988 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
17989 | struct net_device *netdev, u16 reason, | |
667503dd | 17990 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
17991 | { |
17992 | struct sk_buff *msg; | |
17993 | void *hdr; | |
17994 | ||
4ef8c1c9 | 17995 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); |
b23aa676 SO |
17996 | if (!msg) |
17997 | return; | |
17998 | ||
17999 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
18000 | if (!hdr) { | |
18001 | nlmsg_free(msg); | |
18002 | return; | |
18003 | } | |
18004 | ||
9360ffd1 DM |
18005 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
18006 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
86b6c465 | 18007 | (reason && |
9360ffd1 DM |
18008 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
18009 | (from_ap && | |
18010 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
18011 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
18012 | goto nla_put_failure; | |
b23aa676 | 18013 | |
3b7b72ee | 18014 | genlmsg_end(msg, hdr); |
b23aa676 | 18015 | |
68eb5503 | 18016 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 18017 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
18018 | return; |
18019 | ||
18020 | nla_put_failure: | |
b23aa676 | 18021 | nlmsg_free(msg); |
b23aa676 SO |
18022 | } |
18023 | ||
04a773ad JB |
18024 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
18025 | struct net_device *netdev, const u8 *bssid, | |
18026 | gfp_t gfp) | |
18027 | { | |
18028 | struct sk_buff *msg; | |
18029 | void *hdr; | |
18030 | ||
fd2120ca | 18031 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
18032 | if (!msg) |
18033 | return; | |
18034 | ||
18035 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
18036 | if (!hdr) { | |
18037 | nlmsg_free(msg); | |
18038 | return; | |
18039 | } | |
18040 | ||
9360ffd1 DM |
18041 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
18042 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
18043 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
18044 | goto nla_put_failure; | |
04a773ad | 18045 | |
3b7b72ee | 18046 | genlmsg_end(msg, hdr); |
04a773ad | 18047 | |
68eb5503 | 18048 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 18049 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
18050 | return; |
18051 | ||
18052 | nla_put_failure: | |
04a773ad JB |
18053 | nlmsg_free(msg); |
18054 | } | |
18055 | ||
947add36 | 18056 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
ecbc12ad BC |
18057 | const u8 *ie, u8 ie_len, |
18058 | int sig_dbm, gfp_t gfp) | |
c93b5e71 | 18059 | { |
947add36 | 18060 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 18061 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
18062 | struct sk_buff *msg; |
18063 | void *hdr; | |
18064 | ||
947add36 JB |
18065 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
18066 | return; | |
18067 | ||
18068 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
18069 | ||
4ef8c1c9 | 18070 | msg = nlmsg_new(100 + ie_len, gfp); |
c93b5e71 JC |
18071 | if (!msg) |
18072 | return; | |
18073 | ||
18074 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
18075 | if (!hdr) { | |
18076 | nlmsg_free(msg); | |
18077 | return; | |
18078 | } | |
18079 | ||
9360ffd1 | 18080 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
18081 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
18082 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 | 18083 | (ie_len && ie && |
ecbc12ad BC |
18084 | nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) || |
18085 | (sig_dbm && | |
18086 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm))) | |
9360ffd1 | 18087 | goto nla_put_failure; |
c93b5e71 | 18088 | |
3b7b72ee | 18089 | genlmsg_end(msg, hdr); |
c93b5e71 | 18090 | |
68eb5503 | 18091 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 18092 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
18093 | return; |
18094 | ||
18095 | nla_put_failure: | |
c93b5e71 JC |
18096 | nlmsg_free(msg); |
18097 | } | |
947add36 | 18098 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 18099 | |
a3b8b056 JM |
18100 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
18101 | struct net_device *netdev, const u8 *addr, | |
18102 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 18103 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
18104 | { |
18105 | struct sk_buff *msg; | |
18106 | void *hdr; | |
18107 | ||
e6d6e342 | 18108 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
18109 | if (!msg) |
18110 | return; | |
18111 | ||
18112 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
18113 | if (!hdr) { | |
18114 | nlmsg_free(msg); | |
18115 | return; | |
18116 | } | |
18117 | ||
9360ffd1 DM |
18118 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
18119 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
18120 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
18121 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
18122 | (key_id != -1 && | |
18123 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
18124 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
18125 | goto nla_put_failure; | |
a3b8b056 | 18126 | |
3b7b72ee | 18127 | genlmsg_end(msg, hdr); |
a3b8b056 | 18128 | |
68eb5503 | 18129 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 18130 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
18131 | return; |
18132 | ||
18133 | nla_put_failure: | |
a3b8b056 JM |
18134 | nlmsg_free(msg); |
18135 | } | |
18136 | ||
6bad8766 LR |
18137 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
18138 | struct ieee80211_channel *channel_before, | |
18139 | struct ieee80211_channel *channel_after) | |
18140 | { | |
18141 | struct sk_buff *msg; | |
18142 | void *hdr; | |
18143 | struct nlattr *nl_freq; | |
18144 | ||
fd2120ca | 18145 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
18146 | if (!msg) |
18147 | return; | |
18148 | ||
18149 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
18150 | if (!hdr) { | |
18151 | nlmsg_free(msg); | |
18152 | return; | |
18153 | } | |
18154 | ||
18155 | /* | |
18156 | * Since we are applying the beacon hint to a wiphy we know its | |
18157 | * wiphy_idx is valid | |
18158 | */ | |
9360ffd1 DM |
18159 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
18160 | goto nla_put_failure; | |
6bad8766 LR |
18161 | |
18162 | /* Before */ | |
ae0be8de | 18163 | nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE); |
6bad8766 LR |
18164 | if (!nl_freq) |
18165 | goto nla_put_failure; | |
50f32718 HD |
18166 | |
18167 | if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) | |
6bad8766 LR |
18168 | goto nla_put_failure; |
18169 | nla_nest_end(msg, nl_freq); | |
18170 | ||
18171 | /* After */ | |
ae0be8de | 18172 | nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER); |
6bad8766 LR |
18173 | if (!nl_freq) |
18174 | goto nla_put_failure; | |
50f32718 HD |
18175 | |
18176 | if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) | |
6bad8766 LR |
18177 | goto nla_put_failure; |
18178 | nla_nest_end(msg, nl_freq); | |
18179 | ||
3b7b72ee | 18180 | genlmsg_end(msg, hdr); |
6bad8766 | 18181 | |
463d0183 | 18182 | rcu_read_lock(); |
68eb5503 | 18183 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 18184 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 18185 | rcu_read_unlock(); |
6bad8766 LR |
18186 | |
18187 | return; | |
18188 | ||
18189 | nla_put_failure: | |
6bad8766 LR |
18190 | nlmsg_free(msg); |
18191 | } | |
18192 | ||
9588bbd5 JM |
18193 | static void nl80211_send_remain_on_chan_event( |
18194 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 18195 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 18196 | struct ieee80211_channel *chan, |
9588bbd5 JM |
18197 | unsigned int duration, gfp_t gfp) |
18198 | { | |
18199 | struct sk_buff *msg; | |
18200 | void *hdr; | |
18201 | ||
18202 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
18203 | if (!msg) | |
18204 | return; | |
18205 | ||
18206 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
18207 | if (!hdr) { | |
18208 | nlmsg_free(msg); | |
18209 | return; | |
18210 | } | |
18211 | ||
9360ffd1 | 18212 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
18213 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
18214 | wdev->netdev->ifindex)) || | |
2dad624e ND |
18215 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
18216 | NL80211_ATTR_PAD) || | |
9360ffd1 | 18217 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
18218 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
18219 | NL80211_CHAN_NO_HT) || | |
2dad624e ND |
18220 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
18221 | NL80211_ATTR_PAD)) | |
9360ffd1 | 18222 | goto nla_put_failure; |
9588bbd5 | 18223 | |
9360ffd1 DM |
18224 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
18225 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
18226 | goto nla_put_failure; | |
9588bbd5 | 18227 | |
3b7b72ee | 18228 | genlmsg_end(msg, hdr); |
9588bbd5 | 18229 | |
68eb5503 | 18230 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 18231 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
18232 | return; |
18233 | ||
18234 | nla_put_failure: | |
9588bbd5 JM |
18235 | nlmsg_free(msg); |
18236 | } | |
18237 | ||
a083ee8a | 18238 | void cfg80211_assoc_comeback(struct net_device *netdev, |
e69dac88 | 18239 | const u8 *ap_addr, u32 timeout) |
a083ee8a IP |
18240 | { |
18241 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
18242 | struct wiphy *wiphy = wdev->wiphy; | |
18243 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
18244 | struct sk_buff *msg; | |
18245 | void *hdr; | |
18246 | ||
e69dac88 | 18247 | trace_cfg80211_assoc_comeback(wdev, ap_addr, timeout); |
a083ee8a IP |
18248 | |
18249 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
18250 | if (!msg) | |
18251 | return; | |
18252 | ||
18253 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ASSOC_COMEBACK); | |
18254 | if (!hdr) { | |
18255 | nlmsg_free(msg); | |
18256 | return; | |
18257 | } | |
18258 | ||
18259 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
18260 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
e69dac88 | 18261 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ap_addr) || |
a083ee8a IP |
18262 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT, timeout)) |
18263 | goto nla_put_failure; | |
18264 | ||
18265 | genlmsg_end(msg, hdr); | |
18266 | ||
18267 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | |
18268 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
18269 | return; | |
18270 | ||
18271 | nla_put_failure: | |
18272 | nlmsg_free(msg); | |
18273 | } | |
18274 | EXPORT_SYMBOL(cfg80211_assoc_comeback); | |
18275 | ||
947add36 JB |
18276 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
18277 | struct ieee80211_channel *chan, | |
18278 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 18279 | { |
947add36 | 18280 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 18281 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
18282 | |
18283 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 18284 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 18285 | rdev, wdev, cookie, chan, |
42d97a59 | 18286 | duration, gfp); |
9588bbd5 | 18287 | } |
947add36 | 18288 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 18289 | |
947add36 JB |
18290 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
18291 | struct ieee80211_channel *chan, | |
18292 | gfp_t gfp) | |
9588bbd5 | 18293 | { |
947add36 | 18294 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 18295 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
18296 | |
18297 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 18298 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 18299 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 18300 | } |
947add36 | 18301 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 18302 | |
1c38c7f2 JP |
18303 | void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie, |
18304 | struct ieee80211_channel *chan, | |
18305 | gfp_t gfp) | |
18306 | { | |
18307 | struct wiphy *wiphy = wdev->wiphy; | |
18308 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
18309 | ||
18310 | trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan); | |
18311 | nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL, | |
18312 | rdev, wdev, cookie, chan, 0, gfp); | |
18313 | } | |
18314 | EXPORT_SYMBOL(cfg80211_tx_mgmt_expired); | |
18315 | ||
947add36 JB |
18316 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
18317 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 18318 | { |
947add36 | 18319 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 18320 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
18321 | struct sk_buff *msg; |
18322 | ||
947add36 JB |
18323 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
18324 | ||
58050fce | 18325 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
18326 | if (!msg) |
18327 | return; | |
18328 | ||
cf5ead82 | 18329 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
66266b3a | 18330 | rdev, dev, mac_addr, sinfo) < 0) { |
98b62183 JB |
18331 | nlmsg_free(msg); |
18332 | return; | |
18333 | } | |
18334 | ||
68eb5503 | 18335 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 18336 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 18337 | } |
947add36 | 18338 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 18339 | |
cf5ead82 JB |
18340 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
18341 | struct station_info *sinfo, gfp_t gfp) | |
ec15e68b | 18342 | { |
947add36 | 18343 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 18344 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b | 18345 | struct sk_buff *msg; |
73887fd9 | 18346 | struct station_info empty_sinfo = {}; |
cf5ead82 | 18347 | |
73887fd9 JB |
18348 | if (!sinfo) |
18349 | sinfo = &empty_sinfo; | |
ec15e68b | 18350 | |
947add36 JB |
18351 | trace_cfg80211_del_sta(dev, mac_addr); |
18352 | ||
58050fce | 18353 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
7ea3e110 JB |
18354 | if (!msg) { |
18355 | cfg80211_sinfo_release_content(sinfo); | |
73887fd9 | 18356 | return; |
7ea3e110 | 18357 | } |
ec15e68b | 18358 | |
cf5ead82 | 18359 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
57007121 | 18360 | rdev, dev, mac_addr, sinfo) < 0) { |
ec15e68b | 18361 | nlmsg_free(msg); |
73887fd9 | 18362 | return; |
ec15e68b JM |
18363 | } |
18364 | ||
68eb5503 | 18365 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 18366 | NL80211_MCGRP_MLME, gfp); |
ec15e68b | 18367 | } |
cf5ead82 | 18368 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
ec15e68b | 18369 | |
947add36 JB |
18370 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
18371 | enum nl80211_connect_failed_reason reason, | |
18372 | gfp_t gfp) | |
ed44a951 | 18373 | { |
947add36 | 18374 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 18375 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
18376 | struct sk_buff *msg; |
18377 | void *hdr; | |
18378 | ||
18379 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
18380 | if (!msg) | |
18381 | return; | |
18382 | ||
18383 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
18384 | if (!hdr) { | |
18385 | nlmsg_free(msg); | |
18386 | return; | |
18387 | } | |
18388 | ||
18389 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
18390 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
18391 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
18392 | goto nla_put_failure; | |
18393 | ||
18394 | genlmsg_end(msg, hdr); | |
18395 | ||
68eb5503 | 18396 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 18397 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
18398 | return; |
18399 | ||
18400 | nla_put_failure: | |
ed44a951 PP |
18401 | nlmsg_free(msg); |
18402 | } | |
947add36 | 18403 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 18404 | |
b92ab5d8 JB |
18405 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
18406 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
18407 | { |
18408 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 18409 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
18410 | struct sk_buff *msg; |
18411 | void *hdr; | |
6aa7de05 | 18412 | u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 18413 | |
15e47304 | 18414 | if (!nlportid) |
28946da7 JB |
18415 | return false; |
18416 | ||
18417 | msg = nlmsg_new(100, gfp); | |
18418 | if (!msg) | |
18419 | return true; | |
18420 | ||
b92ab5d8 | 18421 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
18422 | if (!hdr) { |
18423 | nlmsg_free(msg); | |
18424 | return true; | |
18425 | } | |
18426 | ||
9360ffd1 DM |
18427 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
18428 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
18429 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
18430 | goto nla_put_failure; | |
28946da7 | 18431 | |
9c90a9f6 | 18432 | genlmsg_end(msg, hdr); |
15e47304 | 18433 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
18434 | return true; |
18435 | ||
18436 | nla_put_failure: | |
28946da7 JB |
18437 | nlmsg_free(msg); |
18438 | return true; | |
18439 | } | |
18440 | ||
947add36 JB |
18441 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
18442 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 18443 | { |
947add36 JB |
18444 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
18445 | bool ret; | |
18446 | ||
18447 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
18448 | ||
18449 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
18450 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
18451 | trace_cfg80211_return_bool(false); | |
18452 | return false; | |
18453 | } | |
18454 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
18455 | addr, gfp); | |
18456 | trace_cfg80211_return_bool(ret); | |
18457 | return ret; | |
b92ab5d8 | 18458 | } |
947add36 | 18459 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 18460 | |
947add36 JB |
18461 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
18462 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 18463 | { |
947add36 JB |
18464 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
18465 | bool ret; | |
18466 | ||
18467 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
18468 | ||
18469 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
18470 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
18471 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
18472 | trace_cfg80211_return_bool(false); | |
18473 | return false; | |
18474 | } | |
18475 | ret = __nl80211_unexpected_frame(dev, | |
18476 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
18477 | addr, gfp); | |
18478 | trace_cfg80211_return_bool(ret); | |
18479 | return ret; | |
b92ab5d8 | 18480 | } |
947add36 | 18481 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 18482 | |
2e161f78 | 18483 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 18484 | struct wireless_dev *wdev, u32 nlportid, |
00b3d840 | 18485 | struct cfg80211_rx_info *info, gfp_t gfp) |
026331c4 | 18486 | { |
71bbc994 | 18487 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
18488 | struct sk_buff *msg; |
18489 | void *hdr; | |
026331c4 | 18490 | |
00b3d840 | 18491 | msg = nlmsg_new(100 + info->len, gfp); |
026331c4 JM |
18492 | if (!msg) |
18493 | return -ENOMEM; | |
18494 | ||
2e161f78 | 18495 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
18496 | if (!hdr) { |
18497 | nlmsg_free(msg); | |
18498 | return -ENOMEM; | |
18499 | } | |
18500 | ||
9360ffd1 | 18501 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
18502 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
18503 | netdev->ifindex)) || | |
2dad624e ND |
18504 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
18505 | NL80211_ATTR_PAD) || | |
6074c9e5 JB |
18506 | (info->have_link_id && |
18507 | nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, info->link_id)) || | |
00b3d840 AS |
18508 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(info->freq)) || |
18509 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, info->freq % 1000) || | |
18510 | (info->sig_dbm && | |
18511 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, info->sig_dbm)) || | |
18512 | nla_put(msg, NL80211_ATTR_FRAME, info->len, info->buf) || | |
18513 | (info->flags && | |
1ff715ff AS |
18514 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, info->flags)) || |
18515 | (info->rx_tstamp && nla_put_u64_64bit(msg, | |
18516 | NL80211_ATTR_RX_HW_TIMESTAMP, | |
18517 | info->rx_tstamp, | |
18518 | NL80211_ATTR_PAD)) || | |
18519 | (info->ack_tstamp && nla_put_u64_64bit(msg, | |
18520 | NL80211_ATTR_TX_HW_TIMESTAMP, | |
18521 | info->ack_tstamp, | |
18522 | NL80211_ATTR_PAD))) | |
9360ffd1 | 18523 | goto nla_put_failure; |
026331c4 | 18524 | |
3b7b72ee | 18525 | genlmsg_end(msg, hdr); |
026331c4 | 18526 | |
15e47304 | 18527 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
18528 | |
18529 | nla_put_failure: | |
026331c4 JM |
18530 | nlmsg_free(msg); |
18531 | return -ENOBUFS; | |
18532 | } | |
18533 | ||
ea7d50c9 AS |
18534 | static void nl80211_frame_tx_status(struct wireless_dev *wdev, |
18535 | struct cfg80211_tx_status *status, | |
dca9ca2d | 18536 | gfp_t gfp, enum nl80211_commands command) |
026331c4 | 18537 | { |
947add36 | 18538 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 18539 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 18540 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
18541 | struct sk_buff *msg; |
18542 | void *hdr; | |
18543 | ||
dca9ca2d | 18544 | if (command == NL80211_CMD_FRAME_TX_STATUS) |
ea7d50c9 AS |
18545 | trace_cfg80211_mgmt_tx_status(wdev, status->cookie, |
18546 | status->ack); | |
dca9ca2d | 18547 | else |
ea7d50c9 AS |
18548 | trace_cfg80211_control_port_tx_status(wdev, status->cookie, |
18549 | status->ack); | |
947add36 | 18550 | |
ea7d50c9 | 18551 | msg = nlmsg_new(100 + status->len, gfp); |
026331c4 JM |
18552 | if (!msg) |
18553 | return; | |
18554 | ||
dca9ca2d | 18555 | hdr = nl80211hdr_put(msg, 0, 0, 0, command); |
026331c4 JM |
18556 | if (!hdr) { |
18557 | nlmsg_free(msg); | |
18558 | return; | |
18559 | } | |
18560 | ||
9360ffd1 | 18561 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
18562 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
18563 | netdev->ifindex)) || | |
2dad624e ND |
18564 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
18565 | NL80211_ATTR_PAD) || | |
ea7d50c9 AS |
18566 | nla_put(msg, NL80211_ATTR_FRAME, status->len, status->buf) || |
18567 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, status->cookie, | |
2dad624e | 18568 | NL80211_ATTR_PAD) || |
ea7d50c9 AS |
18569 | (status->ack && nla_put_flag(msg, NL80211_ATTR_ACK)) || |
18570 | (status->tx_tstamp && | |
18571 | nla_put_u64_64bit(msg, NL80211_ATTR_TX_HW_TIMESTAMP, | |
18572 | status->tx_tstamp, NL80211_ATTR_PAD)) || | |
18573 | (status->ack_tstamp && | |
18574 | nla_put_u64_64bit(msg, NL80211_ATTR_RX_HW_TIMESTAMP, | |
18575 | status->ack_tstamp, NL80211_ATTR_PAD))) | |
9360ffd1 | 18576 | goto nla_put_failure; |
026331c4 | 18577 | |
3b7b72ee | 18578 | genlmsg_end(msg, hdr); |
026331c4 | 18579 | |
68eb5503 | 18580 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 18581 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
18582 | return; |
18583 | ||
dca9ca2d | 18584 | nla_put_failure: |
026331c4 JM |
18585 | nlmsg_free(msg); |
18586 | } | |
dca9ca2d MT |
18587 | |
18588 | void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie, | |
18589 | const u8 *buf, size_t len, bool ack, | |
18590 | gfp_t gfp) | |
18591 | { | |
ea7d50c9 AS |
18592 | struct cfg80211_tx_status status = { |
18593 | .cookie = cookie, | |
18594 | .buf = buf, | |
18595 | .len = len, | |
18596 | .ack = ack | |
18597 | }; | |
18598 | ||
18599 | nl80211_frame_tx_status(wdev, &status, gfp, | |
dca9ca2d MT |
18600 | NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS); |
18601 | } | |
18602 | EXPORT_SYMBOL(cfg80211_control_port_tx_status); | |
18603 | ||
ea7d50c9 AS |
18604 | void cfg80211_mgmt_tx_status_ext(struct wireless_dev *wdev, |
18605 | struct cfg80211_tx_status *status, gfp_t gfp) | |
dca9ca2d | 18606 | { |
ea7d50c9 | 18607 | nl80211_frame_tx_status(wdev, status, gfp, NL80211_CMD_FRAME_TX_STATUS); |
dca9ca2d | 18608 | } |
ea7d50c9 | 18609 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status_ext); |
026331c4 | 18610 | |
6a671a50 | 18611 | static int __nl80211_rx_control_port(struct net_device *dev, |
a948f713 | 18612 | struct sk_buff *skb, |
6a671a50 DK |
18613 | bool unencrypted, gfp_t gfp) |
18614 | { | |
18615 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
18616 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | |
a948f713 | 18617 | struct ethhdr *ehdr = eth_hdr(skb); |
8d74a623 | 18618 | const u8 *addr = ehdr->h_source; |
a948f713 | 18619 | u16 proto = be16_to_cpu(skb->protocol); |
6a671a50 DK |
18620 | struct sk_buff *msg; |
18621 | void *hdr; | |
a948f713 DK |
18622 | struct nlattr *frame; |
18623 | ||
6a671a50 DK |
18624 | u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); |
18625 | ||
18626 | if (!nlportid) | |
18627 | return -ENOENT; | |
18628 | ||
a948f713 | 18629 | msg = nlmsg_new(100 + skb->len, gfp); |
6a671a50 DK |
18630 | if (!msg) |
18631 | return -ENOMEM; | |
18632 | ||
18633 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); | |
18634 | if (!hdr) { | |
18635 | nlmsg_free(msg); | |
18636 | return -ENOBUFS; | |
18637 | } | |
18638 | ||
18639 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
18640 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
18641 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | |
18642 | NL80211_ATTR_PAD) || | |
8d74a623 | 18643 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
6a671a50 DK |
18644 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || |
18645 | (unencrypted && nla_put_flag(msg, | |
18646 | NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | |
18647 | goto nla_put_failure; | |
18648 | ||
a948f713 DK |
18649 | frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len); |
18650 | if (!frame) | |
18651 | goto nla_put_failure; | |
18652 | ||
18653 | skb_copy_bits(skb, 0, nla_data(frame), skb->len); | |
6a671a50 DK |
18654 | genlmsg_end(msg, hdr); |
18655 | ||
18656 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
18657 | ||
18658 | nla_put_failure: | |
18659 | nlmsg_free(msg); | |
18660 | return -ENOBUFS; | |
18661 | } | |
18662 | ||
18663 | bool cfg80211_rx_control_port(struct net_device *dev, | |
a948f713 | 18664 | struct sk_buff *skb, bool unencrypted) |
6a671a50 DK |
18665 | { |
18666 | int ret; | |
18667 | ||
a948f713 DK |
18668 | trace_cfg80211_rx_control_port(dev, skb, unencrypted); |
18669 | ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC); | |
6a671a50 DK |
18670 | trace_cfg80211_return_bool(ret == 0); |
18671 | return ret == 0; | |
18672 | } | |
18673 | EXPORT_SYMBOL(cfg80211_rx_control_port); | |
18674 | ||
5b97f49d JB |
18675 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
18676 | const char *mac, gfp_t gfp) | |
d6dc1a38 | 18677 | { |
947add36 | 18678 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5b97f49d JB |
18679 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
18680 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
18681 | void **cb; | |
947add36 | 18682 | |
d6dc1a38 | 18683 | if (!msg) |
5b97f49d | 18684 | return NULL; |
d6dc1a38 | 18685 | |
5b97f49d JB |
18686 | cb = (void **)msg->cb; |
18687 | ||
18688 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
18689 | if (!cb[0]) { | |
d6dc1a38 | 18690 | nlmsg_free(msg); |
5b97f49d | 18691 | return NULL; |
d6dc1a38 JO |
18692 | } |
18693 | ||
9360ffd1 | 18694 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 18695 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 18696 | goto nla_put_failure; |
d6dc1a38 | 18697 | |
5b97f49d | 18698 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
d6dc1a38 JO |
18699 | goto nla_put_failure; |
18700 | ||
ae0be8de | 18701 | cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM); |
5b97f49d | 18702 | if (!cb[1]) |
9360ffd1 | 18703 | goto nla_put_failure; |
d6dc1a38 | 18704 | |
5b97f49d | 18705 | cb[2] = rdev; |
d6dc1a38 | 18706 | |
5b97f49d JB |
18707 | return msg; |
18708 | nla_put_failure: | |
18709 | nlmsg_free(msg); | |
18710 | return NULL; | |
18711 | } | |
18712 | ||
18713 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | |
18714 | { | |
18715 | void **cb = (void **)msg->cb; | |
18716 | struct cfg80211_registered_device *rdev = cb[2]; | |
18717 | ||
18718 | nla_nest_end(msg, cb[1]); | |
18719 | genlmsg_end(msg, cb[0]); | |
18720 | ||
18721 | memset(msg->cb, 0, sizeof(msg->cb)); | |
d6dc1a38 | 18722 | |
68eb5503 | 18723 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 18724 | NL80211_MCGRP_MLME, gfp); |
5b97f49d JB |
18725 | } |
18726 | ||
18727 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | |
18728 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
bee427b8 | 18729 | s32 rssi_level, gfp_t gfp) |
5b97f49d JB |
18730 | { |
18731 | struct sk_buff *msg; | |
4a4b8169 AZ |
18732 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
18733 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | |
5b97f49d | 18734 | |
bee427b8 | 18735 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); |
5b97f49d | 18736 | |
98f03342 JB |
18737 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
18738 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | |
18739 | return; | |
18740 | ||
4a4b8169 AZ |
18741 | if (wdev->cqm_config) { |
18742 | wdev->cqm_config->last_rssi_event_value = rssi_level; | |
18743 | ||
18744 | cfg80211_cqm_rssi_update(rdev, dev); | |
18745 | ||
18746 | if (rssi_level == 0) | |
18747 | rssi_level = wdev->cqm_config->last_rssi_event_value; | |
18748 | } | |
18749 | ||
5b97f49d JB |
18750 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
18751 | if (!msg) | |
18752 | return; | |
18753 | ||
18754 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
18755 | rssi_event)) | |
18756 | goto nla_put_failure; | |
18757 | ||
bee427b8 AZ |
18758 | if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, |
18759 | rssi_level)) | |
18760 | goto nla_put_failure; | |
18761 | ||
5b97f49d JB |
18762 | cfg80211_send_cqm(msg, gfp); |
18763 | ||
d6dc1a38 JO |
18764 | return; |
18765 | ||
18766 | nla_put_failure: | |
d6dc1a38 JO |
18767 | nlmsg_free(msg); |
18768 | } | |
947add36 | 18769 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 18770 | |
5b97f49d JB |
18771 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
18772 | const u8 *peer, u32 num_packets, | |
18773 | u32 rate, u32 intvl, gfp_t gfp) | |
18774 | { | |
18775 | struct sk_buff *msg; | |
18776 | ||
18777 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
18778 | if (!msg) | |
18779 | return; | |
18780 | ||
18781 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
18782 | goto nla_put_failure; | |
18783 | ||
18784 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
18785 | goto nla_put_failure; | |
18786 | ||
18787 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
18788 | goto nla_put_failure; | |
18789 | ||
18790 | cfg80211_send_cqm(msg, gfp); | |
18791 | return; | |
18792 | ||
18793 | nla_put_failure: | |
18794 | nlmsg_free(msg); | |
18795 | } | |
18796 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | |
18797 | ||
18798 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | |
18799 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
18800 | { | |
18801 | struct sk_buff *msg; | |
18802 | ||
18803 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | |
18804 | ||
18805 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
18806 | if (!msg) | |
18807 | return; | |
18808 | ||
18809 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | |
18810 | goto nla_put_failure; | |
18811 | ||
18812 | cfg80211_send_cqm(msg, gfp); | |
18813 | return; | |
18814 | ||
18815 | nla_put_failure: | |
18816 | nlmsg_free(msg); | |
18817 | } | |
18818 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | |
18819 | ||
98f03342 JB |
18820 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
18821 | { | |
18822 | struct sk_buff *msg; | |
18823 | ||
18824 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | |
18825 | if (!msg) | |
18826 | return; | |
18827 | ||
18828 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | |
18829 | goto nla_put_failure; | |
18830 | ||
18831 | cfg80211_send_cqm(msg, gfp); | |
18832 | return; | |
18833 | ||
18834 | nla_put_failure: | |
18835 | nlmsg_free(msg); | |
18836 | } | |
18837 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); | |
18838 | ||
947add36 JB |
18839 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
18840 | struct net_device *netdev, const u8 *bssid, | |
18841 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
18842 | { |
18843 | struct sk_buff *msg; | |
18844 | struct nlattr *rekey_attr; | |
18845 | void *hdr; | |
18846 | ||
58050fce | 18847 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
18848 | if (!msg) |
18849 | return; | |
18850 | ||
18851 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
18852 | if (!hdr) { | |
18853 | nlmsg_free(msg); | |
18854 | return; | |
18855 | } | |
18856 | ||
9360ffd1 DM |
18857 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
18858 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
18859 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
18860 | goto nla_put_failure; | |
e5497d76 | 18861 | |
ae0be8de | 18862 | rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA); |
e5497d76 JB |
18863 | if (!rekey_attr) |
18864 | goto nla_put_failure; | |
18865 | ||
9360ffd1 DM |
18866 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
18867 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
18868 | goto nla_put_failure; | |
e5497d76 JB |
18869 | |
18870 | nla_nest_end(msg, rekey_attr); | |
18871 | ||
3b7b72ee | 18872 | genlmsg_end(msg, hdr); |
e5497d76 | 18873 | |
68eb5503 | 18874 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 18875 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
18876 | return; |
18877 | ||
18878 | nla_put_failure: | |
e5497d76 JB |
18879 | nlmsg_free(msg); |
18880 | } | |
18881 | ||
947add36 JB |
18882 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
18883 | const u8 *replay_ctr, gfp_t gfp) | |
18884 | { | |
18885 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
18886 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 18887 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
18888 | |
18889 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
18890 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
18891 | } | |
18892 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
18893 | ||
18894 | static void | |
18895 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
18896 | struct net_device *netdev, int index, | |
18897 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
18898 | { |
18899 | struct sk_buff *msg; | |
18900 | struct nlattr *attr; | |
18901 | void *hdr; | |
18902 | ||
58050fce | 18903 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
18904 | if (!msg) |
18905 | return; | |
18906 | ||
18907 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
18908 | if (!hdr) { | |
18909 | nlmsg_free(msg); | |
18910 | return; | |
18911 | } | |
18912 | ||
9360ffd1 DM |
18913 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
18914 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
18915 | goto nla_put_failure; | |
c9df56b4 | 18916 | |
ae0be8de | 18917 | attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
c9df56b4 JM |
18918 | if (!attr) |
18919 | goto nla_put_failure; | |
18920 | ||
9360ffd1 DM |
18921 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
18922 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
18923 | (preauth && | |
18924 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
18925 | goto nla_put_failure; | |
c9df56b4 JM |
18926 | |
18927 | nla_nest_end(msg, attr); | |
18928 | ||
3b7b72ee | 18929 | genlmsg_end(msg, hdr); |
c9df56b4 | 18930 | |
68eb5503 | 18931 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 18932 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
18933 | return; |
18934 | ||
18935 | nla_put_failure: | |
c9df56b4 JM |
18936 | nlmsg_free(msg); |
18937 | } | |
18938 | ||
947add36 JB |
18939 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
18940 | const u8 *bssid, bool preauth, gfp_t gfp) | |
18941 | { | |
18942 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
18943 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 18944 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
18945 | |
18946 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
18947 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
18948 | } | |
18949 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
18950 | ||
18951 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
18952 | struct net_device *netdev, | |
b8c9024e | 18953 | unsigned int link_id, |
947add36 | 18954 | struct cfg80211_chan_def *chandef, |
f8d7552e LC |
18955 | gfp_t gfp, |
18956 | enum nl80211_commands notif, | |
669b8413 | 18957 | u8 count, bool quiet) |
5314526b | 18958 | { |
b8c9024e | 18959 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
5314526b TP |
18960 | struct sk_buff *msg; |
18961 | void *hdr; | |
18962 | ||
58050fce | 18963 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
18964 | if (!msg) |
18965 | return; | |
18966 | ||
f8d7552e | 18967 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
5314526b TP |
18968 | if (!hdr) { |
18969 | nlmsg_free(msg); | |
18970 | return; | |
18971 | } | |
18972 | ||
683b6d3b JB |
18973 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
18974 | goto nla_put_failure; | |
18975 | ||
b8c9024e VJ |
18976 | if (wdev->valid_links && |
18977 | nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) | |
18978 | goto nla_put_failure; | |
18979 | ||
683b6d3b | 18980 | if (nl80211_send_chandef(msg, chandef)) |
7eab0f64 | 18981 | goto nla_put_failure; |
5314526b | 18982 | |
669b8413 JB |
18983 | if (notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) { |
18984 | if (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)) | |
f8d7552e | 18985 | goto nla_put_failure; |
669b8413 JB |
18986 | if (quiet && |
18987 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)) | |
f8d7552e | 18988 | goto nla_put_failure; |
669b8413 | 18989 | } |
f8d7552e | 18990 | |
5314526b TP |
18991 | genlmsg_end(msg, hdr); |
18992 | ||
68eb5503 | 18993 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 18994 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
18995 | return; |
18996 | ||
18997 | nla_put_failure: | |
5314526b TP |
18998 | nlmsg_free(msg); |
18999 | } | |
19000 | ||
947add36 | 19001 | void cfg80211_ch_switch_notify(struct net_device *dev, |
7b0a0e3c JB |
19002 | struct cfg80211_chan_def *chandef, |
19003 | unsigned int link_id) | |
84f10708 | 19004 | { |
947add36 JB |
19005 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
19006 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 19007 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 19008 | |
e487eaeb | 19009 | ASSERT_WDEV_LOCK(wdev); |
7b0a0e3c | 19010 | WARN_INVALID_LINK_ID(wdev, link_id); |
947add36 | 19011 | |
7b0a0e3c | 19012 | trace_cfg80211_ch_switch_notify(dev, chandef, link_id); |
5dc8cdce | 19013 | |
7b0a0e3c JB |
19014 | switch (wdev->iftype) { |
19015 | case NL80211_IFTYPE_STATION: | |
19016 | case NL80211_IFTYPE_P2P_CLIENT: | |
19017 | if (!WARN_ON(!wdev->links[link_id].client.current_bss)) | |
19018 | cfg80211_update_assoc_bss_entry(wdev, link_id, | |
19019 | chandef->chan); | |
19020 | break; | |
19021 | case NL80211_IFTYPE_MESH_POINT: | |
19022 | wdev->u.mesh.chandef = *chandef; | |
19023 | wdev->u.mesh.preset_chandef = *chandef; | |
19024 | break; | |
19025 | case NL80211_IFTYPE_AP: | |
19026 | case NL80211_IFTYPE_P2P_GO: | |
19027 | wdev->links[link_id].ap.chandef = *chandef; | |
19028 | break; | |
77e7b6ba JB |
19029 | case NL80211_IFTYPE_ADHOC: |
19030 | wdev->u.ibss.chandef = *chandef; | |
19031 | break; | |
7b0a0e3c JB |
19032 | default: |
19033 | WARN_ON(1); | |
19034 | break; | |
19035 | } | |
5dc8cdce | 19036 | |
d34990bb MV |
19037 | cfg80211_sched_dfs_chan_update(rdev); |
19038 | ||
b8c9024e | 19039 | nl80211_ch_switch_notify(rdev, dev, link_id, chandef, GFP_KERNEL, |
669b8413 | 19040 | NL80211_CMD_CH_SWITCH_NOTIFY, 0, false); |
947add36 JB |
19041 | } |
19042 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
19043 | ||
f8d7552e LC |
19044 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
19045 | struct cfg80211_chan_def *chandef, | |
b8c9024e VJ |
19046 | unsigned int link_id, u8 count, |
19047 | bool quiet) | |
f8d7552e LC |
19048 | { |
19049 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
19050 | struct wiphy *wiphy = wdev->wiphy; | |
19051 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
19052 | ||
b8c9024e VJ |
19053 | ASSERT_WDEV_LOCK(wdev); |
19054 | WARN_INVALID_LINK_ID(wdev, link_id); | |
19055 | ||
19056 | trace_cfg80211_ch_switch_started_notify(dev, chandef, link_id); | |
f8d7552e | 19057 | |
b8c9024e | 19058 | nl80211_ch_switch_notify(rdev, dev, link_id, chandef, GFP_KERNEL, |
669b8413 JB |
19059 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, |
19060 | count, quiet); | |
f8d7552e LC |
19061 | } |
19062 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | |
19063 | ||
0d2ab3ae JC |
19064 | int cfg80211_bss_color_notify(struct net_device *dev, gfp_t gfp, |
19065 | enum nl80211_commands cmd, u8 count, | |
19066 | u64 color_bitmap) | |
19067 | { | |
19068 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
19069 | struct wiphy *wiphy = wdev->wiphy; | |
19070 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
19071 | struct sk_buff *msg; | |
19072 | void *hdr; | |
19073 | ||
19074 | ASSERT_WDEV_LOCK(wdev); | |
19075 | ||
19076 | trace_cfg80211_bss_color_notify(dev, cmd, count, color_bitmap); | |
19077 | ||
19078 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
19079 | if (!msg) | |
19080 | return -ENOMEM; | |
19081 | ||
19082 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
19083 | if (!hdr) | |
19084 | goto nla_put_failure; | |
19085 | ||
19086 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) | |
19087 | goto nla_put_failure; | |
19088 | ||
19089 | if (cmd == NL80211_CMD_COLOR_CHANGE_STARTED && | |
19090 | nla_put_u32(msg, NL80211_ATTR_COLOR_CHANGE_COUNT, count)) | |
19091 | goto nla_put_failure; | |
19092 | ||
19093 | if (cmd == NL80211_CMD_OBSS_COLOR_COLLISION && | |
19094 | nla_put_u64_64bit(msg, NL80211_ATTR_OBSS_COLOR_BITMAP, | |
19095 | color_bitmap, NL80211_ATTR_PAD)) | |
19096 | goto nla_put_failure; | |
19097 | ||
19098 | genlmsg_end(msg, hdr); | |
19099 | ||
19100 | return genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
19101 | msg, 0, NL80211_MCGRP_MLME, gfp); | |
19102 | ||
19103 | nla_put_failure: | |
19104 | nlmsg_free(msg); | |
19105 | return -EINVAL; | |
19106 | } | |
19107 | EXPORT_SYMBOL(cfg80211_bss_color_notify); | |
19108 | ||
04f39047 SW |
19109 | void |
19110 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 19111 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
19112 | enum nl80211_radar_event event, |
19113 | struct net_device *netdev, gfp_t gfp) | |
19114 | { | |
19115 | struct sk_buff *msg; | |
19116 | void *hdr; | |
19117 | ||
19118 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
19119 | if (!msg) | |
19120 | return; | |
19121 | ||
19122 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
19123 | if (!hdr) { | |
19124 | nlmsg_free(msg); | |
19125 | return; | |
19126 | } | |
19127 | ||
19128 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
19129 | goto nla_put_failure; | |
19130 | ||
19131 | /* NOP and radar events don't need a netdev parameter */ | |
19132 | if (netdev) { | |
19133 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
19134 | ||
19135 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
2dad624e ND |
19136 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
19137 | NL80211_ATTR_PAD)) | |
04f39047 SW |
19138 | goto nla_put_failure; |
19139 | } | |
19140 | ||
19141 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
19142 | goto nla_put_failure; | |
19143 | ||
19144 | if (nl80211_send_chandef(msg, chandef)) | |
19145 | goto nla_put_failure; | |
19146 | ||
9c90a9f6 | 19147 | genlmsg_end(msg, hdr); |
04f39047 | 19148 | |
68eb5503 | 19149 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 19150 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
19151 | return; |
19152 | ||
19153 | nla_put_failure: | |
04f39047 SW |
19154 | nlmsg_free(msg); |
19155 | } | |
19156 | ||
466b9936 | 19157 | void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, |
19158 | struct sta_opmode_info *sta_opmode, | |
19159 | gfp_t gfp) | |
19160 | { | |
19161 | struct sk_buff *msg; | |
19162 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
19163 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | |
19164 | void *hdr; | |
19165 | ||
19166 | if (WARN_ON(!mac)) | |
19167 | return; | |
19168 | ||
19169 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
19170 | if (!msg) | |
19171 | return; | |
19172 | ||
19173 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); | |
19174 | if (!hdr) { | |
19175 | nlmsg_free(msg); | |
19176 | return; | |
19177 | } | |
19178 | ||
19179 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
19180 | goto nla_put_failure; | |
19181 | ||
19182 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) | |
19183 | goto nla_put_failure; | |
19184 | ||
19185 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) | |
19186 | goto nla_put_failure; | |
19187 | ||
19188 | if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && | |
19189 | nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) | |
19190 | goto nla_put_failure; | |
19191 | ||
19192 | if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && | |
0016d320 | 19193 | nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) |
466b9936 | 19194 | goto nla_put_failure; |
19195 | ||
19196 | if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && | |
19197 | nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) | |
19198 | goto nla_put_failure; | |
19199 | ||
19200 | genlmsg_end(msg, hdr); | |
19201 | ||
19202 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | |
19203 | NL80211_MCGRP_MLME, gfp); | |
19204 | ||
19205 | return; | |
19206 | ||
19207 | nla_put_failure: | |
19208 | nlmsg_free(msg); | |
19209 | } | |
19210 | EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); | |
19211 | ||
7f6cf311 | 19212 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
c4b50cd3 VN |
19213 | u64 cookie, bool acked, s32 ack_signal, |
19214 | bool is_valid_ack_signal, gfp_t gfp) | |
7f6cf311 JB |
19215 | { |
19216 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 19217 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
19218 | struct sk_buff *msg; |
19219 | void *hdr; | |
7f6cf311 | 19220 | |
4ee3e063 BL |
19221 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
19222 | ||
58050fce | 19223 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 19224 | |
7f6cf311 JB |
19225 | if (!msg) |
19226 | return; | |
19227 | ||
19228 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
19229 | if (!hdr) { | |
19230 | nlmsg_free(msg); | |
19231 | return; | |
19232 | } | |
19233 | ||
9360ffd1 DM |
19234 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
19235 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
19236 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
2dad624e ND |
19237 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
19238 | NL80211_ATTR_PAD) || | |
c4b50cd3 VN |
19239 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || |
19240 | (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, | |
19241 | ack_signal))) | |
9360ffd1 | 19242 | goto nla_put_failure; |
7f6cf311 | 19243 | |
9c90a9f6 | 19244 | genlmsg_end(msg, hdr); |
7f6cf311 | 19245 | |
68eb5503 | 19246 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 19247 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
19248 | return; |
19249 | ||
19250 | nla_put_failure: | |
7f6cf311 JB |
19251 | nlmsg_free(msg); |
19252 | } | |
19253 | EXPORT_SYMBOL(cfg80211_probe_status); | |
19254 | ||
e76fede8 TP |
19255 | void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame, |
19256 | size_t len, int freq, int sig_dbm) | |
5e760230 | 19257 | { |
f26cbf40 | 19258 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
19259 | struct sk_buff *msg; |
19260 | void *hdr; | |
37c73b5f | 19261 | struct cfg80211_beacon_registration *reg; |
5e760230 | 19262 | |
4ee3e063 BL |
19263 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
19264 | ||
37c73b5f BG |
19265 | spin_lock_bh(&rdev->beacon_registrations_lock); |
19266 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
19267 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
19268 | if (!msg) { | |
19269 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
19270 | return; | |
19271 | } | |
5e760230 | 19272 | |
37c73b5f BG |
19273 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
19274 | if (!hdr) | |
19275 | goto nla_put_failure; | |
5e760230 | 19276 | |
37c73b5f BG |
19277 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
19278 | (freq && | |
942ba88b TP |
19279 | (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
19280 | KHZ_TO_MHZ(freq)) || | |
19281 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, | |
19282 | freq % 1000))) || | |
37c73b5f BG |
19283 | (sig_dbm && |
19284 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19285 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
19286 | goto nla_put_failure; | |
5e760230 | 19287 | |
37c73b5f | 19288 | genlmsg_end(msg, hdr); |
5e760230 | 19289 | |
37c73b5f BG |
19290 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
19291 | } | |
19292 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
19293 | return; |
19294 | ||
19295 | nla_put_failure: | |
37c73b5f | 19296 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
19297 | nlmsg_free(msg); |
19298 | } | |
e76fede8 | 19299 | EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz); |
5e760230 | 19300 | |
cd8f7cb4 | 19301 | #ifdef CONFIG_PM |
8cd4d456 LC |
19302 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
19303 | struct cfg80211_wowlan_wakeup *wakeup) | |
19304 | { | |
19305 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | |
19306 | struct nlattr *nl_results, *nl_match, *nl_freqs; | |
19307 | int i, j; | |
19308 | ||
ae0be8de MK |
19309 | nl_results = nla_nest_start_noflag(msg, |
19310 | NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | |
8cd4d456 LC |
19311 | if (!nl_results) |
19312 | return -EMSGSIZE; | |
19313 | ||
19314 | for (i = 0; i < nd->n_matches; i++) { | |
19315 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | |
19316 | ||
ae0be8de | 19317 | nl_match = nla_nest_start_noflag(msg, i); |
8cd4d456 LC |
19318 | if (!nl_match) |
19319 | break; | |
19320 | ||
19321 | /* The SSID attribute is optional in nl80211, but for | |
19322 | * simplicity reasons it's always present in the | |
19323 | * cfg80211 structure. If a driver can't pass the | |
19324 | * SSID, that needs to be changed. A zero length SSID | |
19325 | * is still a valid SSID (wildcard), so it cannot be | |
19326 | * used for this purpose. | |
19327 | */ | |
19328 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | |
19329 | match->ssid.ssid)) { | |
19330 | nla_nest_cancel(msg, nl_match); | |
19331 | goto out; | |
19332 | } | |
19333 | ||
19334 | if (match->n_channels) { | |
ae0be8de MK |
19335 | nl_freqs = nla_nest_start_noflag(msg, |
19336 | NL80211_ATTR_SCAN_FREQUENCIES); | |
8cd4d456 LC |
19337 | if (!nl_freqs) { |
19338 | nla_nest_cancel(msg, nl_match); | |
19339 | goto out; | |
19340 | } | |
19341 | ||
19342 | for (j = 0; j < match->n_channels; j++) { | |
5528fae8 | 19343 | if (nla_put_u32(msg, j, match->channels[j])) { |
8cd4d456 LC |
19344 | nla_nest_cancel(msg, nl_freqs); |
19345 | nla_nest_cancel(msg, nl_match); | |
19346 | goto out; | |
19347 | } | |
19348 | } | |
19349 | ||
19350 | nla_nest_end(msg, nl_freqs); | |
19351 | } | |
19352 | ||
19353 | nla_nest_end(msg, nl_match); | |
19354 | } | |
19355 | ||
19356 | out: | |
19357 | nla_nest_end(msg, nl_results); | |
19358 | return 0; | |
19359 | } | |
19360 | ||
cd8f7cb4 JB |
19361 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
19362 | struct cfg80211_wowlan_wakeup *wakeup, | |
19363 | gfp_t gfp) | |
19364 | { | |
f26cbf40 | 19365 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
19366 | struct sk_buff *msg; |
19367 | void *hdr; | |
9c90a9f6 | 19368 | int size = 200; |
cd8f7cb4 JB |
19369 | |
19370 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
19371 | ||
19372 | if (wakeup) | |
19373 | size += wakeup->packet_present_len; | |
19374 | ||
19375 | msg = nlmsg_new(size, gfp); | |
19376 | if (!msg) | |
19377 | return; | |
19378 | ||
19379 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
19380 | if (!hdr) | |
19381 | goto free_msg; | |
19382 | ||
19383 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
19384 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
19385 | NL80211_ATTR_PAD)) | |
cd8f7cb4 JB |
19386 | goto free_msg; |
19387 | ||
19388 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
19389 | wdev->netdev->ifindex)) | |
19390 | goto free_msg; | |
19391 | ||
19392 | if (wakeup) { | |
19393 | struct nlattr *reasons; | |
19394 | ||
ae0be8de MK |
19395 | reasons = nla_nest_start_noflag(msg, |
19396 | NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
19397 | if (!reasons) |
19398 | goto free_msg; | |
cd8f7cb4 JB |
19399 | |
19400 | if (wakeup->disconnect && | |
19401 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
19402 | goto free_msg; | |
19403 | if (wakeup->magic_pkt && | |
19404 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
19405 | goto free_msg; | |
19406 | if (wakeup->gtk_rekey_failure && | |
19407 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
19408 | goto free_msg; | |
19409 | if (wakeup->eap_identity_req && | |
19410 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
19411 | goto free_msg; | |
19412 | if (wakeup->four_way_handshake && | |
19413 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
19414 | goto free_msg; | |
19415 | if (wakeup->rfkill_release && | |
19416 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
19417 | goto free_msg; | |
19418 | ||
19419 | if (wakeup->pattern_idx >= 0 && | |
19420 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
19421 | wakeup->pattern_idx)) | |
19422 | goto free_msg; | |
19423 | ||
ae917c9f JB |
19424 | if (wakeup->tcp_match && |
19425 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
19426 | goto free_msg; | |
2a0e047e | 19427 | |
ae917c9f JB |
19428 | if (wakeup->tcp_connlost && |
19429 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
19430 | goto free_msg; | |
2a0e047e | 19431 | |
ae917c9f JB |
19432 | if (wakeup->tcp_nomoretokens && |
19433 | nla_put_flag(msg, | |
19434 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
19435 | goto free_msg; | |
2a0e047e | 19436 | |
cd8f7cb4 JB |
19437 | if (wakeup->packet) { |
19438 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
19439 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
19440 | ||
19441 | if (!wakeup->packet_80211) { | |
19442 | pkt_attr = | |
19443 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
19444 | len_attr = | |
19445 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
19446 | } | |
19447 | ||
19448 | if (wakeup->packet_len && | |
19449 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
19450 | goto free_msg; | |
19451 | ||
19452 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
19453 | wakeup->packet)) | |
19454 | goto free_msg; | |
19455 | } | |
19456 | ||
8cd4d456 LC |
19457 | if (wakeup->net_detect && |
19458 | cfg80211_net_detect_results(msg, wakeup)) | |
19459 | goto free_msg; | |
19460 | ||
cd8f7cb4 JB |
19461 | nla_nest_end(msg, reasons); |
19462 | } | |
19463 | ||
9c90a9f6 | 19464 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 19465 | |
68eb5503 | 19466 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 19467 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
19468 | return; |
19469 | ||
19470 | free_msg: | |
19471 | nlmsg_free(msg); | |
19472 | } | |
19473 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
19474 | #endif | |
19475 | ||
3475b094 JM |
19476 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
19477 | enum nl80211_tdls_operation oper, | |
19478 | u16 reason_code, gfp_t gfp) | |
19479 | { | |
19480 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 19481 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
19482 | struct sk_buff *msg; |
19483 | void *hdr; | |
3475b094 JM |
19484 | |
19485 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
19486 | reason_code); | |
19487 | ||
19488 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
19489 | if (!msg) | |
19490 | return; | |
19491 | ||
19492 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
19493 | if (!hdr) { | |
19494 | nlmsg_free(msg); | |
19495 | return; | |
19496 | } | |
19497 | ||
19498 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
19499 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
19500 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
19501 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
19502 | (reason_code > 0 && | |
19503 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
19504 | goto nla_put_failure; | |
19505 | ||
9c90a9f6 | 19506 | genlmsg_end(msg, hdr); |
3475b094 | 19507 | |
68eb5503 | 19508 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 19509 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
19510 | return; |
19511 | ||
19512 | nla_put_failure: | |
3475b094 JM |
19513 | nlmsg_free(msg); |
19514 | } | |
19515 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
19516 | ||
026331c4 JM |
19517 | static int nl80211_netlink_notify(struct notifier_block * nb, |
19518 | unsigned long state, | |
19519 | void *_notify) | |
19520 | { | |
19521 | struct netlink_notify *notify = _notify; | |
19522 | struct cfg80211_registered_device *rdev; | |
19523 | struct wireless_dev *wdev; | |
37c73b5f | 19524 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 | 19525 | |
8f815cdd | 19526 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
026331c4 JM |
19527 | return NOTIFY_DONE; |
19528 | ||
19529 | rcu_read_lock(); | |
19530 | ||
5e760230 | 19531 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
ca986ad9 | 19532 | struct cfg80211_sched_scan_request *sched_scan_req; |
753aacfd | 19533 | |
ca986ad9 AVS |
19534 | list_for_each_entry_rcu(sched_scan_req, |
19535 | &rdev->sched_scan_req_list, | |
19536 | list) { | |
19537 | if (sched_scan_req->owner_nlportid == notify->portid) { | |
19538 | sched_scan_req->nl_owner_dead = true; | |
753aacfd | 19539 | schedule_work(&rdev->sched_scan_stop_wk); |
ca986ad9 | 19540 | } |
753aacfd | 19541 | } |
78f22b6a | 19542 | |
53873f13 | 19543 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
15e47304 | 19544 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 19545 | |
ab81007a JB |
19546 | if (wdev->owner_nlportid == notify->portid) { |
19547 | wdev->nl_owner_dead = true; | |
19548 | schedule_work(&rdev->destroy_work); | |
19549 | } else if (wdev->conn_owner_nlportid == notify->portid) { | |
bd2522b1 | 19550 | schedule_work(&wdev->disconnect_wk); |
ab81007a | 19551 | } |
9bb7e0f2 JB |
19552 | |
19553 | cfg80211_release_pmsr(wdev, notify->portid); | |
78f22b6a JB |
19554 | } |
19555 | ||
37c73b5f BG |
19556 | spin_lock_bh(&rdev->beacon_registrations_lock); |
19557 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
19558 | list) { | |
19559 | if (reg->nlportid == notify->portid) { | |
19560 | list_del(®->list); | |
19561 | kfree(reg); | |
19562 | break; | |
19563 | } | |
19564 | } | |
19565 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 | 19566 | } |
026331c4 JM |
19567 | |
19568 | rcu_read_unlock(); | |
19569 | ||
05050753 I |
19570 | /* |
19571 | * It is possible that the user space process that is controlling the | |
19572 | * indoor setting disappeared, so notify the regulatory core. | |
19573 | */ | |
19574 | regulatory_netlink_notify(notify->portid); | |
6784c7db | 19575 | return NOTIFY_OK; |
026331c4 JM |
19576 | } |
19577 | ||
19578 | static struct notifier_block nl80211_netlink_notifier = { | |
19579 | .notifier_call = nl80211_netlink_notify, | |
19580 | }; | |
19581 | ||
355199e0 JM |
19582 | void cfg80211_ft_event(struct net_device *netdev, |
19583 | struct cfg80211_ft_event_params *ft_event) | |
19584 | { | |
19585 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 19586 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
19587 | struct sk_buff *msg; |
19588 | void *hdr; | |
355199e0 JM |
19589 | |
19590 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
19591 | ||
19592 | if (!ft_event->target_ap) | |
19593 | return; | |
19594 | ||
1039d081 DL |
19595 | msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, |
19596 | GFP_KERNEL); | |
355199e0 JM |
19597 | if (!msg) |
19598 | return; | |
19599 | ||
19600 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
19601 | if (!hdr) |
19602 | goto out; | |
355199e0 | 19603 | |
ae917c9f JB |
19604 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
19605 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
19606 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
19607 | goto out; | |
355199e0 | 19608 | |
ae917c9f JB |
19609 | if (ft_event->ies && |
19610 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
19611 | goto out; | |
19612 | if (ft_event->ric_ies && | |
19613 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
19614 | ft_event->ric_ies)) | |
19615 | goto out; | |
355199e0 | 19616 | |
9c90a9f6 | 19617 | genlmsg_end(msg, hdr); |
355199e0 | 19618 | |
68eb5503 | 19619 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 19620 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
19621 | return; |
19622 | out: | |
19623 | nlmsg_free(msg); | |
355199e0 JM |
19624 | } |
19625 | EXPORT_SYMBOL(cfg80211_ft_event); | |
19626 | ||
5de17984 AS |
19627 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
19628 | { | |
19629 | struct cfg80211_registered_device *rdev; | |
19630 | struct sk_buff *msg; | |
19631 | void *hdr; | |
19632 | u32 nlportid; | |
19633 | ||
f26cbf40 | 19634 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
19635 | if (!rdev->crit_proto_nlportid) |
19636 | return; | |
19637 | ||
19638 | nlportid = rdev->crit_proto_nlportid; | |
19639 | rdev->crit_proto_nlportid = 0; | |
19640 | ||
19641 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
19642 | if (!msg) | |
19643 | return; | |
19644 | ||
19645 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
19646 | if (!hdr) | |
19647 | goto nla_put_failure; | |
19648 | ||
19649 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
19650 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
19651 | NL80211_ATTR_PAD)) | |
5de17984 AS |
19652 | goto nla_put_failure; |
19653 | ||
19654 | genlmsg_end(msg, hdr); | |
19655 | ||
19656 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
19657 | return; | |
19658 | ||
19659 | nla_put_failure: | |
5de17984 | 19660 | nlmsg_free(msg); |
5de17984 AS |
19661 | } |
19662 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
19663 | ||
348baf0e JB |
19664 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
19665 | { | |
19666 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 19667 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
19668 | struct sk_buff *msg; |
19669 | void *hdr; | |
19670 | ||
19671 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
19672 | if (!msg) | |
19673 | return; | |
19674 | ||
19675 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
19676 | if (!hdr) | |
19677 | goto out; | |
19678 | ||
19679 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
19680 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
2dad624e ND |
19681 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
19682 | NL80211_ATTR_PAD)) | |
348baf0e JB |
19683 | goto out; |
19684 | ||
19685 | genlmsg_end(msg, hdr); | |
19686 | ||
19687 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
19688 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
19689 | return; | |
19690 | out: | |
19691 | nlmsg_free(msg); | |
19692 | } | |
19693 | ||
40cbfa90 SD |
19694 | int cfg80211_external_auth_request(struct net_device *dev, |
19695 | struct cfg80211_external_auth_params *params, | |
19696 | gfp_t gfp) | |
19697 | { | |
19698 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
19699 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | |
19700 | struct sk_buff *msg; | |
19701 | void *hdr; | |
19702 | ||
19703 | if (!wdev->conn_owner_nlportid) | |
19704 | return -EINVAL; | |
19705 | ||
19706 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
19707 | if (!msg) | |
19708 | return -ENOMEM; | |
19709 | ||
19710 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); | |
19711 | if (!hdr) | |
19712 | goto nla_put_failure; | |
19713 | ||
19714 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
19715 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
19716 | nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || | |
19717 | nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, | |
19718 | params->action) || | |
19719 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || | |
19720 | nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, | |
19721 | params->ssid.ssid)) | |
19722 | goto nla_put_failure; | |
19723 | ||
19724 | genlmsg_end(msg, hdr); | |
19725 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, | |
19726 | wdev->conn_owner_nlportid); | |
19727 | return 0; | |
19728 | ||
19729 | nla_put_failure: | |
19730 | nlmsg_free(msg); | |
19731 | return -ENOBUFS; | |
19732 | } | |
19733 | EXPORT_SYMBOL(cfg80211_external_auth_request); | |
19734 | ||
cb74e977 SD |
19735 | void cfg80211_update_owe_info_event(struct net_device *netdev, |
19736 | struct cfg80211_update_owe_info *owe_info, | |
19737 | gfp_t gfp) | |
19738 | { | |
19739 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
19740 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
19741 | struct sk_buff *msg; | |
19742 | void *hdr; | |
19743 | ||
19744 | trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info); | |
19745 | ||
19746 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
19747 | if (!msg) | |
19748 | return; | |
19749 | ||
19750 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO); | |
19751 | if (!hdr) | |
19752 | goto nla_put_failure; | |
19753 | ||
19754 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
19755 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
19756 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer)) | |
19757 | goto nla_put_failure; | |
19758 | ||
19759 | if (!owe_info->ie_len || | |
19760 | nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie)) | |
19761 | goto nla_put_failure; | |
19762 | ||
19763 | genlmsg_end(msg, hdr); | |
19764 | ||
19765 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | |
19766 | NL80211_MCGRP_MLME, gfp); | |
19767 | return; | |
19768 | ||
19769 | nla_put_failure: | |
19770 | genlmsg_cancel(msg, hdr); | |
19771 | nlmsg_free(msg); | |
19772 | } | |
19773 | EXPORT_SYMBOL(cfg80211_update_owe_info_event); | |
19774 | ||
55682965 JB |
19775 | /* initialisation/exit functions */ |
19776 | ||
56989f6d | 19777 | int __init nl80211_init(void) |
55682965 | 19778 | { |
0d63cbb5 | 19779 | int err; |
55682965 | 19780 | |
489111e5 | 19781 | err = genl_register_family(&nl80211_fam); |
55682965 JB |
19782 | if (err) |
19783 | return err; | |
19784 | ||
026331c4 JM |
19785 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
19786 | if (err) | |
19787 | goto err_out; | |
19788 | ||
55682965 JB |
19789 | return 0; |
19790 | err_out: | |
19791 | genl_unregister_family(&nl80211_fam); | |
19792 | return err; | |
19793 | } | |
19794 | ||
19795 | void nl80211_exit(void) | |
19796 | { | |
026331c4 | 19797 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
19798 | genl_unregister_family(&nl80211_fam); |
19799 | } |