mac80211: use PS Poll and Nullfunc templates when sending such frames
authorKalle Valo <kalle.valo@nokia.com>
Tue, 5 Jan 2010 18:16:26 +0000 (20:16 +0200)
committerJohn W. Linville <linville@tuxdriver.com>
Tue, 12 Jan 2010 18:51:24 +0000 (13:51 -0500)
To avoid duplicate code, use ieee80211_[pspoll|nullfunc]_get() to get
templates for PS Poll and Nullfunc frames in mlme.c.

Compile-tested only.

Signed-off-by: Kalle Valo <kalle.valo@nokia.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
net/mac80211/mlme.c

index 97bcf2278bdb4b9c5d15d99e7d8985f3afa529ae..5484cf930a873187c26aab84b365d23d5120e657 100644 (file)
@@ -249,30 +249,15 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
 void ieee80211_send_pspoll(struct ieee80211_local *local,
                           struct ieee80211_sub_if_data *sdata)
 {
-       struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
        struct ieee80211_pspoll *pspoll;
        struct sk_buff *skb;
-       u16 fc;
 
-       skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
-       if (!skb) {
-               printk(KERN_DEBUG "%s: failed to allocate buffer for "
-                      "pspoll frame\n", sdata->name);
+       skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
+       if (!skb)
                return;
-       }
-       skb_reserve(skb, local->hw.extra_tx_headroom);
-
-       pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
-       memset(pspoll, 0, sizeof(*pspoll));
-       fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL | IEEE80211_FCTL_PM;
-       pspoll->frame_control = cpu_to_le16(fc);
-       pspoll->aid = cpu_to_le16(ifmgd->aid);
 
-       /* aid in PS-Poll has its two MSBs each set to 1 */
-       pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
-
-       memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
-       memcpy(pspoll->ta, sdata->vif.addr, ETH_ALEN);
+       pspoll = (struct ieee80211_pspoll *) skb->data;
+       pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
 
        IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
        ieee80211_tx_skb(sdata, skb);
@@ -283,30 +268,15 @@ void ieee80211_send_nullfunc(struct ieee80211_local *local,
                             int powersave)
 {
        struct sk_buff *skb;
-       struct ieee80211_hdr *nullfunc;
-       __le16 fc;
+       struct ieee80211_hdr_3addr *nullfunc;
 
-       if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
+       skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
+       if (!skb)
                return;
 
-       skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
-       if (!skb) {
-               printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
-                      "frame\n", sdata->name);
-               return;
-       }
-       skb_reserve(skb, local->hw.extra_tx_headroom);
-
-       nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
-       memset(nullfunc, 0, 24);
-       fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
-                        IEEE80211_FCTL_TODS);
+       nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
        if (powersave)
-               fc |= cpu_to_le16(IEEE80211_FCTL_PM);
-       nullfunc->frame_control = fc;
-       memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
-       memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
-       memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
+               nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
 
        IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
        ieee80211_tx_skb(sdata, skb);