Merge git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-2.6
[pandora-kernel.git] / net / mac80211 / iface.c
index c261cdb..c20dddd 100644 (file)
@@ -62,6 +62,23 @@ static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
        return 0;
 }
 
+static int ieee80211_change_mac(struct net_device *dev, void *addr)
+{
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       struct sockaddr *sa = addr;
+       int ret;
+
+       if (ieee80211_sdata_running(sdata))
+               return -EBUSY;
+
+       ret = eth_mac_addr(dev, sa);
+
+       if (ret == 0)
+               memcpy(sdata->vif.addr, sa->sa_data, ETH_ALEN);
+
+       return ret;
+}
+
 static inline int identical_mac_addr_allowed(int type1, int type2)
 {
        return type1 == NL80211_IFTYPE_MONITOR ||
@@ -82,7 +99,6 @@ static int ieee80211_open(struct net_device *dev)
        struct ieee80211_sub_if_data *nsdata;
        struct ieee80211_local *local = sdata->local;
        struct sta_info *sta;
-       struct ieee80211_if_init_conf conf;
        u32 changed = 0;
        int res;
        u32 hw_reconf_flags = 0;
@@ -97,7 +113,7 @@ static int ieee80211_open(struct net_device *dev)
        list_for_each_entry(nsdata, &local->interfaces, list) {
                struct net_device *ndev = nsdata->dev;
 
-               if (ndev != dev && netif_running(ndev)) {
+               if (ndev != dev && ieee80211_sdata_running(nsdata)) {
                        /*
                         * Allow only a single IBSS interface to be up at any
                         * time. This is restricted because beacon distribution
@@ -183,7 +199,7 @@ static int ieee80211_open(struct net_device *dev)
                struct net_device *ndev = nsdata->dev;
 
                /*
-                * No need to check netif_running since we do not allow
+                * No need to check running since we do not allow
                 * it to start up with this invalid address.
                 */
                if (compare_ether_addr(null_addr, ndev->dev_addr) == 0) {
@@ -234,10 +250,7 @@ static int ieee80211_open(struct net_device *dev)
                ieee80211_configure_filter(local);
                break;
        default:
-               conf.vif = &sdata->vif;
-               conf.type = sdata->vif.type;
-               conf.mac_addr = dev->dev_addr;
-               res = drv_add_interface(local, &conf);
+               res = drv_add_interface(local, &sdata->vif);
                if (res)
                        goto err_stop;
 
@@ -320,7 +333,7 @@ static int ieee80211_open(struct net_device *dev)
 
        return 0;
  err_del_interface:
-       drv_remove_interface(local, &conf);
+       drv_remove_interface(local, &sdata->vif);
  err_stop:
        if (!local->open_count)
                drv_stop(local);
@@ -335,7 +348,6 @@ static int ieee80211_stop(struct net_device *dev)
 {
        struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
        struct ieee80211_local *local = sdata->local;
-       struct ieee80211_if_init_conf conf;
        struct sta_info *sta;
        unsigned long flags;
        struct sk_buff *skb, *tmp;
@@ -347,6 +359,11 @@ static int ieee80211_stop(struct net_device *dev)
         */
        netif_stop_queue(dev);
 
+       /*
+        * Purge work for this interface.
+        */
+       ieee80211_work_purge(sdata);
+
        /*
         * Now delete all active aggregation sessions.
         */
@@ -514,12 +531,9 @@ static int ieee80211_stop(struct net_device *dev)
                                BSS_CHANGED_BEACON_ENABLED);
                }
 
-               conf.vif = &sdata->vif;
-               conf.type = sdata->vif.type;
-               conf.mac_addr = dev->dev_addr;
                /* disable all keys for as long as this netdev is down */
                ieee80211_disable_keys(sdata);
-               drv_remove_interface(local, &conf);
+               drv_remove_interface(local, &sdata->vif);
        }
 
        sdata->bss = NULL;
@@ -659,7 +673,7 @@ static const struct net_device_ops ieee80211_dataif_ops = {
        .ndo_start_xmit         = ieee80211_subif_start_xmit,
        .ndo_set_multicast_list = ieee80211_set_multicast_list,
        .ndo_change_mtu         = ieee80211_change_mtu,
-       .ndo_set_mac_address    = eth_mac_addr,
+       .ndo_set_mac_address    = ieee80211_change_mac,
        .ndo_select_queue       = ieee80211_netdev_select_queue,
 };
 
@@ -775,7 +789,7 @@ int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
         * and goes into the requested mode.
         */
 
-       if (netif_running(sdata->dev))
+       if (ieee80211_sdata_running(sdata))
                return -EBUSY;
 
        /* Purge and reset type-dependent state. */
@@ -829,6 +843,8 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
        /* don't use IEEE80211_DEV_TO_SUB_IF because it checks too much */
        sdata = netdev_priv(ndev);
        ndev->ieee80211_ptr = &sdata->wdev;
+       memcpy(sdata->vif.addr, ndev->dev_addr, ETH_ALEN);
+       memcpy(sdata->name, ndev->name, IFNAMSIZ);
 
        /* initialise type-independent data */
        sdata->wdev.wiphy = local->hw.wiphy;
@@ -934,6 +950,8 @@ static u32 ieee80211_idle_on(struct ieee80211_local *local)
               wiphy_name(local->hw.wiphy));
 #endif
 
+       drv_flush(local, false);
+
        local->hw.conf.flags |= IEEE80211_CONF_IDLE;
        return IEEE80211_CONF_CHANGE_IDLE;
 }
@@ -943,16 +961,18 @@ u32 __ieee80211_recalc_idle(struct ieee80211_local *local)
        struct ieee80211_sub_if_data *sdata;
        int count = 0;
 
+       if (!list_empty(&local->work_list))
+               return ieee80211_idle_off(local, "working");
+
        if (local->scanning)
                return ieee80211_idle_off(local, "scanning");
 
        list_for_each_entry(sdata, &local->interfaces, list) {
-               if (!netif_running(sdata->dev))
+               if (!ieee80211_sdata_running(sdata))
                        continue;
                /* do not count disabled managed interfaces */
                if (sdata->vif.type == NL80211_IFTYPE_STATION &&
-                   !sdata->u.mgd.associated &&
-                   list_empty(&sdata->u.mgd.work_list))
+                   !sdata->u.mgd.associated)
                        continue;
                /* do not count unused IBSS interfaces */
                if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
@@ -980,3 +1000,41 @@ void ieee80211_recalc_idle(struct ieee80211_local *local)
        if (chg)
                ieee80211_hw_config(local, chg);
 }
+
+static int netdev_notify(struct notifier_block *nb,
+                        unsigned long state,
+                        void *ndev)
+{
+       struct net_device *dev = ndev;
+       struct ieee80211_sub_if_data *sdata;
+
+       if (state != NETDEV_CHANGENAME)
+               return 0;
+
+       if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
+               return 0;
+
+       if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
+               return 0;
+
+       sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+
+       memcpy(sdata->name, sdata->name, IFNAMSIZ);
+
+       ieee80211_debugfs_rename_netdev(sdata);
+       return 0;
+}
+
+static struct notifier_block mac80211_netdev_notifier = {
+       .notifier_call = netdev_notify,
+};
+
+int ieee80211_iface_init(void)
+{
+       return register_netdevice_notifier(&mac80211_netdev_notifier);
+}
+
+void ieee80211_iface_exit(void)
+{
+       unregister_netdevice_notifier(&mac80211_netdev_notifier);
+}