aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211/ieee80211.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/mac80211/ieee80211.c')
-rw-r--r--net/mac80211/ieee80211.c959
1 files changed, 706 insertions, 253 deletions
diff --git a/net/mac80211/ieee80211.c b/net/mac80211/ieee80211.c
index 28bcdf9fc3df..55b63712e48c 100644
--- a/net/mac80211/ieee80211.c
+++ b/net/mac80211/ieee80211.c
@@ -26,6 +26,7 @@
26 26
27#include "ieee80211_i.h" 27#include "ieee80211_i.h"
28#include "ieee80211_rate.h" 28#include "ieee80211_rate.h"
29#include "mesh.h"
29#include "wep.h" 30#include "wep.h"
30#include "wme.h" 31#include "wme.h"
31#include "aes_ccm.h" 32#include "aes_ccm.h"
@@ -67,9 +68,19 @@ static void ieee80211_configure_filter(struct ieee80211_local *local)
67 new_flags |= FIF_ALLMULTI; 68 new_flags |= FIF_ALLMULTI;
68 69
69 if (local->monitors) 70 if (local->monitors)
70 new_flags |= FIF_CONTROL | 71 new_flags |= FIF_BCN_PRBRESP_PROMISC;
71 FIF_OTHER_BSS | 72
72 FIF_BCN_PRBRESP_PROMISC; 73 if (local->fif_fcsfail)
74 new_flags |= FIF_FCSFAIL;
75
76 if (local->fif_plcpfail)
77 new_flags |= FIF_PLCPFAIL;
78
79 if (local->fif_control)
80 new_flags |= FIF_CONTROL;
81
82 if (local->fif_other_bss)
83 new_flags |= FIF_OTHER_BSS;
73 84
74 changed_flags = local->filter_flags ^ new_flags; 85 changed_flags = local->filter_flags ^ new_flags;
75 86
@@ -128,9 +139,15 @@ static void ieee80211_master_set_multicast_list(struct net_device *dev)
128 139
129static int ieee80211_change_mtu(struct net_device *dev, int new_mtu) 140static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
130{ 141{
142 int meshhdrlen;
143 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
144
145 meshhdrlen = (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) ? 5 : 0;
146
131 /* FIX: what would be proper limits for MTU? 147 /* FIX: what would be proper limits for MTU?
132 * This interface uses 802.3 frames. */ 148 * This interface uses 802.3 frames. */
133 if (new_mtu < 256 || new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6) { 149 if (new_mtu < 256 ||
150 new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) {
134 printk(KERN_WARNING "%s: invalid MTU %d\n", 151 printk(KERN_WARNING "%s: invalid MTU %d\n",
135 dev->name, new_mtu); 152 dev->name, new_mtu);
136 return -EINVAL; 153 return -EINVAL;
@@ -166,6 +183,7 @@ static int ieee80211_open(struct net_device *dev)
166 struct ieee80211_if_init_conf conf; 183 struct ieee80211_if_init_conf conf;
167 int res; 184 int res;
168 bool need_hw_reconfig = 0; 185 bool need_hw_reconfig = 0;
186 struct sta_info *sta;
169 187
170 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 188 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
171 189
@@ -173,8 +191,52 @@ static int ieee80211_open(struct net_device *dev)
173 list_for_each_entry(nsdata, &local->interfaces, list) { 191 list_for_each_entry(nsdata, &local->interfaces, list) {
174 struct net_device *ndev = nsdata->dev; 192 struct net_device *ndev = nsdata->dev;
175 193
176 if (ndev != dev && ndev != local->mdev && netif_running(ndev) && 194 if (ndev != dev && ndev != local->mdev && netif_running(ndev)) {
177 compare_ether_addr(dev->dev_addr, ndev->dev_addr) == 0) { 195 /*
196 * Allow only a single IBSS interface to be up at any
197 * time. This is restricted because beacon distribution
198 * cannot work properly if both are in the same IBSS.
199 *
200 * To remove this restriction we'd have to disallow them
201 * from setting the same SSID on different IBSS interfaces
202 * belonging to the same hardware. Then, however, we're
203 * faced with having to adopt two different TSF timers...
204 */
205 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
206 nsdata->vif.type == IEEE80211_IF_TYPE_IBSS)
207 return -EBUSY;
208
209 /*
210 * Disallow multiple IBSS/STA mode interfaces.
211 *
212 * This is a technical restriction, it is possible although
213 * most likely not IEEE 802.11 compliant to have multiple
214 * STAs with just a single hardware (the TSF timer will not
215 * be adjusted properly.)
216 *
217 * However, because mac80211 uses the master device's BSS
218 * information for each STA/IBSS interface, doing this will
219 * currently corrupt that BSS information completely, unless,
220 * a not very useful case, both STAs are associated to the
221 * same BSS.
222 *
223 * To remove this restriction, the BSS information needs to
224 * be embedded in the STA/IBSS mode sdata instead of using
225 * the master device's BSS structure.
226 */
227 if ((sdata->vif.type == IEEE80211_IF_TYPE_STA ||
228 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) &&
229 (nsdata->vif.type == IEEE80211_IF_TYPE_STA ||
230 nsdata->vif.type == IEEE80211_IF_TYPE_IBSS))
231 return -EBUSY;
232
233 /*
234 * The remaining checks are only performed for interfaces
235 * with the same MAC address.
236 */
237 if (compare_ether_addr(dev->dev_addr, ndev->dev_addr))
238 continue;
239
178 /* 240 /*
179 * check whether it may have the same address 241 * check whether it may have the same address
180 */ 242 */
@@ -186,8 +248,7 @@ static int ieee80211_open(struct net_device *dev)
186 * can only add VLANs to enabled APs 248 * can only add VLANs to enabled APs
187 */ 249 */
188 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN && 250 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN &&
189 nsdata->vif.type == IEEE80211_IF_TYPE_AP && 251 nsdata->vif.type == IEEE80211_IF_TYPE_AP)
190 netif_running(nsdata->dev))
191 sdata->u.vlan.ap = nsdata; 252 sdata->u.vlan.ap = nsdata;
192 } 253 }
193 } 254 }
@@ -196,6 +257,20 @@ static int ieee80211_open(struct net_device *dev)
196 case IEEE80211_IF_TYPE_WDS: 257 case IEEE80211_IF_TYPE_WDS:
197 if (is_zero_ether_addr(sdata->u.wds.remote_addr)) 258 if (is_zero_ether_addr(sdata->u.wds.remote_addr))
198 return -ENOLINK; 259 return -ENOLINK;
260
261 /* Create STA entry for the WDS peer */
262 sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
263 GFP_KERNEL);
264 if (!sta)
265 return -ENOMEM;
266
267 sta->flags |= WLAN_STA_AUTHORIZED;
268
269 res = sta_info_insert(sta);
270 if (res) {
271 sta_info_destroy(sta);
272 return res;
273 }
199 break; 274 break;
200 case IEEE80211_IF_TYPE_VLAN: 275 case IEEE80211_IF_TYPE_VLAN:
201 if (!sdata->u.vlan.ap) 276 if (!sdata->u.vlan.ap)
@@ -205,6 +280,7 @@ static int ieee80211_open(struct net_device *dev)
205 case IEEE80211_IF_TYPE_STA: 280 case IEEE80211_IF_TYPE_STA:
206 case IEEE80211_IF_TYPE_MNTR: 281 case IEEE80211_IF_TYPE_MNTR:
207 case IEEE80211_IF_TYPE_IBSS: 282 case IEEE80211_IF_TYPE_IBSS:
283 case IEEE80211_IF_TYPE_MESH_POINT:
208 /* no special treatment */ 284 /* no special treatment */
209 break; 285 break;
210 case IEEE80211_IF_TYPE_INVALID: 286 case IEEE80211_IF_TYPE_INVALID:
@@ -229,15 +305,28 @@ static int ieee80211_open(struct net_device *dev)
229 /* no need to tell driver */ 305 /* no need to tell driver */
230 break; 306 break;
231 case IEEE80211_IF_TYPE_MNTR: 307 case IEEE80211_IF_TYPE_MNTR:
308 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
309 local->cooked_mntrs++;
310 break;
311 }
312
232 /* must be before the call to ieee80211_configure_filter */ 313 /* must be before the call to ieee80211_configure_filter */
233 local->monitors++; 314 local->monitors++;
234 if (local->monitors == 1) { 315 if (local->monitors == 1)
235 netif_tx_lock_bh(local->mdev);
236 ieee80211_configure_filter(local);
237 netif_tx_unlock_bh(local->mdev);
238
239 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP; 316 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
240 } 317
318 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
319 local->fif_fcsfail++;
320 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
321 local->fif_plcpfail++;
322 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
323 local->fif_control++;
324 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
325 local->fif_other_bss++;
326
327 netif_tx_lock_bh(local->mdev);
328 ieee80211_configure_filter(local);
329 netif_tx_unlock_bh(local->mdev);
241 break; 330 break;
242 case IEEE80211_IF_TYPE_STA: 331 case IEEE80211_IF_TYPE_STA:
243 case IEEE80211_IF_TYPE_IBSS: 332 case IEEE80211_IF_TYPE_IBSS:
@@ -293,24 +382,51 @@ static int ieee80211_open(struct net_device *dev)
293 382
294static int ieee80211_stop(struct net_device *dev) 383static int ieee80211_stop(struct net_device *dev)
295{ 384{
296 struct ieee80211_sub_if_data *sdata; 385 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
297 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 386 struct ieee80211_local *local = sdata->local;
298 struct ieee80211_if_init_conf conf; 387 struct ieee80211_if_init_conf conf;
299 struct sta_info *sta; 388 struct sta_info *sta;
300 int i; 389 int i;
301 390
302 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 391 /*
392 * Stop TX on this interface first.
393 */
394 netif_stop_queue(dev);
395
396 /*
397 * Now delete all active aggregation sessions.
398 */
399 rcu_read_lock();
303 400
304 list_for_each_entry(sta, &local->sta_list, list) { 401 list_for_each_entry_rcu(sta, &local->sta_list, list) {
305 if (sta->dev == dev) 402 if (sta->sdata == sdata)
306 for (i = 0; i < STA_TID_NUM; i++) 403 for (i = 0; i < STA_TID_NUM; i++)
307 ieee80211_sta_stop_rx_ba_session(sta->dev, 404 ieee80211_sta_stop_rx_ba_session(sdata->dev,
308 sta->addr, i, 405 sta->addr, i,
309 WLAN_BACK_RECIPIENT, 406 WLAN_BACK_RECIPIENT,
310 WLAN_REASON_QSTA_LEAVE_QBSS); 407 WLAN_REASON_QSTA_LEAVE_QBSS);
311 } 408 }
312 409
313 netif_stop_queue(dev); 410 rcu_read_unlock();
411
412 /*
413 * Remove all stations associated with this interface.
414 *
415 * This must be done before calling ops->remove_interface()
416 * because otherwise we can later invoke ops->sta_notify()
417 * whenever the STAs are removed, and that invalidates driver
418 * assumptions about always getting a vif pointer that is valid
419 * (because if we remove a STA after ops->remove_interface()
420 * the driver will have removed the vif info already!)
421 *
422 * We could relax this and only unlink the stations from the
423 * hash table and list but keep them on a per-sdata list that
424 * will be inserted back again when the interface is brought
425 * up again, but I don't currently see a use case for that,
426 * except with WDS which gets a STA entry created when it is
427 * brought up.
428 */
429 sta_info_flush(local, sdata);
314 430
315 /* 431 /*
316 * Don't count this interface for promisc/allmulti while it 432 * Don't count this interface for promisc/allmulti while it
@@ -352,15 +468,29 @@ static int ieee80211_stop(struct net_device *dev)
352 /* no need to tell driver */ 468 /* no need to tell driver */
353 break; 469 break;
354 case IEEE80211_IF_TYPE_MNTR: 470 case IEEE80211_IF_TYPE_MNTR:
355 local->monitors--; 471 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
356 if (local->monitors == 0) { 472 local->cooked_mntrs--;
357 netif_tx_lock_bh(local->mdev); 473 break;
358 ieee80211_configure_filter(local); 474 }
359 netif_tx_unlock_bh(local->mdev);
360 475
476 local->monitors--;
477 if (local->monitors == 0)
361 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP; 478 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
362 } 479
480 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
481 local->fif_fcsfail--;
482 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
483 local->fif_plcpfail--;
484 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
485 local->fif_control--;
486 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
487 local->fif_other_bss--;
488
489 netif_tx_lock_bh(local->mdev);
490 ieee80211_configure_filter(local);
491 netif_tx_unlock_bh(local->mdev);
363 break; 492 break;
493 case IEEE80211_IF_TYPE_MESH_POINT:
364 case IEEE80211_IF_TYPE_STA: 494 case IEEE80211_IF_TYPE_STA:
365 case IEEE80211_IF_TYPE_IBSS: 495 case IEEE80211_IF_TYPE_IBSS:
366 sdata->u.sta.state = IEEE80211_DISABLED; 496 sdata->u.sta.state = IEEE80211_DISABLED;
@@ -414,6 +544,339 @@ static int ieee80211_stop(struct net_device *dev)
414 return 0; 544 return 0;
415} 545}
416 546
547int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
548{
549 struct ieee80211_local *local = hw_to_local(hw);
550 struct sta_info *sta;
551 struct ieee80211_sub_if_data *sdata;
552 u16 start_seq_num = 0;
553 u8 *state;
554 int ret;
555 DECLARE_MAC_BUF(mac);
556
557 if (tid >= STA_TID_NUM)
558 return -EINVAL;
559
560#ifdef CONFIG_MAC80211_HT_DEBUG
561 printk(KERN_DEBUG "Open BA session requested for %s tid %u\n",
562 print_mac(mac, ra), tid);
563#endif /* CONFIG_MAC80211_HT_DEBUG */
564
565 rcu_read_lock();
566
567 sta = sta_info_get(local, ra);
568 if (!sta) {
569 printk(KERN_DEBUG "Could not find the station\n");
570 rcu_read_unlock();
571 return -ENOENT;
572 }
573
574 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
575
576 /* we have tried too many times, receiver does not want A-MPDU */
577 if (sta->ampdu_mlme.tid_tx[tid].addba_req_num > HT_AGG_MAX_RETRIES) {
578 ret = -EBUSY;
579 goto start_ba_exit;
580 }
581
582 state = &sta->ampdu_mlme.tid_tx[tid].state;
583 /* check if the TID is not in aggregation flow already */
584 if (*state != HT_AGG_STATE_IDLE) {
585#ifdef CONFIG_MAC80211_HT_DEBUG
586 printk(KERN_DEBUG "BA request denied - session is not "
587 "idle on tid %u\n", tid);
588#endif /* CONFIG_MAC80211_HT_DEBUG */
589 ret = -EAGAIN;
590 goto start_ba_exit;
591 }
592
593 /* ensure that TX flow won't interrupt us
594 * until the end of the call to requeue function */
595 spin_lock_bh(&local->mdev->queue_lock);
596
597 /* create a new queue for this aggregation */
598 ret = ieee80211_ht_agg_queue_add(local, sta, tid);
599
600 /* case no queue is available to aggregation
601 * don't switch to aggregation */
602 if (ret) {
603#ifdef CONFIG_MAC80211_HT_DEBUG
604 printk(KERN_DEBUG "BA request denied - no queue available for"
605 " tid %d\n", tid);
606#endif /* CONFIG_MAC80211_HT_DEBUG */
607 spin_unlock_bh(&local->mdev->queue_lock);
608 goto start_ba_exit;
609 }
610 sdata = sta->sdata;
611
612 /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
613 * call back right away, it must see that the flow has begun */
614 *state |= HT_ADDBA_REQUESTED_MSK;
615
616 if (local->ops->ampdu_action)
617 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
618 ra, tid, &start_seq_num);
619
620 if (ret) {
621 /* No need to requeue the packets in the agg queue, since we
622 * held the tx lock: no packet could be enqueued to the newly
623 * allocated queue */
624 ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
625#ifdef CONFIG_MAC80211_HT_DEBUG
626 printk(KERN_DEBUG "BA request denied - HW or queue unavailable"
627 " for tid %d\n", tid);
628#endif /* CONFIG_MAC80211_HT_DEBUG */
629 spin_unlock_bh(&local->mdev->queue_lock);
630 *state = HT_AGG_STATE_IDLE;
631 goto start_ba_exit;
632 }
633
634 /* Will put all the packets in the new SW queue */
635 ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
636 spin_unlock_bh(&local->mdev->queue_lock);
637
638 /* We have most probably almost emptied the legacy queue */
639 /* ieee80211_wake_queue(local_to_hw(local), ieee802_1d_to_ac[tid]); */
640
641 /* send an addBA request */
642 sta->ampdu_mlme.dialog_token_allocator++;
643 sta->ampdu_mlme.tid_tx[tid].dialog_token =
644 sta->ampdu_mlme.dialog_token_allocator;
645 sta->ampdu_mlme.tid_tx[tid].ssn = start_seq_num;
646
647 ieee80211_send_addba_request(sta->sdata->dev, ra, tid,
648 sta->ampdu_mlme.tid_tx[tid].dialog_token,
649 sta->ampdu_mlme.tid_tx[tid].ssn,
650 0x40, 5000);
651
652 /* activate the timer for the recipient's addBA response */
653 sta->ampdu_mlme.tid_tx[tid].addba_resp_timer.expires =
654 jiffies + ADDBA_RESP_INTERVAL;
655 add_timer(&sta->ampdu_mlme.tid_tx[tid].addba_resp_timer);
656 printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
657
658start_ba_exit:
659 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
660 rcu_read_unlock();
661 return ret;
662}
663EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
664
665int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
666 u8 *ra, u16 tid,
667 enum ieee80211_back_parties initiator)
668{
669 struct ieee80211_local *local = hw_to_local(hw);
670 struct sta_info *sta;
671 u8 *state;
672 int ret = 0;
673 DECLARE_MAC_BUF(mac);
674
675 if (tid >= STA_TID_NUM)
676 return -EINVAL;
677
678#ifdef CONFIG_MAC80211_HT_DEBUG
679 printk(KERN_DEBUG "Stop a BA session requested for %s tid %u\n",
680 print_mac(mac, ra), tid);
681#endif /* CONFIG_MAC80211_HT_DEBUG */
682
683 rcu_read_lock();
684 sta = sta_info_get(local, ra);
685 if (!sta) {
686 rcu_read_unlock();
687 return -ENOENT;
688 }
689
690 /* check if the TID is in aggregation */
691 state = &sta->ampdu_mlme.tid_tx[tid].state;
692 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
693
694 if (*state != HT_AGG_STATE_OPERATIONAL) {
695#ifdef CONFIG_MAC80211_HT_DEBUG
696 printk(KERN_DEBUG "Try to stop Tx aggregation on"
697 " non active TID\n");
698#endif /* CONFIG_MAC80211_HT_DEBUG */
699 ret = -ENOENT;
700 goto stop_BA_exit;
701 }
702
703 ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]);
704
705 *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
706 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
707
708 if (local->ops->ampdu_action)
709 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP,
710 ra, tid, NULL);
711
712 /* case HW denied going back to legacy */
713 if (ret) {
714 WARN_ON(ret != -EBUSY);
715 *state = HT_AGG_STATE_OPERATIONAL;
716 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
717 goto stop_BA_exit;
718 }
719
720stop_BA_exit:
721 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
722 rcu_read_unlock();
723 return ret;
724}
725EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
726
727void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
728{
729 struct ieee80211_local *local = hw_to_local(hw);
730 struct sta_info *sta;
731 u8 *state;
732 DECLARE_MAC_BUF(mac);
733
734 if (tid >= STA_TID_NUM) {
735 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
736 tid, STA_TID_NUM);
737 return;
738 }
739
740 rcu_read_lock();
741 sta = sta_info_get(local, ra);
742 if (!sta) {
743 rcu_read_unlock();
744 printk(KERN_DEBUG "Could not find station: %s\n",
745 print_mac(mac, ra));
746 return;
747 }
748
749 state = &sta->ampdu_mlme.tid_tx[tid].state;
750 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
751
752 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
753 printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
754 *state);
755 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
756 rcu_read_unlock();
757 return;
758 }
759
760 WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK);
761
762 *state |= HT_ADDBA_DRV_READY_MSK;
763
764 if (*state == HT_AGG_STATE_OPERATIONAL) {
765 printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
766 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
767 }
768 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
769 rcu_read_unlock();
770}
771EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
772
773void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
774{
775 struct ieee80211_local *local = hw_to_local(hw);
776 struct sta_info *sta;
777 u8 *state;
778 int agg_queue;
779 DECLARE_MAC_BUF(mac);
780
781 if (tid >= STA_TID_NUM) {
782 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
783 tid, STA_TID_NUM);
784 return;
785 }
786
787 printk(KERN_DEBUG "Stop a BA session requested on DA %s tid %d\n",
788 print_mac(mac, ra), tid);
789
790 rcu_read_lock();
791 sta = sta_info_get(local, ra);
792 if (!sta) {
793 printk(KERN_DEBUG "Could not find station: %s\n",
794 print_mac(mac, ra));
795 rcu_read_unlock();
796 return;
797 }
798 state = &sta->ampdu_mlme.tid_tx[tid].state;
799
800 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
801 if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
802 printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
803 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
804 rcu_read_unlock();
805 return;
806 }
807
808 if (*state & HT_AGG_STATE_INITIATOR_MSK)
809 ieee80211_send_delba(sta->sdata->dev, ra, tid,
810 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
811
812 agg_queue = sta->tid_to_tx_q[tid];
813
814 /* avoid ordering issues: we are the only one that can modify
815 * the content of the qdiscs */
816 spin_lock_bh(&local->mdev->queue_lock);
817 /* remove the queue for this aggregation */
818 ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
819 spin_unlock_bh(&local->mdev->queue_lock);
820
821 /* we just requeued the all the frames that were in the removed
822 * queue, and since we might miss a softirq we do netif_schedule.
823 * ieee80211_wake_queue is not used here as this queue is not
824 * necessarily stopped */
825 netif_schedule(local->mdev);
826 *state = HT_AGG_STATE_IDLE;
827 sta->ampdu_mlme.tid_tx[tid].addba_req_num = 0;
828 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
829
830 rcu_read_unlock();
831}
832EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
833
834void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
835 const u8 *ra, u16 tid)
836{
837 struct ieee80211_local *local = hw_to_local(hw);
838 struct ieee80211_ra_tid *ra_tid;
839 struct sk_buff *skb = dev_alloc_skb(0);
840
841 if (unlikely(!skb)) {
842 if (net_ratelimit())
843 printk(KERN_WARNING "%s: Not enough memory, "
844 "dropping start BA session", skb->dev->name);
845 return;
846 }
847 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
848 memcpy(&ra_tid->ra, ra, ETH_ALEN);
849 ra_tid->tid = tid;
850
851 skb->pkt_type = IEEE80211_ADDBA_MSG;
852 skb_queue_tail(&local->skb_queue, skb);
853 tasklet_schedule(&local->tasklet);
854}
855EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
856
857void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
858 const u8 *ra, u16 tid)
859{
860 struct ieee80211_local *local = hw_to_local(hw);
861 struct ieee80211_ra_tid *ra_tid;
862 struct sk_buff *skb = dev_alloc_skb(0);
863
864 if (unlikely(!skb)) {
865 if (net_ratelimit())
866 printk(KERN_WARNING "%s: Not enough memory, "
867 "dropping stop BA session", skb->dev->name);
868 return;
869 }
870 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
871 memcpy(&ra_tid->ra, ra, ETH_ALEN);
872 ra_tid->tid = tid;
873
874 skb->pkt_type = IEEE80211_DELBA_MSG;
875 skb_queue_tail(&local->skb_queue, skb);
876 tasklet_schedule(&local->tasklet);
877}
878EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
879
417static void ieee80211_set_multicast_list(struct net_device *dev) 880static void ieee80211_set_multicast_list(struct net_device *dev)
418{ 881{
419 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 882 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
@@ -465,41 +928,6 @@ void ieee80211_if_setup(struct net_device *dev)
465 dev->destructor = ieee80211_if_free; 928 dev->destructor = ieee80211_if_free;
466} 929}
467 930
468/* WDS specialties */
469
470int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr)
471{
472 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
473 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
474 struct sta_info *sta;
475 DECLARE_MAC_BUF(mac);
476
477 if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0)
478 return 0;
479
480 /* Create STA entry for the new peer */
481 sta = sta_info_add(local, dev, remote_addr, GFP_KERNEL);
482 if (!sta)
483 return -ENOMEM;
484 sta_info_put(sta);
485
486 /* Remove STA entry for the old peer */
487 sta = sta_info_get(local, sdata->u.wds.remote_addr);
488 if (sta) {
489 sta_info_free(sta);
490 sta_info_put(sta);
491 } else {
492 printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
493 "peer %s\n",
494 dev->name, print_mac(mac, sdata->u.wds.remote_addr));
495 }
496
497 /* Update WDS link data */
498 memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN);
499
500 return 0;
501}
502
503/* everything else */ 931/* everything else */
504 932
505static int __ieee80211_if_config(struct net_device *dev, 933static int __ieee80211_if_config(struct net_device *dev,
@@ -520,6 +948,9 @@ static int __ieee80211_if_config(struct net_device *dev,
520 conf.bssid = sdata->u.sta.bssid; 948 conf.bssid = sdata->u.sta.bssid;
521 conf.ssid = sdata->u.sta.ssid; 949 conf.ssid = sdata->u.sta.ssid;
522 conf.ssid_len = sdata->u.sta.ssid_len; 950 conf.ssid_len = sdata->u.sta.ssid_len;
951 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
952 conf.beacon = beacon;
953 ieee80211_start_mesh(dev);
523 } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) { 954 } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
524 conf.ssid = sdata->u.ap.ssid; 955 conf.ssid = sdata->u.ap.ssid;
525 conf.ssid_len = sdata->u.ap.ssid_len; 956 conf.ssid_len = sdata->u.ap.ssid_len;
@@ -532,6 +963,11 @@ static int __ieee80211_if_config(struct net_device *dev,
532 963
533int ieee80211_if_config(struct net_device *dev) 964int ieee80211_if_config(struct net_device *dev)
534{ 965{
966 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
967 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
968 if (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT &&
969 (local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
970 return ieee80211_if_config_beacon(dev);
535 return __ieee80211_if_config(dev, NULL, NULL); 971 return __ieee80211_if_config(dev, NULL, NULL);
536} 972}
537 973
@@ -553,37 +989,28 @@ int ieee80211_if_config_beacon(struct net_device *dev)
553 989
554int ieee80211_hw_config(struct ieee80211_local *local) 990int ieee80211_hw_config(struct ieee80211_local *local)
555{ 991{
556 struct ieee80211_hw_mode *mode;
557 struct ieee80211_channel *chan; 992 struct ieee80211_channel *chan;
558 int ret = 0; 993 int ret = 0;
559 994
560 if (local->sta_sw_scanning) { 995 if (local->sta_sw_scanning)
561 chan = local->scan_channel; 996 chan = local->scan_channel;
562 mode = local->scan_hw_mode; 997 else
563 } else {
564 chan = local->oper_channel; 998 chan = local->oper_channel;
565 mode = local->oper_hw_mode;
566 }
567 999
568 local->hw.conf.channel = chan->chan; 1000 local->hw.conf.channel = chan;
569 local->hw.conf.channel_val = chan->val; 1001
570 if (!local->hw.conf.power_level) { 1002 if (!local->hw.conf.power_level)
571 local->hw.conf.power_level = chan->power_level; 1003 local->hw.conf.power_level = chan->max_power;
572 } else { 1004 else
573 local->hw.conf.power_level = min(chan->power_level, 1005 local->hw.conf.power_level = min(chan->max_power,
574 local->hw.conf.power_level); 1006 local->hw.conf.power_level);
575 } 1007
576 local->hw.conf.freq = chan->freq; 1008 local->hw.conf.max_antenna_gain = chan->max_antenna_gain;
577 local->hw.conf.phymode = mode->mode;
578 local->hw.conf.antenna_max = chan->antenna_max;
579 local->hw.conf.chan = chan;
580 local->hw.conf.mode = mode;
581 1009
582#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1010#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
583 printk(KERN_DEBUG "HW CONFIG: channel=%d freq=%d " 1011 printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n",
584 "phymode=%d\n", local->hw.conf.channel, local->hw.conf.freq, 1012 wiphy_name(local->hw.wiphy), chan->center_freq);
585 local->hw.conf.phymode); 1013#endif
586#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
587 1014
588 if (local->open_count) 1015 if (local->open_count)
589 ret = local->ops->config(local_to_hw(local), &local->hw.conf); 1016 ret = local->ops->config(local_to_hw(local), &local->hw.conf);
@@ -601,11 +1028,13 @@ int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
601 struct ieee80211_ht_bss_info *req_bss_cap) 1028 struct ieee80211_ht_bss_info *req_bss_cap)
602{ 1029{
603 struct ieee80211_conf *conf = &local->hw.conf; 1030 struct ieee80211_conf *conf = &local->hw.conf;
604 struct ieee80211_hw_mode *mode = conf->mode; 1031 struct ieee80211_supported_band *sband;
605 int i; 1032 int i;
606 1033
1034 sband = local->hw.wiphy->bands[conf->channel->band];
1035
607 /* HT is not supported */ 1036 /* HT is not supported */
608 if (!mode->ht_info.ht_supported) { 1037 if (!sband->ht_info.ht_supported) {
609 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE; 1038 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
610 return -EOPNOTSUPP; 1039 return -EOPNOTSUPP;
611 } 1040 }
@@ -615,17 +1044,17 @@ int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
615 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE; 1044 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
616 } else { 1045 } else {
617 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE; 1046 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
618 conf->ht_conf.cap = req_ht_cap->cap & mode->ht_info.cap; 1047 conf->ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap;
619 conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS); 1048 conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS);
620 conf->ht_conf.cap |= 1049 conf->ht_conf.cap |=
621 mode->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS; 1050 sband->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS;
622 conf->ht_bss_conf.primary_channel = 1051 conf->ht_bss_conf.primary_channel =
623 req_bss_cap->primary_channel; 1052 req_bss_cap->primary_channel;
624 conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap; 1053 conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
625 conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode; 1054 conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
626 for (i = 0; i < SUPP_MCS_SET_LEN; i++) 1055 for (i = 0; i < SUPP_MCS_SET_LEN; i++)
627 conf->ht_conf.supp_mcs_set[i] = 1056 conf->ht_conf.supp_mcs_set[i] =
628 mode->ht_info.supp_mcs_set[i] & 1057 sband->ht_info.supp_mcs_set[i] &
629 req_ht_cap->supp_mcs_set[i]; 1058 req_ht_cap->supp_mcs_set[i];
630 1059
631 /* In STA mode, this gives us indication 1060 /* In STA mode, this gives us indication
@@ -713,6 +1142,7 @@ static void ieee80211_tasklet_handler(unsigned long data)
713 struct sk_buff *skb; 1142 struct sk_buff *skb;
714 struct ieee80211_rx_status rx_status; 1143 struct ieee80211_rx_status rx_status;
715 struct ieee80211_tx_status *tx_status; 1144 struct ieee80211_tx_status *tx_status;
1145 struct ieee80211_ra_tid *ra_tid;
716 1146
717 while ((skb = skb_dequeue(&local->skb_queue)) || 1147 while ((skb = skb_dequeue(&local->skb_queue)) ||
718 (skb = skb_dequeue(&local->skb_queue_unreliable))) { 1148 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
@@ -733,6 +1163,18 @@ static void ieee80211_tasklet_handler(unsigned long data)
733 skb, tx_status); 1163 skb, tx_status);
734 kfree(tx_status); 1164 kfree(tx_status);
735 break; 1165 break;
1166 case IEEE80211_DELBA_MSG:
1167 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1168 ieee80211_stop_tx_ba_cb(local_to_hw(local),
1169 ra_tid->ra, ra_tid->tid);
1170 dev_kfree_skb(skb);
1171 break;
1172 case IEEE80211_ADDBA_MSG:
1173 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1174 ieee80211_start_tx_ba_cb(local_to_hw(local),
1175 ra_tid->ra, ra_tid->tid);
1176 dev_kfree_skb(skb);
1177 break ;
736 default: /* should never get here! */ 1178 default: /* should never get here! */
737 printk(KERN_ERR "%s: Unknown message type (%d)\n", 1179 printk(KERN_ERR "%s: Unknown message type (%d)\n",
738 wiphy_name(local->hw.wiphy), skb->pkt_type); 1180 wiphy_name(local->hw.wiphy), skb->pkt_type);
@@ -810,6 +1252,77 @@ no_key:
810 } 1252 }
811} 1253}
812 1254
1255static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
1256 struct sta_info *sta,
1257 struct sk_buff *skb,
1258 struct ieee80211_tx_status *status)
1259{
1260 sta->tx_filtered_count++;
1261
1262 /*
1263 * Clear the TX filter mask for this STA when sending the next
1264 * packet. If the STA went to power save mode, this will happen
1265 * happen when it wakes up for the next time.
1266 */
1267 sta->flags |= WLAN_STA_CLEAR_PS_FILT;
1268
1269 /*
1270 * This code races in the following way:
1271 *
1272 * (1) STA sends frame indicating it will go to sleep and does so
1273 * (2) hardware/firmware adds STA to filter list, passes frame up
1274 * (3) hardware/firmware processes TX fifo and suppresses a frame
1275 * (4) we get TX status before having processed the frame and
1276 * knowing that the STA has gone to sleep.
1277 *
1278 * This is actually quite unlikely even when both those events are
1279 * processed from interrupts coming in quickly after one another or
1280 * even at the same time because we queue both TX status events and
1281 * RX frames to be processed by a tasklet and process them in the
1282 * same order that they were received or TX status last. Hence, there
1283 * is no race as long as the frame RX is processed before the next TX
1284 * status, which drivers can ensure, see below.
1285 *
1286 * Note that this can only happen if the hardware or firmware can
1287 * actually add STAs to the filter list, if this is done by the
1288 * driver in response to set_tim() (which will only reduce the race
1289 * this whole filtering tries to solve, not completely solve it)
1290 * this situation cannot happen.
1291 *
1292 * To completely solve this race drivers need to make sure that they
1293 * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
1294 * functions and
1295 * (b) always process RX events before TX status events if ordering
1296 * can be unknown, for example with different interrupt status
1297 * bits.
1298 */
1299 if (sta->flags & WLAN_STA_PS &&
1300 skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) {
1301 ieee80211_remove_tx_extra(local, sta->key, skb,
1302 &status->control);
1303 skb_queue_tail(&sta->tx_filtered, skb);
1304 return;
1305 }
1306
1307 if (!(sta->flags & WLAN_STA_PS) &&
1308 !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
1309 /* Software retry the packet once */
1310 status->control.flags |= IEEE80211_TXCTL_REQUEUE;
1311 ieee80211_remove_tx_extra(local, sta->key, skb,
1312 &status->control);
1313 dev_queue_xmit(skb);
1314 return;
1315 }
1316
1317 if (net_ratelimit())
1318 printk(KERN_DEBUG "%s: dropped TX filtered frame, "
1319 "queue_len=%d PS=%d @%lu\n",
1320 wiphy_name(local->hw.wiphy),
1321 skb_queue_len(&sta->tx_filtered),
1322 !!(sta->flags & WLAN_STA_PS), jiffies);
1323 dev_kfree_skb(skb);
1324}
1325
813void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb, 1326void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
814 struct ieee80211_tx_status *status) 1327 struct ieee80211_tx_status *status)
815{ 1328{
@@ -819,7 +1332,7 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
819 u16 frag, type; 1332 u16 frag, type;
820 struct ieee80211_tx_status_rtap_hdr *rthdr; 1333 struct ieee80211_tx_status_rtap_hdr *rthdr;
821 struct ieee80211_sub_if_data *sdata; 1334 struct ieee80211_sub_if_data *sdata;
822 int monitors; 1335 struct net_device *prev_dev = NULL;
823 1336
824 if (!status) { 1337 if (!status) {
825 printk(KERN_ERR 1338 printk(KERN_ERR
@@ -829,18 +1342,24 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
829 return; 1342 return;
830 } 1343 }
831 1344
1345 rcu_read_lock();
1346
832 if (status->excessive_retries) { 1347 if (status->excessive_retries) {
833 struct sta_info *sta; 1348 struct sta_info *sta;
834 sta = sta_info_get(local, hdr->addr1); 1349 sta = sta_info_get(local, hdr->addr1);
835 if (sta) { 1350 if (sta) {
836 if (sta->flags & WLAN_STA_PS) { 1351 if (sta->flags & WLAN_STA_PS) {
837 /* The STA is in power save mode, so assume 1352 /*
1353 * The STA is in power save mode, so assume
838 * that this TX packet failed because of that. 1354 * that this TX packet failed because of that.
839 */ 1355 */
840 status->excessive_retries = 0; 1356 status->excessive_retries = 0;
841 status->flags |= IEEE80211_TX_STATUS_TX_FILTERED; 1357 status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
1358 ieee80211_handle_filtered_frame(local, sta,
1359 skb, status);
1360 rcu_read_unlock();
1361 return;
842 } 1362 }
843 sta_info_put(sta);
844 } 1363 }
845 } 1364 }
846 1365
@@ -848,53 +1367,16 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
848 struct sta_info *sta; 1367 struct sta_info *sta;
849 sta = sta_info_get(local, hdr->addr1); 1368 sta = sta_info_get(local, hdr->addr1);
850 if (sta) { 1369 if (sta) {
851 sta->tx_filtered_count++; 1370 ieee80211_handle_filtered_frame(local, sta, skb,
852 1371 status);
853 /* Clear the TX filter mask for this STA when sending 1372 rcu_read_unlock();
854 * the next packet. If the STA went to power save mode,
855 * this will happen when it is waking up for the next
856 * time. */
857 sta->clear_dst_mask = 1;
858
859 /* TODO: Is the WLAN_STA_PS flag always set here or is
860 * the race between RX and TX status causing some
861 * packets to be filtered out before 80211.o gets an
862 * update for PS status? This seems to be the case, so
863 * no changes are likely to be needed. */
864 if (sta->flags & WLAN_STA_PS &&
865 skb_queue_len(&sta->tx_filtered) <
866 STA_MAX_TX_BUFFER) {
867 ieee80211_remove_tx_extra(local, sta->key,
868 skb,
869 &status->control);
870 skb_queue_tail(&sta->tx_filtered, skb);
871 } else if (!(sta->flags & WLAN_STA_PS) &&
872 !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
873 /* Software retry the packet once */
874 status->control.flags |= IEEE80211_TXCTL_REQUEUE;
875 ieee80211_remove_tx_extra(local, sta->key,
876 skb,
877 &status->control);
878 dev_queue_xmit(skb);
879 } else {
880 if (net_ratelimit()) {
881 printk(KERN_DEBUG "%s: dropped TX "
882 "filtered frame queue_len=%d "
883 "PS=%d @%lu\n",
884 wiphy_name(local->hw.wiphy),
885 skb_queue_len(
886 &sta->tx_filtered),
887 !!(sta->flags & WLAN_STA_PS),
888 jiffies);
889 }
890 dev_kfree_skb(skb);
891 }
892 sta_info_put(sta);
893 return; 1373 return;
894 } 1374 }
895 } else 1375 } else
896 rate_control_tx_status(local->mdev, skb, status); 1376 rate_control_tx_status(local->mdev, skb, status);
897 1377
1378 rcu_read_unlock();
1379
898 ieee80211_led_tx(local, 0); 1380 ieee80211_led_tx(local, 0);
899 1381
900 /* SNMP counters 1382 /* SNMP counters
@@ -932,7 +1414,11 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
932 /* this was a transmitted frame, but now we want to reuse it */ 1414 /* this was a transmitted frame, but now we want to reuse it */
933 skb_orphan(skb); 1415 skb_orphan(skb);
934 1416
935 if (!local->monitors) { 1417 /*
1418 * This is a bit racy but we can avoid a lot of work
1419 * with this test...
1420 */
1421 if (!local->monitors && !local->cooked_mntrs) {
936 dev_kfree_skb(skb); 1422 dev_kfree_skb(skb);
937 return; 1423 return;
938 } 1424 }
@@ -966,51 +1452,44 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
966 1452
967 rthdr->data_retries = status->retry_count; 1453 rthdr->data_retries = status->retry_count;
968 1454
1455 /* XXX: is this sufficient for BPF? */
1456 skb_set_mac_header(skb, 0);
1457 skb->ip_summed = CHECKSUM_UNNECESSARY;
1458 skb->pkt_type = PACKET_OTHERHOST;
1459 skb->protocol = htons(ETH_P_802_2);
1460 memset(skb->cb, 0, sizeof(skb->cb));
1461
969 rcu_read_lock(); 1462 rcu_read_lock();
970 monitors = local->monitors;
971 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 1463 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
972 /*
973 * Using the monitors counter is possibly racy, but
974 * if the value is wrong we simply either clone the skb
975 * once too much or forget sending it to one monitor iface
976 * The latter case isn't nice but fixing the race is much
977 * more complicated.
978 */
979 if (!monitors || !skb)
980 goto out;
981
982 if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) { 1464 if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) {
983 if (!netif_running(sdata->dev)) 1465 if (!netif_running(sdata->dev))
984 continue; 1466 continue;
985 monitors--; 1467
986 if (monitors) 1468 if (prev_dev) {
987 skb2 = skb_clone(skb, GFP_ATOMIC); 1469 skb2 = skb_clone(skb, GFP_ATOMIC);
988 else 1470 if (skb2) {
989 skb2 = NULL; 1471 skb2->dev = prev_dev;
990 skb->dev = sdata->dev; 1472 netif_rx(skb2);
991 /* XXX: is this sufficient for BPF? */ 1473 }
992 skb_set_mac_header(skb, 0); 1474 }
993 skb->ip_summed = CHECKSUM_UNNECESSARY; 1475
994 skb->pkt_type = PACKET_OTHERHOST; 1476 prev_dev = sdata->dev;
995 skb->protocol = htons(ETH_P_802_2);
996 memset(skb->cb, 0, sizeof(skb->cb));
997 netif_rx(skb);
998 skb = skb2;
999 } 1477 }
1000 } 1478 }
1001 out: 1479 if (prev_dev) {
1480 skb->dev = prev_dev;
1481 netif_rx(skb);
1482 skb = NULL;
1483 }
1002 rcu_read_unlock(); 1484 rcu_read_unlock();
1003 if (skb) 1485 dev_kfree_skb(skb);
1004 dev_kfree_skb(skb);
1005} 1486}
1006EXPORT_SYMBOL(ieee80211_tx_status); 1487EXPORT_SYMBOL(ieee80211_tx_status);
1007 1488
1008struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, 1489struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1009 const struct ieee80211_ops *ops) 1490 const struct ieee80211_ops *ops)
1010{ 1491{
1011 struct net_device *mdev;
1012 struct ieee80211_local *local; 1492 struct ieee80211_local *local;
1013 struct ieee80211_sub_if_data *sdata;
1014 int priv_size; 1493 int priv_size;
1015 struct wiphy *wiphy; 1494 struct wiphy *wiphy;
1016 1495
@@ -1056,25 +1535,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1056 BUG_ON(!ops->configure_filter); 1535 BUG_ON(!ops->configure_filter);
1057 local->ops = ops; 1536 local->ops = ops;
1058 1537
1059 /* for now, mdev needs sub_if_data :/ */
1060 mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
1061 "wmaster%d", ether_setup);
1062 if (!mdev) {
1063 wiphy_free(wiphy);
1064 return NULL;
1065 }
1066
1067 sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
1068 mdev->ieee80211_ptr = &sdata->wdev;
1069 sdata->wdev.wiphy = wiphy;
1070
1071 local->hw.queues = 1; /* default */ 1538 local->hw.queues = 1; /* default */
1072 1539
1073 local->mdev = mdev;
1074 local->rx_pre_handlers = ieee80211_rx_pre_handlers;
1075 local->rx_handlers = ieee80211_rx_handlers;
1076 local->tx_handlers = ieee80211_tx_handlers;
1077
1078 local->bridge_packets = 1; 1540 local->bridge_packets = 1;
1079 1541
1080 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; 1542 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
@@ -1083,33 +1545,12 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1083 local->long_retry_limit = 4; 1545 local->long_retry_limit = 4;
1084 local->hw.conf.radio_enabled = 1; 1546 local->hw.conf.radio_enabled = 1;
1085 1547
1086 local->enabled_modes = ~0;
1087
1088 INIT_LIST_HEAD(&local->modes_list);
1089
1090 INIT_LIST_HEAD(&local->interfaces); 1548 INIT_LIST_HEAD(&local->interfaces);
1091 1549
1092 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work); 1550 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
1093 ieee80211_rx_bss_list_init(mdev);
1094 1551
1095 sta_info_init(local); 1552 sta_info_init(local);
1096 1553
1097 mdev->hard_start_xmit = ieee80211_master_start_xmit;
1098 mdev->open = ieee80211_master_open;
1099 mdev->stop = ieee80211_master_stop;
1100 mdev->type = ARPHRD_IEEE80211;
1101 mdev->header_ops = &ieee80211_header_ops;
1102 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
1103
1104 sdata->vif.type = IEEE80211_IF_TYPE_AP;
1105 sdata->dev = mdev;
1106 sdata->local = local;
1107 sdata->u.ap.force_unicast_rateidx = -1;
1108 sdata->u.ap.max_ratectrl_rateidx = -1;
1109 ieee80211_if_sdata_init(sdata);
1110 /* no RCU needed since we're still during init phase */
1111 list_add_tail(&sdata->list, &local->interfaces);
1112
1113 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending, 1554 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
1114 (unsigned long)local); 1555 (unsigned long)local);
1115 tasklet_disable(&local->tx_pending_tasklet); 1556 tasklet_disable(&local->tx_pending_tasklet);
@@ -1131,11 +1572,63 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
1131 struct ieee80211_local *local = hw_to_local(hw); 1572 struct ieee80211_local *local = hw_to_local(hw);
1132 const char *name; 1573 const char *name;
1133 int result; 1574 int result;
1575 enum ieee80211_band band;
1576 struct net_device *mdev;
1577 struct ieee80211_sub_if_data *sdata;
1578
1579 /*
1580 * generic code guarantees at least one band,
1581 * set this very early because much code assumes
1582 * that hw.conf.channel is assigned
1583 */
1584 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1585 struct ieee80211_supported_band *sband;
1586
1587 sband = local->hw.wiphy->bands[band];
1588 if (sband) {
1589 /* init channel we're on */
1590 local->hw.conf.channel =
1591 local->oper_channel =
1592 local->scan_channel = &sband->channels[0];
1593 break;
1594 }
1595 }
1134 1596
1135 result = wiphy_register(local->hw.wiphy); 1597 result = wiphy_register(local->hw.wiphy);
1136 if (result < 0) 1598 if (result < 0)
1137 return result; 1599 return result;
1138 1600
1601 /* for now, mdev needs sub_if_data :/ */
1602 mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
1603 "wmaster%d", ether_setup);
1604 if (!mdev)
1605 goto fail_mdev_alloc;
1606
1607 sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
1608 mdev->ieee80211_ptr = &sdata->wdev;
1609 sdata->wdev.wiphy = local->hw.wiphy;
1610
1611 local->mdev = mdev;
1612
1613 ieee80211_rx_bss_list_init(mdev);
1614
1615 mdev->hard_start_xmit = ieee80211_master_start_xmit;
1616 mdev->open = ieee80211_master_open;
1617 mdev->stop = ieee80211_master_stop;
1618 mdev->type = ARPHRD_IEEE80211;
1619 mdev->header_ops = &ieee80211_header_ops;
1620 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
1621
1622 sdata->vif.type = IEEE80211_IF_TYPE_AP;
1623 sdata->dev = mdev;
1624 sdata->local = local;
1625 sdata->u.ap.force_unicast_rateidx = -1;
1626 sdata->u.ap.max_ratectrl_rateidx = -1;
1627 ieee80211_if_sdata_init(sdata);
1628
1629 /* no RCU needed since we're still during init phase */
1630 list_add_tail(&sdata->list, &local->interfaces);
1631
1139 name = wiphy_dev(local->hw.wiphy)->driver->name; 1632 name = wiphy_dev(local->hw.wiphy)->driver->name;
1140 local->hw.workqueue = create_singlethread_workqueue(name); 1633 local->hw.workqueue = create_singlethread_workqueue(name);
1141 if (!local->hw.workqueue) { 1634 if (!local->hw.workqueue) {
@@ -1203,7 +1696,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
1203 1696
1204 /* add one default STA interface */ 1697 /* add one default STA interface */
1205 result = ieee80211_if_add(local->mdev, "wlan%d", NULL, 1698 result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
1206 IEEE80211_IF_TYPE_STA); 1699 IEEE80211_IF_TYPE_STA, NULL);
1207 if (result) 1700 if (result)
1208 printk(KERN_WARNING "%s: Failed to add default virtual iface\n", 1701 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
1209 wiphy_name(local->hw.wiphy)); 1702 wiphy_name(local->hw.wiphy));
@@ -1227,49 +1720,18 @@ fail_sta_info:
1227 debugfs_hw_del(local); 1720 debugfs_hw_del(local);
1228 destroy_workqueue(local->hw.workqueue); 1721 destroy_workqueue(local->hw.workqueue);
1229fail_workqueue: 1722fail_workqueue:
1723 ieee80211_if_free(local->mdev);
1724 local->mdev = NULL;
1725fail_mdev_alloc:
1230 wiphy_unregister(local->hw.wiphy); 1726 wiphy_unregister(local->hw.wiphy);
1231 return result; 1727 return result;
1232} 1728}
1233EXPORT_SYMBOL(ieee80211_register_hw); 1729EXPORT_SYMBOL(ieee80211_register_hw);
1234 1730
1235int ieee80211_register_hwmode(struct ieee80211_hw *hw,
1236 struct ieee80211_hw_mode *mode)
1237{
1238 struct ieee80211_local *local = hw_to_local(hw);
1239 struct ieee80211_rate *rate;
1240 int i;
1241
1242 INIT_LIST_HEAD(&mode->list);
1243 list_add_tail(&mode->list, &local->modes_list);
1244
1245 local->hw_modes |= (1 << mode->mode);
1246 for (i = 0; i < mode->num_rates; i++) {
1247 rate = &(mode->rates[i]);
1248 rate->rate_inv = CHAN_UTIL_RATE_LCM / rate->rate;
1249 }
1250 ieee80211_prepare_rates(local, mode);
1251
1252 if (!local->oper_hw_mode) {
1253 /* Default to this mode */
1254 local->hw.conf.phymode = mode->mode;
1255 local->oper_hw_mode = local->scan_hw_mode = mode;
1256 local->oper_channel = local->scan_channel = &mode->channels[0];
1257 local->hw.conf.mode = local->oper_hw_mode;
1258 local->hw.conf.chan = local->oper_channel;
1259 }
1260
1261 if (!(hw->flags & IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED))
1262 ieee80211_set_default_regdomain(mode);
1263
1264 return 0;
1265}
1266EXPORT_SYMBOL(ieee80211_register_hwmode);
1267
1268void ieee80211_unregister_hw(struct ieee80211_hw *hw) 1731void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1269{ 1732{
1270 struct ieee80211_local *local = hw_to_local(hw); 1733 struct ieee80211_local *local = hw_to_local(hw);
1271 struct ieee80211_sub_if_data *sdata, *tmp; 1734 struct ieee80211_sub_if_data *sdata, *tmp;
1272 int i;
1273 1735
1274 tasklet_kill(&local->tx_pending_tasklet); 1736 tasklet_kill(&local->tx_pending_tasklet);
1275 tasklet_kill(&local->tasklet); 1737 tasklet_kill(&local->tasklet);
@@ -1310,11 +1772,6 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1310 rate_control_deinitialize(local); 1772 rate_control_deinitialize(local);
1311 debugfs_hw_del(local); 1773 debugfs_hw_del(local);
1312 1774
1313 for (i = 0; i < NUM_IEEE80211_MODES; i++) {
1314 kfree(local->supp_rates[i]);
1315 kfree(local->basic_rates[i]);
1316 }
1317
1318 if (skb_queue_len(&local->skb_queue) 1775 if (skb_queue_len(&local->skb_queue)
1319 || skb_queue_len(&local->skb_queue_unreliable)) 1776 || skb_queue_len(&local->skb_queue_unreliable))
1320 printk(KERN_WARNING "%s: skb_queue not empty\n", 1777 printk(KERN_WARNING "%s: skb_queue not empty\n",
@@ -1326,6 +1783,8 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1326 wiphy_unregister(local->hw.wiphy); 1783 wiphy_unregister(local->hw.wiphy);
1327 ieee80211_wep_free(local); 1784 ieee80211_wep_free(local);
1328 ieee80211_led_exit(local); 1785 ieee80211_led_exit(local);
1786 ieee80211_if_free(local->mdev);
1787 local->mdev = NULL;
1329} 1788}
1330EXPORT_SYMBOL(ieee80211_unregister_hw); 1789EXPORT_SYMBOL(ieee80211_unregister_hw);
1331 1790
@@ -1333,7 +1792,6 @@ void ieee80211_free_hw(struct ieee80211_hw *hw)
1333{ 1792{
1334 struct ieee80211_local *local = hw_to_local(hw); 1793 struct ieee80211_local *local = hw_to_local(hw);
1335 1794
1336 ieee80211_if_free(local->mdev);
1337 wiphy_free(local->hw.wiphy); 1795 wiphy_free(local->hw.wiphy);
1338} 1796}
1339EXPORT_SYMBOL(ieee80211_free_hw); 1797EXPORT_SYMBOL(ieee80211_free_hw);
@@ -1345,13 +1803,9 @@ static int __init ieee80211_init(void)
1345 1803
1346 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb)); 1804 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
1347 1805
1348 ret = rc80211_simple_init();
1349 if (ret)
1350 goto out;
1351
1352 ret = rc80211_pid_init(); 1806 ret = rc80211_pid_init();
1353 if (ret) 1807 if (ret)
1354 goto out_cleanup_simple; 1808 goto out;
1355 1809
1356 ret = ieee80211_wme_register(); 1810 ret = ieee80211_wme_register();
1357 if (ret) { 1811 if (ret) {
@@ -1361,23 +1815,22 @@ static int __init ieee80211_init(void)
1361 } 1815 }
1362 1816
1363 ieee80211_debugfs_netdev_init(); 1817 ieee80211_debugfs_netdev_init();
1364 ieee80211_regdomain_init();
1365 1818
1366 return 0; 1819 return 0;
1367 1820
1368 out_cleanup_pid: 1821 out_cleanup_pid:
1369 rc80211_pid_exit(); 1822 rc80211_pid_exit();
1370 out_cleanup_simple:
1371 rc80211_simple_exit();
1372 out: 1823 out:
1373 return ret; 1824 return ret;
1374} 1825}
1375 1826
1376static void __exit ieee80211_exit(void) 1827static void __exit ieee80211_exit(void)
1377{ 1828{
1378 rc80211_simple_exit();
1379 rc80211_pid_exit(); 1829 rc80211_pid_exit();
1380 1830
1831 if (mesh_allocated)
1832 ieee80211s_stop();
1833
1381 ieee80211_wme_unregister(); 1834 ieee80211_wme_unregister();
1382 ieee80211_debugfs_netdev_exit(); 1835 ieee80211_debugfs_netdev_exit();
1383} 1836}