Commit | Line | Data |
---|---|---|
f0706e82 | 1 | /* |
0d143fe1 JB |
2 | * Interface handling (except master interface) |
3 | * | |
f0706e82 JB |
4 | * Copyright 2002-2005, Instant802 Networks, Inc. |
5 | * Copyright 2005-2006, Devicescape Software, Inc. | |
6 | * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz> | |
75636525 | 7 | * Copyright 2008, Johannes Berg <johannes@sipsolutions.net> |
f0706e82 JB |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License version 2 as | |
11 | * published by the Free Software Foundation. | |
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> | |
18 | #include <net/mac80211.h> | |
cf0277e7 | 19 | #include <net/ieee80211_radiotap.h> |
f0706e82 JB |
20 | #include "ieee80211_i.h" |
21 | #include "sta_info.h" | |
e9f207f0 | 22 | #include "debugfs_netdev.h" |
ee385855 | 23 | #include "mesh.h" |
0d143fe1 | 24 | #include "led.h" |
24487981 | 25 | #include "driver-ops.h" |
cf0277e7 | 26 | #include "wme.h" |
0d143fe1 | 27 | |
c771c9d8 JB |
28 | /** |
29 | * DOC: Interface list locking | |
30 | * | |
31 | * The interface list in each struct ieee80211_local is protected | |
32 | * three-fold: | |
33 | * | |
34 | * (1) modifications may only be done under the RTNL | |
35 | * (2) modifications and readers are protected against each other by | |
36 | * the iflist_mtx. | |
37 | * (3) modifications are done in an RCU manner so atomic readers | |
38 | * can traverse the list in RCU-safe blocks. | |
39 | * | |
40 | * As a consequence, reads (traversals) of the list can be protected | |
41 | * by either the RTNL, the iflist_mtx or RCU. | |
42 | */ | |
43 | ||
44 | ||
0d143fe1 JB |
45 | static int ieee80211_change_mtu(struct net_device *dev, int new_mtu) |
46 | { | |
47 | int meshhdrlen; | |
48 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
49 | ||
50 | meshhdrlen = (sdata->vif.type == NL80211_IFTYPE_MESH_POINT) ? 5 : 0; | |
51 | ||
52 | /* FIX: what would be proper limits for MTU? | |
53 | * This interface uses 802.3 frames. */ | |
54 | if (new_mtu < 256 || | |
55 | new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) { | |
56 | return -EINVAL; | |
57 | } | |
58 | ||
59 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | |
60 | printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu); | |
61 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ | |
62 | dev->mtu = new_mtu; | |
63 | return 0; | |
64 | } | |
65 | ||
47846c9b JB |
66 | static int ieee80211_change_mac(struct net_device *dev, void *addr) |
67 | { | |
68 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
fc5f7577 | 69 | struct sockaddr *sa = addr; |
47846c9b JB |
70 | int ret; |
71 | ||
9607e6b6 | 72 | if (ieee80211_sdata_running(sdata)) |
47846c9b JB |
73 | return -EBUSY; |
74 | ||
fc5f7577 | 75 | ret = eth_mac_addr(dev, sa); |
47846c9b JB |
76 | |
77 | if (ret == 0) | |
fc5f7577 | 78 | memcpy(sdata->vif.addr, sa->sa_data, ETH_ALEN); |
47846c9b JB |
79 | |
80 | return ret; | |
81 | } | |
82 | ||
0d143fe1 JB |
83 | static inline int identical_mac_addr_allowed(int type1, int type2) |
84 | { | |
85 | return type1 == NL80211_IFTYPE_MONITOR || | |
86 | type2 == NL80211_IFTYPE_MONITOR || | |
87 | (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_WDS) || | |
88 | (type1 == NL80211_IFTYPE_WDS && | |
89 | (type2 == NL80211_IFTYPE_WDS || | |
90 | type2 == NL80211_IFTYPE_AP)) || | |
91 | (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_AP_VLAN) || | |
92 | (type1 == NL80211_IFTYPE_AP_VLAN && | |
93 | (type2 == NL80211_IFTYPE_AP || | |
94 | type2 == NL80211_IFTYPE_AP_VLAN)); | |
95 | } | |
96 | ||
97 | static int ieee80211_open(struct net_device *dev) | |
98 | { | |
b4a4bf5d JB |
99 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
100 | struct ieee80211_sub_if_data *nsdata; | |
101 | struct ieee80211_local *local = sdata->local; | |
0d143fe1 | 102 | struct sta_info *sta; |
0d143fe1 JB |
103 | u32 changed = 0; |
104 | int res; | |
e8975581 | 105 | u32 hw_reconf_flags = 0; |
0d143fe1 | 106 | |
0d143fe1 | 107 | /* fail early if user set an invalid address */ |
bf533e0b | 108 | if (!is_zero_ether_addr(dev->dev_addr) && |
0d143fe1 JB |
109 | !is_valid_ether_addr(dev->dev_addr)) |
110 | return -EADDRNOTAVAIL; | |
111 | ||
112 | /* we hold the RTNL here so can safely walk the list */ | |
113 | list_for_each_entry(nsdata, &local->interfaces, list) { | |
114 | struct net_device *ndev = nsdata->dev; | |
115 | ||
9607e6b6 | 116 | if (ndev != dev && ieee80211_sdata_running(nsdata)) { |
0d143fe1 JB |
117 | /* |
118 | * Allow only a single IBSS interface to be up at any | |
119 | * time. This is restricted because beacon distribution | |
120 | * cannot work properly if both are in the same IBSS. | |
121 | * | |
122 | * To remove this restriction we'd have to disallow them | |
123 | * from setting the same SSID on different IBSS interfaces | |
124 | * belonging to the same hardware. Then, however, we're | |
125 | * faced with having to adopt two different TSF timers... | |
126 | */ | |
127 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC && | |
128 | nsdata->vif.type == NL80211_IFTYPE_ADHOC) | |
129 | return -EBUSY; | |
130 | ||
131 | /* | |
132 | * The remaining checks are only performed for interfaces | |
133 | * with the same MAC address. | |
134 | */ | |
135 | if (compare_ether_addr(dev->dev_addr, ndev->dev_addr)) | |
136 | continue; | |
137 | ||
138 | /* | |
139 | * check whether it may have the same address | |
140 | */ | |
141 | if (!identical_mac_addr_allowed(sdata->vif.type, | |
142 | nsdata->vif.type)) | |
143 | return -ENOTUNIQ; | |
144 | ||
145 | /* | |
146 | * can only add VLANs to enabled APs | |
147 | */ | |
148 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN && | |
149 | nsdata->vif.type == NL80211_IFTYPE_AP) | |
150 | sdata->bss = &nsdata->u.ap; | |
151 | } | |
152 | } | |
153 | ||
154 | switch (sdata->vif.type) { | |
155 | case NL80211_IFTYPE_WDS: | |
156 | if (!is_valid_ether_addr(sdata->u.wds.remote_addr)) | |
157 | return -ENOLINK; | |
158 | break; | |
159 | case NL80211_IFTYPE_AP_VLAN: | |
160 | if (!sdata->bss) | |
161 | return -ENOLINK; | |
162 | list_add(&sdata->u.vlan.list, &sdata->bss->vlans); | |
163 | break; | |
164 | case NL80211_IFTYPE_AP: | |
165 | sdata->bss = &sdata->u.ap; | |
166 | break; | |
167 | case NL80211_IFTYPE_MESH_POINT: | |
168 | if (!ieee80211_vif_is_mesh(&sdata->vif)) | |
169 | break; | |
170 | /* mesh ifaces must set allmulti to forward mcast traffic */ | |
171 | atomic_inc(&local->iff_allmultis); | |
172 | break; | |
173 | case NL80211_IFTYPE_STATION: | |
174 | case NL80211_IFTYPE_MONITOR: | |
175 | case NL80211_IFTYPE_ADHOC: | |
176 | /* no special treatment */ | |
177 | break; | |
178 | case NL80211_IFTYPE_UNSPECIFIED: | |
2e161f78 | 179 | case NUM_NL80211_IFTYPES: |
0d143fe1 JB |
180 | /* cannot happen */ |
181 | WARN_ON(1); | |
182 | break; | |
183 | } | |
184 | ||
185 | if (local->open_count == 0) { | |
24487981 | 186 | res = drv_start(local); |
0d143fe1 JB |
187 | if (res) |
188 | goto err_del_bss; | |
4e6cbfd0 JL |
189 | if (local->ops->napi_poll) |
190 | napi_enable(&local->napi); | |
e8975581 JB |
191 | /* we're brought up, everything changes */ |
192 | hw_reconf_flags = ~0; | |
1f87f7d3 | 193 | ieee80211_led_radio(local, true); |
0d143fe1 JB |
194 | } |
195 | ||
196 | /* | |
bf533e0b JB |
197 | * Copy the hopefully now-present MAC address to |
198 | * this interface, if it has the special null one. | |
0d143fe1 | 199 | */ |
bf533e0b JB |
200 | if (is_zero_ether_addr(dev->dev_addr)) { |
201 | memcpy(dev->dev_addr, | |
202 | local->hw.wiphy->perm_addr, | |
203 | ETH_ALEN); | |
204 | memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN); | |
205 | ||
206 | if (!is_valid_ether_addr(dev->dev_addr)) { | |
207 | if (!local->open_count) | |
208 | drv_stop(local); | |
209 | return -EADDRNOTAVAIL; | |
0adc23f5 | 210 | } |
0d143fe1 JB |
211 | } |
212 | ||
0d143fe1 JB |
213 | switch (sdata->vif.type) { |
214 | case NL80211_IFTYPE_AP_VLAN: | |
215 | /* no need to tell driver */ | |
216 | break; | |
217 | case NL80211_IFTYPE_MONITOR: | |
218 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { | |
219 | local->cooked_mntrs++; | |
220 | break; | |
221 | } | |
222 | ||
223 | /* must be before the call to ieee80211_configure_filter */ | |
224 | local->monitors++; | |
e8975581 | 225 | if (local->monitors == 1) { |
0869aea0 JB |
226 | local->hw.conf.flags |= IEEE80211_CONF_MONITOR; |
227 | hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR; | |
e8975581 | 228 | } |
0d143fe1 JB |
229 | |
230 | if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) | |
231 | local->fif_fcsfail++; | |
232 | if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) | |
233 | local->fif_plcpfail++; | |
e3b90ca2 | 234 | if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) { |
0d143fe1 | 235 | local->fif_control++; |
e3b90ca2 IP |
236 | local->fif_pspoll++; |
237 | } | |
0d143fe1 JB |
238 | if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) |
239 | local->fif_other_bss++; | |
240 | ||
0d143fe1 | 241 | ieee80211_configure_filter(local); |
53e9b1de DG |
242 | |
243 | netif_carrier_on(dev); | |
0d143fe1 | 244 | break; |
0d143fe1 | 245 | default: |
1ed32e4f | 246 | res = drv_add_interface(local, &sdata->vif); |
0d143fe1 JB |
247 | if (res) |
248 | goto err_stop; | |
249 | ||
a3c9aa51 AY |
250 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
251 | local->fif_other_bss++; | |
a3c9aa51 | 252 | ieee80211_configure_filter(local); |
a3c9aa51 | 253 | |
0d143fe1 | 254 | ieee80211_start_mesh(sdata); |
e3b90ca2 IP |
255 | } else if (sdata->vif.type == NL80211_IFTYPE_AP) { |
256 | local->fif_pspoll++; | |
257 | ||
e3b90ca2 | 258 | ieee80211_configure_filter(local); |
a3c9aa51 | 259 | } |
e3b90ca2 | 260 | |
0d143fe1 JB |
261 | changed |= ieee80211_reset_erp_info(sdata); |
262 | ieee80211_bss_info_change_notify(sdata, changed); | |
0d143fe1 | 263 | |
7986cf95 | 264 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
0d143fe1 JB |
265 | netif_carrier_off(dev); |
266 | else | |
267 | netif_carrier_on(dev); | |
268 | } | |
269 | ||
270 | if (sdata->vif.type == NL80211_IFTYPE_WDS) { | |
271 | /* Create STA entry for the WDS peer */ | |
272 | sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr, | |
273 | GFP_KERNEL); | |
274 | if (!sta) { | |
275 | res = -ENOMEM; | |
276 | goto err_del_interface; | |
277 | } | |
278 | ||
279 | /* no locking required since STA is not live yet */ | |
280 | sta->flags |= WLAN_STA_AUTHORIZED; | |
281 | ||
282 | res = sta_info_insert(sta); | |
283 | if (res) { | |
284 | /* STA has been freed */ | |
285 | goto err_del_interface; | |
286 | } | |
287 | } | |
288 | ||
0d143fe1 JB |
289 | /* |
290 | * set_multicast_list will be invoked by the networking core | |
291 | * which will check whether any increments here were done in | |
292 | * error and sync them down to the hardware as filter flags. | |
293 | */ | |
294 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) | |
295 | atomic_inc(&local->iff_allmultis); | |
296 | ||
297 | if (sdata->flags & IEEE80211_SDATA_PROMISC) | |
298 | atomic_inc(&local->iff_promiscs); | |
299 | ||
7da7cc1d | 300 | mutex_lock(&local->mtx); |
5cff20e6 | 301 | hw_reconf_flags |= __ieee80211_recalc_idle(local); |
7da7cc1d | 302 | mutex_unlock(&local->mtx); |
5cff20e6 | 303 | |
0d143fe1 | 304 | local->open_count++; |
e8975581 JB |
305 | if (hw_reconf_flags) { |
306 | ieee80211_hw_config(local, hw_reconf_flags); | |
0d143fe1 JB |
307 | /* |
308 | * set default queue parameters so drivers don't | |
309 | * need to initialise the hardware if the hardware | |
310 | * doesn't start up with sane defaults | |
311 | */ | |
312 | ieee80211_set_wmm_default(sdata); | |
313 | } | |
314 | ||
10f644a4 | 315 | ieee80211_recalc_ps(local, -1); |
965bedad | 316 | |
8a5b33f5 | 317 | netif_tx_start_all_queues(dev); |
0d143fe1 JB |
318 | |
319 | return 0; | |
320 | err_del_interface: | |
1ed32e4f | 321 | drv_remove_interface(local, &sdata->vif); |
0d143fe1 | 322 | err_stop: |
24487981 JB |
323 | if (!local->open_count) |
324 | drv_stop(local); | |
0d143fe1 JB |
325 | err_del_bss: |
326 | sdata->bss = NULL; | |
327 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) | |
328 | list_del(&sdata->u.vlan.list); | |
329 | return res; | |
330 | } | |
331 | ||
332 | static int ieee80211_stop(struct net_device *dev) | |
333 | { | |
334 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
335 | struct ieee80211_local *local = sdata->local; | |
5061b0c2 JB |
336 | unsigned long flags; |
337 | struct sk_buff *skb, *tmp; | |
e8975581 | 338 | u32 hw_reconf_flags = 0; |
5061b0c2 | 339 | int i; |
0d143fe1 JB |
340 | |
341 | /* | |
342 | * Stop TX on this interface first. | |
343 | */ | |
8a5b33f5 | 344 | netif_tx_stop_all_queues(dev); |
0d143fe1 | 345 | |
af6b6374 JB |
346 | /* |
347 | * Purge work for this interface. | |
348 | */ | |
349 | ieee80211_work_purge(sdata); | |
350 | ||
0d143fe1 JB |
351 | /* |
352 | * Remove all stations associated with this interface. | |
353 | * | |
354 | * This must be done before calling ops->remove_interface() | |
355 | * because otherwise we can later invoke ops->sta_notify() | |
356 | * whenever the STAs are removed, and that invalidates driver | |
357 | * assumptions about always getting a vif pointer that is valid | |
358 | * (because if we remove a STA after ops->remove_interface() | |
359 | * the driver will have removed the vif info already!) | |
360 | * | |
b9dcf712 JB |
361 | * This is relevant only in AP, WDS and mesh modes, since in |
362 | * all other modes we've already removed all stations when | |
363 | * disconnecting etc. | |
0d143fe1 JB |
364 | */ |
365 | sta_info_flush(local, sdata); | |
366 | ||
367 | /* | |
368 | * Don't count this interface for promisc/allmulti while it | |
369 | * is down. dev_mc_unsync() will invoke set_multicast_list | |
370 | * on the master interface which will sync these down to the | |
371 | * hardware as filter flags. | |
372 | */ | |
373 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) | |
374 | atomic_dec(&local->iff_allmultis); | |
375 | ||
376 | if (sdata->flags & IEEE80211_SDATA_PROMISC) | |
377 | atomic_dec(&local->iff_promiscs); | |
378 | ||
e3b90ca2 IP |
379 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
380 | local->fif_pspoll--; | |
381 | ||
3b8d81e0 JB |
382 | netif_addr_lock_bh(dev); |
383 | spin_lock_bh(&local->filter_lock); | |
22bedad3 | 384 | __hw_addr_unsync(&local->mc_list, &dev->mc, dev->addr_len); |
3b8d81e0 JB |
385 | spin_unlock_bh(&local->filter_lock); |
386 | netif_addr_unlock_bh(dev); | |
387 | ||
3ac64bee JB |
388 | ieee80211_configure_filter(local); |
389 | ||
7cbf0ba5 VN |
390 | del_timer_sync(&local->dynamic_ps_timer); |
391 | cancel_work_sync(&local->dynamic_ps_enable_work); | |
0d143fe1 JB |
392 | |
393 | /* APs need special treatment */ | |
394 | if (sdata->vif.type == NL80211_IFTYPE_AP) { | |
57c9fff3 | 395 | struct ieee80211_sub_if_data *vlan, *tmpsdata; |
0d143fe1 JB |
396 | struct beacon_data *old_beacon = sdata->u.ap.beacon; |
397 | ||
b9dcf712 JB |
398 | /* sdata_running will return false, so this will disable */ |
399 | ieee80211_bss_info_change_notify(sdata, | |
400 | BSS_CHANGED_BEACON_ENABLED); | |
401 | ||
0d143fe1 JB |
402 | /* remove beacon */ |
403 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); | |
404 | synchronize_rcu(); | |
405 | kfree(old_beacon); | |
406 | ||
b9dcf712 JB |
407 | /* free all potentially still buffered bcast frames */ |
408 | while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) { | |
409 | local->total_ps_buffered--; | |
410 | dev_kfree_skb(skb); | |
411 | } | |
412 | ||
0d143fe1 | 413 | /* down all dependent devices, that is VLANs */ |
57c9fff3 | 414 | list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans, |
0d143fe1 JB |
415 | u.vlan.list) |
416 | dev_close(vlan->dev); | |
417 | WARN_ON(!list_empty(&sdata->u.ap.vlans)); | |
418 | } | |
419 | ||
420 | local->open_count--; | |
421 | ||
422 | switch (sdata->vif.type) { | |
423 | case NL80211_IFTYPE_AP_VLAN: | |
424 | list_del(&sdata->u.vlan.list); | |
425 | /* no need to tell driver */ | |
426 | break; | |
427 | case NL80211_IFTYPE_MONITOR: | |
428 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { | |
429 | local->cooked_mntrs--; | |
430 | break; | |
431 | } | |
432 | ||
433 | local->monitors--; | |
e8975581 | 434 | if (local->monitors == 0) { |
0869aea0 JB |
435 | local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR; |
436 | hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR; | |
e8975581 | 437 | } |
0d143fe1 JB |
438 | |
439 | if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) | |
440 | local->fif_fcsfail--; | |
441 | if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) | |
442 | local->fif_plcpfail--; | |
e3b90ca2 IP |
443 | if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) { |
444 | local->fif_pspoll--; | |
0d143fe1 | 445 | local->fif_control--; |
e3b90ca2 | 446 | } |
0d143fe1 JB |
447 | if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) |
448 | local->fif_other_bss--; | |
449 | ||
0d143fe1 | 450 | ieee80211_configure_filter(local); |
0d143fe1 | 451 | break; |
0d143fe1 JB |
452 | case NL80211_IFTYPE_MESH_POINT: |
453 | if (ieee80211_vif_is_mesh(&sdata->vif)) { | |
a3c9aa51 AY |
454 | /* other_bss and allmulti are always set on mesh |
455 | * ifaces */ | |
456 | local->fif_other_bss--; | |
0d143fe1 | 457 | atomic_dec(&local->iff_allmultis); |
a3c9aa51 | 458 | |
a3c9aa51 | 459 | ieee80211_configure_filter(local); |
a3c9aa51 | 460 | |
0d143fe1 JB |
461 | ieee80211_stop_mesh(sdata); |
462 | } | |
463 | /* fall through */ | |
464 | default: | |
c1475ca9 | 465 | flush_work(&sdata->work); |
35f20c14 JB |
466 | /* |
467 | * When we get here, the interface is marked down. | |
468 | * Call synchronize_rcu() to wait for the RX path | |
469 | * should it be using the interface and enqueuing | |
470 | * frames at this very time on another CPU. | |
471 | */ | |
472 | synchronize_rcu(); | |
473 | skb_queue_purge(&sdata->skb_queue); | |
474 | ||
15db0b7f JB |
475 | if (local->scan_sdata == sdata) |
476 | ieee80211_scan_cancel(local); | |
0d143fe1 | 477 | |
97af7432 | 478 | /* |
b9dcf712 JB |
479 | * Disable beaconing here for mesh only, AP and IBSS |
480 | * are already taken care of. | |
97af7432 | 481 | */ |
b9dcf712 | 482 | if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT) |
97af7432 BC |
483 | ieee80211_bss_info_change_notify(sdata, |
484 | BSS_CHANGED_BEACON_ENABLED); | |
97af7432 | 485 | |
b9dcf712 JB |
486 | /* |
487 | * Free all remaining keys, there shouldn't be any, | |
488 | * except maybe group keys in AP more or WDS? | |
489 | */ | |
ad0e2b5a | 490 | ieee80211_free_keys(sdata); |
b9dcf712 | 491 | |
1ed32e4f | 492 | drv_remove_interface(local, &sdata->vif); |
0d143fe1 JB |
493 | } |
494 | ||
495 | sdata->bss = NULL; | |
496 | ||
7da7cc1d | 497 | mutex_lock(&local->mtx); |
5cff20e6 | 498 | hw_reconf_flags |= __ieee80211_recalc_idle(local); |
7da7cc1d | 499 | mutex_unlock(&local->mtx); |
5cff20e6 JB |
500 | |
501 | ieee80211_recalc_ps(local, -1); | |
502 | ||
0d143fe1 | 503 | if (local->open_count == 0) { |
4e6cbfd0 JL |
504 | if (local->ops->napi_poll) |
505 | napi_disable(&local->napi); | |
ea77f12f | 506 | ieee80211_clear_tx_pending(local); |
84f6a01c | 507 | ieee80211_stop_device(local); |
0d143fe1 | 508 | |
e8975581 JB |
509 | /* no reconfiguring after stop! */ |
510 | hw_reconf_flags = 0; | |
0d143fe1 JB |
511 | } |
512 | ||
e8975581 JB |
513 | /* do after stop to avoid reconfiguring when we stop anyway */ |
514 | if (hw_reconf_flags) | |
515 | ieee80211_hw_config(local, hw_reconf_flags); | |
516 | ||
5061b0c2 JB |
517 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
518 | for (i = 0; i < IEEE80211_MAX_QUEUES; i++) { | |
519 | skb_queue_walk_safe(&local->pending[i], skb, tmp) { | |
520 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
521 | if (info->control.vif == &sdata->vif) { | |
522 | __skb_unlink(skb, &local->pending[i]); | |
523 | dev_kfree_skb_irq(skb); | |
524 | } | |
525 | } | |
526 | } | |
527 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); | |
528 | ||
0d143fe1 JB |
529 | return 0; |
530 | } | |
531 | ||
532 | static void ieee80211_set_multicast_list(struct net_device *dev) | |
533 | { | |
0d143fe1 | 534 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
b4a4bf5d | 535 | struct ieee80211_local *local = sdata->local; |
0d143fe1 JB |
536 | int allmulti, promisc, sdata_allmulti, sdata_promisc; |
537 | ||
538 | allmulti = !!(dev->flags & IFF_ALLMULTI); | |
539 | promisc = !!(dev->flags & IFF_PROMISC); | |
540 | sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI); | |
541 | sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC); | |
542 | ||
543 | if (allmulti != sdata_allmulti) { | |
544 | if (dev->flags & IFF_ALLMULTI) | |
545 | atomic_inc(&local->iff_allmultis); | |
546 | else | |
547 | atomic_dec(&local->iff_allmultis); | |
548 | sdata->flags ^= IEEE80211_SDATA_ALLMULTI; | |
549 | } | |
550 | ||
551 | if (promisc != sdata_promisc) { | |
552 | if (dev->flags & IFF_PROMISC) | |
553 | atomic_inc(&local->iff_promiscs); | |
554 | else | |
555 | atomic_dec(&local->iff_promiscs); | |
556 | sdata->flags ^= IEEE80211_SDATA_PROMISC; | |
557 | } | |
3b8d81e0 | 558 | spin_lock_bh(&local->filter_lock); |
22bedad3 | 559 | __hw_addr_sync(&local->mc_list, &dev->mc, dev->addr_len); |
3b8d81e0 | 560 | spin_unlock_bh(&local->filter_lock); |
3ac64bee | 561 | ieee80211_queue_work(&local->hw, &local->reconfig_filter); |
0d143fe1 JB |
562 | } |
563 | ||
75636525 JB |
564 | /* |
565 | * Called when the netdev is removed or, by the code below, before | |
566 | * the interface type changes. | |
567 | */ | |
568 | static void ieee80211_teardown_sdata(struct net_device *dev) | |
f0706e82 | 569 | { |
75636525 JB |
570 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
571 | struct ieee80211_local *local = sdata->local; | |
75636525 | 572 | int flushed; |
f0706e82 JB |
573 | int i; |
574 | ||
75636525 JB |
575 | /* free extra data */ |
576 | ieee80211_free_keys(sdata); | |
577 | ||
aee14ceb JM |
578 | ieee80211_debugfs_remove_netdev(sdata); |
579 | ||
f0706e82 | 580 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) |
75636525 JB |
581 | __skb_queue_purge(&sdata->fragments[i].skb_list); |
582 | sdata->fragment_next = 0; | |
11a843b7 | 583 | |
b9dcf712 JB |
584 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
585 | mesh_rmc_free(sdata); | |
75636525 JB |
586 | |
587 | flushed = sta_info_flush(local, sdata); | |
588 | WARN_ON(flushed); | |
f0706e82 JB |
589 | } |
590 | ||
cf0277e7 JB |
591 | static u16 ieee80211_netdev_select_queue(struct net_device *dev, |
592 | struct sk_buff *skb) | |
593 | { | |
594 | return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb); | |
595 | } | |
596 | ||
587e729e JB |
597 | static const struct net_device_ops ieee80211_dataif_ops = { |
598 | .ndo_open = ieee80211_open, | |
599 | .ndo_stop = ieee80211_stop, | |
600 | .ndo_uninit = ieee80211_teardown_sdata, | |
601 | .ndo_start_xmit = ieee80211_subif_start_xmit, | |
602 | .ndo_set_multicast_list = ieee80211_set_multicast_list, | |
603 | .ndo_change_mtu = ieee80211_change_mtu, | |
47846c9b | 604 | .ndo_set_mac_address = ieee80211_change_mac, |
cf0277e7 | 605 | .ndo_select_queue = ieee80211_netdev_select_queue, |
587e729e JB |
606 | }; |
607 | ||
cf0277e7 JB |
608 | static u16 ieee80211_monitor_select_queue(struct net_device *dev, |
609 | struct sk_buff *skb) | |
610 | { | |
611 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
612 | struct ieee80211_local *local = sdata->local; | |
613 | struct ieee80211_hdr *hdr; | |
614 | struct ieee80211_radiotap_header *rtap = (void *)skb->data; | |
193e70ef | 615 | u8 *p; |
cf0277e7 JB |
616 | |
617 | if (local->hw.queues < 4) | |
618 | return 0; | |
619 | ||
620 | if (skb->len < 4 || | |
b49bb574 | 621 | skb->len < le16_to_cpu(rtap->it_len) + 2 /* frame control */) |
cf0277e7 JB |
622 | return 0; /* doesn't matter, frame will be dropped */ |
623 | ||
b49bb574 | 624 | hdr = (void *)((u8 *)skb->data + le16_to_cpu(rtap->it_len)); |
cf0277e7 | 625 | |
861a57cd | 626 | if (!ieee80211_is_data(hdr->frame_control)) { |
cf0277e7 JB |
627 | skb->priority = 7; |
628 | return ieee802_1d_to_ac[skb->priority]; | |
629 | } | |
861a57cd FF |
630 | if (!ieee80211_is_data_qos(hdr->frame_control)) { |
631 | skb->priority = 0; | |
632 | return ieee802_1d_to_ac[skb->priority]; | |
633 | } | |
cf0277e7 | 634 | |
193e70ef FF |
635 | p = ieee80211_get_qos_ctl(hdr); |
636 | skb->priority = *p & IEEE80211_QOS_CTL_TAG1D_MASK; | |
637 | ||
cf0277e7 JB |
638 | return ieee80211_downgrade_queue(local, skb); |
639 | } | |
640 | ||
587e729e JB |
641 | static const struct net_device_ops ieee80211_monitorif_ops = { |
642 | .ndo_open = ieee80211_open, | |
643 | .ndo_stop = ieee80211_stop, | |
644 | .ndo_uninit = ieee80211_teardown_sdata, | |
645 | .ndo_start_xmit = ieee80211_monitor_start_xmit, | |
646 | .ndo_set_multicast_list = ieee80211_set_multicast_list, | |
647 | .ndo_change_mtu = ieee80211_change_mtu, | |
648 | .ndo_set_mac_address = eth_mac_addr, | |
cf0277e7 | 649 | .ndo_select_queue = ieee80211_monitor_select_queue, |
587e729e JB |
650 | }; |
651 | ||
652 | static void ieee80211_if_setup(struct net_device *dev) | |
653 | { | |
654 | ether_setup(dev); | |
655 | dev->netdev_ops = &ieee80211_dataif_ops; | |
587e729e JB |
656 | dev->destructor = free_netdev; |
657 | } | |
658 | ||
1fa57d01 JB |
659 | static void ieee80211_iface_work(struct work_struct *work) |
660 | { | |
661 | struct ieee80211_sub_if_data *sdata = | |
662 | container_of(work, struct ieee80211_sub_if_data, work); | |
663 | struct ieee80211_local *local = sdata->local; | |
664 | struct sk_buff *skb; | |
344eec67 | 665 | struct sta_info *sta; |
c1475ca9 | 666 | struct ieee80211_ra_tid *ra_tid; |
1fa57d01 JB |
667 | |
668 | if (!ieee80211_sdata_running(sdata)) | |
669 | return; | |
670 | ||
671 | if (local->scanning) | |
672 | return; | |
673 | ||
674 | /* | |
675 | * ieee80211_queue_work() should have picked up most cases, | |
676 | * here we'll pick the rest. | |
677 | */ | |
678 | if (WARN(local->suspended, | |
679 | "interface work scheduled while going to suspend\n")) | |
680 | return; | |
681 | ||
682 | /* first process frames */ | |
683 | while ((skb = skb_dequeue(&sdata->skb_queue))) { | |
bed7ee6e JB |
684 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
685 | ||
c1475ca9 JB |
686 | if (skb->pkt_type == IEEE80211_SDATA_QUEUE_AGG_START) { |
687 | ra_tid = (void *)&skb->cb; | |
688 | ieee80211_start_tx_ba_cb(&sdata->vif, ra_tid->ra, | |
689 | ra_tid->tid); | |
690 | } else if (skb->pkt_type == IEEE80211_SDATA_QUEUE_AGG_STOP) { | |
691 | ra_tid = (void *)&skb->cb; | |
692 | ieee80211_stop_tx_ba_cb(&sdata->vif, ra_tid->ra, | |
693 | ra_tid->tid); | |
694 | } else if (ieee80211_is_action(mgmt->frame_control) && | |
695 | mgmt->u.action.category == WLAN_CATEGORY_BACK) { | |
bed7ee6e | 696 | int len = skb->len; |
bed7ee6e | 697 | |
a93e3644 | 698 | mutex_lock(&local->sta_mtx); |
875ae5f6 | 699 | sta = sta_info_get_bss(sdata, mgmt->sa); |
bed7ee6e JB |
700 | if (sta) { |
701 | switch (mgmt->u.action.u.addba_req.action_code) { | |
702 | case WLAN_ACTION_ADDBA_REQ: | |
703 | ieee80211_process_addba_request( | |
704 | local, sta, mgmt, len); | |
705 | break; | |
706 | case WLAN_ACTION_ADDBA_RESP: | |
707 | ieee80211_process_addba_resp(local, sta, | |
708 | mgmt, len); | |
709 | break; | |
710 | case WLAN_ACTION_DELBA: | |
711 | ieee80211_process_delba(sdata, sta, | |
712 | mgmt, len); | |
713 | break; | |
714 | default: | |
715 | WARN_ON(1); | |
716 | break; | |
717 | } | |
718 | } | |
a93e3644 | 719 | mutex_unlock(&local->sta_mtx); |
344eec67 JB |
720 | } else if (ieee80211_is_data_qos(mgmt->frame_control)) { |
721 | struct ieee80211_hdr *hdr = (void *)mgmt; | |
722 | /* | |
723 | * So the frame isn't mgmt, but frame_control | |
724 | * is at the right place anyway, of course, so | |
725 | * the if statement is correct. | |
726 | * | |
727 | * Warn if we have other data frame types here, | |
728 | * they must not get here. | |
729 | */ | |
730 | WARN_ON(hdr->frame_control & | |
731 | cpu_to_le16(IEEE80211_STYPE_NULLFUNC)); | |
732 | WARN_ON(!(hdr->seq_ctrl & | |
733 | cpu_to_le16(IEEE80211_SCTL_FRAG))); | |
734 | /* | |
735 | * This was a fragment of a frame, received while | |
736 | * a block-ack session was active. That cannot be | |
737 | * right, so terminate the session. | |
738 | */ | |
a93e3644 | 739 | mutex_lock(&local->sta_mtx); |
875ae5f6 | 740 | sta = sta_info_get_bss(sdata, mgmt->sa); |
344eec67 JB |
741 | if (sta) { |
742 | u16 tid = *ieee80211_get_qos_ctl(hdr) & | |
743 | IEEE80211_QOS_CTL_TID_MASK; | |
744 | ||
745 | __ieee80211_stop_rx_ba_session( | |
746 | sta, tid, WLAN_BACK_RECIPIENT, | |
747 | WLAN_REASON_QSTA_REQUIRE_SETUP); | |
748 | } | |
a93e3644 | 749 | mutex_unlock(&local->sta_mtx); |
bed7ee6e | 750 | } else switch (sdata->vif.type) { |
1fa57d01 JB |
751 | case NL80211_IFTYPE_STATION: |
752 | ieee80211_sta_rx_queued_mgmt(sdata, skb); | |
753 | break; | |
754 | case NL80211_IFTYPE_ADHOC: | |
755 | ieee80211_ibss_rx_queued_mgmt(sdata, skb); | |
756 | break; | |
757 | case NL80211_IFTYPE_MESH_POINT: | |
758 | if (!ieee80211_vif_is_mesh(&sdata->vif)) | |
759 | break; | |
760 | ieee80211_mesh_rx_queued_mgmt(sdata, skb); | |
761 | break; | |
762 | default: | |
763 | WARN(1, "frame for unexpected interface type"); | |
1fa57d01 JB |
764 | break; |
765 | } | |
36b3a628 JB |
766 | |
767 | kfree_skb(skb); | |
1fa57d01 JB |
768 | } |
769 | ||
770 | /* then other type-dependent work */ | |
771 | switch (sdata->vif.type) { | |
772 | case NL80211_IFTYPE_STATION: | |
773 | ieee80211_sta_work(sdata); | |
774 | break; | |
775 | case NL80211_IFTYPE_ADHOC: | |
776 | ieee80211_ibss_work(sdata); | |
777 | break; | |
778 | case NL80211_IFTYPE_MESH_POINT: | |
779 | if (!ieee80211_vif_is_mesh(&sdata->vif)) | |
780 | break; | |
781 | ieee80211_mesh_work(sdata); | |
782 | break; | |
783 | default: | |
784 | break; | |
785 | } | |
786 | } | |
787 | ||
788 | ||
75636525 JB |
789 | /* |
790 | * Helper function to initialise an interface to a specific type. | |
791 | */ | |
792 | static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata, | |
05c914fe | 793 | enum nl80211_iftype type) |
f0706e82 | 794 | { |
75636525 JB |
795 | /* clear type-dependent union */ |
796 | memset(&sdata->u, 0, sizeof(sdata->u)); | |
797 | ||
798 | /* and set some type-dependent values */ | |
799 | sdata->vif.type = type; | |
587e729e | 800 | sdata->dev->netdev_ops = &ieee80211_dataif_ops; |
60719ffd | 801 | sdata->wdev.iftype = type; |
75636525 | 802 | |
a621fa4d JB |
803 | sdata->control_port_protocol = cpu_to_be16(ETH_P_PAE); |
804 | sdata->control_port_no_encrypt = false; | |
805 | ||
75636525 JB |
806 | /* only monitor differs */ |
807 | sdata->dev->type = ARPHRD_ETHER; | |
808 | ||
35f20c14 | 809 | skb_queue_head_init(&sdata->skb_queue); |
1fa57d01 | 810 | INIT_WORK(&sdata->work, ieee80211_iface_work); |
35f20c14 | 811 | |
75636525 | 812 | switch (type) { |
05c914fe | 813 | case NL80211_IFTYPE_AP: |
75636525 JB |
814 | skb_queue_head_init(&sdata->u.ap.ps_bc_buf); |
815 | INIT_LIST_HEAD(&sdata->u.ap.vlans); | |
816 | break; | |
05c914fe | 817 | case NL80211_IFTYPE_STATION: |
9c6bd790 | 818 | ieee80211_sta_setup_sdata(sdata); |
472dbc45 | 819 | break; |
46900298 JB |
820 | case NL80211_IFTYPE_ADHOC: |
821 | ieee80211_ibss_setup_sdata(sdata); | |
822 | break; | |
05c914fe | 823 | case NL80211_IFTYPE_MESH_POINT: |
75636525 JB |
824 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
825 | ieee80211_mesh_init_sdata(sdata); | |
826 | break; | |
05c914fe | 827 | case NL80211_IFTYPE_MONITOR: |
75636525 | 828 | sdata->dev->type = ARPHRD_IEEE80211_RADIOTAP; |
587e729e | 829 | sdata->dev->netdev_ops = &ieee80211_monitorif_ops; |
75636525 JB |
830 | sdata->u.mntr_flags = MONITOR_FLAG_CONTROL | |
831 | MONITOR_FLAG_OTHER_BSS; | |
832 | break; | |
05c914fe JB |
833 | case NL80211_IFTYPE_WDS: |
834 | case NL80211_IFTYPE_AP_VLAN: | |
75636525 | 835 | break; |
05c914fe | 836 | case NL80211_IFTYPE_UNSPECIFIED: |
2e161f78 | 837 | case NUM_NL80211_IFTYPES: |
75636525 JB |
838 | BUG(); |
839 | break; | |
840 | } | |
841 | ||
842 | ieee80211_debugfs_add_netdev(sdata); | |
843 | } | |
844 | ||
f3947e2d | 845 | int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata, |
05c914fe | 846 | enum nl80211_iftype type) |
75636525 | 847 | { |
f3947e2d JB |
848 | ASSERT_RTNL(); |
849 | ||
850 | if (type == sdata->vif.type) | |
851 | return 0; | |
852 | ||
e60c7744 | 853 | /* Setting ad-hoc mode on non-IBSS channel is not supported. */ |
dcebf45c PR |
854 | if (sdata->local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS && |
855 | type == NL80211_IFTYPE_ADHOC) | |
e60c7744 JB |
856 | return -EOPNOTSUPP; |
857 | ||
f3947e2d JB |
858 | /* |
859 | * We could, here, on changes between IBSS/STA/MESH modes, | |
860 | * invoke an MLME function instead that disassociates etc. | |
861 | * and goes into the requested mode. | |
862 | */ | |
863 | ||
9607e6b6 | 864 | if (ieee80211_sdata_running(sdata)) |
f3947e2d JB |
865 | return -EBUSY; |
866 | ||
75636525 JB |
867 | /* Purge and reset type-dependent state. */ |
868 | ieee80211_teardown_sdata(sdata->dev); | |
869 | ieee80211_setup_sdata(sdata, type); | |
870 | ||
871 | /* reset some values that shouldn't be kept across type changes */ | |
bda3933a | 872 | sdata->vif.bss_conf.basic_rates = |
96dd22ac JB |
873 | ieee80211_mandatory_rates(sdata->local, |
874 | sdata->local->hw.conf.channel->band); | |
75636525 | 875 | sdata->drop_unencrypted = 0; |
9bc383de JB |
876 | if (type == NL80211_IFTYPE_STATION) |
877 | sdata->u.mgd.use_4addr = false; | |
f3947e2d JB |
878 | |
879 | return 0; | |
f0706e82 JB |
880 | } |
881 | ||
fa9029f8 JB |
882 | static void ieee80211_assign_perm_addr(struct ieee80211_local *local, |
883 | struct net_device *dev, | |
884 | enum nl80211_iftype type) | |
885 | { | |
886 | struct ieee80211_sub_if_data *sdata; | |
887 | u64 mask, start, addr, val, inc; | |
888 | u8 *m; | |
889 | u8 tmp_addr[ETH_ALEN]; | |
890 | int i; | |
891 | ||
892 | /* default ... something at least */ | |
893 | memcpy(dev->perm_addr, local->hw.wiphy->perm_addr, ETH_ALEN); | |
894 | ||
895 | if (is_zero_ether_addr(local->hw.wiphy->addr_mask) && | |
896 | local->hw.wiphy->n_addresses <= 1) | |
897 | return; | |
898 | ||
899 | ||
900 | mutex_lock(&local->iflist_mtx); | |
901 | ||
902 | switch (type) { | |
903 | case NL80211_IFTYPE_MONITOR: | |
904 | /* doesn't matter */ | |
905 | break; | |
906 | case NL80211_IFTYPE_WDS: | |
907 | case NL80211_IFTYPE_AP_VLAN: | |
908 | /* match up with an AP interface */ | |
909 | list_for_each_entry(sdata, &local->interfaces, list) { | |
910 | if (sdata->vif.type != NL80211_IFTYPE_AP) | |
911 | continue; | |
912 | memcpy(dev->perm_addr, sdata->vif.addr, ETH_ALEN); | |
913 | break; | |
914 | } | |
915 | /* keep default if no AP interface present */ | |
916 | break; | |
917 | default: | |
918 | /* assign a new address if possible -- try n_addresses first */ | |
919 | for (i = 0; i < local->hw.wiphy->n_addresses; i++) { | |
920 | bool used = false; | |
921 | ||
922 | list_for_each_entry(sdata, &local->interfaces, list) { | |
923 | if (memcmp(local->hw.wiphy->addresses[i].addr, | |
924 | sdata->vif.addr, ETH_ALEN) == 0) { | |
925 | used = true; | |
926 | break; | |
927 | } | |
928 | } | |
929 | ||
930 | if (!used) { | |
931 | memcpy(dev->perm_addr, | |
932 | local->hw.wiphy->addresses[i].addr, | |
933 | ETH_ALEN); | |
934 | break; | |
935 | } | |
936 | } | |
937 | ||
938 | /* try mask if available */ | |
939 | if (is_zero_ether_addr(local->hw.wiphy->addr_mask)) | |
940 | break; | |
941 | ||
942 | m = local->hw.wiphy->addr_mask; | |
943 | mask = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) | | |
944 | ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) | | |
945 | ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8); | |
946 | ||
947 | if (__ffs64(mask) + hweight64(mask) != fls64(mask)) { | |
948 | /* not a contiguous mask ... not handled now! */ | |
949 | printk(KERN_DEBUG "not contiguous\n"); | |
950 | break; | |
951 | } | |
952 | ||
953 | m = local->hw.wiphy->perm_addr; | |
954 | start = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) | | |
955 | ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) | | |
956 | ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8); | |
957 | ||
958 | inc = 1ULL<<__ffs64(mask); | |
959 | val = (start & mask); | |
960 | addr = (start & ~mask) | (val & mask); | |
961 | do { | |
962 | bool used = false; | |
963 | ||
964 | tmp_addr[5] = addr >> 0*8; | |
965 | tmp_addr[4] = addr >> 1*8; | |
966 | tmp_addr[3] = addr >> 2*8; | |
967 | tmp_addr[2] = addr >> 3*8; | |
968 | tmp_addr[1] = addr >> 4*8; | |
969 | tmp_addr[0] = addr >> 5*8; | |
970 | ||
971 | val += inc; | |
972 | ||
973 | list_for_each_entry(sdata, &local->interfaces, list) { | |
974 | if (memcmp(tmp_addr, sdata->vif.addr, | |
975 | ETH_ALEN) == 0) { | |
976 | used = true; | |
977 | break; | |
978 | } | |
979 | } | |
980 | ||
981 | if (!used) { | |
982 | memcpy(dev->perm_addr, tmp_addr, ETH_ALEN); | |
983 | break; | |
984 | } | |
985 | addr = (start & ~mask) | (val & mask); | |
986 | } while (addr != start); | |
987 | ||
988 | break; | |
989 | } | |
990 | ||
991 | mutex_unlock(&local->iflist_mtx); | |
992 | } | |
993 | ||
3e122be0 | 994 | int ieee80211_if_add(struct ieee80211_local *local, const char *name, |
05c914fe | 995 | struct net_device **new_dev, enum nl80211_iftype type, |
ee385855 | 996 | struct vif_params *params) |
f0706e82 JB |
997 | { |
998 | struct net_device *ndev; | |
f0706e82 | 999 | struct ieee80211_sub_if_data *sdata = NULL; |
75636525 | 1000 | int ret, i; |
f0706e82 JB |
1001 | |
1002 | ASSERT_RTNL(); | |
75636525 | 1003 | |
cf0277e7 JB |
1004 | ndev = alloc_netdev_mq(sizeof(*sdata) + local->hw.vif_data_size, |
1005 | name, ieee80211_if_setup, local->hw.queues); | |
f0706e82 JB |
1006 | if (!ndev) |
1007 | return -ENOMEM; | |
a272a720 | 1008 | dev_net_set(ndev, wiphy_net(local->hw.wiphy)); |
f0706e82 | 1009 | |
f3994ece JB |
1010 | ndev->needed_headroom = local->tx_headroom + |
1011 | 4*6 /* four MAC addresses */ | |
1012 | + 2 + 2 + 2 + 2 /* ctl, dur, seq, qos */ | |
1013 | + 6 /* mesh */ | |
1014 | + 8 /* rfc1042/bridge tunnel */ | |
1015 | - ETH_HLEN /* ethernet hard_header_len */ | |
1016 | + IEEE80211_ENCRYPT_HEADROOM; | |
1017 | ndev->needed_tailroom = IEEE80211_ENCRYPT_TAILROOM; | |
1018 | ||
f0706e82 JB |
1019 | ret = dev_alloc_name(ndev, ndev->name); |
1020 | if (ret < 0) | |
1021 | goto fail; | |
1022 | ||
fa9029f8 JB |
1023 | ieee80211_assign_perm_addr(local, ndev, type); |
1024 | memcpy(ndev->dev_addr, ndev->perm_addr, ETH_ALEN); | |
f0706e82 JB |
1025 | SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy)); |
1026 | ||
3e122be0 JB |
1027 | /* don't use IEEE80211_DEV_TO_SUB_IF because it checks too much */ |
1028 | sdata = netdev_priv(ndev); | |
f0706e82 | 1029 | ndev->ieee80211_ptr = &sdata->wdev; |
47846c9b JB |
1030 | memcpy(sdata->vif.addr, ndev->dev_addr, ETH_ALEN); |
1031 | memcpy(sdata->name, ndev->name, IFNAMSIZ); | |
75636525 JB |
1032 | |
1033 | /* initialise type-independent data */ | |
f0706e82 | 1034 | sdata->wdev.wiphy = local->hw.wiphy; |
f0706e82 | 1035 | sdata->local = local; |
75636525 | 1036 | sdata->dev = ndev; |
68542962 JO |
1037 | #ifdef CONFIG_INET |
1038 | sdata->arp_filter_state = true; | |
1039 | #endif | |
75636525 JB |
1040 | |
1041 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) | |
1042 | skb_queue_head_init(&sdata->fragments[i].skb_list); | |
1043 | ||
1044 | INIT_LIST_HEAD(&sdata->key_list); | |
1045 | ||
37eb0b16 JM |
1046 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
1047 | struct ieee80211_supported_band *sband; | |
1048 | sband = local->hw.wiphy->bands[i]; | |
1049 | sdata->rc_rateidx_mask[i] = | |
1050 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
1051 | } | |
75636525 JB |
1052 | |
1053 | /* setup type-dependent data */ | |
1054 | ieee80211_setup_sdata(sdata, type); | |
f0706e82 | 1055 | |
9bc383de JB |
1056 | if (params) { |
1057 | ndev->ieee80211_ptr->use_4addr = params->use_4addr; | |
1058 | if (type == NL80211_IFTYPE_STATION) | |
1059 | sdata->u.mgd.use_4addr = params->use_4addr; | |
1060 | } | |
1061 | ||
f0706e82 JB |
1062 | ret = register_netdevice(ndev); |
1063 | if (ret) | |
1064 | goto fail; | |
1065 | ||
902acc78 JB |
1066 | if (ieee80211_vif_is_mesh(&sdata->vif) && |
1067 | params && params->mesh_id_len) | |
472dbc45 JB |
1068 | ieee80211_sdata_set_mesh_id(sdata, |
1069 | params->mesh_id_len, | |
1070 | params->mesh_id); | |
ee385855 | 1071 | |
c771c9d8 | 1072 | mutex_lock(&local->iflist_mtx); |
79010420 | 1073 | list_add_tail_rcu(&sdata->list, &local->interfaces); |
c771c9d8 | 1074 | mutex_unlock(&local->iflist_mtx); |
79010420 | 1075 | |
f0706e82 JB |
1076 | if (new_dev) |
1077 | *new_dev = ndev; | |
f0706e82 | 1078 | |
f0706e82 JB |
1079 | return 0; |
1080 | ||
75636525 | 1081 | fail: |
f0706e82 JB |
1082 | free_netdev(ndev); |
1083 | return ret; | |
1084 | } | |
1085 | ||
f698d856 | 1086 | void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata) |
f0706e82 | 1087 | { |
f0706e82 | 1088 | ASSERT_RTNL(); |
11a843b7 | 1089 | |
c771c9d8 | 1090 | mutex_lock(&sdata->local->iflist_mtx); |
75636525 | 1091 | list_del_rcu(&sdata->list); |
c771c9d8 JB |
1092 | mutex_unlock(&sdata->local->iflist_mtx); |
1093 | ||
75636525 | 1094 | synchronize_rcu(); |
f698d856 | 1095 | unregister_netdevice(sdata->dev); |
f0706e82 JB |
1096 | } |
1097 | ||
75636525 JB |
1098 | /* |
1099 | * Remove all interfaces, may only be called at hardware unregistration | |
1100 | * time because it doesn't do RCU-safe list removals. | |
1101 | */ | |
1102 | void ieee80211_remove_interfaces(struct ieee80211_local *local) | |
f0706e82 | 1103 | { |
75636525 | 1104 | struct ieee80211_sub_if_data *sdata, *tmp; |
efe117ab | 1105 | LIST_HEAD(unreg_list); |
f0706e82 JB |
1106 | |
1107 | ASSERT_RTNL(); | |
1108 | ||
efe117ab | 1109 | mutex_lock(&local->iflist_mtx); |
75636525 JB |
1110 | list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) { |
1111 | list_del(&sdata->list); | |
c771c9d8 | 1112 | |
efe117ab | 1113 | unregister_netdevice_queue(sdata->dev, &unreg_list); |
f0706e82 | 1114 | } |
efe117ab ED |
1115 | mutex_unlock(&local->iflist_mtx); |
1116 | unregister_netdevice_many(&unreg_list); | |
f0706e82 | 1117 | } |
5cff20e6 JB |
1118 | |
1119 | static u32 ieee80211_idle_off(struct ieee80211_local *local, | |
1120 | const char *reason) | |
1121 | { | |
1122 | if (!(local->hw.conf.flags & IEEE80211_CONF_IDLE)) | |
1123 | return 0; | |
1124 | ||
1125 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | |
0fb9a9ec | 1126 | wiphy_debug(local->hw.wiphy, "device no longer idle - %s\n", reason); |
5cff20e6 JB |
1127 | #endif |
1128 | ||
1129 | local->hw.conf.flags &= ~IEEE80211_CONF_IDLE; | |
1130 | return IEEE80211_CONF_CHANGE_IDLE; | |
1131 | } | |
1132 | ||
1133 | static u32 ieee80211_idle_on(struct ieee80211_local *local) | |
1134 | { | |
1135 | if (local->hw.conf.flags & IEEE80211_CONF_IDLE) | |
1136 | return 0; | |
1137 | ||
1138 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | |
0fb9a9ec | 1139 | wiphy_debug(local->hw.wiphy, "device now idle\n"); |
5cff20e6 JB |
1140 | #endif |
1141 | ||
a80f7c0b JB |
1142 | drv_flush(local, false); |
1143 | ||
5cff20e6 JB |
1144 | local->hw.conf.flags |= IEEE80211_CONF_IDLE; |
1145 | return IEEE80211_CONF_CHANGE_IDLE; | |
1146 | } | |
1147 | ||
1148 | u32 __ieee80211_recalc_idle(struct ieee80211_local *local) | |
1149 | { | |
1150 | struct ieee80211_sub_if_data *sdata; | |
1151 | int count = 0; | |
7da7cc1d JB |
1152 | bool working = false, scanning = false; |
1153 | struct ieee80211_work *wk; | |
5cff20e6 | 1154 | |
7da7cc1d JB |
1155 | #ifdef CONFIG_PROVE_LOCKING |
1156 | WARN_ON(debug_locks && !lockdep_rtnl_is_held() && | |
1157 | !lockdep_is_held(&local->iflist_mtx)); | |
1158 | #endif | |
1159 | lockdep_assert_held(&local->mtx); | |
5cff20e6 JB |
1160 | |
1161 | list_for_each_entry(sdata, &local->interfaces, list) { | |
7da7cc1d JB |
1162 | if (!ieee80211_sdata_running(sdata)) { |
1163 | sdata->vif.bss_conf.idle = true; | |
5cff20e6 | 1164 | continue; |
7da7cc1d JB |
1165 | } |
1166 | ||
1167 | sdata->old_idle = sdata->vif.bss_conf.idle; | |
1168 | ||
5cff20e6 JB |
1169 | /* do not count disabled managed interfaces */ |
1170 | if (sdata->vif.type == NL80211_IFTYPE_STATION && | |
7da7cc1d JB |
1171 | !sdata->u.mgd.associated) { |
1172 | sdata->vif.bss_conf.idle = true; | |
5cff20e6 | 1173 | continue; |
7da7cc1d | 1174 | } |
5cff20e6 JB |
1175 | /* do not count unused IBSS interfaces */ |
1176 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC && | |
7da7cc1d JB |
1177 | !sdata->u.ibss.ssid_len) { |
1178 | sdata->vif.bss_conf.idle = true; | |
5cff20e6 | 1179 | continue; |
7da7cc1d | 1180 | } |
5cff20e6 JB |
1181 | /* count everything else */ |
1182 | count++; | |
1183 | } | |
1184 | ||
7da7cc1d JB |
1185 | list_for_each_entry(wk, &local->work_list, list) { |
1186 | working = true; | |
1187 | wk->sdata->vif.bss_conf.idle = false; | |
1188 | } | |
1189 | ||
1190 | if (local->scan_sdata) { | |
1191 | scanning = true; | |
1192 | local->scan_sdata->vif.bss_conf.idle = false; | |
1193 | } | |
1194 | ||
1195 | list_for_each_entry(sdata, &local->interfaces, list) { | |
1196 | if (sdata->old_idle == sdata->vif.bss_conf.idle) | |
1197 | continue; | |
1198 | if (!ieee80211_sdata_running(sdata)) | |
1199 | continue; | |
1200 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IDLE); | |
1201 | } | |
1202 | ||
1203 | if (working) | |
1204 | return ieee80211_idle_off(local, "working"); | |
1205 | if (scanning) | |
1206 | return ieee80211_idle_off(local, "scanning"); | |
5cff20e6 JB |
1207 | if (!count) |
1208 | return ieee80211_idle_on(local); | |
1209 | else | |
1210 | return ieee80211_idle_off(local, "in use"); | |
1211 | ||
1212 | return 0; | |
1213 | } | |
1214 | ||
1215 | void ieee80211_recalc_idle(struct ieee80211_local *local) | |
1216 | { | |
1217 | u32 chg; | |
1218 | ||
1219 | mutex_lock(&local->iflist_mtx); | |
1220 | chg = __ieee80211_recalc_idle(local); | |
1221 | mutex_unlock(&local->iflist_mtx); | |
58905ca5 JB |
1222 | if (chg) |
1223 | ieee80211_hw_config(local, chg); | |
5cff20e6 | 1224 | } |
47846c9b JB |
1225 | |
1226 | static int netdev_notify(struct notifier_block *nb, | |
1227 | unsigned long state, | |
1228 | void *ndev) | |
1229 | { | |
1230 | struct net_device *dev = ndev; | |
1231 | struct ieee80211_sub_if_data *sdata; | |
1232 | ||
1233 | if (state != NETDEV_CHANGENAME) | |
1234 | return 0; | |
1235 | ||
1236 | if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy) | |
1237 | return 0; | |
1238 | ||
1239 | if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid) | |
1240 | return 0; | |
1241 | ||
1242 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1243 | ||
2f5265e6 | 1244 | memcpy(sdata->name, dev->name, IFNAMSIZ); |
47846c9b JB |
1245 | |
1246 | ieee80211_debugfs_rename_netdev(sdata); | |
1247 | return 0; | |
1248 | } | |
1249 | ||
1250 | static struct notifier_block mac80211_netdev_notifier = { | |
1251 | .notifier_call = netdev_notify, | |
1252 | }; | |
1253 | ||
1254 | int ieee80211_iface_init(void) | |
1255 | { | |
1256 | return register_netdevice_notifier(&mac80211_netdev_notifier); | |
1257 | } | |
1258 | ||
1259 | void ieee80211_iface_exit(void) | |
1260 | { | |
1261 | unregister_netdevice_notifier(&mac80211_netdev_notifier); | |
1262 | } |