ipv4: flush route cache after change accept_local
[linux-2.6.git] / net / mac80211 / scan.c
index 0ea6ada..6f09eca 100644 (file)
@@ -170,7 +170,7 @@ ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
                return RX_CONTINUE;
 
        if (skb->len < 24)
-               return RX_DROP_MONITOR;
+               return RX_CONTINUE;
 
        presp = ieee80211_is_probe_resp(fc);
        if (presp) {
@@ -251,17 +251,19 @@ static bool ieee80211_prep_hw_scan(struct ieee80211_local *local)
        local->hw_scan_req->n_channels = n_chans;
 
        ielen = ieee80211_build_preq_ies(local, (u8 *)local->hw_scan_req->ie,
-                                        req->ie, req->ie_len, band, (u32) -1,
-                                        0);
+                                        req->ie, req->ie_len, band,
+                                        req->rates[band], 0);
        local->hw_scan_req->ie_len = ielen;
 
        return true;
 }
 
-static bool __ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted,
+static void __ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted,
                                       bool was_hw_scan)
 {
        struct ieee80211_local *local = hw_to_local(hw);
+       bool on_oper_chan;
+       bool enable_beacons = false;
 
        lockdep_assert_held(&local->mtx);
 
@@ -275,12 +277,12 @@ static bool __ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted,
                aborted = true;
 
        if (WARN_ON(!local->scan_req))
-               return false;
+               return;
 
        if (was_hw_scan && !aborted && ieee80211_prep_hw_scan(local)) {
                int rc = drv_hw_scan(local, local->scan_sdata, local->hw_scan_req);
                if (rc == 0)
-                       return false;
+                       return;
        }
 
        kfree(local->hw_scan_req);
@@ -294,24 +296,13 @@ static bool __ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted,
        local->scanning = 0;
        local->scan_channel = NULL;
 
-       return true;
-}
-
-static void __ieee80211_scan_completed_finish(struct ieee80211_hw *hw,
-                                             bool was_hw_scan)
-{
-       struct ieee80211_local *local = hw_to_local(hw);
-       bool on_oper_chan;
-       bool enable_beacons = false;
-
-       mutex_lock(&local->mtx);
        on_oper_chan = ieee80211_cfg_on_oper_channel(local);
 
-       if (was_hw_scan || !on_oper_chan) {
-               if (WARN_ON(local->scan_channel))
-                       local->scan_channel = NULL;
+       if (was_hw_scan || !on_oper_chan)
                ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
-       }
+       else
+               /* Set power back to normal operating levels. */
+               ieee80211_hw_config(local, 0);
 
        if (!was_hw_scan) {
                bool on_oper_chan2;
@@ -327,7 +318,6 @@ static void __ieee80211_scan_completed_finish(struct ieee80211_hw *hw,
        }
 
        ieee80211_recalc_idle(local);
-       mutex_unlock(&local->mtx);
 
        ieee80211_mlme_notify_scan_completed(local);
        ieee80211_ibss_notify_scan_completed(local);
@@ -377,6 +367,9 @@ static int ieee80211_start_sw_scan(struct ieee80211_local *local)
 
        ieee80211_configure_filter(local);
 
+       /* We need to set power level at maximum rate for scanning. */
+       ieee80211_hw_config(local, 0);
+
        ieee80211_queue_delayed_work(&local->hw,
                                     &local->scan_work,
                                     IEEE80211_CHANNEL_TIME);
@@ -517,8 +510,7 @@ static void ieee80211_scan_state_decision(struct ieee80211_local *local,
 
        if (ieee80211_cfg_on_oper_channel(local)) {
                /* We're currently on operating channel. */
-               if ((next_chan == local->oper_channel) &&
-                   (local->_oper_channel_type == NL80211_CHAN_NO_HT))
+               if (next_chan == local->oper_channel)
                        /* We don't need to move off of operating channel. */
                        local->next_scan_state = SCAN_SET_CHANNEL;
                else
@@ -620,8 +612,7 @@ static void ieee80211_scan_state_set_channel(struct ieee80211_local *local,
        local->scan_channel = chan;
 
        /* Only call hw-config if we really need to change channels. */
-       if ((chan != local->hw.conf.channel) ||
-           (local->hw.conf.channel_type != NL80211_CHAN_NO_HT))
+       if (chan != local->hw.conf.channel)
                if (ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL))
                        skip = 1;
 
@@ -661,13 +652,15 @@ static void ieee80211_scan_state_send_probe(struct ieee80211_local *local,
 {
        int i;
        struct ieee80211_sub_if_data *sdata = local->scan_sdata;
+       enum ieee80211_band band = local->hw.conf.channel->band;
 
        for (i = 0; i < local->scan_req->n_ssids; i++)
                ieee80211_send_probe_req(
                        sdata, NULL,
                        local->scan_req->ssids[i].ssid,
                        local->scan_req->ssids[i].ssid_len,
-                       local->scan_req->ie, local->scan_req->ie_len);
+                       local->scan_req->ie, local->scan_req->ie_len,
+                       local->scan_req->rates[band], false);
 
        /*
         * After sending probe requests, wait for probe responses
@@ -681,12 +674,14 @@ void ieee80211_scan_work(struct work_struct *work)
 {
        struct ieee80211_local *local =
                container_of(work, struct ieee80211_local, scan_work.work);
-       struct ieee80211_sub_if_data *sdata = local->scan_sdata;
+       struct ieee80211_sub_if_data *sdata;
        unsigned long next_delay = 0;
-       bool aborted, hw_scan, finish;
+       bool aborted, hw_scan;
 
        mutex_lock(&local->mtx);
 
+       sdata = local->scan_sdata;
+
        if (test_and_clear_bit(SCAN_COMPLETED, &local->scanning)) {
                aborted = test_and_clear_bit(SCAN_ABORTED, &local->scanning);
                goto out_complete;
@@ -725,6 +720,11 @@ void ieee80211_scan_work(struct work_struct *work)
         * without scheduling a new work
         */
        do {
+               if (!ieee80211_sdata_running(sdata)) {
+                       aborted = true;
+                       goto out_complete;
+               }
+
                switch (local->next_scan_state) {
                case SCAN_DECISION:
                        /* if no more bands/channels left, complete scan */
@@ -750,17 +750,11 @@ void ieee80211_scan_work(struct work_struct *work)
        } while (next_delay == 0);
 
        ieee80211_queue_delayed_work(&local->hw, &local->scan_work, next_delay);
-       mutex_unlock(&local->mtx);
-       return;
+       goto out;
 
 out_complete:
        hw_scan = test_bit(SCAN_HW_SCANNING, &local->scanning);
-       finish = __ieee80211_scan_completed(&local->hw, aborted, hw_scan);
-       mutex_unlock(&local->mtx);
-       if (finish)
-               __ieee80211_scan_completed_finish(&local->hw, hw_scan);
-       return;
-
+       __ieee80211_scan_completed(&local->hw, aborted, hw_scan);
 out:
        mutex_unlock(&local->mtx);
 }
@@ -829,11 +823,8 @@ int ieee80211_request_internal_scan(struct ieee80211_sub_if_data *sdata,
  */
 void ieee80211_scan_cancel(struct ieee80211_local *local)
 {
-       bool abortscan;
-       bool finish = false;
-
        /*
-        * We are only canceling software scan, or deferred scan that was not
+        * We are canceling software scan, or deferred scan that was not
         * yet really started (see __ieee80211_start_scan ).
         *
         * Regarding hardware scan:
@@ -845,19 +836,149 @@ void ieee80211_scan_cancel(struct ieee80211_local *local)
         * - we can not cancel scan_work since driver can schedule it
         *   by ieee80211_scan_completed(..., true) to finish scan
         *
-        * Hence low lever driver is responsible for canceling HW scan.
+        * Hence we only call the cancel_hw_scan() callback, but the low-level
+        * driver is still responsible for calling ieee80211_scan_completed()
+        * after the scan was completed/aborted.
         */
 
        mutex_lock(&local->mtx);
-       abortscan = local->scan_req && !test_bit(SCAN_HW_SCANNING, &local->scanning);
-       if (abortscan)
-               finish = __ieee80211_scan_completed(&local->hw, true, false);
+       if (!local->scan_req)
+               goto out;
+
+       if (test_bit(SCAN_HW_SCANNING, &local->scanning)) {
+               if (local->ops->cancel_hw_scan)
+                       drv_cancel_hw_scan(local, local->scan_sdata);
+               goto out;
+       }
+
+       /*
+        * If the work is currently running, it must be blocked on
+        * the mutex, but we'll set scan_sdata = NULL and it'll
+        * simply exit once it acquires the mutex.
+        */
+       cancel_delayed_work(&local->scan_work);
+       /* and clean up */
+       __ieee80211_scan_completed(&local->hw, true, false);
+out:
        mutex_unlock(&local->mtx);
+}
+
+int ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata,
+                                      struct cfg80211_sched_scan_request *req)
+{
+       struct ieee80211_local *local = sdata->local;
+       int ret, i;
 
-       if (abortscan) {
-               /* The scan is canceled, but stop work from being pending */
-               cancel_delayed_work_sync(&local->scan_work);
+       mutex_lock(&sdata->local->mtx);
+
+       if (local->sched_scanning) {
+               ret = -EBUSY;
+               goto out;
        }
-       if (finish)
-               __ieee80211_scan_completed_finish(&local->hw, false);
+
+       if (!local->ops->sched_scan_start) {
+               ret = -ENOTSUPP;
+               goto out;
+       }
+
+       for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
+               local->sched_scan_ies.ie[i] = kzalloc(2 +
+                                                     IEEE80211_MAX_SSID_LEN +
+                                                     local->scan_ies_len +
+                                                     req->ie_len,
+                                                     GFP_KERNEL);
+               if (!local->sched_scan_ies.ie[i]) {
+                       ret = -ENOMEM;
+                       goto out_free;
+               }
+
+               local->sched_scan_ies.len[i] =
+                       ieee80211_build_preq_ies(local,
+                                                local->sched_scan_ies.ie[i],
+                                                req->ie, req->ie_len, i,
+                                                (u32) -1, 0);
+       }
+
+       ret = drv_sched_scan_start(local, sdata, req,
+                                  &local->sched_scan_ies);
+       if (ret == 0) {
+               local->sched_scanning = true;
+               goto out;
+       }
+
+out_free:
+       while (i > 0)
+               kfree(local->sched_scan_ies.ie[--i]);
+out:
+       mutex_unlock(&sdata->local->mtx);
+       return ret;
+}
+
+int ieee80211_request_sched_scan_stop(struct ieee80211_sub_if_data *sdata)
+{
+       struct ieee80211_local *local = sdata->local;
+       int ret = 0, i;
+
+       mutex_lock(&sdata->local->mtx);
+
+       if (!local->ops->sched_scan_stop) {
+               ret = -ENOTSUPP;
+               goto out;
+       }
+
+       if (local->sched_scanning) {
+               for (i = 0; i < IEEE80211_NUM_BANDS; i++)
+                       kfree(local->sched_scan_ies.ie[i]);
+
+               drv_sched_scan_stop(local, sdata);
+               local->sched_scanning = false;
+       }
+out:
+       mutex_unlock(&sdata->local->mtx);
+
+       return ret;
+}
+
+void ieee80211_sched_scan_results(struct ieee80211_hw *hw)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+
+       trace_api_sched_scan_results(local);
+
+       cfg80211_sched_scan_results(hw->wiphy);
+}
+EXPORT_SYMBOL(ieee80211_sched_scan_results);
+
+void ieee80211_sched_scan_stopped_work(struct work_struct *work)
+{
+       struct ieee80211_local *local =
+               container_of(work, struct ieee80211_local,
+                            sched_scan_stopped_work);
+       int i;
+
+       mutex_lock(&local->mtx);
+
+       if (!local->sched_scanning) {
+               mutex_unlock(&local->mtx);
+               return;
+       }
+
+       for (i = 0; i < IEEE80211_NUM_BANDS; i++)
+               kfree(local->sched_scan_ies.ie[i]);
+
+       local->sched_scanning = false;
+
+       mutex_unlock(&local->mtx);
+
+       cfg80211_sched_scan_stopped(local->hw.wiphy);
+}
+
+void ieee80211_sched_scan_stopped(struct ieee80211_hw *hw)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+
+       trace_api_sched_scan_stopped(local);
+
+       ieee80211_queue_work(&local->hw, &local->sched_scan_stopped_work);
 }
+EXPORT_SYMBOL(ieee80211_sched_scan_stopped);