00001
00002
00003
00004
00005
00006
00007
00008
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 || local->scanning)
00051 new_flags |= FIF_BCN_PRBRESP_PROMISC;
00052
00053 if (local->fif_probe_req || local->probe_req_reg)
00054 new_flags |= FIF_PROBE_REQ;
00055
00056 if (local->fif_fcsfail)
00057 new_flags |= FIF_FCSFAIL;
00058
00059 if (local->fif_plcpfail)
00060 new_flags |= FIF_PLCPFAIL;
00061
00062 if (local->fif_control)
00063 new_flags |= FIF_CONTROL;
00064
00065 if (local->fif_other_bss)
00066 new_flags |= FIF_OTHER_BSS;
00067
00068 if (local->fif_pspoll)
00069 new_flags |= FIF_PSPOLL;
00070
00071 spin_lock_bh(&local->filter_lock);
00072 changed_flags = local->filter_flags ^ new_flags;
00073
00074 mc = drv_prepare_multicast(local, &local->mc_list);
00075 spin_unlock_bh(&local->filter_lock);
00076
00077
00078 new_flags |= (1<<31);
00079
00080 drv_configure_filter(local, changed_flags, &new_flags, mc);
00081
00082 WARN_ON(new_flags & (1<<31));
00083
00084 local->filter_flags = new_flags & ~(1<<31);
00085 }
00086
00087 static void ieee80211_reconfig_filter(struct work_struct *work)
00088 {
00089 struct ieee80211_local *local =
00090 container_of(work, struct ieee80211_local, reconfig_filter);
00091
00092 ieee80211_configure_filter(local);
00093 }
00094
00095 int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
00096 {
00097 struct ieee80211_channel *chan, *scan_chan;
00098 int ret = 0;
00099 int power;
00100 enum nl80211_channel_type channel_type;
00101 u32 offchannel_flag;
00102
00103 might_sleep();
00104
00105 scan_chan = local->scan_channel;
00106
00107 offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
00108 if (scan_chan) {
00109 chan = scan_chan;
00110
00111
00112
00113 if (chan == local->oper_channel)
00114 channel_type = local->_oper_channel_type;
00115 else
00116 channel_type = NL80211_CHAN_NO_HT;
00117 local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
00118 } else if (local->tmp_channel &&
00119 local->oper_channel != local->tmp_channel) {
00120 chan = scan_chan = local->tmp_channel;
00121 channel_type = local->tmp_channel_type;
00122 local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
00123 } else {
00124 chan = local->oper_channel;
00125 channel_type = local->_oper_channel_type;
00126 local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL;
00127 }
00128
00129 offchannel_flag ^= local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
00130
00131 if (offchannel_flag || chan != local->hw.conf.channel ||
00132 channel_type != local->hw.conf.channel_type) {
00133 local->hw.conf.channel = chan;
00134 local->hw.conf.channel_type = channel_type;
00135 changed |= IEEE80211_CONF_CHANGE_CHANNEL;
00136 }
00137
00138 if (!conf_is_ht(&local->hw.conf)) {
00139
00140
00141
00142
00143
00144 local->hw.conf.smps_mode = IEEE80211_SMPS_STATIC;
00145 } else if (local->hw.conf.smps_mode != local->smps_mode) {
00146 local->hw.conf.smps_mode = local->smps_mode;
00147 changed |= IEEE80211_CONF_CHANGE_SMPS;
00148 }
00149
00150 if ((local->scanning & SCAN_SW_SCANNING) ||
00151 (local->scanning & SCAN_HW_SCANNING))
00152 power = chan->max_power;
00153 else
00154 power = local->power_constr_level ?
00155 (chan->max_power - local->power_constr_level) :
00156 chan->max_power;
00157
00158 if (local->user_power_level >= 0)
00159 power = min(power, local->user_power_level);
00160
00161 if (local->hw.conf.power_level != power) {
00162 changed |= IEEE80211_CONF_CHANGE_POWER;
00163 local->hw.conf.power_level = power;
00164 }
00165
00166 if (changed && local->open_count) {
00167 ret = drv_config(local, changed);
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 }
00184
00185 return ret;
00186 }
00187
00188 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
00189 u32 changed)
00190 {
00191 struct ieee80211_local *local = sdata->local;
00192 static const u8 zero[ETH_ALEN] = { 0 };
00193
00194 if (!changed)
00195 return;
00196
00197 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
00198
00199
00200
00201
00202
00203 if (sdata->vif.bss_conf.assoc)
00204 sdata->vif.bss_conf.bssid = sdata->u.mgd.bssid;
00205 else
00206 sdata->vif.bss_conf.bssid = zero;
00207 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
00208 sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid;
00209 else if (sdata->vif.type == NL80211_IFTYPE_AP)
00210 sdata->vif.bss_conf.bssid = sdata->vif.addr;
00211 else if (sdata->vif.type == NL80211_IFTYPE_WDS)
00212 sdata->vif.bss_conf.bssid = NULL;
00213 else if (ieee80211_vif_is_mesh(&sdata->vif)) {
00214 sdata->vif.bss_conf.bssid = zero;
00215 } else {
00216 WARN_ON(1);
00217 return;
00218 }
00219
00220 switch (sdata->vif.type) {
00221 case NL80211_IFTYPE_AP:
00222 case NL80211_IFTYPE_ADHOC:
00223 case NL80211_IFTYPE_WDS:
00224 case NL80211_IFTYPE_MESH_POINT:
00225 break;
00226 default:
00227
00228 changed &= ~BSS_CHANGED_BEACON_ENABLED;
00229 if (WARN_ON(changed & BSS_CHANGED_BEACON))
00230 return;
00231 break;
00232 }
00233
00234 if (changed & BSS_CHANGED_BEACON_ENABLED) {
00235 if (local->quiescing || !ieee80211_sdata_running(sdata) ||
00236 test_bit(SCAN_SW_SCANNING, &local->scanning)) {
00237 sdata->vif.bss_conf.enable_beacon = false;
00238 } else {
00239
00240
00241
00242
00243 switch (sdata->vif.type) {
00244 case NL80211_IFTYPE_AP:
00245 sdata->vif.bss_conf.enable_beacon =
00246 !!sdata->u.ap.beacon;
00247 break;
00248 case NL80211_IFTYPE_ADHOC:
00249 sdata->vif.bss_conf.enable_beacon =
00250 !!sdata->u.ibss.presp;
00251 break;
00252 #ifdef CONFIG_MAC80211_MESH
00253 case NL80211_IFTYPE_MESH_POINT:
00254 sdata->vif.bss_conf.enable_beacon =
00255 !!sdata->u.mesh.mesh_id_len;
00256 break;
00257 #endif
00258 default:
00259
00260 WARN_ON(1);
00261 break;
00262 }
00263 }
00264 }
00265
00266 drv_bss_info_changed(local, sdata, &sdata->vif.bss_conf, changed);
00267 }
00268
00269 u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
00270 {
00271 sdata->vif.bss_conf.use_cts_prot = false;
00272 sdata->vif.bss_conf.use_short_preamble = false;
00273 sdata->vif.bss_conf.use_short_slot = false;
00274 return BSS_CHANGED_ERP_CTS_PROT |
00275 BSS_CHANGED_ERP_PREAMBLE |
00276 BSS_CHANGED_ERP_SLOT;
00277 }
00278
00279 static void ieee80211_tasklet_handler(unsigned long data)
00280 {
00281 struct ieee80211_local *local = (struct ieee80211_local *) data;
00282 struct sta_info *sta, *tmp;
00283 struct skb_eosp_msg_data *eosp_data;
00284 struct sk_buff *skb;
00285
00286 while ((skb = skb_dequeue(&local->skb_queue)) ||
00287 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
00288 switch (skb->pkt_type) {
00289 case IEEE80211_RX_MSG:
00290
00291
00292 skb->pkt_type = 0;
00293 ieee80211_rx(local_to_hw(local), skb);
00294 break;
00295 case IEEE80211_TX_STATUS_MSG:
00296 skb->pkt_type = 0;
00297 ieee80211_tx_status(local_to_hw(local), skb);
00298 break;
00299 case IEEE80211_EOSP_MSG:
00300 eosp_data = (void *)skb->cb;
00301 for_each_sta_info(local, eosp_data->sta, sta, tmp) {
00302
00303 if (memcmp(eosp_data->iface,
00304 sta->sdata->vif.addr, ETH_ALEN))
00305 continue;
00306 clear_sta_flag(sta, WLAN_STA_SP);
00307 break;
00308 }
00309 dev_kfree_skb(skb);
00310 break;
00311 default:
00312 WARN(1, "mac80211: Packet is of unknown type %d\n",
00313 skb->pkt_type);
00314 dev_kfree_skb(skb);
00315 break;
00316 }
00317 }
00318 }
00319
00320 static void ieee80211_restart_work(struct work_struct *work)
00321 {
00322 struct ieee80211_local *local =
00323 container_of(work, struct ieee80211_local, restart_work);
00324
00325
00326 flush_workqueue(local->workqueue);
00327
00328 mutex_lock(&local->mtx);
00329 WARN(test_bit(SCAN_HW_SCANNING, &local->scanning) ||
00330 local->sched_scanning,
00331 "%s called with hardware scan in progress\n", __func__);
00332 mutex_unlock(&local->mtx);
00333
00334 rtnl_lock();
00335 ieee80211_scan_cancel(local);
00336 ieee80211_reconfig(local);
00337 rtnl_unlock();
00338 }
00339
00340 void ieee80211_restart_hw(struct ieee80211_hw *hw)
00341 {
00342 struct ieee80211_local *local = hw_to_local(hw);
00343
00344 trace_api_restart_hw(local);
00345
00346 wiphy_info(hw->wiphy,
00347 "Hardware restart was requested\n");
00348
00349
00350 ieee80211_stop_queues_by_reason(hw,
00351 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
00352
00353 schedule_work(&local->restart_work);
00354 }
00355 EXPORT_SYMBOL(ieee80211_restart_hw);
00356
00357 static void ieee80211_recalc_smps_work(struct work_struct *work)
00358 {
00359 struct ieee80211_local *local =
00360 container_of(work, struct ieee80211_local, recalc_smps);
00361
00362 mutex_lock(&local->iflist_mtx);
00363 ieee80211_recalc_smps(local);
00364 mutex_unlock(&local->iflist_mtx);
00365 }
00366
00367 #ifdef CONFIG_INET
00368 static int ieee80211_ifa_changed(struct notifier_block *nb,
00369 unsigned long data, void *arg)
00370 {
00371 struct in_ifaddr *ifa = arg;
00372 struct ieee80211_local *local =
00373 container_of(nb, struct ieee80211_local,
00374 ifa_notifier);
00375 struct net_device *ndev = ifa->ifa_dev->dev;
00376 struct wireless_dev *wdev = ndev->ieee80211_ptr;
00377 struct in_device *idev;
00378 struct ieee80211_sub_if_data *sdata;
00379 struct ieee80211_bss_conf *bss_conf;
00380 struct ieee80211_if_managed *ifmgd;
00381 int c = 0;
00382
00383
00384 if (!wdev)
00385 return NOTIFY_DONE;
00386
00387 if (wdev->wiphy != local->hw.wiphy)
00388 return NOTIFY_DONE;
00389
00390 sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
00391 bss_conf = &sdata->vif.bss_conf;
00392
00393 if (!ieee80211_sdata_running(sdata))
00394 return NOTIFY_DONE;
00395
00396
00397 if (sdata->vif.type != NL80211_IFTYPE_STATION)
00398 return NOTIFY_DONE;
00399
00400 idev = __in_dev_get_rtnl(sdata->dev);
00401 if (!idev)
00402 return NOTIFY_DONE;
00403
00404 ifmgd = &sdata->u.mgd;
00405 mutex_lock(&ifmgd->mtx);
00406
00407
00408 ifa = idev->ifa_list;
00409 while (c < IEEE80211_BSS_ARP_ADDR_LIST_LEN && ifa) {
00410 bss_conf->arp_addr_list[c] = ifa->ifa_address;
00411 ifa = ifa->ifa_next;
00412 c++;
00413 }
00414
00415
00416 if (ifa) {
00417 sdata->arp_filter_state = false;
00418 c = 0;
00419 } else {
00420 sdata->arp_filter_state = true;
00421 }
00422 bss_conf->arp_addr_cnt = c;
00423
00424
00425 if (ifmgd->associated) {
00426 bss_conf->arp_filter_enabled = sdata->arp_filter_state;
00427 ieee80211_bss_info_change_notify(sdata,
00428 BSS_CHANGED_ARP_FILTER);
00429 }
00430
00431 mutex_unlock(&ifmgd->mtx);
00432
00433 return NOTIFY_DONE;
00434 }
00435 #endif
00436
00437 static int ieee80211_napi_poll(struct napi_struct *napi, int budget)
00438 {
00439 struct ieee80211_local *local =
00440 container_of(napi, struct ieee80211_local, napi);
00441
00442 return local->ops->napi_poll(&local->hw, budget);
00443 }
00444
00445 void ieee80211_napi_schedule(struct ieee80211_hw *hw)
00446 {
00447 struct ieee80211_local *local = hw_to_local(hw);
00448
00449 napi_schedule(&local->napi);
00450 }
00451 EXPORT_SYMBOL(ieee80211_napi_schedule);
00452
00453 void ieee80211_napi_complete(struct ieee80211_hw *hw)
00454 {
00455 struct ieee80211_local *local = hw_to_local(hw);
00456
00457 napi_complete(&local->napi);
00458 }
00459 EXPORT_SYMBOL(ieee80211_napi_complete);
00460
00461
00462 static const struct ieee80211_txrx_stypes
00463 ieee80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
00464 [NL80211_IFTYPE_ADHOC] = {
00465 .tx = 0xffff,
00466 .rx = BIT(IEEE80211_STYPE_ACTION >> 4),
00467 },
00468 [NL80211_IFTYPE_STATION] = {
00469 .tx = 0xffff,
00470 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
00471 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
00472 },
00473 [NL80211_IFTYPE_AP] = {
00474 .tx = 0xffff,
00475 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
00476 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
00477 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
00478 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
00479 BIT(IEEE80211_STYPE_AUTH >> 4) |
00480 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
00481 BIT(IEEE80211_STYPE_ACTION >> 4),
00482 },
00483 [NL80211_IFTYPE_AP_VLAN] = {
00484
00485 .tx = 0xffff,
00486 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
00487 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
00488 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
00489 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
00490 BIT(IEEE80211_STYPE_AUTH >> 4) |
00491 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
00492 BIT(IEEE80211_STYPE_ACTION >> 4),
00493 },
00494 [NL80211_IFTYPE_P2P_CLIENT] = {
00495 .tx = 0xffff,
00496 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
00497 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
00498 },
00499 [NL80211_IFTYPE_P2P_GO] = {
00500 .tx = 0xffff,
00501 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
00502 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
00503 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
00504 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
00505 BIT(IEEE80211_STYPE_AUTH >> 4) |
00506 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
00507 BIT(IEEE80211_STYPE_ACTION >> 4),
00508 },
00509 [NL80211_IFTYPE_MESH_POINT] = {
00510 .tx = 0xffff,
00511 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
00512 BIT(IEEE80211_STYPE_AUTH >> 4) |
00513 BIT(IEEE80211_STYPE_DEAUTH >> 4),
00514 },
00515 };
00516
00517 struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
00518 const struct ieee80211_ops *ops)
00519 {
00520 struct ieee80211_local *local;
00521 int priv_size, i;
00522 struct wiphy *wiphy;
00523 printk(KERN_ERR "Initializing mac80211_mod");
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539 priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
00540
00541 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
00542
00543 if (!wiphy)
00544 return NULL;
00545
00546 wiphy->mgmt_stypes = ieee80211_default_mgmt_stypes;
00547
00548 wiphy->privid = mac80211_wiphy_privid;
00549
00550 wiphy->flags |= WIPHY_FLAG_NETNS_OK |
00551 WIPHY_FLAG_4ADDR_AP |
00552 WIPHY_FLAG_4ADDR_STATION;
00553
00554 if (!ops->set_key)
00555 wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
00556
00557 wiphy->bss_priv_size = sizeof(struct ieee80211_bss);
00558
00559 local = wiphy_priv(wiphy);
00560
00561 local->hw.wiphy = wiphy;
00562
00563 local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
00564
00565 BUG_ON(!ops->tx);
00566 BUG_ON(!ops->start);
00567 BUG_ON(!ops->stop);
00568 BUG_ON(!ops->config);
00569 BUG_ON(!ops->add_interface);
00570 BUG_ON(!ops->remove_interface);
00571 BUG_ON(!ops->configure_filter);
00572 local->ops = ops;
00573
00574
00575 local->hw.queues = 1;
00576 local->hw.max_rates = 1;
00577 local->hw.max_report_rates = 0;
00578 local->hw.max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
00579 local->hw.max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
00580 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
00581 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
00582 local->user_power_level = -1;
00583 local->uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
00584 local->uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
00585
00586 INIT_LIST_HEAD(&local->interfaces);
00587
00588 __hw_addr_init(&local->mc_list);
00589
00590 mutex_init(&local->iflist_mtx);
00591 mutex_init(&local->mtx);
00592
00593 mutex_init(&local->key_mtx);
00594 spin_lock_init(&local->filter_lock);
00595 spin_lock_init(&local->queue_stop_reason_lock);
00596
00597
00598
00599
00600
00601
00602
00603
00604 skb_queue_head_init_class(&local->rx_skb_queue,
00605 &ieee80211_rx_skb_queue_class);
00606
00607 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
00608
00609 ieee80211_work_init(local);
00610
00611 INIT_WORK(&local->restart_work, ieee80211_restart_work);
00612
00613 INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter);
00614 INIT_WORK(&local->recalc_smps, ieee80211_recalc_smps_work);
00615 local->smps_mode = IEEE80211_SMPS_OFF;
00616
00617 INIT_WORK(&local->dynamic_ps_enable_work,
00618 ieee80211_dynamic_ps_enable_work);
00619 INIT_WORK(&local->dynamic_ps_disable_work,
00620 ieee80211_dynamic_ps_disable_work);
00621 setup_timer(&local->dynamic_ps_timer,
00622 ieee80211_dynamic_ps_timer, (unsigned long) local);
00623
00624 INIT_WORK(&local->sched_scan_stopped_work,
00625 ieee80211_sched_scan_stopped_work);
00626
00627 sta_info_init(local);
00628
00629 for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
00630 skb_queue_head_init(&local->pending[i]);
00631 atomic_set(&local->agg_queue_stop[i], 0);
00632 }
00633 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
00634 (unsigned long)local);
00635
00636 tasklet_init(&local->tasklet,
00637 ieee80211_tasklet_handler,
00638 (unsigned long) local);
00639
00640 skb_queue_head_init(&local->skb_queue);
00641 skb_queue_head_init(&local->skb_queue_unreliable);
00642
00643
00644 init_dummy_netdev(&local->napi_dev);
00645
00646 ieee80211_led_names(local);
00647
00648 ieee80211_hw_roc_setup(local);
00649
00650 return local_to_hw(local);
00651 }
00652 EXPORT_SYMBOL(ieee80211_alloc_hw);
00653
00654 int ieee80211_register_hw(struct ieee80211_hw *hw)
00655 {
00656 struct ieee80211_local *local = hw_to_local(hw);
00657 int result, i;
00658 enum ieee80211_band band;
00659 int channels, max_bitrates;
00660 bool supp_ht;
00661 static const u32 cipher_suites[] = {
00662
00663 WLAN_CIPHER_SUITE_WEP40,
00664 WLAN_CIPHER_SUITE_WEP104,
00665 WLAN_CIPHER_SUITE_TKIP,
00666 WLAN_CIPHER_SUITE_CCMP,
00667
00668
00669 WLAN_CIPHER_SUITE_AES_CMAC
00670 };
00671
00672 if ((hw->wiphy->wowlan.flags || hw->wiphy->wowlan.n_patterns)
00673 #ifdef CONFIG_PM
00674 && (!local->ops->suspend || !local->ops->resume)
00675 #endif
00676 )
00677 return -EINVAL;
00678
00679 if (hw->max_report_rates == 0)
00680 hw->max_report_rates = hw->max_rates;
00681
00682
00683
00684
00685
00686
00687 channels = 0;
00688 max_bitrates = 0;
00689 supp_ht = false;
00690 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
00691 struct ieee80211_supported_band *sband;
00692
00693 sband = local->hw.wiphy->bands[band];
00694 if (!sband)
00695 continue;
00696 if (!local->oper_channel) {
00697
00698 local->hw.conf.channel =
00699 local->oper_channel = &sband->channels[0];
00700 local->hw.conf.channel_type = NL80211_CHAN_NO_HT;
00701 }
00702 channels += sband->n_channels;
00703
00704 if (max_bitrates < sband->n_bitrates)
00705 max_bitrates = sband->n_bitrates;
00706 supp_ht = supp_ht || sband->ht_cap.ht_supported;
00707 }
00708
00709 local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) +
00710 sizeof(void *) * channels, GFP_KERNEL);
00711 if (!local->int_scan_req)
00712 return -ENOMEM;
00713
00714 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
00715 if (!local->hw.wiphy->bands[band])
00716 continue;
00717 local->int_scan_req->rates[band] = (u32) -1;
00718 }
00719
00720
00721 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
00722 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
00723 hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
00724 }
00725
00726
00727 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
00728 hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
00729
00730
00731
00732
00733
00734 for (i = 0; i < hw->wiphy->n_iface_combinations; i++) {
00735 const struct ieee80211_iface_combination *c;
00736 int j;
00737
00738 c = &hw->wiphy->iface_combinations[i];
00739
00740 if (c->num_different_channels > 1)
00741 return -EINVAL;
00742
00743 for (j = 0; j < c->n_limits; j++)
00744 if ((c->limits[j].types & BIT(NL80211_IFTYPE_ADHOC)) &&
00745 c->limits[j].max > 1)
00746 return -EINVAL;
00747 }
00748
00749 #ifndef CONFIG_MAC80211_MESH
00750
00751 local->hw.wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MESH_POINT);
00752 #endif
00753
00754
00755
00756 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
00757 local->hw.wiphy->flags |= WIPHY_FLAG_MESH_AUTH;
00758
00759
00760 local->hw.wiphy->flags |= WIPHY_FLAG_CONTROL_PORT_PROTOCOL;
00761
00762 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
00763 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
00764 else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
00765 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
00766
00767 WARN((local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
00768 && (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK),
00769 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n");
00770
00771
00772
00773
00774
00775
00776
00777 local->scan_ies_len = 4 + max_bitrates +
00778 3 ;
00779 if (supp_ht)
00780 local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
00781
00782 if (!local->ops->hw_scan) {
00783
00784 local->hw.wiphy->max_scan_ssids = 4;
00785 local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
00786 }
00787
00788
00789
00790
00791
00792
00793
00794
00795 if (local->hw.wiphy->max_scan_ie_len)
00796 local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
00797
00798
00799 if (!local->hw.wiphy->cipher_suites) {
00800 local->hw.wiphy->cipher_suites = cipher_suites;
00801 local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
00802 if (!(local->hw.flags & IEEE80211_HW_MFP_CAPABLE))
00803 local->hw.wiphy->n_cipher_suites--;
00804 }
00805 if (IS_ERR(local->wep_tx_tfm) || IS_ERR(local->wep_rx_tfm)) {
00806 if (local->hw.wiphy->cipher_suites == cipher_suites) {
00807 local->hw.wiphy->cipher_suites += 2;
00808 local->hw.wiphy->n_cipher_suites -= 2;
00809 } else {
00810 u32 *suites;
00811 int r, w = 0;
00812
00813
00814
00815 suites = kmemdup(
00816 local->hw.wiphy->cipher_suites,
00817 sizeof(u32) * local->hw.wiphy->n_cipher_suites,
00818 GFP_KERNEL);
00819 if (!suites)
00820 return -ENOMEM;
00821 for (r = 0; r < local->hw.wiphy->n_cipher_suites; r++) {
00822 u32 suite = local->hw.wiphy->cipher_suites[r];
00823 if (suite == WLAN_CIPHER_SUITE_WEP40 ||
00824 suite == WLAN_CIPHER_SUITE_WEP104)
00825 continue;
00826 suites[w++] = suite;
00827 }
00828 local->hw.wiphy->cipher_suites = suites;
00829 local->hw.wiphy->n_cipher_suites = w;
00830 local->wiphy_ciphers_allocated = true;
00831 }
00832 }
00833
00834 if (!local->ops->remain_on_channel)
00835 local->hw.wiphy->max_remain_on_channel_duration = 5000;
00836
00837 if (local->ops->sched_scan_start)
00838 local->hw.wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
00839
00840
00841 if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)
00842 local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
00843
00844 result = wiphy_register(local->hw.wiphy);
00845 if (result < 0)
00846 goto fail_wiphy_register;
00847
00848
00849
00850
00851
00852 if (hw->queues > IEEE80211_MAX_QUEUES)
00853 hw->queues = IEEE80211_MAX_QUEUES;
00854
00855 local->workqueue =
00856 alloc_ordered_workqueue(wiphy_name(local->hw.wiphy), 0);
00857 if (!local->workqueue) {
00858 result = -ENOMEM;
00859 goto fail_workqueue;
00860 }
00861
00862
00863
00864
00865
00866
00867 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
00868 IEEE80211_TX_STATUS_HEADROOM);
00869
00870 debugfs_hw_add(local);
00871
00872
00873
00874
00875
00876 if (local->hw.max_listen_interval == 0)
00877 local->hw.max_listen_interval = 5;
00878
00879 local->hw.conf.listen_interval = local->hw.max_listen_interval;
00880
00881 local->dynamic_ps_forced_timeout = -1;
00882
00883 result = ieee80211_wep_init(local);
00884 if (result < 0)
00885 wiphy_debug(local->hw.wiphy, "Failed to initialize wep: %d\n",
00886 result);
00887
00888 ieee80211_led_init(local);
00889
00890 rtnl_lock();
00891
00892 result = ieee80211_init_rate_ctrl_alg(local,
00893 hw->rate_control_algorithm);
00894 if (result < 0) {
00895 wiphy_debug(local->hw.wiphy,
00896 "Failed to initialize rate control algorithm\n");
00897 goto fail_rate;
00898 }
00899
00900
00901 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION)) {
00902 result = ieee80211_if_add(local, "wlan%d", NULL,
00903 NL80211_IFTYPE_STATION, NULL);
00904 if (result)
00905 wiphy_warn(local->hw.wiphy,
00906 "Failed to add default virtual iface\n");
00907 }
00908
00909 rtnl_unlock();
00910
00911 local->network_latency_notifier.notifier_call =
00912 ieee80211_max_network_latency;
00913 result = pm_qos_add_notifier(PM_QOS_NETWORK_LATENCY,
00914 &local->network_latency_notifier);
00915 if (result) {
00916 rtnl_lock();
00917 goto fail_pm_qos;
00918 }
00919
00920 #ifdef CONFIG_INET
00921 local->ifa_notifier.notifier_call = ieee80211_ifa_changed;
00922 result = register_inetaddr_notifier(&local->ifa_notifier);
00923 if (result)
00924 goto fail_ifa;
00925 #endif
00926
00927 netif_napi_add(&local->napi_dev, &local->napi, ieee80211_napi_poll,
00928 local->hw.napi_weight);
00929
00930 return 0;
00931
00932 #ifdef CONFIG_INET
00933 fail_ifa:
00934 pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
00935 &local->network_latency_notifier);
00936 rtnl_lock();
00937 #endif
00938 fail_pm_qos:
00939 ieee80211_led_exit(local);
00940 ieee80211_remove_interfaces(local);
00941 fail_rate:
00942 rtnl_unlock();
00943 ieee80211_wep_free(local);
00944 sta_info_stop(local);
00945 destroy_workqueue(local->workqueue);
00946 fail_workqueue:
00947 wiphy_unregister(local->hw.wiphy);
00948 fail_wiphy_register:
00949 if (local->wiphy_ciphers_allocated)
00950 kfree(local->hw.wiphy->cipher_suites);
00951 kfree(local->int_scan_req);
00952 return result;
00953 }
00954 EXPORT_SYMBOL(ieee80211_register_hw);
00955
00956 void ieee80211_unregister_hw(struct ieee80211_hw *hw)
00957 {
00958 struct ieee80211_local *local = hw_to_local(hw);
00959
00960 tasklet_kill(&local->tx_pending_tasklet);
00961 tasklet_kill(&local->tasklet);
00962
00963 pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
00964 &local->network_latency_notifier);
00965 #ifdef CONFIG_INET
00966 unregister_inetaddr_notifier(&local->ifa_notifier);
00967 #endif
00968
00969 rtnl_lock();
00970
00971
00972
00973
00974
00975
00976 ieee80211_remove_interfaces(local);
00977
00978 rtnl_unlock();
00979
00980
00981
00982
00983
00984 del_timer_sync(&local->work_timer);
00985
00986 cancel_work_sync(&local->restart_work);
00987 cancel_work_sync(&local->reconfig_filter);
00988
00989 ieee80211_clear_tx_pending(local);
00990 rate_control_deinitialize(local);
00991
00992 if (skb_queue_len(&local->skb_queue) ||
00993 skb_queue_len(&local->skb_queue_unreliable))
00994 wiphy_warn(local->hw.wiphy, "skb_queue not empty\n");
00995 skb_queue_purge(&local->skb_queue);
00996 skb_queue_purge(&local->skb_queue_unreliable);
00997 skb_queue_purge(&local->rx_skb_queue);
00998
00999 destroy_workqueue(local->workqueue);
01000 wiphy_unregister(local->hw.wiphy);
01001 sta_info_stop(local);
01002 ieee80211_wep_free(local);
01003 ieee80211_led_exit(local);
01004 kfree(local->int_scan_req);
01005 }
01006 EXPORT_SYMBOL(ieee80211_unregister_hw);
01007
01008 void ieee80211_free_hw(struct ieee80211_hw *hw)
01009 {
01010 struct ieee80211_local *local = hw_to_local(hw);
01011
01012 mutex_destroy(&local->iflist_mtx);
01013 mutex_destroy(&local->mtx);
01014
01015 if (local->wiphy_ciphers_allocated)
01016 kfree(local->hw.wiphy->cipher_suites);
01017
01018 wiphy_free(local->hw.wiphy);
01019 }
01020 EXPORT_SYMBOL(ieee80211_free_hw);
01021
01022 static int __init ieee80211_init(void)
01023 {
01024 struct sk_buff *skb;
01025 int ret;
01026
01027 printk(KERN_INFO "*** MAC80211-RT-WMP Loading...\n");
01028
01029 BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
01030 BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
01031 IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
01032
01033 ret = rc80211_minstrel_init();
01034 if (ret)
01035 return ret;
01036
01037 ret = rc80211_minstrel_ht_init();
01038 if (ret)
01039 goto err_minstrel;
01040
01041 ret = rc80211_pid_init();
01042 if (ret)
01043 goto err_pid;
01044
01045 ret = ieee80211_iface_init();
01046 if (ret)
01047 goto err_netdev;
01048
01049 return 0;
01050 err_netdev:
01051 rc80211_pid_exit();
01052 err_pid:
01053 rc80211_minstrel_ht_exit();
01054 err_minstrel:
01055 rc80211_minstrel_exit();
01056
01057 return ret;
01058 }
01059
01060 static void __exit ieee80211_exit(void)
01061 {
01062 rc80211_pid_exit();
01063 rc80211_minstrel_ht_exit();
01064 rc80211_minstrel_exit();
01065
01066 if (mesh_allocated)
01067 ieee80211s_stop();
01068
01069 ieee80211_iface_exit();
01070
01071 rcu_barrier();
01072 }
01073
01074
01075 subsys_initcall(ieee80211_init);
01076 module_exit(ieee80211_exit);
01077
01078 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
01079 MODULE_LICENSE("GPL");