]> err.no Git - linux-2.6/blobdiff - net/mac80211/util.c
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6] / net / mac80211 / util.c
index d9109dee461f02a974fbf1d1a6fa7eb525f614da..ce62b163b82c46d2e8814e29d1f5ce73a2f250c3 100644 (file)
@@ -34,49 +34,48 @@ void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
 
 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
-const unsigned char rfc1042_header[] =
+const unsigned char rfc1042_header[] __aligned(2) =
        { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
 
 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
-const unsigned char bridge_tunnel_header[] =
+const unsigned char bridge_tunnel_header[] __aligned(2) =
        { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
 
 
 u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
                        enum ieee80211_if_types type)
 {
-       u16 fc;
+       __le16 fc = hdr->frame_control;
 
         /* drop ACK/CTS frames and incorrect hdr len (ctrl) */
        if (len < 16)
                return NULL;
 
-       fc = le16_to_cpu(hdr->frame_control);
-
-       switch (fc & IEEE80211_FCTL_FTYPE) {
-       case IEEE80211_FTYPE_DATA:
+       if (ieee80211_is_data(fc)) {
                if (len < 24) /* drop incorrect hdr len (data) */
                        return NULL;
-               switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
-               case IEEE80211_FCTL_TODS:
-                       return hdr->addr1;
-               case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
+
+               if (ieee80211_has_a4(fc))
                        return NULL;
-               case IEEE80211_FCTL_FROMDS:
+               if (ieee80211_has_tods(fc))
+                       return hdr->addr1;
+               if (ieee80211_has_fromds(fc))
                        return hdr->addr2;
-               case 0:
-                       return hdr->addr3;
-               }
-               break;
-       case IEEE80211_FTYPE_MGMT:
+
+               return hdr->addr3;
+       }
+
+       if (ieee80211_is_mgmt(fc)) {
                if (len < 24) /* drop incorrect hdr len (mgmt) */
                        return NULL;
                return hdr->addr3;
-       case IEEE80211_FTYPE_CTL:
-               if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)
+       }
+
+       if (ieee80211_is_ctl(fc)) {
+               if(ieee80211_is_pspoll(fc))
                        return hdr->addr1;
-               else if ((fc & IEEE80211_FCTL_STYPE) ==
-                                               IEEE80211_STYPE_BACK_REQ) {
+
+               if (ieee80211_is_back_req(fc)) {
                        switch (type) {
                        case IEEE80211_IF_TYPE_STA:
                                return hdr->addr2;
@@ -84,11 +83,9 @@ u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
                        case IEEE80211_IF_TYPE_VLAN:
                                return hdr->addr1;
                        default:
-                               return NULL;
+                               break; /* fall through to the return */
                        }
                }
-               else
-                       return NULL;
        }
 
        return NULL;
@@ -133,14 +130,46 @@ int ieee80211_get_hdrlen(u16 fc)
 }
 EXPORT_SYMBOL(ieee80211_get_hdrlen);
 
-int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
+unsigned int ieee80211_hdrlen(__le16 fc)
+{
+       unsigned int hdrlen = 24;
+
+       if (ieee80211_is_data(fc)) {
+               if (ieee80211_has_a4(fc))
+                       hdrlen = 30;
+               if (ieee80211_is_data_qos(fc))
+                       hdrlen += IEEE80211_QOS_CTL_LEN;
+               goto out;
+       }
+
+       if (ieee80211_is_ctl(fc)) {
+               /*
+                * ACK and CTS are 10 bytes, all others 16. To see how
+                * to get this condition consider
+                *   subtype mask:   0b0000000011110000 (0x00F0)
+                *   ACK subtype:    0b0000000011010000 (0x00D0)
+                *   CTS subtype:    0b0000000011000000 (0x00C0)
+                *   bits that matter:         ^^^      (0x00E0)
+                *   value of those: 0b0000000011000000 (0x00C0)
+                */
+               if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
+                       hdrlen = 10;
+               else
+                       hdrlen = 16;
+       }
+out:
+       return hdrlen;
+}
+EXPORT_SYMBOL(ieee80211_hdrlen);
+
+unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
 {
-       const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *) skb->data;
-       int hdrlen;
+       const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *)skb->data;
+       unsigned int hdrlen;
 
        if (unlikely(skb->len < 10))
                return 0;
-       hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control));
+       hdrlen = ieee80211_hdrlen(hdr->frame_control);
        if (unlikely(hdrlen > skb->len))
                return 0;
        return hdrlen;
@@ -331,17 +360,15 @@ void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
 {
        struct ieee80211_local *local = hw_to_local(hw);
 
-       if (test_and_clear_bit(IEEE80211_LINK_STATE_XOFF,
-                              &local->state[queue])) {
-               if (test_bit(IEEE80211_LINK_STATE_PENDING,
-                            &local->state[queue]))
-                       tasklet_schedule(&local->tx_pending_tasklet);
-               else
-                       if (!ieee80211_qdisc_installed(local->mdev)) {
-                               if (queue == 0)
-                                       netif_wake_queue(local->mdev);
-                       } else
-                               __netif_schedule(local->mdev);
+       if (test_bit(queue, local->queues_pending)) {
+               tasklet_schedule(&local->tx_pending_tasklet);
+       } else {
+               if (ieee80211_is_multiqueue(local)) {
+                       netif_wake_subqueue(local->mdev, queue);
+               } else {
+                       WARN_ON(queue != 0);
+                       netif_wake_queue(local->mdev);
+               }
        }
 }
 EXPORT_SYMBOL(ieee80211_wake_queue);
@@ -350,9 +377,12 @@ void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
 {
        struct ieee80211_local *local = hw_to_local(hw);
 
-       if (!ieee80211_qdisc_installed(local->mdev) && queue == 0)
+       if (ieee80211_is_multiqueue(local)) {
+               netif_stop_subqueue(local->mdev, queue);
+       } else {
+               WARN_ON(queue != 0);
                netif_stop_queue(local->mdev);
-       set_bit(IEEE80211_LINK_STATE_XOFF, &local->state[queue]);
+       }
 }
 EXPORT_SYMBOL(ieee80211_stop_queue);
 
@@ -360,7 +390,7 @@ void ieee80211_stop_queues(struct ieee80211_hw *hw)
 {
        int i;
 
-       for (i = 0; i < hw->queues + hw->ampdu_queues; i++)
+       for (i = 0; i < ieee80211_num_queues(hw); i++)
                ieee80211_stop_queue(hw, i);
 }
 EXPORT_SYMBOL(ieee80211_stop_queues);
@@ -383,6 +413,41 @@ void ieee80211_iterate_active_interfaces(
        struct ieee80211_local *local = hw_to_local(hw);
        struct ieee80211_sub_if_data *sdata;
 
+       rtnl_lock();
+
+       list_for_each_entry(sdata, &local->interfaces, list) {
+               switch (sdata->vif.type) {
+               case IEEE80211_IF_TYPE_INVALID:
+               case IEEE80211_IF_TYPE_MNTR:
+               case IEEE80211_IF_TYPE_VLAN:
+                       continue;
+               case IEEE80211_IF_TYPE_AP:
+               case IEEE80211_IF_TYPE_STA:
+               case IEEE80211_IF_TYPE_IBSS:
+               case IEEE80211_IF_TYPE_WDS:
+               case IEEE80211_IF_TYPE_MESH_POINT:
+                       break;
+               }
+               if (sdata->dev == local->mdev)
+                       continue;
+               if (netif_running(sdata->dev))
+                       iterator(data, sdata->dev->dev_addr,
+                                &sdata->vif);
+       }
+
+       rtnl_unlock();
+}
+EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces);
+
+void ieee80211_iterate_active_interfaces_atomic(
+       struct ieee80211_hw *hw,
+       void (*iterator)(void *data, u8 *mac,
+                        struct ieee80211_vif *vif),
+       void *data)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+       struct ieee80211_sub_if_data *sdata;
+
        rcu_read_lock();
 
        list_for_each_entry_rcu(sdata, &local->interfaces, list) {
@@ -407,4 +472,4 @@ void ieee80211_iterate_active_interfaces(
 
        rcu_read_unlock();
 }
-EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces);
+EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);