2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <net/mac80211.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/netdevice.h>
15 #include <linux/types.h>
16 #include <linux/slab.h>
17 #include <linux/skbuff.h>
18 #include <linux/etherdevice.h>
19 #include <linux/if_arp.h>
20 #include <linux/rtnetlink.h>
21 #include <linux/bitmap.h>
22 #include <linux/pm_qos.h>
23 #include <linux/inetdevice.h>
24 #include <net/net_namespace.h>
25 #include <net/cfg80211.h>
26 #include <net/addrconf.h>
28 #include "ieee80211_i.h"
29 #include "driver-ops.h"
37 void ieee80211_configure_filter(struct ieee80211_local *local)
40 unsigned int changed_flags;
41 unsigned int new_flags = 0;
43 if (atomic_read(&local->iff_promiscs))
44 new_flags |= FIF_PROMISC_IN_BSS;
46 if (atomic_read(&local->iff_allmultis))
47 new_flags |= FIF_ALLMULTI;
49 if (local->monitors || test_bit(SCAN_SW_SCANNING, &local->scanning) ||
50 test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning))
51 new_flags |= FIF_BCN_PRBRESP_PROMISC;
53 if (local->fif_probe_req || local->probe_req_reg)
54 new_flags |= FIF_PROBE_REQ;
56 if (local->fif_fcsfail)
57 new_flags |= FIF_FCSFAIL;
59 if (local->fif_plcpfail)
60 new_flags |= FIF_PLCPFAIL;
62 if (local->fif_control)
63 new_flags |= FIF_CONTROL;
65 if (local->fif_other_bss)
66 new_flags |= FIF_OTHER_BSS;
68 if (local->fif_pspoll)
69 new_flags |= FIF_PSPOLL;
71 spin_lock_bh(&local->filter_lock);
72 changed_flags = local->filter_flags ^ new_flags;
74 mc = drv_prepare_multicast(local, &local->mc_list);
75 spin_unlock_bh(&local->filter_lock);
80 drv_configure_filter(local, changed_flags, &new_flags, mc);
82 WARN_ON(new_flags & (1<<31));
84 local->filter_flags = new_flags & ~(1<<31);
87 static void ieee80211_reconfig_filter(struct work_struct *work)
89 struct ieee80211_local *local =
90 container_of(work, struct ieee80211_local, reconfig_filter);
92 ieee80211_configure_filter(local);
95 static u32 ieee80211_hw_conf_chan(struct ieee80211_local *local)
97 struct ieee80211_sub_if_data *sdata;
98 struct cfg80211_chan_def chandef = {};
103 offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
105 if (local->scan_chandef.chan) {
106 chandef = local->scan_chandef;
107 } else if (local->tmp_channel) {
108 chandef.chan = local->tmp_channel;
109 chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
110 chandef.center_freq1 = chandef.chan->center_freq;
112 chandef = local->_oper_chandef;
114 WARN(!cfg80211_chandef_valid(&chandef),
115 "control:%d MHz width:%d center: %d/%d MHz",
116 chandef.chan->center_freq, chandef.width,
117 chandef.center_freq1, chandef.center_freq2);
119 if (!cfg80211_chandef_identical(&chandef, &local->_oper_chandef))
120 local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
122 local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL;
124 offchannel_flag ^= local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
126 if (offchannel_flag ||
127 !cfg80211_chandef_identical(&local->hw.conf.chandef,
128 &local->_oper_chandef)) {
129 local->hw.conf.chandef = chandef;
130 changed |= IEEE80211_CONF_CHANGE_CHANNEL;
133 if (!conf_is_ht(&local->hw.conf)) {
135 * mac80211.h documents that this is only valid
136 * when the channel is set to an HT type, and
137 * that otherwise STATIC is used.
139 local->hw.conf.smps_mode = IEEE80211_SMPS_STATIC;
140 } else if (local->hw.conf.smps_mode != local->smps_mode) {
141 local->hw.conf.smps_mode = local->smps_mode;
142 changed |= IEEE80211_CONF_CHANGE_SMPS;
145 power = ieee80211_chandef_max_power(&chandef);
148 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
149 if (!rcu_access_pointer(sdata->vif.chanctx_conf))
151 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
153 power = min(power, sdata->vif.bss_conf.txpower);
157 if (local->hw.conf.power_level != power) {
158 changed |= IEEE80211_CONF_CHANGE_POWER;
159 local->hw.conf.power_level = power;
165 int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
171 if (!local->use_chanctx)
172 changed |= ieee80211_hw_conf_chan(local);
174 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
175 IEEE80211_CONF_CHANGE_POWER);
177 if (changed && local->open_count) {
178 ret = drv_config(local, changed);
181 * HW reconfiguration should never fail, the driver has told
182 * us what it can support so it should live up to that promise.
185 * rfkill is not integrated with mac80211 and a
186 * configuration command can thus fail if hardware rfkill
189 * FIXME: integrate rfkill with mac80211 and then add this
199 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
202 struct ieee80211_local *local = sdata->local;
204 if (!changed || sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
207 drv_bss_info_changed(local, sdata, &sdata->vif.bss_conf, changed);
210 u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
212 sdata->vif.bss_conf.use_cts_prot = false;
213 sdata->vif.bss_conf.use_short_preamble = false;
214 sdata->vif.bss_conf.use_short_slot = false;
215 return BSS_CHANGED_ERP_CTS_PROT |
216 BSS_CHANGED_ERP_PREAMBLE |
217 BSS_CHANGED_ERP_SLOT;
220 static void ieee80211_tasklet_handler(unsigned long data)
222 struct ieee80211_local *local = (struct ieee80211_local *) data;
225 while ((skb = skb_dequeue(&local->skb_queue)) ||
226 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
227 switch (skb->pkt_type) {
228 case IEEE80211_RX_MSG:
229 /* Clear skb->pkt_type in order to not confuse kernel
232 ieee80211_rx(&local->hw, skb);
234 case IEEE80211_TX_STATUS_MSG:
236 ieee80211_tx_status(&local->hw, skb);
239 WARN(1, "mac80211: Packet is of unknown type %d\n",
247 static void ieee80211_restart_work(struct work_struct *work)
249 struct ieee80211_local *local =
250 container_of(work, struct ieee80211_local, restart_work);
251 struct ieee80211_sub_if_data *sdata;
253 /* wait for scan work complete */
254 flush_workqueue(local->workqueue);
256 WARN(test_bit(SCAN_HW_SCANNING, &local->scanning),
257 "%s called with hardware scan in progress\n", __func__);
260 list_for_each_entry(sdata, &local->interfaces, list)
261 flush_delayed_work(&sdata->dec_tailroom_needed_wk);
262 ieee80211_scan_cancel(local);
263 ieee80211_reconfig(local);
267 void ieee80211_restart_hw(struct ieee80211_hw *hw)
269 struct ieee80211_local *local = hw_to_local(hw);
271 trace_api_restart_hw(local);
273 wiphy_info(hw->wiphy,
274 "Hardware restart was requested\n");
276 /* use this reason, ieee80211_reconfig will unblock it */
277 ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
278 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
281 * Stop all Rx during the reconfig. We don't want state changes
282 * or driver callbacks while this is in progress.
284 local->in_reconfig = true;
287 schedule_work(&local->restart_work);
289 EXPORT_SYMBOL(ieee80211_restart_hw);
292 static int ieee80211_ifa_changed(struct notifier_block *nb,
293 unsigned long data, void *arg)
295 struct in_ifaddr *ifa = arg;
296 struct ieee80211_local *local =
297 container_of(nb, struct ieee80211_local,
299 struct net_device *ndev = ifa->ifa_dev->dev;
300 struct wireless_dev *wdev = ndev->ieee80211_ptr;
301 struct in_device *idev;
302 struct ieee80211_sub_if_data *sdata;
303 struct ieee80211_bss_conf *bss_conf;
304 struct ieee80211_if_managed *ifmgd;
307 /* Make sure it's our interface that got changed */
311 if (wdev->wiphy != local->hw.wiphy)
314 sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
315 bss_conf = &sdata->vif.bss_conf;
317 /* ARP filtering is only supported in managed mode */
318 if (sdata->vif.type != NL80211_IFTYPE_STATION)
321 idev = __in_dev_get_rtnl(sdata->dev);
325 ifmgd = &sdata->u.mgd;
328 /* Copy the addresses to the bss_conf list */
329 ifa = idev->ifa_list;
331 if (c < IEEE80211_BSS_ARP_ADDR_LIST_LEN)
332 bss_conf->arp_addr_list[c] = ifa->ifa_address;
337 bss_conf->arp_addr_cnt = c;
339 /* Configure driver only if associated (which also implies it is up) */
340 if (ifmgd->associated)
341 ieee80211_bss_info_change_notify(sdata,
342 BSS_CHANGED_ARP_FILTER);
350 #if IS_ENABLED(CONFIG_IPV6)
351 static int ieee80211_ifa6_changed(struct notifier_block *nb,
352 unsigned long data, void *arg)
354 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)arg;
355 struct inet6_dev *idev = ifa->idev;
356 struct net_device *ndev = ifa->idev->dev;
357 struct ieee80211_local *local =
358 container_of(nb, struct ieee80211_local, ifa6_notifier);
359 struct wireless_dev *wdev = ndev->ieee80211_ptr;
360 struct ieee80211_sub_if_data *sdata;
362 /* Make sure it's our interface that got changed */
363 if (!wdev || wdev->wiphy != local->hw.wiphy)
366 sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
369 * For now only support station mode. This is mostly because
370 * doing AP would have to handle AP_VLAN in some way ...
372 if (sdata->vif.type != NL80211_IFTYPE_STATION)
375 drv_ipv6_addr_change(local, sdata, idev);
381 /* There isn't a lot of sense in it, but you can transmit anything you like */
382 static const struct ieee80211_txrx_stypes
383 ieee80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
384 [NL80211_IFTYPE_ADHOC] = {
386 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
387 BIT(IEEE80211_STYPE_AUTH >> 4) |
388 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
389 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
391 [NL80211_IFTYPE_STATION] = {
393 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
394 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
396 [NL80211_IFTYPE_AP] = {
398 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
399 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
400 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
401 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
402 BIT(IEEE80211_STYPE_AUTH >> 4) |
403 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
404 BIT(IEEE80211_STYPE_ACTION >> 4),
406 [NL80211_IFTYPE_AP_VLAN] = {
409 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
410 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
411 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
412 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
413 BIT(IEEE80211_STYPE_AUTH >> 4) |
414 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
415 BIT(IEEE80211_STYPE_ACTION >> 4),
417 [NL80211_IFTYPE_P2P_CLIENT] = {
419 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
420 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
422 [NL80211_IFTYPE_P2P_GO] = {
424 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
425 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
426 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
427 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
428 BIT(IEEE80211_STYPE_AUTH >> 4) |
429 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
430 BIT(IEEE80211_STYPE_ACTION >> 4),
432 [NL80211_IFTYPE_MESH_POINT] = {
434 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
435 BIT(IEEE80211_STYPE_AUTH >> 4) |
436 BIT(IEEE80211_STYPE_DEAUTH >> 4),
438 [NL80211_IFTYPE_P2P_DEVICE] = {
440 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
441 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
445 static const struct ieee80211_ht_cap mac80211_ht_capa_mod_mask = {
446 .ampdu_params_info = IEEE80211_HT_AMPDU_PARM_FACTOR |
447 IEEE80211_HT_AMPDU_PARM_DENSITY,
449 .cap_info = cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
450 IEEE80211_HT_CAP_MAX_AMSDU |
451 IEEE80211_HT_CAP_SGI_20 |
452 IEEE80211_HT_CAP_SGI_40 |
453 IEEE80211_HT_CAP_LDPC_CODING |
454 IEEE80211_HT_CAP_40MHZ_INTOLERANT),
456 .rx_mask = { 0xff, 0xff, 0xff, 0xff, 0xff,
457 0xff, 0xff, 0xff, 0xff, 0xff, },
461 static const struct ieee80211_vht_cap mac80211_vht_capa_mod_mask = {
463 cpu_to_le32(IEEE80211_VHT_CAP_RXLDPC |
464 IEEE80211_VHT_CAP_SHORT_GI_80 |
465 IEEE80211_VHT_CAP_SHORT_GI_160 |
466 IEEE80211_VHT_CAP_RXSTBC_1 |
467 IEEE80211_VHT_CAP_RXSTBC_2 |
468 IEEE80211_VHT_CAP_RXSTBC_3 |
469 IEEE80211_VHT_CAP_RXSTBC_4 |
470 IEEE80211_VHT_CAP_TXSTBC |
471 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
472 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
473 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
474 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
475 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK),
477 .rx_mcs_map = cpu_to_le16(~0),
478 .tx_mcs_map = cpu_to_le16(~0),
482 static const u8 extended_capabilities[] = {
484 WLAN_EXT_CAPA8_OPMODE_NOTIF,
487 struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
488 const struct ieee80211_ops *ops)
490 struct ieee80211_local *local;
495 if (WARN_ON(!ops->tx || !ops->start || !ops->stop || !ops->config ||
496 !ops->add_interface || !ops->remove_interface ||
497 !ops->configure_filter))
500 if (WARN_ON(ops->sta_state && (ops->sta_add || ops->sta_remove)))
503 /* check all or no channel context operations exist */
504 i = !!ops->add_chanctx + !!ops->remove_chanctx +
505 !!ops->change_chanctx + !!ops->assign_vif_chanctx +
506 !!ops->unassign_vif_chanctx;
507 if (WARN_ON(i != 0 && i != 5))
509 use_chanctx = i == 5;
511 /* Ensure 32-byte alignment of our private data and hw private data.
512 * We use the wiphy priv data for both our ieee80211_local and for
513 * the driver's private data
515 * In memory it'll be like this:
517 * +-------------------------+
519 * +-------------------------+
520 * | struct ieee80211_local |
521 * +-------------------------+
522 * | driver's private data |
523 * +-------------------------+
526 priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
528 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
533 wiphy->mgmt_stypes = ieee80211_default_mgmt_stypes;
535 wiphy->privid = mac80211_wiphy_privid;
537 wiphy->flags |= WIPHY_FLAG_NETNS_OK |
538 WIPHY_FLAG_4ADDR_AP |
539 WIPHY_FLAG_4ADDR_STATION |
540 WIPHY_FLAG_REPORTS_OBSS |
541 WIPHY_FLAG_OFFCHAN_TX;
543 wiphy->extended_capabilities = extended_capabilities;
544 wiphy->extended_capabilities_mask = extended_capabilities;
545 wiphy->extended_capabilities_len = ARRAY_SIZE(extended_capabilities);
547 if (ops->remain_on_channel)
548 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
550 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS |
551 NL80211_FEATURE_SAE |
552 NL80211_FEATURE_HT_IBSS |
553 NL80211_FEATURE_VIF_TXPOWER |
554 NL80211_FEATURE_USERSPACE_MPM;
557 wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN |
558 NL80211_FEATURE_AP_SCAN;
562 wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
564 wiphy->bss_priv_size = sizeof(struct ieee80211_bss);
566 local = wiphy_priv(wiphy);
568 local->hw.wiphy = wiphy;
570 local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
573 local->use_chanctx = use_chanctx;
575 /* set up some defaults */
576 local->hw.queues = 1;
577 local->hw.max_rates = 1;
578 local->hw.max_report_rates = 0;
579 local->hw.max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
580 local->hw.max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
581 local->hw.offchannel_tx_hw_queue = IEEE80211_INVAL_HW_QUEUE;
582 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
583 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
584 local->hw.radiotap_mcs_details = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
585 IEEE80211_RADIOTAP_MCS_HAVE_GI |
586 IEEE80211_RADIOTAP_MCS_HAVE_BW;
587 local->hw.radiotap_vht_details = IEEE80211_RADIOTAP_VHT_KNOWN_GI |
588 IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
589 local->hw.uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
590 local->hw.uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
591 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
592 wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask;
593 wiphy->vht_capa_mod_mask = &mac80211_vht_capa_mod_mask;
595 INIT_LIST_HEAD(&local->interfaces);
597 __hw_addr_init(&local->mc_list);
599 mutex_init(&local->iflist_mtx);
600 mutex_init(&local->mtx);
602 mutex_init(&local->key_mtx);
603 spin_lock_init(&local->filter_lock);
604 spin_lock_init(&local->rx_path_lock);
605 spin_lock_init(&local->queue_stop_reason_lock);
607 INIT_LIST_HEAD(&local->chanctx_list);
608 mutex_init(&local->chanctx_mtx);
610 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
612 INIT_WORK(&local->restart_work, ieee80211_restart_work);
614 INIT_WORK(&local->radar_detected_work,
615 ieee80211_dfs_radar_detected_work);
617 INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter);
618 local->smps_mode = IEEE80211_SMPS_OFF;
620 INIT_WORK(&local->dynamic_ps_enable_work,
621 ieee80211_dynamic_ps_enable_work);
622 INIT_WORK(&local->dynamic_ps_disable_work,
623 ieee80211_dynamic_ps_disable_work);
624 setup_timer(&local->dynamic_ps_timer,
625 ieee80211_dynamic_ps_timer, (unsigned long) local);
627 INIT_WORK(&local->sched_scan_stopped_work,
628 ieee80211_sched_scan_stopped_work);
630 spin_lock_init(&local->ack_status_lock);
631 idr_init(&local->ack_status_frames);
633 sta_info_init(local);
635 for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
636 skb_queue_head_init(&local->pending[i]);
637 atomic_set(&local->agg_queue_stop[i], 0);
639 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
640 (unsigned long)local);
642 tasklet_init(&local->tasklet,
643 ieee80211_tasklet_handler,
644 (unsigned long) local);
646 skb_queue_head_init(&local->skb_queue);
647 skb_queue_head_init(&local->skb_queue_unreliable);
649 ieee80211_led_names(local);
651 ieee80211_roc_setup(local);
655 EXPORT_SYMBOL(ieee80211_alloc_hw);
657 static int ieee80211_init_cipher_suites(struct ieee80211_local *local)
659 bool have_wep = !(IS_ERR(local->wep_tx_tfm) ||
660 IS_ERR(local->wep_rx_tfm));
661 bool have_mfp = local->hw.flags & IEEE80211_HW_MFP_CAPABLE;
662 const struct ieee80211_cipher_scheme *cs = local->hw.cipher_schemes;
663 int n_suites = 0, r = 0, w = 0;
665 static const u32 cipher_suites[] = {
666 /* keep WEP first, it may be removed below */
667 WLAN_CIPHER_SUITE_WEP40,
668 WLAN_CIPHER_SUITE_WEP104,
669 WLAN_CIPHER_SUITE_TKIP,
670 WLAN_CIPHER_SUITE_CCMP,
672 /* keep last -- depends on hw flags! */
673 WLAN_CIPHER_SUITE_AES_CMAC
676 /* Driver specifies the ciphers, we have nothing to do... */
677 if (local->hw.wiphy->cipher_suites && have_wep)
680 /* Set up cipher suites if driver relies on mac80211 cipher defs */
681 if (!local->hw.wiphy->cipher_suites && !cs) {
682 local->hw.wiphy->cipher_suites = cipher_suites;
683 local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
686 local->hw.wiphy->n_cipher_suites--;
689 local->hw.wiphy->cipher_suites += 2;
690 local->hw.wiphy->n_cipher_suites -= 2;
696 if (!local->hw.wiphy->cipher_suites) {
698 * Driver specifies cipher schemes only
699 * We start counting ciphers defined by schemes, TKIP and CCMP
701 n_suites = local->hw.n_cipher_schemes + 2;
703 /* check if we have WEP40 and WEP104 */
707 /* check if we have AES_CMAC */
711 suites = kmalloc(sizeof(u32) * n_suites, GFP_KERNEL);
715 suites[w++] = WLAN_CIPHER_SUITE_CCMP;
716 suites[w++] = WLAN_CIPHER_SUITE_TKIP;
719 suites[w++] = WLAN_CIPHER_SUITE_WEP40;
720 suites[w++] = WLAN_CIPHER_SUITE_WEP104;
724 suites[w++] = WLAN_CIPHER_SUITE_AES_CMAC;
726 for (r = 0; r < local->hw.n_cipher_schemes; r++)
727 suites[w++] = cs[r].cipher;
729 /* Driver provides cipher suites, but we need to exclude WEP */
730 suites = kmemdup(local->hw.wiphy->cipher_suites,
731 sizeof(u32) * local->hw.wiphy->n_cipher_suites,
736 for (r = 0; r < local->hw.wiphy->n_cipher_suites; r++) {
737 u32 suite = local->hw.wiphy->cipher_suites[r];
739 if (suite == WLAN_CIPHER_SUITE_WEP40 ||
740 suite == WLAN_CIPHER_SUITE_WEP104)
746 local->hw.wiphy->cipher_suites = suites;
747 local->hw.wiphy->n_cipher_suites = w;
748 local->wiphy_ciphers_allocated = true;
753 int ieee80211_register_hw(struct ieee80211_hw *hw)
755 struct ieee80211_local *local = hw_to_local(hw);
757 enum ieee80211_band band;
758 int channels, max_bitrates;
759 bool supp_ht, supp_vht;
760 netdev_features_t feature_whitelist;
761 struct cfg80211_chan_def dflt_chandef = {};
763 if (hw->flags & IEEE80211_HW_QUEUE_CONTROL &&
764 (local->hw.offchannel_tx_hw_queue == IEEE80211_INVAL_HW_QUEUE ||
765 local->hw.offchannel_tx_hw_queue >= local->hw.queues))
769 if (hw->wiphy->wowlan && (!local->ops->suspend || !local->ops->resume))
773 if (!local->use_chanctx) {
774 for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
775 const struct ieee80211_iface_combination *comb;
777 comb = &local->hw.wiphy->iface_combinations[i];
779 if (comb->num_different_channels > 1)
784 * WDS is currently prohibited when channel contexts are used
785 * because there's no clear definition of which channel WDS
786 * type interfaces use
788 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_WDS))
791 /* DFS currently not supported with channel context drivers */
792 for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
793 const struct ieee80211_iface_combination *comb;
795 comb = &local->hw.wiphy->iface_combinations[i];
797 if (comb->radar_detect_widths)
802 /* Only HW csum features are currently compatible with mac80211 */
803 feature_whitelist = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
805 if (WARN_ON(hw->netdev_features & ~feature_whitelist))
808 if (hw->max_report_rates == 0)
809 hw->max_report_rates = hw->max_rates;
811 local->rx_chains = 1;
814 * generic code guarantees at least one band,
815 * set this very early because much code assumes
816 * that hw.conf.channel is assigned
822 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
823 struct ieee80211_supported_band *sband;
825 sband = local->hw.wiphy->bands[band];
829 if (!dflt_chandef.chan) {
830 cfg80211_chandef_create(&dflt_chandef,
833 /* init channel we're on */
834 if (!local->use_chanctx && !local->_oper_chandef.chan) {
835 local->hw.conf.chandef = dflt_chandef;
836 local->_oper_chandef = dflt_chandef;
838 local->monitor_chandef = dflt_chandef;
841 channels += sband->n_channels;
843 if (max_bitrates < sband->n_bitrates)
844 max_bitrates = sband->n_bitrates;
845 supp_ht = supp_ht || sband->ht_cap.ht_supported;
846 supp_vht = supp_vht || sband->vht_cap.vht_supported;
848 if (sband->ht_cap.ht_supported)
850 max(ieee80211_mcs_to_chains(&sband->ht_cap.mcs),
853 /* TODO: consider VHT for RX chains, hopefully it's the same */
856 /* if low-level driver supports AP, we also support VLAN */
857 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
858 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
859 hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
862 /* mac80211 always supports monitor */
863 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
864 hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
866 /* mac80211 doesn't support more than one IBSS interface right now */
867 for (i = 0; i < hw->wiphy->n_iface_combinations; i++) {
868 const struct ieee80211_iface_combination *c;
871 c = &hw->wiphy->iface_combinations[i];
873 for (j = 0; j < c->n_limits; j++)
874 if ((c->limits[j].types & BIT(NL80211_IFTYPE_ADHOC)) &&
875 c->limits[j].max > 1)
879 local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) +
880 sizeof(void *) * channels, GFP_KERNEL);
881 if (!local->int_scan_req)
884 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
885 if (!local->hw.wiphy->bands[band])
887 local->int_scan_req->rates[band] = (u32) -1;
890 #ifndef CONFIG_MAC80211_MESH
891 /* mesh depends on Kconfig, but drivers should set it if they want */
892 local->hw.wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MESH_POINT);
895 /* if the underlying driver supports mesh, mac80211 will (at least)
896 * provide routing of mesh authentication frames to userspace */
897 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
898 local->hw.wiphy->flags |= WIPHY_FLAG_MESH_AUTH;
900 /* mac80211 supports control port protocol changing */
901 local->hw.wiphy->flags |= WIPHY_FLAG_CONTROL_PORT_PROTOCOL;
903 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
904 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
905 } else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
906 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
907 if (hw->max_signal <= 0) {
909 goto fail_wiphy_register;
913 WARN((local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
914 && (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK),
915 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n");
918 * Calculate scan IE length -- we need this to alloc
919 * memory and to subtract from the driver limit. It
920 * includes the DS Params, (extended) supported rates, and HT
921 * information -- SSID is the driver's responsibility.
923 local->scan_ies_len = 4 + max_bitrates /* (ext) supp rates */ +
926 local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
929 local->scan_ies_len +=
930 2 + sizeof(struct ieee80211_vht_cap);
932 if (!local->ops->hw_scan) {
933 /* For hw_scan, driver needs to set these up. */
934 local->hw.wiphy->max_scan_ssids = 4;
935 local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
939 * If the driver supports any scan IEs, then assume the
940 * limit includes the IEs mac80211 will add, otherwise
941 * leave it at zero and let the driver sort it out; we
942 * still pass our IEs to the driver but userspace will
943 * not be allowed to in that case.
945 if (local->hw.wiphy->max_scan_ie_len)
946 local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
948 WARN_ON(!ieee80211_cs_list_valid(local->hw.cipher_schemes,
949 local->hw.n_cipher_schemes));
951 result = ieee80211_init_cipher_suites(local);
953 goto fail_wiphy_register;
955 if (!local->ops->remain_on_channel)
956 local->hw.wiphy->max_remain_on_channel_duration = 5000;
958 /* mac80211 based drivers don't support internal TDLS setup */
959 if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)
960 local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
962 local->hw.wiphy->max_num_csa_counters = IEEE80211_MAX_CSA_COUNTERS_NUM;
964 result = wiphy_register(local->hw.wiphy);
966 goto fail_wiphy_register;
969 * We use the number of queues for feature tests (QoS, HT) internally
970 * so restrict them appropriately.
972 if (hw->queues > IEEE80211_MAX_QUEUES)
973 hw->queues = IEEE80211_MAX_QUEUES;
976 alloc_ordered_workqueue("%s", 0, wiphy_name(local->hw.wiphy));
977 if (!local->workqueue) {
983 * The hardware needs headroom for sending the frame,
984 * and we need some headroom for passing the frame to monitor
985 * interfaces, but never both at the same time.
987 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
988 IEEE80211_TX_STATUS_HEADROOM);
990 debugfs_hw_add(local);
993 * if the driver doesn't specify a max listen interval we
994 * use 5 which should be a safe default
996 if (local->hw.max_listen_interval == 0)
997 local->hw.max_listen_interval = 5;
999 local->hw.conf.listen_interval = local->hw.max_listen_interval;
1001 local->dynamic_ps_forced_timeout = -1;
1003 result = ieee80211_wep_init(local);
1005 wiphy_debug(local->hw.wiphy, "Failed to initialize wep: %d\n",
1008 local->hw.conf.flags = IEEE80211_CONF_IDLE;
1010 ieee80211_led_init(local);
1014 result = ieee80211_init_rate_ctrl_alg(local,
1015 hw->rate_control_algorithm);
1017 wiphy_debug(local->hw.wiphy,
1018 "Failed to initialize rate control algorithm\n");
1022 /* add one default STA interface if supported */
1023 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION)) {
1024 result = ieee80211_if_add(local, "wlan%d", NULL,
1025 NL80211_IFTYPE_STATION, NULL);
1027 wiphy_warn(local->hw.wiphy,
1028 "Failed to add default virtual iface\n");
1033 local->network_latency_notifier.notifier_call =
1034 ieee80211_max_network_latency;
1035 result = pm_qos_add_notifier(PM_QOS_NETWORK_LATENCY,
1036 &local->network_latency_notifier);
1043 local->ifa_notifier.notifier_call = ieee80211_ifa_changed;
1044 result = register_inetaddr_notifier(&local->ifa_notifier);
1049 #if IS_ENABLED(CONFIG_IPV6)
1050 local->ifa6_notifier.notifier_call = ieee80211_ifa6_changed;
1051 result = register_inet6addr_notifier(&local->ifa6_notifier);
1058 #if IS_ENABLED(CONFIG_IPV6)
1061 unregister_inetaddr_notifier(&local->ifa_notifier);
1064 #if defined(CONFIG_INET) || defined(CONFIG_IPV6)
1066 pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
1067 &local->network_latency_notifier);
1071 ieee80211_led_exit(local);
1072 ieee80211_remove_interfaces(local);
1075 ieee80211_wep_free(local);
1076 sta_info_stop(local);
1077 destroy_workqueue(local->workqueue);
1079 wiphy_unregister(local->hw.wiphy);
1080 fail_wiphy_register:
1081 if (local->wiphy_ciphers_allocated)
1082 kfree(local->hw.wiphy->cipher_suites);
1083 kfree(local->int_scan_req);
1086 EXPORT_SYMBOL(ieee80211_register_hw);
1088 void ieee80211_napi_add(struct ieee80211_hw *hw, struct napi_struct *napi,
1089 struct net_device *napi_dev,
1090 int (*poll)(struct napi_struct *, int),
1093 struct ieee80211_local *local = hw_to_local(hw);
1095 netif_napi_add(napi_dev, napi, poll, weight);
1098 EXPORT_SYMBOL_GPL(ieee80211_napi_add);
1100 void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1102 struct ieee80211_local *local = hw_to_local(hw);
1104 tasklet_kill(&local->tx_pending_tasklet);
1105 tasklet_kill(&local->tasklet);
1107 pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
1108 &local->network_latency_notifier);
1110 unregister_inetaddr_notifier(&local->ifa_notifier);
1112 #if IS_ENABLED(CONFIG_IPV6)
1113 unregister_inet6addr_notifier(&local->ifa6_notifier);
1119 * At this point, interface list manipulations are fine
1120 * because the driver cannot be handing us frames any
1121 * more and the tasklet is killed.
1123 ieee80211_remove_interfaces(local);
1127 cancel_work_sync(&local->restart_work);
1128 cancel_work_sync(&local->reconfig_filter);
1129 flush_work(&local->sched_scan_stopped_work);
1131 ieee80211_clear_tx_pending(local);
1132 rate_control_deinitialize(local);
1134 if (skb_queue_len(&local->skb_queue) ||
1135 skb_queue_len(&local->skb_queue_unreliable))
1136 wiphy_warn(local->hw.wiphy, "skb_queue not empty\n");
1137 skb_queue_purge(&local->skb_queue);
1138 skb_queue_purge(&local->skb_queue_unreliable);
1140 destroy_workqueue(local->workqueue);
1141 wiphy_unregister(local->hw.wiphy);
1142 sta_info_stop(local);
1143 ieee80211_wep_free(local);
1144 ieee80211_led_exit(local);
1145 kfree(local->int_scan_req);
1147 EXPORT_SYMBOL(ieee80211_unregister_hw);
1149 static int ieee80211_free_ack_frame(int id, void *p, void *data)
1151 WARN_ONCE(1, "Have pending ack frames!\n");
1156 void ieee80211_free_hw(struct ieee80211_hw *hw)
1158 struct ieee80211_local *local = hw_to_local(hw);
1160 mutex_destroy(&local->iflist_mtx);
1161 mutex_destroy(&local->mtx);
1163 if (local->wiphy_ciphers_allocated)
1164 kfree(local->hw.wiphy->cipher_suites);
1166 idr_for_each(&local->ack_status_frames,
1167 ieee80211_free_ack_frame, NULL);
1168 idr_destroy(&local->ack_status_frames);
1170 kfree(rcu_access_pointer(local->tx_latency));
1172 wiphy_free(local->hw.wiphy);
1174 EXPORT_SYMBOL(ieee80211_free_hw);
1176 static int __init ieee80211_init(void)
1178 struct sk_buff *skb;
1181 BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
1182 BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
1183 IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
1185 ret = rc80211_minstrel_init();
1189 ret = rc80211_minstrel_ht_init();
1193 ret = rc80211_pid_init();
1197 ret = ieee80211_iface_init();
1205 rc80211_minstrel_ht_exit();
1207 rc80211_minstrel_exit();
1212 static void __exit ieee80211_exit(void)
1215 rc80211_minstrel_ht_exit();
1216 rc80211_minstrel_exit();
1220 ieee80211_iface_exit();
1226 subsys_initcall(ieee80211_init);
1227 module_exit(ieee80211_exit);
1229 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1230 MODULE_LICENSE("GPL");