iface.c
Go to the documentation of this file.
00001 /*
00002  * Interface handling (except master interface)
00003  *
00004  * Copyright 2002-2005, Instant802 Networks, Inc.
00005  * Copyright 2005-2006, Devicescape Software, Inc.
00006  * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
00007  * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License version 2 as
00011  * published by the Free Software Foundation.
00012  */
00013 #include <linux/slab.h>
00014 #include <linux/kernel.h>
00015 #include <linux/if_arp.h>
00016 #include <linux/netdevice.h>
00017 #include <linux/rtnetlink.h>
00018 #include <net/mac80211.h>
00019 #include <net/ieee80211_radiotap.h>
00020 #include "ieee80211_i.h"
00021 #include "sta_info.h"
00022 #include "debugfs_netdev.h"
00023 #include "mesh.h"
00024 #include "led.h"
00025 #include "driver-ops.h"
00026 #include "wme.h"
00027 #include "rate.h"
00028 
00046 static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
00047 {
00048         int meshhdrlen;
00049         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
00050 
00051         meshhdrlen = (sdata->vif.type == NL80211_IFTYPE_MESH_POINT) ? 5 : 0;
00052 
00053         /* FIX: what would be proper limits for MTU?
00054          * This interface uses 802.3 frames. */
00055         if (new_mtu < 256 ||
00056             new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) {
00057                 return -EINVAL;
00058         }
00059 
00060 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
00061         printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
00062 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
00063         dev->mtu = new_mtu;
00064         return 0;
00065 }
00066 
00067 static int ieee80211_change_mac(struct net_device *dev, void *addr)
00068 {
00069         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
00070         struct sockaddr *sa = addr;
00071         int ret;
00072 
00073         if (ieee80211_sdata_running(sdata))
00074                 return -EBUSY;
00075 
00076         ret = eth_mac_addr(dev, sa);
00077 
00078         if (ret == 0)
00079                 memcpy(sdata->vif.addr, sa->sa_data, ETH_ALEN);
00080 
00081         return ret;
00082 }
00083 
00084 static inline int identical_mac_addr_allowed(int type1, int type2)
00085 {
00086         return type1 == NL80211_IFTYPE_MONITOR ||
00087                 type2 == NL80211_IFTYPE_MONITOR ||
00088                 (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_WDS) ||
00089                 (type1 == NL80211_IFTYPE_WDS &&
00090                         (type2 == NL80211_IFTYPE_WDS ||
00091                          type2 == NL80211_IFTYPE_AP)) ||
00092                 (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_AP_VLAN) ||
00093                 (type1 == NL80211_IFTYPE_AP_VLAN &&
00094                         (type2 == NL80211_IFTYPE_AP ||
00095                          type2 == NL80211_IFTYPE_AP_VLAN));
00096 }
00097 
00098 static int ieee80211_check_concurrent_iface(struct ieee80211_sub_if_data *sdata,
00099                                             enum nl80211_iftype iftype)
00100 {
00101         struct ieee80211_local *local = sdata->local;
00102         struct ieee80211_sub_if_data *nsdata;
00103         struct net_device *dev = sdata->dev;
00104 
00105         ASSERT_RTNL();
00106 
00107         /* we hold the RTNL here so can safely walk the list */
00108         list_for_each_entry(nsdata, &local->interfaces, list) {
00109                 struct net_device *ndev = nsdata->dev;
00110 
00111                 if (ndev != dev && ieee80211_sdata_running(nsdata)) {
00112                         /*
00113                          * Allow only a single IBSS interface to be up at any
00114                          * time. This is restricted because beacon distribution
00115                          * cannot work properly if both are in the same IBSS.
00116                          *
00117                          * To remove this restriction we'd have to disallow them
00118                          * from setting the same SSID on different IBSS interfaces
00119                          * belonging to the same hardware. Then, however, we're
00120                          * faced with having to adopt two different TSF timers...
00121                          */
00122                         if (iftype == NL80211_IFTYPE_ADHOC &&
00123                             nsdata->vif.type == NL80211_IFTYPE_ADHOC)
00124                                 return -EBUSY;
00125 
00126                         /*
00127                          * The remaining checks are only performed for interfaces
00128                          * with the same MAC address.
00129                          */
00130                         if (compare_ether_addr(dev->dev_addr, ndev->dev_addr))
00131                                 continue;
00132 
00133                         /*
00134                          * check whether it may have the same address
00135                          */
00136                         if (!identical_mac_addr_allowed(iftype,
00137                                                         nsdata->vif.type))
00138                                 return -ENOTUNIQ;
00139 
00140                         /*
00141                          * can only add VLANs to enabled APs
00142                          */
00143                         if (iftype == NL80211_IFTYPE_AP_VLAN &&
00144                             nsdata->vif.type == NL80211_IFTYPE_AP)
00145                                 sdata->bss = &nsdata->u.ap;
00146                 }
00147         }
00148 
00149         return 0;
00150 }
00151 
00152 void ieee80211_adjust_monitor_flags(struct ieee80211_sub_if_data *sdata,
00153                                     const int offset)
00154 {
00155         struct ieee80211_local *local = sdata->local;
00156         u32 flags = sdata->u.mntr_flags;
00157 
00158 #define ADJUST(_f, _s)  do {                                    \
00159         if (flags & MONITOR_FLAG_##_f)                          \
00160                 local->fif_##_s += offset;                      \
00161         } while (0)
00162 
00163         ADJUST(FCSFAIL, fcsfail);
00164         ADJUST(PLCPFAIL, plcpfail);
00165         ADJUST(CONTROL, control);
00166         ADJUST(CONTROL, pspoll);
00167         ADJUST(OTHER_BSS, other_bss);
00168 
00169 #undef ADJUST
00170 }
00171 
00172 /*
00173  * NOTE: Be very careful when changing this function, it must NOT return
00174  * an error on interface type changes that have been pre-checked, so most
00175  * checks should be in ieee80211_check_concurrent_iface.
00176  */
00177 static int ieee80211_do_open(struct net_device *dev, bool coming_up)
00178 {
00179         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
00180         struct ieee80211_local *local = sdata->local;
00181         struct sta_info *sta;
00182         u32 changed = 0;
00183         int res;
00184         u32 hw_reconf_flags = 0;
00185 
00186         switch (sdata->vif.type) {
00187         case NL80211_IFTYPE_WDS:
00188                 if (!is_valid_ether_addr(sdata->u.wds.remote_addr))
00189                         return -ENOLINK;
00190                 break;
00191         case NL80211_IFTYPE_AP_VLAN:
00192                 if (!sdata->bss)
00193                         return -ENOLINK;
00194                 list_add(&sdata->u.vlan.list, &sdata->bss->vlans);
00195                 break;
00196         case NL80211_IFTYPE_AP:
00197                 sdata->bss = &sdata->u.ap;
00198                 break;
00199         case NL80211_IFTYPE_MESH_POINT:
00200         case NL80211_IFTYPE_STATION:
00201         case NL80211_IFTYPE_MONITOR:
00202         case NL80211_IFTYPE_ADHOC:
00203                 /* no special treatment */
00204                 break;
00205         case NL80211_IFTYPE_UNSPECIFIED:
00206         case NUM_NL80211_IFTYPES:
00207         case NL80211_IFTYPE_P2P_CLIENT:
00208         case NL80211_IFTYPE_P2P_GO:
00209                 /* cannot happen */
00210                 WARN_ON(1);
00211                 break;
00212         }
00213 
00214         if (local->open_count == 0) {
00215                 res = drv_start(local);
00216                 if (res)
00217                         goto err_del_bss;
00218                 if (local->ops->napi_poll)
00219                         napi_enable(&local->napi);
00220                 /* we're brought up, everything changes */
00221                 hw_reconf_flags = ~0;
00222                 ieee80211_led_radio(local, true);
00223                 ieee80211_mod_tpt_led_trig(local,
00224                                            IEEE80211_TPT_LEDTRIG_FL_RADIO, 0);
00225         }
00226 
00227         /*
00228          * Copy the hopefully now-present MAC address to
00229          * this interface, if it has the special null one.
00230          */
00231         if (is_zero_ether_addr(dev->dev_addr)) {
00232                 memcpy(dev->dev_addr,
00233                        local->hw.wiphy->perm_addr,
00234                        ETH_ALEN);
00235                 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
00236 
00237                 if (!is_valid_ether_addr(dev->dev_addr)) {
00238                         if (!local->open_count)
00239                                 drv_stop(local);
00240                         return -EADDRNOTAVAIL;
00241                 }
00242         }
00243 
00244         switch (sdata->vif.type) {
00245         case NL80211_IFTYPE_AP_VLAN:
00246                 /* no need to tell driver */
00247                 break;
00248         case NL80211_IFTYPE_MONITOR:
00249                 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
00250                         local->cooked_mntrs++;
00251                         break;
00252                 }
00253 
00254                 /* must be before the call to ieee80211_configure_filter */
00255                 local->monitors++;
00256                 if (local->monitors == 1) {
00257                         local->hw.conf.flags |= IEEE80211_CONF_MONITOR;
00258                         hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
00259                 }
00260 
00261                 ieee80211_adjust_monitor_flags(sdata, 1);
00262                 ieee80211_configure_filter(local);
00263 
00264                 netif_carrier_on(dev);
00265                 break;
00266         default:
00267                 if (coming_up) {
00268                         res = drv_add_interface(local, &sdata->vif);
00269                         if (res)
00270                                 goto err_stop;
00271                 }
00272 
00273                 if (sdata->vif.type == NL80211_IFTYPE_AP) {
00274                         local->fif_pspoll++;
00275                         local->fif_probe_req++;
00276 
00277                         ieee80211_configure_filter(local);
00278                 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
00279                         local->fif_probe_req++;
00280                 }
00281 
00282                 changed |= ieee80211_reset_erp_info(sdata);
00283                 ieee80211_bss_info_change_notify(sdata, changed);
00284 
00285                 if (sdata->vif.type == NL80211_IFTYPE_STATION)
00286                         netif_carrier_off(dev);
00287                 else
00288                         netif_carrier_on(dev);
00289         }
00290 
00291         set_bit(SDATA_STATE_RUNNING, &sdata->state);
00292 
00293         if (sdata->vif.type == NL80211_IFTYPE_WDS) {
00294                 /* Create STA entry for the WDS peer */
00295                 sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
00296                                      GFP_KERNEL);
00297                 if (!sta) {
00298                         res = -ENOMEM;
00299                         goto err_del_interface;
00300                 }
00301 
00302                 /* no atomic bitop required since STA is not live yet */
00303                 set_sta_flag(sta, WLAN_STA_AUTHORIZED);
00304 
00305                 res = sta_info_insert(sta);
00306                 if (res) {
00307                         /* STA has been freed */
00308                         goto err_del_interface;
00309                 }
00310 
00311                 rate_control_rate_init(sta);
00312         }
00313 
00314         /*
00315          * set_multicast_list will be invoked by the networking core
00316          * which will check whether any increments here were done in
00317          * error and sync them down to the hardware as filter flags.
00318          */
00319         if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
00320                 atomic_inc(&local->iff_allmultis);
00321 
00322         if (sdata->flags & IEEE80211_SDATA_PROMISC)
00323                 atomic_inc(&local->iff_promiscs);
00324 
00325         mutex_lock(&local->mtx);
00326         hw_reconf_flags |= __ieee80211_recalc_idle(local);
00327         mutex_unlock(&local->mtx);
00328 
00329         if (coming_up)
00330                 local->open_count++;
00331 
00332         if (hw_reconf_flags) {
00333                 ieee80211_hw_config(local, hw_reconf_flags);
00334                 /*
00335                  * set default queue parameters so drivers don't
00336                  * need to initialise the hardware if the hardware
00337                  * doesn't start up with sane defaults
00338                  */
00339                 ieee80211_set_wmm_default(sdata);
00340         }
00341 
00342         ieee80211_recalc_ps(local, -1);
00343 
00344         netif_tx_start_all_queues(dev);
00345 
00346         return 0;
00347  err_del_interface:
00348         drv_remove_interface(local, &sdata->vif);
00349  err_stop:
00350         if (!local->open_count)
00351                 drv_stop(local);
00352  err_del_bss:
00353         sdata->bss = NULL;
00354         if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
00355                 list_del(&sdata->u.vlan.list);
00356         clear_bit(SDATA_STATE_RUNNING, &sdata->state);
00357         return res;
00358 }
00359 
00360 static int ieee80211_open(struct net_device *dev)
00361 {
00362         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
00363         int err;
00364 
00365         /* fail early if user set an invalid address */
00366         if (!is_valid_ether_addr(dev->dev_addr))
00367                 return -EADDRNOTAVAIL;
00368 
00369         err = ieee80211_check_concurrent_iface(sdata, sdata->vif.type);
00370         if (err)
00371                 return err;
00372 
00373         return ieee80211_do_open(dev, true);
00374 }
00375 
00376 static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
00377                               bool going_down)
00378 {
00379         struct ieee80211_local *local = sdata->local;
00380         unsigned long flags;
00381         struct sk_buff *skb, *tmp;
00382         u32 hw_reconf_flags = 0;
00383         int i;
00384         enum nl80211_channel_type orig_ct;
00385 
00386         clear_bit(SDATA_STATE_RUNNING, &sdata->state);
00387 
00388         if (local->scan_sdata == sdata)
00389                 ieee80211_scan_cancel(local);
00390 
00391         /*
00392          * Stop TX on this interface first.
00393          */
00394         netif_tx_stop_all_queues(sdata->dev);
00395 
00396         /*
00397          * Purge work for this interface.
00398          */
00399         ieee80211_work_purge(sdata);
00400 
00401         /*
00402          * Remove all stations associated with this interface.
00403          *
00404          * This must be done before calling ops->remove_interface()
00405          * because otherwise we can later invoke ops->sta_notify()
00406          * whenever the STAs are removed, and that invalidates driver
00407          * assumptions about always getting a vif pointer that is valid
00408          * (because if we remove a STA after ops->remove_interface()
00409          * the driver will have removed the vif info already!)
00410          *
00411          * This is relevant only in AP, WDS and mesh modes, since in
00412          * all other modes we've already removed all stations when
00413          * disconnecting etc.
00414          */
00415         sta_info_flush(local, sdata);
00416 
00417         /*
00418          * Don't count this interface for promisc/allmulti while it
00419          * is down. dev_mc_unsync() will invoke set_multicast_list
00420          * on the master interface which will sync these down to the
00421          * hardware as filter flags.
00422          */
00423         if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
00424                 atomic_dec(&local->iff_allmultis);
00425 
00426         if (sdata->flags & IEEE80211_SDATA_PROMISC)
00427                 atomic_dec(&local->iff_promiscs);
00428 
00429         if (sdata->vif.type == NL80211_IFTYPE_AP) {
00430                 local->fif_pspoll--;
00431                 local->fif_probe_req--;
00432         } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
00433                 local->fif_probe_req--;
00434         }
00435 
00436         netif_addr_lock_bh(sdata->dev);
00437         spin_lock_bh(&local->filter_lock);
00438         __hw_addr_unsync(&local->mc_list, &sdata->dev->mc,
00439                          sdata->dev->addr_len);
00440         spin_unlock_bh(&local->filter_lock);
00441         netif_addr_unlock_bh(sdata->dev);
00442 
00443         ieee80211_configure_filter(local);
00444 
00445         del_timer_sync(&local->dynamic_ps_timer);
00446         cancel_work_sync(&local->dynamic_ps_enable_work);
00447 
00448         /* APs need special treatment */
00449         if (sdata->vif.type == NL80211_IFTYPE_AP) {
00450                 struct ieee80211_sub_if_data *vlan, *tmpsdata;
00451                 struct beacon_data *old_beacon =
00452                         rtnl_dereference(sdata->u.ap.beacon);
00453 
00454                 /* sdata_running will return false, so this will disable */
00455                 ieee80211_bss_info_change_notify(sdata,
00456                                                  BSS_CHANGED_BEACON_ENABLED);
00457 
00458                 /* remove beacon */
00459                 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
00460                 synchronize_rcu();
00461                 kfree(old_beacon);
00462 
00463                 /* down all dependent devices, that is VLANs */
00464                 list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans,
00465                                          u.vlan.list)
00466                         dev_close(vlan->dev);
00467                 WARN_ON(!list_empty(&sdata->u.ap.vlans));
00468 
00469                 /* free all potentially still buffered bcast frames */
00470                 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps_bc_buf);
00471                 skb_queue_purge(&sdata->u.ap.ps_bc_buf);
00472         }
00473 
00474         if (going_down)
00475                 local->open_count--;
00476 
00477         switch (sdata->vif.type) {
00478         case NL80211_IFTYPE_AP_VLAN:
00479                 list_del(&sdata->u.vlan.list);
00480                 /* no need to tell driver */
00481                 break;
00482         case NL80211_IFTYPE_MONITOR:
00483                 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
00484                         local->cooked_mntrs--;
00485                         break;
00486                 }
00487 
00488                 local->monitors--;
00489                 if (local->monitors == 0) {
00490                         local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR;
00491                         hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
00492                 }
00493 
00494                 ieee80211_adjust_monitor_flags(sdata, -1);
00495                 ieee80211_configure_filter(local);
00496                 break;
00497         default:
00498                 mutex_lock(&local->mtx);
00499                 if (local->hw_roc_dev == sdata->dev &&
00500                     local->hw_roc_channel) {
00501                         /* ignore return value since this is racy */
00502                         drv_cancel_remain_on_channel(local);
00503                         ieee80211_queue_work(&local->hw, &local->hw_roc_done);
00504                 }
00505                 mutex_unlock(&local->mtx);
00506 
00507                 flush_work(&local->hw_roc_start);
00508                 flush_work(&local->hw_roc_done);
00509 
00510                 flush_work(&sdata->work);
00511                 /*
00512                  * When we get here, the interface is marked down.
00513                  * Call synchronize_rcu() to wait for the RX path
00514                  * should it be using the interface and enqueuing
00515                  * frames at this very time on another CPU.
00516                  */
00517                 synchronize_rcu();
00518                 skb_queue_purge(&sdata->skb_queue);
00519 
00520                 /*
00521                  * Disable beaconing here for mesh only, AP and IBSS
00522                  * are already taken care of.
00523                  */
00524                 if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
00525                         ieee80211_bss_info_change_notify(sdata,
00526                                 BSS_CHANGED_BEACON_ENABLED);
00527 
00528                 /*
00529                  * Free all remaining keys, there shouldn't be any,
00530                  * except maybe group keys in AP more or WDS?
00531                  */
00532                 ieee80211_free_keys(sdata);
00533 
00534                 if (going_down)
00535                         drv_remove_interface(local, &sdata->vif);
00536         }
00537 
00538         sdata->bss = NULL;
00539 
00540         mutex_lock(&local->mtx);
00541         hw_reconf_flags |= __ieee80211_recalc_idle(local);
00542         mutex_unlock(&local->mtx);
00543 
00544         ieee80211_recalc_ps(local, -1);
00545 
00546         if (local->open_count == 0) {
00547                 if (local->ops->napi_poll)
00548                         napi_disable(&local->napi);
00549                 ieee80211_clear_tx_pending(local);
00550                 ieee80211_stop_device(local);
00551 
00552                 /* no reconfiguring after stop! */
00553                 hw_reconf_flags = 0;
00554         }
00555 
00556         /* Re-calculate channel-type, in case there are multiple vifs
00557          * on different channel types.
00558          */
00559         orig_ct = local->_oper_channel_type;
00560         ieee80211_set_channel_type(local, NULL, NL80211_CHAN_NO_HT);
00561 
00562         /* do after stop to avoid reconfiguring when we stop anyway */
00563         if (hw_reconf_flags || (orig_ct != local->_oper_channel_type))
00564                 ieee80211_hw_config(local, hw_reconf_flags);
00565 
00566         spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
00567         for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
00568                 skb_queue_walk_safe(&local->pending[i], skb, tmp) {
00569                         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
00570                         if (info->control.vif == &sdata->vif) {
00571                                 __skb_unlink(skb, &local->pending[i]);
00572                                 dev_kfree_skb_irq(skb);
00573                         }
00574                 }
00575         }
00576         spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
00577 }
00578 
00579 static int ieee80211_stop(struct net_device *dev)
00580 {
00581         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
00582 
00583         ieee80211_do_stop(sdata, true);
00584 
00585         return 0;
00586 }
00587 
00588 static void ieee80211_set_multicast_list(struct net_device *dev)
00589 {
00590         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
00591         struct ieee80211_local *local = sdata->local;
00592         int allmulti, promisc, sdata_allmulti, sdata_promisc;
00593 
00594         allmulti = !!(dev->flags & IFF_ALLMULTI);
00595         promisc = !!(dev->flags & IFF_PROMISC);
00596         sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
00597         sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC);
00598 
00599         if (allmulti != sdata_allmulti) {
00600                 if (dev->flags & IFF_ALLMULTI)
00601                         atomic_inc(&local->iff_allmultis);
00602                 else
00603                         atomic_dec(&local->iff_allmultis);
00604                 sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
00605         }
00606 
00607         if (promisc != sdata_promisc) {
00608                 if (dev->flags & IFF_PROMISC)
00609                         atomic_inc(&local->iff_promiscs);
00610                 else
00611                         atomic_dec(&local->iff_promiscs);
00612                 sdata->flags ^= IEEE80211_SDATA_PROMISC;
00613         }
00614         spin_lock_bh(&local->filter_lock);
00615         __hw_addr_sync(&local->mc_list, &dev->mc, dev->addr_len);
00616         spin_unlock_bh(&local->filter_lock);
00617         ieee80211_queue_work(&local->hw, &local->reconfig_filter);
00618 }
00619 
00620 /*
00621  * Called when the netdev is removed or, by the code below, before
00622  * the interface type changes.
00623  */
00624 static void ieee80211_teardown_sdata(struct net_device *dev)
00625 {
00626         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
00627         struct ieee80211_local *local = sdata->local;
00628         int flushed;
00629         int i;
00630 
00631         /* free extra data */
00632         ieee80211_free_keys(sdata);
00633 
00634         ieee80211_debugfs_remove_netdev(sdata);
00635 
00636         for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
00637                 __skb_queue_purge(&sdata->fragments[i].skb_list);
00638         sdata->fragment_next = 0;
00639 
00640         if (ieee80211_vif_is_mesh(&sdata->vif))
00641                 mesh_rmc_free(sdata);
00642 
00643         flushed = sta_info_flush(local, sdata);
00644         WARN_ON(flushed);
00645 }
00646 
00647 static u16 ieee80211_netdev_select_queue(struct net_device *dev,
00648                                          struct sk_buff *skb)
00649 {
00650         return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb);
00651 }
00652 
00653 static const struct net_device_ops ieee80211_dataif_ops = {
00654         .ndo_open               = ieee80211_open,
00655         .ndo_stop               = ieee80211_stop,
00656         .ndo_uninit             = ieee80211_teardown_sdata,
00657         .ndo_start_xmit         = ieee80211_subif_start_xmit,
00658         .ndo_set_rx_mode        = ieee80211_set_multicast_list,
00659         .ndo_change_mtu         = ieee80211_change_mtu,
00660         .ndo_set_mac_address    = ieee80211_change_mac,
00661         .ndo_select_queue       = ieee80211_netdev_select_queue,
00662 };
00663 
00664 static u16 ieee80211_monitor_select_queue(struct net_device *dev,
00665                                           struct sk_buff *skb)
00666 {
00667         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
00668         struct ieee80211_local *local = sdata->local;
00669         struct ieee80211_hdr *hdr;
00670         struct ieee80211_radiotap_header *rtap = (void *)skb->data;
00671         u8 *p;
00672 
00673         if (local->hw.queues < 4)
00674                 return 0;
00675 
00676         if (skb->len < 4 ||
00677             skb->len < le16_to_cpu(rtap->it_len) + 2 /* frame control */)
00678                 return 0; /* doesn't matter, frame will be dropped */
00679 
00680         hdr = (void *)((u8 *)skb->data + le16_to_cpu(rtap->it_len));
00681 
00682         if (!ieee80211_is_data(hdr->frame_control)) {
00683                 skb->priority = 7;
00684                 return ieee802_1d_to_ac[skb->priority];
00685         }
00686         if (!ieee80211_is_data_qos(hdr->frame_control)) {
00687                 skb->priority = 0;
00688                 return ieee802_1d_to_ac[skb->priority];
00689         }
00690 
00691         p = ieee80211_get_qos_ctl(hdr);
00692         skb->priority = *p & IEEE80211_QOS_CTL_TAG1D_MASK;
00693 
00694         return ieee80211_downgrade_queue(local, skb);
00695 }
00696 
00697 static const struct net_device_ops ieee80211_monitorif_ops = {
00698         .ndo_open               = ieee80211_open,
00699         .ndo_stop               = ieee80211_stop,
00700         .ndo_uninit             = ieee80211_teardown_sdata,
00701         .ndo_start_xmit         = ieee80211_monitor_start_xmit,
00702         .ndo_set_rx_mode        = ieee80211_set_multicast_list,
00703         .ndo_change_mtu         = ieee80211_change_mtu,
00704         .ndo_set_mac_address    = eth_mac_addr,
00705         .ndo_select_queue       = ieee80211_monitor_select_queue,
00706 };
00707 
00708 static void ieee80211_if_setup(struct net_device *dev)
00709 {
00710         ether_setup(dev);
00711         dev->priv_flags &= ~IFF_TX_SKB_SHARING;
00712         dev->netdev_ops = &ieee80211_dataif_ops;
00713         dev->destructor = free_netdev;
00714 }
00715 
00716 static void ieee80211_iface_work(struct work_struct *work)
00717 {
00718         struct ieee80211_sub_if_data *sdata =
00719                 container_of(work, struct ieee80211_sub_if_data, work);
00720         struct ieee80211_local *local = sdata->local;
00721         struct sk_buff *skb;
00722         struct sta_info *sta;
00723         struct ieee80211_ra_tid *ra_tid;
00724 
00725         if (!ieee80211_sdata_running(sdata))
00726                 return;
00727 
00728         if (local->scanning)
00729                 return;
00730 
00731         /*
00732          * ieee80211_queue_work() should have picked up most cases,
00733          * here we'll pick the rest.
00734          */
00735         if (WARN(local->suspended,
00736                  "interface work scheduled while going to suspend\n"))
00737                 return;
00738 
00739         /* first process frames */
00740         while ((skb = skb_dequeue(&sdata->skb_queue))) {
00741                 struct ieee80211_mgmt *mgmt = (void *)skb->data;
00742 
00743                 if (skb->pkt_type == IEEE80211_SDATA_QUEUE_AGG_START) {
00744                         ra_tid = (void *)&skb->cb;
00745                         ieee80211_start_tx_ba_cb(&sdata->vif, ra_tid->ra,
00746                                                  ra_tid->tid);
00747                 } else if (skb->pkt_type == IEEE80211_SDATA_QUEUE_AGG_STOP) {
00748                         ra_tid = (void *)&skb->cb;
00749                         ieee80211_stop_tx_ba_cb(&sdata->vif, ra_tid->ra,
00750                                                 ra_tid->tid);
00751                 } else if (ieee80211_is_action(mgmt->frame_control) &&
00752                            mgmt->u.action.category == WLAN_CATEGORY_BACK) {
00753                         int len = skb->len;
00754 
00755                         mutex_lock(&local->sta_mtx);
00756                         sta = sta_info_get_bss(sdata, mgmt->sa);
00757                         if (sta) {
00758                                 switch (mgmt->u.action.u.addba_req.action_code) {
00759                                 case WLAN_ACTION_ADDBA_REQ:
00760                                         ieee80211_process_addba_request(
00761                                                         local, sta, mgmt, len);
00762                                         break;
00763                                 case WLAN_ACTION_ADDBA_RESP:
00764                                         ieee80211_process_addba_resp(local, sta,
00765                                                                      mgmt, len);
00766                                         break;
00767                                 case WLAN_ACTION_DELBA:
00768                                         ieee80211_process_delba(sdata, sta,
00769                                                                 mgmt, len);
00770                                         break;
00771                                 default:
00772                                         WARN_ON(1);
00773                                         break;
00774                                 }
00775                         }
00776                         mutex_unlock(&local->sta_mtx);
00777                 } else if (ieee80211_is_data_qos(mgmt->frame_control)) {
00778                         struct ieee80211_hdr *hdr = (void *)mgmt;
00779                         /*
00780                          * So the frame isn't mgmt, but frame_control
00781                          * is at the right place anyway, of course, so
00782                          * the if statement is correct.
00783                          *
00784                          * Warn if we have other data frame types here,
00785                          * they must not get here.
00786                          */
00787                         WARN_ON(hdr->frame_control &
00788                                         cpu_to_le16(IEEE80211_STYPE_NULLFUNC));
00789                         WARN_ON(!(hdr->seq_ctrl &
00790                                         cpu_to_le16(IEEE80211_SCTL_FRAG)));
00791                         /*
00792                          * This was a fragment of a frame, received while
00793                          * a block-ack session was active. That cannot be
00794                          * right, so terminate the session.
00795                          */
00796                         mutex_lock(&local->sta_mtx);
00797                         sta = sta_info_get_bss(sdata, mgmt->sa);
00798                         if (sta) {
00799                                 u16 tid = *ieee80211_get_qos_ctl(hdr) &
00800                                                 IEEE80211_QOS_CTL_TID_MASK;
00801 
00802                                 __ieee80211_stop_rx_ba_session(
00803                                         sta, tid, WLAN_BACK_RECIPIENT,
00804                                         WLAN_REASON_QSTA_REQUIRE_SETUP,
00805                                         true);
00806                         }
00807                         mutex_unlock(&local->sta_mtx);
00808                 } else switch (sdata->vif.type) {
00809                 case NL80211_IFTYPE_STATION:
00810                         ieee80211_sta_rx_queued_mgmt(sdata, skb);
00811                         break;
00812                 case NL80211_IFTYPE_ADHOC:
00813                         ieee80211_ibss_rx_queued_mgmt(sdata, skb);
00814                         break;
00815                 case NL80211_IFTYPE_MESH_POINT:
00816                         if (!ieee80211_vif_is_mesh(&sdata->vif))
00817                                 break;
00818                         ieee80211_mesh_rx_queued_mgmt(sdata, skb);
00819                         break;
00820                 default:
00821                         WARN(1, "frame for unexpected interface type");
00822                         break;
00823                 }
00824 
00825                 kfree_skb(skb);
00826         }
00827 
00828         /* then other type-dependent work */
00829         switch (sdata->vif.type) {
00830         case NL80211_IFTYPE_STATION:
00831                 ieee80211_sta_work(sdata);
00832                 break;
00833         case NL80211_IFTYPE_ADHOC:
00834                 ieee80211_ibss_work(sdata);
00835                 break;
00836         case NL80211_IFTYPE_MESH_POINT:
00837                 if (!ieee80211_vif_is_mesh(&sdata->vif))
00838                         break;
00839                 ieee80211_mesh_work(sdata);
00840                 break;
00841         default:
00842                 break;
00843         }
00844 }
00845 
00846 
00847 /*
00848  * Helper function to initialise an interface to a specific type.
00849  */
00850 static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
00851                                   enum nl80211_iftype type)
00852 {
00853         /* clear type-dependent union */
00854         memset(&sdata->u, 0, sizeof(sdata->u));
00855 
00856         /* and set some type-dependent values */
00857         sdata->vif.type = type;
00858         sdata->vif.p2p = false;
00859         sdata->dev->netdev_ops = &ieee80211_dataif_ops;
00860         sdata->wdev.iftype = type;
00861 
00862         sdata->control_port_protocol = cpu_to_be16(ETH_P_PAE);
00863         sdata->control_port_no_encrypt = false;
00864 
00865         /* only monitor differs */
00866         sdata->dev->type = ARPHRD_ETHER;
00867 
00868         skb_queue_head_init(&sdata->skb_queue);
00869         INIT_WORK(&sdata->work, ieee80211_iface_work);
00870 
00871         switch (type) {
00872         case NL80211_IFTYPE_P2P_GO:
00873                 type = NL80211_IFTYPE_AP;
00874                 sdata->vif.type = type;
00875                 sdata->vif.p2p = true;
00876                 /* fall through */
00877         case NL80211_IFTYPE_AP:
00878                 skb_queue_head_init(&sdata->u.ap.ps_bc_buf);
00879                 INIT_LIST_HEAD(&sdata->u.ap.vlans);
00880                 break;
00881         case NL80211_IFTYPE_P2P_CLIENT:
00882                 type = NL80211_IFTYPE_STATION;
00883                 sdata->vif.type = type;
00884                 sdata->vif.p2p = true;
00885                 /* fall through */
00886         case NL80211_IFTYPE_STATION:
00887                 ieee80211_sta_setup_sdata(sdata);
00888                 break;
00889         case NL80211_IFTYPE_ADHOC:
00890                 ieee80211_ibss_setup_sdata(sdata);
00891                 break;
00892         case NL80211_IFTYPE_MESH_POINT:
00893                 if (ieee80211_vif_is_mesh(&sdata->vif))
00894                         ieee80211_mesh_init_sdata(sdata);
00895                 break;
00896         case NL80211_IFTYPE_MONITOR:
00897                 sdata->dev->type = ARPHRD_IEEE80211_RADIOTAP;
00898                 sdata->dev->netdev_ops = &ieee80211_monitorif_ops;
00899                 sdata->u.mntr_flags = MONITOR_FLAG_CONTROL |
00900                                       MONITOR_FLAG_OTHER_BSS;
00901                 break;
00902         case NL80211_IFTYPE_WDS:
00903         case NL80211_IFTYPE_AP_VLAN:
00904                 break;
00905         case NL80211_IFTYPE_UNSPECIFIED:
00906         case NUM_NL80211_IFTYPES:
00907                 BUG();
00908                 break;
00909         }
00910 
00911         ieee80211_debugfs_add_netdev(sdata);
00912 }
00913 
00914 static int ieee80211_runtime_change_iftype(struct ieee80211_sub_if_data *sdata,
00915                                            enum nl80211_iftype type)
00916 {
00917         struct ieee80211_local *local = sdata->local;
00918         int ret, err;
00919         enum nl80211_iftype internal_type = type;
00920         bool p2p = false;
00921 
00922         ASSERT_RTNL();
00923 
00924         if (!local->ops->change_interface)
00925                 return -EBUSY;
00926 
00927         switch (sdata->vif.type) {
00928         case NL80211_IFTYPE_AP:
00929         case NL80211_IFTYPE_STATION:
00930         case NL80211_IFTYPE_ADHOC:
00931                 /*
00932                  * Could maybe also all others here?
00933                  * Just not sure how that interacts
00934                  * with the RX/config path e.g. for
00935                  * mesh.
00936                  */
00937                 break;
00938         default:
00939                 return -EBUSY;
00940         }
00941 
00942         switch (type) {
00943         case NL80211_IFTYPE_AP:
00944         case NL80211_IFTYPE_STATION:
00945         case NL80211_IFTYPE_ADHOC:
00946                 /*
00947                  * Could probably support everything
00948                  * but WDS here (WDS do_open can fail
00949                  * under memory pressure, which this
00950                  * code isn't prepared to handle).
00951                  */
00952                 break;
00953         case NL80211_IFTYPE_P2P_CLIENT:
00954                 p2p = true;
00955                 internal_type = NL80211_IFTYPE_STATION;
00956                 break;
00957         case NL80211_IFTYPE_P2P_GO:
00958                 p2p = true;
00959                 internal_type = NL80211_IFTYPE_AP;
00960                 break;
00961         default:
00962                 return -EBUSY;
00963         }
00964 
00965         ret = ieee80211_check_concurrent_iface(sdata, internal_type);
00966         if (ret)
00967                 return ret;
00968 
00969         ieee80211_do_stop(sdata, false);
00970 
00971         ieee80211_teardown_sdata(sdata->dev);
00972 
00973         ret = drv_change_interface(local, sdata, internal_type, p2p);
00974         if (ret)
00975                 type = sdata->vif.type;
00976 
00977         ieee80211_setup_sdata(sdata, type);
00978 
00979         err = ieee80211_do_open(sdata->dev, false);
00980         WARN(err, "type change: do_open returned %d", err);
00981 
00982         return ret;
00983 }
00984 
00985 int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
00986                              enum nl80211_iftype type)
00987 {
00988         int ret;
00989 
00990         ASSERT_RTNL();
00991 
00992         if (type == ieee80211_vif_type_p2p(&sdata->vif))
00993                 return 0;
00994 
00995         /* Setting ad-hoc mode on non-IBSS channel is not supported. */
00996         if (sdata->local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS &&
00997             type == NL80211_IFTYPE_ADHOC)
00998                 return -EOPNOTSUPP;
00999 
01000         if (ieee80211_sdata_running(sdata)) {
01001                 ret = ieee80211_runtime_change_iftype(sdata, type);
01002                 if (ret)
01003                         return ret;
01004         } else {
01005                 /* Purge and reset type-dependent state. */
01006                 ieee80211_teardown_sdata(sdata->dev);
01007                 ieee80211_setup_sdata(sdata, type);
01008         }
01009 
01010         /* reset some values that shouldn't be kept across type changes */
01011         sdata->vif.bss_conf.basic_rates =
01012                 ieee80211_mandatory_rates(sdata->local,
01013                         sdata->local->hw.conf.channel->band);
01014         sdata->drop_unencrypted = 0;
01015         if (type == NL80211_IFTYPE_STATION)
01016                 sdata->u.mgd.use_4addr = false;
01017 
01018         return 0;
01019 }
01020 
01021 static void ieee80211_assign_perm_addr(struct ieee80211_local *local,
01022                                        struct net_device *dev,
01023                                        enum nl80211_iftype type)
01024 {
01025         struct ieee80211_sub_if_data *sdata;
01026         u64 mask, start, addr, val, inc;
01027         u8 *m;
01028         u8 tmp_addr[ETH_ALEN];
01029         int i;
01030 
01031         /* default ... something at least */
01032         memcpy(dev->perm_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
01033 
01034         if (is_zero_ether_addr(local->hw.wiphy->addr_mask) &&
01035             local->hw.wiphy->n_addresses <= 1)
01036                 return;
01037 
01038 
01039         mutex_lock(&local->iflist_mtx);
01040 
01041         switch (type) {
01042         case NL80211_IFTYPE_MONITOR:
01043                 /* doesn't matter */
01044                 break;
01045         case NL80211_IFTYPE_WDS:
01046         case NL80211_IFTYPE_AP_VLAN:
01047                 /* match up with an AP interface */
01048                 list_for_each_entry(sdata, &local->interfaces, list) {
01049                         if (sdata->vif.type != NL80211_IFTYPE_AP)
01050                                 continue;
01051                         memcpy(dev->perm_addr, sdata->vif.addr, ETH_ALEN);
01052                         break;
01053                 }
01054                 /* keep default if no AP interface present */
01055                 break;
01056         default:
01057                 /* assign a new address if possible -- try n_addresses first */
01058                 for (i = 0; i < local->hw.wiphy->n_addresses; i++) {
01059                         bool used = false;
01060 
01061                         list_for_each_entry(sdata, &local->interfaces, list) {
01062                                 if (memcmp(local->hw.wiphy->addresses[i].addr,
01063                                            sdata->vif.addr, ETH_ALEN) == 0) {
01064                                         used = true;
01065                                         break;
01066                                 }
01067                         }
01068 
01069                         if (!used) {
01070                                 memcpy(dev->perm_addr,
01071                                        local->hw.wiphy->addresses[i].addr,
01072                                        ETH_ALEN);
01073                                 break;
01074                         }
01075                 }
01076 
01077                 /* try mask if available */
01078                 if (is_zero_ether_addr(local->hw.wiphy->addr_mask))
01079                         break;
01080 
01081                 m = local->hw.wiphy->addr_mask;
01082                 mask =  ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
01083                         ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
01084                         ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
01085 
01086                 if (__ffs64(mask) + hweight64(mask) != fls64(mask)) {
01087                         /* not a contiguous mask ... not handled now! */
01088                         printk(KERN_DEBUG "not contiguous\n");
01089                         break;
01090                 }
01091 
01092                 m = local->hw.wiphy->perm_addr;
01093                 start = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
01094                         ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
01095                         ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
01096 
01097                 inc = 1ULL<<__ffs64(mask);
01098                 val = (start & mask);
01099                 addr = (start & ~mask) | (val & mask);
01100                 do {
01101                         bool used = false;
01102 
01103                         tmp_addr[5] = addr >> 0*8;
01104                         tmp_addr[4] = addr >> 1*8;
01105                         tmp_addr[3] = addr >> 2*8;
01106                         tmp_addr[2] = addr >> 3*8;
01107                         tmp_addr[1] = addr >> 4*8;
01108                         tmp_addr[0] = addr >> 5*8;
01109 
01110                         val += inc;
01111 
01112                         list_for_each_entry(sdata, &local->interfaces, list) {
01113                                 if (memcmp(tmp_addr, sdata->vif.addr,
01114                                                         ETH_ALEN) == 0) {
01115                                         used = true;
01116                                         break;
01117                                 }
01118                         }
01119 
01120                         if (!used) {
01121                                 memcpy(dev->perm_addr, tmp_addr, ETH_ALEN);
01122                                 break;
01123                         }
01124                         addr = (start & ~mask) | (val & mask);
01125                 } while (addr != start);
01126 
01127                 break;
01128         }
01129 
01130         mutex_unlock(&local->iflist_mtx);
01131 }
01132 
01133 int ieee80211_if_add(struct ieee80211_local *local, const char *name,
01134                      struct net_device **new_dev, enum nl80211_iftype type,
01135                      struct vif_params *params)
01136 {
01137         struct net_device *ndev;
01138         struct ieee80211_sub_if_data *sdata = NULL;
01139         int ret, i;
01140 
01141         ASSERT_RTNL();
01142 
01143         ndev = alloc_netdev_mqs(sizeof(*sdata) + local->hw.vif_data_size,
01144                                 name, ieee80211_if_setup, local->hw.queues, 1);
01145         if (!ndev)
01146                 return -ENOMEM;
01147         dev_net_set(ndev, wiphy_net(local->hw.wiphy));
01148 
01149         ndev->needed_headroom = local->tx_headroom +
01150                                 4*6 /* four MAC addresses */
01151                                 + 2 + 2 + 2 + 2 /* ctl, dur, seq, qos */
01152                                 + 6 /* mesh */
01153                                 + 8 /* rfc1042/bridge tunnel */
01154                                 - ETH_HLEN /* ethernet hard_header_len */
01155                                 + IEEE80211_ENCRYPT_HEADROOM;
01156         ndev->needed_tailroom = IEEE80211_ENCRYPT_TAILROOM;
01157 
01158         ret = dev_alloc_name(ndev, ndev->name);
01159         if (ret < 0)
01160                 goto fail;
01161 
01162         ieee80211_assign_perm_addr(local, ndev, type);
01163         memcpy(ndev->dev_addr, ndev->perm_addr, ETH_ALEN);
01164         SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));
01165 
01166         /* don't use IEEE80211_DEV_TO_SUB_IF because it checks too much */
01167         sdata = netdev_priv(ndev);
01168         ndev->ieee80211_ptr = &sdata->wdev;
01169         memcpy(sdata->vif.addr, ndev->dev_addr, ETH_ALEN);
01170         memcpy(sdata->name, ndev->name, IFNAMSIZ);
01171 
01172         /* initialise type-independent data */
01173         sdata->wdev.wiphy = local->hw.wiphy;
01174         sdata->local = local;
01175         sdata->dev = ndev;
01176 #ifdef CONFIG_INET
01177         sdata->arp_filter_state = true;
01178 #endif
01179 
01180         for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
01181                 skb_queue_head_init(&sdata->fragments[i].skb_list);
01182 
01183         INIT_LIST_HEAD(&sdata->key_list);
01184 
01185         for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
01186                 struct ieee80211_supported_band *sband;
01187                 sband = local->hw.wiphy->bands[i];
01188                 sdata->rc_rateidx_mask[i] =
01189                         sband ? (1 << sband->n_bitrates) - 1 : 0;
01190         }
01191 
01192         /* setup type-dependent data */
01193         ieee80211_setup_sdata(sdata, type);
01194 
01195         if (params) {
01196                 ndev->ieee80211_ptr->use_4addr = params->use_4addr;
01197                 if (type == NL80211_IFTYPE_STATION)
01198                         sdata->u.mgd.use_4addr = params->use_4addr;
01199         }
01200 
01201         ret = register_netdevice(ndev);
01202         if (ret)
01203                 goto fail;
01204 
01205         mutex_lock(&local->iflist_mtx);
01206         list_add_tail_rcu(&sdata->list, &local->interfaces);
01207         mutex_unlock(&local->iflist_mtx);
01208 
01209         if (new_dev)
01210                 *new_dev = ndev;
01211 
01212         return 0;
01213 
01214  fail:
01215         free_netdev(ndev);
01216         return ret;
01217 }
01218 
01219 void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata)
01220 {
01221         ASSERT_RTNL();
01222 
01223         mutex_lock(&sdata->local->iflist_mtx);
01224         list_del_rcu(&sdata->list);
01225         mutex_unlock(&sdata->local->iflist_mtx);
01226 
01227         if (ieee80211_vif_is_mesh(&sdata->vif))
01228                 mesh_path_flush_by_iface(sdata);
01229 
01230         synchronize_rcu();
01231         unregister_netdevice(sdata->dev);
01232 }
01233 
01234 /*
01235  * Remove all interfaces, may only be called at hardware unregistration
01236  * time because it doesn't do RCU-safe list removals.
01237  */
01238 void ieee80211_remove_interfaces(struct ieee80211_local *local)
01239 {
01240         struct ieee80211_sub_if_data *sdata, *tmp;
01241         LIST_HEAD(unreg_list);
01242 
01243         ASSERT_RTNL();
01244 
01245         mutex_lock(&local->iflist_mtx);
01246         list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
01247                 list_del(&sdata->list);
01248 
01249                 if (ieee80211_vif_is_mesh(&sdata->vif))
01250                         mesh_path_flush_by_iface(sdata);
01251 
01252                 unregister_netdevice_queue(sdata->dev, &unreg_list);
01253         }
01254         mutex_unlock(&local->iflist_mtx);
01255         unregister_netdevice_many(&unreg_list);
01256         list_del(&unreg_list);
01257 }
01258 
01259 static u32 ieee80211_idle_off(struct ieee80211_local *local,
01260                               const char *reason)
01261 {
01262         if (!(local->hw.conf.flags & IEEE80211_CONF_IDLE))
01263                 return 0;
01264 
01265 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
01266         wiphy_debug(local->hw.wiphy, "device no longer idle - %s\n", reason);
01267 #endif
01268 
01269         local->hw.conf.flags &= ~IEEE80211_CONF_IDLE;
01270         return IEEE80211_CONF_CHANGE_IDLE;
01271 }
01272 
01273 static u32 ieee80211_idle_on(struct ieee80211_local *local)
01274 {
01275         if (local->hw.conf.flags & IEEE80211_CONF_IDLE)
01276                 return 0;
01277 
01278 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
01279         wiphy_debug(local->hw.wiphy, "device now idle\n");
01280 #endif
01281 
01282         drv_flush(local, false);
01283 
01284         local->hw.conf.flags |= IEEE80211_CONF_IDLE;
01285         return IEEE80211_CONF_CHANGE_IDLE;
01286 }
01287 
01288 u32 __ieee80211_recalc_idle(struct ieee80211_local *local)
01289 {
01290         struct ieee80211_sub_if_data *sdata;
01291         int count = 0;
01292         bool working = false, scanning = false, hw_roc = false;
01293         struct ieee80211_work *wk;
01294         unsigned int led_trig_start = 0, led_trig_stop = 0;
01295 
01296 #ifdef CONFIG_PROVE_LOCKING
01297         WARN_ON(debug_locks && !lockdep_rtnl_is_held() &&
01298                 !lockdep_is_held(&local->iflist_mtx));
01299 #endif
01300         lockdep_assert_held(&local->mtx);
01301 
01302         list_for_each_entry(sdata, &local->interfaces, list) {
01303                 if (!ieee80211_sdata_running(sdata)) {
01304                         sdata->vif.bss_conf.idle = true;
01305                         continue;
01306                 }
01307 
01308                 sdata->old_idle = sdata->vif.bss_conf.idle;
01309 
01310                 /* do not count disabled managed interfaces */
01311                 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
01312                     !sdata->u.mgd.associated) {
01313                         sdata->vif.bss_conf.idle = true;
01314                         continue;
01315                 }
01316                 /* do not count unused IBSS interfaces */
01317                 if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
01318                     !sdata->u.ibss.ssid_len) {
01319                         sdata->vif.bss_conf.idle = true;
01320                         continue;
01321                 }
01322                 /* count everything else */
01323                 count++;
01324         }
01325 
01326         list_for_each_entry(wk, &local->work_list, list) {
01327                 working = true;
01328                 wk->sdata->vif.bss_conf.idle = false;
01329         }
01330 
01331         if (local->scan_sdata) {
01332                 scanning = true;
01333                 local->scan_sdata->vif.bss_conf.idle = false;
01334         }
01335 
01336         if (local->hw_roc_channel)
01337                 hw_roc = true;
01338 
01339         list_for_each_entry(sdata, &local->interfaces, list) {
01340                 if (sdata->old_idle == sdata->vif.bss_conf.idle)
01341                         continue;
01342                 if (!ieee80211_sdata_running(sdata))
01343                         continue;
01344                 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IDLE);
01345         }
01346 
01347         if (working || scanning || hw_roc)
01348                 led_trig_start |= IEEE80211_TPT_LEDTRIG_FL_WORK;
01349         else
01350                 led_trig_stop |= IEEE80211_TPT_LEDTRIG_FL_WORK;
01351 
01352         if (count)
01353                 led_trig_start |= IEEE80211_TPT_LEDTRIG_FL_CONNECTED;
01354         else
01355                 led_trig_stop |= IEEE80211_TPT_LEDTRIG_FL_CONNECTED;
01356 
01357         ieee80211_mod_tpt_led_trig(local, led_trig_start, led_trig_stop);
01358 
01359         if (hw_roc)
01360                 return ieee80211_idle_off(local, "hw remain-on-channel");
01361         if (working)
01362                 return ieee80211_idle_off(local, "working");
01363         if (scanning)
01364                 return ieee80211_idle_off(local, "scanning");
01365         if (!count)
01366                 return ieee80211_idle_on(local);
01367         else
01368                 return ieee80211_idle_off(local, "in use");
01369 
01370         return 0;
01371 }
01372 
01373 void ieee80211_recalc_idle(struct ieee80211_local *local)
01374 {
01375         u32 chg;
01376 
01377         mutex_lock(&local->iflist_mtx);
01378         chg = __ieee80211_recalc_idle(local);
01379         mutex_unlock(&local->iflist_mtx);
01380         if (chg)
01381                 ieee80211_hw_config(local, chg);
01382 }
01383 
01384 static int netdev_notify(struct notifier_block *nb,
01385                          unsigned long state,
01386                          void *ndev)
01387 {
01388         struct net_device *dev = ndev;
01389         struct ieee80211_sub_if_data *sdata;
01390 
01391         if (state != NETDEV_CHANGENAME)
01392                 return 0;
01393 
01394         if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
01395                 return 0;
01396 
01397         if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
01398                 return 0;
01399 
01400         sdata = IEEE80211_DEV_TO_SUB_IF(dev);
01401 
01402         memcpy(sdata->name, dev->name, IFNAMSIZ);
01403 
01404         ieee80211_debugfs_rename_netdev(sdata);
01405         return 0;
01406 }
01407 
01408 static struct notifier_block mac80211_netdev_notifier = {
01409         .notifier_call = netdev_notify,
01410 };
01411 
01412 int ieee80211_iface_init(void)
01413 {
01414         return register_netdevice_notifier(&mac80211_netdev_notifier);
01415 }
01416 
01417 void ieee80211_iface_exit(void)
01418 {
01419         unregister_netdevice_notifier(&mac80211_netdev_notifier);
01420 }


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Mon Oct 6 2014 08:27:10