diff options
Diffstat (limited to 'net/mac80211/iface.c')
-rw-r--r-- | net/mac80211/iface.c | 620 |
1 files changed, 571 insertions, 49 deletions
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index 610ed1d9893a..8336fee68d3e 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 = IEEE80211_DEV_TO_SUB_IF(dev); | ||
62 | struct ieee80211_sub_if_data *nsdata; | ||
63 | struct ieee80211_local *local = sdata->local; | ||
64 | struct sta_info *sta; | ||
65 | struct ieee80211_if_init_conf conf; | ||
66 | u32 changed = 0; | ||
67 | int res; | ||
68 | bool need_hw_reconfig = 0; | ||
69 | u8 null_addr[ETH_ALEN] = {0}; | ||
70 | |||
71 | /* fail early if user set an invalid address */ | ||
72 | if (compare_ether_addr(dev->dev_addr, null_addr) && | ||
73 | !is_valid_ether_addr(dev->dev_addr)) | ||
74 | return -EADDRNOTAVAIL; | ||
75 | |||
76 | /* we hold the RTNL here so can safely walk the list */ | ||
77 | list_for_each_entry(nsdata, &local->interfaces, list) { | ||
78 | struct net_device *ndev = nsdata->dev; | ||
79 | |||
80 | if (ndev != dev && netif_running(ndev)) { | ||
81 | /* | ||
82 | * Allow only a single IBSS interface to be up at any | ||
83 | * time. This is restricted because beacon distribution | ||
84 | * cannot work properly if both are in the same IBSS. | ||
85 | * | ||
86 | * To remove this restriction we'd have to disallow them | ||
87 | * from setting the same SSID on different IBSS interfaces | ||
88 | * belonging to the same hardware. Then, however, we're | ||
89 | * faced with having to adopt two different TSF timers... | ||
90 | */ | ||
91 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC && | ||
92 | nsdata->vif.type == NL80211_IFTYPE_ADHOC) | ||
93 | return -EBUSY; | ||
94 | |||
95 | /* | ||
96 | * The remaining checks are only performed for interfaces | ||
97 | * with the same MAC address. | ||
98 | */ | ||
99 | if (compare_ether_addr(dev->dev_addr, ndev->dev_addr)) | ||
100 | continue; | ||
101 | |||
102 | /* | ||
103 | * check whether it may have the same address | ||
104 | */ | ||
105 | if (!identical_mac_addr_allowed(sdata->vif.type, | ||
106 | nsdata->vif.type)) | ||
107 | return -ENOTUNIQ; | ||
108 | |||
109 | /* | ||
110 | * can only add VLANs to enabled APs | ||
111 | */ | ||
112 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN && | ||
113 | nsdata->vif.type == NL80211_IFTYPE_AP) | ||
114 | sdata->bss = &nsdata->u.ap; | ||
115 | } | ||
116 | } | ||
117 | |||
118 | switch (sdata->vif.type) { | ||
119 | case NL80211_IFTYPE_WDS: | ||
120 | if (!is_valid_ether_addr(sdata->u.wds.remote_addr)) | ||
121 | return -ENOLINK; | ||
122 | break; | ||
123 | case NL80211_IFTYPE_AP_VLAN: | ||
124 | if (!sdata->bss) | ||
125 | return -ENOLINK; | ||
126 | list_add(&sdata->u.vlan.list, &sdata->bss->vlans); | ||
127 | break; | ||
128 | case NL80211_IFTYPE_AP: | ||
129 | sdata->bss = &sdata->u.ap; | ||
130 | break; | ||
131 | case NL80211_IFTYPE_MESH_POINT: | ||
132 | if (!ieee80211_vif_is_mesh(&sdata->vif)) | ||
133 | break; | ||
134 | /* mesh ifaces must set allmulti to forward mcast traffic */ | ||
135 | atomic_inc(&local->iff_allmultis); | ||
136 | break; | ||
137 | case NL80211_IFTYPE_STATION: | ||
138 | case NL80211_IFTYPE_MONITOR: | ||
139 | case NL80211_IFTYPE_ADHOC: | ||
140 | /* no special treatment */ | ||
141 | break; | ||
142 | case NL80211_IFTYPE_UNSPECIFIED: | ||
143 | case __NL80211_IFTYPE_AFTER_LAST: | ||
144 | /* cannot happen */ | ||
145 | WARN_ON(1); | ||
146 | break; | ||
147 | } | ||
148 | |||
149 | if (local->open_count == 0) { | ||
150 | res = 0; | ||
151 | if (local->ops->start) | ||
152 | res = local->ops->start(local_to_hw(local)); | ||
153 | if (res) | ||
154 | goto err_del_bss; | ||
155 | need_hw_reconfig = 1; | ||
156 | ieee80211_led_radio(local, local->hw.conf.radio_enabled); | ||
157 | } | ||
158 | |||
159 | /* | ||
160 | * Check all interfaces and copy the hopefully now-present | ||
161 | * MAC address to those that have the special null one. | ||
162 | */ | ||
163 | list_for_each_entry(nsdata, &local->interfaces, list) { | ||
164 | struct net_device *ndev = nsdata->dev; | ||
165 | |||
166 | /* | ||
167 | * No need to check netif_running since we do not allow | ||
168 | * it to start up with this invalid address. | ||
169 | */ | ||
170 | if (compare_ether_addr(null_addr, ndev->dev_addr) == 0) | ||
171 | memcpy(ndev->dev_addr, | ||
172 | local->hw.wiphy->perm_addr, | ||
173 | ETH_ALEN); | ||
174 | } | ||
175 | |||
176 | if (compare_ether_addr(null_addr, local->mdev->dev_addr) == 0) | ||
177 | memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, | ||
178 | ETH_ALEN); | ||
179 | |||
180 | /* | ||
181 | * Validate the MAC address for this device. | ||
182 | */ | ||
183 | if (!is_valid_ether_addr(dev->dev_addr)) { | ||
184 | if (!local->open_count && local->ops->stop) | ||
185 | local->ops->stop(local_to_hw(local)); | ||
186 | return -EADDRNOTAVAIL; | ||
187 | } | ||
188 | |||
189 | switch (sdata->vif.type) { | ||
190 | case NL80211_IFTYPE_AP_VLAN: | ||
191 | /* no need to tell driver */ | ||
192 | break; | ||
193 | case NL80211_IFTYPE_MONITOR: | ||
194 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { | ||
195 | local->cooked_mntrs++; | ||
196 | break; | ||
197 | } | ||
198 | |||
199 | /* must be before the call to ieee80211_configure_filter */ | ||
200 | local->monitors++; | ||
201 | if (local->monitors == 1) | ||
202 | local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP; | ||
203 | |||
204 | if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) | ||
205 | local->fif_fcsfail++; | ||
206 | if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) | ||
207 | local->fif_plcpfail++; | ||
208 | if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) | ||
209 | local->fif_control++; | ||
210 | if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) | ||
211 | local->fif_other_bss++; | ||
212 | |||
213 | netif_addr_lock_bh(local->mdev); | ||
214 | ieee80211_configure_filter(local); | ||
215 | netif_addr_unlock_bh(local->mdev); | ||
216 | break; | ||
217 | case NL80211_IFTYPE_STATION: | ||
218 | case NL80211_IFTYPE_ADHOC: | ||
219 | sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET; | ||
220 | /* fall through */ | ||
221 | default: | ||
222 | conf.vif = &sdata->vif; | ||
223 | conf.type = sdata->vif.type; | ||
224 | conf.mac_addr = dev->dev_addr; | ||
225 | res = local->ops->add_interface(local_to_hw(local), &conf); | ||
226 | if (res) | ||
227 | goto err_stop; | ||
228 | |||
229 | if (ieee80211_vif_is_mesh(&sdata->vif)) | ||
230 | ieee80211_start_mesh(sdata); | ||
231 | changed |= ieee80211_reset_erp_info(sdata); | ||
232 | ieee80211_bss_info_change_notify(sdata, changed); | ||
233 | ieee80211_enable_keys(sdata); | ||
234 | |||
235 | if (sdata->vif.type == NL80211_IFTYPE_STATION && | ||
236 | !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)) | ||
237 | netif_carrier_off(dev); | ||
238 | else | ||
239 | netif_carrier_on(dev); | ||
240 | } | ||
241 | |||
242 | if (sdata->vif.type == NL80211_IFTYPE_WDS) { | ||
243 | /* Create STA entry for the WDS peer */ | ||
244 | sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr, | ||
245 | GFP_KERNEL); | ||
246 | if (!sta) { | ||
247 | res = -ENOMEM; | ||
248 | goto err_del_interface; | ||
249 | } | ||
250 | |||
251 | /* no locking required since STA is not live yet */ | ||
252 | sta->flags |= WLAN_STA_AUTHORIZED; | ||
253 | |||
254 | res = sta_info_insert(sta); | ||
255 | if (res) { | ||
256 | /* STA has been freed */ | ||
257 | goto err_del_interface; | ||
258 | } | ||
259 | } | ||
260 | |||
261 | if (local->open_count == 0) { | ||
262 | res = dev_open(local->mdev); | ||
263 | WARN_ON(res); | ||
264 | if (res) | ||
265 | goto err_del_interface; | ||
266 | tasklet_enable(&local->tx_pending_tasklet); | ||
267 | tasklet_enable(&local->tasklet); | ||
268 | } | ||
269 | |||
270 | /* | ||
271 | * set_multicast_list will be invoked by the networking core | ||
272 | * which will check whether any increments here were done in | ||
273 | * error and sync them down to the hardware as filter flags. | ||
274 | */ | ||
275 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) | ||
276 | atomic_inc(&local->iff_allmultis); | ||
277 | |||
278 | if (sdata->flags & IEEE80211_SDATA_PROMISC) | ||
279 | atomic_inc(&local->iff_promiscs); | ||
280 | |||
281 | local->open_count++; | ||
282 | if (need_hw_reconfig) { | ||
283 | ieee80211_hw_config(local); | ||
284 | /* | ||
285 | * set default queue parameters so drivers don't | ||
286 | * need to initialise the hardware if the hardware | ||
287 | * doesn't start up with sane defaults | ||
288 | */ | ||
289 | ieee80211_set_wmm_default(sdata); | ||
290 | } | ||
291 | |||
292 | /* | ||
293 | * ieee80211_sta_work is disabled while network interface | ||
294 | * is down. Therefore, some configuration changes may not | ||
295 | * yet be effective. Trigger execution of ieee80211_sta_work | ||
296 | * to fix this. | ||
297 | */ | ||
298 | if (sdata->vif.type == NL80211_IFTYPE_STATION || | ||
299 | sdata->vif.type == NL80211_IFTYPE_ADHOC) { | ||
300 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; | ||
301 | queue_work(local->hw.workqueue, &ifsta->work); | ||
302 | } | ||
303 | |||
304 | netif_tx_start_all_queues(dev); | ||
305 | |||
306 | return 0; | ||
307 | err_del_interface: | ||
308 | local->ops->remove_interface(local_to_hw(local), &conf); | ||
309 | err_stop: | ||
310 | if (!local->open_count && local->ops->stop) | ||
311 | local->ops->stop(local_to_hw(local)); | ||
312 | err_del_bss: | ||
313 | sdata->bss = NULL; | ||
314 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) | ||
315 | list_del(&sdata->u.vlan.list); | ||
316 | return res; | ||
317 | } | ||
318 | |||
319 | static int ieee80211_stop(struct net_device *dev) | ||
320 | { | ||
321 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | ||
322 | struct ieee80211_local *local = sdata->local; | ||
323 | struct ieee80211_if_init_conf conf; | ||
324 | struct sta_info *sta; | ||
325 | |||
326 | /* | ||
327 | * Stop TX on this interface first. | ||
328 | */ | ||
329 | netif_tx_stop_all_queues(dev); | ||
330 | |||
331 | /* | ||
332 | * Now delete all active aggregation sessions. | ||
333 | */ | ||
334 | rcu_read_lock(); | ||
335 | |||
336 | list_for_each_entry_rcu(sta, &local->sta_list, list) { | ||
337 | if (sta->sdata == sdata) | ||
338 | ieee80211_sta_tear_down_BA_sessions(sdata, | ||
339 | sta->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_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | ||
515 | struct ieee80211_local *local = sdata->local; | ||
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 | } | ||
20 | 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. |
@@ -31,17 +565,17 @@ static void ieee80211_teardown_sdata(struct net_device *dev) | |||
31 | int flushed; | 565 | int flushed; |
32 | int i; | 566 | int i; |
33 | 567 | ||
34 | ieee80211_debugfs_remove_netdev(sdata); | ||
35 | |||
36 | /* free extra data */ | 568 | /* free extra data */ |
37 | ieee80211_free_keys(sdata); | 569 | ieee80211_free_keys(sdata); |
38 | 570 | ||
571 | ieee80211_debugfs_remove_netdev(sdata); | ||
572 | |||
39 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) | 573 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) |
40 | __skb_queue_purge(&sdata->fragments[i].skb_list); | 574 | __skb_queue_purge(&sdata->fragments[i].skb_list); |
41 | sdata->fragment_next = 0; | 575 | sdata->fragment_next = 0; |
42 | 576 | ||
43 | switch (sdata->vif.type) { | 577 | switch (sdata->vif.type) { |
44 | case IEEE80211_IF_TYPE_AP: | 578 | case NL80211_IFTYPE_AP: |
45 | beacon = sdata->u.ap.beacon; | 579 | beacon = sdata->u.ap.beacon; |
46 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); | 580 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); |
47 | synchronize_rcu(); | 581 | synchronize_rcu(); |
@@ -53,23 +587,23 @@ static void ieee80211_teardown_sdata(struct net_device *dev) | |||
53 | } | 587 | } |
54 | 588 | ||
55 | break; | 589 | break; |
56 | case IEEE80211_IF_TYPE_MESH_POINT: | 590 | case NL80211_IFTYPE_MESH_POINT: |
57 | /* Allow compiler to elide mesh_rmc_free call. */ | ||
58 | if (ieee80211_vif_is_mesh(&sdata->vif)) | 591 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
59 | mesh_rmc_free(dev); | 592 | mesh_rmc_free(sdata); |
60 | /* fall through */ | 593 | break; |
61 | case IEEE80211_IF_TYPE_STA: | 594 | case NL80211_IFTYPE_STATION: |
62 | case IEEE80211_IF_TYPE_IBSS: | 595 | case NL80211_IFTYPE_ADHOC: |
63 | kfree(sdata->u.sta.extra_ie); | 596 | kfree(sdata->u.sta.extra_ie); |
64 | kfree(sdata->u.sta.assocreq_ies); | 597 | kfree(sdata->u.sta.assocreq_ies); |
65 | kfree(sdata->u.sta.assocresp_ies); | 598 | kfree(sdata->u.sta.assocresp_ies); |
66 | kfree_skb(sdata->u.sta.probe_resp); | 599 | kfree_skb(sdata->u.sta.probe_resp); |
67 | break; | 600 | break; |
68 | case IEEE80211_IF_TYPE_WDS: | 601 | case NL80211_IFTYPE_WDS: |
69 | case IEEE80211_IF_TYPE_VLAN: | 602 | case NL80211_IFTYPE_AP_VLAN: |
70 | case IEEE80211_IF_TYPE_MNTR: | 603 | case NL80211_IFTYPE_MONITOR: |
71 | break; | 604 | break; |
72 | case IEEE80211_IF_TYPE_INVALID: | 605 | case NL80211_IFTYPE_UNSPECIFIED: |
606 | case __NL80211_IFTYPE_AFTER_LAST: | ||
73 | BUG(); | 607 | BUG(); |
74 | break; | 608 | break; |
75 | } | 609 | } |
@@ -82,55 +616,43 @@ static void ieee80211_teardown_sdata(struct net_device *dev) | |||
82 | * Helper function to initialise an interface to a specific type. | 616 | * Helper function to initialise an interface to a specific type. |
83 | */ | 617 | */ |
84 | static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata, | 618 | static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata, |
85 | enum ieee80211_if_types type) | 619 | enum nl80211_iftype type) |
86 | { | 620 | { |
87 | struct ieee80211_if_sta *ifsta; | ||
88 | |||
89 | /* clear type-dependent union */ | 621 | /* clear type-dependent union */ |
90 | memset(&sdata->u, 0, sizeof(sdata->u)); | 622 | memset(&sdata->u, 0, sizeof(sdata->u)); |
91 | 623 | ||
92 | /* and set some type-dependent values */ | 624 | /* and set some type-dependent values */ |
93 | sdata->vif.type = type; | 625 | sdata->vif.type = type; |
626 | sdata->dev->hard_start_xmit = ieee80211_subif_start_xmit; | ||
627 | sdata->wdev.iftype = type; | ||
94 | 628 | ||
95 | /* only monitor differs */ | 629 | /* only monitor differs */ |
96 | sdata->dev->type = ARPHRD_ETHER; | 630 | sdata->dev->type = ARPHRD_ETHER; |
97 | 631 | ||
98 | switch (type) { | 632 | switch (type) { |
99 | case IEEE80211_IF_TYPE_AP: | 633 | case NL80211_IFTYPE_AP: |
100 | skb_queue_head_init(&sdata->u.ap.ps_bc_buf); | 634 | skb_queue_head_init(&sdata->u.ap.ps_bc_buf); |
101 | INIT_LIST_HEAD(&sdata->u.ap.vlans); | 635 | INIT_LIST_HEAD(&sdata->u.ap.vlans); |
102 | break; | 636 | break; |
103 | case IEEE80211_IF_TYPE_MESH_POINT: | 637 | case NL80211_IFTYPE_STATION: |
104 | case IEEE80211_IF_TYPE_STA: | 638 | case NL80211_IFTYPE_ADHOC: |
105 | case IEEE80211_IF_TYPE_IBSS: | 639 | ieee80211_sta_setup_sdata(sdata); |
106 | ifsta = &sdata->u.sta; | 640 | break; |
107 | INIT_WORK(&ifsta->work, ieee80211_sta_work); | 641 | case NL80211_IFTYPE_MESH_POINT: |
108 | setup_timer(&ifsta->timer, ieee80211_sta_timer, | ||
109 | (unsigned long) sdata); | ||
110 | skb_queue_head_init(&ifsta->skb_queue); | ||
111 | |||
112 | ifsta->capab = WLAN_CAPABILITY_ESS; | ||
113 | ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN | | ||
114 | IEEE80211_AUTH_ALG_SHARED_KEY; | ||
115 | ifsta->flags |= IEEE80211_STA_CREATE_IBSS | | ||
116 | IEEE80211_STA_AUTO_BSSID_SEL | | ||
117 | IEEE80211_STA_AUTO_CHANNEL_SEL; | ||
118 | if (ieee80211_num_regular_queues(&sdata->local->hw) >= 4) | ||
119 | ifsta->flags |= IEEE80211_STA_WMM_ENABLED; | ||
120 | |||
121 | if (ieee80211_vif_is_mesh(&sdata->vif)) | 642 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
122 | ieee80211_mesh_init_sdata(sdata); | 643 | ieee80211_mesh_init_sdata(sdata); |
123 | break; | 644 | break; |
124 | case IEEE80211_IF_TYPE_MNTR: | 645 | case NL80211_IFTYPE_MONITOR: |
125 | sdata->dev->type = ARPHRD_IEEE80211_RADIOTAP; | 646 | sdata->dev->type = ARPHRD_IEEE80211_RADIOTAP; |
126 | sdata->dev->hard_start_xmit = ieee80211_monitor_start_xmit; | 647 | sdata->dev->hard_start_xmit = ieee80211_monitor_start_xmit; |
127 | sdata->u.mntr_flags = MONITOR_FLAG_CONTROL | | 648 | sdata->u.mntr_flags = MONITOR_FLAG_CONTROL | |
128 | MONITOR_FLAG_OTHER_BSS; | 649 | MONITOR_FLAG_OTHER_BSS; |
129 | break; | 650 | break; |
130 | case IEEE80211_IF_TYPE_WDS: | 651 | case NL80211_IFTYPE_WDS: |
131 | case IEEE80211_IF_TYPE_VLAN: | 652 | case NL80211_IFTYPE_AP_VLAN: |
132 | break; | 653 | break; |
133 | case IEEE80211_IF_TYPE_INVALID: | 654 | case NL80211_IFTYPE_UNSPECIFIED: |
655 | case __NL80211_IFTYPE_AFTER_LAST: | ||
134 | BUG(); | 656 | BUG(); |
135 | break; | 657 | break; |
136 | } | 658 | } |
@@ -139,7 +661,7 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata, | |||
139 | } | 661 | } |
140 | 662 | ||
141 | int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata, | 663 | int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata, |
142 | enum ieee80211_if_types type) | 664 | enum nl80211_iftype type) |
143 | { | 665 | { |
144 | ASSERT_RTNL(); | 666 | ASSERT_RTNL(); |
145 | 667 | ||
@@ -160,14 +682,16 @@ int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata, | |||
160 | ieee80211_setup_sdata(sdata, type); | 682 | ieee80211_setup_sdata(sdata, type); |
161 | 683 | ||
162 | /* reset some values that shouldn't be kept across type changes */ | 684 | /* reset some values that shouldn't be kept across type changes */ |
163 | sdata->basic_rates = 0; | 685 | sdata->bss_conf.basic_rates = |
686 | ieee80211_mandatory_rates(sdata->local, | ||
687 | sdata->local->hw.conf.channel->band); | ||
164 | sdata->drop_unencrypted = 0; | 688 | sdata->drop_unencrypted = 0; |
165 | 689 | ||
166 | return 0; | 690 | return 0; |
167 | } | 691 | } |
168 | 692 | ||
169 | int ieee80211_if_add(struct ieee80211_local *local, const char *name, | 693 | int ieee80211_if_add(struct ieee80211_local *local, const char *name, |
170 | struct net_device **new_dev, enum ieee80211_if_types type, | 694 | struct net_device **new_dev, enum nl80211_iftype type, |
171 | struct vif_params *params) | 695 | struct vif_params *params) |
172 | { | 696 | { |
173 | struct net_device *ndev; | 697 | struct net_device *ndev; |
@@ -225,9 +749,9 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name, | |||
225 | 749 | ||
226 | if (ieee80211_vif_is_mesh(&sdata->vif) && | 750 | if (ieee80211_vif_is_mesh(&sdata->vif) && |
227 | params && params->mesh_id_len) | 751 | params && params->mesh_id_len) |
228 | ieee80211_if_sta_set_mesh_id(&sdata->u.sta, | 752 | ieee80211_sdata_set_mesh_id(sdata, |
229 | params->mesh_id_len, | 753 | params->mesh_id_len, |
230 | params->mesh_id); | 754 | params->mesh_id); |
231 | 755 | ||
232 | list_add_tail_rcu(&sdata->list, &local->interfaces); | 756 | list_add_tail_rcu(&sdata->list, &local->interfaces); |
233 | 757 | ||
@@ -241,15 +765,13 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name, | |||
241 | return ret; | 765 | return ret; |
242 | } | 766 | } |
243 | 767 | ||
244 | void ieee80211_if_remove(struct net_device *dev) | 768 | void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata) |
245 | { | 769 | { |
246 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | ||
247 | |||
248 | ASSERT_RTNL(); | 770 | ASSERT_RTNL(); |
249 | 771 | ||
250 | list_del_rcu(&sdata->list); | 772 | list_del_rcu(&sdata->list); |
251 | synchronize_rcu(); | 773 | synchronize_rcu(); |
252 | unregister_netdevice(dev); | 774 | unregister_netdevice(sdata->dev); |
253 | } | 775 | } |
254 | 776 | ||
255 | /* | 777 | /* |