aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211/iface.c
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /net/mac80211/iface.c
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'net/mac80211/iface.c')
-rw-r--r--net/mac80211/iface.c529
1 files changed, 329 insertions, 200 deletions
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index ebbe264e2b0b..dee30aea9ab3 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -24,6 +24,7 @@
24#include "led.h" 24#include "led.h"
25#include "driver-ops.h" 25#include "driver-ops.h"
26#include "wme.h" 26#include "wme.h"
27#include "rate.h"
27 28
28/** 29/**
29 * DOC: Interface list locking 30 * DOC: Interface list locking
@@ -94,21 +95,14 @@ static inline int identical_mac_addr_allowed(int type1, int type2)
94 type2 == NL80211_IFTYPE_AP_VLAN)); 95 type2 == NL80211_IFTYPE_AP_VLAN));
95} 96}
96 97
97static int ieee80211_open(struct net_device *dev) 98static int ieee80211_check_concurrent_iface(struct ieee80211_sub_if_data *sdata,
99 enum nl80211_iftype iftype)
98{ 100{
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; 101 struct ieee80211_local *local = sdata->local;
102 struct sta_info *sta; 102 struct ieee80211_sub_if_data *nsdata;
103 u32 changed = 0; 103 struct net_device *dev = sdata->dev;
104 int res;
105 u32 hw_reconf_flags = 0;
106 u8 null_addr[ETH_ALEN] = {0};
107 104
108 /* fail early if user set an invalid address */ 105 ASSERT_RTNL();
109 if (compare_ether_addr(dev->dev_addr, null_addr) &&
110 !is_valid_ether_addr(dev->dev_addr))
111 return -EADDRNOTAVAIL;
112 106
113 /* we hold the RTNL here so can safely walk the list */ 107 /* we hold the RTNL here so can safely walk the list */
114 list_for_each_entry(nsdata, &local->interfaces, list) { 108 list_for_each_entry(nsdata, &local->interfaces, list) {
@@ -125,7 +119,7 @@ static int ieee80211_open(struct net_device *dev)
125 * belonging to the same hardware. Then, however, we're 119 * belonging to the same hardware. Then, however, we're
126 * faced with having to adopt two different TSF timers... 120 * faced with having to adopt two different TSF timers...
127 */ 121 */
128 if (sdata->vif.type == NL80211_IFTYPE_ADHOC && 122 if (iftype == NL80211_IFTYPE_ADHOC &&
129 nsdata->vif.type == NL80211_IFTYPE_ADHOC) 123 nsdata->vif.type == NL80211_IFTYPE_ADHOC)
130 return -EBUSY; 124 return -EBUSY;
131 125
@@ -139,19 +133,56 @@ static int ieee80211_open(struct net_device *dev)
139 /* 133 /*
140 * check whether it may have the same address 134 * check whether it may have the same address
141 */ 135 */
142 if (!identical_mac_addr_allowed(sdata->vif.type, 136 if (!identical_mac_addr_allowed(iftype,
143 nsdata->vif.type)) 137 nsdata->vif.type))
144 return -ENOTUNIQ; 138 return -ENOTUNIQ;
145 139
146 /* 140 /*
147 * can only add VLANs to enabled APs 141 * can only add VLANs to enabled APs
148 */ 142 */
149 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN && 143 if (iftype == NL80211_IFTYPE_AP_VLAN &&
150 nsdata->vif.type == NL80211_IFTYPE_AP) 144 nsdata->vif.type == NL80211_IFTYPE_AP)
151 sdata->bss = &nsdata->u.ap; 145 sdata->bss = &nsdata->u.ap;
152 } 146 }
153 } 147 }
154 148
149 return 0;
150}
151
152void ieee80211_adjust_monitor_flags(struct ieee80211_sub_if_data *sdata,
153 const int offset)
154{
155 struct ieee80211_local *local = sdata->local;
156 u32 flags = sdata->u.mntr_flags;
157
158#define ADJUST(_f, _s) do { \
159 if (flags & MONITOR_FLAG_##_f) \
160 local->fif_##_s += offset; \
161 } while (0)
162
163 ADJUST(FCSFAIL, fcsfail);
164 ADJUST(PLCPFAIL, plcpfail);
165 ADJUST(CONTROL, control);
166 ADJUST(CONTROL, pspoll);
167 ADJUST(OTHER_BSS, other_bss);
168
169#undef ADJUST
170}
171
172/*
173 * NOTE: Be very careful when changing this function, it must NOT return
174 * an error on interface type changes that have been pre-checked, so most
175 * checks should be in ieee80211_check_concurrent_iface.
176 */
177static int ieee80211_do_open(struct net_device *dev, bool coming_up)
178{
179 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
180 struct ieee80211_local *local = sdata->local;
181 struct sta_info *sta;
182 u32 changed = 0;
183 int res;
184 u32 hw_reconf_flags = 0;
185
155 switch (sdata->vif.type) { 186 switch (sdata->vif.type) {
156 case NL80211_IFTYPE_WDS: 187 case NL80211_IFTYPE_WDS:
157 if (!is_valid_ether_addr(sdata->u.wds.remote_addr)) 188 if (!is_valid_ether_addr(sdata->u.wds.remote_addr))
@@ -166,18 +197,15 @@ static int ieee80211_open(struct net_device *dev)
166 sdata->bss = &sdata->u.ap; 197 sdata->bss = &sdata->u.ap;
167 break; 198 break;
168 case NL80211_IFTYPE_MESH_POINT: 199 case NL80211_IFTYPE_MESH_POINT:
169 if (!ieee80211_vif_is_mesh(&sdata->vif))
170 break;
171 /* mesh ifaces must set allmulti to forward mcast traffic */
172 atomic_inc(&local->iff_allmultis);
173 break;
174 case NL80211_IFTYPE_STATION: 200 case NL80211_IFTYPE_STATION:
175 case NL80211_IFTYPE_MONITOR: 201 case NL80211_IFTYPE_MONITOR:
176 case NL80211_IFTYPE_ADHOC: 202 case NL80211_IFTYPE_ADHOC:
177 /* no special treatment */ 203 /* no special treatment */
178 break; 204 break;
179 case NL80211_IFTYPE_UNSPECIFIED: 205 case NL80211_IFTYPE_UNSPECIFIED:
180 case __NL80211_IFTYPE_AFTER_LAST: 206 case NUM_NL80211_IFTYPES:
207 case NL80211_IFTYPE_P2P_CLIENT:
208 case NL80211_IFTYPE_P2P_GO:
181 /* cannot happen */ 209 /* cannot happen */
182 WARN_ON(1); 210 WARN_ON(1);
183 break; 211 break;
@@ -187,39 +215,32 @@ static int ieee80211_open(struct net_device *dev)
187 res = drv_start(local); 215 res = drv_start(local);
188 if (res) 216 if (res)
189 goto err_del_bss; 217 goto err_del_bss;
218 if (local->ops->napi_poll)
219 napi_enable(&local->napi);
190 /* we're brought up, everything changes */ 220 /* we're brought up, everything changes */
191 hw_reconf_flags = ~0; 221 hw_reconf_flags = ~0;
192 ieee80211_led_radio(local, true); 222 ieee80211_led_radio(local, true);
223 ieee80211_mod_tpt_led_trig(local,
224 IEEE80211_TPT_LEDTRIG_FL_RADIO, 0);
193 } 225 }
194 226
195 /* 227 /*
196 * Check all interfaces and copy the hopefully now-present 228 * Copy the hopefully now-present MAC address to
197 * MAC address to those that have the special null one. 229 * this interface, if it has the special null one.
198 */ 230 */
199 list_for_each_entry(nsdata, &local->interfaces, list) { 231 if (is_zero_ether_addr(dev->dev_addr)) {
200 struct net_device *ndev = nsdata->dev; 232 memcpy(dev->dev_addr,
201 233 local->hw.wiphy->perm_addr,
202 /* 234 ETH_ALEN);
203 * No need to check running since we do not allow 235 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
204 * it to start up with this invalid address. 236
205 */ 237 if (!is_valid_ether_addr(dev->dev_addr)) {
206 if (compare_ether_addr(null_addr, ndev->dev_addr) == 0) { 238 if (!local->open_count)
207 memcpy(ndev->dev_addr, 239 drv_stop(local);
208 local->hw.wiphy->perm_addr, 240 return -EADDRNOTAVAIL;
209 ETH_ALEN);
210 memcpy(ndev->perm_addr, ndev->dev_addr, ETH_ALEN);
211 } 241 }
212 } 242 }
213 243
214 /*
215 * Validate the MAC address for this device.
216 */
217 if (!is_valid_ether_addr(dev->dev_addr)) {
218 if (!local->open_count)
219 drv_stop(local);
220 return -EADDRNOTAVAIL;
221 }
222
223 switch (sdata->vif.type) { 244 switch (sdata->vif.type) {
224 case NL80211_IFTYPE_AP_VLAN: 245 case NL80211_IFTYPE_AP_VLAN:
225 /* no need to tell driver */ 246 /* no need to tell driver */
@@ -237,35 +258,25 @@ static int ieee80211_open(struct net_device *dev)
237 hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR; 258 hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
238 } 259 }
239 260
240 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) 261 ieee80211_adjust_monitor_flags(sdata, 1);
241 local->fif_fcsfail++;
242 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
243 local->fif_plcpfail++;
244 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) {
245 local->fif_control++;
246 local->fif_pspoll++;
247 }
248 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
249 local->fif_other_bss++;
250
251 ieee80211_configure_filter(local); 262 ieee80211_configure_filter(local);
252 263
253 netif_carrier_on(dev); 264 netif_carrier_on(dev);
254 break; 265 break;
255 default: 266 default:
256 res = drv_add_interface(local, &sdata->vif); 267 if (coming_up) {
257 if (res) 268 res = drv_add_interface(local, &sdata->vif);
258 goto err_stop; 269 if (res)
259 270 goto err_stop;
260 if (ieee80211_vif_is_mesh(&sdata->vif)) { 271 }
261 local->fif_other_bss++;
262 ieee80211_configure_filter(local);
263 272
264 ieee80211_start_mesh(sdata); 273 if (sdata->vif.type == NL80211_IFTYPE_AP) {
265 } else if (sdata->vif.type == NL80211_IFTYPE_AP) {
266 local->fif_pspoll++; 274 local->fif_pspoll++;
275 local->fif_probe_req++;
267 276
268 ieee80211_configure_filter(local); 277 ieee80211_configure_filter(local);
278 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
279 local->fif_probe_req++;
269 } 280 }
270 281
271 changed |= ieee80211_reset_erp_info(sdata); 282 changed |= ieee80211_reset_erp_info(sdata);
@@ -277,6 +288,8 @@ static int ieee80211_open(struct net_device *dev)
277 netif_carrier_on(dev); 288 netif_carrier_on(dev);
278 } 289 }
279 290
291 set_bit(SDATA_STATE_RUNNING, &sdata->state);
292
280 if (sdata->vif.type == NL80211_IFTYPE_WDS) { 293 if (sdata->vif.type == NL80211_IFTYPE_WDS) {
281 /* Create STA entry for the WDS peer */ 294 /* Create STA entry for the WDS peer */
282 sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr, 295 sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
@@ -294,6 +307,8 @@ static int ieee80211_open(struct net_device *dev)
294 /* STA has been freed */ 307 /* STA has been freed */
295 goto err_del_interface; 308 goto err_del_interface;
296 } 309 }
310
311 rate_control_rate_init(sta);
297 } 312 }
298 313
299 /* 314 /*
@@ -307,9 +322,13 @@ static int ieee80211_open(struct net_device *dev)
307 if (sdata->flags & IEEE80211_SDATA_PROMISC) 322 if (sdata->flags & IEEE80211_SDATA_PROMISC)
308 atomic_inc(&local->iff_promiscs); 323 atomic_inc(&local->iff_promiscs);
309 324
325 mutex_lock(&local->mtx);
310 hw_reconf_flags |= __ieee80211_recalc_idle(local); 326 hw_reconf_flags |= __ieee80211_recalc_idle(local);
327 mutex_unlock(&local->mtx);
328
329 if (coming_up)
330 local->open_count++;
311 331
312 local->open_count++;
313 if (hw_reconf_flags) { 332 if (hw_reconf_flags) {
314 ieee80211_hw_config(local, hw_reconf_flags); 333 ieee80211_hw_config(local, hw_reconf_flags);
315 /* 334 /*
@@ -334,22 +353,46 @@ static int ieee80211_open(struct net_device *dev)
334 sdata->bss = NULL; 353 sdata->bss = NULL;
335 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 354 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
336 list_del(&sdata->u.vlan.list); 355 list_del(&sdata->u.vlan.list);
356 clear_bit(SDATA_STATE_RUNNING, &sdata->state);
337 return res; 357 return res;
338} 358}
339 359
340static int ieee80211_stop(struct net_device *dev) 360static int ieee80211_open(struct net_device *dev)
341{ 361{
342 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 362 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
363 int err;
364
365 /* fail early if user set an invalid address */
366 if (!is_zero_ether_addr(dev->dev_addr) &&
367 !is_valid_ether_addr(dev->dev_addr))
368 return -EADDRNOTAVAIL;
369
370 err = ieee80211_check_concurrent_iface(sdata, sdata->vif.type);
371 if (err)
372 return err;
373
374 return ieee80211_do_open(dev, true);
375}
376
377static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
378 bool going_down)
379{
343 struct ieee80211_local *local = sdata->local; 380 struct ieee80211_local *local = sdata->local;
344 unsigned long flags; 381 unsigned long flags;
345 struct sk_buff *skb, *tmp; 382 struct sk_buff *skb, *tmp;
346 u32 hw_reconf_flags = 0; 383 u32 hw_reconf_flags = 0;
347 int i; 384 int i;
385 enum nl80211_channel_type orig_ct;
386
387 clear_bit(SDATA_STATE_RUNNING, &sdata->state);
388
389 if (local->scan_sdata == sdata)
390 ieee80211_scan_cancel(local);
348 391
349 /* 392 /*
350 * Stop TX on this interface first. 393 * Stop TX on this interface first.
351 */ 394 */
352 netif_tx_stop_all_queues(dev); 395 netif_tx_stop_all_queues(sdata->dev);
353 396
354 /* 397 /*
355 * Purge work for this interface. 398 * Purge work for this interface.
@@ -366,12 +409,9 @@ static int ieee80211_stop(struct net_device *dev)
366 * (because if we remove a STA after ops->remove_interface() 409 * (because if we remove a STA after ops->remove_interface()
367 * the driver will have removed the vif info already!) 410 * the driver will have removed the vif info already!)
368 * 411 *
369 * We could relax this and only unlink the stations from the 412 * This is relevant only in AP, WDS and mesh modes, since in
370 * hash table and list but keep them on a per-sdata list that 413 * all other modes we've already removed all stations when
371 * will be inserted back again when the interface is brought 414 * disconnecting etc.
372 * up again, but I don't currently see a use case for that,
373 * except with WDS which gets a STA entry created when it is
374 * brought up.
375 */ 415 */
376 sta_info_flush(local, sdata); 416 sta_info_flush(local, sdata);
377 417
@@ -387,14 +427,19 @@ static int ieee80211_stop(struct net_device *dev)
387 if (sdata->flags & IEEE80211_SDATA_PROMISC) 427 if (sdata->flags & IEEE80211_SDATA_PROMISC)
388 atomic_dec(&local->iff_promiscs); 428 atomic_dec(&local->iff_promiscs);
389 429
390 if (sdata->vif.type == NL80211_IFTYPE_AP) 430 if (sdata->vif.type == NL80211_IFTYPE_AP) {
391 local->fif_pspoll--; 431 local->fif_pspoll--;
432 local->fif_probe_req--;
433 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
434 local->fif_probe_req--;
435 }
392 436
393 netif_addr_lock_bh(dev); 437 netif_addr_lock_bh(sdata->dev);
394 spin_lock_bh(&local->filter_lock); 438 spin_lock_bh(&local->filter_lock);
395 __hw_addr_unsync(&local->mc_list, &dev->mc, dev->addr_len); 439 __hw_addr_unsync(&local->mc_list, &sdata->dev->mc,
440 sdata->dev->addr_len);
396 spin_unlock_bh(&local->filter_lock); 441 spin_unlock_bh(&local->filter_lock);
397 netif_addr_unlock_bh(dev); 442 netif_addr_unlock_bh(sdata->dev);
398 443
399 ieee80211_configure_filter(local); 444 ieee80211_configure_filter(local);
400 445
@@ -404,13 +449,24 @@ static int ieee80211_stop(struct net_device *dev)
404 /* APs need special treatment */ 449 /* APs need special treatment */
405 if (sdata->vif.type == NL80211_IFTYPE_AP) { 450 if (sdata->vif.type == NL80211_IFTYPE_AP) {
406 struct ieee80211_sub_if_data *vlan, *tmpsdata; 451 struct ieee80211_sub_if_data *vlan, *tmpsdata;
407 struct beacon_data *old_beacon = sdata->u.ap.beacon; 452 struct beacon_data *old_beacon =
453 rtnl_dereference(sdata->u.ap.beacon);
454
455 /* sdata_running will return false, so this will disable */
456 ieee80211_bss_info_change_notify(sdata,
457 BSS_CHANGED_BEACON_ENABLED);
408 458
409 /* remove beacon */ 459 /* remove beacon */
410 rcu_assign_pointer(sdata->u.ap.beacon, NULL); 460 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
411 synchronize_rcu(); 461 synchronize_rcu();
412 kfree(old_beacon); 462 kfree(old_beacon);
413 463
464 /* free all potentially still buffered bcast frames */
465 while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) {
466 local->total_ps_buffered--;
467 dev_kfree_skb(skb);
468 }
469
414 /* down all dependent devices, that is VLANs */ 470 /* down all dependent devices, that is VLANs */
415 list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans, 471 list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans,
416 u.vlan.list) 472 u.vlan.list)
@@ -418,7 +474,8 @@ static int ieee80211_stop(struct net_device *dev)
418 WARN_ON(!list_empty(&sdata->u.ap.vlans)); 474 WARN_ON(!list_empty(&sdata->u.ap.vlans));
419 } 475 }
420 476
421 local->open_count--; 477 if (going_down)
478 local->open_count--;
422 479
423 switch (sdata->vif.type) { 480 switch (sdata->vif.type) {
424 case NL80211_IFTYPE_AP_VLAN: 481 case NL80211_IFTYPE_AP_VLAN:
@@ -437,52 +494,9 @@ static int ieee80211_stop(struct net_device *dev)
437 hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR; 494 hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
438 } 495 }
439 496
440 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) 497 ieee80211_adjust_monitor_flags(sdata, -1);
441 local->fif_fcsfail--;
442 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
443 local->fif_plcpfail--;
444 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) {
445 local->fif_pspoll--;
446 local->fif_control--;
447 }
448 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
449 local->fif_other_bss--;
450
451 ieee80211_configure_filter(local); 498 ieee80211_configure_filter(local);
452 break; 499 break;
453 case NL80211_IFTYPE_STATION:
454 del_timer_sync(&sdata->u.mgd.chswitch_timer);
455 del_timer_sync(&sdata->u.mgd.timer);
456 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
457 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
458 /*
459 * If any of the timers fired while we waited for it, it will
460 * have queued its work. Now the work will be running again
461 * but will not rearm the timer again because it checks
462 * whether the interface is running, which, at this point,
463 * it no longer is.
464 */
465 cancel_work_sync(&sdata->u.mgd.chswitch_work);
466 cancel_work_sync(&sdata->u.mgd.monitor_work);
467 cancel_work_sync(&sdata->u.mgd.beacon_connection_loss_work);
468
469 /* fall through */
470 case NL80211_IFTYPE_ADHOC:
471 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
472 del_timer_sync(&sdata->u.ibss.timer);
473 /* fall through */
474 case NL80211_IFTYPE_MESH_POINT:
475 if (ieee80211_vif_is_mesh(&sdata->vif)) {
476 /* other_bss and allmulti are always set on mesh
477 * ifaces */
478 local->fif_other_bss--;
479 atomic_dec(&local->iff_allmultis);
480
481 ieee80211_configure_filter(local);
482
483 ieee80211_stop_mesh(sdata);
484 }
485 /* fall through */
486 default: 500 default:
487 flush_work(&sdata->work); 501 flush_work(&sdata->work);
488 /* 502 /*
@@ -494,31 +508,35 @@ static int ieee80211_stop(struct net_device *dev)
494 synchronize_rcu(); 508 synchronize_rcu();
495 skb_queue_purge(&sdata->skb_queue); 509 skb_queue_purge(&sdata->skb_queue);
496 510
497 if (local->scan_sdata == sdata)
498 ieee80211_scan_cancel(local);
499
500 /* 511 /*
501 * Disable beaconing for AP and mesh, IBSS can't 512 * Disable beaconing here for mesh only, AP and IBSS
502 * still be joined to a network at this point. 513 * are already taken care of.
503 */ 514 */
504 if (sdata->vif.type == NL80211_IFTYPE_AP || 515 if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
505 sdata->vif.type == NL80211_IFTYPE_MESH_POINT) {
506 ieee80211_bss_info_change_notify(sdata, 516 ieee80211_bss_info_change_notify(sdata,
507 BSS_CHANGED_BEACON_ENABLED); 517 BSS_CHANGED_BEACON_ENABLED);
508 }
509 518
510 /* free all remaining keys, there shouldn't be any */ 519 /*
520 * Free all remaining keys, there shouldn't be any,
521 * except maybe group keys in AP more or WDS?
522 */
511 ieee80211_free_keys(sdata); 523 ieee80211_free_keys(sdata);
512 drv_remove_interface(local, &sdata->vif); 524
525 if (going_down)
526 drv_remove_interface(local, &sdata->vif);
513 } 527 }
514 528
515 sdata->bss = NULL; 529 sdata->bss = NULL;
516 530
531 mutex_lock(&local->mtx);
517 hw_reconf_flags |= __ieee80211_recalc_idle(local); 532 hw_reconf_flags |= __ieee80211_recalc_idle(local);
533 mutex_unlock(&local->mtx);
518 534
519 ieee80211_recalc_ps(local, -1); 535 ieee80211_recalc_ps(local, -1);
520 536
521 if (local->open_count == 0) { 537 if (local->open_count == 0) {
538 if (local->ops->napi_poll)
539 napi_disable(&local->napi);
522 ieee80211_clear_tx_pending(local); 540 ieee80211_clear_tx_pending(local);
523 ieee80211_stop_device(local); 541 ieee80211_stop_device(local);
524 542
@@ -526,8 +544,14 @@ static int ieee80211_stop(struct net_device *dev)
526 hw_reconf_flags = 0; 544 hw_reconf_flags = 0;
527 } 545 }
528 546
547 /* Re-calculate channel-type, in case there are multiple vifs
548 * on different channel types.
549 */
550 orig_ct = local->_oper_channel_type;
551 ieee80211_set_channel_type(local, NULL, NL80211_CHAN_NO_HT);
552
529 /* do after stop to avoid reconfiguring when we stop anyway */ 553 /* do after stop to avoid reconfiguring when we stop anyway */
530 if (hw_reconf_flags) 554 if (hw_reconf_flags || (orig_ct != local->_oper_channel_type))
531 ieee80211_hw_config(local, hw_reconf_flags); 555 ieee80211_hw_config(local, hw_reconf_flags);
532 556
533 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 557 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
@@ -541,6 +565,13 @@ static int ieee80211_stop(struct net_device *dev)
541 } 565 }
542 } 566 }
543 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 567 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
568}
569
570static int ieee80211_stop(struct net_device *dev)
571{
572 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
573
574 ieee80211_do_stop(sdata, true);
544 575
545 return 0; 576 return 0;
546} 577}
@@ -585,8 +616,6 @@ static void ieee80211_teardown_sdata(struct net_device *dev)
585{ 616{
586 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 617 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
587 struct ieee80211_local *local = sdata->local; 618 struct ieee80211_local *local = sdata->local;
588 struct beacon_data *beacon;
589 struct sk_buff *skb;
590 int flushed; 619 int flushed;
591 int i; 620 int i;
592 621
@@ -599,37 +628,8 @@ static void ieee80211_teardown_sdata(struct net_device *dev)
599 __skb_queue_purge(&sdata->fragments[i].skb_list); 628 __skb_queue_purge(&sdata->fragments[i].skb_list);
600 sdata->fragment_next = 0; 629 sdata->fragment_next = 0;
601 630
602 switch (sdata->vif.type) { 631 if (ieee80211_vif_is_mesh(&sdata->vif))
603 case NL80211_IFTYPE_AP: 632 mesh_rmc_free(sdata);
604 beacon = sdata->u.ap.beacon;
605 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
606 synchronize_rcu();
607 kfree(beacon);
608
609 while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) {
610 local->total_ps_buffered--;
611 dev_kfree_skb(skb);
612 }
613
614 break;
615 case NL80211_IFTYPE_MESH_POINT:
616 if (ieee80211_vif_is_mesh(&sdata->vif))
617 mesh_rmc_free(sdata);
618 break;
619 case NL80211_IFTYPE_ADHOC:
620 if (WARN_ON(sdata->u.ibss.presp))
621 kfree_skb(sdata->u.ibss.presp);
622 break;
623 case NL80211_IFTYPE_STATION:
624 case NL80211_IFTYPE_WDS:
625 case NL80211_IFTYPE_AP_VLAN:
626 case NL80211_IFTYPE_MONITOR:
627 break;
628 case NL80211_IFTYPE_UNSPECIFIED:
629 case __NL80211_IFTYPE_AFTER_LAST:
630 BUG();
631 break;
632 }
633 633
634 flushed = sta_info_flush(local, sdata); 634 flushed = sta_info_flush(local, sdata);
635 WARN_ON(flushed); 635 WARN_ON(flushed);
@@ -791,7 +791,8 @@ static void ieee80211_iface_work(struct work_struct *work)
791 791
792 __ieee80211_stop_rx_ba_session( 792 __ieee80211_stop_rx_ba_session(
793 sta, tid, WLAN_BACK_RECIPIENT, 793 sta, tid, WLAN_BACK_RECIPIENT,
794 WLAN_REASON_QSTA_REQUIRE_SETUP); 794 WLAN_REASON_QSTA_REQUIRE_SETUP,
795 true);
795 } 796 }
796 mutex_unlock(&local->sta_mtx); 797 mutex_unlock(&local->sta_mtx);
797 } else switch (sdata->vif.type) { 798 } else switch (sdata->vif.type) {
@@ -844,9 +845,13 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
844 845
845 /* and set some type-dependent values */ 846 /* and set some type-dependent values */
846 sdata->vif.type = type; 847 sdata->vif.type = type;
848 sdata->vif.p2p = false;
847 sdata->dev->netdev_ops = &ieee80211_dataif_ops; 849 sdata->dev->netdev_ops = &ieee80211_dataif_ops;
848 sdata->wdev.iftype = type; 850 sdata->wdev.iftype = type;
849 851
852 sdata->control_port_protocol = cpu_to_be16(ETH_P_PAE);
853 sdata->control_port_no_encrypt = false;
854
850 /* only monitor differs */ 855 /* only monitor differs */
851 sdata->dev->type = ARPHRD_ETHER; 856 sdata->dev->type = ARPHRD_ETHER;
852 857
@@ -854,10 +859,20 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
854 INIT_WORK(&sdata->work, ieee80211_iface_work); 859 INIT_WORK(&sdata->work, ieee80211_iface_work);
855 860
856 switch (type) { 861 switch (type) {
862 case NL80211_IFTYPE_P2P_GO:
863 type = NL80211_IFTYPE_AP;
864 sdata->vif.type = type;
865 sdata->vif.p2p = true;
866 /* fall through */
857 case NL80211_IFTYPE_AP: 867 case NL80211_IFTYPE_AP:
858 skb_queue_head_init(&sdata->u.ap.ps_bc_buf); 868 skb_queue_head_init(&sdata->u.ap.ps_bc_buf);
859 INIT_LIST_HEAD(&sdata->u.ap.vlans); 869 INIT_LIST_HEAD(&sdata->u.ap.vlans);
860 break; 870 break;
871 case NL80211_IFTYPE_P2P_CLIENT:
872 type = NL80211_IFTYPE_STATION;
873 sdata->vif.type = type;
874 sdata->vif.p2p = true;
875 /* fall through */
861 case NL80211_IFTYPE_STATION: 876 case NL80211_IFTYPE_STATION:
862 ieee80211_sta_setup_sdata(sdata); 877 ieee80211_sta_setup_sdata(sdata);
863 break; 878 break;
@@ -878,7 +893,7 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
878 case NL80211_IFTYPE_AP_VLAN: 893 case NL80211_IFTYPE_AP_VLAN:
879 break; 894 break;
880 case NL80211_IFTYPE_UNSPECIFIED: 895 case NL80211_IFTYPE_UNSPECIFIED:
881 case __NL80211_IFTYPE_AFTER_LAST: 896 case NUM_NL80211_IFTYPES:
882 BUG(); 897 BUG();
883 break; 898 break;
884 } 899 }
@@ -886,12 +901,85 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
886 ieee80211_debugfs_add_netdev(sdata); 901 ieee80211_debugfs_add_netdev(sdata);
887} 902}
888 903
904static int ieee80211_runtime_change_iftype(struct ieee80211_sub_if_data *sdata,
905 enum nl80211_iftype type)
906{
907 struct ieee80211_local *local = sdata->local;
908 int ret, err;
909 enum nl80211_iftype internal_type = type;
910 bool p2p = false;
911
912 ASSERT_RTNL();
913
914 if (!local->ops->change_interface)
915 return -EBUSY;
916
917 switch (sdata->vif.type) {
918 case NL80211_IFTYPE_AP:
919 case NL80211_IFTYPE_STATION:
920 case NL80211_IFTYPE_ADHOC:
921 /*
922 * Could maybe also all others here?
923 * Just not sure how that interacts
924 * with the RX/config path e.g. for
925 * mesh.
926 */
927 break;
928 default:
929 return -EBUSY;
930 }
931
932 switch (type) {
933 case NL80211_IFTYPE_AP:
934 case NL80211_IFTYPE_STATION:
935 case NL80211_IFTYPE_ADHOC:
936 /*
937 * Could probably support everything
938 * but WDS here (WDS do_open can fail
939 * under memory pressure, which this
940 * code isn't prepared to handle).
941 */
942 break;
943 case NL80211_IFTYPE_P2P_CLIENT:
944 p2p = true;
945 internal_type = NL80211_IFTYPE_STATION;
946 break;
947 case NL80211_IFTYPE_P2P_GO:
948 p2p = true;
949 internal_type = NL80211_IFTYPE_AP;
950 break;
951 default:
952 return -EBUSY;
953 }
954
955 ret = ieee80211_check_concurrent_iface(sdata, internal_type);
956 if (ret)
957 return ret;
958
959 ieee80211_do_stop(sdata, false);
960
961 ieee80211_teardown_sdata(sdata->dev);
962
963 ret = drv_change_interface(local, sdata, internal_type, p2p);
964 if (ret)
965 type = sdata->vif.type;
966
967 ieee80211_setup_sdata(sdata, type);
968
969 err = ieee80211_do_open(sdata->dev, false);
970 WARN(err, "type change: do_open returned %d", err);
971
972 return ret;
973}
974
889int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata, 975int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
890 enum nl80211_iftype type) 976 enum nl80211_iftype type)
891{ 977{
978 int ret;
979
892 ASSERT_RTNL(); 980 ASSERT_RTNL();
893 981
894 if (type == sdata->vif.type) 982 if (type == ieee80211_vif_type_p2p(&sdata->vif))
895 return 0; 983 return 0;
896 984
897 /* Setting ad-hoc mode on non-IBSS channel is not supported. */ 985 /* Setting ad-hoc mode on non-IBSS channel is not supported. */
@@ -899,18 +987,15 @@ int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
899 type == NL80211_IFTYPE_ADHOC) 987 type == NL80211_IFTYPE_ADHOC)
900 return -EOPNOTSUPP; 988 return -EOPNOTSUPP;
901 989
902 /* 990 if (ieee80211_sdata_running(sdata)) {
903 * We could, here, on changes between IBSS/STA/MESH modes, 991 ret = ieee80211_runtime_change_iftype(sdata, type);
904 * invoke an MLME function instead that disassociates etc. 992 if (ret)
905 * and goes into the requested mode. 993 return ret;
906 */ 994 } else {
907 995 /* Purge and reset type-dependent state. */
908 if (ieee80211_sdata_running(sdata)) 996 ieee80211_teardown_sdata(sdata->dev);
909 return -EBUSY; 997 ieee80211_setup_sdata(sdata, type);
910 998 }
911 /* Purge and reset type-dependent state. */
912 ieee80211_teardown_sdata(sdata->dev);
913 ieee80211_setup_sdata(sdata, type);
914 999
915 /* reset some values that shouldn't be kept across type changes */ 1000 /* reset some values that shouldn't be kept across type changes */
916 sdata->vif.bss_conf.basic_rates = 1001 sdata->vif.bss_conf.basic_rates =
@@ -1107,12 +1192,6 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
1107 if (ret) 1192 if (ret)
1108 goto fail; 1193 goto fail;
1109 1194
1110 if (ieee80211_vif_is_mesh(&sdata->vif) &&
1111 params && params->mesh_id_len)
1112 ieee80211_sdata_set_mesh_id(sdata,
1113 params->mesh_id_len,
1114 params->mesh_id);
1115
1116 mutex_lock(&local->iflist_mtx); 1195 mutex_lock(&local->iflist_mtx);
1117 list_add_tail_rcu(&sdata->list, &local->interfaces); 1196 list_add_tail_rcu(&sdata->list, &local->interfaces);
1118 mutex_unlock(&local->iflist_mtx); 1197 mutex_unlock(&local->iflist_mtx);
@@ -1158,6 +1237,7 @@ void ieee80211_remove_interfaces(struct ieee80211_local *local)
1158 } 1237 }
1159 mutex_unlock(&local->iflist_mtx); 1238 mutex_unlock(&local->iflist_mtx);
1160 unregister_netdevice_many(&unreg_list); 1239 unregister_netdevice_many(&unreg_list);
1240 list_del(&unreg_list);
1161} 1241}
1162 1242
1163static u32 ieee80211_idle_off(struct ieee80211_local *local, 1243static u32 ieee80211_idle_off(struct ieee80211_local *local,
@@ -1167,8 +1247,7 @@ static u32 ieee80211_idle_off(struct ieee80211_local *local,
1167 return 0; 1247 return 0;
1168 1248
1169#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1249#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1170 printk(KERN_DEBUG "%s: device no longer idle - %s\n", 1250 wiphy_debug(local->hw.wiphy, "device no longer idle - %s\n", reason);
1171 wiphy_name(local->hw.wiphy), reason);
1172#endif 1251#endif
1173 1252
1174 local->hw.conf.flags &= ~IEEE80211_CONF_IDLE; 1253 local->hw.conf.flags &= ~IEEE80211_CONF_IDLE;
@@ -1181,8 +1260,7 @@ static u32 ieee80211_idle_on(struct ieee80211_local *local)
1181 return 0; 1260 return 0;
1182 1261
1183#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1262#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1184 printk(KERN_DEBUG "%s: device now idle\n", 1263 wiphy_debug(local->hw.wiphy, "device now idle\n");
1185 wiphy_name(local->hw.wiphy));
1186#endif 1264#endif
1187 1265
1188 drv_flush(local, false); 1266 drv_flush(local, false);
@@ -1195,28 +1273,79 @@ u32 __ieee80211_recalc_idle(struct ieee80211_local *local)
1195{ 1273{
1196 struct ieee80211_sub_if_data *sdata; 1274 struct ieee80211_sub_if_data *sdata;
1197 int count = 0; 1275 int count = 0;
1276 bool working = false, scanning = false, hw_roc = false;
1277 struct ieee80211_work *wk;
1278 unsigned int led_trig_start = 0, led_trig_stop = 0;
1198 1279
1199 if (!list_empty(&local->work_list)) 1280#ifdef CONFIG_PROVE_LOCKING
1200 return ieee80211_idle_off(local, "working"); 1281 WARN_ON(debug_locks && !lockdep_rtnl_is_held() &&
1201 1282 !lockdep_is_held(&local->iflist_mtx));
1202 if (local->scanning) 1283#endif
1203 return ieee80211_idle_off(local, "scanning"); 1284 lockdep_assert_held(&local->mtx);
1204 1285
1205 list_for_each_entry(sdata, &local->interfaces, list) { 1286 list_for_each_entry(sdata, &local->interfaces, list) {
1206 if (!ieee80211_sdata_running(sdata)) 1287 if (!ieee80211_sdata_running(sdata)) {
1288 sdata->vif.bss_conf.idle = true;
1207 continue; 1289 continue;
1290 }
1291
1292 sdata->old_idle = sdata->vif.bss_conf.idle;
1293
1208 /* do not count disabled managed interfaces */ 1294 /* do not count disabled managed interfaces */
1209 if (sdata->vif.type == NL80211_IFTYPE_STATION && 1295 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1210 !sdata->u.mgd.associated) 1296 !sdata->u.mgd.associated) {
1297 sdata->vif.bss_conf.idle = true;
1211 continue; 1298 continue;
1299 }
1212 /* do not count unused IBSS interfaces */ 1300 /* do not count unused IBSS interfaces */
1213 if (sdata->vif.type == NL80211_IFTYPE_ADHOC && 1301 if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
1214 !sdata->u.ibss.ssid_len) 1302 !sdata->u.ibss.ssid_len) {
1303 sdata->vif.bss_conf.idle = true;
1215 continue; 1304 continue;
1305 }
1216 /* count everything else */ 1306 /* count everything else */
1217 count++; 1307 count++;
1218 } 1308 }
1219 1309
1310 list_for_each_entry(wk, &local->work_list, list) {
1311 working = true;
1312 wk->sdata->vif.bss_conf.idle = false;
1313 }
1314
1315 if (local->scan_sdata) {
1316 scanning = true;
1317 local->scan_sdata->vif.bss_conf.idle = false;
1318 }
1319
1320 if (local->hw_roc_channel)
1321 hw_roc = true;
1322
1323 list_for_each_entry(sdata, &local->interfaces, list) {
1324 if (sdata->old_idle == sdata->vif.bss_conf.idle)
1325 continue;
1326 if (!ieee80211_sdata_running(sdata))
1327 continue;
1328 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IDLE);
1329 }
1330
1331 if (working || scanning || hw_roc)
1332 led_trig_start |= IEEE80211_TPT_LEDTRIG_FL_WORK;
1333 else
1334 led_trig_stop |= IEEE80211_TPT_LEDTRIG_FL_WORK;
1335
1336 if (count)
1337 led_trig_start |= IEEE80211_TPT_LEDTRIG_FL_CONNECTED;
1338 else
1339 led_trig_stop |= IEEE80211_TPT_LEDTRIG_FL_CONNECTED;
1340
1341 ieee80211_mod_tpt_led_trig(local, led_trig_start, led_trig_stop);
1342
1343 if (hw_roc)
1344 return ieee80211_idle_off(local, "hw remain-on-channel");
1345 if (working)
1346 return ieee80211_idle_off(local, "working");
1347 if (scanning)
1348 return ieee80211_idle_off(local, "scanning");
1220 if (!count) 1349 if (!count)
1221 return ieee80211_idle_on(local); 1350 return ieee80211_idle_on(local);
1222 else 1351 else