diff options
author | Johannes Berg <johannes@sipsolutions.net> | 2008-09-10 18:01:59 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2008-09-15 16:48:23 -0400 |
commit | 0d143fe1e2efc084fa730d2dfa22d0d1ca2ee5f1 (patch) | |
tree | d3a08fc38cad01024b37981e8258f84fe61d7ac3 /net/mac80211 | |
parent | 05c914fe330fa8e1cc67870dc0d3809dfd96c107 (diff) |
mac80211: move regular interface handling
Move the code to handle regular interfaces out of main.c and
into iface.c, keep only the master interface stuff in main.c.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'net/mac80211')
-rw-r--r-- | net/mac80211/ieee80211_i.h | 2 | ||||
-rw-r--r-- | net/mac80211/iface.c | 534 | ||||
-rw-r--r-- | net/mac80211/main.c | 565 |
3 files changed, 550 insertions, 551 deletions
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 80d88f5ff90c..6bd6a6306da3 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h | |||
@@ -891,6 +891,7 @@ u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht, | |||
891 | struct ieee80211_ht_bss_info *req_bss_cap); | 891 | struct ieee80211_ht_bss_info *req_bss_cap); |
892 | void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata, | 892 | void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata, |
893 | u32 changed); | 893 | u32 changed); |
894 | void ieee80211_configure_filter(struct ieee80211_local *local); | ||
894 | 895 | ||
895 | /* wireless extensions */ | 896 | /* wireless extensions */ |
896 | extern const struct iw_handler_def ieee80211_iw_handler_def; | 897 | extern const struct iw_handler_def ieee80211_iw_handler_def; |
@@ -952,7 +953,6 @@ void ieee80211_rx_bss_put(struct ieee80211_local *local, | |||
952 | struct ieee80211_bss *bss); | 953 | struct ieee80211_bss *bss); |
953 | 954 | ||
954 | /* interface handling */ | 955 | /* interface handling */ |
955 | void ieee80211_if_setup(struct net_device *dev); | ||
956 | int ieee80211_if_add(struct ieee80211_local *local, const char *name, | 956 | int ieee80211_if_add(struct ieee80211_local *local, const char *name, |
957 | struct net_device **new_dev, enum nl80211_iftype type, | 957 | struct net_device **new_dev, enum nl80211_iftype type, |
958 | struct vif_params *params); | 958 | struct vif_params *params); |
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index 004fb23241da..f528962b13e3 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c | |||
@@ -1,4 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * Interface handling (except master interface) | ||
3 | * | ||
2 | * Copyright 2002-2005, Instant802 Networks, Inc. | 4 | * Copyright 2002-2005, Instant802 Networks, Inc. |
3 | * Copyright 2005-2006, Devicescape Software, Inc. | 5 | * Copyright 2005-2006, Devicescape Software, Inc. |
4 | * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz> | 6 | * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz> |
@@ -17,7 +19,539 @@ | |||
17 | #include "sta_info.h" | 19 | #include "sta_info.h" |
18 | #include "debugfs_netdev.h" | 20 | #include "debugfs_netdev.h" |
19 | #include "mesh.h" | 21 | #include "mesh.h" |
22 | #include "led.h" | ||
23 | |||
24 | static int ieee80211_change_mtu(struct net_device *dev, int new_mtu) | ||
25 | { | ||
26 | int meshhdrlen; | ||
27 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | ||
28 | |||
29 | meshhdrlen = (sdata->vif.type == NL80211_IFTYPE_MESH_POINT) ? 5 : 0; | ||
30 | |||
31 | /* FIX: what would be proper limits for MTU? | ||
32 | * This interface uses 802.3 frames. */ | ||
33 | if (new_mtu < 256 || | ||
34 | new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) { | ||
35 | return -EINVAL; | ||
36 | } | ||
37 | |||
38 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | ||
39 | printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu); | ||
40 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ | ||
41 | dev->mtu = new_mtu; | ||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | static inline int identical_mac_addr_allowed(int type1, int type2) | ||
46 | { | ||
47 | return type1 == NL80211_IFTYPE_MONITOR || | ||
48 | type2 == NL80211_IFTYPE_MONITOR || | ||
49 | (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_WDS) || | ||
50 | (type1 == NL80211_IFTYPE_WDS && | ||
51 | (type2 == NL80211_IFTYPE_WDS || | ||
52 | type2 == NL80211_IFTYPE_AP)) || | ||
53 | (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_AP_VLAN) || | ||
54 | (type1 == NL80211_IFTYPE_AP_VLAN && | ||
55 | (type2 == NL80211_IFTYPE_AP || | ||
56 | type2 == NL80211_IFTYPE_AP_VLAN)); | ||
57 | } | ||
58 | |||
59 | static int ieee80211_open(struct net_device *dev) | ||
60 | { | ||
61 | struct ieee80211_sub_if_data *sdata, *nsdata; | ||
62 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | ||
63 | struct sta_info *sta; | ||
64 | struct ieee80211_if_init_conf conf; | ||
65 | u32 changed = 0; | ||
66 | int res; | ||
67 | bool need_hw_reconfig = 0; | ||
68 | u8 null_addr[ETH_ALEN] = {0}; | ||
69 | |||
70 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | ||
71 | |||
72 | /* fail early if user set an invalid address */ | ||
73 | if (compare_ether_addr(dev->dev_addr, null_addr) && | ||
74 | !is_valid_ether_addr(dev->dev_addr)) | ||
75 | return -EADDRNOTAVAIL; | ||
76 | |||
77 | /* we hold the RTNL here so can safely walk the list */ | ||
78 | list_for_each_entry(nsdata, &local->interfaces, list) { | ||
79 | struct net_device *ndev = nsdata->dev; | ||
80 | |||
81 | if (ndev != dev && netif_running(ndev)) { | ||
82 | /* | ||
83 | * Allow only a single IBSS interface to be up at any | ||
84 | * time. This is restricted because beacon distribution | ||
85 | * cannot work properly if both are in the same IBSS. | ||
86 | * | ||
87 | * To remove this restriction we'd have to disallow them | ||
88 | * from setting the same SSID on different IBSS interfaces | ||
89 | * belonging to the same hardware. Then, however, we're | ||
90 | * faced with having to adopt two different TSF timers... | ||
91 | */ | ||
92 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC && | ||
93 | nsdata->vif.type == NL80211_IFTYPE_ADHOC) | ||
94 | return -EBUSY; | ||
95 | |||
96 | /* | ||
97 | * The remaining checks are only performed for interfaces | ||
98 | * with the same MAC address. | ||
99 | */ | ||
100 | if (compare_ether_addr(dev->dev_addr, ndev->dev_addr)) | ||
101 | continue; | ||
102 | |||
103 | /* | ||
104 | * check whether it may have the same address | ||
105 | */ | ||
106 | if (!identical_mac_addr_allowed(sdata->vif.type, | ||
107 | nsdata->vif.type)) | ||
108 | return -ENOTUNIQ; | ||
109 | |||
110 | /* | ||
111 | * can only add VLANs to enabled APs | ||
112 | */ | ||
113 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN && | ||
114 | nsdata->vif.type == NL80211_IFTYPE_AP) | ||
115 | sdata->bss = &nsdata->u.ap; | ||
116 | } | ||
117 | } | ||
118 | |||
119 | switch (sdata->vif.type) { | ||
120 | case NL80211_IFTYPE_WDS: | ||
121 | if (!is_valid_ether_addr(sdata->u.wds.remote_addr)) | ||
122 | return -ENOLINK; | ||
123 | break; | ||
124 | case NL80211_IFTYPE_AP_VLAN: | ||
125 | if (!sdata->bss) | ||
126 | return -ENOLINK; | ||
127 | list_add(&sdata->u.vlan.list, &sdata->bss->vlans); | ||
128 | break; | ||
129 | case NL80211_IFTYPE_AP: | ||
130 | sdata->bss = &sdata->u.ap; | ||
131 | break; | ||
132 | case NL80211_IFTYPE_MESH_POINT: | ||
133 | if (!ieee80211_vif_is_mesh(&sdata->vif)) | ||
134 | break; | ||
135 | /* mesh ifaces must set allmulti to forward mcast traffic */ | ||
136 | atomic_inc(&local->iff_allmultis); | ||
137 | break; | ||
138 | case NL80211_IFTYPE_STATION: | ||
139 | case NL80211_IFTYPE_MONITOR: | ||
140 | case NL80211_IFTYPE_ADHOC: | ||
141 | /* no special treatment */ | ||
142 | break; | ||
143 | case NL80211_IFTYPE_UNSPECIFIED: | ||
144 | case __NL80211_IFTYPE_AFTER_LAST: | ||
145 | /* cannot happen */ | ||
146 | WARN_ON(1); | ||
147 | break; | ||
148 | } | ||
149 | |||
150 | if (local->open_count == 0) { | ||
151 | res = 0; | ||
152 | if (local->ops->start) | ||
153 | res = local->ops->start(local_to_hw(local)); | ||
154 | if (res) | ||
155 | goto err_del_bss; | ||
156 | need_hw_reconfig = 1; | ||
157 | ieee80211_led_radio(local, local->hw.conf.radio_enabled); | ||
158 | } | ||
20 | 159 | ||
160 | /* | ||
161 | * Check all interfaces and copy the hopefully now-present | ||
162 | * MAC address to those that have the special null one. | ||
163 | */ | ||
164 | list_for_each_entry(nsdata, &local->interfaces, list) { | ||
165 | struct net_device *ndev = nsdata->dev; | ||
166 | |||
167 | /* | ||
168 | * No need to check netif_running since we do not allow | ||
169 | * it to start up with this invalid address. | ||
170 | */ | ||
171 | if (compare_ether_addr(null_addr, ndev->dev_addr) == 0) | ||
172 | memcpy(ndev->dev_addr, | ||
173 | local->hw.wiphy->perm_addr, | ||
174 | ETH_ALEN); | ||
175 | } | ||
176 | |||
177 | if (compare_ether_addr(null_addr, local->mdev->dev_addr) == 0) | ||
178 | memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, | ||
179 | ETH_ALEN); | ||
180 | |||
181 | /* | ||
182 | * Validate the MAC address for this device. | ||
183 | */ | ||
184 | if (!is_valid_ether_addr(dev->dev_addr)) { | ||
185 | if (!local->open_count && local->ops->stop) | ||
186 | local->ops->stop(local_to_hw(local)); | ||
187 | return -EADDRNOTAVAIL; | ||
188 | } | ||
189 | |||
190 | switch (sdata->vif.type) { | ||
191 | case NL80211_IFTYPE_AP_VLAN: | ||
192 | /* no need to tell driver */ | ||
193 | break; | ||
194 | case NL80211_IFTYPE_MONITOR: | ||
195 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { | ||
196 | local->cooked_mntrs++; | ||
197 | break; | ||
198 | } | ||
199 | |||
200 | /* must be before the call to ieee80211_configure_filter */ | ||
201 | local->monitors++; | ||
202 | if (local->monitors == 1) | ||
203 | local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP; | ||
204 | |||
205 | if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) | ||
206 | local->fif_fcsfail++; | ||
207 | if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) | ||
208 | local->fif_plcpfail++; | ||
209 | if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) | ||
210 | local->fif_control++; | ||
211 | if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) | ||
212 | local->fif_other_bss++; | ||
213 | |||
214 | netif_addr_lock_bh(local->mdev); | ||
215 | ieee80211_configure_filter(local); | ||
216 | netif_addr_unlock_bh(local->mdev); | ||
217 | break; | ||
218 | case NL80211_IFTYPE_STATION: | ||
219 | case NL80211_IFTYPE_ADHOC: | ||
220 | sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET; | ||
221 | /* fall through */ | ||
222 | default: | ||
223 | conf.vif = &sdata->vif; | ||
224 | conf.type = sdata->vif.type; | ||
225 | conf.mac_addr = dev->dev_addr; | ||
226 | res = local->ops->add_interface(local_to_hw(local), &conf); | ||
227 | if (res) | ||
228 | goto err_stop; | ||
229 | |||
230 | if (ieee80211_vif_is_mesh(&sdata->vif)) | ||
231 | ieee80211_start_mesh(sdata); | ||
232 | changed |= ieee80211_reset_erp_info(sdata); | ||
233 | ieee80211_bss_info_change_notify(sdata, changed); | ||
234 | ieee80211_enable_keys(sdata); | ||
235 | |||
236 | if (sdata->vif.type == NL80211_IFTYPE_STATION && | ||
237 | !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)) | ||
238 | netif_carrier_off(dev); | ||
239 | else | ||
240 | netif_carrier_on(dev); | ||
241 | } | ||
242 | |||
243 | if (sdata->vif.type == NL80211_IFTYPE_WDS) { | ||
244 | /* Create STA entry for the WDS peer */ | ||
245 | sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr, | ||
246 | GFP_KERNEL); | ||
247 | if (!sta) { | ||
248 | res = -ENOMEM; | ||
249 | goto err_del_interface; | ||
250 | } | ||
251 | |||
252 | /* no locking required since STA is not live yet */ | ||
253 | sta->flags |= WLAN_STA_AUTHORIZED; | ||
254 | |||
255 | res = sta_info_insert(sta); | ||
256 | if (res) { | ||
257 | /* STA has been freed */ | ||
258 | goto err_del_interface; | ||
259 | } | ||
260 | } | ||
261 | |||
262 | if (local->open_count == 0) { | ||
263 | res = dev_open(local->mdev); | ||
264 | WARN_ON(res); | ||
265 | if (res) | ||
266 | goto err_del_interface; | ||
267 | tasklet_enable(&local->tx_pending_tasklet); | ||
268 | tasklet_enable(&local->tasklet); | ||
269 | } | ||
270 | |||
271 | /* | ||
272 | * set_multicast_list will be invoked by the networking core | ||
273 | * which will check whether any increments here were done in | ||
274 | * error and sync them down to the hardware as filter flags. | ||
275 | */ | ||
276 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) | ||
277 | atomic_inc(&local->iff_allmultis); | ||
278 | |||
279 | if (sdata->flags & IEEE80211_SDATA_PROMISC) | ||
280 | atomic_inc(&local->iff_promiscs); | ||
281 | |||
282 | local->open_count++; | ||
283 | if (need_hw_reconfig) { | ||
284 | ieee80211_hw_config(local); | ||
285 | /* | ||
286 | * set default queue parameters so drivers don't | ||
287 | * need to initialise the hardware if the hardware | ||
288 | * doesn't start up with sane defaults | ||
289 | */ | ||
290 | ieee80211_set_wmm_default(sdata); | ||
291 | } | ||
292 | |||
293 | /* | ||
294 | * ieee80211_sta_work is disabled while network interface | ||
295 | * is down. Therefore, some configuration changes may not | ||
296 | * yet be effective. Trigger execution of ieee80211_sta_work | ||
297 | * to fix this. | ||
298 | */ | ||
299 | if (sdata->vif.type == NL80211_IFTYPE_STATION || | ||
300 | sdata->vif.type == NL80211_IFTYPE_ADHOC) { | ||
301 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; | ||
302 | queue_work(local->hw.workqueue, &ifsta->work); | ||
303 | } | ||
304 | |||
305 | netif_tx_start_all_queues(dev); | ||
306 | |||
307 | return 0; | ||
308 | err_del_interface: | ||
309 | local->ops->remove_interface(local_to_hw(local), &conf); | ||
310 | err_stop: | ||
311 | if (!local->open_count && local->ops->stop) | ||
312 | local->ops->stop(local_to_hw(local)); | ||
313 | err_del_bss: | ||
314 | sdata->bss = NULL; | ||
315 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) | ||
316 | list_del(&sdata->u.vlan.list); | ||
317 | return res; | ||
318 | } | ||
319 | |||
320 | static int ieee80211_stop(struct net_device *dev) | ||
321 | { | ||
322 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | ||
323 | struct ieee80211_local *local = sdata->local; | ||
324 | struct ieee80211_if_init_conf conf; | ||
325 | struct sta_info *sta; | ||
326 | |||
327 | /* | ||
328 | * Stop TX on this interface first. | ||
329 | */ | ||
330 | netif_tx_stop_all_queues(dev); | ||
331 | |||
332 | /* | ||
333 | * Now delete all active aggregation sessions. | ||
334 | */ | ||
335 | rcu_read_lock(); | ||
336 | |||
337 | list_for_each_entry_rcu(sta, &local->sta_list, list) { | ||
338 | if (sta->sdata == sdata) | ||
339 | ieee80211_sta_tear_down_BA_sessions(sdata, sta->addr); | ||
340 | } | ||
341 | |||
342 | rcu_read_unlock(); | ||
343 | |||
344 | /* | ||
345 | * Remove all stations associated with this interface. | ||
346 | * | ||
347 | * This must be done before calling ops->remove_interface() | ||
348 | * because otherwise we can later invoke ops->sta_notify() | ||
349 | * whenever the STAs are removed, and that invalidates driver | ||
350 | * assumptions about always getting a vif pointer that is valid | ||
351 | * (because if we remove a STA after ops->remove_interface() | ||
352 | * the driver will have removed the vif info already!) | ||
353 | * | ||
354 | * We could relax this and only unlink the stations from the | ||
355 | * hash table and list but keep them on a per-sdata list that | ||
356 | * will be inserted back again when the interface is brought | ||
357 | * up again, but I don't currently see a use case for that, | ||
358 | * except with WDS which gets a STA entry created when it is | ||
359 | * brought up. | ||
360 | */ | ||
361 | sta_info_flush(local, sdata); | ||
362 | |||
363 | /* | ||
364 | * Don't count this interface for promisc/allmulti while it | ||
365 | * is down. dev_mc_unsync() will invoke set_multicast_list | ||
366 | * on the master interface which will sync these down to the | ||
367 | * hardware as filter flags. | ||
368 | */ | ||
369 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) | ||
370 | atomic_dec(&local->iff_allmultis); | ||
371 | |||
372 | if (sdata->flags & IEEE80211_SDATA_PROMISC) | ||
373 | atomic_dec(&local->iff_promiscs); | ||
374 | |||
375 | dev_mc_unsync(local->mdev, dev); | ||
376 | |||
377 | /* APs need special treatment */ | ||
378 | if (sdata->vif.type == NL80211_IFTYPE_AP) { | ||
379 | struct ieee80211_sub_if_data *vlan, *tmp; | ||
380 | struct beacon_data *old_beacon = sdata->u.ap.beacon; | ||
381 | |||
382 | /* remove beacon */ | ||
383 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); | ||
384 | synchronize_rcu(); | ||
385 | kfree(old_beacon); | ||
386 | |||
387 | /* down all dependent devices, that is VLANs */ | ||
388 | list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans, | ||
389 | u.vlan.list) | ||
390 | dev_close(vlan->dev); | ||
391 | WARN_ON(!list_empty(&sdata->u.ap.vlans)); | ||
392 | } | ||
393 | |||
394 | local->open_count--; | ||
395 | |||
396 | switch (sdata->vif.type) { | ||
397 | case NL80211_IFTYPE_AP_VLAN: | ||
398 | list_del(&sdata->u.vlan.list); | ||
399 | /* no need to tell driver */ | ||
400 | break; | ||
401 | case NL80211_IFTYPE_MONITOR: | ||
402 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { | ||
403 | local->cooked_mntrs--; | ||
404 | break; | ||
405 | } | ||
406 | |||
407 | local->monitors--; | ||
408 | if (local->monitors == 0) | ||
409 | local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP; | ||
410 | |||
411 | if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) | ||
412 | local->fif_fcsfail--; | ||
413 | if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) | ||
414 | local->fif_plcpfail--; | ||
415 | if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) | ||
416 | local->fif_control--; | ||
417 | if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) | ||
418 | local->fif_other_bss--; | ||
419 | |||
420 | netif_addr_lock_bh(local->mdev); | ||
421 | ieee80211_configure_filter(local); | ||
422 | netif_addr_unlock_bh(local->mdev); | ||
423 | break; | ||
424 | case NL80211_IFTYPE_STATION: | ||
425 | case NL80211_IFTYPE_ADHOC: | ||
426 | sdata->u.sta.state = IEEE80211_STA_MLME_DISABLED; | ||
427 | memset(sdata->u.sta.bssid, 0, ETH_ALEN); | ||
428 | del_timer_sync(&sdata->u.sta.timer); | ||
429 | /* | ||
430 | * If the timer fired while we waited for it, it will have | ||
431 | * requeued the work. Now the work will be running again | ||
432 | * but will not rearm the timer again because it checks | ||
433 | * whether the interface is running, which, at this point, | ||
434 | * it no longer is. | ||
435 | */ | ||
436 | cancel_work_sync(&sdata->u.sta.work); | ||
437 | /* | ||
438 | * When we get here, the interface is marked down. | ||
439 | * Call synchronize_rcu() to wait for the RX path | ||
440 | * should it be using the interface and enqueuing | ||
441 | * frames at this very time on another CPU. | ||
442 | */ | ||
443 | synchronize_rcu(); | ||
444 | skb_queue_purge(&sdata->u.sta.skb_queue); | ||
445 | |||
446 | sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED; | ||
447 | kfree(sdata->u.sta.extra_ie); | ||
448 | sdata->u.sta.extra_ie = NULL; | ||
449 | sdata->u.sta.extra_ie_len = 0; | ||
450 | /* fall through */ | ||
451 | case NL80211_IFTYPE_MESH_POINT: | ||
452 | if (ieee80211_vif_is_mesh(&sdata->vif)) { | ||
453 | /* allmulti is always set on mesh ifaces */ | ||
454 | atomic_dec(&local->iff_allmultis); | ||
455 | ieee80211_stop_mesh(sdata); | ||
456 | } | ||
457 | /* fall through */ | ||
458 | default: | ||
459 | if (local->scan_sdata == sdata) { | ||
460 | if (!local->ops->hw_scan) | ||
461 | cancel_delayed_work_sync(&local->scan_work); | ||
462 | /* | ||
463 | * The software scan can no longer run now, so we can | ||
464 | * clear out the scan_sdata reference. However, the | ||
465 | * hardware scan may still be running. The complete | ||
466 | * function must be prepared to handle a NULL value. | ||
467 | */ | ||
468 | local->scan_sdata = NULL; | ||
469 | /* | ||
470 | * The memory barrier guarantees that another CPU | ||
471 | * that is hardware-scanning will now see the fact | ||
472 | * that this interface is gone. | ||
473 | */ | ||
474 | smp_mb(); | ||
475 | /* | ||
476 | * If software scanning, complete the scan but since | ||
477 | * the scan_sdata is NULL already don't send out a | ||
478 | * scan event to userspace -- the scan is incomplete. | ||
479 | */ | ||
480 | if (local->sw_scanning) | ||
481 | ieee80211_scan_completed(&local->hw); | ||
482 | } | ||
483 | |||
484 | conf.vif = &sdata->vif; | ||
485 | conf.type = sdata->vif.type; | ||
486 | conf.mac_addr = dev->dev_addr; | ||
487 | /* disable all keys for as long as this netdev is down */ | ||
488 | ieee80211_disable_keys(sdata); | ||
489 | local->ops->remove_interface(local_to_hw(local), &conf); | ||
490 | } | ||
491 | |||
492 | sdata->bss = NULL; | ||
493 | |||
494 | if (local->open_count == 0) { | ||
495 | if (netif_running(local->mdev)) | ||
496 | dev_close(local->mdev); | ||
497 | |||
498 | if (local->ops->stop) | ||
499 | local->ops->stop(local_to_hw(local)); | ||
500 | |||
501 | ieee80211_led_radio(local, 0); | ||
502 | |||
503 | flush_workqueue(local->hw.workqueue); | ||
504 | |||
505 | tasklet_disable(&local->tx_pending_tasklet); | ||
506 | tasklet_disable(&local->tasklet); | ||
507 | } | ||
508 | |||
509 | return 0; | ||
510 | } | ||
511 | |||
512 | static void ieee80211_set_multicast_list(struct net_device *dev) | ||
513 | { | ||
514 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | ||
515 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | ||
516 | int allmulti, promisc, sdata_allmulti, sdata_promisc; | ||
517 | |||
518 | allmulti = !!(dev->flags & IFF_ALLMULTI); | ||
519 | promisc = !!(dev->flags & IFF_PROMISC); | ||
520 | sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI); | ||
521 | sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC); | ||
522 | |||
523 | if (allmulti != sdata_allmulti) { | ||
524 | if (dev->flags & IFF_ALLMULTI) | ||
525 | atomic_inc(&local->iff_allmultis); | ||
526 | else | ||
527 | atomic_dec(&local->iff_allmultis); | ||
528 | sdata->flags ^= IEEE80211_SDATA_ALLMULTI; | ||
529 | } | ||
530 | |||
531 | if (promisc != sdata_promisc) { | ||
532 | if (dev->flags & IFF_PROMISC) | ||
533 | atomic_inc(&local->iff_promiscs); | ||
534 | else | ||
535 | atomic_dec(&local->iff_promiscs); | ||
536 | sdata->flags ^= IEEE80211_SDATA_PROMISC; | ||
537 | } | ||
538 | |||
539 | dev_mc_sync(local->mdev, dev); | ||
540 | } | ||
541 | |||
542 | static void ieee80211_if_setup(struct net_device *dev) | ||
543 | { | ||
544 | ether_setup(dev); | ||
545 | dev->hard_start_xmit = ieee80211_subif_start_xmit; | ||
546 | dev->wireless_handlers = &ieee80211_iw_handler_def; | ||
547 | dev->set_multicast_list = ieee80211_set_multicast_list; | ||
548 | dev->change_mtu = ieee80211_change_mtu; | ||
549 | dev->open = ieee80211_open; | ||
550 | dev->stop = ieee80211_stop; | ||
551 | dev->destructor = free_netdev; | ||
552 | /* we will validate the address ourselves in ->open */ | ||
553 | dev->validate_addr = NULL; | ||
554 | } | ||
21 | /* | 555 | /* |
22 | * Called when the netdev is removed or, by the code below, before | 556 | * Called when the netdev is removed or, by the code below, before |
23 | * the interface type changes. | 557 | * the interface type changes. |
diff --git a/net/mac80211/main.c b/net/mac80211/main.c index 584a75bd6cfe..c532043c1a1c 100644 --- a/net/mac80211/main.c +++ b/net/mac80211/main.c | |||
@@ -45,16 +45,9 @@ struct ieee80211_tx_status_rtap_hdr { | |||
45 | u8 data_retries; | 45 | u8 data_retries; |
46 | } __attribute__ ((packed)); | 46 | } __attribute__ ((packed)); |
47 | 47 | ||
48 | /* common interface routines */ | ||
49 | |||
50 | static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr) | ||
51 | { | ||
52 | memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */ | ||
53 | return ETH_ALEN; | ||
54 | } | ||
55 | 48 | ||
56 | /* must be called under mdev tx lock */ | 49 | /* must be called under mdev tx lock */ |
57 | static void ieee80211_configure_filter(struct ieee80211_local *local) | 50 | void ieee80211_configure_filter(struct ieee80211_local *local) |
58 | { | 51 | { |
59 | unsigned int changed_flags; | 52 | unsigned int changed_flags; |
60 | unsigned int new_flags = 0; | 53 | unsigned int new_flags = 0; |
@@ -97,6 +90,20 @@ static void ieee80211_configure_filter(struct ieee80211_local *local) | |||
97 | 90 | ||
98 | /* master interface */ | 91 | /* master interface */ |
99 | 92 | ||
93 | static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr) | ||
94 | { | ||
95 | memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */ | ||
96 | return ETH_ALEN; | ||
97 | } | ||
98 | |||
99 | static const struct header_ops ieee80211_header_ops = { | ||
100 | .create = eth_header, | ||
101 | .parse = header_parse_80211, | ||
102 | .rebuild = eth_rebuild_header, | ||
103 | .cache = eth_header_cache, | ||
104 | .cache_update = eth_header_cache_update, | ||
105 | }; | ||
106 | |||
100 | static int ieee80211_master_open(struct net_device *dev) | 107 | static int ieee80211_master_open(struct net_device *dev) |
101 | { | 108 | { |
102 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 109 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
@@ -139,548 +146,6 @@ static void ieee80211_master_set_multicast_list(struct net_device *dev) | |||
139 | ieee80211_configure_filter(local); | 146 | ieee80211_configure_filter(local); |
140 | } | 147 | } |
141 | 148 | ||
142 | /* regular interfaces */ | ||
143 | |||
144 | static int ieee80211_change_mtu(struct net_device *dev, int new_mtu) | ||
145 | { | ||
146 | int meshhdrlen; | ||
147 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | ||
148 | |||
149 | meshhdrlen = (sdata->vif.type == NL80211_IFTYPE_MESH_POINT) ? 5 : 0; | ||
150 | |||
151 | /* FIX: what would be proper limits for MTU? | ||
152 | * This interface uses 802.3 frames. */ | ||
153 | if (new_mtu < 256 || | ||
154 | new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) { | ||
155 | return -EINVAL; | ||
156 | } | ||
157 | |||
158 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | ||
159 | printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu); | ||
160 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ | ||
161 | dev->mtu = new_mtu; | ||
162 | return 0; | ||
163 | } | ||
164 | |||
165 | static inline int identical_mac_addr_allowed(int type1, int type2) | ||
166 | { | ||
167 | return type1 == NL80211_IFTYPE_MONITOR || | ||
168 | type2 == NL80211_IFTYPE_MONITOR || | ||
169 | (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_WDS) || | ||
170 | (type1 == NL80211_IFTYPE_WDS && | ||
171 | (type2 == NL80211_IFTYPE_WDS || | ||
172 | type2 == NL80211_IFTYPE_AP)) || | ||
173 | (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_AP_VLAN) || | ||
174 | (type1 == NL80211_IFTYPE_AP_VLAN && | ||
175 | (type2 == NL80211_IFTYPE_AP || | ||
176 | type2 == NL80211_IFTYPE_AP_VLAN)); | ||
177 | } | ||
178 | |||
179 | static int ieee80211_open(struct net_device *dev) | ||
180 | { | ||
181 | struct ieee80211_sub_if_data *sdata, *nsdata; | ||
182 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | ||
183 | struct sta_info *sta; | ||
184 | struct ieee80211_if_init_conf conf; | ||
185 | u32 changed = 0; | ||
186 | int res; | ||
187 | bool need_hw_reconfig = 0; | ||
188 | u8 null_addr[ETH_ALEN] = {0}; | ||
189 | |||
190 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | ||
191 | |||
192 | /* fail early if user set an invalid address */ | ||
193 | if (compare_ether_addr(dev->dev_addr, null_addr) && | ||
194 | !is_valid_ether_addr(dev->dev_addr)) | ||
195 | return -EADDRNOTAVAIL; | ||
196 | |||
197 | /* we hold the RTNL here so can safely walk the list */ | ||
198 | list_for_each_entry(nsdata, &local->interfaces, list) { | ||
199 | struct net_device *ndev = nsdata->dev; | ||
200 | |||
201 | if (ndev != dev && netif_running(ndev)) { | ||
202 | /* | ||
203 | * Allow only a single IBSS interface to be up at any | ||
204 | * time. This is restricted because beacon distribution | ||
205 | * cannot work properly if both are in the same IBSS. | ||
206 | * | ||
207 | * To remove this restriction we'd have to disallow them | ||
208 | * from setting the same SSID on different IBSS interfaces | ||
209 | * belonging to the same hardware. Then, however, we're | ||
210 | * faced with having to adopt two different TSF timers... | ||
211 | */ | ||
212 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC && | ||
213 | nsdata->vif.type == NL80211_IFTYPE_ADHOC) | ||
214 | return -EBUSY; | ||
215 | |||
216 | /* | ||
217 | * The remaining checks are only performed for interfaces | ||
218 | * with the same MAC address. | ||
219 | */ | ||
220 | if (compare_ether_addr(dev->dev_addr, ndev->dev_addr)) | ||
221 | continue; | ||
222 | |||
223 | /* | ||
224 | * check whether it may have the same address | ||
225 | */ | ||
226 | if (!identical_mac_addr_allowed(sdata->vif.type, | ||
227 | nsdata->vif.type)) | ||
228 | return -ENOTUNIQ; | ||
229 | |||
230 | /* | ||
231 | * can only add VLANs to enabled APs | ||
232 | */ | ||
233 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN && | ||
234 | nsdata->vif.type == NL80211_IFTYPE_AP) | ||
235 | sdata->bss = &nsdata->u.ap; | ||
236 | } | ||
237 | } | ||
238 | |||
239 | switch (sdata->vif.type) { | ||
240 | case NL80211_IFTYPE_WDS: | ||
241 | if (!is_valid_ether_addr(sdata->u.wds.remote_addr)) | ||
242 | return -ENOLINK; | ||
243 | break; | ||
244 | case NL80211_IFTYPE_AP_VLAN: | ||
245 | if (!sdata->bss) | ||
246 | return -ENOLINK; | ||
247 | list_add(&sdata->u.vlan.list, &sdata->bss->vlans); | ||
248 | break; | ||
249 | case NL80211_IFTYPE_AP: | ||
250 | sdata->bss = &sdata->u.ap; | ||
251 | break; | ||
252 | case NL80211_IFTYPE_MESH_POINT: | ||
253 | if (!ieee80211_vif_is_mesh(&sdata->vif)) | ||
254 | break; | ||
255 | /* mesh ifaces must set allmulti to forward mcast traffic */ | ||
256 | atomic_inc(&local->iff_allmultis); | ||
257 | break; | ||
258 | case NL80211_IFTYPE_STATION: | ||
259 | case NL80211_IFTYPE_MONITOR: | ||
260 | case NL80211_IFTYPE_ADHOC: | ||
261 | /* no special treatment */ | ||
262 | break; | ||
263 | case NL80211_IFTYPE_UNSPECIFIED: | ||
264 | case __NL80211_IFTYPE_AFTER_LAST: | ||
265 | /* cannot happen */ | ||
266 | WARN_ON(1); | ||
267 | break; | ||
268 | } | ||
269 | |||
270 | if (local->open_count == 0) { | ||
271 | res = 0; | ||
272 | if (local->ops->start) | ||
273 | res = local->ops->start(local_to_hw(local)); | ||
274 | if (res) | ||
275 | goto err_del_bss; | ||
276 | need_hw_reconfig = 1; | ||
277 | ieee80211_led_radio(local, local->hw.conf.radio_enabled); | ||
278 | } | ||
279 | |||
280 | /* | ||
281 | * Check all interfaces and copy the hopefully now-present | ||
282 | * MAC address to those that have the special null one. | ||
283 | */ | ||
284 | list_for_each_entry(nsdata, &local->interfaces, list) { | ||
285 | struct net_device *ndev = nsdata->dev; | ||
286 | |||
287 | /* | ||
288 | * No need to check netif_running since we do not allow | ||
289 | * it to start up with this invalid address. | ||
290 | */ | ||
291 | if (compare_ether_addr(null_addr, ndev->dev_addr) == 0) | ||
292 | memcpy(ndev->dev_addr, | ||
293 | local->hw.wiphy->perm_addr, | ||
294 | ETH_ALEN); | ||
295 | } | ||
296 | |||
297 | if (compare_ether_addr(null_addr, local->mdev->dev_addr) == 0) | ||
298 | memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, | ||
299 | ETH_ALEN); | ||
300 | |||
301 | /* | ||
302 | * Validate the MAC address for this device. | ||
303 | */ | ||
304 | if (!is_valid_ether_addr(dev->dev_addr)) { | ||
305 | if (!local->open_count && local->ops->stop) | ||
306 | local->ops->stop(local_to_hw(local)); | ||
307 | return -EADDRNOTAVAIL; | ||
308 | } | ||
309 | |||
310 | switch (sdata->vif.type) { | ||
311 | case NL80211_IFTYPE_AP_VLAN: | ||
312 | /* no need to tell driver */ | ||
313 | break; | ||
314 | case NL80211_IFTYPE_MONITOR: | ||
315 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { | ||
316 | local->cooked_mntrs++; | ||
317 | break; | ||
318 | } | ||
319 | |||
320 | /* must be before the call to ieee80211_configure_filter */ | ||
321 | local->monitors++; | ||
322 | if (local->monitors == 1) | ||
323 | local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP; | ||
324 | |||
325 | if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) | ||
326 | local->fif_fcsfail++; | ||
327 | if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) | ||
328 | local->fif_plcpfail++; | ||
329 | if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) | ||
330 | local->fif_control++; | ||
331 | if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) | ||
332 | local->fif_other_bss++; | ||
333 | |||
334 | netif_addr_lock_bh(local->mdev); | ||
335 | ieee80211_configure_filter(local); | ||
336 | netif_addr_unlock_bh(local->mdev); | ||
337 | break; | ||
338 | case NL80211_IFTYPE_STATION: | ||
339 | case NL80211_IFTYPE_ADHOC: | ||
340 | sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET; | ||
341 | /* fall through */ | ||
342 | default: | ||
343 | conf.vif = &sdata->vif; | ||
344 | conf.type = sdata->vif.type; | ||
345 | conf.mac_addr = dev->dev_addr; | ||
346 | res = local->ops->add_interface(local_to_hw(local), &conf); | ||
347 | if (res) | ||
348 | goto err_stop; | ||
349 | |||
350 | if (ieee80211_vif_is_mesh(&sdata->vif)) | ||
351 | ieee80211_start_mesh(sdata); | ||
352 | changed |= ieee80211_reset_erp_info(sdata); | ||
353 | ieee80211_bss_info_change_notify(sdata, changed); | ||
354 | ieee80211_enable_keys(sdata); | ||
355 | |||
356 | if (sdata->vif.type == NL80211_IFTYPE_STATION && | ||
357 | !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)) | ||
358 | netif_carrier_off(dev); | ||
359 | else | ||
360 | netif_carrier_on(dev); | ||
361 | } | ||
362 | |||
363 | if (sdata->vif.type == NL80211_IFTYPE_WDS) { | ||
364 | /* Create STA entry for the WDS peer */ | ||
365 | sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr, | ||
366 | GFP_KERNEL); | ||
367 | if (!sta) { | ||
368 | res = -ENOMEM; | ||
369 | goto err_del_interface; | ||
370 | } | ||
371 | |||
372 | /* no locking required since STA is not live yet */ | ||
373 | sta->flags |= WLAN_STA_AUTHORIZED; | ||
374 | |||
375 | res = sta_info_insert(sta); | ||
376 | if (res) { | ||
377 | /* STA has been freed */ | ||
378 | goto err_del_interface; | ||
379 | } | ||
380 | } | ||
381 | |||
382 | if (local->open_count == 0) { | ||
383 | res = dev_open(local->mdev); | ||
384 | WARN_ON(res); | ||
385 | if (res) | ||
386 | goto err_del_interface; | ||
387 | tasklet_enable(&local->tx_pending_tasklet); | ||
388 | tasklet_enable(&local->tasklet); | ||
389 | } | ||
390 | |||
391 | /* | ||
392 | * set_multicast_list will be invoked by the networking core | ||
393 | * which will check whether any increments here were done in | ||
394 | * error and sync them down to the hardware as filter flags. | ||
395 | */ | ||
396 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) | ||
397 | atomic_inc(&local->iff_allmultis); | ||
398 | |||
399 | if (sdata->flags & IEEE80211_SDATA_PROMISC) | ||
400 | atomic_inc(&local->iff_promiscs); | ||
401 | |||
402 | local->open_count++; | ||
403 | if (need_hw_reconfig) { | ||
404 | ieee80211_hw_config(local); | ||
405 | /* | ||
406 | * set default queue parameters so drivers don't | ||
407 | * need to initialise the hardware if the hardware | ||
408 | * doesn't start up with sane defaults | ||
409 | */ | ||
410 | ieee80211_set_wmm_default(sdata); | ||
411 | } | ||
412 | |||
413 | /* | ||
414 | * ieee80211_sta_work is disabled while network interface | ||
415 | * is down. Therefore, some configuration changes may not | ||
416 | * yet be effective. Trigger execution of ieee80211_sta_work | ||
417 | * to fix this. | ||
418 | */ | ||
419 | if (sdata->vif.type == NL80211_IFTYPE_STATION || | ||
420 | sdata->vif.type == NL80211_IFTYPE_ADHOC) { | ||
421 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; | ||
422 | queue_work(local->hw.workqueue, &ifsta->work); | ||
423 | } | ||
424 | |||
425 | netif_tx_start_all_queues(dev); | ||
426 | |||
427 | return 0; | ||
428 | err_del_interface: | ||
429 | local->ops->remove_interface(local_to_hw(local), &conf); | ||
430 | err_stop: | ||
431 | if (!local->open_count && local->ops->stop) | ||
432 | local->ops->stop(local_to_hw(local)); | ||
433 | err_del_bss: | ||
434 | sdata->bss = NULL; | ||
435 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) | ||
436 | list_del(&sdata->u.vlan.list); | ||
437 | return res; | ||
438 | } | ||
439 | |||
440 | static int ieee80211_stop(struct net_device *dev) | ||
441 | { | ||
442 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | ||
443 | struct ieee80211_local *local = sdata->local; | ||
444 | struct ieee80211_if_init_conf conf; | ||
445 | struct sta_info *sta; | ||
446 | |||
447 | /* | ||
448 | * Stop TX on this interface first. | ||
449 | */ | ||
450 | netif_tx_stop_all_queues(dev); | ||
451 | |||
452 | /* | ||
453 | * Now delete all active aggregation sessions. | ||
454 | */ | ||
455 | rcu_read_lock(); | ||
456 | |||
457 | list_for_each_entry_rcu(sta, &local->sta_list, list) { | ||
458 | if (sta->sdata == sdata) | ||
459 | ieee80211_sta_tear_down_BA_sessions(sdata, sta->addr); | ||
460 | } | ||
461 | |||
462 | rcu_read_unlock(); | ||
463 | |||
464 | /* | ||
465 | * Remove all stations associated with this interface. | ||
466 | * | ||
467 | * This must be done before calling ops->remove_interface() | ||
468 | * because otherwise we can later invoke ops->sta_notify() | ||
469 | * whenever the STAs are removed, and that invalidates driver | ||
470 | * assumptions about always getting a vif pointer that is valid | ||
471 | * (because if we remove a STA after ops->remove_interface() | ||
472 | * the driver will have removed the vif info already!) | ||
473 | * | ||
474 | * We could relax this and only unlink the stations from the | ||
475 | * hash table and list but keep them on a per-sdata list that | ||
476 | * will be inserted back again when the interface is brought | ||
477 | * up again, but I don't currently see a use case for that, | ||
478 | * except with WDS which gets a STA entry created when it is | ||
479 | * brought up. | ||
480 | */ | ||
481 | sta_info_flush(local, sdata); | ||
482 | |||
483 | /* | ||
484 | * Don't count this interface for promisc/allmulti while it | ||
485 | * is down. dev_mc_unsync() will invoke set_multicast_list | ||
486 | * on the master interface which will sync these down to the | ||
487 | * hardware as filter flags. | ||
488 | */ | ||
489 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) | ||
490 | atomic_dec(&local->iff_allmultis); | ||
491 | |||
492 | if (sdata->flags & IEEE80211_SDATA_PROMISC) | ||
493 | atomic_dec(&local->iff_promiscs); | ||
494 | |||
495 | dev_mc_unsync(local->mdev, dev); | ||
496 | |||
497 | /* APs need special treatment */ | ||
498 | if (sdata->vif.type == NL80211_IFTYPE_AP) { | ||
499 | struct ieee80211_sub_if_data *vlan, *tmp; | ||
500 | struct beacon_data *old_beacon = sdata->u.ap.beacon; | ||
501 | |||
502 | /* remove beacon */ | ||
503 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); | ||
504 | synchronize_rcu(); | ||
505 | kfree(old_beacon); | ||
506 | |||
507 | /* down all dependent devices, that is VLANs */ | ||
508 | list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans, | ||
509 | u.vlan.list) | ||
510 | dev_close(vlan->dev); | ||
511 | WARN_ON(!list_empty(&sdata->u.ap.vlans)); | ||
512 | } | ||
513 | |||
514 | local->open_count--; | ||
515 | |||
516 | switch (sdata->vif.type) { | ||
517 | case NL80211_IFTYPE_AP_VLAN: | ||
518 | list_del(&sdata->u.vlan.list); | ||
519 | /* no need to tell driver */ | ||
520 | break; | ||
521 | case NL80211_IFTYPE_MONITOR: | ||
522 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { | ||
523 | local->cooked_mntrs--; | ||
524 | break; | ||
525 | } | ||
526 | |||
527 | local->monitors--; | ||
528 | if (local->monitors == 0) | ||
529 | local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP; | ||
530 | |||
531 | if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) | ||
532 | local->fif_fcsfail--; | ||
533 | if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) | ||
534 | local->fif_plcpfail--; | ||
535 | if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) | ||
536 | local->fif_control--; | ||
537 | if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) | ||
538 | local->fif_other_bss--; | ||
539 | |||
540 | netif_addr_lock_bh(local->mdev); | ||
541 | ieee80211_configure_filter(local); | ||
542 | netif_addr_unlock_bh(local->mdev); | ||
543 | break; | ||
544 | case NL80211_IFTYPE_STATION: | ||
545 | case NL80211_IFTYPE_ADHOC: | ||
546 | sdata->u.sta.state = IEEE80211_STA_MLME_DISABLED; | ||
547 | memset(sdata->u.sta.bssid, 0, ETH_ALEN); | ||
548 | del_timer_sync(&sdata->u.sta.timer); | ||
549 | /* | ||
550 | * If the timer fired while we waited for it, it will have | ||
551 | * requeued the work. Now the work will be running again | ||
552 | * but will not rearm the timer again because it checks | ||
553 | * whether the interface is running, which, at this point, | ||
554 | * it no longer is. | ||
555 | */ | ||
556 | cancel_work_sync(&sdata->u.sta.work); | ||
557 | /* | ||
558 | * When we get here, the interface is marked down. | ||
559 | * Call synchronize_rcu() to wait for the RX path | ||
560 | * should it be using the interface and enqueuing | ||
561 | * frames at this very time on another CPU. | ||
562 | */ | ||
563 | synchronize_rcu(); | ||
564 | skb_queue_purge(&sdata->u.sta.skb_queue); | ||
565 | |||
566 | sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED; | ||
567 | kfree(sdata->u.sta.extra_ie); | ||
568 | sdata->u.sta.extra_ie = NULL; | ||
569 | sdata->u.sta.extra_ie_len = 0; | ||
570 | /* fall through */ | ||
571 | case NL80211_IFTYPE_MESH_POINT: | ||
572 | if (ieee80211_vif_is_mesh(&sdata->vif)) { | ||
573 | /* allmulti is always set on mesh ifaces */ | ||
574 | atomic_dec(&local->iff_allmultis); | ||
575 | ieee80211_stop_mesh(sdata); | ||
576 | } | ||
577 | /* fall through */ | ||
578 | default: | ||
579 | if (local->scan_sdata == sdata) { | ||
580 | if (!local->ops->hw_scan) | ||
581 | cancel_delayed_work_sync(&local->scan_work); | ||
582 | /* | ||
583 | * The software scan can no longer run now, so we can | ||
584 | * clear out the scan_sdata reference. However, the | ||
585 | * hardware scan may still be running. The complete | ||
586 | * function must be prepared to handle a NULL value. | ||
587 | */ | ||
588 | local->scan_sdata = NULL; | ||
589 | /* | ||
590 | * The memory barrier guarantees that another CPU | ||
591 | * that is hardware-scanning will now see the fact | ||
592 | * that this interface is gone. | ||
593 | */ | ||
594 | smp_mb(); | ||
595 | /* | ||
596 | * If software scanning, complete the scan but since | ||
597 | * the scan_sdata is NULL already don't send out a | ||
598 | * scan event to userspace -- the scan is incomplete. | ||
599 | */ | ||
600 | if (local->sw_scanning) | ||
601 | ieee80211_scan_completed(&local->hw); | ||
602 | } | ||
603 | |||
604 | conf.vif = &sdata->vif; | ||
605 | conf.type = sdata->vif.type; | ||
606 | conf.mac_addr = dev->dev_addr; | ||
607 | /* disable all keys for as long as this netdev is down */ | ||
608 | ieee80211_disable_keys(sdata); | ||
609 | local->ops->remove_interface(local_to_hw(local), &conf); | ||
610 | } | ||
611 | |||
612 | sdata->bss = NULL; | ||
613 | |||
614 | if (local->open_count == 0) { | ||
615 | if (netif_running(local->mdev)) | ||
616 | dev_close(local->mdev); | ||
617 | |||
618 | if (local->ops->stop) | ||
619 | local->ops->stop(local_to_hw(local)); | ||
620 | |||
621 | ieee80211_led_radio(local, 0); | ||
622 | |||
623 | flush_workqueue(local->hw.workqueue); | ||
624 | |||
625 | tasklet_disable(&local->tx_pending_tasklet); | ||
626 | tasklet_disable(&local->tasklet); | ||
627 | } | ||
628 | |||
629 | return 0; | ||
630 | } | ||
631 | |||
632 | static void ieee80211_set_multicast_list(struct net_device *dev) | ||
633 | { | ||
634 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | ||
635 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | ||
636 | int allmulti, promisc, sdata_allmulti, sdata_promisc; | ||
637 | |||
638 | allmulti = !!(dev->flags & IFF_ALLMULTI); | ||
639 | promisc = !!(dev->flags & IFF_PROMISC); | ||
640 | sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI); | ||
641 | sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC); | ||
642 | |||
643 | if (allmulti != sdata_allmulti) { | ||
644 | if (dev->flags & IFF_ALLMULTI) | ||
645 | atomic_inc(&local->iff_allmultis); | ||
646 | else | ||
647 | atomic_dec(&local->iff_allmultis); | ||
648 | sdata->flags ^= IEEE80211_SDATA_ALLMULTI; | ||
649 | } | ||
650 | |||
651 | if (promisc != sdata_promisc) { | ||
652 | if (dev->flags & IFF_PROMISC) | ||
653 | atomic_inc(&local->iff_promiscs); | ||
654 | else | ||
655 | atomic_dec(&local->iff_promiscs); | ||
656 | sdata->flags ^= IEEE80211_SDATA_PROMISC; | ||
657 | } | ||
658 | |||
659 | dev_mc_sync(local->mdev, dev); | ||
660 | } | ||
661 | |||
662 | static const struct header_ops ieee80211_header_ops = { | ||
663 | .create = eth_header, | ||
664 | .parse = header_parse_80211, | ||
665 | .rebuild = eth_rebuild_header, | ||
666 | .cache = eth_header_cache, | ||
667 | .cache_update = eth_header_cache_update, | ||
668 | }; | ||
669 | |||
670 | void ieee80211_if_setup(struct net_device *dev) | ||
671 | { | ||
672 | ether_setup(dev); | ||
673 | dev->hard_start_xmit = ieee80211_subif_start_xmit; | ||
674 | dev->wireless_handlers = &ieee80211_iw_handler_def; | ||
675 | dev->set_multicast_list = ieee80211_set_multicast_list; | ||
676 | dev->change_mtu = ieee80211_change_mtu; | ||
677 | dev->open = ieee80211_open; | ||
678 | dev->stop = ieee80211_stop; | ||
679 | dev->destructor = free_netdev; | ||
680 | /* we will validate the address ourselves in ->open */ | ||
681 | dev->validate_addr = NULL; | ||
682 | } | ||
683 | |||
684 | /* everything else */ | 149 | /* everything else */ |
685 | 150 | ||
686 | int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed) | 151 | int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed) |