Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
f0706e82 | 2 | /* |
c5d54fbf | 3 | * Interface handling |
0d143fe1 | 4 | * |
f0706e82 JB |
5 | * Copyright 2002-2005, Instant802 Networks, Inc. |
6 | * Copyright 2005-2006, Devicescape Software, Inc. | |
7 | * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz> | |
75636525 | 8 | * Copyright 2008, Johannes Berg <johannes@sipsolutions.net> |
d98ad83e | 9 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
d2941df8 | 10 | * Copyright (c) 2016 Intel Deutschland GmbH |
6c93fd50 | 11 | * Copyright (C) 2018-2025 Intel Corporation |
f0706e82 | 12 | */ |
5a0e3ad6 | 13 | #include <linux/slab.h> |
f0706e82 JB |
14 | #include <linux/kernel.h> |
15 | #include <linux/if_arp.h> | |
16 | #include <linux/netdevice.h> | |
17 | #include <linux/rtnetlink.h> | |
183f47fc | 18 | #include <linux/kcov.h> |
f0706e82 | 19 | #include <net/mac80211.h> |
cf0277e7 | 20 | #include <net/ieee80211_radiotap.h> |
f0706e82 JB |
21 | #include "ieee80211_i.h" |
22 | #include "sta_info.h" | |
e9f207f0 | 23 | #include "debugfs_netdev.h" |
ee385855 | 24 | #include "mesh.h" |
0d143fe1 | 25 | #include "led.h" |
24487981 | 26 | #include "driver-ops.h" |
cf0277e7 | 27 | #include "wme.h" |
1be7fe8d | 28 | #include "rate.h" |
0d143fe1 | 29 | |
c771c9d8 JB |
30 | /** |
31 | * DOC: Interface list locking | |
32 | * | |
33 | * The interface list in each struct ieee80211_local is protected | |
34 | * three-fold: | |
35 | * | |
be0df01d JB |
36 | * (1) modifications may only be done under the RTNL *and* wiphy mutex |
37 | * *and* iflist_mtx | |
38 | * (2) modifications are done in an RCU manner so atomic readers | |
c771c9d8 JB |
39 | * can traverse the list in RCU-safe blocks. |
40 | * | |
41 | * As a consequence, reads (traversals) of the list can be protected | |
be0df01d | 42 | * by either the RTNL, the wiphy mutex, the iflist_mtx or RCU. |
c771c9d8 JB |
43 | */ |
44 | ||
16114496 | 45 | static void ieee80211_iface_work(struct wiphy *wiphy, struct wiphy_work *work); |
42bd20d9 | 46 | |
0b7392ee | 47 | bool __ieee80211_recalc_txpower(struct ieee80211_link_data *link) |
1ea6f9c0 JB |
48 | { |
49 | struct ieee80211_chanctx_conf *chanctx_conf; | |
50 | int power; | |
51 | ||
52 | rcu_read_lock(); | |
c4382d5c | 53 | chanctx_conf = rcu_dereference(link->conf->chanctx_conf); |
1ea6f9c0 JB |
54 | if (!chanctx_conf) { |
55 | rcu_read_unlock(); | |
56 | return false; | |
57 | } | |
58 | ||
0430c883 | 59 | power = ieee80211_chandef_max_power(&chanctx_conf->def); |
1ea6f9c0 JB |
60 | rcu_read_unlock(); |
61 | ||
c4382d5c EG |
62 | if (link->user_power_level != IEEE80211_UNSET_POWER_LEVEL) |
63 | power = min(power, link->user_power_level); | |
1ea6f9c0 | 64 | |
c4382d5c EG |
65 | if (link->ap_power_level != IEEE80211_UNSET_POWER_LEVEL) |
66 | power = min(power, link->ap_power_level); | |
1ea6f9c0 | 67 | |
c4382d5c EG |
68 | if (power != link->conf->txpower) { |
69 | link->conf->txpower = power; | |
1ea6f9c0 JB |
70 | return true; |
71 | } | |
72 | ||
73 | return false; | |
74 | } | |
75 | ||
9925aa85 | 76 | void ieee80211_recalc_txpower(struct ieee80211_link_data *link, |
db82d8a9 | 77 | bool update_bss) |
1ea6f9c0 | 78 | { |
0b7392ee | 79 | if (__ieee80211_recalc_txpower(link) || |
9925aa85 EG |
80 | (update_bss && ieee80211_sdata_running(link->sdata))) |
81 | ieee80211_link_info_change_notify(link->sdata, link, | |
7b7090b4 | 82 | BSS_CHANGED_TXPOWER); |
1ea6f9c0 | 83 | } |
c771c9d8 | 84 | |
62a40a15 | 85 | static u32 __ieee80211_idle_off(struct ieee80211_local *local) |
cc45ae54 JB |
86 | { |
87 | if (!(local->hw.conf.flags & IEEE80211_CONF_IDLE)) | |
88 | return 0; | |
89 | ||
90 | local->hw.conf.flags &= ~IEEE80211_CONF_IDLE; | |
91 | return IEEE80211_CONF_CHANGE_IDLE; | |
92 | } | |
93 | ||
62a40a15 | 94 | static u32 __ieee80211_idle_on(struct ieee80211_local *local) |
cc45ae54 JB |
95 | { |
96 | if (local->hw.conf.flags & IEEE80211_CONF_IDLE) | |
97 | return 0; | |
98 | ||
3b24f4c6 | 99 | ieee80211_flush_queues(local, NULL, false); |
cc45ae54 JB |
100 | |
101 | local->hw.conf.flags |= IEEE80211_CONF_IDLE; | |
102 | return IEEE80211_CONF_CHANGE_IDLE; | |
103 | } | |
104 | ||
62a40a15 JB |
105 | static u32 __ieee80211_recalc_idle(struct ieee80211_local *local, |
106 | bool force_active) | |
cc45ae54 | 107 | { |
1d5e1266 | 108 | bool working, scanning, active; |
cc45ae54 | 109 | unsigned int led_trig_start = 0, led_trig_stop = 0; |
cc45ae54 | 110 | |
0cd8080e | 111 | lockdep_assert_wiphy(local->hw.wiphy); |
cc45ae54 | 112 | |
62a40a15 JB |
113 | active = force_active || |
114 | !list_empty(&local->chanctx_list) || | |
115 | local->monitors; | |
cc45ae54 | 116 | |
1d5e1266 JB |
117 | working = !local->ops->remain_on_channel && |
118 | !list_empty(&local->roc_list); | |
cc45ae54 | 119 | |
f1e3e051 JB |
120 | scanning = test_bit(SCAN_SW_SCANNING, &local->scanning) || |
121 | test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning); | |
cc45ae54 | 122 | |
cc45ae54 JB |
123 | if (working || scanning) |
124 | led_trig_start |= IEEE80211_TPT_LEDTRIG_FL_WORK; | |
125 | else | |
126 | led_trig_stop |= IEEE80211_TPT_LEDTRIG_FL_WORK; | |
127 | ||
fd0f979a | 128 | if (active) |
cc45ae54 JB |
129 | led_trig_start |= IEEE80211_TPT_LEDTRIG_FL_CONNECTED; |
130 | else | |
131 | led_trig_stop |= IEEE80211_TPT_LEDTRIG_FL_CONNECTED; | |
132 | ||
133 | ieee80211_mod_tpt_led_trig(local, led_trig_start, led_trig_stop); | |
134 | ||
fd0f979a | 135 | if (working || scanning || active) |
62a40a15 JB |
136 | return __ieee80211_idle_off(local); |
137 | return __ieee80211_idle_on(local); | |
138 | } | |
139 | ||
140 | u32 ieee80211_idle_off(struct ieee80211_local *local) | |
141 | { | |
142 | return __ieee80211_recalc_idle(local, true); | |
143 | } | |
144 | ||
145 | void ieee80211_recalc_idle(struct ieee80211_local *local) | |
146 | { | |
147 | u32 change = __ieee80211_recalc_idle(local, false); | |
fd0f979a JB |
148 | if (change) |
149 | ieee80211_hw_config(local, change); | |
cc45ae54 JB |
150 | } |
151 | ||
3899ba90 | 152 | static int ieee80211_verify_mac(struct ieee80211_sub_if_data *sdata, u8 *addr, |
31eba5bc | 153 | bool check_dup) |
478622e8 | 154 | { |
ac20976d HS |
155 | struct ieee80211_local *local = sdata->local; |
156 | struct ieee80211_sub_if_data *iter; | |
478622e8 HS |
157 | u64 new, mask, tmp; |
158 | u8 *m; | |
159 | int ret = 0; | |
160 | ||
be0df01d JB |
161 | lockdep_assert_wiphy(local->hw.wiphy); |
162 | ||
478622e8 HS |
163 | if (is_zero_ether_addr(local->hw.wiphy->addr_mask)) |
164 | return 0; | |
165 | ||
166 | m = addr; | |
167 | new = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) | | |
168 | ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) | | |
169 | ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8); | |
170 | ||
171 | m = local->hw.wiphy->addr_mask; | |
172 | mask = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) | | |
173 | ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) | | |
174 | ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8); | |
175 | ||
31eba5bc FF |
176 | if (!check_dup) |
177 | return ret; | |
478622e8 | 178 | |
ac20976d HS |
179 | list_for_each_entry(iter, &local->interfaces, list) { |
180 | if (iter == sdata) | |
478622e8 HS |
181 | continue; |
182 | ||
3899ba90 | 183 | if (iter->vif.type == NL80211_IFTYPE_MONITOR && |
d8212184 | 184 | !(iter->u.mntr.flags & MONITOR_FLAG_ACTIVE)) |
478622e8 HS |
185 | continue; |
186 | ||
ac20976d | 187 | m = iter->vif.addr; |
478622e8 HS |
188 | tmp = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) | |
189 | ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) | | |
190 | ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8); | |
191 | ||
192 | if ((new & ~mask) != (tmp & ~mask)) { | |
193 | ret = -EINVAL; | |
194 | break; | |
195 | } | |
196 | } | |
478622e8 HS |
197 | |
198 | return ret; | |
199 | } | |
200 | ||
3c06e91b JP |
201 | static int ieee80211_can_powered_addr_change(struct ieee80211_sub_if_data *sdata) |
202 | { | |
203 | struct ieee80211_roc_work *roc; | |
204 | struct ieee80211_local *local = sdata->local; | |
205 | struct ieee80211_sub_if_data *scan_sdata; | |
206 | int ret = 0; | |
207 | ||
0cd8080e JB |
208 | lockdep_assert_wiphy(local->hw.wiphy); |
209 | ||
3c06e91b JP |
210 | /* To be the most flexible here we want to only limit changing the |
211 | * address if the specific interface is doing offchannel work or | |
212 | * scanning. | |
213 | */ | |
214 | if (netif_carrier_ok(sdata->dev)) | |
215 | return -EBUSY; | |
216 | ||
3c06e91b JP |
217 | /* First check no ROC work is happening on this iface */ |
218 | list_for_each_entry(roc, &local->roc_list, list) { | |
219 | if (roc->sdata != sdata) | |
220 | continue; | |
221 | ||
222 | if (roc->started) { | |
223 | ret = -EBUSY; | |
224 | goto unlock; | |
225 | } | |
226 | } | |
227 | ||
228 | /* And if this iface is scanning */ | |
229 | if (local->scanning) { | |
230 | scan_sdata = rcu_dereference_protected(local->scan_sdata, | |
0cd8080e | 231 | lockdep_is_held(&local->hw.wiphy->mtx)); |
3c06e91b JP |
232 | if (sdata == scan_sdata) |
233 | ret = -EBUSY; | |
234 | } | |
235 | ||
236 | switch (sdata->vif.type) { | |
237 | case NL80211_IFTYPE_STATION: | |
238 | case NL80211_IFTYPE_P2P_CLIENT: | |
239 | /* More interface types could be added here but changing the | |
240 | * address while powered makes the most sense in client modes. | |
241 | */ | |
242 | break; | |
243 | default: | |
ceb3d688 | 244 | ret = -EOPNOTSUPP; |
3c06e91b JP |
245 | } |
246 | ||
247 | unlock: | |
3c06e91b JP |
248 | return ret; |
249 | } | |
250 | ||
a26787aa JB |
251 | static int _ieee80211_change_mac(struct ieee80211_sub_if_data *sdata, |
252 | void *addr) | |
47846c9b | 253 | { |
3c06e91b | 254 | struct ieee80211_local *local = sdata->local; |
fc5f7577 | 255 | struct sockaddr *sa = addr; |
31eba5bc | 256 | bool check_dup = true; |
3c06e91b | 257 | bool live = false; |
47846c9b JB |
258 | int ret; |
259 | ||
3c06e91b JP |
260 | if (ieee80211_sdata_running(sdata)) { |
261 | ret = ieee80211_can_powered_addr_change(sdata); | |
262 | if (ret) | |
263 | return ret; | |
264 | ||
265 | live = true; | |
266 | } | |
47846c9b | 267 | |
31eba5bc | 268 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR && |
d8212184 | 269 | !(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE)) |
31eba5bc FF |
270 | check_dup = false; |
271 | ||
3899ba90 | 272 | ret = ieee80211_verify_mac(sdata, sa->sa_data, check_dup); |
478622e8 HS |
273 | if (ret) |
274 | return ret; | |
275 | ||
3c06e91b JP |
276 | if (live) |
277 | drv_remove_interface(local, sdata); | |
a26787aa | 278 | ret = eth_mac_addr(sdata->dev, sa); |
47846c9b | 279 | |
d8787ec6 | 280 | if (ret == 0) { |
52cebabb FF |
281 | memcpy(sdata->vif.addr, sa->sa_data, ETH_ALEN); |
282 | ether_addr_copy(sdata->vif.bss_conf.addr, sdata->vif.addr); | |
d8787ec6 | 283 | } |
47846c9b | 284 | |
3c06e91b JP |
285 | /* Regardless of eth_mac_addr() return we still want to add the |
286 | * interface back. This should not fail... | |
287 | */ | |
288 | if (live) | |
289 | WARN_ON(drv_add_interface(local, sdata)); | |
290 | ||
47846c9b JB |
291 | return ret; |
292 | } | |
293 | ||
a26787aa JB |
294 | static int ieee80211_change_mac(struct net_device *dev, void *addr) |
295 | { | |
296 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
297 | struct ieee80211_local *local = sdata->local; | |
a26787aa | 298 | |
74a7c93f JB |
299 | /* |
300 | * This happens during unregistration if there's a bond device | |
301 | * active (maybe other cases?) and we must get removed from it. | |
302 | * But we really don't care anymore if it's not registered now. | |
303 | */ | |
304 | if (!dev->ieee80211_ptr->registered) | |
305 | return 0; | |
306 | ||
8e66f6c6 | 307 | guard(wiphy)(local->hw.wiphy); |
a26787aa | 308 | |
8e66f6c6 | 309 | return _ieee80211_change_mac(sdata, addr); |
a26787aa JB |
310 | } |
311 | ||
0d143fe1 JB |
312 | static inline int identical_mac_addr_allowed(int type1, int type2) |
313 | { | |
314 | return type1 == NL80211_IFTYPE_MONITOR || | |
315 | type2 == NL80211_IFTYPE_MONITOR || | |
f142c6b9 JB |
316 | type1 == NL80211_IFTYPE_P2P_DEVICE || |
317 | type2 == NL80211_IFTYPE_P2P_DEVICE || | |
0d143fe1 JB |
318 | (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_AP_VLAN) || |
319 | (type1 == NL80211_IFTYPE_AP_VLAN && | |
320 | (type2 == NL80211_IFTYPE_AP || | |
321 | type2 == NL80211_IFTYPE_AP_VLAN)); | |
322 | } | |
323 | ||
87490f6d JB |
324 | static int ieee80211_check_concurrent_iface(struct ieee80211_sub_if_data *sdata, |
325 | enum nl80211_iftype iftype) | |
0d143fe1 | 326 | { |
b4a4bf5d | 327 | struct ieee80211_local *local = sdata->local; |
87490f6d | 328 | struct ieee80211_sub_if_data *nsdata; |
0d143fe1 | 329 | |
87490f6d | 330 | ASSERT_RTNL(); |
5435af6e | 331 | lockdep_assert_wiphy(local->hw.wiphy); |
0d143fe1 JB |
332 | |
333 | /* we hold the RTNL here so can safely walk the list */ | |
334 | list_for_each_entry(nsdata, &local->interfaces, list) { | |
371a255e | 335 | if (nsdata != sdata && ieee80211_sdata_running(nsdata)) { |
239281f8 RL |
336 | /* |
337 | * Only OCB and monitor mode may coexist | |
338 | */ | |
339 | if ((sdata->vif.type == NL80211_IFTYPE_OCB && | |
340 | nsdata->vif.type != NL80211_IFTYPE_MONITOR) || | |
341 | (sdata->vif.type != NL80211_IFTYPE_MONITOR && | |
342 | nsdata->vif.type == NL80211_IFTYPE_OCB)) | |
343 | return -EBUSY; | |
344 | ||
0d143fe1 JB |
345 | /* |
346 | * Allow only a single IBSS interface to be up at any | |
347 | * time. This is restricted because beacon distribution | |
348 | * cannot work properly if both are in the same IBSS. | |
349 | * | |
350 | * To remove this restriction we'd have to disallow them | |
351 | * from setting the same SSID on different IBSS interfaces | |
352 | * belonging to the same hardware. Then, however, we're | |
353 | * faced with having to adopt two different TSF timers... | |
354 | */ | |
87490f6d | 355 | if (iftype == NL80211_IFTYPE_ADHOC && |
0d143fe1 JB |
356 | nsdata->vif.type == NL80211_IFTYPE_ADHOC) |
357 | return -EBUSY; | |
73da7d5b SW |
358 | /* |
359 | * will not add another interface while any channel | |
360 | * switch is active. | |
361 | */ | |
d0a9123e | 362 | if (nsdata->vif.bss_conf.csa_active) |
73da7d5b | 363 | return -EBUSY; |
0d143fe1 JB |
364 | |
365 | /* | |
366 | * The remaining checks are only performed for interfaces | |
367 | * with the same MAC address. | |
368 | */ | |
371a255e JB |
369 | if (!ether_addr_equal(sdata->vif.addr, |
370 | nsdata->vif.addr)) | |
0d143fe1 JB |
371 | continue; |
372 | ||
373 | /* | |
374 | * check whether it may have the same address | |
375 | */ | |
87490f6d | 376 | if (!identical_mac_addr_allowed(iftype, |
0d143fe1 JB |
377 | nsdata->vif.type)) |
378 | return -ENOTUNIQ; | |
379 | ||
ae960ee9 JB |
380 | /* No support for VLAN with MLO yet */ |
381 | if (iftype == NL80211_IFTYPE_AP_VLAN && | |
f216033d FF |
382 | sdata->wdev.use_4addr && |
383 | nsdata->vif.type == NL80211_IFTYPE_AP && | |
384 | nsdata->vif.valid_links) | |
ae960ee9 JB |
385 | return -EOPNOTSUPP; |
386 | ||
0d143fe1 JB |
387 | /* |
388 | * can only add VLANs to enabled APs | |
389 | */ | |
87490f6d | 390 | if (iftype == NL80211_IFTYPE_AP_VLAN && |
0d143fe1 JB |
391 | nsdata->vif.type == NL80211_IFTYPE_AP) |
392 | sdata->bss = &nsdata->u.ap; | |
393 | } | |
394 | } | |
395 | ||
0874bcd0 | 396 | return ieee80211_check_combinations(sdata, NULL, 0, 0, -1); |
87490f6d JB |
397 | } |
398 | ||
a9865538 JB |
399 | static int ieee80211_check_queues(struct ieee80211_sub_if_data *sdata, |
400 | enum nl80211_iftype iftype) | |
3a25a8c8 JB |
401 | { |
402 | int n_queues = sdata->local->hw.queues; | |
403 | int i; | |
404 | ||
708d50ed AB |
405 | if (iftype == NL80211_IFTYPE_NAN) |
406 | return 0; | |
407 | ||
a9865538 | 408 | if (iftype != NL80211_IFTYPE_P2P_DEVICE) { |
0ef24e52 IP |
409 | for (i = 0; i < IEEE80211_NUM_ACS; i++) { |
410 | if (WARN_ON_ONCE(sdata->vif.hw_queue[i] == | |
411 | IEEE80211_INVAL_HW_QUEUE)) | |
412 | return -EINVAL; | |
413 | if (WARN_ON_ONCE(sdata->vif.hw_queue[i] >= | |
414 | n_queues)) | |
415 | return -EINVAL; | |
416 | } | |
3a25a8c8 JB |
417 | } |
418 | ||
a9865538 JB |
419 | if ((iftype != NL80211_IFTYPE_AP && |
420 | iftype != NL80211_IFTYPE_P2P_GO && | |
421 | iftype != NL80211_IFTYPE_MESH_POINT) || | |
30686bf7 | 422 | !ieee80211_hw_check(&sdata->local->hw, QUEUE_CONTROL)) { |
3a25a8c8 JB |
423 | sdata->vif.cab_queue = IEEE80211_INVAL_HW_QUEUE; |
424 | return 0; | |
425 | } | |
426 | ||
427 | if (WARN_ON_ONCE(sdata->vif.cab_queue == IEEE80211_INVAL_HW_QUEUE)) | |
428 | return -EINVAL; | |
429 | ||
430 | if (WARN_ON_ONCE(sdata->vif.cab_queue >= n_queues)) | |
431 | return -EINVAL; | |
432 | ||
433 | return 0; | |
434 | } | |
435 | ||
4b7afb52 | 436 | static int ieee80211_open(struct net_device *dev) |
6aea26ce | 437 | { |
4b7afb52 FF |
438 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
439 | int err; | |
440 | ||
441 | /* fail early if user set an invalid address */ | |
442 | if (!is_valid_ether_addr(dev->dev_addr)) | |
443 | return -EADDRNOTAVAIL; | |
444 | ||
8e66f6c6 JB |
445 | guard(wiphy)(sdata->local->hw.wiphy); |
446 | ||
4b7afb52 FF |
447 | err = ieee80211_check_concurrent_iface(sdata, sdata->vif.type); |
448 | if (err) | |
8e66f6c6 | 449 | return err; |
4b7afb52 | 450 | |
8e66f6c6 | 451 | return ieee80211_do_open(&sdata->wdev, true); |
6aea26ce FF |
452 | } |
453 | ||
a05829a7 | 454 | static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata, bool going_down) |
6aea26ce FF |
455 | { |
456 | struct ieee80211_local *local = sdata->local; | |
4b7afb52 | 457 | unsigned long flags; |
9d301de1 | 458 | struct sk_buff_head freeq; |
4b7afb52 FF |
459 | struct sk_buff *skb, *tmp; |
460 | u32 hw_reconf_flags = 0; | |
461 | int i, flushed; | |
462 | struct ps_data *ps; | |
463 | struct cfg80211_chan_def chandef; | |
464 | bool cancel_scan; | |
465 | struct cfg80211_nan_func *func; | |
6aea26ce | 466 | |
0cd8080e JB |
467 | lockdep_assert_wiphy(local->hw.wiphy); |
468 | ||
4b7afb52 | 469 | clear_bit(SDATA_STATE_RUNNING, &sdata->state); |
3598cb6e | 470 | synchronize_rcu(); /* flush _ieee80211_wake_txqs() */ |
6aea26ce | 471 | |
4b7afb52 FF |
472 | cancel_scan = rcu_access_pointer(local->scan_sdata) == sdata; |
473 | if (cancel_scan) | |
474 | ieee80211_scan_cancel(local); | |
6aea26ce | 475 | |
4b7afb52 | 476 | ieee80211_roc_purge(local, sdata); |
6aea26ce | 477 | |
4b7afb52 FF |
478 | switch (sdata->vif.type) { |
479 | case NL80211_IFTYPE_STATION: | |
480 | ieee80211_mgd_stop(sdata); | |
481 | break; | |
482 | case NL80211_IFTYPE_ADHOC: | |
483 | ieee80211_ibss_stop(sdata); | |
484 | break; | |
485 | case NL80211_IFTYPE_MONITOR: | |
4b7afb52 FF |
486 | list_del_rcu(&sdata->u.mntr.list); |
487 | break; | |
90233b0a MS |
488 | case NL80211_IFTYPE_AP_VLAN: |
489 | ieee80211_apvlan_link_clear(sdata); | |
490 | break; | |
4b7afb52 FF |
491 | default: |
492 | break; | |
493 | } | |
6aea26ce | 494 | |
4b7afb52 FF |
495 | /* |
496 | * Remove all stations associated with this interface. | |
497 | * | |
498 | * This must be done before calling ops->remove_interface() | |
499 | * because otherwise we can later invoke ops->sta_notify() | |
500 | * whenever the STAs are removed, and that invalidates driver | |
501 | * assumptions about always getting a vif pointer that is valid | |
502 | * (because if we remove a STA after ops->remove_interface() | |
503 | * the driver will have removed the vif info already!) | |
504 | * | |
70d9c599 | 505 | * For AP_VLANs stations may exist since there's nothing else that |
4b7afb52 FF |
506 | * would have removed them, but in other modes there shouldn't |
507 | * be any stations. | |
508 | */ | |
ec67d6e0 | 509 | flushed = sta_info_flush(sdata, -1); |
70d9c599 | 510 | WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP_VLAN && flushed > 0); |
6aea26ce | 511 | |
4b7afb52 FF |
512 | /* don't count this interface for allmulti while it is down */ |
513 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) | |
514 | atomic_dec(&local->iff_allmultis); | |
6aea26ce | 515 | |
4b7afb52 FF |
516 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
517 | local->fif_pspoll--; | |
518 | local->fif_probe_req--; | |
519 | } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { | |
520 | local->fif_probe_req--; | |
6aea26ce FF |
521 | } |
522 | ||
4b7afb52 FF |
523 | if (sdata->dev) { |
524 | netif_addr_lock_bh(sdata->dev); | |
525 | spin_lock_bh(&local->filter_lock); | |
526 | __hw_addr_unsync(&local->mc_list, &sdata->dev->mc, | |
527 | sdata->dev->addr_len); | |
528 | spin_unlock_bh(&local->filter_lock); | |
529 | netif_addr_unlock_bh(sdata->dev); | |
6aea26ce | 530 | } |
6aea26ce | 531 | |
8fa7292f | 532 | timer_delete_sync(&local->dynamic_ps_timer); |
9fa659f9 | 533 | wiphy_work_cancel(local->hw.wiphy, &local->dynamic_ps_enable_work); |
6aea26ce | 534 | |
f1871abd | 535 | WARN(ieee80211_vif_is_mld(&sdata->vif), |
d8787ec6 JB |
536 | "destroying interface with valid links 0x%04x\n", |
537 | sdata->vif.valid_links); | |
538 | ||
d0a9123e | 539 | sdata->vif.bss_conf.csa_active = false; |
4b7afb52 | 540 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
344d18ce | 541 | sdata->deflink.u.mgd.csa.waiting_bcn = false; |
dc494fdc | 542 | ieee80211_vif_unblock_queues_csa(sdata); |
6aea26ce | 543 | |
344d18ce | 544 | wiphy_work_cancel(local->hw.wiphy, &sdata->deflink.csa.finalize_work); |
b38579ae JB |
545 | wiphy_work_cancel(local->hw.wiphy, |
546 | &sdata->deflink.color_change_finalize_work); | |
766d2601 | 547 | wiphy_delayed_work_cancel(local->hw.wiphy, |
6241d79f | 548 | &sdata->deflink.dfs_cac_timer_work); |
85416a4f | 549 | |
62c16f21 | 550 | if (sdata->wdev.links[0].cac_started) { |
6092077a | 551 | chandef = sdata->vif.bss_conf.chanreq.oper; |
4b7afb52 | 552 | WARN_ON(local->suspended); |
d8675a63 | 553 | ieee80211_link_release_channel(&sdata->deflink); |
4b7afb52 FF |
554 | cfg80211_cac_event(sdata->dev, &chandef, |
555 | NL80211_RADAR_CAC_ABORTED, | |
81f67d60 | 556 | GFP_KERNEL, 0); |
4b7afb52 | 557 | } |
85416a4f | 558 | |
4b7afb52 | 559 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
4b7afb52 FF |
560 | WARN_ON(!list_empty(&sdata->u.ap.vlans)); |
561 | } else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { | |
562 | /* remove all packets in parent bc_buf pointing to this dev */ | |
563 | ps = &sdata->bss->ps; | |
3a25a8c8 | 564 | |
4b7afb52 FF |
565 | spin_lock_irqsave(&ps->bc_buf.lock, flags); |
566 | skb_queue_walk_safe(&ps->bc_buf, skb, tmp) { | |
567 | if (skb->dev == sdata->dev) { | |
568 | __skb_unlink(skb, &ps->bc_buf); | |
569 | local->total_ps_buffered--; | |
570 | ieee80211_free_txskb(&local->hw, skb); | |
571 | } | |
572 | } | |
573 | spin_unlock_irqrestore(&ps->bc_buf.lock, flags); | |
3a25a8c8 | 574 | } |
3a25a8c8 | 575 | |
4b7afb52 FF |
576 | if (going_down) |
577 | local->open_count--; | |
4b6f1dd6 | 578 | |
4b7afb52 FF |
579 | switch (sdata->vif.type) { |
580 | case NL80211_IFTYPE_AP_VLAN: | |
4b7afb52 | 581 | list_del(&sdata->u.vlan.list); |
d0a9123e | 582 | RCU_INIT_POINTER(sdata->vif.bss_conf.chanctx_conf, NULL); |
4b7afb52 FF |
583 | /* see comment in the default case below */ |
584 | ieee80211_free_keys(sdata, true); | |
585 | /* no need to tell driver */ | |
586 | break; | |
587 | case NL80211_IFTYPE_MONITOR: | |
12986004 AW |
588 | local->monitors--; |
589 | ||
286e6967 AW |
590 | if (!(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) && |
591 | !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) { | |
685fb72b | 592 | |
12986004 AW |
593 | local->virt_monitors--; |
594 | if (local->virt_monitors == 0) { | |
286e6967 AW |
595 | local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR; |
596 | hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR; | |
597 | } | |
4b6f1dd6 | 598 | |
286e6967 AW |
599 | ieee80211_adjust_monitor_flags(sdata, -1); |
600 | } | |
4b7afb52 FF |
601 | break; |
602 | case NL80211_IFTYPE_NAN: | |
603 | /* clean all the functions */ | |
604 | spin_lock_bh(&sdata->u.nan.func_lock); | |
4b6f1dd6 | 605 | |
4b7afb52 FF |
606 | idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, i) { |
607 | idr_remove(&sdata->u.nan.function_inst_ids, i); | |
608 | cfg80211_free_nan_func(func); | |
609 | } | |
610 | idr_destroy(&sdata->u.nan.function_inst_ids); | |
3a25a8c8 | 611 | |
4b7afb52 FF |
612 | spin_unlock_bh(&sdata->u.nan.func_lock); |
613 | break; | |
614 | case NL80211_IFTYPE_P2P_DEVICE: | |
615 | /* relies on synchronize_rcu() below */ | |
616 | RCU_INIT_POINTER(local->p2p_sdata, NULL); | |
617 | fallthrough; | |
618 | default: | |
16114496 | 619 | wiphy_work_cancel(sdata->local->hw.wiphy, &sdata->work); |
4b7afb52 FF |
620 | /* |
621 | * When we get here, the interface is marked down. | |
622 | * Free the remaining keys, if there are any | |
623 | * (which can happen in AP mode if userspace sets | |
70d9c599 | 624 | * keys before the interface is operating) |
4b7afb52 FF |
625 | * |
626 | * Force the key freeing to always synchronize_net() | |
627 | * to wait for the RX path in case it is using this | |
628 | * interface enqueuing frames at this very time on | |
629 | * another CPU. | |
630 | */ | |
631 | ieee80211_free_keys(sdata, true); | |
632 | skb_queue_purge(&sdata->skb_queue); | |
f5a4c24e | 633 | skb_queue_purge(&sdata->status_queue); |
4b6f1dd6 JB |
634 | } |
635 | ||
9d301de1 DA |
636 | /* |
637 | * Since ieee80211_free_txskb() may issue __dev_queue_xmit() | |
638 | * which should be called with interrupts enabled, reclamation | |
639 | * is done in two phases: | |
640 | */ | |
641 | __skb_queue_head_init(&freeq); | |
642 | ||
643 | /* unlink from local queues... */ | |
4b7afb52 FF |
644 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
645 | for (i = 0; i < IEEE80211_MAX_QUEUES; i++) { | |
646 | skb_queue_walk_safe(&local->pending[i], skb, tmp) { | |
647 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
648 | if (info->control.vif == &sdata->vif) { | |
649 | __skb_unlink(skb, &local->pending[i]); | |
9d301de1 | 650 | __skb_queue_tail(&freeq, skb); |
4b7afb52 FF |
651 | } |
652 | } | |
3a25a8c8 | 653 | } |
4b7afb52 | 654 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
3a25a8c8 | 655 | |
9d301de1 DA |
656 | /* ... and perform actual reclamation with interrupts enabled. */ |
657 | skb_queue_walk_safe(&freeq, skb, tmp) { | |
658 | __skb_unlink(skb, &freeq); | |
659 | ieee80211_free_txskb(&local->hw, skb); | |
660 | } | |
661 | ||
4b7afb52 FF |
662 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
663 | ieee80211_txq_remove_vlan(local, sdata); | |
fab57a6c | 664 | |
378677eb RP |
665 | if (sdata->vif.txq) |
666 | ieee80211_txq_purge(sdata->local, to_txq_info(sdata->vif.txq)); | |
667 | ||
4b7afb52 FF |
668 | sdata->bss = NULL; |
669 | ||
670 | if (local->open_count == 0) | |
671 | ieee80211_clear_tx_pending(local); | |
672 | ||
673 | sdata->vif.bss_conf.beacon_int = 0; | |
674 | ||
675 | /* | |
676 | * If the interface goes down while suspended, presumably because | |
677 | * the device was unplugged and that happens before our resume, | |
678 | * then the driver is already unconfigured and the remainder of | |
679 | * this function isn't needed. | |
680 | * XXX: what about WoWLAN? If the device has software state, e.g. | |
681 | * memory allocated, it might expect teardown commands from | |
682 | * mac80211 here? | |
683 | */ | |
684 | if (local->suspended) { | |
685 | WARN_ON(local->wowlan); | |
6dd23603 | 686 | WARN_ON(rcu_access_pointer(local->monitor_sdata)); |
4b7afb52 | 687 | return; |
55de908a JB |
688 | } |
689 | ||
4b7afb52 FF |
690 | switch (sdata->vif.type) { |
691 | case NL80211_IFTYPE_AP_VLAN: | |
692 | break; | |
693 | case NL80211_IFTYPE_MONITOR: | |
12986004 | 694 | if (local->virt_monitors == 0) |
4b7afb52 | 695 | ieee80211_del_virtual_monitor(local); |
42bd20d9 | 696 | |
4b7afb52 | 697 | ieee80211_recalc_idle(local); |
7d09e17c | 698 | ieee80211_recalc_offload(local); |
4b6f1dd6 | 699 | |
9d40f7e3 FF |
700 | if (!(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) && |
701 | !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) | |
4b7afb52 | 702 | break; |
4b6f1dd6 | 703 | |
9d40f7e3 | 704 | ieee80211_link_release_channel(&sdata->deflink); |
4b7afb52 FF |
705 | fallthrough; |
706 | default: | |
574e609c FF |
707 | if (!going_down) |
708 | break; | |
709 | drv_remove_interface(local, sdata); | |
710 | ||
711 | /* Clear private driver data to prevent reuse */ | |
712 | memset(sdata->vif.drv_priv, 0, local->hw.vif_data_size); | |
4b7afb52 | 713 | } |
4b6f1dd6 | 714 | |
4b7afb52 | 715 | ieee80211_recalc_ps(local); |
8b305780 | 716 | |
4b7afb52 | 717 | if (cancel_scan) |
20171251 | 718 | wiphy_delayed_work_flush(local->hw.wiphy, &local->scan_work); |
4b6f1dd6 | 719 | |
4b7afb52 | 720 | if (local->open_count == 0) { |
1decf05d | 721 | ieee80211_stop_device(local, false); |
4b7afb52 FF |
722 | |
723 | /* no reconfiguring after stop! */ | |
8b305780 JB |
724 | return; |
725 | } | |
4b6f1dd6 | 726 | |
4b7afb52 FF |
727 | /* do after stop to avoid reconfiguring when we stop anyway */ |
728 | ieee80211_configure_filter(local); | |
729 | ieee80211_hw_config(local, hw_reconf_flags); | |
8b305780 | 730 | |
12986004 | 731 | if (local->virt_monitors == local->open_count) |
4b7afb52 FF |
732 | ieee80211_add_virtual_monitor(local); |
733 | } | |
4b6f1dd6 | 734 | |
f6008327 | 735 | void ieee80211_stop_mbssid(struct ieee80211_sub_if_data *sdata) |
17196425 | 736 | { |
f6008327 RS |
737 | struct ieee80211_sub_if_data *tx_sdata; |
738 | struct ieee80211_bss_conf *link_conf, *tx_bss_conf; | |
739 | struct ieee80211_link_data *tx_link, *link; | |
740 | unsigned int link_id; | |
17196425 | 741 | |
f6008327 RS |
742 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
743 | ||
744 | /* Check if any of the links of current sdata is an MBSSID. */ | |
745 | for_each_vif_active_link(&sdata->vif, link_conf, link_id) { | |
746 | tx_bss_conf = sdata_dereference(link_conf->tx_bss_conf, sdata); | |
747 | if (!tx_bss_conf) | |
748 | continue; | |
17196425 | 749 | |
f6008327 RS |
750 | tx_sdata = vif_to_sdata(tx_bss_conf->vif); |
751 | RCU_INIT_POINTER(link_conf->tx_bss_conf, NULL); | |
752 | ||
753 | /* If we are not tx sdata reset tx sdata's tx_bss_conf to avoid recusrion | |
754 | * while closing tx sdata at the end of outer loop below. | |
755 | */ | |
756 | if (sdata != tx_sdata) { | |
757 | tx_link = sdata_dereference(tx_sdata->link[tx_bss_conf->link_id], | |
758 | tx_sdata); | |
759 | if (!tx_link) | |
760 | continue; | |
17196425 | 761 | |
f6008327 RS |
762 | RCU_INIT_POINTER(tx_link->conf->tx_bss_conf, NULL); |
763 | } | |
764 | ||
765 | /* loop through sdatas to find if any of their links | |
766 | * belong to same MBSSID set as the one getting deleted. | |
767 | */ | |
768 | for_each_sdata_link(tx_sdata->local, link) { | |
769 | struct ieee80211_sub_if_data *link_sdata = link->sdata; | |
770 | ||
771 | if (link_sdata == sdata || link_sdata == tx_sdata || | |
772 | rcu_access_pointer(link->conf->tx_bss_conf) != tx_bss_conf) | |
773 | continue; | |
774 | ||
775 | RCU_INIT_POINTER(link->conf->tx_bss_conf, NULL); | |
776 | ||
777 | /* Remove all links of matching MLD until dynamic link | |
778 | * removal can be supported. | |
779 | */ | |
780 | cfg80211_stop_iface(link_sdata->wdev.wiphy, &link_sdata->wdev, | |
781 | GFP_KERNEL); | |
17196425 | 782 | } |
17196425 | 783 | |
f6008327 RS |
784 | /* If we are not tx sdata, remove links of tx sdata and proceed */ |
785 | if (sdata != tx_sdata && ieee80211_sdata_running(tx_sdata)) | |
786 | cfg80211_stop_iface(tx_sdata->wdev.wiphy, | |
787 | &tx_sdata->wdev, GFP_KERNEL); | |
17196425 JC |
788 | } |
789 | } | |
790 | ||
4b7afb52 FF |
791 | static int ieee80211_stop(struct net_device *dev) |
792 | { | |
793 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
55de908a | 794 | |
f6008327 | 795 | /* close dependent VLAN interfaces before locking wiphy */ |
d5befb22 JB |
796 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
797 | struct ieee80211_sub_if_data *vlan, *tmpsdata; | |
798 | ||
799 | list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans, | |
800 | u.vlan.list) | |
801 | dev_close(vlan->dev); | |
802 | } | |
803 | ||
8e66f6c6 JB |
804 | guard(wiphy)(sdata->local->hw.wiphy); |
805 | ||
7206a948 JB |
806 | wiphy_work_cancel(sdata->local->hw.wiphy, &sdata->activate_links_work); |
807 | ||
f6008327 RS |
808 | /* Close the dependent MBSSID interfaces with wiphy lock as we may be |
809 | * terminating its partner links too in case of MLD. | |
810 | */ | |
811 | if (sdata->vif.type == NL80211_IFTYPE_AP) | |
812 | ieee80211_stop_mbssid(sdata); | |
813 | ||
4b7afb52 | 814 | ieee80211_do_stop(sdata, true); |
4b6f1dd6 | 815 | |
4b7afb52 | 816 | return 0; |
4b6f1dd6 JB |
817 | } |
818 | ||
4b7afb52 | 819 | static void ieee80211_set_multicast_list(struct net_device *dev) |
87490f6d | 820 | { |
4b7afb52 | 821 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
87490f6d | 822 | struct ieee80211_local *local = sdata->local; |
4b7afb52 | 823 | int allmulti, sdata_allmulti; |
87490f6d | 824 | |
4b7afb52 FF |
825 | allmulti = !!(dev->flags & IFF_ALLMULTI); |
826 | sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI); | |
665c93a9 | 827 | |
4b7afb52 FF |
828 | if (allmulti != sdata_allmulti) { |
829 | if (dev->flags & IFF_ALLMULTI) | |
830 | atomic_inc(&local->iff_allmultis); | |
831 | else | |
832 | atomic_dec(&local->iff_allmultis); | |
833 | sdata->flags ^= IEEE80211_SDATA_ALLMULTI; | |
834 | } | |
665c93a9 | 835 | |
4b7afb52 FF |
836 | spin_lock_bh(&local->filter_lock); |
837 | __hw_addr_sync(&local->mc_list, &dev->mc, dev->addr_len); | |
838 | spin_unlock_bh(&local->filter_lock); | |
a6add8be | 839 | wiphy_work_queue(local->hw.wiphy, &local->reconfig_filter); |
4b7afb52 | 840 | } |
665c93a9 | 841 | |
4b7afb52 FF |
842 | /* |
843 | * Called when the netdev is removed or, by the code below, before | |
844 | * the interface type changes. | |
845 | */ | |
846 | static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata) | |
847 | { | |
6c93fd50 MK |
848 | if (WARN_ON(!list_empty(&sdata->work.entry))) |
849 | wiphy_work_cancel(sdata->local->hw.wiphy, &sdata->work); | |
850 | ||
4b7afb52 FF |
851 | /* free extra data */ |
852 | ieee80211_free_keys(sdata, false); | |
f9dca80b | 853 | |
4b7afb52 | 854 | ieee80211_debugfs_remove_netdev(sdata); |
0d143fe1 | 855 | |
3a11ce08 | 856 | ieee80211_destroy_frag_cache(&sdata->frags); |
0d143fe1 | 857 | |
4b7afb52 FF |
858 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
859 | ieee80211_mesh_teardown_sdata(sdata); | |
b2e8434f JB |
860 | |
861 | ieee80211_vif_clear_links(sdata); | |
862 | ieee80211_link_stop(&sdata->deflink); | |
4b7afb52 | 863 | } |
0d143fe1 | 864 | |
4b7afb52 FF |
865 | static void ieee80211_uninit(struct net_device *dev) |
866 | { | |
867 | ieee80211_teardown_sdata(IEEE80211_DEV_TO_SUB_IF(dev)); | |
868 | } | |
075e0847 | 869 | |
61587f15 FF |
870 | static int ieee80211_netdev_setup_tc(struct net_device *dev, |
871 | enum tc_setup_type type, void *type_data) | |
872 | { | |
873 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
874 | struct ieee80211_local *local = sdata->local; | |
875 | ||
876 | return drv_net_setup_tc(local, sdata, dev, type, type_data); | |
877 | } | |
878 | ||
4b7afb52 FF |
879 | static const struct net_device_ops ieee80211_dataif_ops = { |
880 | .ndo_open = ieee80211_open, | |
881 | .ndo_stop = ieee80211_stop, | |
882 | .ndo_uninit = ieee80211_uninit, | |
883 | .ndo_start_xmit = ieee80211_subif_start_xmit, | |
884 | .ndo_set_rx_mode = ieee80211_set_multicast_list, | |
885 | .ndo_set_mac_address = ieee80211_change_mac, | |
61587f15 | 886 | .ndo_setup_tc = ieee80211_netdev_setup_tc, |
4b7afb52 | 887 | }; |
e3b90ca2 | 888 | |
4b7afb52 FF |
889 | static u16 ieee80211_monitor_select_queue(struct net_device *dev, |
890 | struct sk_buff *skb, | |
891 | struct net_device *sb_dev) | |
892 | { | |
893 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
894 | struct ieee80211_local *local = sdata->local; | |
895 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
896 | struct ieee80211_hdr *hdr; | |
897 | int len_rthdr; | |
90e8f58d | 898 | |
4b7afb52 FF |
899 | if (local->hw.queues < IEEE80211_NUM_ACS) |
900 | return 0; | |
0d143fe1 | 901 | |
4b7afb52 FF |
902 | /* reset flags and info before parsing radiotap header */ |
903 | memset(info, 0, sizeof(*info)); | |
59034591 | 904 | |
4b7afb52 FF |
905 | if (!ieee80211_parse_tx_radiotap(skb, dev)) |
906 | return 0; /* doesn't matter, frame will be dropped */ | |
0d143fe1 | 907 | |
4b7afb52 FF |
908 | len_rthdr = ieee80211_get_radiotap_len(skb->data); |
909 | hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr); | |
910 | if (skb->len < len_rthdr + 2 || | |
911 | skb->len < len_rthdr + ieee80211_hdrlen(hdr->frame_control)) | |
912 | return 0; /* doesn't matter, frame will be dropped */ | |
2d2080c3 | 913 | |
4b7afb52 FF |
914 | return ieee80211_select_queue_80211(sdata, skb, hdr); |
915 | } | |
0d143fe1 | 916 | |
4b7afb52 FF |
917 | static const struct net_device_ops ieee80211_monitorif_ops = { |
918 | .ndo_open = ieee80211_open, | |
919 | .ndo_stop = ieee80211_stop, | |
920 | .ndo_uninit = ieee80211_uninit, | |
921 | .ndo_start_xmit = ieee80211_monitor_start_xmit, | |
922 | .ndo_set_rx_mode = ieee80211_set_multicast_list, | |
923 | .ndo_set_mac_address = ieee80211_change_mac, | |
924 | .ndo_select_queue = ieee80211_monitor_select_queue, | |
4b7afb52 | 925 | }; |
0d143fe1 | 926 | |
d787a3e3 FF |
927 | static int ieee80211_netdev_fill_forward_path(struct net_device_path_ctx *ctx, |
928 | struct net_device_path *path) | |
929 | { | |
930 | struct ieee80211_sub_if_data *sdata; | |
931 | struct ieee80211_local *local; | |
932 | struct sta_info *sta; | |
933 | int ret = -ENOENT; | |
934 | ||
935 | sdata = IEEE80211_DEV_TO_SUB_IF(ctx->dev); | |
936 | local = sdata->local; | |
937 | ||
938 | if (!local->ops->net_fill_forward_path) | |
939 | return -EOPNOTSUPP; | |
940 | ||
941 | rcu_read_lock(); | |
942 | switch (sdata->vif.type) { | |
943 | case NL80211_IFTYPE_AP_VLAN: | |
944 | sta = rcu_dereference(sdata->u.vlan.sta); | |
945 | if (sta) | |
946 | break; | |
947 | if (sdata->wdev.use_4addr) | |
948 | goto out; | |
949 | if (is_multicast_ether_addr(ctx->daddr)) | |
950 | goto out; | |
951 | sta = sta_info_get_bss(sdata, ctx->daddr); | |
952 | break; | |
953 | case NL80211_IFTYPE_AP: | |
954 | if (is_multicast_ether_addr(ctx->daddr)) | |
955 | goto out; | |
956 | sta = sta_info_get(sdata, ctx->daddr); | |
957 | break; | |
958 | case NL80211_IFTYPE_STATION: | |
959 | if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) { | |
960 | sta = sta_info_get(sdata, ctx->daddr); | |
961 | if (sta && test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { | |
962 | if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH)) | |
963 | goto out; | |
964 | ||
965 | break; | |
966 | } | |
967 | } | |
968 | ||
bfd8403a | 969 | sta = sta_info_get(sdata, sdata->deflink.u.mgd.bssid); |
d787a3e3 FF |
970 | break; |
971 | default: | |
972 | goto out; | |
973 | } | |
974 | ||
975 | if (!sta) | |
976 | goto out; | |
977 | ||
978 | ret = drv_net_fill_forward_path(local, sdata, &sta->sta, ctx, path); | |
979 | out: | |
980 | rcu_read_unlock(); | |
981 | ||
982 | return ret; | |
983 | } | |
984 | ||
4b7afb52 FF |
985 | static const struct net_device_ops ieee80211_dataif_8023_ops = { |
986 | .ndo_open = ieee80211_open, | |
987 | .ndo_stop = ieee80211_stop, | |
988 | .ndo_uninit = ieee80211_uninit, | |
989 | .ndo_start_xmit = ieee80211_subif_start_xmit_8023, | |
990 | .ndo_set_rx_mode = ieee80211_set_multicast_list, | |
991 | .ndo_set_mac_address = ieee80211_change_mac, | |
d787a3e3 | 992 | .ndo_fill_forward_path = ieee80211_netdev_fill_forward_path, |
61587f15 | 993 | .ndo_setup_tc = ieee80211_netdev_setup_tc, |
4b7afb52 | 994 | }; |
1be7fe8d | 995 | |
80a915ec | 996 | static bool ieee80211_iftype_supports_hdr_offload(enum nl80211_iftype iftype) |
4b7afb52 FF |
997 | { |
998 | switch (iftype) { | |
999 | /* P2P GO and client are mapped to AP/STATION types */ | |
1000 | case NL80211_IFTYPE_AP: | |
1001 | case NL80211_IFTYPE_STATION: | |
1002 | return true; | |
f64331d5 | 1003 | default: |
4b7afb52 | 1004 | return false; |
0d143fe1 | 1005 | } |
4b7afb52 | 1006 | } |
0d143fe1 | 1007 | |
4b7afb52 FF |
1008 | static bool ieee80211_set_sdata_offload_flags(struct ieee80211_sub_if_data *sdata) |
1009 | { | |
1010 | struct ieee80211_local *local = sdata->local; | |
1011 | u32 flags; | |
965bedad | 1012 | |
4b7afb52 | 1013 | flags = sdata->vif.offload_flags; |
2b730daa | 1014 | |
4b7afb52 | 1015 | if (ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD) && |
80a915ec | 1016 | ieee80211_iftype_supports_hdr_offload(sdata->vif.type)) { |
4b7afb52 | 1017 | flags |= IEEE80211_OFFLOAD_ENCAP_ENABLED; |
2b730daa | 1018 | |
4b7afb52 FF |
1019 | if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_FRAG) && |
1020 | local->hw.wiphy->frag_threshold != (u32)-1) | |
1021 | flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED; | |
2b730daa | 1022 | |
12986004 | 1023 | if (local->virt_monitors) |
4b7afb52 FF |
1024 | flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED; |
1025 | } else { | |
1026 | flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED; | |
2b730daa | 1027 | } |
0d143fe1 | 1028 | |
80a915ec FF |
1029 | if (ieee80211_hw_check(&local->hw, SUPPORTS_RX_DECAP_OFFLOAD) && |
1030 | ieee80211_iftype_supports_hdr_offload(sdata->vif.type)) { | |
1031 | flags |= IEEE80211_OFFLOAD_DECAP_ENABLED; | |
1032 | ||
12986004 | 1033 | if (local->virt_monitors && |
55f8205e | 1034 | !ieee80211_hw_check(&local->hw, SUPPORTS_CONC_MON_RX_DECAP)) |
80a915ec FF |
1035 | flags &= ~IEEE80211_OFFLOAD_DECAP_ENABLED; |
1036 | } else { | |
1037 | flags &= ~IEEE80211_OFFLOAD_DECAP_ENABLED; | |
1038 | } | |
1039 | ||
4b7afb52 FF |
1040 | if (sdata->vif.offload_flags == flags) |
1041 | return false; | |
1042 | ||
1043 | sdata->vif.offload_flags = flags; | |
80a915ec | 1044 | ieee80211_check_fast_rx_iface(sdata); |
4b7afb52 | 1045 | return true; |
0d143fe1 JB |
1046 | } |
1047 | ||
4b7afb52 | 1048 | static void ieee80211_set_vif_encap_ops(struct ieee80211_sub_if_data *sdata) |
0d143fe1 | 1049 | { |
4b7afb52 FF |
1050 | struct ieee80211_local *local = sdata->local; |
1051 | struct ieee80211_sub_if_data *bss = sdata; | |
1052 | bool enabled; | |
34d4bc4d | 1053 | |
4b7afb52 FF |
1054 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { |
1055 | if (!sdata->bss) | |
1056 | return; | |
34d4bc4d | 1057 | |
4b7afb52 FF |
1058 | bss = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap); |
1059 | } | |
34d4bc4d | 1060 | |
4b7afb52 | 1061 | if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD) || |
80a915ec | 1062 | !ieee80211_iftype_supports_hdr_offload(bss->vif.type)) |
4b7afb52 | 1063 | return; |
34d4bc4d | 1064 | |
4b7afb52 FF |
1065 | enabled = bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED; |
1066 | if (sdata->wdev.use_4addr && | |
1067 | !(bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_4ADDR)) | |
1068 | enabled = false; | |
0d143fe1 | 1069 | |
4b7afb52 FF |
1070 | sdata->dev->netdev_ops = enabled ? &ieee80211_dataif_8023_ops : |
1071 | &ieee80211_dataif_ops; | |
1072 | } | |
c29acf20 | 1073 | |
4b7afb52 FF |
1074 | static void ieee80211_recalc_sdata_offload(struct ieee80211_sub_if_data *sdata) |
1075 | { | |
1076 | struct ieee80211_local *local = sdata->local; | |
1077 | struct ieee80211_sub_if_data *vsdata; | |
352ffad6 | 1078 | |
4b7afb52 FF |
1079 | if (ieee80211_set_sdata_offload_flags(sdata)) { |
1080 | drv_update_vif_offload(local, sdata); | |
1081 | ieee80211_set_vif_encap_ops(sdata); | |
1082 | } | |
0d143fe1 | 1083 | |
4b7afb52 FF |
1084 | list_for_each_entry(vsdata, &local->interfaces, list) { |
1085 | if (vsdata->vif.type != NL80211_IFTYPE_AP_VLAN || | |
1086 | vsdata->bss != &sdata->u.ap) | |
1087 | continue; | |
af6b6374 | 1088 | |
4b7afb52 | 1089 | ieee80211_set_vif_encap_ops(vsdata); |
8ffcc704 | 1090 | } |
4b7afb52 | 1091 | } |
cd7760e6 | 1092 | |
4b7afb52 FF |
1093 | void ieee80211_recalc_offload(struct ieee80211_local *local) |
1094 | { | |
1095 | struct ieee80211_sub_if_data *sdata; | |
0d143fe1 | 1096 | |
4b7afb52 FF |
1097 | if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD)) |
1098 | return; | |
0d143fe1 | 1099 | |
be0df01d | 1100 | lockdep_assert_wiphy(local->hw.wiphy); |
e3b90ca2 | 1101 | |
4b7afb52 FF |
1102 | list_for_each_entry(sdata, &local->interfaces, list) { |
1103 | if (!ieee80211_sdata_running(sdata)) | |
1104 | continue; | |
1105 | ||
1106 | ieee80211_recalc_sdata_offload(sdata); | |
f142c6b9 | 1107 | } |
4b7afb52 | 1108 | } |
0d143fe1 | 1109 | |
4b7afb52 FF |
1110 | void ieee80211_adjust_monitor_flags(struct ieee80211_sub_if_data *sdata, |
1111 | const int offset) | |
1112 | { | |
1113 | struct ieee80211_local *local = sdata->local; | |
1114 | u32 flags = sdata->u.mntr.flags; | |
59af6928 | 1115 | |
4b7afb52 FF |
1116 | #define ADJUST(_f, _s) do { \ |
1117 | if (flags & MONITOR_FLAG_##_f) \ | |
1118 | local->fif_##_s += offset; \ | |
1119 | } while (0) | |
04ecd257 | 1120 | |
4b7afb52 FF |
1121 | ADJUST(FCSFAIL, fcsfail); |
1122 | ADJUST(PLCPFAIL, plcpfail); | |
1123 | ADJUST(CONTROL, control); | |
1124 | ADJUST(CONTROL, pspoll); | |
1125 | ADJUST(OTHER_BSS, other_bss); | |
754905ce FF |
1126 | if (!(flags & MONITOR_FLAG_SKIP_TX)) |
1127 | local->tx_mntrs += offset; | |
164eb02d | 1128 | |
4b7afb52 FF |
1129 | #undef ADJUST |
1130 | } | |
1131 | ||
1132 | static void ieee80211_set_default_queues(struct ieee80211_sub_if_data *sdata) | |
1133 | { | |
1134 | struct ieee80211_local *local = sdata->local; | |
1135 | int i; | |
1136 | ||
1137 | for (i = 0; i < IEEE80211_NUM_ACS; i++) { | |
1138 | if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) | |
1139 | sdata->vif.hw_queue[i] = IEEE80211_INVAL_HW_QUEUE; | |
1140 | else if (local->hw.queues >= IEEE80211_NUM_ACS) | |
1141 | sdata->vif.hw_queue[i] = i; | |
1142 | else | |
1143 | sdata->vif.hw_queue[i] = 0; | |
164eb02d | 1144 | } |
4b7afb52 FF |
1145 | sdata->vif.cab_queue = IEEE80211_INVAL_HW_QUEUE; |
1146 | } | |
164eb02d | 1147 | |
8e14130d JB |
1148 | static void ieee80211_sdata_init(struct ieee80211_local *local, |
1149 | struct ieee80211_sub_if_data *sdata) | |
1150 | { | |
1151 | sdata->local = local; | |
1152 | ||
d7a54d02 MK |
1153 | INIT_LIST_HEAD(&sdata->key_list); |
1154 | ||
8e14130d JB |
1155 | /* |
1156 | * Initialize the default link, so we can use link_id 0 for non-MLD, | |
1157 | * and that continues to work for non-MLD-aware drivers that use just | |
1158 | * vif.bss_conf instead of vif.link_conf. | |
1159 | * | |
1160 | * Note that we never change this, so if link ID 0 isn't used in an | |
1161 | * MLD connection, we get a separate allocation for it. | |
1162 | */ | |
d8787ec6 | 1163 | ieee80211_link_init(sdata, -1, &sdata->deflink, &sdata->vif.bss_conf); |
8e14130d JB |
1164 | } |
1165 | ||
4b7afb52 FF |
1166 | int ieee80211_add_virtual_monitor(struct ieee80211_local *local) |
1167 | { | |
1168 | struct ieee80211_sub_if_data *sdata; | |
1169 | int ret; | |
0d143fe1 | 1170 | |
4b7afb52 | 1171 | ASSERT_RTNL(); |
6dd23603 | 1172 | lockdep_assert_wiphy(local->hw.wiphy); |
0d143fe1 | 1173 | |
9d40f7e3 FF |
1174 | if (local->monitor_sdata || |
1175 | ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) | |
4b7afb52 | 1176 | return 0; |
0d143fe1 | 1177 | |
4b7afb52 FF |
1178 | sdata = kzalloc(sizeof(*sdata) + local->hw.vif_data_size, GFP_KERNEL); |
1179 | if (!sdata) | |
1180 | return -ENOMEM; | |
0d143fe1 | 1181 | |
4b7afb52 | 1182 | /* set up data */ |
4b7afb52 FF |
1183 | sdata->vif.type = NL80211_IFTYPE_MONITOR; |
1184 | snprintf(sdata->name, IFNAMSIZ, "%s-monitor", | |
1185 | wiphy_name(local->hw.wiphy)); | |
1186 | sdata->wdev.iftype = NL80211_IFTYPE_MONITOR; | |
a7614b48 | 1187 | sdata->wdev.wiphy = local->hw.wiphy; |
0d143fe1 | 1188 | |
8e14130d JB |
1189 | ieee80211_sdata_init(local, sdata); |
1190 | ||
4b7afb52 | 1191 | ieee80211_set_default_queues(sdata); |
167e33f4 | 1192 | |
0d9c2bee JB |
1193 | if (ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF)) { |
1194 | ret = drv_add_interface(local, sdata); | |
1195 | if (WARN_ON(ret)) { | |
1196 | /* ok .. stupid driver, it asked for this! */ | |
1197 | kfree(sdata); | |
1198 | return ret; | |
1199 | } | |
4b7afb52 FF |
1200 | } |
1201 | ||
bdeca45a BA |
1202 | set_bit(SDATA_STATE_RUNNING, &sdata->state); |
1203 | ||
4b7afb52 FF |
1204 | ret = ieee80211_check_queues(sdata, NL80211_IFTYPE_MONITOR); |
1205 | if (ret) { | |
1206 | kfree(sdata); | |
1207 | return ret; | |
0d143fe1 JB |
1208 | } |
1209 | ||
4b7afb52 FF |
1210 | mutex_lock(&local->iflist_mtx); |
1211 | rcu_assign_pointer(local->monitor_sdata, sdata); | |
1212 | mutex_unlock(&local->iflist_mtx); | |
1213 | ||
6092077a | 1214 | ret = ieee80211_link_use_channel(&sdata->deflink, &local->monitor_chanreq, |
b4f85443 | 1215 | IEEE80211_CHANCTX_EXCLUSIVE); |
4b7afb52 FF |
1216 | if (ret) { |
1217 | mutex_lock(&local->iflist_mtx); | |
1218 | RCU_INIT_POINTER(local->monitor_sdata, NULL); | |
1219 | mutex_unlock(&local->iflist_mtx); | |
1220 | synchronize_net(); | |
1221 | drv_remove_interface(local, sdata); | |
1222 | kfree(sdata); | |
1223 | return ret; | |
5061b0c2 | 1224 | } |
075e0847 | 1225 | |
4b7afb52 | 1226 | skb_queue_head_init(&sdata->skb_queue); |
f5a4c24e | 1227 | skb_queue_head_init(&sdata->status_queue); |
16114496 | 1228 | wiphy_work_init(&sdata->work, ieee80211_iface_work); |
53168215 | 1229 | |
4b7afb52 FF |
1230 | return 0; |
1231 | } | |
ba8c3d6f | 1232 | |
4b7afb52 FF |
1233 | void ieee80211_del_virtual_monitor(struct ieee80211_local *local) |
1234 | { | |
1235 | struct ieee80211_sub_if_data *sdata; | |
b2c0958b | 1236 | |
9d40f7e3 FF |
1237 | if (ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) |
1238 | return; | |
1239 | ||
4b7afb52 | 1240 | ASSERT_RTNL(); |
6dd23603 | 1241 | lockdep_assert_wiphy(local->hw.wiphy); |
4b7afb52 FF |
1242 | |
1243 | mutex_lock(&local->iflist_mtx); | |
1244 | ||
1245 | sdata = rcu_dereference_protected(local->monitor_sdata, | |
1246 | lockdep_is_held(&local->iflist_mtx)); | |
1247 | if (!sdata) { | |
1248 | mutex_unlock(&local->iflist_mtx); | |
b2c0958b JB |
1249 | return; |
1250 | } | |
1251 | ||
646262c7 | 1252 | clear_bit(SDATA_STATE_RUNNING, &sdata->state); |
d8675a63 | 1253 | ieee80211_link_release_channel(&sdata->deflink); |
4b7afb52 | 1254 | |
0d9c2bee JB |
1255 | if (ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF)) |
1256 | drv_remove_interface(local, sdata); | |
4b7afb52 | 1257 | |
646262c7 AW |
1258 | RCU_INIT_POINTER(local->monitor_sdata, NULL); |
1259 | mutex_unlock(&local->iflist_mtx); | |
1260 | ||
1261 | synchronize_net(); | |
1262 | ||
4b7afb52 FF |
1263 | kfree(sdata); |
1264 | } | |
1265 | ||
1266 | /* | |
1267 | * NOTE: Be very careful when changing this function, it must NOT return | |
1268 | * an error on interface type changes that have been pre-checked, so most | |
1269 | * checks should be in ieee80211_check_concurrent_iface. | |
1270 | */ | |
1271 | int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up) | |
1272 | { | |
1273 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
1274 | struct net_device *dev = wdev->netdev; | |
1275 | struct ieee80211_local *local = sdata->local; | |
15ddba5f | 1276 | u64 changed = 0; |
4b7afb52 FF |
1277 | int res; |
1278 | u32 hw_reconf_flags = 0; | |
1279 | ||
2a8b665e JB |
1280 | lockdep_assert_wiphy(local->hw.wiphy); |
1281 | ||
b2c0958b | 1282 | switch (sdata->vif.type) { |
4b7afb52 FF |
1283 | case NL80211_IFTYPE_AP_VLAN: { |
1284 | struct ieee80211_sub_if_data *master; | |
1285 | ||
1286 | if (!sdata->bss) | |
1287 | return -ENOLINK; | |
b2c0958b | 1288 | |
4b7afb52 | 1289 | list_add(&sdata->u.vlan.list, &sdata->bss->vlans); |
31eba5bc | 1290 | |
4b7afb52 FF |
1291 | master = container_of(sdata->bss, |
1292 | struct ieee80211_sub_if_data, u.ap); | |
1293 | sdata->control_port_protocol = | |
1294 | master->control_port_protocol; | |
1295 | sdata->control_port_no_encrypt = | |
1296 | master->control_port_no_encrypt; | |
1297 | sdata->control_port_over_nl80211 = | |
1298 | master->control_port_over_nl80211; | |
1299 | sdata->control_port_no_preauth = | |
1300 | master->control_port_no_preauth; | |
1301 | sdata->vif.cab_queue = master->vif.cab_queue; | |
1302 | memcpy(sdata->vif.hw_queue, master->vif.hw_queue, | |
1303 | sizeof(sdata->vif.hw_queue)); | |
6092077a | 1304 | sdata->vif.bss_conf.chanreq = master->vif.bss_conf.chanreq; |
b2c0958b | 1305 | |
4b7afb52 FF |
1306 | sdata->crypto_tx_tailroom_needed_cnt += |
1307 | master->crypto_tx_tailroom_needed_cnt; | |
b2c0958b | 1308 | |
90233b0a MS |
1309 | ieee80211_apvlan_link_setup(sdata); |
1310 | ||
4b7afb52 FF |
1311 | break; |
1312 | } | |
1313 | case NL80211_IFTYPE_AP: | |
1314 | sdata->bss = &sdata->u.ap; | |
1315 | break; | |
1316 | case NL80211_IFTYPE_MESH_POINT: | |
1317 | case NL80211_IFTYPE_STATION: | |
1318 | case NL80211_IFTYPE_MONITOR: | |
1319 | case NL80211_IFTYPE_ADHOC: | |
1320 | case NL80211_IFTYPE_P2P_DEVICE: | |
1321 | case NL80211_IFTYPE_OCB: | |
1322 | case NL80211_IFTYPE_NAN: | |
1323 | /* no special treatment */ | |
1324 | break; | |
1325 | case NL80211_IFTYPE_UNSPECIFIED: | |
1326 | case NUM_NL80211_IFTYPES: | |
1327 | case NL80211_IFTYPE_P2P_CLIENT: | |
1328 | case NL80211_IFTYPE_P2P_GO: | |
70d9c599 | 1329 | case NL80211_IFTYPE_WDS: |
4b7afb52 FF |
1330 | /* cannot happen */ |
1331 | WARN_ON(1); | |
1332 | break; | |
1333 | } | |
46238845 | 1334 | |
b2c0958b | 1335 | if (local->open_count == 0) { |
c4fdb081 JB |
1336 | /* here we can consider everything in good order (again) */ |
1337 | local->reconfig_failure = false; | |
1338 | ||
4b7afb52 FF |
1339 | res = drv_start(local); |
1340 | if (res) | |
1341 | goto err_del_bss; | |
4b7afb52 FF |
1342 | ieee80211_led_radio(local, true); |
1343 | ieee80211_mod_tpt_led_trig(local, | |
1344 | IEEE80211_TPT_LEDTRIG_FL_RADIO, 0); | |
b2c0958b JB |
1345 | } |
1346 | ||
4b7afb52 FF |
1347 | /* |
1348 | * Copy the hopefully now-present MAC address to | |
1349 | * this interface, if it has the special null one. | |
1350 | */ | |
1351 | if (dev && is_zero_ether_addr(dev->dev_addr)) { | |
de1352ea | 1352 | eth_hw_addr_set(dev, local->hw.wiphy->perm_addr); |
4b7afb52 | 1353 | memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN); |
34d4bc4d | 1354 | |
4b7afb52 FF |
1355 | if (!is_valid_ether_addr(dev->dev_addr)) { |
1356 | res = -EADDRNOTAVAIL; | |
1357 | goto err_stop; | |
1358 | } | |
1359 | } | |
34d4bc4d | 1360 | |
52cebabb FF |
1361 | sdata->vif.addr_valid = sdata->vif.type != NL80211_IFTYPE_MONITOR || |
1362 | (sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE); | |
4b7afb52 FF |
1363 | switch (sdata->vif.type) { |
1364 | case NL80211_IFTYPE_AP_VLAN: | |
1365 | /* no need to tell driver, but set carrier and chanctx */ | |
bfd8403a | 1366 | if (sdata->bss->active) { |
90233b0a MS |
1367 | struct ieee80211_link_data *link; |
1368 | ||
1369 | for_each_link_data(sdata, link) { | |
1370 | ieee80211_link_vlan_copy_chanctx(link); | |
1371 | } | |
1372 | ||
4b7afb52 FF |
1373 | netif_carrier_on(dev); |
1374 | ieee80211_set_vif_encap_ops(sdata); | |
1375 | } else { | |
1376 | netif_carrier_off(dev); | |
1377 | } | |
1378 | break; | |
1379 | case NL80211_IFTYPE_MONITOR: | |
9d40f7e3 FF |
1380 | if ((sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) || |
1381 | ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) { | |
4b7afb52 FF |
1382 | res = drv_add_interface(local, sdata); |
1383 | if (res) | |
1384 | goto err_stop; | |
286e6967 | 1385 | } else { |
12986004 | 1386 | if (local->virt_monitors == 0 && local->open_count == 0) { |
286e6967 AW |
1387 | res = ieee80211_add_virtual_monitor(local); |
1388 | if (res) | |
1389 | goto err_stop; | |
1390 | } | |
12986004 | 1391 | local->virt_monitors++; |
0d143fe1 | 1392 | |
286e6967 | 1393 | /* must be before the call to ieee80211_configure_filter */ |
12986004 | 1394 | if (local->virt_monitors == 1) { |
286e6967 AW |
1395 | local->hw.conf.flags |= IEEE80211_CONF_MONITOR; |
1396 | hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR; | |
1397 | } | |
4b7afb52 | 1398 | } |
0d143fe1 | 1399 | |
12986004 AW |
1400 | local->monitors++; |
1401 | ||
4b7afb52 FF |
1402 | ieee80211_adjust_monitor_flags(sdata, 1); |
1403 | ieee80211_configure_filter(local); | |
1404 | ieee80211_recalc_offload(local); | |
4b7afb52 | 1405 | ieee80211_recalc_idle(local); |
0d143fe1 | 1406 | |
4b7afb52 FF |
1407 | netif_carrier_on(dev); |
1408 | break; | |
1409 | default: | |
1410 | if (coming_up) { | |
1411 | ieee80211_del_virtual_monitor(local); | |
1412 | ieee80211_set_sdata_offload_flags(sdata); | |
0d143fe1 | 1413 | |
4b7afb52 FF |
1414 | res = drv_add_interface(local, sdata); |
1415 | if (res) | |
1416 | goto err_stop; | |
0d143fe1 | 1417 | |
4b7afb52 FF |
1418 | ieee80211_set_vif_encap_ops(sdata); |
1419 | res = ieee80211_check_queues(sdata, | |
1420 | ieee80211_vif_type_p2p(&sdata->vif)); | |
1421 | if (res) | |
1422 | goto err_del_interface; | |
1423 | } | |
f0706e82 | 1424 | |
4b7afb52 FF |
1425 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
1426 | local->fif_pspoll++; | |
1427 | local->fif_probe_req++; | |
75636525 | 1428 | |
4b7afb52 FF |
1429 | ieee80211_configure_filter(local); |
1430 | } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { | |
1431 | local->fif_probe_req++; | |
1432 | } | |
aee14ceb | 1433 | |
4b7afb52 FF |
1434 | if (sdata->vif.probe_req_reg) |
1435 | drv_config_iface_filter(local, sdata, | |
1436 | FIF_PROBE_REQ, | |
1437 | FIF_PROBE_REQ); | |
11a843b7 | 1438 | |
4b7afb52 FF |
1439 | if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE && |
1440 | sdata->vif.type != NL80211_IFTYPE_NAN) | |
1441 | changed |= ieee80211_reset_erp_info(sdata); | |
d8675a63 JB |
1442 | ieee80211_link_info_change_notify(sdata, &sdata->deflink, |
1443 | changed); | |
f0706e82 | 1444 | |
4b7afb52 FF |
1445 | switch (sdata->vif.type) { |
1446 | case NL80211_IFTYPE_STATION: | |
1447 | case NL80211_IFTYPE_ADHOC: | |
1448 | case NL80211_IFTYPE_AP: | |
1449 | case NL80211_IFTYPE_MESH_POINT: | |
1450 | case NL80211_IFTYPE_OCB: | |
1451 | netif_carrier_off(dev); | |
1452 | break; | |
4b7afb52 FF |
1453 | case NL80211_IFTYPE_P2P_DEVICE: |
1454 | case NL80211_IFTYPE_NAN: | |
1455 | break; | |
1456 | default: | |
1457 | /* not reached */ | |
1458 | WARN_ON(1); | |
1459 | } | |
f142c6b9 | 1460 | |
4b7afb52 FF |
1461 | /* |
1462 | * Set default queue parameters so drivers don't | |
1463 | * need to initialise the hardware if the hardware | |
1464 | * doesn't start up with sane defaults. | |
1465 | * Enable QoS for anything but station interfaces. | |
1466 | */ | |
b3e2130b | 1467 | ieee80211_set_wmm_default(&sdata->deflink, true, |
4b7afb52 FF |
1468 | sdata->vif.type != NL80211_IFTYPE_STATION); |
1469 | } | |
cf0277e7 | 1470 | |
4b7afb52 | 1471 | switch (sdata->vif.type) { |
4b7afb52 FF |
1472 | case NL80211_IFTYPE_P2P_DEVICE: |
1473 | rcu_assign_pointer(local->p2p_sdata, sdata); | |
1474 | break; | |
1475 | case NL80211_IFTYPE_MONITOR: | |
4b7afb52 FF |
1476 | list_add_tail_rcu(&sdata->u.mntr.list, &local->mon_list); |
1477 | break; | |
1478 | default: | |
1479 | break; | |
5a490510 | 1480 | } |
5a490510 | 1481 | |
4b7afb52 FF |
1482 | /* |
1483 | * set_multicast_list will be invoked by the networking core | |
1484 | * which will check whether any increments here were done in | |
1485 | * error and sync them down to the hardware as filter flags. | |
1486 | */ | |
1487 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) | |
1488 | atomic_inc(&local->iff_allmultis); | |
587e729e | 1489 | |
4b7afb52 FF |
1490 | if (coming_up) |
1491 | local->open_count++; | |
cf0277e7 | 1492 | |
0a44dfc0 JB |
1493 | if (local->open_count == 1) |
1494 | ieee80211_hw_conf_init(local); | |
1495 | else if (hw_reconf_flags) | |
4b7afb52 | 1496 | ieee80211_hw_config(local, hw_reconf_flags); |
cf0277e7 | 1497 | |
4b7afb52 | 1498 | ieee80211_recalc_ps(local); |
cb17ed29 | 1499 | |
c95014e1 AW |
1500 | set_bit(SDATA_STATE_RUNNING, &sdata->state); |
1501 | ||
4b7afb52 FF |
1502 | return 0; |
1503 | err_del_interface: | |
1504 | drv_remove_interface(local, sdata); | |
1505 | err_stop: | |
1506 | if (!local->open_count) | |
1decf05d | 1507 | drv_stop(local, false); |
4b7afb52 FF |
1508 | err_del_bss: |
1509 | sdata->bss = NULL; | |
0cd8080e | 1510 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
4b7afb52 | 1511 | list_del(&sdata->u.vlan.list); |
4b7afb52 FF |
1512 | /* might already be clear but that doesn't matter */ |
1513 | clear_bit(SDATA_STATE_RUNNING, &sdata->state); | |
1514 | return res; | |
1515 | } | |
50ff477a | 1516 | |
587e729e JB |
1517 | static void ieee80211_if_setup(struct net_device *dev) |
1518 | { | |
1519 | ether_setup(dev); | |
550fd08c | 1520 | dev->priv_flags &= ~IFF_TX_SKB_SHARING; |
107395f9 | 1521 | dev->priv_flags |= IFF_NO_QUEUE; |
587e729e | 1522 | dev->netdev_ops = &ieee80211_dataif_ops; |
cf124db5 | 1523 | dev->needs_free_netdev = true; |
587e729e JB |
1524 | } |
1525 | ||
07bd1c79 JB |
1526 | static void ieee80211_iface_process_skb(struct ieee80211_local *local, |
1527 | struct ieee80211_sub_if_data *sdata, | |
1528 | struct sk_buff *skb) | |
1529 | { | |
1530 | struct ieee80211_mgmt *mgmt = (void *)skb->data; | |
1531 | ||
4d3acf43 JB |
1532 | lockdep_assert_wiphy(local->hw.wiphy); |
1533 | ||
07bd1c79 JB |
1534 | if (ieee80211_is_action(mgmt->frame_control) && |
1535 | mgmt->u.action.category == WLAN_CATEGORY_BACK) { | |
1536 | struct sta_info *sta; | |
1537 | int len = skb->len; | |
1538 | ||
07bd1c79 JB |
1539 | sta = sta_info_get_bss(sdata, mgmt->sa); |
1540 | if (sta) { | |
1541 | switch (mgmt->u.action.u.addba_req.action_code) { | |
1542 | case WLAN_ACTION_ADDBA_REQ: | |
1543 | ieee80211_process_addba_request(local, sta, | |
1544 | mgmt, len); | |
1545 | break; | |
1546 | case WLAN_ACTION_ADDBA_RESP: | |
1547 | ieee80211_process_addba_resp(local, sta, | |
1548 | mgmt, len); | |
1549 | break; | |
1550 | case WLAN_ACTION_DELBA: | |
1551 | ieee80211_process_delba(sdata, sta, | |
1552 | mgmt, len); | |
1553 | break; | |
1554 | default: | |
1555 | WARN_ON(1); | |
1556 | break; | |
1557 | } | |
1558 | } | |
07bd1c79 JB |
1559 | } else if (ieee80211_is_action(mgmt->frame_control) && |
1560 | mgmt->u.action.category == WLAN_CATEGORY_VHT) { | |
1561 | switch (mgmt->u.action.u.vht_group_notif.action_code) { | |
1562 | case WLAN_VHT_ACTION_OPMODE_NOTIF: { | |
1563 | struct ieee80211_rx_status *status; | |
1564 | enum nl80211_band band; | |
1565 | struct sta_info *sta; | |
1566 | u8 opmode; | |
1567 | ||
1568 | status = IEEE80211_SKB_RXCB(skb); | |
1569 | band = status->band; | |
1570 | opmode = mgmt->u.action.u.vht_opmode_notif.operating_mode; | |
1571 | ||
07bd1c79 JB |
1572 | sta = sta_info_get_bss(sdata, mgmt->sa); |
1573 | ||
1574 | if (sta) | |
c71420db JB |
1575 | ieee80211_vht_handle_opmode(sdata, |
1576 | &sta->deflink, | |
afe0d181 | 1577 | opmode, band); |
07bd1c79 | 1578 | |
07bd1c79 JB |
1579 | break; |
1580 | } | |
1581 | case WLAN_VHT_ACTION_GROUPID_MGMT: | |
d8675a63 JB |
1582 | ieee80211_process_mu_groups(sdata, &sdata->deflink, |
1583 | mgmt); | |
07bd1c79 JB |
1584 | break; |
1585 | default: | |
1586 | WARN_ON(1); | |
1587 | break; | |
1588 | } | |
f5a4c24e LB |
1589 | } else if (ieee80211_is_action(mgmt->frame_control) && |
1590 | mgmt->u.action.category == WLAN_CATEGORY_S1G) { | |
1591 | switch (mgmt->u.action.u.s1g.action_code) { | |
1592 | case WLAN_S1G_TWT_TEARDOWN: | |
1593 | case WLAN_S1G_TWT_SETUP: | |
1594 | ieee80211_s1g_rx_twt_action(sdata, skb); | |
1595 | break; | |
1596 | default: | |
1597 | break; | |
1598 | } | |
8f500fbc AB |
1599 | } else if (ieee80211_is_action(mgmt->frame_control) && |
1600 | mgmt->u.action.category == WLAN_CATEGORY_PROTECTED_EHT) { | |
1601 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { | |
1602 | switch (mgmt->u.action.u.ttlm_req.action_code) { | |
1603 | case WLAN_PROTECTED_EHT_ACTION_TTLM_REQ: | |
1604 | ieee80211_process_neg_ttlm_req(sdata, mgmt, | |
1605 | skb->len); | |
1606 | break; | |
f7660b3f AB |
1607 | case WLAN_PROTECTED_EHT_ACTION_TTLM_RES: |
1608 | ieee80211_process_neg_ttlm_res(sdata, mgmt, | |
1609 | skb->len); | |
1610 | break; | |
8b8a6731 IP |
1611 | case WLAN_PROTECTED_EHT_ACTION_TTLM_TEARDOWN: |
1612 | ieee80211_process_ttlm_teardown(sdata); | |
1613 | break; | |
36e05b0b IP |
1614 | case WLAN_PROTECTED_EHT_ACTION_LINK_RECONFIG_RESP: |
1615 | ieee80211_process_ml_reconf_resp(sdata, mgmt, | |
1616 | skb->len); | |
1617 | break; | |
de86c5f6 IP |
1618 | case WLAN_PROTECTED_EHT_ACTION_EPCS_ENABLE_RESP: |
1619 | ieee80211_process_epcs_ena_resp(sdata, mgmt, | |
1620 | skb->len); | |
1621 | break; | |
1622 | case WLAN_PROTECTED_EHT_ACTION_EPCS_ENABLE_TEARDOWN: | |
1623 | ieee80211_process_epcs_teardown(sdata, mgmt, | |
1624 | skb->len); | |
1625 | break; | |
8f500fbc AB |
1626 | default: |
1627 | break; | |
1628 | } | |
1629 | } | |
07bd1c79 JB |
1630 | } else if (ieee80211_is_ext(mgmt->frame_control)) { |
1631 | if (sdata->vif.type == NL80211_IFTYPE_STATION) | |
1632 | ieee80211_sta_rx_queued_ext(sdata, skb); | |
1633 | else | |
1634 | WARN_ON(1); | |
1635 | } else if (ieee80211_is_data_qos(mgmt->frame_control)) { | |
1636 | struct ieee80211_hdr *hdr = (void *)mgmt; | |
1637 | struct sta_info *sta; | |
1638 | ||
1639 | /* | |
1640 | * So the frame isn't mgmt, but frame_control | |
1641 | * is at the right place anyway, of course, so | |
1642 | * the if statement is correct. | |
1643 | * | |
1644 | * Warn if we have other data frame types here, | |
1645 | * they must not get here. | |
1646 | */ | |
1647 | WARN_ON(hdr->frame_control & | |
1648 | cpu_to_le16(IEEE80211_STYPE_NULLFUNC)); | |
1649 | WARN_ON(!(hdr->seq_ctrl & | |
1650 | cpu_to_le16(IEEE80211_SCTL_FRAG))); | |
1651 | /* | |
1652 | * This was a fragment of a frame, received while | |
1653 | * a block-ack session was active. That cannot be | |
1654 | * right, so terminate the session. | |
1655 | */ | |
07bd1c79 JB |
1656 | sta = sta_info_get_bss(sdata, mgmt->sa); |
1657 | if (sta) { | |
1658 | u16 tid = ieee80211_get_tid(hdr); | |
1659 | ||
1660 | __ieee80211_stop_rx_ba_session( | |
1661 | sta, tid, WLAN_BACK_RECIPIENT, | |
1662 | WLAN_REASON_QSTA_REQUIRE_SETUP, | |
1663 | true); | |
1664 | } | |
07bd1c79 JB |
1665 | } else switch (sdata->vif.type) { |
1666 | case NL80211_IFTYPE_STATION: | |
1667 | ieee80211_sta_rx_queued_mgmt(sdata, skb); | |
1668 | break; | |
1669 | case NL80211_IFTYPE_ADHOC: | |
1670 | ieee80211_ibss_rx_queued_mgmt(sdata, skb); | |
1671 | break; | |
1672 | case NL80211_IFTYPE_MESH_POINT: | |
1673 | if (!ieee80211_vif_is_mesh(&sdata->vif)) | |
1674 | break; | |
1675 | ieee80211_mesh_rx_queued_mgmt(sdata, skb); | |
1676 | break; | |
1677 | default: | |
1678 | WARN(1, "frame for unexpected interface type"); | |
1679 | break; | |
1680 | } | |
1681 | } | |
1682 | ||
f5a4c24e LB |
1683 | static void ieee80211_iface_process_status(struct ieee80211_sub_if_data *sdata, |
1684 | struct sk_buff *skb) | |
1685 | { | |
1686 | struct ieee80211_mgmt *mgmt = (void *)skb->data; | |
1687 | ||
1688 | if (ieee80211_is_action(mgmt->frame_control) && | |
1689 | mgmt->u.action.category == WLAN_CATEGORY_S1G) { | |
1690 | switch (mgmt->u.action.u.s1g.action_code) { | |
1691 | case WLAN_S1G_TWT_TEARDOWN: | |
1692 | case WLAN_S1G_TWT_SETUP: | |
1693 | ieee80211_s1g_status_twt_action(sdata, skb); | |
1694 | break; | |
1695 | default: | |
1696 | break; | |
1697 | } | |
1698 | } | |
1699 | } | |
1700 | ||
16114496 | 1701 | static void ieee80211_iface_work(struct wiphy *wiphy, struct wiphy_work *work) |
1fa57d01 JB |
1702 | { |
1703 | struct ieee80211_sub_if_data *sdata = | |
1704 | container_of(work, struct ieee80211_sub_if_data, work); | |
1705 | struct ieee80211_local *local = sdata->local; | |
1706 | struct sk_buff *skb; | |
1707 | ||
1708 | if (!ieee80211_sdata_running(sdata)) | |
1709 | return; | |
1710 | ||
fc58c47e | 1711 | if (test_bit(SCAN_SW_SCANNING, &local->scanning)) |
1fa57d01 JB |
1712 | return; |
1713 | ||
4afaff17 | 1714 | if (!ieee80211_can_run_worker(local)) |
1fa57d01 JB |
1715 | return; |
1716 | ||
1717 | /* first process frames */ | |
1718 | while ((skb = skb_dequeue(&sdata->skb_queue))) { | |
261e411b | 1719 | kcov_remote_start_common(skb_get_kcov_handle(skb)); |
bed7ee6e | 1720 | |
f057d140 JB |
1721 | if (skb->protocol == cpu_to_be16(ETH_P_TDLS)) |
1722 | ieee80211_process_tdls_channel_switch(sdata, skb); | |
1723 | else | |
1724 | ieee80211_iface_process_skb(local, sdata, skb); | |
36b3a628 JB |
1725 | |
1726 | kfree_skb(skb); | |
261e411b | 1727 | kcov_remote_stop(); |
1fa57d01 JB |
1728 | } |
1729 | ||
f5a4c24e LB |
1730 | /* process status queue */ |
1731 | while ((skb = skb_dequeue(&sdata->status_queue))) { | |
1732 | kcov_remote_start_common(skb_get_kcov_handle(skb)); | |
1733 | ||
1734 | ieee80211_iface_process_status(sdata, skb); | |
1735 | kfree_skb(skb); | |
1736 | ||
1737 | kcov_remote_stop(); | |
1738 | } | |
1739 | ||
1fa57d01 JB |
1740 | /* then other type-dependent work */ |
1741 | switch (sdata->vif.type) { | |
1742 | case NL80211_IFTYPE_STATION: | |
1743 | ieee80211_sta_work(sdata); | |
1744 | break; | |
1745 | case NL80211_IFTYPE_ADHOC: | |
1746 | ieee80211_ibss_work(sdata); | |
1747 | break; | |
1748 | case NL80211_IFTYPE_MESH_POINT: | |
1749 | if (!ieee80211_vif_is_mesh(&sdata->vif)) | |
1750 | break; | |
1751 | ieee80211_mesh_work(sdata); | |
1752 | break; | |
239281f8 RL |
1753 | case NL80211_IFTYPE_OCB: |
1754 | ieee80211_ocb_work(sdata); | |
1755 | break; | |
1fa57d01 JB |
1756 | default: |
1757 | break; | |
1758 | } | |
1759 | } | |
1760 | ||
7206a948 JB |
1761 | static void ieee80211_activate_links_work(struct wiphy *wiphy, |
1762 | struct wiphy_work *work) | |
3d901102 JB |
1763 | { |
1764 | struct ieee80211_sub_if_data *sdata = | |
1765 | container_of(work, struct ieee80211_sub_if_data, | |
1766 | activate_links_work); | |
c6d075be MK |
1767 | struct ieee80211_local *local = wiphy_priv(wiphy); |
1768 | ||
1769 | if (local->in_reconfig) | |
1770 | return; | |
3d901102 JB |
1771 | |
1772 | ieee80211_set_active_links(&sdata->vif, sdata->desired_active_links); | |
c6d075be | 1773 | sdata->desired_active_links = 0; |
3d901102 JB |
1774 | } |
1775 | ||
75636525 JB |
1776 | /* |
1777 | * Helper function to initialise an interface to a specific type. | |
1778 | */ | |
1779 | static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata, | |
05c914fe | 1780 | enum nl80211_iftype type) |
f0706e82 | 1781 | { |
239281f8 RL |
1782 | static const u8 bssid_wildcard[ETH_ALEN] = {0xff, 0xff, 0xff, |
1783 | 0xff, 0xff, 0xff}; | |
1784 | ||
bfd8403a | 1785 | /* clear type-dependent unions */ |
75636525 | 1786 | memset(&sdata->u, 0, sizeof(sdata->u)); |
bfd8403a | 1787 | memset(&sdata->deflink.u, 0, sizeof(sdata->deflink.u)); |
75636525 JB |
1788 | |
1789 | /* and set some type-dependent values */ | |
1790 | sdata->vif.type = type; | |
2ca27bcf | 1791 | sdata->vif.p2p = false; |
60719ffd | 1792 | sdata->wdev.iftype = type; |
75636525 | 1793 | |
a621fa4d JB |
1794 | sdata->control_port_protocol = cpu_to_be16(ETH_P_PAE); |
1795 | sdata->control_port_no_encrypt = false; | |
7f3f96ce MT |
1796 | sdata->control_port_over_nl80211 = false; |
1797 | sdata->control_port_no_preauth = false; | |
f276e20b | 1798 | sdata->vif.cfg.idle = true; |
db6d9e9e | 1799 | sdata->vif.bss_conf.txpower = INT_MIN; /* unset */ |
a621fa4d | 1800 | |
b53be792 SW |
1801 | sdata->noack_map = 0; |
1802 | ||
f142c6b9 JB |
1803 | /* only monitor/p2p-device differ */ |
1804 | if (sdata->dev) { | |
1805 | sdata->dev->netdev_ops = &ieee80211_dataif_ops; | |
1806 | sdata->dev->type = ARPHRD_ETHER; | |
1807 | } | |
75636525 | 1808 | |
35f20c14 | 1809 | skb_queue_head_init(&sdata->skb_queue); |
f5a4c24e | 1810 | skb_queue_head_init(&sdata->status_queue); |
16114496 | 1811 | wiphy_work_init(&sdata->work, ieee80211_iface_work); |
7206a948 JB |
1812 | wiphy_work_init(&sdata->activate_links_work, |
1813 | ieee80211_activate_links_work); | |
35f20c14 | 1814 | |
75636525 | 1815 | switch (type) { |
2ca27bcf JB |
1816 | case NL80211_IFTYPE_P2P_GO: |
1817 | type = NL80211_IFTYPE_AP; | |
1818 | sdata->vif.type = type; | |
1819 | sdata->vif.p2p = true; | |
fc0561dc | 1820 | fallthrough; |
05c914fe | 1821 | case NL80211_IFTYPE_AP: |
d012a605 | 1822 | skb_queue_head_init(&sdata->u.ap.ps.bc_buf); |
75636525 | 1823 | INIT_LIST_HEAD(&sdata->u.ap.vlans); |
ad2d223a | 1824 | sdata->vif.bss_conf.bssid = sdata->vif.addr; |
75636525 | 1825 | break; |
2ca27bcf JB |
1826 | case NL80211_IFTYPE_P2P_CLIENT: |
1827 | type = NL80211_IFTYPE_STATION; | |
1828 | sdata->vif.type = type; | |
1829 | sdata->vif.p2p = true; | |
fc0561dc | 1830 | fallthrough; |
05c914fe | 1831 | case NL80211_IFTYPE_STATION: |
bfd8403a | 1832 | sdata->vif.bss_conf.bssid = sdata->deflink.u.mgd.bssid; |
9c6bd790 | 1833 | ieee80211_sta_setup_sdata(sdata); |
472dbc45 | 1834 | break; |
6e0bd6c3 | 1835 | case NL80211_IFTYPE_OCB: |
239281f8 RL |
1836 | sdata->vif.bss_conf.bssid = bssid_wildcard; |
1837 | ieee80211_ocb_setup_sdata(sdata); | |
6e0bd6c3 | 1838 | break; |
46900298 | 1839 | case NL80211_IFTYPE_ADHOC: |
ad2d223a | 1840 | sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid; |
46900298 JB |
1841 | ieee80211_ibss_setup_sdata(sdata); |
1842 | break; | |
05c914fe | 1843 | case NL80211_IFTYPE_MESH_POINT: |
75636525 JB |
1844 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
1845 | ieee80211_mesh_init_sdata(sdata); | |
1846 | break; | |
05c914fe | 1847 | case NL80211_IFTYPE_MONITOR: |
75636525 | 1848 | sdata->dev->type = ARPHRD_IEEE80211_RADIOTAP; |
587e729e | 1849 | sdata->dev->netdev_ops = &ieee80211_monitorif_ops; |
d8212184 | 1850 | sdata->u.mntr.flags = MONITOR_FLAG_CONTROL | |
75636525 JB |
1851 | MONITOR_FLAG_OTHER_BSS; |
1852 | break; | |
167e33f4 AB |
1853 | case NL80211_IFTYPE_NAN: |
1854 | idr_init(&sdata->u.nan.function_inst_ids); | |
1855 | spin_lock_init(&sdata->u.nan.func_lock); | |
1856 | sdata->vif.bss_conf.bssid = sdata->vif.addr; | |
1857 | break; | |
05c914fe | 1858 | case NL80211_IFTYPE_AP_VLAN: |
98104fde | 1859 | case NL80211_IFTYPE_P2P_DEVICE: |
ad2d223a | 1860 | sdata->vif.bss_conf.bssid = sdata->vif.addr; |
f142c6b9 | 1861 | break; |
05c914fe | 1862 | case NL80211_IFTYPE_UNSPECIFIED: |
70d9c599 | 1863 | case NL80211_IFTYPE_WDS: |
2e161f78 | 1864 | case NUM_NL80211_IFTYPES: |
c7976f52 | 1865 | WARN_ON(1); |
75636525 JB |
1866 | break; |
1867 | } | |
1868 | ||
b2e8434f JB |
1869 | /* need to do this after the switch so vif.type is correct */ |
1870 | ieee80211_link_setup(&sdata->deflink); | |
1871 | ||
733c498a | 1872 | ieee80211_debugfs_recreate_netdev(sdata, false); |
75636525 JB |
1873 | } |
1874 | ||
34d4bc4d JB |
1875 | static int ieee80211_runtime_change_iftype(struct ieee80211_sub_if_data *sdata, |
1876 | enum nl80211_iftype type) | |
1877 | { | |
1878 | struct ieee80211_local *local = sdata->local; | |
1879 | int ret, err; | |
2ca27bcf JB |
1880 | enum nl80211_iftype internal_type = type; |
1881 | bool p2p = false; | |
34d4bc4d JB |
1882 | |
1883 | ASSERT_RTNL(); | |
1884 | ||
1885 | if (!local->ops->change_interface) | |
1886 | return -EBUSY; | |
1887 | ||
d8787ec6 | 1888 | /* for now, don't support changing while links exist */ |
f1871abd | 1889 | if (ieee80211_vif_is_mld(&sdata->vif)) |
d8787ec6 JB |
1890 | return -EBUSY; |
1891 | ||
34d4bc4d JB |
1892 | switch (sdata->vif.type) { |
1893 | case NL80211_IFTYPE_AP: | |
d5befb22 JB |
1894 | if (!list_empty(&sdata->u.ap.vlans)) |
1895 | return -EBUSY; | |
1896 | break; | |
34d4bc4d JB |
1897 | case NL80211_IFTYPE_STATION: |
1898 | case NL80211_IFTYPE_ADHOC: | |
239281f8 | 1899 | case NL80211_IFTYPE_OCB: |
34d4bc4d JB |
1900 | /* |
1901 | * Could maybe also all others here? | |
1902 | * Just not sure how that interacts | |
1903 | * with the RX/config path e.g. for | |
1904 | * mesh. | |
1905 | */ | |
1906 | break; | |
1907 | default: | |
1908 | return -EBUSY; | |
1909 | } | |
1910 | ||
1911 | switch (type) { | |
1912 | case NL80211_IFTYPE_AP: | |
1913 | case NL80211_IFTYPE_STATION: | |
1914 | case NL80211_IFTYPE_ADHOC: | |
239281f8 | 1915 | case NL80211_IFTYPE_OCB: |
34d4bc4d JB |
1916 | /* |
1917 | * Could probably support everything | |
70d9c599 | 1918 | * but here. |
34d4bc4d JB |
1919 | */ |
1920 | break; | |
2ca27bcf JB |
1921 | case NL80211_IFTYPE_P2P_CLIENT: |
1922 | p2p = true; | |
1923 | internal_type = NL80211_IFTYPE_STATION; | |
1924 | break; | |
1925 | case NL80211_IFTYPE_P2P_GO: | |
1926 | p2p = true; | |
1927 | internal_type = NL80211_IFTYPE_AP; | |
1928 | break; | |
34d4bc4d JB |
1929 | default: |
1930 | return -EBUSY; | |
1931 | } | |
1932 | ||
2ca27bcf | 1933 | ret = ieee80211_check_concurrent_iface(sdata, internal_type); |
34d4bc4d JB |
1934 | if (ret) |
1935 | return ret; | |
1936 | ||
054c9939 JB |
1937 | ieee80211_stop_vif_queues(local, sdata, |
1938 | IEEE80211_QUEUE_STOP_REASON_IFTYPE_CHANGE); | |
b2ddde56 | 1939 | /* do_stop will synchronize_rcu() first thing */ |
34d4bc4d JB |
1940 | ieee80211_do_stop(sdata, false); |
1941 | ||
f142c6b9 | 1942 | ieee80211_teardown_sdata(sdata); |
34d4bc4d | 1943 | |
6aea26ce | 1944 | ieee80211_set_sdata_offload_flags(sdata); |
2ca27bcf | 1945 | ret = drv_change_interface(local, sdata, internal_type, p2p); |
34d4bc4d | 1946 | if (ret) |
a9865538 | 1947 | type = ieee80211_vif_type_p2p(&sdata->vif); |
34d4bc4d | 1948 | |
3a25a8c8 JB |
1949 | /* |
1950 | * Ignore return value here, there's not much we can do since | |
1951 | * the driver changed the interface type internally already. | |
1952 | * The warnings will hopefully make driver authors fix it :-) | |
1953 | */ | |
a9865538 | 1954 | ieee80211_check_queues(sdata, type); |
3a25a8c8 | 1955 | |
34d4bc4d | 1956 | ieee80211_setup_sdata(sdata, type); |
6aea26ce | 1957 | ieee80211_set_vif_encap_ops(sdata); |
34d4bc4d | 1958 | |
f142c6b9 | 1959 | err = ieee80211_do_open(&sdata->wdev, false); |
34d4bc4d JB |
1960 | WARN(err, "type change: do_open returned %d", err); |
1961 | ||
054c9939 JB |
1962 | ieee80211_wake_vif_queues(local, sdata, |
1963 | IEEE80211_QUEUE_STOP_REASON_IFTYPE_CHANGE); | |
34d4bc4d JB |
1964 | return ret; |
1965 | } | |
1966 | ||
f3947e2d | 1967 | int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata, |
05c914fe | 1968 | enum nl80211_iftype type) |
75636525 | 1969 | { |
34d4bc4d JB |
1970 | int ret; |
1971 | ||
f3947e2d JB |
1972 | ASSERT_RTNL(); |
1973 | ||
2ca27bcf | 1974 | if (type == ieee80211_vif_type_p2p(&sdata->vif)) |
f3947e2d JB |
1975 | return 0; |
1976 | ||
34d4bc4d JB |
1977 | if (ieee80211_sdata_running(sdata)) { |
1978 | ret = ieee80211_runtime_change_iftype(sdata, type); | |
1979 | if (ret) | |
1980 | return ret; | |
1981 | } else { | |
1982 | /* Purge and reset type-dependent state. */ | |
f142c6b9 | 1983 | ieee80211_teardown_sdata(sdata); |
34d4bc4d JB |
1984 | ieee80211_setup_sdata(sdata, type); |
1985 | } | |
75636525 JB |
1986 | |
1987 | /* reset some values that shouldn't be kept across type changes */ | |
9bc383de JB |
1988 | if (type == NL80211_IFTYPE_STATION) |
1989 | sdata->u.mgd.use_4addr = false; | |
f3947e2d JB |
1990 | |
1991 | return 0; | |
f0706e82 JB |
1992 | } |
1993 | ||
fa9029f8 | 1994 | static void ieee80211_assign_perm_addr(struct ieee80211_local *local, |
f142c6b9 | 1995 | u8 *perm_addr, enum nl80211_iftype type) |
fa9029f8 JB |
1996 | { |
1997 | struct ieee80211_sub_if_data *sdata; | |
1998 | u64 mask, start, addr, val, inc; | |
1999 | u8 *m; | |
2000 | u8 tmp_addr[ETH_ALEN]; | |
2001 | int i; | |
2002 | ||
be0df01d JB |
2003 | lockdep_assert_wiphy(local->hw.wiphy); |
2004 | ||
fa9029f8 | 2005 | /* default ... something at least */ |
f142c6b9 | 2006 | memcpy(perm_addr, local->hw.wiphy->perm_addr, ETH_ALEN); |
fa9029f8 JB |
2007 | |
2008 | if (is_zero_ether_addr(local->hw.wiphy->addr_mask) && | |
2009 | local->hw.wiphy->n_addresses <= 1) | |
2010 | return; | |
2011 | ||
fa9029f8 JB |
2012 | switch (type) { |
2013 | case NL80211_IFTYPE_MONITOR: | |
2014 | /* doesn't matter */ | |
2015 | break; | |
fa9029f8 JB |
2016 | case NL80211_IFTYPE_AP_VLAN: |
2017 | /* match up with an AP interface */ | |
2018 | list_for_each_entry(sdata, &local->interfaces, list) { | |
2019 | if (sdata->vif.type != NL80211_IFTYPE_AP) | |
2020 | continue; | |
f142c6b9 | 2021 | memcpy(perm_addr, sdata->vif.addr, ETH_ALEN); |
fa9029f8 JB |
2022 | break; |
2023 | } | |
2024 | /* keep default if no AP interface present */ | |
2025 | break; | |
6d71117a JB |
2026 | case NL80211_IFTYPE_P2P_CLIENT: |
2027 | case NL80211_IFTYPE_P2P_GO: | |
30686bf7 | 2028 | if (ieee80211_hw_check(&local->hw, P2P_DEV_ADDR_FOR_INTF)) { |
6d71117a JB |
2029 | list_for_each_entry(sdata, &local->interfaces, list) { |
2030 | if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE) | |
2031 | continue; | |
2032 | if (!ieee80211_sdata_running(sdata)) | |
2033 | continue; | |
2034 | memcpy(perm_addr, sdata->vif.addr, ETH_ALEN); | |
be0df01d | 2035 | return; |
6d71117a JB |
2036 | } |
2037 | } | |
fc0561dc | 2038 | fallthrough; |
fa9029f8 JB |
2039 | default: |
2040 | /* assign a new address if possible -- try n_addresses first */ | |
2041 | for (i = 0; i < local->hw.wiphy->n_addresses; i++) { | |
2042 | bool used = false; | |
2043 | ||
2044 | list_for_each_entry(sdata, &local->interfaces, list) { | |
496d7e8e | 2045 | if (ether_addr_equal(local->hw.wiphy->addresses[i].addr, |
2046 | sdata->vif.addr)) { | |
fa9029f8 JB |
2047 | used = true; |
2048 | break; | |
2049 | } | |
2050 | } | |
2051 | ||
2052 | if (!used) { | |
f142c6b9 | 2053 | memcpy(perm_addr, |
fa9029f8 JB |
2054 | local->hw.wiphy->addresses[i].addr, |
2055 | ETH_ALEN); | |
2056 | break; | |
2057 | } | |
2058 | } | |
2059 | ||
2060 | /* try mask if available */ | |
2061 | if (is_zero_ether_addr(local->hw.wiphy->addr_mask)) | |
2062 | break; | |
2063 | ||
2064 | m = local->hw.wiphy->addr_mask; | |
2065 | mask = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) | | |
2066 | ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) | | |
2067 | ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8); | |
2068 | ||
2069 | if (__ffs64(mask) + hweight64(mask) != fls64(mask)) { | |
2070 | /* not a contiguous mask ... not handled now! */ | |
bdcbd8e0 | 2071 | pr_info("not contiguous\n"); |
fa9029f8 JB |
2072 | break; |
2073 | } | |
2074 | ||
ac20976d HS |
2075 | /* |
2076 | * Pick address of existing interface in case user changed | |
2077 | * MAC address manually, default to perm_addr. | |
2078 | */ | |
fa9029f8 | 2079 | m = local->hw.wiphy->perm_addr; |
ac20976d HS |
2080 | list_for_each_entry(sdata, &local->interfaces, list) { |
2081 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) | |
2082 | continue; | |
2083 | m = sdata->vif.addr; | |
2084 | break; | |
2085 | } | |
fa9029f8 JB |
2086 | start = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) | |
2087 | ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) | | |
2088 | ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8); | |
2089 | ||
2090 | inc = 1ULL<<__ffs64(mask); | |
2091 | val = (start & mask); | |
2092 | addr = (start & ~mask) | (val & mask); | |
2093 | do { | |
2094 | bool used = false; | |
2095 | ||
2096 | tmp_addr[5] = addr >> 0*8; | |
2097 | tmp_addr[4] = addr >> 1*8; | |
2098 | tmp_addr[3] = addr >> 2*8; | |
2099 | tmp_addr[2] = addr >> 3*8; | |
2100 | tmp_addr[1] = addr >> 4*8; | |
2101 | tmp_addr[0] = addr >> 5*8; | |
2102 | ||
2103 | val += inc; | |
2104 | ||
2105 | list_for_each_entry(sdata, &local->interfaces, list) { | |
496d7e8e | 2106 | if (ether_addr_equal(tmp_addr, sdata->vif.addr)) { |
fa9029f8 JB |
2107 | used = true; |
2108 | break; | |
2109 | } | |
2110 | } | |
2111 | ||
2112 | if (!used) { | |
f142c6b9 | 2113 | memcpy(perm_addr, tmp_addr, ETH_ALEN); |
fa9029f8 JB |
2114 | break; |
2115 | } | |
2116 | addr = (start & ~mask) | (val & mask); | |
2117 | } while (addr != start); | |
2118 | ||
2119 | break; | |
2120 | } | |
fa9029f8 JB |
2121 | } |
2122 | ||
3e122be0 | 2123 | int ieee80211_if_add(struct ieee80211_local *local, const char *name, |
6bab2e19 | 2124 | unsigned char name_assign_type, |
84efbb84 | 2125 | struct wireless_dev **new_wdev, enum nl80211_iftype type, |
ee385855 | 2126 | struct vif_params *params) |
f0706e82 | 2127 | { |
f142c6b9 | 2128 | struct net_device *ndev = NULL; |
f0706e82 | 2129 | struct ieee80211_sub_if_data *sdata = NULL; |
ba8c3d6f | 2130 | struct txq_info *txqi; |
75636525 | 2131 | int ret, i; |
f0706e82 JB |
2132 | |
2133 | ASSERT_RTNL(); | |
be0df01d | 2134 | lockdep_assert_wiphy(local->hw.wiphy); |
75636525 | 2135 | |
708d50ed | 2136 | if (type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN) { |
f142c6b9 JB |
2137 | struct wireless_dev *wdev; |
2138 | ||
2139 | sdata = kzalloc(sizeof(*sdata) + local->hw.vif_data_size, | |
2140 | GFP_KERNEL); | |
2141 | if (!sdata) | |
2142 | return -ENOMEM; | |
2143 | wdev = &sdata->wdev; | |
2144 | ||
2145 | sdata->dev = NULL; | |
28b904ec | 2146 | strscpy(sdata->name, name, IFNAMSIZ); |
f142c6b9 JB |
2147 | ieee80211_assign_perm_addr(local, wdev->address, type); |
2148 | memcpy(sdata->vif.addr, wdev->address, ETH_ALEN); | |
d8787ec6 | 2149 | ether_addr_copy(sdata->vif.bss_conf.addr, sdata->vif.addr); |
f142c6b9 | 2150 | } else { |
ba8c3d6f FF |
2151 | int size = ALIGN(sizeof(*sdata) + local->hw.vif_data_size, |
2152 | sizeof(void *)); | |
2153 | int txq_size = 0; | |
2154 | ||
107395f9 | 2155 | if (type != NL80211_IFTYPE_AP_VLAN && |
8105f9b8 FF |
2156 | (type != NL80211_IFTYPE_MONITOR || |
2157 | (params->flags & MONITOR_FLAG_ACTIVE))) | |
ba8c3d6f FF |
2158 | txq_size += sizeof(struct txq_info) + |
2159 | local->hw.txq_data_size; | |
2160 | ||
ba8c3d6f | 2161 | ndev = alloc_netdev_mqs(size + txq_size, |
6bab2e19 | 2162 | name, name_assign_type, |
107395f9 | 2163 | ieee80211_if_setup, 1, 1); |
f142c6b9 JB |
2164 | if (!ndev) |
2165 | return -ENOMEM; | |
1f6e0baa | 2166 | |
f142c6b9 JB |
2167 | dev_net_set(ndev, wiphy_net(local->hw.wiphy)); |
2168 | ||
7b7890f3 | 2169 | ndev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS; |
5a490510 | 2170 | |
f142c6b9 JB |
2171 | ndev->needed_headroom = local->tx_headroom + |
2172 | 4*6 /* four MAC addresses */ | |
2173 | + 2 + 2 + 2 + 2 /* ctl, dur, seq, qos */ | |
2174 | + 6 /* mesh */ | |
2175 | + 8 /* rfc1042/bridge tunnel */ | |
2176 | - ETH_HLEN /* ethernet hard_header_len */ | |
2177 | + IEEE80211_ENCRYPT_HEADROOM; | |
2178 | ndev->needed_tailroom = IEEE80211_ENCRYPT_TAILROOM; | |
2179 | ||
2180 | ret = dev_alloc_name(ndev, ndev->name); | |
2181 | if (ret < 0) { | |
c7a61cba | 2182 | free_netdev(ndev); |
f142c6b9 JB |
2183 | return ret; |
2184 | } | |
2185 | ||
2186 | ieee80211_assign_perm_addr(local, ndev->perm_addr, type); | |
dd665d23 | 2187 | if (is_valid_ether_addr(params->macaddr)) |
de1352ea | 2188 | eth_hw_addr_set(ndev, params->macaddr); |
b5dfae02 | 2189 | else |
de1352ea | 2190 | eth_hw_addr_set(ndev, ndev->perm_addr); |
f142c6b9 JB |
2191 | SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy)); |
2192 | ||
2193 | /* don't use IEEE80211_DEV_TO_SUB_IF -- it checks too much */ | |
2194 | sdata = netdev_priv(ndev); | |
2195 | ndev->ieee80211_ptr = &sdata->wdev; | |
2196 | memcpy(sdata->vif.addr, ndev->dev_addr, ETH_ALEN); | |
d8787ec6 | 2197 | ether_addr_copy(sdata->vif.bss_conf.addr, sdata->vif.addr); |
f142c6b9 JB |
2198 | memcpy(sdata->name, ndev->name, IFNAMSIZ); |
2199 | ||
ba8c3d6f FF |
2200 | if (txq_size) { |
2201 | txqi = netdev_priv(ndev) + size; | |
fa962b92 | 2202 | ieee80211_txq_init(sdata, NULL, txqi, 0); |
ba8c3d6f FF |
2203 | } |
2204 | ||
f142c6b9 JB |
2205 | sdata->dev = ndev; |
2206 | } | |
75636525 JB |
2207 | |
2208 | /* initialise type-independent data */ | |
f0706e82 | 2209 | sdata->wdev.wiphy = local->hw.wiphy; |
8e14130d JB |
2210 | |
2211 | ieee80211_sdata_init(local, sdata); | |
75636525 | 2212 | |
3a11ce08 | 2213 | ieee80211_init_frag_cache(&sdata->frags); |
75636525 | 2214 | |
e3208fb7 JB |
2215 | wiphy_delayed_work_init(&sdata->dec_tailroom_needed_wk, |
2216 | ieee80211_delayed_tailroom_dec); | |
97f97b1f | 2217 | |
57fbcce3 | 2218 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
37eb0b16 JM |
2219 | struct ieee80211_supported_band *sband; |
2220 | sband = local->hw.wiphy->bands[i]; | |
2221 | sdata->rc_rateidx_mask[i] = | |
2222 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
b119ad6e LB |
2223 | if (sband) { |
2224 | __le16 cap; | |
2225 | u16 *vht_rate_mask; | |
2226 | ||
19468413 SW |
2227 | memcpy(sdata->rc_rateidx_mcs_mask[i], |
2228 | sband->ht_cap.mcs.rx_mask, | |
2229 | sizeof(sdata->rc_rateidx_mcs_mask[i])); | |
b119ad6e LB |
2230 | |
2231 | cap = sband->vht_cap.vht_mcs.rx_mcs_map; | |
2232 | vht_rate_mask = sdata->rc_rateidx_vht_mcs_mask[i]; | |
2233 | ieee80211_get_vht_mask_from_cap(cap, vht_rate_mask); | |
2234 | } else { | |
19468413 SW |
2235 | memset(sdata->rc_rateidx_mcs_mask[i], 0, |
2236 | sizeof(sdata->rc_rateidx_mcs_mask[i])); | |
b119ad6e LB |
2237 | memset(sdata->rc_rateidx_vht_mcs_mask[i], 0, |
2238 | sizeof(sdata->rc_rateidx_vht_mcs_mask[i])); | |
2239 | } | |
37eb0b16 | 2240 | } |
75636525 | 2241 | |
3a25a8c8 JB |
2242 | ieee80211_set_default_queues(sdata); |
2243 | ||
75636525 JB |
2244 | /* setup type-dependent data */ |
2245 | ieee80211_setup_sdata(sdata, type); | |
f0706e82 | 2246 | |
f142c6b9 | 2247 | if (ndev) { |
dd665d23 JB |
2248 | ndev->ieee80211_ptr->use_4addr = params->use_4addr; |
2249 | if (type == NL80211_IFTYPE_STATION) | |
2250 | sdata->u.mgd.use_4addr = params->use_4addr; | |
9bc383de | 2251 | |
f142c6b9 | 2252 | ndev->features |= local->hw.netdev_features; |
3c06e91b | 2253 | ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE; |
07b83d2e JB |
2254 | ndev->hw_features |= ndev->features & |
2255 | MAC80211_SUPPORTED_FEATURES_TX; | |
7d360f60 | 2256 | sdata->vif.netdev_features = local->hw.netdev_features; |
72d78728 | 2257 | |
b7ffbd7e JB |
2258 | netdev_set_default_ethtool_ops(ndev, &ieee80211_ethtool_ops); |
2259 | ||
79f5962b JA |
2260 | /* MTU range is normally 256 - 2304, where the upper limit is |
2261 | * the maximum MSDU size. Monitor interfaces send and receive | |
2262 | * MPDU and A-MSDU frames which may be much larger so we do | |
2263 | * not impose an upper limit in that case. | |
2264 | */ | |
9c22b4a3 | 2265 | ndev->min_mtu = 256; |
79f5962b JA |
2266 | if (type == NL80211_IFTYPE_MONITOR) |
2267 | ndev->max_mtu = 0; | |
2268 | else | |
2269 | ndev->max_mtu = local->hw.max_mtu; | |
9c22b4a3 | 2270 | |
2fe8ef10 | 2271 | ret = cfg80211_register_netdevice(ndev); |
f142c6b9 | 2272 | if (ret) { |
cf124db5 | 2273 | free_netdev(ndev); |
f142c6b9 JB |
2274 | return ret; |
2275 | } | |
2276 | } | |
f0706e82 | 2277 | |
c771c9d8 | 2278 | mutex_lock(&local->iflist_mtx); |
79010420 | 2279 | list_add_tail_rcu(&sdata->list, &local->interfaces); |
c771c9d8 | 2280 | mutex_unlock(&local->iflist_mtx); |
79010420 | 2281 | |
84efbb84 JB |
2282 | if (new_wdev) |
2283 | *new_wdev = &sdata->wdev; | |
f0706e82 | 2284 | |
f0706e82 | 2285 | return 0; |
f0706e82 JB |
2286 | } |
2287 | ||
f698d856 | 2288 | void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata) |
f0706e82 | 2289 | { |
f0706e82 | 2290 | ASSERT_RTNL(); |
be0df01d | 2291 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
11a843b7 | 2292 | |
c771c9d8 | 2293 | mutex_lock(&sdata->local->iflist_mtx); |
75636525 | 2294 | list_del_rcu(&sdata->list); |
c771c9d8 JB |
2295 | mutex_unlock(&sdata->local->iflist_mtx); |
2296 | ||
f1267cf3 BP |
2297 | if (sdata->vif.txq) |
2298 | ieee80211_txq_purge(sdata->local, to_txq_info(sdata->vif.txq)); | |
2299 | ||
75636525 | 2300 | synchronize_rcu(); |
f142c6b9 | 2301 | |
2fe8ef10 JB |
2302 | cfg80211_unregister_wdev(&sdata->wdev); |
2303 | ||
2304 | if (!sdata->dev) { | |
835112b2 | 2305 | ieee80211_teardown_sdata(sdata); |
f142c6b9 JB |
2306 | kfree(sdata); |
2307 | } | |
2308 | } | |
2309 | ||
2310 | void ieee80211_sdata_stop(struct ieee80211_sub_if_data *sdata) | |
2311 | { | |
2312 | if (WARN_ON_ONCE(!test_bit(SDATA_STATE_RUNNING, &sdata->state))) | |
2313 | return; | |
2314 | ieee80211_do_stop(sdata, true); | |
f0706e82 JB |
2315 | } |
2316 | ||
75636525 | 2317 | void ieee80211_remove_interfaces(struct ieee80211_local *local) |
f0706e82 | 2318 | { |
75636525 | 2319 | struct ieee80211_sub_if_data *sdata, *tmp; |
efe117ab | 2320 | LIST_HEAD(unreg_list); |
f0706e82 JB |
2321 | |
2322 | ASSERT_RTNL(); | |
2323 | ||
d8d9008c JB |
2324 | /* Before destroying the interfaces, make sure they're all stopped so |
2325 | * that the hardware is stopped. Otherwise, the driver might still be | |
2326 | * iterating the interfaces during the shutdown, e.g. from a worker | |
2327 | * or from RX processing or similar, and if it does so (using atomic | |
2328 | * iteration) while we're manipulating the list, the iteration will | |
2329 | * crash. | |
2330 | * | |
2331 | * After this, the hardware should be stopped and the driver should | |
2332 | * have stopped all of its activities, so that we can do RCU-unaware | |
2333 | * manipulations of the interface list below. | |
c8aa22db | 2334 | */ |
d8d9008c JB |
2335 | cfg80211_shutdown_all_interfaces(local->hw.wiphy); |
2336 | ||
8e66f6c6 | 2337 | guard(wiphy)(local->hw.wiphy); |
332e68bc | 2338 | |
d8d9008c JB |
2339 | WARN(local->open_count, "%s: open count remains %d\n", |
2340 | wiphy_name(local->hw.wiphy), local->open_count); | |
c8aa22db | 2341 | |
efe117ab | 2342 | mutex_lock(&local->iflist_mtx); |
a3df43b1 | 2343 | list_splice_init(&local->interfaces, &unreg_list); |
efe117ab | 2344 | mutex_unlock(&local->iflist_mtx); |
a05829a7 | 2345 | |
a3df43b1 JB |
2346 | list_for_each_entry_safe(sdata, tmp, &unreg_list, list) { |
2347 | bool netdev = sdata->dev; | |
2348 | ||
730538ed JB |
2349 | /* |
2350 | * Remove IP addresses explicitly, since the notifier will | |
2351 | * skip the callbacks if wdev->registered is false, since | |
2352 | * we can't acquire the wiphy_lock() again there if already | |
2353 | * inside this locked section. | |
2354 | */ | |
730538ed JB |
2355 | sdata->vif.cfg.arp_addr_cnt = 0; |
2356 | if (sdata->vif.type == NL80211_IFTYPE_STATION && | |
2357 | sdata->u.mgd.associated) | |
2358 | ieee80211_vif_cfg_change_notify(sdata, | |
2359 | BSS_CHANGED_ARP_FILTER); | |
730538ed | 2360 | |
f142c6b9 JB |
2361 | list_del(&sdata->list); |
2362 | cfg80211_unregister_wdev(&sdata->wdev); | |
a3df43b1 JB |
2363 | |
2364 | if (!netdev) | |
2365 | kfree(sdata); | |
f142c6b9 | 2366 | } |
f0706e82 | 2367 | } |
5cff20e6 | 2368 | |
47846c9b | 2369 | static int netdev_notify(struct notifier_block *nb, |
351638e7 | 2370 | unsigned long state, void *ptr) |
47846c9b | 2371 | { |
351638e7 | 2372 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); |
47846c9b JB |
2373 | struct ieee80211_sub_if_data *sdata; |
2374 | ||
2375 | if (state != NETDEV_CHANGENAME) | |
8bd811aa | 2376 | return NOTIFY_DONE; |
47846c9b JB |
2377 | |
2378 | if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy) | |
8bd811aa | 2379 | return NOTIFY_DONE; |
47846c9b JB |
2380 | |
2381 | if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid) | |
8bd811aa | 2382 | return NOTIFY_DONE; |
47846c9b JB |
2383 | |
2384 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2f5265e6 | 2385 | memcpy(sdata->name, dev->name, IFNAMSIZ); |
47846c9b | 2386 | ieee80211_debugfs_rename_netdev(sdata); |
8bd811aa ZG |
2387 | |
2388 | return NOTIFY_OK; | |
47846c9b JB |
2389 | } |
2390 | ||
2391 | static struct notifier_block mac80211_netdev_notifier = { | |
2392 | .notifier_call = netdev_notify, | |
2393 | }; | |
2394 | ||
2395 | int ieee80211_iface_init(void) | |
2396 | { | |
2397 | return register_netdevice_notifier(&mac80211_netdev_notifier); | |
2398 | } | |
2399 | ||
2400 | void ieee80211_iface_exit(void) | |
2401 | { | |
2402 | unregister_netdevice_notifier(&mac80211_netdev_notifier); | |
2403 | } | |
72f15d53 MB |
2404 | |
2405 | void ieee80211_vif_inc_num_mcast(struct ieee80211_sub_if_data *sdata) | |
2406 | { | |
2407 | if (sdata->vif.type == NL80211_IFTYPE_AP) | |
2408 | atomic_inc(&sdata->u.ap.num_mcast_sta); | |
2409 | else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) | |
2410 | atomic_inc(&sdata->u.vlan.num_mcast_sta); | |
2411 | } | |
2412 | ||
2413 | void ieee80211_vif_dec_num_mcast(struct ieee80211_sub_if_data *sdata) | |
2414 | { | |
2415 | if (sdata->vif.type == NL80211_IFTYPE_AP) | |
2416 | atomic_dec(&sdata->u.ap.num_mcast_sta); | |
2417 | else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) | |
2418 | atomic_dec(&sdata->u.vlan.num_mcast_sta); | |
2419 | } | |
dc494fdc JB |
2420 | |
2421 | void ieee80211_vif_block_queues_csa(struct ieee80211_sub_if_data *sdata) | |
2422 | { | |
2423 | struct ieee80211_local *local = sdata->local; | |
2424 | ||
2425 | if (ieee80211_hw_check(&local->hw, HANDLES_QUIET_CSA)) | |
2426 | return; | |
2427 | ||
11ac0d7c EG |
2428 | ieee80211_stop_vif_queues_norefcount(local, sdata, |
2429 | IEEE80211_QUEUE_STOP_REASON_CSA); | |
dc494fdc JB |
2430 | } |
2431 | ||
2432 | void ieee80211_vif_unblock_queues_csa(struct ieee80211_sub_if_data *sdata) | |
2433 | { | |
2434 | struct ieee80211_local *local = sdata->local; | |
2435 | ||
11ac0d7c EG |
2436 | ieee80211_wake_vif_queues_norefcount(local, sdata, |
2437 | IEEE80211_QUEUE_STOP_REASON_CSA); | |
dc494fdc | 2438 | } |