mac80211: improve powersave implementation
[deliverable/linux.git] / net / mac80211 / mlme.c
index 7ecda9d59d8a8e0d2eabefde24472a5538b9de3d..06d9a1d23252510657790ada62962cfd0702f1eb 100644 (file)
@@ -80,6 +80,89 @@ static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
        return count;
 }
 
+/*
+ * ieee80211_enable_ht should be called only after the operating band
+ * has been determined as ht configuration depends on the hw's
+ * HT abilities for a specific band.
+ */
+static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
+                              struct ieee80211_ht_info *hti,
+                              u16 ap_ht_cap_flags)
+{
+       struct ieee80211_local *local = sdata->local;
+       struct ieee80211_supported_band *sband;
+       struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
+       struct ieee80211_bss_ht_conf ht;
+       struct sta_info *sta;
+       u32 changed = 0;
+       bool enable_ht = true, ht_changed;
+       enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
+
+       sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+
+       memset(&ht, 0, sizeof(ht));
+
+       /* HT is not supported */
+       if (!sband->ht_cap.ht_supported)
+               enable_ht = false;
+
+       /* check that channel matches the right operating channel */
+       if (local->hw.conf.channel->center_freq !=
+           ieee80211_channel_to_frequency(hti->control_chan))
+               enable_ht = false;
+
+       if (enable_ht) {
+               channel_type = NL80211_CHAN_HT20;
+
+               if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
+                   (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
+                   (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
+                       switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
+                       case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
+                               channel_type = NL80211_CHAN_HT40PLUS;
+                               break;
+                       case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
+                               channel_type = NL80211_CHAN_HT40MINUS;
+                               break;
+                       }
+               }
+       }
+
+       ht_changed = conf_is_ht(&local->hw.conf) != enable_ht ||
+                    channel_type != local->hw.conf.channel_type;
+
+       local->oper_channel_type = channel_type;
+
+       if (ht_changed) {
+                /* channel_type change automatically detected */
+               ieee80211_hw_config(local, 0);
+
+               rcu_read_lock();
+
+               sta = sta_info_get(local, ifmgd->bssid);
+               if (sta)
+                       rate_control_rate_update(local, sband, sta,
+                                                IEEE80211_RC_HT_CHANGED);
+
+               rcu_read_unlock();
+
+        }
+
+       /* disable HT */
+       if (!enable_ht)
+               return 0;
+
+       ht.operation_mode = le16_to_cpu(hti->operation_mode);
+
+       /* if bss configuration changed store the new one */
+       if (memcmp(&sdata->vif.bss_conf.ht, &ht, sizeof(ht))) {
+               changed |= BSS_CHANGED_HT;
+               sdata->vif.bss_conf.ht = ht;
+       }
+
+       return changed;
+}
+
 /* frame sending functions */
 
 static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
@@ -325,6 +408,10 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
        /* u.deauth.reason_code == u.disassoc.reason_code */
        mgmt->u.deauth.reason_code = cpu_to_le16(reason);
 
+       if (stype == IEEE80211_STYPE_DEAUTH)
+               cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, skb->len);
+       else
+               cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, skb->len);
        ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED);
 }
 
@@ -359,6 +446,145 @@ void ieee80211_send_pspoll(struct ieee80211_local *local,
        ieee80211_tx_skb(sdata, skb, 0);
 }
 
+void ieee80211_send_nullfunc(struct ieee80211_local *local,
+                            struct ieee80211_sub_if_data *sdata,
+                            int powersave)
+{
+       struct sk_buff *skb;
+       struct ieee80211_hdr *nullfunc;
+       __le16 fc;
+
+       if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
+               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->dev->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);
+       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->dev->dev_addr, ETH_ALEN);
+       memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
+
+       ieee80211_tx_skb(sdata, skb, 0);
+}
+
+/* powersave */
+static void ieee80211_enable_ps(struct ieee80211_local *local,
+                               struct ieee80211_sub_if_data *sdata)
+{
+       struct ieee80211_conf *conf = &local->hw.conf;
+
+       if (conf->dynamic_ps_timeout > 0 &&
+           !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
+               mod_timer(&local->dynamic_ps_timer, jiffies +
+                         msecs_to_jiffies(conf->dynamic_ps_timeout));
+       } else {
+               if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
+                       ieee80211_send_nullfunc(local, sdata, 1);
+               conf->flags |= IEEE80211_CONF_PS;
+               ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
+       }
+}
+
+static void ieee80211_change_ps(struct ieee80211_local *local)
+{
+       struct ieee80211_conf *conf = &local->hw.conf;
+
+       if (local->ps_sdata) {
+               if (!(local->ps_sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED))
+                       return;
+
+               ieee80211_enable_ps(local, local->ps_sdata);
+       } else if (conf->flags & IEEE80211_CONF_PS) {
+               conf->flags &= ~IEEE80211_CONF_PS;
+               ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
+               del_timer_sync(&local->dynamic_ps_timer);
+               cancel_work_sync(&local->dynamic_ps_enable_work);
+       }
+}
+
+/* need to hold RTNL or interface lock */
+void ieee80211_recalc_ps(struct ieee80211_local *local)
+{
+       struct ieee80211_sub_if_data *sdata, *found = NULL;
+       int count = 0;
+
+       if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
+               local->ps_sdata = NULL;
+               return;
+       }
+
+       list_for_each_entry(sdata, &local->interfaces, list) {
+               if (!netif_running(sdata->dev))
+                       continue;
+               if (sdata->vif.type != NL80211_IFTYPE_STATION)
+                       continue;
+               found = sdata;
+               count++;
+       }
+
+       if (count == 1 && found->u.mgd.powersave)
+               local->ps_sdata = found;
+       else
+               local->ps_sdata = NULL;
+
+       ieee80211_change_ps(local);
+}
+
+void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
+{
+       struct ieee80211_local *local =
+               container_of(work, struct ieee80211_local,
+                            dynamic_ps_disable_work);
+
+       if (local->hw.conf.flags & IEEE80211_CONF_PS) {
+               local->hw.conf.flags &= ~IEEE80211_CONF_PS;
+               ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
+       }
+
+       ieee80211_wake_queues_by_reason(&local->hw,
+                                       IEEE80211_QUEUE_STOP_REASON_PS);
+}
+
+void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
+{
+       struct ieee80211_local *local =
+               container_of(work, struct ieee80211_local,
+                            dynamic_ps_enable_work);
+       struct ieee80211_sub_if_data *sdata = local->ps_sdata;
+
+       /* can only happen when PS was just disabled anyway */
+       if (!sdata)
+               return;
+
+       if (local->hw.conf.flags & IEEE80211_CONF_PS)
+               return;
+
+       if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
+               ieee80211_send_nullfunc(local, sdata, 1);
+
+       local->hw.conf.flags |= IEEE80211_CONF_PS;
+       ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
+}
+
+void ieee80211_dynamic_ps_timer(unsigned long data)
+{
+       struct ieee80211_local *local = (void *) data;
+
+       queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
+}
+
 /* MLME */
 static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
                                     struct ieee80211_if_managed *ifmgd,
@@ -441,6 +667,9 @@ static bool ieee80211_check_tim(struct ieee802_11_elems *elems, u16 aid)
        u8 index, indexn1, indexn2;
        struct ieee80211_tim_ie *tim = (struct ieee80211_tim_ie *) elems->tim;
 
+       if (unlikely(!tim || elems->tim_len < 4))
+               return false;
+
        aid &= 0x3fff;
        index = aid / 8;
        mask  = 1 << (aid & 7);
@@ -631,19 +860,9 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
        bss_info_changed |= BSS_CHANGED_BASIC_RATES;
        ieee80211_bss_info_change_notify(sdata, bss_info_changed);
 
-       if (local->powersave) {
-               if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) &&
-                   local->hw.conf.dynamic_ps_timeout > 0) {
-                       mod_timer(&local->dynamic_ps_timer, jiffies +
-                                 msecs_to_jiffies(
-                                       local->hw.conf.dynamic_ps_timeout));
-               } else {
-                       if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
-                               ieee80211_send_nullfunc(local, sdata, 1);
-                       conf->flags |= IEEE80211_CONF_PS;
-                       ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
-               }
-       }
+       /* will be same as sdata */
+       if (local->ps_sdata)
+               ieee80211_enable_ps(local, sdata);
 
        netif_tx_start_all_queues(sdata->dev);
        netif_carrier_on(sdata->dev);
@@ -945,9 +1164,13 @@ void ieee80211_beacon_loss_work(struct work_struct *work)
                             u.mgd.beacon_loss_work);
        struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
 
-       printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM "
-              "- sending probe request\n", sdata->dev->name,
-              sdata->u.mgd.bssid);
+#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+       if (net_ratelimit()) {
+               printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM "
+                      "- sending probe request\n", sdata->dev->name,
+                      sdata->u.mgd.bssid);
+       }
+#endif
 
        ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
        ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
@@ -1007,9 +1230,13 @@ static void ieee80211_associated(struct ieee80211_sub_if_data *sdata)
              (local->hw.conf.flags & IEEE80211_CONF_PS)) &&
            time_after(jiffies,
                       ifmgd->last_beacon + IEEE80211_MONITORING_INTERVAL)) {
-               printk(KERN_DEBUG "%s: beacon loss from AP %pM "
-                      "- sending probe request\n",
-                      sdata->dev->name, ifmgd->bssid);
+#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+               if (net_ratelimit()) {
+                       printk(KERN_DEBUG "%s: beacon loss from AP %pM "
+                              "- sending probe request\n",
+                              sdata->dev->name, ifmgd->bssid);
+               }
+#endif
                ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
                ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
                                         ifmgd->ssid_len, NULL, 0);
@@ -1176,7 +1403,7 @@ static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
 
        ieee80211_set_disassoc(sdata, true, false, 0);
        ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
-       cfg80211_send_rx_deauth(sdata->dev, (u8 *) mgmt, len);
+       cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, len);
 }
 
 
@@ -1207,7 +1434,7 @@ static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
        }
 
        ieee80211_set_disassoc(sdata, false, false, reason_code);
-       cfg80211_send_rx_disassoc(sdata->dev, (u8 *) mgmt, len);
+       cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, len);
 }
 
 
@@ -1276,6 +1503,11 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
                 * association next time. This works around some broken APs
                 * which do not correctly reject reassociation requests. */
                ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
+               cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
+               if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
+                       /* Wait for SME to decide what to do next */
+                       ifmgd->state = IEEE80211_STA_MLME_DISABLED;
+               }
                return;
        }
 
@@ -1355,7 +1587,7 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
 
        for (i = 0; i < elems.ext_supp_rates_len; i++) {
                int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
-               bool is_basic = !!(elems.supp_rates[i] & 0x80);
+               bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
 
                if (rate > 110)
                        have_higher_than_11mbit = true;
@@ -1902,9 +2134,17 @@ static void ieee80211_sta_work(struct work_struct *work)
 
 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
 {
-       if (sdata->vif.type == NL80211_IFTYPE_STATION)
+       if (sdata->vif.type == NL80211_IFTYPE_STATION) {
+               /*
+                * Need to update last_beacon to avoid beacon loss
+                * test to trigger.
+                */
+               sdata->u.mgd.last_beacon = jiffies;
+
+
                queue_work(sdata->local->hw.workqueue,
                           &sdata->u.mgd.work);
+       }
 }
 
 /* interface setup */
@@ -2084,75 +2324,3 @@ void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
                ieee80211_restart_sta_timer(sdata);
        rcu_read_unlock();
 }
-
-void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
-{
-       struct ieee80211_local *local =
-               container_of(work, struct ieee80211_local,
-                            dynamic_ps_disable_work);
-
-       if (local->hw.conf.flags & IEEE80211_CONF_PS) {
-               local->hw.conf.flags &= ~IEEE80211_CONF_PS;
-               ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
-       }
-
-       ieee80211_wake_queues_by_reason(&local->hw,
-                                       IEEE80211_QUEUE_STOP_REASON_PS);
-}
-
-void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
-{
-       struct ieee80211_local *local =
-               container_of(work, struct ieee80211_local,
-                            dynamic_ps_enable_work);
-       struct ieee80211_sub_if_data *sdata = local->scan_sdata;
-
-       if (local->hw.conf.flags & IEEE80211_CONF_PS)
-               return;
-
-       if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
-               ieee80211_send_nullfunc(local, sdata, 1);
-
-       local->hw.conf.flags |= IEEE80211_CONF_PS;
-       ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
-}
-
-void ieee80211_dynamic_ps_timer(unsigned long data)
-{
-       struct ieee80211_local *local = (void *) data;
-
-       queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
-}
-
-void ieee80211_send_nullfunc(struct ieee80211_local *local,
-                            struct ieee80211_sub_if_data *sdata,
-                            int powersave)
-{
-       struct sk_buff *skb;
-       struct ieee80211_hdr *nullfunc;
-       __le16 fc;
-
-       if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
-               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->dev->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);
-       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->dev->dev_addr, ETH_ALEN);
-       memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
-
-       ieee80211_tx_skb(sdata, skb, 0);
-}
This page took 0.041859 seconds and 5 git commands to generate.