cfg80211: fix netdev down problem
[pandora-kernel.git] / net / wireless / core.c
index d41b741..83ec719 100644 (file)
@@ -321,6 +321,7 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
        }
 
        INIT_WORK(&drv->rfkill_sync, cfg80211_rfkill_sync_work);
+       INIT_WORK(&drv->conn_work, cfg80211_conn_work);
 
        /*
         * Initialize wiphy parameters to IEEE 802.11 MIB default values.
@@ -481,6 +482,8 @@ void wiphy_unregister(struct wiphy *wiphy)
        /* unlock again before freeing */
        mutex_unlock(&drv->mtx);
 
+       cancel_work_sync(&drv->conn_work);
+
        cfg80211_debugfs_drv_del(drv);
 
        /* If this device got a regulatory hint tell core its
@@ -546,26 +549,59 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
                                "symlink to netdev!\n");
                }
                wdev->netdev = dev;
+               wdev->sme_state = CFG80211_SME_IDLE;
+               mutex_unlock(&rdev->devlist_mtx);
 #ifdef CONFIG_WIRELESS_EXT
                wdev->wext.default_key = -1;
                wdev->wext.default_mgmt_key = -1;
+               wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
+               wdev->wext.ps = CONFIG_CFG80211_DEFAULT_PS_VALUE;
+               wdev->wext.ps_timeout = 500;
+               if (rdev->ops->set_power_mgmt)
+                       if (rdev->ops->set_power_mgmt(wdev->wiphy, dev,
+                                                     wdev->wext.ps,
+                                                     wdev->wext.ps_timeout)) {
+                               /* assume this means it's off */
+                               wdev->wext.ps = false;
+                       }
 #endif
-               mutex_unlock(&rdev->devlist_mtx);
                break;
        case NETDEV_GOING_DOWN:
-               if (wdev->iftype != NL80211_IFTYPE_ADHOC)
+               switch (wdev->iftype) {
+               case NL80211_IFTYPE_ADHOC:
+                       cfg80211_leave_ibss(rdev, dev, true);
                        break;
-               if (!wdev->ssid_len)
+               case NL80211_IFTYPE_STATION:
+#ifdef CONFIG_WIRELESS_EXT
+                       kfree(wdev->wext.ie);
+                       wdev->wext.ie = NULL;
+                       wdev->wext.ie_len = 0;
+                       wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
+#endif
+                       cfg80211_disconnect(rdev, dev,
+                                           WLAN_REASON_DEAUTH_LEAVING, true);
+                       cfg80211_mlme_down(rdev, dev);
                        break;
-               cfg80211_leave_ibss(rdev, dev, true);
+               default:
+                       break;
+               }
                break;
        case NETDEV_UP:
 #ifdef CONFIG_WIRELESS_EXT
-               if (wdev->iftype != NL80211_IFTYPE_ADHOC)
+               switch (wdev->iftype) {
+               case NL80211_IFTYPE_ADHOC:
+                       if (wdev->wext.ibss.ssid_len)
+                               cfg80211_join_ibss(rdev, dev,
+                                                  &wdev->wext.ibss);
                        break;
-               if (!wdev->wext.ibss.ssid_len)
+               case NL80211_IFTYPE_STATION:
+                       if (wdev->wext.connect.ssid_len)
+                               cfg80211_connect(rdev, dev,
+                                                &wdev->wext.connect);
                        break;
-               cfg80211_join_ibss(rdev, dev, &wdev->wext.ibss);
+               default:
+                       break;
+               }
 #endif
                break;
        case NETDEV_UNREGISTER: