hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/net/mac80211/main.c
....@@ -1,17 +1,16 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright 2002-2005, Instant802 Networks, Inc.
34 * Copyright 2005-2006, Devicescape Software, Inc.
45 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
56 * Copyright 2013-2014 Intel Mobile Communications GmbH
67 * Copyright (C) 2017 Intel Deutschland GmbH
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
8
+ * Copyright (C) 2018 - 2019 Intel Corporation
119 */
1210
1311 #include <net/mac80211.h>
1412 #include <linux/module.h>
13
+#include <linux/fips.h>
1514 #include <linux/init.h>
1615 #include <linux/netdevice.h>
1716 #include <linux/types.h>
....@@ -65,6 +64,9 @@
6564 if (local->fif_pspoll)
6665 new_flags |= FIF_PSPOLL;
6766
67
+ if (local->rx_mcast_action_reg)
68
+ new_flags |= FIF_MCAST_ACTION;
69
+
6870 spin_lock_bh(&local->filter_lock);
6971 changed_flags = local->filter_flags ^ new_flags;
7072
....@@ -105,13 +107,15 @@
105107 chandef.chan = local->tmp_channel;
106108 chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
107109 chandef.center_freq1 = chandef.chan->center_freq;
110
+ chandef.freq1_offset = chandef.chan->freq_offset;
108111 } else
109112 chandef = local->_oper_chandef;
110113
111114 WARN(!cfg80211_chandef_valid(&chandef),
112
- "control:%d MHz width:%d center: %d/%d MHz",
113
- chandef.chan->center_freq, chandef.width,
114
- chandef.center_freq1, chandef.center_freq2);
115
+ "control:%d.%03d MHz width:%d center: %d.%03d/%d MHz",
116
+ chandef.chan->center_freq, chandef.chan->freq_offset,
117
+ chandef.width, chandef.center_freq1, chandef.freq1_offset,
118
+ chandef.center_freq2);
115119
116120 if (!cfg80211_chandef_identical(&chandef, &local->_oper_chandef))
117121 local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
....@@ -146,6 +150,8 @@
146150 if (!rcu_access_pointer(sdata->vif.chanctx_conf))
147151 continue;
148152 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
153
+ continue;
154
+ if (sdata->vif.bss_conf.txpower == INT_MIN)
149155 continue;
150156 power = min(power, sdata->vif.bss_conf.txpower);
151157 }
....@@ -353,11 +359,11 @@
353359 sdata_lock(sdata);
354360
355361 /* Copy the addresses to the bss_conf list */
356
- ifa = idev->ifa_list;
362
+ ifa = rtnl_dereference(idev->ifa_list);
357363 while (ifa) {
358364 if (c < IEEE80211_BSS_ARP_ADDR_LIST_LEN)
359365 bss_conf->arp_addr_list[c] = ifa->ifa_address;
360
- ifa = ifa->ifa_next;
366
+ ifa = rtnl_dereference(ifa->ifa_next);
361367 c++;
362368 }
363369
....@@ -417,7 +423,20 @@
417423 },
418424 [NL80211_IFTYPE_STATION] = {
419425 .tx = 0xffff,
426
+ /*
427
+ * To support Pre Association Security Negotiation (PASN) while
428
+ * already associated to one AP, allow user space to register to
429
+ * Rx authentication frames, so that the user space logic would
430
+ * be able to receive/handle authentication frames from a
431
+ * different AP as part of PASN.
432
+ * It is expected that user space would intelligently register
433
+ * for Rx authentication frames, i.e., only when PASN is used
434
+ * and configure a match filter only for PASN authentication
435
+ * algorithm, as otherwise the MLME functionality of mac80211
436
+ * would be broken.
437
+ */
420438 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
439
+ BIT(IEEE80211_STYPE_AUTH >> 4) |
421440 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
422441 },
423442 [NL80211_IFTYPE_AP] = {
....@@ -477,6 +496,8 @@
477496 IEEE80211_HT_CAP_MAX_AMSDU |
478497 IEEE80211_HT_CAP_SGI_20 |
479498 IEEE80211_HT_CAP_SGI_40 |
499
+ IEEE80211_HT_CAP_TX_STBC |
500
+ IEEE80211_HT_CAP_RX_STBC |
480501 IEEE80211_HT_CAP_LDPC_CODING |
481502 IEEE80211_HT_CAP_40MHZ_INTOLERANT),
482503 .mcs = {
....@@ -560,7 +581,7 @@
560581 WIPHY_FLAG_REPORTS_OBSS |
561582 WIPHY_FLAG_OFFCHAN_TX;
562583
563
- if (ops->remain_on_channel)
584
+ if (!use_chanctx || ops->remain_on_channel)
564585 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
565586
566587 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS |
....@@ -573,6 +594,12 @@
573594 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_FILS_STA);
574595 wiphy_ext_feature_set(wiphy,
575596 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211);
597
+ wiphy_ext_feature_set(wiphy,
598
+ NL80211_EXT_FEATURE_CONTROL_PORT_NO_PREAUTH);
599
+ wiphy_ext_feature_set(wiphy,
600
+ NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211_TX_STATUS);
601
+ wiphy_ext_feature_set(wiphy,
602
+ NL80211_EXT_FEATURE_SCAN_FREQ_KHZ);
576603
577604 if (!ops->hw_scan) {
578605 wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN |
....@@ -610,6 +637,18 @@
610637 local->ops = ops;
611638 local->use_chanctx = use_chanctx;
612639
640
+ /*
641
+ * We need a bit of data queued to build aggregates properly, so
642
+ * instruct the TCP stack to allow more than a single ms of data
643
+ * to be queued in the stack. The value is a bit-shift of 1
644
+ * second, so 7 is ~8ms of queued data. Only affects local TCP
645
+ * sockets.
646
+ * This is the default, anyhow - drivers may need to override it
647
+ * for local reasons (longer buffers, longer completion time, or
648
+ * similar).
649
+ */
650
+ local->hw.tx_sk_pacing_shift = 7;
651
+
613652 /* set up some defaults */
614653 local->hw.queues = 1;
615654 local->hw.max_rates = 1;
....@@ -626,6 +665,7 @@
626665 IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
627666 local->hw.uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
628667 local->hw.uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
668
+ local->hw.max_mtu = IEEE80211_MAX_DATA_LEN;
629669 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
630670 wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask;
631671 wiphy->vht_capa_mod_mask = &mac80211_vht_capa_mod_mask;
....@@ -649,6 +689,18 @@
649689 spin_lock_init(&local->filter_lock);
650690 spin_lock_init(&local->rx_path_lock);
651691 spin_lock_init(&local->queue_stop_reason_lock);
692
+
693
+ for (i = 0; i < IEEE80211_NUM_ACS; i++) {
694
+ INIT_LIST_HEAD(&local->active_txqs[i]);
695
+ spin_lock_init(&local->active_txq_lock[i]);
696
+ local->aql_txq_limit_low[i] = IEEE80211_DEFAULT_AQL_TXQ_LIMIT_L;
697
+ local->aql_txq_limit_high[i] =
698
+ IEEE80211_DEFAULT_AQL_TXQ_LIMIT_H;
699
+ }
700
+
701
+ local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX;
702
+ local->aql_threshold = IEEE80211_AQL_THRESHOLD;
703
+ atomic_set(&local->aql_total_pending_airtime, 0);
652704
653705 INIT_LIST_HEAD(&local->chanctx_list);
654706 mutex_init(&local->chanctx_mtx);
....@@ -684,6 +736,10 @@
684736 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
685737 (unsigned long)local);
686738
739
+ if (ops->wake_tx_queue)
740
+ tasklet_init(&local->wake_txqs_tasklet, ieee80211_wake_txqs,
741
+ (unsigned long)local);
742
+
687743 tasklet_init(&local->tasklet,
688744 ieee80211_tasklet_handler,
689745 (unsigned long) local);
....@@ -708,8 +764,7 @@
708764
709765 static int ieee80211_init_cipher_suites(struct ieee80211_local *local)
710766 {
711
- bool have_wep = !(IS_ERR(local->wep_tx_tfm) ||
712
- IS_ERR(local->wep_rx_tfm));
767
+ bool have_wep = !fips_enabled; /* FIPS does not permit the use of RC4 */
713768 bool have_mfp = ieee80211_hw_check(&local->hw, MFP_CAPABLE);
714769 int n_suites = 0, r = 0, w = 0;
715770 u32 *suites;
....@@ -843,7 +898,6 @@
843898 enum nl80211_band band;
844899 int channels, max_bitrates;
845900 bool supp_ht, supp_vht, supp_he;
846
- netdev_features_t feature_whitelist;
847901 struct cfg80211_chan_def dflt_chandef = {};
848902
849903 if (ieee80211_hw_check(hw, QUEUE_CONTROL) &&
....@@ -902,10 +956,7 @@
902956 }
903957
904958 /* Only HW csum features are currently compatible with mac80211 */
905
- feature_whitelist = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
906
- NETIF_F_HW_CSUM | NETIF_F_SG | NETIF_F_HIGHDMA |
907
- NETIF_F_GSO_SOFTWARE | NETIF_F_RXCSUM;
908
- if (WARN_ON(hw->netdev_features & ~feature_whitelist))
959
+ if (WARN_ON(hw->netdev_features & ~MAC80211_SUPPORTED_FEATURES))
909960 return -EINVAL;
910961
911962 if (hw->max_report_rates == 0)
....@@ -962,6 +1013,11 @@
9621013
9631014 if (!supp_he)
9641015 supp_he = !!ieee80211_get_he_sta_cap(sband);
1016
+
1017
+ /* HT, VHT, HE require QoS, thus >= 4 queues */
1018
+ if (WARN_ON(local->hw.queues < IEEE80211_NUM_ACS &&
1019
+ (supp_ht || supp_vht || supp_he)))
1020
+ return -EINVAL;
9651021
9661022 if (!sband->ht_cap.ht_supported)
9671023 continue;
....@@ -1033,9 +1089,23 @@
10331089 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
10341090 if (hw->max_signal <= 0) {
10351091 result = -EINVAL;
1036
- goto fail_wiphy_register;
1092
+ goto fail_workqueue;
10371093 }
10381094 }
1095
+
1096
+ /* Mac80211 and therefore all drivers using SW crypto only
1097
+ * are able to handle PTK rekeys and Extended Key ID.
1098
+ */
1099
+ if (!local->ops->set_key) {
1100
+ wiphy_ext_feature_set(local->hw.wiphy,
1101
+ NL80211_EXT_FEATURE_CAN_REPLACE_PTK0);
1102
+ wiphy_ext_feature_set(local->hw.wiphy,
1103
+ NL80211_EXT_FEATURE_EXT_KEY_ID);
1104
+ }
1105
+
1106
+ if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_ADHOC))
1107
+ wiphy_ext_feature_set(local->hw.wiphy,
1108
+ NL80211_EXT_FEATURE_DEL_IBSS_STA);
10391109
10401110 /*
10411111 * Calculate scan IE length -- we need this to alloc
....@@ -1088,7 +1158,7 @@
10881158
10891159 result = ieee80211_init_cipher_suites(local);
10901160 if (result < 0)
1091
- goto fail_wiphy_register;
1161
+ goto fail_workqueue;
10921162
10931163 if (!local->ops->remain_on_channel)
10941164 local->hw.wiphy->max_remain_on_channel_duration = 5000;
....@@ -1101,11 +1171,18 @@
11011171 if (ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA))
11021172 local->ext_capa[0] |= WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING;
11031173
1104
- local->hw.wiphy->max_num_csa_counters = IEEE80211_MAX_CSA_COUNTERS_NUM;
1174
+ /* mac80211 supports multi BSSID, if the driver supports it */
1175
+ if (ieee80211_hw_check(&local->hw, SUPPORTS_MULTI_BSSID)) {
1176
+ local->hw.wiphy->support_mbssid = true;
1177
+ if (ieee80211_hw_check(&local->hw,
1178
+ SUPPORTS_ONLY_HE_MULTI_BSSID))
1179
+ local->hw.wiphy->support_only_he_mbssid = true;
1180
+ else
1181
+ local->ext_capa[2] |=
1182
+ WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
1183
+ }
11051184
1106
- result = wiphy_register(local->hw.wiphy);
1107
- if (result < 0)
1108
- goto fail_wiphy_register;
1185
+ local->hw.wiphy->max_num_csa_counters = IEEE80211_MAX_CNTDWN_COUNTERS_NUM;
11091186
11101187 /*
11111188 * We use the number of queues for feature tests (QoS, HT) internally
....@@ -1129,8 +1206,6 @@
11291206 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
11301207 IEEE80211_TX_STATUS_HEADROOM);
11311208
1132
- debugfs_hw_add(local);
1133
-
11341209 /*
11351210 * if the driver doesn't specify a max listen interval we
11361211 * use 5 which should be a safe default
....@@ -1145,10 +1220,10 @@
11451220 if (!local->hw.max_nan_de_entries)
11461221 local->hw.max_nan_de_entries = IEEE80211_MAX_NAN_INSTANCE_ID;
11471222
1148
- result = ieee80211_wep_init(local);
1149
- if (result < 0)
1150
- wiphy_debug(local->hw.wiphy, "Failed to initialize wep: %d\n",
1151
- result);
1223
+ if (!local->hw.weight_multiplier)
1224
+ local->hw.weight_multiplier = 1;
1225
+
1226
+ ieee80211_wep_init(local);
11521227
11531228 local->hw.conf.flags = IEEE80211_CONF_IDLE;
11541229
....@@ -1159,20 +1234,78 @@
11591234 goto fail_flows;
11601235
11611236 rtnl_lock();
1162
-
11631237 result = ieee80211_init_rate_ctrl_alg(local,
11641238 hw->rate_control_algorithm);
1239
+ rtnl_unlock();
11651240 if (result < 0) {
11661241 wiphy_debug(local->hw.wiphy,
11671242 "Failed to initialize rate control algorithm\n");
11681243 goto fail_rate;
11691244 }
11701245
1246
+ if (local->rate_ctrl) {
1247
+ clear_bit(IEEE80211_HW_SUPPORTS_VHT_EXT_NSS_BW, hw->flags);
1248
+ if (local->rate_ctrl->ops->capa & RATE_CTRL_CAPA_VHT_EXT_NSS_BW)
1249
+ ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
1250
+ }
1251
+
1252
+ /*
1253
+ * If the VHT capabilities don't have IEEE80211_VHT_EXT_NSS_BW_CAPABLE,
1254
+ * or have it when we don't, copy the sband structure and set/clear it.
1255
+ * This is necessary because rate scaling algorithms could be switched
1256
+ * and have different support values.
1257
+ * Print a message so that in the common case the reallocation can be
1258
+ * avoided.
1259
+ */
1260
+ BUILD_BUG_ON(NUM_NL80211_BANDS > 8 * sizeof(local->sband_allocated));
1261
+ for (band = 0; band < NUM_NL80211_BANDS; band++) {
1262
+ struct ieee80211_supported_band *sband;
1263
+ bool local_cap, ie_cap;
1264
+
1265
+ local_cap = ieee80211_hw_check(hw, SUPPORTS_VHT_EXT_NSS_BW);
1266
+
1267
+ sband = local->hw.wiphy->bands[band];
1268
+ if (!sband || !sband->vht_cap.vht_supported)
1269
+ continue;
1270
+
1271
+ ie_cap = !!(sband->vht_cap.vht_mcs.tx_highest &
1272
+ cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE));
1273
+
1274
+ if (local_cap == ie_cap)
1275
+ continue;
1276
+
1277
+ sband = kmemdup(sband, sizeof(*sband), GFP_KERNEL);
1278
+ if (!sband) {
1279
+ result = -ENOMEM;
1280
+ goto fail_rate;
1281
+ }
1282
+
1283
+ wiphy_dbg(hw->wiphy, "copying sband (band %d) due to VHT EXT NSS BW flag\n",
1284
+ band);
1285
+
1286
+ sband->vht_cap.vht_mcs.tx_highest ^=
1287
+ cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE);
1288
+
1289
+ local->hw.wiphy->bands[band] = sband;
1290
+ local->sband_allocated |= BIT(band);
1291
+ }
1292
+
1293
+ result = wiphy_register(local->hw.wiphy);
1294
+ if (result < 0)
1295
+ goto fail_wiphy_register;
1296
+
1297
+ debugfs_hw_add(local);
1298
+ rate_control_add_debugfs(local);
1299
+
1300
+ rtnl_lock();
1301
+
11711302 /* add one default STA interface if supported */
11721303 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION) &&
11731304 !ieee80211_hw_check(hw, NO_AUTO_VIF)) {
1305
+ struct vif_params params = {0};
1306
+
11741307 result = ieee80211_if_add(local, "wlan%d", NET_NAME_ENUM, NULL,
1175
- NL80211_IFTYPE_STATION, NULL);
1308
+ NL80211_IFTYPE_STATION, &params);
11761309 if (result)
11771310 wiphy_warn(local->hw.wiphy,
11781311 "Failed to add default virtual iface\n");
....@@ -1205,20 +1338,21 @@
12051338 #if defined(CONFIG_INET) || defined(CONFIG_IPV6)
12061339 fail_ifa:
12071340 #endif
1341
+ wiphy_unregister(local->hw.wiphy);
1342
+ fail_wiphy_register:
12081343 rtnl_lock();
12091344 rate_control_deinitialize(local);
12101345 ieee80211_remove_interfaces(local);
1211
- fail_rate:
12121346 rtnl_unlock();
1213
- ieee80211_led_exit(local);
1214
- ieee80211_wep_free(local);
1347
+ fail_rate:
12151348 fail_flows:
1349
+ ieee80211_led_exit(local);
12161350 destroy_workqueue(local->workqueue);
12171351 fail_workqueue:
1218
- wiphy_unregister(local->hw.wiphy);
1219
- fail_wiphy_register:
1220
- if (local->wiphy_ciphers_allocated)
1352
+ if (local->wiphy_ciphers_allocated) {
12211353 kfree(local->hw.wiphy->cipher_suites);
1354
+ local->wiphy_ciphers_allocated = false;
1355
+ }
12221356 kfree(local->int_scan_req);
12231357 return result;
12241358 }
....@@ -1266,9 +1400,8 @@
12661400 skb_queue_purge(&local->skb_queue_unreliable);
12671401 skb_queue_purge(&local->skb_queue_tdls_chsw);
12681402
1269
- destroy_workqueue(local->workqueue);
12701403 wiphy_unregister(local->hw.wiphy);
1271
- ieee80211_wep_free(local);
1404
+ destroy_workqueue(local->workqueue);
12721405 ieee80211_led_exit(local);
12731406 kfree(local->int_scan_req);
12741407 }
....@@ -1284,12 +1417,15 @@
12841417 void ieee80211_free_hw(struct ieee80211_hw *hw)
12851418 {
12861419 struct ieee80211_local *local = hw_to_local(hw);
1420
+ enum nl80211_band band;
12871421
12881422 mutex_destroy(&local->iflist_mtx);
12891423 mutex_destroy(&local->mtx);
12901424
1291
- if (local->wiphy_ciphers_allocated)
1425
+ if (local->wiphy_ciphers_allocated) {
12921426 kfree(local->hw.wiphy->cipher_suites);
1427
+ local->wiphy_ciphers_allocated = false;
1428
+ }
12931429
12941430 idr_for_each(&local->ack_status_frames,
12951431 ieee80211_free_ack_frame, NULL);
....@@ -1298,6 +1434,12 @@
12981434 sta_info_stop(local);
12991435
13001436 ieee80211_free_led_names(local);
1437
+
1438
+ for (band = 0; band < NUM_NL80211_BANDS; band++) {
1439
+ if (!(local->sband_allocated & BIT(band)))
1440
+ continue;
1441
+ kfree(local->hw.wiphy->bands[band]);
1442
+ }
13011443
13021444 wiphy_free(local->hw.wiphy);
13031445 }
....@@ -1316,18 +1458,12 @@
13161458 if (ret)
13171459 return ret;
13181460
1319
- ret = rc80211_minstrel_ht_init();
1320
- if (ret)
1321
- goto err_minstrel;
1322
-
13231461 ret = ieee80211_iface_init();
13241462 if (ret)
13251463 goto err_netdev;
13261464
13271465 return 0;
13281466 err_netdev:
1329
- rc80211_minstrel_ht_exit();
1330
- err_minstrel:
13311467 rc80211_minstrel_exit();
13321468
13331469 return ret;
....@@ -1335,7 +1471,6 @@
13351471
13361472 static void __exit ieee80211_exit(void)
13371473 {
1338
- rc80211_minstrel_ht_exit();
13391474 rc80211_minstrel_exit();
13401475
13411476 ieee80211s_stop();