main.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2002-2005, Instant802 Networks, Inc.
00003  * Copyright 2005-2006, Devicescape Software, Inc.
00004  * Copyright 2006-2007  Jiri Benc <jbenc@suse.cz>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License version 2 as
00008  * published by the Free Software Foundation.
00009  */
00010 
00011 #include <net/mac80211.h>
00012 #include <linux/module.h>
00013 #include <linux/init.h>
00014 #include <linux/netdevice.h>
00015 #include <linux/types.h>
00016 #include <linux/slab.h>
00017 #include <linux/skbuff.h>
00018 #include <linux/etherdevice.h>
00019 #include <linux/if_arp.h>
00020 #include <linux/rtnetlink.h>
00021 #include <linux/bitmap.h>
00022 #include <linux/pm_qos.h>
00023 #include <linux/inetdevice.h>
00024 #include <net/net_namespace.h>
00025 #include <net/cfg80211.h>
00026 
00027 #include "ieee80211_i.h"
00028 #include "driver-ops.h"
00029 #include "rate.h"
00030 #include "mesh.h"
00031 #include "wep.h"
00032 #include "led.h"
00033 #include "cfg.h"
00034 #include "debugfs.h"
00035 
00036 static struct lock_class_key ieee80211_rx_skb_queue_class;
00037 
00038 void ieee80211_configure_filter(struct ieee80211_local *local)
00039 {
00040         u64 mc;
00041         unsigned int changed_flags;
00042         unsigned int new_flags = 0;
00043 
00044         if (atomic_read(&local->iff_promiscs))
00045                 new_flags |= FIF_PROMISC_IN_BSS;
00046 
00047         if (atomic_read(&local->iff_allmultis))
00048                 new_flags |= FIF_ALLMULTI;
00049 
00050         if (local->monitors || test_bit(SCAN_SW_SCANNING, &local->scanning) ||
00051             test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning))
00052                 new_flags |= FIF_BCN_PRBRESP_PROMISC;
00053 
00054         if (local->fif_probe_req || local->probe_req_reg)
00055                 new_flags |= FIF_PROBE_REQ;
00056 
00057         if (local->fif_fcsfail)
00058                 new_flags |= FIF_FCSFAIL;
00059 
00060         if (local->fif_plcpfail)
00061                 new_flags |= FIF_PLCPFAIL;
00062 
00063         if (local->fif_control)
00064                 new_flags |= FIF_CONTROL;
00065 
00066         if (local->fif_other_bss)
00067                 new_flags |= FIF_OTHER_BSS;
00068 
00069         if (local->fif_pspoll)
00070                 new_flags |= FIF_PSPOLL;
00071 
00072         spin_lock_bh(&local->filter_lock);
00073         changed_flags = local->filter_flags ^ new_flags;
00074 
00075         mc = drv_prepare_multicast(local, &local->mc_list);
00076         spin_unlock_bh(&local->filter_lock);
00077 
00078         /* be a bit nasty */
00079         new_flags |= (1<<31);
00080 
00081         drv_configure_filter(local, changed_flags, &new_flags, mc);
00082 
00083         WARN_ON(new_flags & (1<<31));
00084 
00085         local->filter_flags = new_flags & ~(1<<31);
00086 }
00087 
00088 static void ieee80211_reconfig_filter(struct work_struct *work)
00089 {
00090         struct ieee80211_local *local =
00091                 container_of(work, struct ieee80211_local, reconfig_filter);
00092 
00093         ieee80211_configure_filter(local);
00094 }
00095 
00096 int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
00097 {
00098         struct ieee80211_channel *chan;
00099         int ret = 0;
00100         int power;
00101         enum nl80211_channel_type channel_type;
00102         u32 offchannel_flag;
00103 
00104         might_sleep();
00105 
00106         offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
00107         if (local->scan_channel) {
00108                 chan = local->scan_channel;
00109                 /* If scanning on oper channel, use whatever channel-type
00110                  * is currently in use.
00111                  */
00112                 if (chan == local->oper_channel)
00113                         channel_type = local->_oper_channel_type;
00114                 else
00115                         channel_type = NL80211_CHAN_NO_HT;
00116         } else if (local->tmp_channel) {
00117                 chan = local->tmp_channel;
00118                 channel_type = local->tmp_channel_type;
00119         } else {
00120                 chan = local->oper_channel;
00121                 channel_type = local->_oper_channel_type;
00122         }
00123 
00124         if (chan != local->oper_channel ||
00125             channel_type != local->_oper_channel_type)
00126                 local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
00127         else
00128                 local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL;
00129 
00130         offchannel_flag ^= local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
00131 
00132         if (offchannel_flag || chan != local->hw.conf.channel ||
00133             channel_type != local->hw.conf.channel_type) {
00134                 local->hw.conf.channel = chan;
00135                 local->hw.conf.channel_type = channel_type;
00136                 changed |= IEEE80211_CONF_CHANGE_CHANNEL;
00137         }
00138 
00139         if (!conf_is_ht(&local->hw.conf)) {
00140                 /*
00141                  * mac80211.h documents that this is only valid
00142                  * when the channel is set to an HT type, and
00143                  * that otherwise STATIC is used.
00144                  */
00145                 local->hw.conf.smps_mode = IEEE80211_SMPS_STATIC;
00146         } else if (local->hw.conf.smps_mode != local->smps_mode) {
00147                 local->hw.conf.smps_mode = local->smps_mode;
00148                 changed |= IEEE80211_CONF_CHANGE_SMPS;
00149         }
00150 
00151         if (test_bit(SCAN_SW_SCANNING, &local->scanning) ||
00152             test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning) ||
00153             test_bit(SCAN_HW_SCANNING, &local->scanning))
00154                 power = chan->max_power;
00155         else
00156                 power = local->power_constr_level ?
00157                         min(chan->max_power,
00158                                 (chan->max_reg_power  - local->power_constr_level)) :
00159                         chan->max_power;
00160 
00161         if (local->user_power_level >= 0)
00162                 power = min(power, local->user_power_level);
00163 
00164         if (local->hw.conf.power_level != power) {
00165                 changed |= IEEE80211_CONF_CHANGE_POWER;
00166                 local->hw.conf.power_level = power;
00167         }
00168 
00169         if (changed && local->open_count) {
00170                 ret = drv_config(local, changed);
00171                 /*
00172                  * Goal:
00173                  * HW reconfiguration should never fail, the driver has told
00174                  * us what it can support so it should live up to that promise.
00175                  *
00176                  * Current status:
00177                  * rfkill is not integrated with mac80211 and a
00178                  * configuration command can thus fail if hardware rfkill
00179                  * is enabled
00180                  *
00181                  * FIXME: integrate rfkill with mac80211 and then add this
00182                  * WARN_ON() back
00183                  *
00184                  */
00185                 /* WARN_ON(ret); */
00186         }
00187 
00188         return ret;
00189 }
00190 
00191 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
00192                                       u32 changed)
00193 {
00194         struct ieee80211_local *local = sdata->local;
00195         static const u8 zero[ETH_ALEN] = { 0 };
00196 
00197         if (!changed)
00198                 return;
00199 
00200         if (sdata->vif.type == NL80211_IFTYPE_STATION) {
00201                 sdata->vif.bss_conf.bssid = sdata->u.mgd.bssid;
00202         } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
00203                 sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid;
00204         else if (sdata->vif.type == NL80211_IFTYPE_AP)
00205                 sdata->vif.bss_conf.bssid = sdata->vif.addr;
00206         else if (sdata->vif.type == NL80211_IFTYPE_WDS)
00207                 sdata->vif.bss_conf.bssid = NULL;
00208         else if (ieee80211_vif_is_mesh(&sdata->vif)) {
00209                 sdata->vif.bss_conf.bssid = zero;
00210         } else {
00211                 WARN_ON(1);
00212                 return;
00213         }
00214 
00215         switch (sdata->vif.type) {
00216         case NL80211_IFTYPE_AP:
00217         case NL80211_IFTYPE_ADHOC:
00218         case NL80211_IFTYPE_WDS:
00219         case NL80211_IFTYPE_MESH_POINT:
00220                 break;
00221         default:
00222                 /* do not warn to simplify caller in scan.c */
00223                 changed &= ~BSS_CHANGED_BEACON_ENABLED;
00224                 if (WARN_ON(changed & BSS_CHANGED_BEACON))
00225                         return;
00226                 break;
00227         }
00228 
00229         if (changed & BSS_CHANGED_BEACON_ENABLED) {
00230                 if (local->quiescing || !ieee80211_sdata_running(sdata) ||
00231                     test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)) {
00232                         sdata->vif.bss_conf.enable_beacon = false;
00233                 } else {
00234                         /*
00235                          * Beacon should be enabled, but AP mode must
00236                          * check whether there is a beacon configured.
00237                          */
00238                         switch (sdata->vif.type) {
00239                         case NL80211_IFTYPE_AP:
00240                                 sdata->vif.bss_conf.enable_beacon =
00241                                         !!sdata->u.ap.beacon;
00242                                 break;
00243                         case NL80211_IFTYPE_ADHOC:
00244                                 sdata->vif.bss_conf.enable_beacon =
00245                                         !!sdata->u.ibss.presp;
00246                                 break;
00247 #ifdef CONFIG_MAC80211_MESH
00248                         case NL80211_IFTYPE_MESH_POINT:
00249                                 sdata->vif.bss_conf.enable_beacon =
00250                                         !!sdata->u.mesh.mesh_id_len;
00251                                 break;
00252 #endif
00253                         default:
00254                                 /* not reached */
00255                                 WARN_ON(1);
00256                                 break;
00257                         }
00258                 }
00259         }
00260 
00261         drv_bss_info_changed(local, sdata, &sdata->vif.bss_conf, changed);
00262 }
00263 
00264 u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
00265 {
00266         sdata->vif.bss_conf.use_cts_prot = false;
00267         sdata->vif.bss_conf.use_short_preamble = false;
00268         sdata->vif.bss_conf.use_short_slot = false;
00269         return BSS_CHANGED_ERP_CTS_PROT |
00270                BSS_CHANGED_ERP_PREAMBLE |
00271                BSS_CHANGED_ERP_SLOT;
00272 }
00273 
00274 static void ieee80211_tasklet_handler(unsigned long data)
00275 {
00276         struct ieee80211_local *local = (struct ieee80211_local *) data;
00277         struct sta_info *sta, *tmp;
00278         struct skb_eosp_msg_data *eosp_data;
00279         struct sk_buff *skb;
00280 
00281         while ((skb = skb_dequeue(&local->skb_queue)) ||
00282                (skb = skb_dequeue(&local->skb_queue_unreliable))) {
00283                 switch (skb->pkt_type) {
00284                 case IEEE80211_RX_MSG:
00285                         /* Clear skb->pkt_type in order to not confuse kernel
00286                          * netstack. */
00287                         skb->pkt_type = 0;
00288                         ieee80211_rx(&local->hw, skb);
00289                         break;
00290                 case IEEE80211_TX_STATUS_MSG:
00291                         skb->pkt_type = 0;
00292                         ieee80211_tx_status(&local->hw, skb);
00293                         break;
00294                 case IEEE80211_EOSP_MSG:
00295                         eosp_data = (void *)skb->cb;
00296                         for_each_sta_info(local, eosp_data->sta, sta, tmp) {
00297                                 /* skip wrong virtual interface */
00298                                 if (memcmp(eosp_data->iface,
00299                                            sta->sdata->vif.addr, ETH_ALEN))
00300                                         continue;
00301                                 clear_sta_flag(sta, WLAN_STA_SP);
00302                                 break;
00303                         }
00304                         dev_kfree_skb(skb);
00305                         break;
00306                 default:
00307                         WARN(1, "mac80211: Packet is of unknown type %d\n",
00308                              skb->pkt_type);
00309                         dev_kfree_skb(skb);
00310                         break;
00311                 }
00312         }
00313 }
00314 
00315 static void ieee80211_restart_work(struct work_struct *work)
00316 {
00317         struct ieee80211_local *local =
00318                 container_of(work, struct ieee80211_local, restart_work);
00319 
00320         /* wait for scan work complete */
00321         flush_workqueue(local->workqueue);
00322 
00323         mutex_lock(&local->mtx);
00324         WARN(test_bit(SCAN_HW_SCANNING, &local->scanning) ||
00325              local->sched_scanning,
00326                 "%s called with hardware scan in progress\n", __func__);
00327         mutex_unlock(&local->mtx);
00328 
00329         rtnl_lock();
00330         ieee80211_scan_cancel(local);
00331         ieee80211_reconfig(local);
00332         rtnl_unlock();
00333 }
00334 
00335 void ieee80211_restart_hw(struct ieee80211_hw *hw)
00336 {
00337         struct ieee80211_local *local = hw_to_local(hw);
00338 
00339         trace_api_restart_hw(local);
00340 
00341         wiphy_info(hw->wiphy,
00342                    "Hardware restart was requested\n");
00343 
00344         /* use this reason, ieee80211_reconfig will unblock it */
00345         ieee80211_stop_queues_by_reason(hw,
00346                 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
00347 
00348         schedule_work(&local->restart_work);
00349 }
00350 EXPORT_SYMBOL(ieee80211_restart_hw);
00351 
00352 static void ieee80211_recalc_smps_work(struct work_struct *work)
00353 {
00354         struct ieee80211_local *local =
00355                 container_of(work, struct ieee80211_local, recalc_smps);
00356 
00357         mutex_lock(&local->iflist_mtx);
00358         ieee80211_recalc_smps(local);
00359         mutex_unlock(&local->iflist_mtx);
00360 }
00361 
00362 #ifdef CONFIG_INET
00363 static int ieee80211_ifa_changed(struct notifier_block *nb,
00364                                  unsigned long data, void *arg)
00365 {
00366         struct in_ifaddr *ifa = arg;
00367         struct ieee80211_local *local =
00368                 container_of(nb, struct ieee80211_local,
00369                              ifa_notifier);
00370         struct net_device *ndev = ifa->ifa_dev->dev;
00371         struct wireless_dev *wdev = ndev->ieee80211_ptr;
00372         struct in_device *idev;
00373         struct ieee80211_sub_if_data *sdata;
00374         struct ieee80211_bss_conf *bss_conf;
00375         struct ieee80211_if_managed *ifmgd;
00376         int c = 0;
00377 
00378         /* Make sure it's our interface that got changed */
00379         if (!wdev)
00380                 return NOTIFY_DONE;
00381 
00382         if (wdev->wiphy != local->hw.wiphy)
00383                 return NOTIFY_DONE;
00384 
00385         sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
00386         bss_conf = &sdata->vif.bss_conf;
00387 
00388         /* ARP filtering is only supported in managed mode */
00389         if (sdata->vif.type != NL80211_IFTYPE_STATION)
00390                 return NOTIFY_DONE;
00391 
00392         idev = __in_dev_get_rtnl(sdata->dev);
00393         if (!idev)
00394                 return NOTIFY_DONE;
00395 
00396         ifmgd = &sdata->u.mgd;
00397         mutex_lock(&ifmgd->mtx);
00398 
00399         /* Copy the addresses to the bss_conf list */
00400         ifa = idev->ifa_list;
00401         while (c < IEEE80211_BSS_ARP_ADDR_LIST_LEN && ifa) {
00402                 bss_conf->arp_addr_list[c] = ifa->ifa_address;
00403                 ifa = ifa->ifa_next;
00404                 c++;
00405         }
00406 
00407         /* If not all addresses fit the list, disable filtering */
00408         if (ifa) {
00409                 sdata->arp_filter_state = false;
00410                 c = 0;
00411         } else {
00412                 sdata->arp_filter_state = true;
00413         }
00414         bss_conf->arp_addr_cnt = c;
00415 
00416         /* Configure driver only if associated (which also implies it is up) */
00417         if (ifmgd->associated) {
00418                 bss_conf->arp_filter_enabled = sdata->arp_filter_state;
00419                 ieee80211_bss_info_change_notify(sdata,
00420                                                  BSS_CHANGED_ARP_FILTER);
00421         }
00422 
00423         mutex_unlock(&ifmgd->mtx);
00424 
00425         return NOTIFY_DONE;
00426 }
00427 #endif
00428 
00429 static int ieee80211_napi_poll(struct napi_struct *napi, int budget)
00430 {
00431         struct ieee80211_local *local =
00432                 container_of(napi, struct ieee80211_local, napi);
00433 
00434         return local->ops->napi_poll(&local->hw, budget);
00435 }
00436 
00437 void ieee80211_napi_schedule(struct ieee80211_hw *hw)
00438 {
00439         struct ieee80211_local *local = hw_to_local(hw);
00440 
00441         napi_schedule(&local->napi);
00442 }
00443 EXPORT_SYMBOL(ieee80211_napi_schedule);
00444 
00445 void ieee80211_napi_complete(struct ieee80211_hw *hw)
00446 {
00447         struct ieee80211_local *local = hw_to_local(hw);
00448 
00449         napi_complete(&local->napi);
00450 }
00451 EXPORT_SYMBOL(ieee80211_napi_complete);
00452 
00453 /* There isn't a lot of sense in it, but you can transmit anything you like */
00454 static const struct ieee80211_txrx_stypes
00455 ieee80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
00456         [NL80211_IFTYPE_ADHOC] = {
00457                 .tx = 0xffff,
00458                 .rx = BIT(IEEE80211_STYPE_ACTION >> 4),
00459         },
00460         [NL80211_IFTYPE_STATION] = {
00461                 .tx = 0xffff,
00462                 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
00463                         BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
00464         },
00465         [NL80211_IFTYPE_AP] = {
00466                 .tx = 0xffff,
00467                 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
00468                         BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
00469                         BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
00470                         BIT(IEEE80211_STYPE_DISASSOC >> 4) |
00471                         BIT(IEEE80211_STYPE_AUTH >> 4) |
00472                         BIT(IEEE80211_STYPE_DEAUTH >> 4) |
00473                         BIT(IEEE80211_STYPE_ACTION >> 4),
00474         },
00475         [NL80211_IFTYPE_AP_VLAN] = {
00476                 /* copy AP */
00477                 .tx = 0xffff,
00478                 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
00479                         BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
00480                         BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
00481                         BIT(IEEE80211_STYPE_DISASSOC >> 4) |
00482                         BIT(IEEE80211_STYPE_AUTH >> 4) |
00483                         BIT(IEEE80211_STYPE_DEAUTH >> 4) |
00484                         BIT(IEEE80211_STYPE_ACTION >> 4),
00485         },
00486         [NL80211_IFTYPE_P2P_CLIENT] = {
00487                 .tx = 0xffff,
00488                 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
00489                         BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
00490         },
00491         [NL80211_IFTYPE_P2P_GO] = {
00492                 .tx = 0xffff,
00493                 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
00494                         BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
00495                         BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
00496                         BIT(IEEE80211_STYPE_DISASSOC >> 4) |
00497                         BIT(IEEE80211_STYPE_AUTH >> 4) |
00498                         BIT(IEEE80211_STYPE_DEAUTH >> 4) |
00499                         BIT(IEEE80211_STYPE_ACTION >> 4),
00500         },
00501         [NL80211_IFTYPE_MESH_POINT] = {
00502                 .tx = 0xffff,
00503                 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
00504                         BIT(IEEE80211_STYPE_AUTH >> 4) |
00505                         BIT(IEEE80211_STYPE_DEAUTH >> 4),
00506         },
00507 };
00508 
00509 static const struct ieee80211_ht_cap mac80211_ht_capa_mod_mask = {
00510         .ampdu_params_info = IEEE80211_HT_AMPDU_PARM_FACTOR |
00511                              IEEE80211_HT_AMPDU_PARM_DENSITY,
00512 
00513         .cap_info = cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
00514                                 IEEE80211_HT_CAP_MAX_AMSDU |
00515                                 IEEE80211_HT_CAP_SGI_40),
00516         .mcs = {
00517                 .rx_mask = { 0xff, 0xff, 0xff, 0xff, 0xff,
00518                              0xff, 0xff, 0xff, 0xff, 0xff, },
00519         },
00520 };
00521 
00522 struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
00523                                         const struct ieee80211_ops *ops)
00524 {
00525         struct ieee80211_local *local;
00526         int priv_size, i;
00527         struct wiphy *wiphy;
00528 
00529         if (WARN_ON(ops->sta_state && (ops->sta_add || ops->sta_remove)))
00530                 return NULL;
00531 
00532         printk(KERN_ERR "*** MAC80211 for RT-WMP is loading...");
00533         /* Ensure 32-byte alignment of our private data and hw private data.
00534          * We use the wiphy priv data for both our ieee80211_local and for
00535          * the driver's private data
00536          *
00537          * In memory it'll be like this:
00538          *
00539          * +-------------------------+
00540          * | struct wiphy           |
00541          * +-------------------------+
00542          * | struct ieee80211_local  |
00543          * +-------------------------+
00544          * | driver's private data   |
00545          * +-------------------------+
00546          *
00547          */
00548         priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
00549 
00550         wiphy = wiphy_new(&mac80211_config_ops, priv_size);
00551 
00552         if (!wiphy)
00553                 return NULL;
00554 
00555         wiphy->mgmt_stypes = ieee80211_default_mgmt_stypes;
00556 
00557         wiphy->privid = mac80211_wiphy_privid;
00558 
00559         wiphy->flags |= WIPHY_FLAG_NETNS_OK |
00560                         WIPHY_FLAG_4ADDR_AP |
00561                         WIPHY_FLAG_4ADDR_STATION |
00562                         WIPHY_FLAG_REPORTS_OBSS |
00563                         WIPHY_FLAG_OFFCHAN_TX;
00564 
00565         if (ops->remain_on_channel)
00566                 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
00567 
00568         wiphy->features = NL80211_FEATURE_SK_TX_STATUS |
00569                           NL80211_FEATURE_HT_IBSS;
00570 
00571         if (!ops->set_key)
00572                 wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
00573 
00574         wiphy->bss_priv_size = sizeof(struct ieee80211_bss);
00575 
00576         local = wiphy_priv(wiphy);
00577 
00578         local->hw.wiphy = wiphy;
00579 
00580         local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
00581 
00582         BUG_ON(!ops->tx && !ops->tx_frags);
00583         BUG_ON(!ops->start);
00584         BUG_ON(!ops->stop);
00585         BUG_ON(!ops->config);
00586         BUG_ON(!ops->add_interface);
00587         BUG_ON(!ops->remove_interface);
00588         BUG_ON(!ops->configure_filter);
00589         local->ops = ops;
00590 
00591         /* set up some defaults */
00592         local->hw.queues = 1;
00593         local->hw.max_rates = 1;
00594         local->hw.max_report_rates = 0;
00595         local->hw.max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
00596         local->hw.max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
00597         local->hw.offchannel_tx_hw_queue = IEEE80211_INVAL_HW_QUEUE;
00598         local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
00599         local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
00600         local->hw.radiotap_mcs_details = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
00601                                          IEEE80211_RADIOTAP_MCS_HAVE_GI |
00602                                          IEEE80211_RADIOTAP_MCS_HAVE_BW;
00603         local->user_power_level = -1;
00604         wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask;
00605 
00606         INIT_LIST_HEAD(&local->interfaces);
00607 
00608         __hw_addr_init(&local->mc_list);
00609 
00610         mutex_init(&local->iflist_mtx);
00611         mutex_init(&local->mtx);
00612 
00613         mutex_init(&local->key_mtx);
00614         spin_lock_init(&local->filter_lock);
00615         spin_lock_init(&local->queue_stop_reason_lock);
00616 
00617         /*
00618          * The rx_skb_queue is only accessed from tasklets,
00619          * but other SKB queues are used from within IRQ
00620          * context. Therefore, this one needs a different
00621          * locking class so our direct, non-irq-safe use of
00622          * the queue's lock doesn't throw lockdep warnings.
00623          */
00624         skb_queue_head_init_class(&local->rx_skb_queue,
00625                                   &ieee80211_rx_skb_queue_class);
00626 
00627         INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
00628 
00629         ieee80211_work_init(local);
00630 
00631         INIT_WORK(&local->restart_work, ieee80211_restart_work);
00632 
00633         INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter);
00634         INIT_WORK(&local->recalc_smps, ieee80211_recalc_smps_work);
00635         local->smps_mode = IEEE80211_SMPS_OFF;
00636 
00637         INIT_WORK(&local->dynamic_ps_enable_work,
00638                   ieee80211_dynamic_ps_enable_work);
00639         INIT_WORK(&local->dynamic_ps_disable_work,
00640                   ieee80211_dynamic_ps_disable_work);
00641         setup_timer(&local->dynamic_ps_timer,
00642                     ieee80211_dynamic_ps_timer, (unsigned long) local);
00643 
00644         INIT_WORK(&local->sched_scan_stopped_work,
00645                   ieee80211_sched_scan_stopped_work);
00646 
00647         spin_lock_init(&local->ack_status_lock);
00648         idr_init(&local->ack_status_frames);
00649         /* preallocate at least one entry */
00650         idr_pre_get(&local->ack_status_frames, GFP_KERNEL);
00651 
00652         sta_info_init(local);
00653 
00654         for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
00655                 skb_queue_head_init(&local->pending[i]);
00656                 atomic_set(&local->agg_queue_stop[i], 0);
00657         }
00658         tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
00659                      (unsigned long)local);
00660 
00661         tasklet_init(&local->tasklet,
00662                      ieee80211_tasklet_handler,
00663                      (unsigned long) local);
00664 
00665         skb_queue_head_init(&local->skb_queue);
00666         skb_queue_head_init(&local->skb_queue_unreliable);
00667 
00668         /* init dummy netdev for use w/ NAPI */
00669         init_dummy_netdev(&local->napi_dev);
00670 
00671         ieee80211_led_names(local);
00672 
00673         ieee80211_hw_roc_setup(local);
00674 
00675         return &local->hw;
00676 }
00677 EXPORT_SYMBOL(ieee80211_alloc_hw);
00678 
00679 int ieee80211_register_hw(struct ieee80211_hw *hw)
00680 {
00681         struct ieee80211_local *local = hw_to_local(hw);
00682         int result, i;
00683         enum ieee80211_band band;
00684         int channels, max_bitrates;
00685         bool supp_ht;
00686         static const u32 cipher_suites[] = {
00687                 /* keep WEP first, it may be removed below */
00688                 WLAN_CIPHER_SUITE_WEP40,
00689                 WLAN_CIPHER_SUITE_WEP104,
00690                 WLAN_CIPHER_SUITE_TKIP,
00691                 WLAN_CIPHER_SUITE_CCMP,
00692 
00693                 /* keep last -- depends on hw flags! */
00694                 WLAN_CIPHER_SUITE_AES_CMAC
00695         };
00696 
00697         if (hw->flags & IEEE80211_HW_QUEUE_CONTROL &&
00698             (local->hw.offchannel_tx_hw_queue == IEEE80211_INVAL_HW_QUEUE ||
00699              local->hw.offchannel_tx_hw_queue >= local->hw.queues))
00700                 return -EINVAL;
00701 
00702         if ((hw->wiphy->wowlan.flags || hw->wiphy->wowlan.n_patterns)
00703 #ifdef CONFIG_PM
00704             && (!local->ops->suspend || !local->ops->resume)
00705 #endif
00706             )
00707                 return -EINVAL;
00708 
00709         if ((hw->flags & IEEE80211_HW_SCAN_WHILE_IDLE) && !local->ops->hw_scan)
00710                 return -EINVAL;
00711 
00712         if (hw->max_report_rates == 0)
00713                 hw->max_report_rates = hw->max_rates;
00714 
00715         /*
00716          * generic code guarantees at least one band,
00717          * set this very early because much code assumes
00718          * that hw.conf.channel is assigned
00719          */
00720         channels = 0;
00721         max_bitrates = 0;
00722         supp_ht = false;
00723         for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
00724                 struct ieee80211_supported_band *sband;
00725 
00726                 sband = local->hw.wiphy->bands[band];
00727                 if (!sband)
00728                         continue;
00729                 if (!local->oper_channel) {
00730                         /* init channel we're on */
00731                         local->hw.conf.channel =
00732                         local->oper_channel = &sband->channels[0];
00733                         local->hw.conf.channel_type = NL80211_CHAN_NO_HT;
00734                 }
00735                 channels += sband->n_channels;
00736 
00737                 if (max_bitrates < sband->n_bitrates)
00738                         max_bitrates = sband->n_bitrates;
00739                 supp_ht = supp_ht || sband->ht_cap.ht_supported;
00740         }
00741 
00742         local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) +
00743                                       sizeof(void *) * channels, GFP_KERNEL);
00744         if (!local->int_scan_req)
00745                 return -ENOMEM;
00746 
00747         for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
00748                 if (!local->hw.wiphy->bands[band])
00749                         continue;
00750                 local->int_scan_req->rates[band] = (u32) -1;
00751         }
00752 
00753         /* if low-level driver supports AP, we also support VLAN */
00754         if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
00755                 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
00756                 hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
00757         }
00758 
00759         /* mac80211 always supports monitor */
00760         hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
00761         hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
00762 
00763         /*
00764          * mac80211 doesn't support more than 1 channel, and also not more
00765          * than one IBSS interface
00766          */
00767         for (i = 0; i < hw->wiphy->n_iface_combinations; i++) {
00768                 const struct ieee80211_iface_combination *c;
00769                 int j;
00770 
00771                 c = &hw->wiphy->iface_combinations[i];
00772 
00773                 if (c->num_different_channels > 1)
00774                         return -EINVAL;
00775 
00776                 for (j = 0; j < c->n_limits; j++)
00777                         if ((c->limits[j].types & BIT(NL80211_IFTYPE_ADHOC)) &&
00778                             c->limits[j].max > 1)
00779                                 return -EINVAL;
00780         }
00781 
00782 #ifndef CONFIG_MAC80211_MESH
00783         /* mesh depends on Kconfig, but drivers should set it if they want */
00784         local->hw.wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MESH_POINT);
00785 #endif
00786 
00787         /* if the underlying driver supports mesh, mac80211 will (at least)
00788          * provide routing of mesh authentication frames to userspace */
00789         if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
00790                 local->hw.wiphy->flags |= WIPHY_FLAG_MESH_AUTH;
00791 
00792         /* mac80211 supports control port protocol changing */
00793         local->hw.wiphy->flags |= WIPHY_FLAG_CONTROL_PORT_PROTOCOL;
00794 
00795         if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
00796                 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
00797         else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
00798                 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
00799 
00800         WARN((local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
00801              && (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK),
00802              "U-APSD not supported with HW_PS_NULLFUNC_STACK\n");
00803 
00804         /*
00805          * Calculate scan IE length -- we need this to alloc
00806          * memory and to subtract from the driver limit. It
00807          * includes the DS Params, (extended) supported rates, and HT
00808          * information -- SSID is the driver's responsibility.
00809          */
00810         local->scan_ies_len = 4 + max_bitrates /* (ext) supp rates */ +
00811                 3 /* DS Params */;
00812         if (supp_ht)
00813                 local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
00814 
00815         if (!local->ops->hw_scan) {
00816                 /* For hw_scan, driver needs to set these up. */
00817                 local->hw.wiphy->max_scan_ssids = 4;
00818                 local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
00819         }
00820 
00821         /*
00822          * If the driver supports any scan IEs, then assume the
00823          * limit includes the IEs mac80211 will add, otherwise
00824          * leave it at zero and let the driver sort it out; we
00825          * still pass our IEs to the driver but userspace will
00826          * not be allowed to in that case.
00827          */
00828         if (local->hw.wiphy->max_scan_ie_len)
00829                 local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
00830 
00831         /* Set up cipher suites unless driver already did */
00832         if (!local->hw.wiphy->cipher_suites) {
00833                 local->hw.wiphy->cipher_suites = cipher_suites;
00834                 local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
00835                 if (!(local->hw.flags & IEEE80211_HW_MFP_CAPABLE))
00836                         local->hw.wiphy->n_cipher_suites--;
00837         }
00838         if (IS_ERR(local->wep_tx_tfm) || IS_ERR(local->wep_rx_tfm)) {
00839                 if (local->hw.wiphy->cipher_suites == cipher_suites) {
00840                         local->hw.wiphy->cipher_suites += 2;
00841                         local->hw.wiphy->n_cipher_suites -= 2;
00842                 } else {
00843                         u32 *suites;
00844                         int r, w = 0;
00845 
00846                         /* Filter out WEP */
00847 
00848                         suites = kmemdup(
00849                                 local->hw.wiphy->cipher_suites,
00850                                 sizeof(u32) * local->hw.wiphy->n_cipher_suites,
00851                                 GFP_KERNEL);
00852                         if (!suites)
00853                                 return -ENOMEM;
00854                         for (r = 0; r < local->hw.wiphy->n_cipher_suites; r++) {
00855                                 u32 suite = local->hw.wiphy->cipher_suites[r];
00856                                 if (suite == WLAN_CIPHER_SUITE_WEP40 ||
00857                                     suite == WLAN_CIPHER_SUITE_WEP104)
00858                                         continue;
00859                                 suites[w++] = suite;
00860                         }
00861                         local->hw.wiphy->cipher_suites = suites;
00862                         local->hw.wiphy->n_cipher_suites = w;
00863                         local->wiphy_ciphers_allocated = true;
00864                 }
00865         }
00866 
00867         if (!local->ops->remain_on_channel)
00868                 local->hw.wiphy->max_remain_on_channel_duration = 5000;
00869 
00870         if (local->ops->sched_scan_start)
00871                 local->hw.wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
00872 
00873         /* mac80211 based drivers don't support internal TDLS setup */
00874         if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)
00875                 local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
00876 
00877         result = wiphy_register(local->hw.wiphy);
00878         if (result < 0)
00879                 goto fail_wiphy_register;
00880 
00881         /*
00882          * We use the number of queues for feature tests (QoS, HT) internally
00883          * so restrict them appropriately.
00884          */
00885         if (hw->queues > IEEE80211_MAX_QUEUES)
00886                 hw->queues = IEEE80211_MAX_QUEUES;
00887 
00888         local->workqueue =
00889                 alloc_ordered_workqueue(wiphy_name(local->hw.wiphy), 0);
00890         if (!local->workqueue) {
00891                 result = -ENOMEM;
00892                 goto fail_workqueue;
00893         }
00894 
00895         /*
00896          * The hardware needs headroom for sending the frame,
00897          * and we need some headroom for passing the frame to monitor
00898          * interfaces, but never both at the same time.
00899          */
00900         local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
00901                                    IEEE80211_TX_STATUS_HEADROOM);
00902 
00903         debugfs_hw_add(local);
00904 
00905         /*
00906          * if the driver doesn't specify a max listen interval we
00907          * use 5 which should be a safe default
00908          */
00909         if (local->hw.max_listen_interval == 0)
00910                 local->hw.max_listen_interval = 5;
00911 
00912         local->hw.conf.listen_interval = local->hw.max_listen_interval;
00913 
00914         local->dynamic_ps_forced_timeout = -1;
00915 
00916         result = ieee80211_wep_init(local);
00917         if (result < 0)
00918                 wiphy_debug(local->hw.wiphy, "Failed to initialize wep: %d\n",
00919                             result);
00920 
00921         ieee80211_led_init(local);
00922 
00923         rtnl_lock();
00924 
00925         result = ieee80211_init_rate_ctrl_alg(local,
00926                                               hw->rate_control_algorithm);
00927         if (result < 0) {
00928                 wiphy_debug(local->hw.wiphy,
00929                             "Failed to initialize rate control algorithm\n");
00930                 goto fail_rate;
00931         }
00932 
00933         /* add one default STA interface if supported */
00934         if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION)) {
00935                 result = ieee80211_if_add(local, "wlan%d", NULL,
00936                                           NL80211_IFTYPE_STATION, NULL);
00937                 if (result)
00938                         wiphy_warn(local->hw.wiphy,
00939                                    "Failed to add default virtual iface\n");
00940         }
00941 
00942         rtnl_unlock();
00943 
00944         local->network_latency_notifier.notifier_call =
00945                 ieee80211_max_network_latency;
00946         result = pm_qos_add_notifier(PM_QOS_NETWORK_LATENCY,
00947                                      &local->network_latency_notifier);
00948         if (result) {
00949                 rtnl_lock();
00950                 goto fail_pm_qos;
00951         }
00952 
00953 #ifdef CONFIG_INET
00954         local->ifa_notifier.notifier_call = ieee80211_ifa_changed;
00955         result = register_inetaddr_notifier(&local->ifa_notifier);
00956         if (result)
00957                 goto fail_ifa;
00958 #endif
00959 
00960         netif_napi_add(&local->napi_dev, &local->napi, ieee80211_napi_poll,
00961                         local->hw.napi_weight);
00962 
00963         return 0;
00964 
00965 #ifdef CONFIG_INET
00966  fail_ifa:
00967         pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
00968                                &local->network_latency_notifier);
00969         rtnl_lock();
00970 #endif
00971  fail_pm_qos:
00972         ieee80211_led_exit(local);
00973         ieee80211_remove_interfaces(local);
00974  fail_rate:
00975         rtnl_unlock();
00976         ieee80211_wep_free(local);
00977         sta_info_stop(local);
00978         destroy_workqueue(local->workqueue);
00979  fail_workqueue:
00980         wiphy_unregister(local->hw.wiphy);
00981  fail_wiphy_register:
00982         if (local->wiphy_ciphers_allocated)
00983                 kfree(local->hw.wiphy->cipher_suites);
00984         kfree(local->int_scan_req);
00985         return result;
00986 }
00987 EXPORT_SYMBOL(ieee80211_register_hw);
00988 
00989 void ieee80211_unregister_hw(struct ieee80211_hw *hw)
00990 {
00991         struct ieee80211_local *local = hw_to_local(hw);
00992 
00993         tasklet_kill(&local->tx_pending_tasklet);
00994         tasklet_kill(&local->tasklet);
00995 
00996         pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
00997                                &local->network_latency_notifier);
00998 #ifdef CONFIG_INET
00999         unregister_inetaddr_notifier(&local->ifa_notifier);
01000 #endif
01001 
01002         rtnl_lock();
01003 
01004         /*
01005          * At this point, interface list manipulations are fine
01006          * because the driver cannot be handing us frames any
01007          * more and the tasklet is killed.
01008          */
01009         ieee80211_remove_interfaces(local);
01010 
01011         rtnl_unlock();
01012 
01013         /*
01014          * Now all work items will be gone, but the
01015          * timer might still be armed, so delete it
01016          */
01017         del_timer_sync(&local->work_timer);
01018 
01019         cancel_work_sync(&local->restart_work);
01020         cancel_work_sync(&local->reconfig_filter);
01021 
01022         ieee80211_clear_tx_pending(local);
01023         rate_control_deinitialize(local);
01024 
01025         if (skb_queue_len(&local->skb_queue) ||
01026             skb_queue_len(&local->skb_queue_unreliable))
01027                 wiphy_warn(local->hw.wiphy, "skb_queue not empty\n");
01028         skb_queue_purge(&local->skb_queue);
01029         skb_queue_purge(&local->skb_queue_unreliable);
01030         skb_queue_purge(&local->rx_skb_queue);
01031 
01032         destroy_workqueue(local->workqueue);
01033         wiphy_unregister(local->hw.wiphy);
01034         sta_info_stop(local);
01035         ieee80211_wep_free(local);
01036         ieee80211_led_exit(local);
01037         kfree(local->int_scan_req);
01038 }
01039 EXPORT_SYMBOL(ieee80211_unregister_hw);
01040 
01041 static int ieee80211_free_ack_frame(int id, void *p, void *data)
01042 {
01043         WARN_ONCE(1, "Have pending ack frames!\n");
01044         kfree_skb(p);
01045         return 0;
01046 }
01047 
01048 void ieee80211_free_hw(struct ieee80211_hw *hw)
01049 {
01050         struct ieee80211_local *local = hw_to_local(hw);
01051 
01052         mutex_destroy(&local->iflist_mtx);
01053         mutex_destroy(&local->mtx);
01054 
01055         if (local->wiphy_ciphers_allocated)
01056                 kfree(local->hw.wiphy->cipher_suites);
01057 
01058         idr_for_each(&local->ack_status_frames,
01059                      ieee80211_free_ack_frame, NULL);
01060         idr_destroy(&local->ack_status_frames);
01061 
01062         wiphy_free(local->hw.wiphy);
01063 }
01064 EXPORT_SYMBOL(ieee80211_free_hw);
01065 
01066 static int __init ieee80211_init(void)
01067 {
01068         struct sk_buff *skb;
01069         int ret;
01070 
01071         BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
01072         BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
01073                      IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
01074 
01075         ret = rc80211_minstrel_init();
01076         if (ret)
01077                 return ret;
01078 
01079         ret = rc80211_minstrel_ht_init();
01080         if (ret)
01081                 goto err_minstrel;
01082 
01083         ret = rc80211_pid_init();
01084         if (ret)
01085                 goto err_pid;
01086 
01087         ret = ieee80211_iface_init();
01088         if (ret)
01089                 goto err_netdev;
01090 
01091         return 0;
01092  err_netdev:
01093         rc80211_pid_exit();
01094  err_pid:
01095         rc80211_minstrel_ht_exit();
01096  err_minstrel:
01097         rc80211_minstrel_exit();
01098 
01099         return ret;
01100 }
01101 
01102 static void __exit ieee80211_exit(void)
01103 {
01104         rc80211_pid_exit();
01105         rc80211_minstrel_ht_exit();
01106         rc80211_minstrel_exit();
01107 
01108         if (mesh_allocated)
01109                 ieee80211s_stop();
01110 
01111         ieee80211_iface_exit();
01112 
01113         rcu_barrier();
01114 }
01115 
01116 
01117 subsys_initcall(ieee80211_init);
01118 module_exit(ieee80211_exit);
01119 
01120 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
01121 MODULE_LICENSE("GPL");


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Fri Jan 3 2014 12:07:55