netfilter: xt_recent: inform user when hitcount is too large
[safe/jmp/linux-2.6] / net / mac80211 / work.c
index 0acea7c..7e708d5 100644 (file)
@@ -202,7 +202,7 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
        struct ieee80211_local *local = sdata->local;
        struct sk_buff *skb;
        struct ieee80211_mgmt *mgmt;
-       u8 *pos;
+       u8 *pos, qos_info;
        const u8 *ies;
        size_t offset = 0, noffset;
        int i, len, count, rates_len, supp_rates_len;
@@ -375,6 +375,14 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
        }
 
        if (wk->assoc.wmm_used && local->hw.queues >= 4) {
+               if (wk->assoc.uapsd_used) {
+                       qos_info = local->uapsd_queues;
+                       qos_info |= (local->uapsd_max_sp_len <<
+                                    IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
+               } else {
+                       qos_info = 0;
+               }
+
                pos = skb_put(skb, 9);
                *pos++ = WLAN_EID_VENDOR_SPECIFIC;
                *pos++ = 7; /* len */
@@ -384,7 +392,7 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
                *pos++ = 2; /* WME */
                *pos++ = 0; /* WME info */
                *pos++ = 1; /* WME ver */
-               *pos++ = 0;
+               *pos++ = qos_info;
        }
 
        /* add any remaining custom (i.e. vendor specific here) IEs */
@@ -435,12 +443,6 @@ ieee80211_direct_probe(struct ieee80211_work *wk)
                 */
                ieee80211_remove_auth_bss(local, wk);
 
-               /*
-                * We might have a pending scan which had no chance to run yet
-                * due to work needing to be done. Hence, queue the STAs work
-                * again for that.
-                */
-               ieee80211_queue_work(&local->hw, &local->work_work);
                return WORK_ACT_TIMEOUT;
        }
 
@@ -478,12 +480,6 @@ ieee80211_authenticate(struct ieee80211_work *wk)
                 */
                ieee80211_remove_auth_bss(local, wk);
 
-               /*
-                * We might have a pending scan which had no chance to run yet
-                * due to work needing to be done. Hence, queue the STAs work
-                * again for that.
-                */
-               ieee80211_queue_work(&local->hw, &local->work_work);
                return WORK_ACT_TIMEOUT;
        }
 
@@ -519,12 +515,6 @@ ieee80211_associate(struct ieee80211_work *wk)
                if (wk->assoc.bss)
                        cfg80211_unlink_bss(local->hw.wiphy, wk->assoc.bss);
 
-               /*
-                * We might have a pending scan which had no chance to run yet
-                * due to work needing to be done. Hence, queue the STAs work
-                * again for that.
-                */
-               ieee80211_queue_work(&local->hw, &local->work_work);
                return WORK_ACT_TIMEOUT;
        }
 
@@ -541,39 +531,21 @@ ieee80211_associate(struct ieee80211_work *wk)
 static enum work_action __must_check
 ieee80211_remain_on_channel_timeout(struct ieee80211_work *wk)
 {
-       struct ieee80211_sub_if_data *sdata = wk->sdata;
-       struct ieee80211_local *local = sdata->local;
-
        /*
         * First time we run, do nothing -- the generic code will
         * have switched to the right channel etc.
         */
-       if (wk->timeout != wk->remain.timeout) {
-               wk->timeout = wk->remain.timeout;
-               return WORK_ACT_NONE;
-       }
+       if (!wk->started) {
+               wk->timeout = jiffies + msecs_to_jiffies(wk->remain.duration);
 
-       /*
-        * We are done serving the remain-on-channel command; kill the work
-        * item to allow idle state to be entered again. In addition, clear the
-        * temporary channel information to allow operational channel to be
-        * used.
-        */
-       list_del(&wk->list);
-       free_work(wk);
+               cfg80211_ready_on_channel(wk->sdata->dev, (unsigned long) wk,
+                                         wk->chan, wk->chan_type,
+                                         wk->remain.duration, GFP_KERNEL);
 
-       if (local->tmp_channel) {
-               cfg80211_remain_on_channel_expired(sdata->dev, (u64)wk,
-                                                  local->tmp_channel,
-                                                  local->tmp_channel_type,
-                                                  GFP_KERNEL);
-
-               local->tmp_channel = NULL;
-               ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
-               ieee80211_offchannel_return(local, true);
+               return WORK_ACT_NONE;
        }
 
-       return WORK_ACT_NONE;
+       return WORK_ACT_TIMEOUT;
 }
 
 static void ieee80211_auth_challenge(struct ieee80211_work *wk,
@@ -799,7 +771,7 @@ static void ieee80211_work_rx_queued_mgmt(struct ieee80211_local *local,
                break;
        case WORK_DONE_REQUEUE:
                synchronize_rcu();
-               wk->timeout = jiffies; /* run again directly */
+               wk->started = false; /* restart */
                mutex_lock(&local->work_mtx);
                list_add_tail(&wk->list, &local->work_list);
                mutex_unlock(&local->work_mtx);
@@ -827,6 +799,7 @@ static void ieee80211_work_work(struct work_struct *work)
        struct ieee80211_work *wk, *tmp;
        LIST_HEAD(free_work);
        enum work_action rma;
+       bool remain_off_channel = false;
 
        if (local->scanning)
                return;
@@ -847,6 +820,37 @@ static void ieee80211_work_work(struct work_struct *work)
        mutex_lock(&local->work_mtx);
 
        list_for_each_entry_safe(wk, tmp, &local->work_list, list) {
+               bool started = wk->started;
+
+               /* mark work as started if it's on the current off-channel */
+               if (!started && local->tmp_channel &&
+                   wk->chan == local->tmp_channel &&
+                   wk->chan_type == local->tmp_channel_type) {
+                       started = true;
+                       wk->timeout = jiffies;
+               }
+
+               if (!started && !local->tmp_channel) {
+                       /*
+                        * TODO: could optimize this by leaving the
+                        *       station vifs in awake mode if they
+                        *       happen to be on the same channel as
+                        *       the requested channel
+                        */
+                       ieee80211_offchannel_stop_beaconing(local);
+                       ieee80211_offchannel_stop_station(local);
+
+                       local->tmp_channel = wk->chan;
+                       local->tmp_channel_type = wk->chan_type;
+                       ieee80211_hw_config(local, 0);
+                       started = true;
+                       wk->timeout = jiffies;
+               }
+
+               /* don't try to work with items that aren't started */
+               if (!started)
+                       continue;
+
                if (time_is_after_jiffies(wk->timeout)) {
                        /*
                         * This work item isn't supposed to be worked on
@@ -879,9 +883,12 @@ static void ieee80211_work_work(struct work_struct *work)
                        break;
                }
 
+               wk->started = started;
+
                switch (rma) {
                case WORK_ACT_NONE:
-                       /* no action required */
+                       /* might have changed the timeout */
+                       run_again(local, wk->timeout);
                        break;
                case WORK_ACT_TIMEOUT:
                        list_del_rcu(&wk->list);
@@ -893,6 +900,24 @@ static void ieee80211_work_work(struct work_struct *work)
                }
        }
 
+       list_for_each_entry(wk, &local->work_list, list) {
+               if (!wk->started)
+                       continue;
+               if (wk->chan != local->tmp_channel)
+                       continue;
+               if (wk->chan_type != local->tmp_channel_type)
+                       continue;
+               remain_off_channel = true;
+       }
+
+       if (!remain_off_channel && local->tmp_channel) {
+               local->tmp_channel = NULL;
+               ieee80211_hw_config(local, 0);
+               ieee80211_offchannel_return(local, true);
+               /* give connection some time to breathe */
+               run_again(local, jiffies + HZ/2);
+       }
+
        if (list_empty(&local->work_list) && local->scan_req)
                ieee80211_queue_delayed_work(&local->hw,
                                             &local->scan_work,
@@ -900,6 +925,8 @@ static void ieee80211_work_work(struct work_struct *work)
 
        mutex_unlock(&local->work_mtx);
 
+       ieee80211_recalc_idle(local);
+
        list_for_each_entry_safe(wk, tmp, &free_work, list) {
                wk->done(wk, NULL);
                list_del(&wk->list);
@@ -920,7 +947,10 @@ void ieee80211_add_work(struct ieee80211_work *wk)
        if (WARN_ON(!wk->done))
                return;
 
-       wk->timeout = jiffies;
+       if (WARN_ON(!ieee80211_sdata_running(wk->sdata)))
+               return;
+
+       wk->started = false;
 
        local = wk->sdata->local;
        mutex_lock(&local->work_mtx);
@@ -950,6 +980,8 @@ void ieee80211_work_purge(struct ieee80211_sub_if_data *sdata)
                if (wk->sdata != sdata)
                        continue;
                wk->type = IEEE80211_WORK_ABORT;
+               wk->started = true;
+               wk->timeout = jiffies;
        }
        mutex_unlock(&local->work_mtx);
 
@@ -993,8 +1025,6 @@ ieee80211_rx_result ieee80211_work_rx_mgmt(struct ieee80211_sub_if_data *sdata,
                case IEEE80211_STYPE_PROBE_RESP:
                case IEEE80211_STYPE_ASSOC_RESP:
                case IEEE80211_STYPE_REASSOC_RESP:
-               case IEEE80211_STYPE_DEAUTH:
-               case IEEE80211_STYPE_DISASSOC:
                        skb_queue_tail(&local->work_skb_queue, skb);
                        ieee80211_queue_work(&local->hw, &local->work_work);
                        return RX_QUEUED;
@@ -1004,12 +1034,24 @@ ieee80211_rx_result ieee80211_work_rx_mgmt(struct ieee80211_sub_if_data *sdata,
        return RX_CONTINUE;
 }
 
+static enum work_done_result ieee80211_remain_done(struct ieee80211_work *wk,
+                                                  struct sk_buff *skb)
+{
+       /*
+        * We are done serving the remain-on-channel command.
+        */
+       cfg80211_remain_on_channel_expired(wk->sdata->dev, (unsigned long) wk,
+                                          wk->chan, wk->chan_type,
+                                          GFP_KERNEL);
+
+       return WORK_DONE_DESTROY;
+}
+
 int ieee80211_wk_remain_on_channel(struct ieee80211_sub_if_data *sdata,
                                   struct ieee80211_channel *chan,
                                   enum nl80211_channel_type channel_type,
                                   unsigned int duration, u64 *cookie)
 {
-       struct ieee80211_local *local = sdata->local;
        struct ieee80211_work *wk;
 
        wk = kzalloc(sizeof(*wk), GFP_KERNEL);
@@ -1018,28 +1060,16 @@ int ieee80211_wk_remain_on_channel(struct ieee80211_sub_if_data *sdata,
 
        wk->type = IEEE80211_WORK_REMAIN_ON_CHANNEL;
        wk->chan = chan;
+       wk->chan_type = channel_type;
        wk->sdata = sdata;
+       wk->done = ieee80211_remain_done;
 
-       wk->remain.timeout = jiffies + msecs_to_jiffies(duration);
+       wk->remain.duration = duration;
 
-       *cookie = (u64)wk;
+       *cookie = (unsigned long) wk;
 
        ieee80211_add_work(wk);
 
-       /*
-        * TODO: could optimize this by leaving the station vifs in awake mode
-        * if they happen to be on the same channel as the requested channel
-        */
-       ieee80211_offchannel_stop_beaconing(local);
-       ieee80211_offchannel_stop_station(local);
-
-       sdata->local->tmp_channel = chan;
-       sdata->local->tmp_channel_type = channel_type;
-       ieee80211_hw_config(sdata->local, IEEE80211_CONF_CHANGE_CHANNEL);
-
-       cfg80211_ready_on_channel(sdata->dev, (u64)wk, chan, channel_type,
-                                 duration, GFP_KERNEL);
-
        return 0;
 }
 
@@ -1052,10 +1082,9 @@ int ieee80211_wk_cancel_remain_on_channel(struct ieee80211_sub_if_data *sdata,
 
        mutex_lock(&local->work_mtx);
        list_for_each_entry_safe(wk, tmp, &local->work_list, list) {
-               if ((u64)wk == cookie) {
+               if ((unsigned long) wk == cookie) {
+                       wk->timeout = jiffies;
                        found = true;
-                       list_del(&wk->list);
-                       free_work(wk);
                        break;
                }
        }
@@ -1064,14 +1093,7 @@ int ieee80211_wk_cancel_remain_on_channel(struct ieee80211_sub_if_data *sdata,
        if (!found)
                return -ENOENT;
 
-       if (sdata->local->tmp_channel) {
-               sdata->local->tmp_channel = NULL;
-               ieee80211_hw_config(sdata->local,
-                                   IEEE80211_CONF_CHANGE_CHANNEL);
-               ieee80211_offchannel_return(sdata->local, true);
-       }
-
-       ieee80211_recalc_idle(local);
+       ieee80211_queue_work(&local->hw, &local->work_work);
 
        return 0;
 }