License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2008-01-24 18:38:38 +00:00
|
|
|
/*
|
|
|
|
* Wireless utility functions
|
|
|
|
*
|
2009-04-20 12:31:42 +00:00
|
|
|
* Copyright 2007-2009 Johannes Berg <johannes@sipsolutions.net>
|
2014-09-03 12:24:58 +00:00
|
|
|
* Copyright 2013-2014 Intel Mobile Communications GmbH
|
2018-06-09 06:14:42 +00:00
|
|
|
* Copyright 2017 Intel Deutschland GmbH
|
2023-06-08 13:36:04 +00:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2008-01-24 18:38:38 +00:00
|
|
|
*/
|
2011-07-15 15:47:34 +00:00
|
|
|
#include <linux/export.h>
|
2009-04-20 12:31:42 +00:00
|
|
|
#include <linux/bitops.h>
|
2009-05-21 13:47:03 +00:00
|
|
|
#include <linux/etherdevice.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2018-08-31 08:31:16 +00:00
|
|
|
#include <linux/ieee80211.h>
|
2009-04-20 12:31:42 +00:00
|
|
|
#include <net/cfg80211.h>
|
2009-05-21 13:47:03 +00:00
|
|
|
#include <net/ip.h>
|
2011-12-22 20:55:08 +00:00
|
|
|
#include <net/dsfield.h>
|
2013-08-26 12:04:52 +00:00
|
|
|
#include <linux/if_vlan.h>
|
2014-03-03 16:23:12 +00:00
|
|
|
#include <linux/mpls.h>
|
2016-10-21 12:25:13 +00:00
|
|
|
#include <linux/gcd.h>
|
2018-08-31 08:31:16 +00:00
|
|
|
#include <linux/bitfield.h>
|
2019-02-06 11:17:14 +00:00
|
|
|
#include <linux/nospec.h>
|
2008-01-24 18:38:38 +00:00
|
|
|
#include "core.h"
|
2012-06-27 14:19:42 +00:00
|
|
|
#include "rdev-ops.h"
|
|
|
|
|
2008-01-24 18:38:38 +00:00
|
|
|
|
2021-04-18 08:39:53 +00:00
|
|
|
const struct ieee80211_rate *
|
2008-10-29 19:00:45 +00:00
|
|
|
ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
|
2009-01-21 14:13:48 +00:00
|
|
|
u32 basic_rates, int bitrate)
|
2008-10-29 19:00:45 +00:00
|
|
|
{
|
|
|
|
struct ieee80211_rate *result = &sband->bitrates[0];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sband->n_bitrates; i++) {
|
|
|
|
if (!(basic_rates & BIT(i)))
|
|
|
|
continue;
|
|
|
|
if (sband->bitrates[i].bitrate > bitrate)
|
|
|
|
continue;
|
|
|
|
result = &sband->bitrates[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee80211_get_response_rate);
|
|
|
|
|
2023-08-29 10:17:43 +00:00
|
|
|
u32 ieee80211_mandatory_rates(struct ieee80211_supported_band *sband)
|
2013-05-11 00:50:51 +00:00
|
|
|
{
|
|
|
|
struct ieee80211_rate *bitrates;
|
|
|
|
u32 mandatory_rates = 0;
|
|
|
|
enum ieee80211_rate_flags mandatory_flag;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (WARN_ON(!sband))
|
|
|
|
return 1;
|
|
|
|
|
2023-08-29 10:17:43 +00:00
|
|
|
if (sband->band == NL80211_BAND_2GHZ)
|
|
|
|
mandatory_flag = IEEE80211_RATE_MANDATORY_B;
|
|
|
|
else
|
2013-05-11 00:50:51 +00:00
|
|
|
mandatory_flag = IEEE80211_RATE_MANDATORY_A;
|
|
|
|
|
|
|
|
bitrates = sband->bitrates;
|
|
|
|
for (i = 0; i < sband->n_bitrates; i++)
|
|
|
|
if (bitrates[i].flags & mandatory_flag)
|
|
|
|
mandatory_rates |= BIT(i);
|
|
|
|
return mandatory_rates;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee80211_mandatory_rates);
|
|
|
|
|
2020-04-02 01:18:03 +00:00
|
|
|
u32 ieee80211_channel_to_freq_khz(int chan, enum nl80211_band band)
|
2008-01-24 18:38:38 +00:00
|
|
|
{
|
2011-01-17 04:37:28 +00:00
|
|
|
/* see 802.11 17.3.8.3.2 and Annex J
|
|
|
|
* there are overlapping channel numbers in 5GHz and 2GHz bands */
|
2012-07-02 06:32:32 +00:00
|
|
|
if (chan <= 0)
|
|
|
|
return 0; /* not supported */
|
|
|
|
switch (band) {
|
2016-04-12 13:56:15 +00:00
|
|
|
case NL80211_BAND_2GHZ:
|
2021-10-18 10:00:54 +00:00
|
|
|
case NL80211_BAND_LC:
|
2011-01-17 04:37:28 +00:00
|
|
|
if (chan == 14)
|
2020-04-02 01:18:03 +00:00
|
|
|
return MHZ_TO_KHZ(2484);
|
2011-01-17 04:37:28 +00:00
|
|
|
else if (chan < 14)
|
2020-04-02 01:18:03 +00:00
|
|
|
return MHZ_TO_KHZ(2407 + chan * 5);
|
2012-07-02 06:32:32 +00:00
|
|
|
break;
|
2016-04-12 13:56:15 +00:00
|
|
|
case NL80211_BAND_5GHZ:
|
2012-07-02 06:32:32 +00:00
|
|
|
if (chan >= 182 && chan <= 196)
|
2020-04-02 01:18:03 +00:00
|
|
|
return MHZ_TO_KHZ(4000 + chan * 5);
|
2011-01-17 04:37:28 +00:00
|
|
|
else
|
2020-04-02 01:18:03 +00:00
|
|
|
return MHZ_TO_KHZ(5000 + chan * 5);
|
2012-07-02 06:32:32 +00:00
|
|
|
break;
|
2019-08-02 11:31:00 +00:00
|
|
|
case NL80211_BAND_6GHZ:
|
2020-05-29 09:41:43 +00:00
|
|
|
/* see 802.11ax D6.1 27.3.23.2 */
|
|
|
|
if (chan == 2)
|
|
|
|
return MHZ_TO_KHZ(5935);
|
2020-09-17 09:52:23 +00:00
|
|
|
if (chan <= 233)
|
2020-05-29 09:41:43 +00:00
|
|
|
return MHZ_TO_KHZ(5950 + chan * 5);
|
2019-08-02 11:31:00 +00:00
|
|
|
break;
|
2016-04-12 13:56:15 +00:00
|
|
|
case NL80211_BAND_60GHZ:
|
2018-08-13 12:33:00 +00:00
|
|
|
if (chan < 7)
|
2020-04-02 01:18:03 +00:00
|
|
|
return MHZ_TO_KHZ(56160 + chan * 2160);
|
2012-07-02 06:32:32 +00:00
|
|
|
break;
|
2020-06-02 06:22:47 +00:00
|
|
|
case NL80211_BAND_S1GHZ:
|
|
|
|
return 902000 + chan * 500;
|
2012-07-02 06:32:32 +00:00
|
|
|
default:
|
|
|
|
;
|
2011-01-17 04:37:28 +00:00
|
|
|
}
|
2012-07-02 06:32:32 +00:00
|
|
|
return 0; /* not supported */
|
2008-01-24 18:38:38 +00:00
|
|
|
}
|
2020-04-02 01:18:03 +00:00
|
|
|
EXPORT_SYMBOL(ieee80211_channel_to_freq_khz);
|
2008-01-24 18:38:38 +00:00
|
|
|
|
2020-09-08 19:03:06 +00:00
|
|
|
enum nl80211_chan_width
|
|
|
|
ieee80211_s1g_channel_width(const struct ieee80211_channel *chan)
|
|
|
|
{
|
|
|
|
if (WARN_ON(!chan || chan->band != NL80211_BAND_S1GHZ))
|
|
|
|
return NL80211_CHAN_WIDTH_20_NOHT;
|
|
|
|
|
|
|
|
/*S1G defines a single allowed channel width per channel.
|
|
|
|
* Extract that width here.
|
|
|
|
*/
|
|
|
|
if (chan->flags & IEEE80211_CHAN_1MHZ)
|
|
|
|
return NL80211_CHAN_WIDTH_1;
|
|
|
|
else if (chan->flags & IEEE80211_CHAN_2MHZ)
|
|
|
|
return NL80211_CHAN_WIDTH_2;
|
|
|
|
else if (chan->flags & IEEE80211_CHAN_4MHZ)
|
|
|
|
return NL80211_CHAN_WIDTH_4;
|
|
|
|
else if (chan->flags & IEEE80211_CHAN_8MHZ)
|
|
|
|
return NL80211_CHAN_WIDTH_8;
|
|
|
|
else if (chan->flags & IEEE80211_CHAN_16MHZ)
|
|
|
|
return NL80211_CHAN_WIDTH_16;
|
|
|
|
|
|
|
|
pr_err("unknown channel width for channel at %dKHz?\n",
|
|
|
|
ieee80211_channel_to_khz(chan));
|
|
|
|
|
|
|
|
return NL80211_CHAN_WIDTH_1;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee80211_s1g_channel_width);
|
|
|
|
|
2020-04-02 01:18:03 +00:00
|
|
|
int ieee80211_freq_khz_to_channel(u32 freq)
|
2008-01-24 18:38:38 +00:00
|
|
|
{
|
2020-04-02 01:18:03 +00:00
|
|
|
/* TODO: just handle MHz for now */
|
|
|
|
freq = KHZ_TO_MHZ(freq);
|
|
|
|
|
2011-01-17 04:37:28 +00:00
|
|
|
/* see 802.11 17.3.8.3.2 and Annex J */
|
2008-01-24 18:38:38 +00:00
|
|
|
if (freq == 2484)
|
|
|
|
return 14;
|
2011-01-17 04:37:28 +00:00
|
|
|
else if (freq < 2484)
|
2008-01-24 18:38:38 +00:00
|
|
|
return (freq - 2407) / 5;
|
2011-01-17 04:37:28 +00:00
|
|
|
else if (freq >= 4910 && freq <= 4980)
|
|
|
|
return (freq - 4000) / 5;
|
2020-06-19 20:52:01 +00:00
|
|
|
else if (freq < 5925)
|
2011-01-17 04:37:28 +00:00
|
|
|
return (freq - 5000) / 5;
|
2020-06-19 20:52:01 +00:00
|
|
|
else if (freq == 5935)
|
|
|
|
return 2;
|
2019-08-02 11:31:00 +00:00
|
|
|
else if (freq <= 45000) /* DMG band lower limit */
|
2020-06-19 20:52:01 +00:00
|
|
|
/* see 802.11ax D6.1 27.3.22.2 */
|
|
|
|
return (freq - 5950) / 5;
|
2018-08-13 12:33:00 +00:00
|
|
|
else if (freq >= 58320 && freq <= 70200)
|
2012-07-02 06:32:32 +00:00
|
|
|
return (freq - 56160) / 2160;
|
|
|
|
else
|
|
|
|
return 0;
|
2008-01-24 18:38:38 +00:00
|
|
|
}
|
2020-04-02 01:18:03 +00:00
|
|
|
EXPORT_SYMBOL(ieee80211_freq_khz_to_channel);
|
2008-01-24 18:38:38 +00:00
|
|
|
|
2020-04-02 01:18:03 +00:00
|
|
|
struct ieee80211_channel *ieee80211_get_channel_khz(struct wiphy *wiphy,
|
|
|
|
u32 freq)
|
2008-03-16 17:34:33 +00:00
|
|
|
{
|
2016-04-12 13:56:15 +00:00
|
|
|
enum nl80211_band band;
|
2008-03-16 17:34:33 +00:00
|
|
|
struct ieee80211_supported_band *sband;
|
|
|
|
int i;
|
|
|
|
|
2016-04-12 13:56:15 +00:00
|
|
|
for (band = 0; band < NUM_NL80211_BANDS; band++) {
|
2008-03-16 17:34:33 +00:00
|
|
|
sband = wiphy->bands[band];
|
|
|
|
|
|
|
|
if (!sband)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (i = 0; i < sband->n_channels; i++) {
|
2020-04-02 01:18:03 +00:00
|
|
|
struct ieee80211_channel *chan = &sband->channels[i];
|
|
|
|
|
|
|
|
if (ieee80211_channel_to_khz(chan) == freq)
|
|
|
|
return chan;
|
2008-03-16 17:34:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-04-02 01:18:03 +00:00
|
|
|
EXPORT_SYMBOL(ieee80211_get_channel_khz);
|
2008-03-16 17:34:33 +00:00
|
|
|
|
2017-01-04 10:53:37 +00:00
|
|
|
static void set_mandatory_flags_band(struct ieee80211_supported_band *sband)
|
2008-01-24 18:38:38 +00:00
|
|
|
{
|
|
|
|
int i, want;
|
|
|
|
|
2017-01-04 10:53:37 +00:00
|
|
|
switch (sband->band) {
|
2016-04-12 13:56:15 +00:00
|
|
|
case NL80211_BAND_5GHZ:
|
2019-08-02 11:31:05 +00:00
|
|
|
case NL80211_BAND_6GHZ:
|
2008-01-24 18:38:38 +00:00
|
|
|
want = 3;
|
|
|
|
for (i = 0; i < sband->n_bitrates; i++) {
|
|
|
|
if (sband->bitrates[i].bitrate == 60 ||
|
|
|
|
sband->bitrates[i].bitrate == 120 ||
|
|
|
|
sband->bitrates[i].bitrate == 240) {
|
|
|
|
sband->bitrates[i].flags |=
|
|
|
|
IEEE80211_RATE_MANDATORY_A;
|
|
|
|
want--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WARN_ON(want);
|
|
|
|
break;
|
2016-04-12 13:56:15 +00:00
|
|
|
case NL80211_BAND_2GHZ:
|
2021-10-18 10:00:54 +00:00
|
|
|
case NL80211_BAND_LC:
|
2008-01-24 18:38:38 +00:00
|
|
|
want = 7;
|
|
|
|
for (i = 0; i < sband->n_bitrates; i++) {
|
2017-09-07 15:47:43 +00:00
|
|
|
switch (sband->bitrates[i].bitrate) {
|
|
|
|
case 10:
|
|
|
|
case 20:
|
|
|
|
case 55:
|
|
|
|
case 110:
|
2008-01-24 18:38:38 +00:00
|
|
|
sband->bitrates[i].flags |=
|
|
|
|
IEEE80211_RATE_MANDATORY_B |
|
|
|
|
IEEE80211_RATE_MANDATORY_G;
|
|
|
|
want--;
|
2017-09-07 15:47:43 +00:00
|
|
|
break;
|
|
|
|
case 60:
|
|
|
|
case 120:
|
|
|
|
case 240:
|
2008-01-24 18:38:38 +00:00
|
|
|
sband->bitrates[i].flags |=
|
|
|
|
IEEE80211_RATE_MANDATORY_G;
|
|
|
|
want--;
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough;
|
2017-09-07 15:47:43 +00:00
|
|
|
default:
|
2008-01-24 18:38:38 +00:00
|
|
|
sband->bitrates[i].flags |=
|
|
|
|
IEEE80211_RATE_ERP_G;
|
2017-09-07 15:47:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-01-24 18:38:38 +00:00
|
|
|
}
|
2017-09-07 15:47:43 +00:00
|
|
|
WARN_ON(want != 0 && want != 3);
|
2008-01-24 18:38:38 +00:00
|
|
|
break;
|
2016-04-12 13:56:15 +00:00
|
|
|
case NL80211_BAND_60GHZ:
|
2012-07-02 06:32:32 +00:00
|
|
|
/* check for mandatory HT MCS 1..4 */
|
|
|
|
WARN_ON(!sband->ht_cap.ht_supported);
|
|
|
|
WARN_ON((sband->ht_cap.mcs.rx_mask[0] & 0x1e) != 0x1e);
|
|
|
|
break;
|
2020-06-02 06:22:47 +00:00
|
|
|
case NL80211_BAND_S1GHZ:
|
|
|
|
/* Figure 9-589bd: 3 means unsupported, so != 3 means at least
|
|
|
|
* mandatory is ok.
|
|
|
|
*/
|
|
|
|
WARN_ON((sband->s1g_cap.nss_mcs[0] & 0x3) == 0x3);
|
|
|
|
break;
|
2016-04-12 13:56:15 +00:00
|
|
|
case NUM_NL80211_BANDS:
|
2017-01-04 10:53:37 +00:00
|
|
|
default:
|
2008-01-24 18:38:38 +00:00
|
|
|
WARN_ON(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ieee80211_set_bitrate_flags(struct wiphy *wiphy)
|
|
|
|
{
|
2016-04-12 13:56:15 +00:00
|
|
|
enum nl80211_band band;
|
2008-01-24 18:38:38 +00:00
|
|
|
|
2016-04-12 13:56:15 +00:00
|
|
|
for (band = 0; band < NUM_NL80211_BANDS; band++)
|
2008-01-24 18:38:38 +00:00
|
|
|
if (wiphy->bands[band])
|
2017-01-04 10:53:37 +00:00
|
|
|
set_mandatory_flags_band(wiphy->bands[band]);
|
2008-01-24 18:38:38 +00:00
|
|
|
}
|
2009-05-11 11:54:58 +00:00
|
|
|
|
2011-09-21 15:14:56 +00:00
|
|
|
bool cfg80211_supported_cipher_suite(struct wiphy *wiphy, u32 cipher)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < wiphy->n_cipher_suites; i++)
|
|
|
|
if (cipher == wiphy->cipher_suites[i])
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-04 21:58:25 +00:00
|
|
|
static bool
|
|
|
|
cfg80211_igtk_cipher_supported(struct cfg80211_registered_device *rdev)
|
|
|
|
{
|
|
|
|
struct wiphy *wiphy = &rdev->wiphy;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < wiphy->n_cipher_suites; i++) {
|
|
|
|
switch (wiphy->cipher_suites[i]) {
|
|
|
|
case WLAN_CIPHER_SUITE_AES_CMAC:
|
|
|
|
case WLAN_CIPHER_SUITE_BIP_CMAC_256:
|
|
|
|
case WLAN_CIPHER_SUITE_BIP_GMAC_128:
|
|
|
|
case WLAN_CIPHER_SUITE_BIP_GMAC_256:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cfg80211_valid_key_idx(struct cfg80211_registered_device *rdev,
|
|
|
|
int key_idx, bool pairwise)
|
2009-05-11 11:54:58 +00:00
|
|
|
{
|
2020-12-04 21:58:25 +00:00
|
|
|
int max_key_idx;
|
2020-02-22 13:25:43 +00:00
|
|
|
|
2020-12-04 21:58:25 +00:00
|
|
|
if (pairwise)
|
|
|
|
max_key_idx = 3;
|
|
|
|
else if (wiphy_ext_feature_isset(&rdev->wiphy,
|
|
|
|
NL80211_EXT_FEATURE_BEACON_PROTECTION) ||
|
|
|
|
wiphy_ext_feature_isset(&rdev->wiphy,
|
|
|
|
NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT))
|
2020-02-22 13:25:43 +00:00
|
|
|
max_key_idx = 7;
|
2020-12-04 21:58:25 +00:00
|
|
|
else if (cfg80211_igtk_cipher_supported(rdev))
|
|
|
|
max_key_idx = 5;
|
|
|
|
else
|
|
|
|
max_key_idx = 3;
|
|
|
|
|
2020-02-22 13:25:43 +00:00
|
|
|
if (key_idx < 0 || key_idx > max_key_idx)
|
2020-12-04 21:58:25 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
|
|
|
|
struct key_params *params, int key_idx,
|
|
|
|
bool pairwise, const u8 *mac_addr)
|
|
|
|
{
|
|
|
|
if (!cfg80211_valid_key_idx(rdev, key_idx, pairwise))
|
2009-05-11 11:54:58 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2010-10-05 17:39:30 +00:00
|
|
|
if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (pairwise && !mac_addr)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2015-01-24 17:52:04 +00:00
|
|
|
switch (params->cipher) {
|
|
|
|
case WLAN_CIPHER_SUITE_TKIP:
|
2019-08-05 12:34:00 +00:00
|
|
|
/* Extended Key ID can only be used with CCMP/GCMP ciphers */
|
|
|
|
if ((pairwise && key_idx) ||
|
|
|
|
params->mode != NL80211_KEY_RX_TX)
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
2015-01-24 17:52:04 +00:00
|
|
|
case WLAN_CIPHER_SUITE_CCMP:
|
2015-01-24 17:52:05 +00:00
|
|
|
case WLAN_CIPHER_SUITE_CCMP_256:
|
|
|
|
case WLAN_CIPHER_SUITE_GCMP:
|
|
|
|
case WLAN_CIPHER_SUITE_GCMP_256:
|
2019-08-05 12:34:00 +00:00
|
|
|
/* IEEE802.11-2016 allows only 0 and - when supporting
|
|
|
|
* Extended Key ID - 1 as index for pairwise keys.
|
2019-03-19 20:34:07 +00:00
|
|
|
* @NL80211_KEY_NO_TX is only allowed for pairwise keys when
|
|
|
|
* the driver supports Extended Key ID.
|
|
|
|
* @NL80211_KEY_SET_TX can't be set when installing and
|
|
|
|
* validating a key.
|
2015-01-24 17:52:04 +00:00
|
|
|
*/
|
2019-08-05 12:34:00 +00:00
|
|
|
if ((params->mode == NL80211_KEY_NO_TX && !pairwise) ||
|
|
|
|
params->mode == NL80211_KEY_SET_TX)
|
|
|
|
return -EINVAL;
|
|
|
|
if (wiphy_ext_feature_isset(&rdev->wiphy,
|
|
|
|
NL80211_EXT_FEATURE_EXT_KEY_ID)) {
|
|
|
|
if (pairwise && (key_idx < 0 || key_idx > 1))
|
2019-03-19 20:34:07 +00:00
|
|
|
return -EINVAL;
|
2019-08-05 12:34:00 +00:00
|
|
|
} else if (pairwise && key_idx) {
|
2015-01-24 17:52:04 +00:00
|
|
|
return -EINVAL;
|
2019-03-19 20:34:07 +00:00
|
|
|
}
|
2015-01-24 17:52:04 +00:00
|
|
|
break;
|
|
|
|
case WLAN_CIPHER_SUITE_AES_CMAC:
|
2015-01-24 17:52:05 +00:00
|
|
|
case WLAN_CIPHER_SUITE_BIP_CMAC_256:
|
|
|
|
case WLAN_CIPHER_SUITE_BIP_GMAC_128:
|
|
|
|
case WLAN_CIPHER_SUITE_BIP_GMAC_256:
|
2015-01-24 17:52:04 +00:00
|
|
|
/* Disallow BIP (group-only) cipher as pairwise cipher */
|
|
|
|
if (pairwise)
|
|
|
|
return -EINVAL;
|
2016-09-13 14:37:40 +00:00
|
|
|
if (key_idx < 4)
|
|
|
|
return -EINVAL;
|
2015-01-24 17:52:04 +00:00
|
|
|
break;
|
2016-09-13 14:37:40 +00:00
|
|
|
case WLAN_CIPHER_SUITE_WEP40:
|
|
|
|
case WLAN_CIPHER_SUITE_WEP104:
|
|
|
|
if (key_idx > 3)
|
|
|
|
return -EINVAL;
|
2020-11-20 18:34:50 +00:00
|
|
|
break;
|
2015-01-24 17:52:04 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-05-11 11:54:58 +00:00
|
|
|
|
|
|
|
switch (params->cipher) {
|
|
|
|
case WLAN_CIPHER_SUITE_WEP40:
|
2009-05-24 14:57:19 +00:00
|
|
|
if (params->key_len != WLAN_KEY_LEN_WEP40)
|
2009-05-11 11:54:58 +00:00
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
case WLAN_CIPHER_SUITE_TKIP:
|
2009-05-24 14:57:19 +00:00
|
|
|
if (params->key_len != WLAN_KEY_LEN_TKIP)
|
2009-05-11 11:54:58 +00:00
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
case WLAN_CIPHER_SUITE_CCMP:
|
2009-05-24 14:57:19 +00:00
|
|
|
if (params->key_len != WLAN_KEY_LEN_CCMP)
|
2009-05-11 11:54:58 +00:00
|
|
|
return -EINVAL;
|
|
|
|
break;
|
2015-01-24 17:52:05 +00:00
|
|
|
case WLAN_CIPHER_SUITE_CCMP_256:
|
|
|
|
if (params->key_len != WLAN_KEY_LEN_CCMP_256)
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
case WLAN_CIPHER_SUITE_GCMP:
|
|
|
|
if (params->key_len != WLAN_KEY_LEN_GCMP)
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
case WLAN_CIPHER_SUITE_GCMP_256:
|
|
|
|
if (params->key_len != WLAN_KEY_LEN_GCMP_256)
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
2009-05-11 11:54:58 +00:00
|
|
|
case WLAN_CIPHER_SUITE_WEP104:
|
2009-05-24 14:57:19 +00:00
|
|
|
if (params->key_len != WLAN_KEY_LEN_WEP104)
|
2009-05-11 11:54:58 +00:00
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
case WLAN_CIPHER_SUITE_AES_CMAC:
|
2009-05-24 14:57:19 +00:00
|
|
|
if (params->key_len != WLAN_KEY_LEN_AES_CMAC)
|
2009-05-11 11:54:58 +00:00
|
|
|
return -EINVAL;
|
|
|
|
break;
|
2015-01-24 17:52:05 +00:00
|
|
|
case WLAN_CIPHER_SUITE_BIP_CMAC_256:
|
|
|
|
if (params->key_len != WLAN_KEY_LEN_BIP_CMAC_256)
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
case WLAN_CIPHER_SUITE_BIP_GMAC_128:
|
|
|
|
if (params->key_len != WLAN_KEY_LEN_BIP_GMAC_128)
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
case WLAN_CIPHER_SUITE_BIP_GMAC_256:
|
|
|
|
if (params->key_len != WLAN_KEY_LEN_BIP_GMAC_256)
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
2009-05-11 11:54:58 +00:00
|
|
|
default:
|
2010-08-27 11:26:51 +00:00
|
|
|
/*
|
|
|
|
* We don't know anything about this algorithm,
|
|
|
|
* allow using it -- but the driver must check
|
|
|
|
* all parameters! We still check below whether
|
|
|
|
* or not the driver supports this algorithm,
|
|
|
|
* of course.
|
|
|
|
*/
|
|
|
|
break;
|
2009-05-11 11:54:58 +00:00
|
|
|
}
|
|
|
|
|
2009-05-15 09:38:32 +00:00
|
|
|
if (params->seq) {
|
|
|
|
switch (params->cipher) {
|
|
|
|
case WLAN_CIPHER_SUITE_WEP40:
|
|
|
|
case WLAN_CIPHER_SUITE_WEP104:
|
|
|
|
/* These ciphers do not use key sequence */
|
|
|
|
return -EINVAL;
|
|
|
|
case WLAN_CIPHER_SUITE_TKIP:
|
|
|
|
case WLAN_CIPHER_SUITE_CCMP:
|
2015-01-24 17:52:05 +00:00
|
|
|
case WLAN_CIPHER_SUITE_CCMP_256:
|
|
|
|
case WLAN_CIPHER_SUITE_GCMP:
|
|
|
|
case WLAN_CIPHER_SUITE_GCMP_256:
|
2009-05-15 09:38:32 +00:00
|
|
|
case WLAN_CIPHER_SUITE_AES_CMAC:
|
2015-01-24 17:52:05 +00:00
|
|
|
case WLAN_CIPHER_SUITE_BIP_CMAC_256:
|
|
|
|
case WLAN_CIPHER_SUITE_BIP_GMAC_128:
|
|
|
|
case WLAN_CIPHER_SUITE_BIP_GMAC_256:
|
2009-05-15 09:38:32 +00:00
|
|
|
if (params->seq_len != 6)
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-21 15:14:56 +00:00
|
|
|
if (!cfg80211_supported_cipher_suite(&rdev->wiphy, params->cipher))
|
cfg80211: rework key operation
This reworks the key operation in cfg80211, and now only
allows, from userspace, configuring keys (via nl80211)
after the connection has been established (in managed
mode), the IBSS been joined (in IBSS mode), at any time
(in AP[_VLAN] modes) or never for all the other modes.
In order to do shared key authentication correctly, it
is now possible to give a WEP key to the AUTH command.
To configure static WEP keys, these are given to the
CONNECT or IBSS_JOIN command directly, for a userspace
SME it is assumed it will configure it properly after
the connection has been established.
Since mac80211 used to check the default key in IBSS
mode to see whether or not the network is protected,
it needs an update in that area, as well as an update
to make use of the WEP key passed to auth() for shared
key authentication.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-07-08 12:22:54 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2009-05-11 11:54:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-05-21 13:47:03 +00:00
|
|
|
|
2010-08-12 12:49:58 +00:00
|
|
|
unsigned int __attribute_const__ ieee80211_hdrlen(__le16 fc)
|
2009-05-21 13:47:03 +00:00
|
|
|
{
|
|
|
|
unsigned int hdrlen = 24;
|
|
|
|
|
2020-09-08 19:03:05 +00:00
|
|
|
if (ieee80211_is_ext(fc)) {
|
|
|
|
hdrlen = 4;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-05-21 13:47:03 +00:00
|
|
|
if (ieee80211_is_data(fc)) {
|
|
|
|
if (ieee80211_has_a4(fc))
|
|
|
|
hdrlen = 30;
|
2010-01-20 11:55:06 +00:00
|
|
|
if (ieee80211_is_data_qos(fc)) {
|
2009-05-21 13:47:03 +00:00
|
|
|
hdrlen += IEEE80211_QOS_CTL_LEN;
|
2010-01-20 11:55:06 +00:00
|
|
|
if (ieee80211_has_order(fc))
|
|
|
|
hdrlen += IEEE80211_HT_CTL_LEN;
|
|
|
|
}
|
2009-05-21 13:47:03 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-01-20 02:17:27 +00:00
|
|
|
if (ieee80211_is_mgmt(fc)) {
|
|
|
|
if (ieee80211_has_order(fc))
|
|
|
|
hdrlen += IEEE80211_HT_CTL_LEN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-05-21 13:47:03 +00:00
|
|
|
if (ieee80211_is_ctl(fc)) {
|
|
|
|
/*
|
|
|
|
* ACK and CTS are 10 bytes, all others 16. To see how
|
|
|
|
* to get this condition consider
|
|
|
|
* subtype mask: 0b0000000011110000 (0x00F0)
|
|
|
|
* ACK subtype: 0b0000000011010000 (0x00D0)
|
|
|
|
* CTS subtype: 0b0000000011000000 (0x00C0)
|
|
|
|
* bits that matter: ^^^ (0x00E0)
|
|
|
|
* value of those: 0b0000000011000000 (0x00C0)
|
|
|
|
*/
|
|
|
|
if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
|
|
|
|
hdrlen = 10;
|
|
|
|
else
|
|
|
|
hdrlen = 16;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
return hdrlen;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee80211_hdrlen);
|
|
|
|
|
|
|
|
unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
const struct ieee80211_hdr *hdr =
|
|
|
|
(const struct ieee80211_hdr *)skb->data;
|
|
|
|
unsigned int hdrlen;
|
|
|
|
|
|
|
|
if (unlikely(skb->len < 10))
|
|
|
|
return 0;
|
|
|
|
hdrlen = ieee80211_hdrlen(hdr->frame_control);
|
|
|
|
if (unlikely(hdrlen > skb->len))
|
|
|
|
return 0;
|
|
|
|
return hdrlen;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
|
|
|
|
|
2016-02-02 13:39:09 +00:00
|
|
|
static unsigned int __ieee80211_get_mesh_hdrlen(u8 flags)
|
2009-05-21 13:47:03 +00:00
|
|
|
{
|
2016-02-02 13:39:09 +00:00
|
|
|
int ae = flags & MESH_FLAGS_AE;
|
2012-10-25 19:51:59 +00:00
|
|
|
/* 802.11-2012, 8.2.4.7.3 */
|
2009-05-21 13:47:03 +00:00
|
|
|
switch (ae) {
|
2012-10-25 19:51:59 +00:00
|
|
|
default:
|
2009-05-21 13:47:03 +00:00
|
|
|
case 0:
|
|
|
|
return 6;
|
2009-08-10 19:15:48 +00:00
|
|
|
case MESH_FLAGS_AE_A4:
|
2009-05-21 13:47:03 +00:00
|
|
|
return 12;
|
2009-08-10 19:15:48 +00:00
|
|
|
case MESH_FLAGS_AE_A5_A6:
|
2009-05-21 13:47:03 +00:00
|
|
|
return 18;
|
|
|
|
}
|
|
|
|
}
|
2016-02-02 13:39:09 +00:00
|
|
|
|
|
|
|
unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
|
|
|
|
{
|
|
|
|
return __ieee80211_get_mesh_hdrlen(meshhdr->flags);
|
|
|
|
}
|
2012-10-25 22:36:40 +00:00
|
|
|
EXPORT_SYMBOL(ieee80211_get_mesh_hdrlen);
|
2009-05-21 13:47:03 +00:00
|
|
|
|
2023-02-13 10:08:54 +00:00
|
|
|
bool ieee80211_get_8023_tunnel_proto(const void *hdr, __be16 *proto)
|
2023-02-13 10:08:52 +00:00
|
|
|
{
|
|
|
|
const __be16 *hdr_proto = hdr + ETH_ALEN;
|
|
|
|
|
|
|
|
if (!(ether_addr_equal(hdr, rfc1042_header) &&
|
|
|
|
*hdr_proto != htons(ETH_P_AARP) &&
|
|
|
|
*hdr_proto != htons(ETH_P_IPX)) &&
|
|
|
|
!ether_addr_equal(hdr, bridge_tunnel_header))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*proto = *hdr_proto;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2023-02-13 10:08:54 +00:00
|
|
|
EXPORT_SYMBOL(ieee80211_get_8023_tunnel_proto);
|
|
|
|
|
|
|
|
int ieee80211_strip_8023_mesh_hdr(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
const void *mesh_addr;
|
|
|
|
struct {
|
|
|
|
struct ethhdr eth;
|
|
|
|
u8 flags;
|
|
|
|
} payload;
|
|
|
|
int hdrlen;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = skb_copy_bits(skb, 0, &payload, sizeof(payload));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
hdrlen = sizeof(payload.eth) + __ieee80211_get_mesh_hdrlen(payload.flags);
|
|
|
|
|
|
|
|
if (likely(pskb_may_pull(skb, hdrlen + 8) &&
|
|
|
|
ieee80211_get_8023_tunnel_proto(skb->data + hdrlen,
|
|
|
|
&payload.eth.h_proto)))
|
|
|
|
hdrlen += ETH_ALEN + 2;
|
|
|
|
else if (!pskb_may_pull(skb, hdrlen))
|
|
|
|
return -EINVAL;
|
2023-07-11 11:50:52 +00:00
|
|
|
else
|
|
|
|
payload.eth.h_proto = htons(skb->len - hdrlen);
|
2023-02-13 10:08:54 +00:00
|
|
|
|
|
|
|
mesh_addr = skb->data + sizeof(payload.eth) + ETH_ALEN;
|
|
|
|
switch (payload.flags & MESH_FLAGS_AE) {
|
|
|
|
case MESH_FLAGS_AE_A4:
|
|
|
|
memcpy(&payload.eth.h_source, mesh_addr, ETH_ALEN);
|
|
|
|
break;
|
|
|
|
case MESH_FLAGS_AE_A5_A6:
|
|
|
|
memcpy(&payload.eth, mesh_addr, 2 * ETH_ALEN);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pskb_pull(skb, hdrlen - sizeof(payload.eth));
|
|
|
|
memcpy(skb->data, &payload.eth, sizeof(payload.eth));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee80211_strip_8023_mesh_hdr);
|
2023-02-13 10:08:52 +00:00
|
|
|
|
2016-10-05 13:29:49 +00:00
|
|
|
int ieee80211_data_to_8023_exthdr(struct sk_buff *skb, struct ethhdr *ehdr,
|
2018-02-27 12:03:07 +00:00
|
|
|
const u8 *addr, enum nl80211_iftype iftype,
|
2021-05-11 18:02:44 +00:00
|
|
|
u8 data_offset, bool is_amsdu)
|
2009-05-21 13:47:03 +00:00
|
|
|
{
|
|
|
|
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
2016-02-02 13:39:09 +00:00
|
|
|
struct {
|
|
|
|
u8 hdr[ETH_ALEN] __aligned(2);
|
|
|
|
__be16 proto;
|
|
|
|
} payload;
|
|
|
|
struct ethhdr tmp;
|
|
|
|
u16 hdrlen;
|
2009-05-21 13:47:03 +00:00
|
|
|
|
|
|
|
if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
|
|
|
|
return -1;
|
|
|
|
|
2018-02-27 12:03:07 +00:00
|
|
|
hdrlen = ieee80211_hdrlen(hdr->frame_control) + data_offset;
|
2022-10-07 12:56:11 +00:00
|
|
|
if (skb->len < hdrlen)
|
2016-02-02 13:39:09 +00:00
|
|
|
return -1;
|
2009-05-21 13:47:03 +00:00
|
|
|
|
|
|
|
/* convert IEEE 802.11 header + possible LLC headers into Ethernet
|
|
|
|
* header
|
|
|
|
* IEEE 802.11 address fields:
|
|
|
|
* ToDS FromDS Addr1 Addr2 Addr3 Addr4
|
|
|
|
* 0 0 DA SA BSSID n/a
|
|
|
|
* 0 1 DA BSSID SA n/a
|
|
|
|
* 1 0 BSSID SA DA n/a
|
|
|
|
* 1 1 RA TA DA SA
|
|
|
|
*/
|
2016-02-02 13:39:09 +00:00
|
|
|
memcpy(tmp.h_dest, ieee80211_get_DA(hdr), ETH_ALEN);
|
|
|
|
memcpy(tmp.h_source, ieee80211_get_SA(hdr), ETH_ALEN);
|
|
|
|
|
2009-05-21 13:47:03 +00:00
|
|
|
switch (hdr->frame_control &
|
|
|
|
cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
|
|
|
|
case cpu_to_le16(IEEE80211_FCTL_TODS):
|
|
|
|
if (unlikely(iftype != NL80211_IFTYPE_AP &&
|
2010-09-16 12:58:22 +00:00
|
|
|
iftype != NL80211_IFTYPE_AP_VLAN &&
|
|
|
|
iftype != NL80211_IFTYPE_P2P_GO))
|
2009-05-21 13:47:03 +00:00
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
|
2020-11-09 09:57:47 +00:00
|
|
|
if (unlikely(iftype != NL80211_IFTYPE_MESH_POINT &&
|
2009-11-10 19:10:05 +00:00
|
|
|
iftype != NL80211_IFTYPE_AP_VLAN &&
|
|
|
|
iftype != NL80211_IFTYPE_STATION))
|
2009-05-21 13:47:03 +00:00
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
case cpu_to_le16(IEEE80211_FCTL_FROMDS):
|
2009-08-10 19:15:48 +00:00
|
|
|
if ((iftype != NL80211_IFTYPE_STATION &&
|
2010-09-16 12:58:22 +00:00
|
|
|
iftype != NL80211_IFTYPE_P2P_CLIENT &&
|
|
|
|
iftype != NL80211_IFTYPE_MESH_POINT) ||
|
2016-02-02 13:39:09 +00:00
|
|
|
(is_multicast_ether_addr(tmp.h_dest) &&
|
|
|
|
ether_addr_equal(tmp.h_source, addr)))
|
2009-05-21 13:47:03 +00:00
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
case cpu_to_le16(0):
|
2011-09-28 11:12:54 +00:00
|
|
|
if (iftype != NL80211_IFTYPE_ADHOC &&
|
2014-11-03 09:33:18 +00:00
|
|
|
iftype != NL80211_IFTYPE_STATION &&
|
|
|
|
iftype != NL80211_IFTYPE_OCB)
|
2011-09-28 11:12:54 +00:00
|
|
|
return -1;
|
2009-05-21 13:47:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-02-13 10:08:54 +00:00
|
|
|
if (likely(!is_amsdu && iftype != NL80211_IFTYPE_MESH_POINT &&
|
2023-02-13 10:08:51 +00:00
|
|
|
skb_copy_bits(skb, hdrlen, &payload, sizeof(payload)) == 0 &&
|
2023-02-13 10:08:52 +00:00
|
|
|
ieee80211_get_8023_tunnel_proto(&payload, &tmp.h_proto))) {
|
|
|
|
/* remove RFC1042 or Bridge-Tunnel encapsulation */
|
2016-02-02 13:39:09 +00:00
|
|
|
hdrlen += ETH_ALEN + 2;
|
cfg80211/mac80211: assume CHECKSUM_COMPLETE includes SNAP
There's currently only one driver that reports CHECKSUM_COMPLETE,
that is iwlwifi. The current hardware there calculates checksum
after the SNAP header, but only RFC 1042 (and some other cases,
but replicating the exact hardware logic for corner cases in the
driver seemed awkward.)
Newer generations of hardware will checksum _including_ the SNAP,
which makes things easier.
To handle that, simply always assume the checksum _includes_ the
SNAP header, which this patch does, requiring to first add it
for older iwlwifi hardware, and then remove it again later on
conversion.
Alternatively, we could have:
1) Always assumed the checksum starts _after_ the SNAP header;
the problem with this is that we'd have to replace the exact
"what is the SNAP" check in iwlwifi that cfg80211 has.
2) Made it configurable with some flag, but that seemed like too
much complexity.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
Link: https://lore.kernel.org/r/iwlwifi.20220202104617.230736e19e0e.I3e6745873585ad943c152fab9e23b5221f17a95f@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
2022-02-02 08:49:36 +00:00
|
|
|
skb_postpull_rcsum(skb, &payload, ETH_ALEN + 2);
|
|
|
|
} else {
|
2016-06-29 08:36:39 +00:00
|
|
|
tmp.h_proto = htons(skb->len - hdrlen);
|
cfg80211/mac80211: assume CHECKSUM_COMPLETE includes SNAP
There's currently only one driver that reports CHECKSUM_COMPLETE,
that is iwlwifi. The current hardware there calculates checksum
after the SNAP header, but only RFC 1042 (and some other cases,
but replicating the exact hardware logic for corner cases in the
driver seemed awkward.)
Newer generations of hardware will checksum _including_ the SNAP,
which makes things easier.
To handle that, simply always assume the checksum _includes_ the
SNAP header, which this patch does, requiring to first add it
for older iwlwifi hardware, and then remove it again later on
conversion.
Alternatively, we could have:
1) Always assumed the checksum starts _after_ the SNAP header;
the problem with this is that we'd have to replace the exact
"what is the SNAP" check in iwlwifi that cfg80211 has.
2) Made it configurable with some flag, but that seemed like too
much complexity.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
Link: https://lore.kernel.org/r/iwlwifi.20220202104617.230736e19e0e.I3e6745873585ad943c152fab9e23b5221f17a95f@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
2022-02-02 08:49:36 +00:00
|
|
|
}
|
2016-02-02 13:39:09 +00:00
|
|
|
|
|
|
|
pskb_pull(skb, hdrlen);
|
2009-05-21 13:47:03 +00:00
|
|
|
|
2016-02-02 13:39:09 +00:00
|
|
|
if (!ehdr)
|
networking: make skb_push & __skb_push return void pointers
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.
Make these functions return void * and remove all the casts across
the tree, adding a (u8 *) cast only where the unsigned char pointer
was used directly, all done with the following spatch:
@@
expression SKB, LEN;
typedef u8;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)
@@
expression E, SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)
@@
expression SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- fn(SKB, LEN)[0]
+ *(u8 *)fn(SKB, LEN)
Note that the last part there converts from push(...)[0] to the
more idiomatic *(u8 *)push(...).
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 12:29:23 +00:00
|
|
|
ehdr = skb_push(skb, sizeof(struct ethhdr));
|
2016-02-02 13:39:09 +00:00
|
|
|
memcpy(ehdr, &tmp, sizeof(tmp));
|
|
|
|
|
2009-05-21 13:47:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-10-05 13:29:49 +00:00
|
|
|
EXPORT_SYMBOL(ieee80211_data_to_8023_exthdr);
|
2009-05-21 13:47:03 +00:00
|
|
|
|
2016-02-08 13:34:42 +00:00
|
|
|
static void
|
|
|
|
__frame_add_frag(struct sk_buff *skb, struct page *page,
|
|
|
|
void *ptr, int len, int size)
|
|
|
|
{
|
|
|
|
struct skb_shared_info *sh = skb_shinfo(skb);
|
|
|
|
int page_offset;
|
|
|
|
|
2020-01-13 18:21:07 +00:00
|
|
|
get_page(page);
|
2016-02-08 13:34:42 +00:00
|
|
|
page_offset = ptr - page_address(page);
|
|
|
|
skb_add_rx_frag(skb, sh->nr_frags, page, page_offset, len, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
__ieee80211_amsdu_copy_frag(struct sk_buff *skb, struct sk_buff *frame,
|
|
|
|
int offset, int len)
|
|
|
|
{
|
|
|
|
struct skb_shared_info *sh = skb_shinfo(skb);
|
2017-04-13 17:05:04 +00:00
|
|
|
const skb_frag_t *frag = &sh->frags[0];
|
2016-02-08 13:34:42 +00:00
|
|
|
struct page *frag_page;
|
|
|
|
void *frag_ptr;
|
|
|
|
int frag_len, frag_size;
|
|
|
|
int head_size = skb->len - skb->data_len;
|
|
|
|
int cur_len;
|
|
|
|
|
|
|
|
frag_page = virt_to_head_page(skb->head);
|
|
|
|
frag_ptr = skb->data;
|
|
|
|
frag_size = head_size;
|
|
|
|
|
|
|
|
while (offset >= frag_size) {
|
|
|
|
offset -= frag_size;
|
|
|
|
frag_page = skb_frag_page(frag);
|
|
|
|
frag_ptr = skb_frag_address(frag);
|
|
|
|
frag_size = skb_frag_size(frag);
|
2017-04-13 17:05:04 +00:00
|
|
|
frag++;
|
2016-02-08 13:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
frag_ptr += offset;
|
|
|
|
frag_len = frag_size - offset;
|
|
|
|
|
|
|
|
cur_len = min(len, frag_len);
|
|
|
|
|
|
|
|
__frame_add_frag(frame, frag_page, frag_ptr, cur_len, frag_size);
|
|
|
|
len -= cur_len;
|
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
frag_len = skb_frag_size(frag);
|
|
|
|
cur_len = min(len, frag_len);
|
|
|
|
__frame_add_frag(frame, skb_frag_page(frag),
|
|
|
|
skb_frag_address(frag), cur_len, frag_len);
|
|
|
|
len -= cur_len;
|
2017-04-13 17:05:04 +00:00
|
|
|
frag++;
|
2016-02-08 13:34:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-02 13:39:10 +00:00
|
|
|
static struct sk_buff *
|
|
|
|
__ieee80211_amsdu_copy(struct sk_buff *skb, unsigned int hlen,
|
2023-02-13 10:08:54 +00:00
|
|
|
int offset, int len, bool reuse_frag,
|
|
|
|
int min_len)
|
2016-02-02 13:39:10 +00:00
|
|
|
{
|
|
|
|
struct sk_buff *frame;
|
2016-02-08 13:34:42 +00:00
|
|
|
int cur_len = len;
|
2016-02-02 13:39:10 +00:00
|
|
|
|
|
|
|
if (skb->len - offset < len)
|
|
|
|
return NULL;
|
|
|
|
|
2016-02-08 13:34:42 +00:00
|
|
|
/*
|
|
|
|
* When reusing framents, copy some data to the head to simplify
|
|
|
|
* ethernet header handling and speed up protocol header processing
|
|
|
|
* in the stack later.
|
|
|
|
*/
|
|
|
|
if (reuse_frag)
|
2023-02-13 10:08:54 +00:00
|
|
|
cur_len = min_t(int, len, min_len);
|
2016-02-08 13:34:42 +00:00
|
|
|
|
2016-02-02 13:39:10 +00:00
|
|
|
/*
|
|
|
|
* Allocate and reserve two bytes more for payload
|
|
|
|
* alignment since sizeof(struct ethhdr) is 14.
|
|
|
|
*/
|
2016-02-08 13:34:42 +00:00
|
|
|
frame = dev_alloc_skb(hlen + sizeof(struct ethhdr) + 2 + cur_len);
|
2016-07-05 12:23:10 +00:00
|
|
|
if (!frame)
|
|
|
|
return NULL;
|
2016-02-02 13:39:10 +00:00
|
|
|
|
2023-02-13 10:08:54 +00:00
|
|
|
frame->priority = skb->priority;
|
2016-02-02 13:39:10 +00:00
|
|
|
skb_reserve(frame, hlen + sizeof(struct ethhdr) + 2);
|
2016-02-08 13:34:42 +00:00
|
|
|
skb_copy_bits(skb, offset, skb_put(frame, cur_len), cur_len);
|
|
|
|
|
|
|
|
len -= cur_len;
|
|
|
|
if (!len)
|
|
|
|
return frame;
|
|
|
|
|
|
|
|
offset += cur_len;
|
|
|
|
__ieee80211_amsdu_copy_frag(skb, frame, offset, len);
|
2016-02-02 13:39:10 +00:00
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
2009-12-01 02:18:37 +00:00
|
|
|
|
2023-03-14 09:59:56 +00:00
|
|
|
static u16
|
|
|
|
ieee80211_amsdu_subframe_length(void *field, u8 mesh_flags, u8 hdr_type)
|
|
|
|
{
|
|
|
|
__le16 *field_le = field;
|
|
|
|
__be16 *field_be = field;
|
|
|
|
u16 len;
|
|
|
|
|
|
|
|
if (hdr_type >= 2)
|
|
|
|
len = le16_to_cpu(*field_le);
|
|
|
|
else
|
|
|
|
len = be16_to_cpu(*field_be);
|
|
|
|
if (hdr_type)
|
|
|
|
len += __ieee80211_get_mesh_hdrlen(mesh_flags);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ieee80211_is_valid_amsdu(struct sk_buff *skb, u8 mesh_hdr)
|
2023-02-13 10:08:55 +00:00
|
|
|
{
|
2024-02-26 19:34:06 +00:00
|
|
|
int offset = 0, subframe_len, padding;
|
2023-02-13 10:08:55 +00:00
|
|
|
|
|
|
|
for (offset = 0; offset < skb->len; offset += subframe_len + padding) {
|
2024-02-26 19:34:06 +00:00
|
|
|
int remaining = skb->len - offset;
|
2023-02-13 10:08:55 +00:00
|
|
|
struct {
|
|
|
|
__be16 len;
|
|
|
|
u8 mesh_flags;
|
|
|
|
} hdr;
|
|
|
|
u16 len;
|
|
|
|
|
2024-02-26 19:34:06 +00:00
|
|
|
if (sizeof(hdr) > remaining)
|
|
|
|
return false;
|
|
|
|
|
2023-02-13 10:08:55 +00:00
|
|
|
if (skb_copy_bits(skb, offset + 2 * ETH_ALEN, &hdr, sizeof(hdr)) < 0)
|
|
|
|
return false;
|
|
|
|
|
2023-03-14 09:59:56 +00:00
|
|
|
len = ieee80211_amsdu_subframe_length(&hdr.len, hdr.mesh_flags,
|
|
|
|
mesh_hdr);
|
2023-02-13 10:08:55 +00:00
|
|
|
subframe_len = sizeof(struct ethhdr) + len;
|
|
|
|
padding = (4 - subframe_len) & 0x3;
|
|
|
|
|
|
|
|
if (subframe_len > remaining)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee80211_is_valid_amsdu);
|
|
|
|
|
2009-12-01 02:18:37 +00:00
|
|
|
void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
|
|
|
|
const u8 *addr, enum nl80211_iftype iftype,
|
2011-05-13 18:22:31 +00:00
|
|
|
const unsigned int extra_headroom,
|
2023-02-13 10:08:54 +00:00
|
|
|
const u8 *check_da, const u8 *check_sa,
|
2023-03-14 09:59:56 +00:00
|
|
|
u8 mesh_control)
|
2009-12-01 02:18:37 +00:00
|
|
|
{
|
2016-02-02 13:39:10 +00:00
|
|
|
unsigned int hlen = ALIGN(extra_headroom, 4);
|
2009-12-01 02:18:37 +00:00
|
|
|
struct sk_buff *frame = NULL;
|
2024-02-26 19:34:06 +00:00
|
|
|
int offset = 0;
|
2023-02-13 10:08:54 +00:00
|
|
|
struct {
|
|
|
|
struct ethhdr eth;
|
|
|
|
uint8_t flags;
|
|
|
|
} hdr;
|
2016-02-08 13:34:42 +00:00
|
|
|
bool reuse_frag = skb->head_frag && !skb_has_frag_list(skb);
|
2016-02-08 13:25:26 +00:00
|
|
|
bool reuse_skb = false;
|
2016-02-02 13:39:10 +00:00
|
|
|
bool last = false;
|
2023-02-13 10:08:54 +00:00
|
|
|
int copy_len = sizeof(hdr.eth);
|
|
|
|
|
|
|
|
if (iftype == NL80211_IFTYPE_MESH_POINT)
|
|
|
|
copy_len = sizeof(hdr);
|
2016-02-02 13:39:08 +00:00
|
|
|
|
2016-02-02 13:39:10 +00:00
|
|
|
while (!last) {
|
2024-02-26 19:34:06 +00:00
|
|
|
int remaining = skb->len - offset;
|
2016-02-02 13:39:10 +00:00
|
|
|
unsigned int subframe_len;
|
2023-02-13 10:08:54 +00:00
|
|
|
int len, mesh_len = 0;
|
2009-12-01 02:18:37 +00:00
|
|
|
u8 padding;
|
|
|
|
|
2024-02-26 19:34:06 +00:00
|
|
|
if (copy_len > remaining)
|
|
|
|
goto purge;
|
|
|
|
|
2023-02-13 10:08:54 +00:00
|
|
|
skb_copy_bits(skb, offset, &hdr, copy_len);
|
|
|
|
if (iftype == NL80211_IFTYPE_MESH_POINT)
|
|
|
|
mesh_len = __ieee80211_get_mesh_hdrlen(hdr.flags);
|
2023-03-14 09:59:56 +00:00
|
|
|
len = ieee80211_amsdu_subframe_length(&hdr.eth.h_proto, hdr.flags,
|
|
|
|
mesh_control);
|
2016-02-02 13:39:10 +00:00
|
|
|
subframe_len = sizeof(struct ethhdr) + len;
|
2009-12-01 02:18:37 +00:00
|
|
|
padding = (4 - subframe_len) & 0x3;
|
2016-02-02 13:39:10 +00:00
|
|
|
|
2009-12-01 02:18:37 +00:00
|
|
|
/* the last MSDU has no padding */
|
|
|
|
if (subframe_len > remaining)
|
|
|
|
goto purge;
|
2021-05-11 18:02:45 +00:00
|
|
|
/* mitigate A-MSDU aggregation injection attacks */
|
2023-02-13 10:08:54 +00:00
|
|
|
if (ether_addr_equal(hdr.eth.h_dest, rfc1042_header))
|
2021-05-11 18:02:45 +00:00
|
|
|
goto purge;
|
2009-12-01 02:18:37 +00:00
|
|
|
|
2016-02-02 13:39:10 +00:00
|
|
|
offset += sizeof(struct ethhdr);
|
|
|
|
last = remaining <= subframe_len + padding;
|
2016-10-05 14:17:01 +00:00
|
|
|
|
|
|
|
/* FIXME: should we really accept multicast DA? */
|
2023-02-13 10:08:54 +00:00
|
|
|
if ((check_da && !is_multicast_ether_addr(hdr.eth.h_dest) &&
|
|
|
|
!ether_addr_equal(check_da, hdr.eth.h_dest)) ||
|
|
|
|
(check_sa && !ether_addr_equal(check_sa, hdr.eth.h_source))) {
|
2016-10-05 14:17:01 +00:00
|
|
|
offset += len + padding;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reuse skb for the last subframe */
|
2016-02-08 13:34:42 +00:00
|
|
|
if (!skb_is_nonlinear(skb) && !reuse_frag && last) {
|
2016-02-02 13:39:10 +00:00
|
|
|
skb_pull(skb, offset);
|
2009-12-01 02:18:37 +00:00
|
|
|
frame = skb;
|
2016-02-02 13:39:10 +00:00
|
|
|
reuse_skb = true;
|
|
|
|
} else {
|
2016-02-08 13:34:42 +00:00
|
|
|
frame = __ieee80211_amsdu_copy(skb, hlen, offset, len,
|
2023-02-13 10:08:54 +00:00
|
|
|
reuse_frag, 32 + mesh_len);
|
2009-12-01 02:18:37 +00:00
|
|
|
if (!frame)
|
|
|
|
goto purge;
|
|
|
|
|
2016-02-02 13:39:10 +00:00
|
|
|
offset += len + padding;
|
2009-12-01 02:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
skb_reset_network_header(frame);
|
|
|
|
frame->dev = skb->dev;
|
|
|
|
frame->priority = skb->priority;
|
|
|
|
|
2023-02-13 10:08:54 +00:00
|
|
|
if (likely(iftype != NL80211_IFTYPE_MESH_POINT &&
|
|
|
|
ieee80211_get_8023_tunnel_proto(frame->data, &hdr.eth.h_proto)))
|
2016-02-02 13:39:10 +00:00
|
|
|
skb_pull(frame, ETH_ALEN + 2);
|
|
|
|
|
2023-02-13 10:08:54 +00:00
|
|
|
memcpy(skb_push(frame, sizeof(hdr.eth)), &hdr.eth, sizeof(hdr.eth));
|
2009-12-01 02:18:37 +00:00
|
|
|
__skb_queue_tail(list, frame);
|
|
|
|
}
|
|
|
|
|
2016-02-02 13:39:10 +00:00
|
|
|
if (!reuse_skb)
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
|
2009-12-01 02:18:37 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
purge:
|
|
|
|
__skb_queue_purge(list);
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee80211_amsdu_to_8023s);
|
|
|
|
|
2009-05-21 13:47:03 +00:00
|
|
|
/* Given a data frame determine the 802.1p/1d tag to use. */
|
2013-12-17 07:01:30 +00:00
|
|
|
unsigned int cfg80211_classify8021d(struct sk_buff *skb,
|
|
|
|
struct cfg80211_qos_map *qos_map)
|
2009-05-21 13:47:03 +00:00
|
|
|
{
|
|
|
|
unsigned int dscp;
|
2013-08-26 12:04:52 +00:00
|
|
|
unsigned char vlan_priority;
|
2019-02-06 11:17:14 +00:00
|
|
|
unsigned int ret;
|
2009-05-21 13:47:03 +00:00
|
|
|
|
|
|
|
/* skb->priority values from 256->263 are magic values to
|
|
|
|
* directly indicate a specific 802.1d priority. This is used
|
|
|
|
* to allow 802.1d priority to be passed directly in from VLAN
|
|
|
|
* tags, etc.
|
|
|
|
*/
|
2019-02-06 11:17:14 +00:00
|
|
|
if (skb->priority >= 256 && skb->priority <= 263) {
|
|
|
|
ret = skb->priority - 256;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-05-21 13:47:03 +00:00
|
|
|
|
2015-01-13 16:13:44 +00:00
|
|
|
if (skb_vlan_tag_present(skb)) {
|
|
|
|
vlan_priority = (skb_vlan_tag_get(skb) & VLAN_PRIO_MASK)
|
2013-08-26 12:04:52 +00:00
|
|
|
>> VLAN_PRIO_SHIFT;
|
2019-02-06 11:17:14 +00:00
|
|
|
if (vlan_priority > 0) {
|
|
|
|
ret = vlan_priority;
|
|
|
|
goto out;
|
|
|
|
}
|
2013-08-26 12:04:52 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 13:47:03 +00:00
|
|
|
switch (skb->protocol) {
|
|
|
|
case htons(ETH_P_IP):
|
2011-12-22 20:55:08 +00:00
|
|
|
dscp = ipv4_get_dsfield(ip_hdr(skb)) & 0xfc;
|
|
|
|
break;
|
|
|
|
case htons(ETH_P_IPV6):
|
|
|
|
dscp = ipv6_get_dsfield(ipv6_hdr(skb)) & 0xfc;
|
2009-05-21 13:47:03 +00:00
|
|
|
break;
|
2014-03-03 16:23:12 +00:00
|
|
|
case htons(ETH_P_MPLS_UC):
|
|
|
|
case htons(ETH_P_MPLS_MC): {
|
|
|
|
struct mpls_label mpls_tmp, *mpls;
|
|
|
|
|
|
|
|
mpls = skb_header_pointer(skb, sizeof(struct ethhdr),
|
|
|
|
sizeof(*mpls), &mpls_tmp);
|
|
|
|
if (!mpls)
|
|
|
|
return 0;
|
|
|
|
|
2019-02-06 11:17:14 +00:00
|
|
|
ret = (ntohl(mpls->entry) & MPLS_LS_TC_MASK)
|
2014-03-03 16:23:12 +00:00
|
|
|
>> MPLS_LS_TC_SHIFT;
|
2019-02-06 11:17:14 +00:00
|
|
|
goto out;
|
2014-03-03 16:23:12 +00:00
|
|
|
}
|
|
|
|
case htons(ETH_P_80221):
|
|
|
|
/* 802.21 is always network control traffic */
|
|
|
|
return 7;
|
2009-05-21 13:47:03 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-17 07:01:30 +00:00
|
|
|
if (qos_map) {
|
|
|
|
unsigned int i, tmp_dscp = dscp >> 2;
|
|
|
|
|
|
|
|
for (i = 0; i < qos_map->num_des; i++) {
|
2019-02-06 11:17:14 +00:00
|
|
|
if (tmp_dscp == qos_map->dscp_exception[i].dscp) {
|
|
|
|
ret = qos_map->dscp_exception[i].up;
|
|
|
|
goto out;
|
|
|
|
}
|
2013-12-17 07:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (tmp_dscp >= qos_map->up[i].low &&
|
2019-02-06 11:17:14 +00:00
|
|
|
tmp_dscp <= qos_map->up[i].high) {
|
|
|
|
ret = i;
|
|
|
|
goto out;
|
|
|
|
}
|
2013-12-17 07:01:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-18 09:30:05 +00:00
|
|
|
/* The default mapping as defined Section 2.3 in RFC8325: The three
|
|
|
|
* Most Significant Bits (MSBs) of the DSCP are used as the
|
|
|
|
* corresponding L2 markings.
|
|
|
|
*/
|
2019-02-06 11:17:14 +00:00
|
|
|
ret = dscp >> 5;
|
2023-12-18 09:30:05 +00:00
|
|
|
|
|
|
|
/* Handle specific DSCP values for which the default mapping (as
|
|
|
|
* described above) doesn't adhere to the intended usage of the DSCP
|
|
|
|
* value. See section 4 in RFC8325. Specifically, for the following
|
|
|
|
* Diffserv Service Classes no update is needed:
|
|
|
|
* - Standard: DF
|
|
|
|
* - Low Priority Data: CS1
|
|
|
|
* - Multimedia Conferencing: AF41, AF42, AF43
|
|
|
|
* - Network Control Traffic: CS7
|
|
|
|
* - Real-Time Interactive: CS4
|
2024-08-07 08:22:05 +00:00
|
|
|
* - Signaling: CS5
|
2023-12-18 09:30:05 +00:00
|
|
|
*/
|
|
|
|
switch (dscp >> 2) {
|
|
|
|
case 10:
|
|
|
|
case 12:
|
|
|
|
case 14:
|
|
|
|
/* High throughput data: AF11, AF12, AF13 */
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
/* Operations, Administration, and Maintenance and Provisioning:
|
|
|
|
* CS2
|
|
|
|
*/
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
case 18:
|
|
|
|
case 20:
|
|
|
|
case 22:
|
|
|
|
/* Low latency data: AF21, AF22, AF23 */
|
|
|
|
ret = 3;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
/* Broadcasting video: CS3 */
|
|
|
|
ret = 4;
|
|
|
|
break;
|
2024-08-07 08:22:05 +00:00
|
|
|
case 26:
|
|
|
|
case 28:
|
|
|
|
case 30:
|
|
|
|
/* Multimedia Streaming: AF31, AF32, AF33 */
|
|
|
|
ret = 4;
|
2023-12-18 09:30:05 +00:00
|
|
|
break;
|
|
|
|
case 44:
|
|
|
|
/* Voice Admit: VA */
|
|
|
|
ret = 6;
|
|
|
|
break;
|
|
|
|
case 46:
|
|
|
|
/* Telephony traffic: EF */
|
|
|
|
ret = 6;
|
|
|
|
break;
|
|
|
|
case 48:
|
|
|
|
/* Network Control Traffic: CS6 */
|
|
|
|
ret = 7;
|
|
|
|
break;
|
|
|
|
}
|
2019-02-06 11:17:14 +00:00
|
|
|
out:
|
|
|
|
return array_index_nospec(ret, IEEE80211_NUM_TIDS);
|
2009-05-21 13:47:03 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cfg80211_classify8021d);
|
2009-07-02 15:18:40 +00:00
|
|
|
|
2019-02-07 22:26:38 +00:00
|
|
|
const struct element *ieee80211_bss_get_elem(struct cfg80211_bss *bss, u8 id)
|
2009-07-02 15:18:40 +00:00
|
|
|
{
|
2012-11-29 00:25:20 +00:00
|
|
|
const struct cfg80211_bss_ies *ies;
|
|
|
|
|
|
|
|
ies = rcu_dereference(bss->ies);
|
|
|
|
if (!ies)
|
2009-07-02 15:18:40 +00:00
|
|
|
return NULL;
|
2012-11-29 00:25:20 +00:00
|
|
|
|
2019-02-07 22:26:38 +00:00
|
|
|
return cfg80211_find_elem(id, ies->data, ies->len);
|
2009-07-02 15:18:40 +00:00
|
|
|
}
|
2019-02-07 22:26:38 +00:00
|
|
|
EXPORT_SYMBOL(ieee80211_bss_get_elem);
|
cfg80211: rework key operation
This reworks the key operation in cfg80211, and now only
allows, from userspace, configuring keys (via nl80211)
after the connection has been established (in managed
mode), the IBSS been joined (in IBSS mode), at any time
(in AP[_VLAN] modes) or never for all the other modes.
In order to do shared key authentication correctly, it
is now possible to give a WEP key to the AUTH command.
To configure static WEP keys, these are given to the
CONNECT or IBSS_JOIN command directly, for a userspace
SME it is assumed it will configure it properly after
the connection has been established.
Since mac80211 used to check the default key in IBSS
mode to see whether or not the network is protected,
it needs an update in that area, as well as an update
to make use of the WEP key passed to auth() for shared
key authentication.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-07-08 12:22:54 +00:00
|
|
|
|
|
|
|
void cfg80211_upload_connect_keys(struct wireless_dev *wdev)
|
|
|
|
{
|
2014-04-21 04:53:03 +00:00
|
|
|
struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
|
cfg80211: rework key operation
This reworks the key operation in cfg80211, and now only
allows, from userspace, configuring keys (via nl80211)
after the connection has been established (in managed
mode), the IBSS been joined (in IBSS mode), at any time
(in AP[_VLAN] modes) or never for all the other modes.
In order to do shared key authentication correctly, it
is now possible to give a WEP key to the AUTH command.
To configure static WEP keys, these are given to the
CONNECT or IBSS_JOIN command directly, for a userspace
SME it is assumed it will configure it properly after
the connection has been established.
Since mac80211 used to check the default key in IBSS
mode to see whether or not the network is protected,
it needs an update in that area, as well as an update
to make use of the WEP key passed to auth() for shared
key authentication.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-07-08 12:22:54 +00:00
|
|
|
struct net_device *dev = wdev->netdev;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!wdev->connect_keys)
|
|
|
|
return;
|
|
|
|
|
2023-01-16 14:24:11 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
cfg80211: rework key operation
This reworks the key operation in cfg80211, and now only
allows, from userspace, configuring keys (via nl80211)
after the connection has been established (in managed
mode), the IBSS been joined (in IBSS mode), at any time
(in AP[_VLAN] modes) or never for all the other modes.
In order to do shared key authentication correctly, it
is now possible to give a WEP key to the AUTH command.
To configure static WEP keys, these are given to the
CONNECT or IBSS_JOIN command directly, for a userspace
SME it is assumed it will configure it properly after
the connection has been established.
Since mac80211 used to check the default key in IBSS
mode to see whether or not the network is protected,
it needs an update in that area, as well as an update
to make use of the WEP key passed to auth() for shared
key authentication.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-07-08 12:22:54 +00:00
|
|
|
if (!wdev->connect_keys->params[i].cipher)
|
|
|
|
continue;
|
2022-07-30 05:26:43 +00:00
|
|
|
if (rdev_add_key(rdev, dev, -1, i, false, NULL,
|
2012-06-27 14:19:42 +00:00
|
|
|
&wdev->connect_keys->params[i])) {
|
2010-11-17 03:56:49 +00:00
|
|
|
netdev_err(dev, "failed to set key %d\n", i);
|
2009-07-20 08:12:57 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-02-13 19:53:38 +00:00
|
|
|
if (wdev->connect_keys->def == i &&
|
2022-07-30 05:26:43 +00:00
|
|
|
rdev_set_default_key(rdev, dev, -1, i, true, true)) {
|
2017-02-13 19:53:38 +00:00
|
|
|
netdev_err(dev, "failed to set defkey %d\n", i);
|
|
|
|
continue;
|
|
|
|
}
|
cfg80211: rework key operation
This reworks the key operation in cfg80211, and now only
allows, from userspace, configuring keys (via nl80211)
after the connection has been established (in managed
mode), the IBSS been joined (in IBSS mode), at any time
(in AP[_VLAN] modes) or never for all the other modes.
In order to do shared key authentication correctly, it
is now possible to give a WEP key to the AUTH command.
To configure static WEP keys, these are given to the
CONNECT or IBSS_JOIN command directly, for a userspace
SME it is assumed it will configure it properly after
the connection has been established.
Since mac80211 used to check the default key in IBSS
mode to see whether or not the network is protected,
it needs an update in that area, as well as an update
to make use of the WEP key passed to auth() for shared
key authentication.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-07-08 12:22:54 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 06:18:13 +00:00
|
|
|
kfree_sensitive(wdev->connect_keys);
|
cfg80211: rework key operation
This reworks the key operation in cfg80211, and now only
allows, from userspace, configuring keys (via nl80211)
after the connection has been established (in managed
mode), the IBSS been joined (in IBSS mode), at any time
(in AP[_VLAN] modes) or never for all the other modes.
In order to do shared key authentication correctly, it
is now possible to give a WEP key to the AUTH command.
To configure static WEP keys, these are given to the
CONNECT or IBSS_JOIN command directly, for a userspace
SME it is assumed it will configure it properly after
the connection has been established.
Since mac80211 used to check the default key in IBSS
mode to see whether or not the network is protected,
it needs an update in that area, as well as an update
to make use of the WEP key passed to auth() for shared
key authentication.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-07-08 12:22:54 +00:00
|
|
|
wdev->connect_keys = NULL;
|
|
|
|
}
|
2009-08-21 12:51:05 +00:00
|
|
|
|
2012-08-02 17:41:48 +00:00
|
|
|
void cfg80211_process_wdev_events(struct wireless_dev *wdev)
|
2009-08-21 12:51:05 +00:00
|
|
|
{
|
|
|
|
struct cfg80211_event *ev;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&wdev->event_lock, flags);
|
|
|
|
while (!list_empty(&wdev->event_list)) {
|
|
|
|
ev = list_first_entry(&wdev->event_list,
|
|
|
|
struct cfg80211_event, list);
|
|
|
|
list_del(&ev->list);
|
|
|
|
spin_unlock_irqrestore(&wdev->event_lock, flags);
|
|
|
|
|
|
|
|
switch (ev->type) {
|
|
|
|
case EVENT_CONNECT_RESULT:
|
|
|
|
__cfg80211_connect_result(
|
2017-03-30 21:22:33 +00:00
|
|
|
wdev->netdev,
|
|
|
|
&ev->cr,
|
|
|
|
ev->cr.status == WLAN_STATUS_SUCCESS);
|
2009-08-21 12:51:05 +00:00
|
|
|
break;
|
|
|
|
case EVENT_ROAMED:
|
2017-04-26 07:58:49 +00:00
|
|
|
__cfg80211_roamed(wdev, &ev->rm);
|
2009-08-21 12:51:05 +00:00
|
|
|
break;
|
|
|
|
case EVENT_DISCONNECTED:
|
|
|
|
__cfg80211_disconnected(wdev->netdev,
|
|
|
|
ev->dc.ie, ev->dc.ie_len,
|
2015-05-22 14:22:20 +00:00
|
|
|
ev->dc.reason,
|
|
|
|
!ev->dc.locally_generated);
|
2009-08-21 12:51:05 +00:00
|
|
|
break;
|
|
|
|
case EVENT_IBSS_JOINED:
|
2014-01-29 16:53:43 +00:00
|
|
|
__cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid,
|
|
|
|
ev->ij.channel);
|
2009-08-21 12:51:05 +00:00
|
|
|
break;
|
2014-04-09 13:11:01 +00:00
|
|
|
case EVENT_STOPPED:
|
2023-08-29 10:18:56 +00:00
|
|
|
cfg80211_leave(wiphy_to_rdev(wdev->wiphy), wdev);
|
2014-04-09 13:11:01 +00:00
|
|
|
break;
|
2017-09-29 12:21:49 +00:00
|
|
|
case EVENT_PORT_AUTHORIZED:
|
2023-09-26 10:32:22 +00:00
|
|
|
__cfg80211_port_authorized(wdev, ev->pa.peer_addr,
|
2022-09-07 12:44:48 +00:00
|
|
|
ev->pa.td_bitmap,
|
|
|
|
ev->pa.td_bitmap_len);
|
2017-09-29 12:21:49 +00:00
|
|
|
break;
|
2009-08-21 12:51:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
kfree(ev);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&wdev->event_lock, flags);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&wdev->event_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev)
|
|
|
|
{
|
|
|
|
struct wireless_dev *wdev;
|
|
|
|
|
2021-01-22 15:19:43 +00:00
|
|
|
lockdep_assert_held(&rdev->wiphy.mtx);
|
2009-08-21 12:51:05 +00:00
|
|
|
|
2016-05-03 13:52:04 +00:00
|
|
|
list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list)
|
2009-08-21 12:51:05 +00:00
|
|
|
cfg80211_process_wdev_events(wdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
|
|
|
|
struct net_device *dev, enum nl80211_iftype ntype,
|
2017-04-12 09:23:28 +00:00
|
|
|
struct vif_params *params)
|
2009-08-21 12:51:05 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
enum nl80211_iftype otype = dev->ieee80211_ptr->iftype;
|
|
|
|
|
2021-01-22 15:19:43 +00:00
|
|
|
lockdep_assert_held(&rdev->wiphy.mtx);
|
2009-08-21 12:51:05 +00:00
|
|
|
|
|
|
|
/* don't support changing VLANs, you just re-create them */
|
|
|
|
if (otype == NL80211_IFTYPE_AP_VLAN)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2016-09-20 14:31:13 +00:00
|
|
|
/* cannot change into P2P device or NAN */
|
|
|
|
if (ntype == NL80211_IFTYPE_P2P_DEVICE ||
|
|
|
|
ntype == NL80211_IFTYPE_NAN)
|
2012-06-15 22:19:54 +00:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2009-08-21 12:51:05 +00:00
|
|
|
if (!rdev->ops->change_virtual_intf ||
|
|
|
|
!(rdev->wiphy.interface_modes & (1 << ntype)))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2015-05-22 08:57:22 +00:00
|
|
|
if (ntype != otype) {
|
2021-10-24 20:15:46 +00:00
|
|
|
/* if it's part of a bridge, reject changing type to station/ibss */
|
|
|
|
if (netif_is_bridge_port(dev) &&
|
|
|
|
(ntype == NL80211_IFTYPE_ADHOC ||
|
|
|
|
ntype == NL80211_IFTYPE_STATION ||
|
|
|
|
ntype == NL80211_IFTYPE_P2P_CLIENT))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2009-11-19 10:55:19 +00:00
|
|
|
dev->ieee80211_ptr->use_4addr = false;
|
2013-12-17 07:01:30 +00:00
|
|
|
rdev_set_qos_map(rdev, dev, NULL);
|
2009-11-19 10:55:19 +00:00
|
|
|
|
2009-08-21 12:51:05 +00:00
|
|
|
switch (otype) {
|
2012-06-29 10:46:57 +00:00
|
|
|
case NL80211_IFTYPE_AP:
|
2021-10-27 17:37:22 +00:00
|
|
|
case NL80211_IFTYPE_P2P_GO:
|
2022-04-14 14:50:57 +00:00
|
|
|
cfg80211_stop_ap(rdev, dev, -1, true);
|
2012-06-29 10:46:57 +00:00
|
|
|
break;
|
2009-08-21 12:51:05 +00:00
|
|
|
case NL80211_IFTYPE_ADHOC:
|
|
|
|
cfg80211_leave_ibss(rdev, dev, false);
|
|
|
|
break;
|
|
|
|
case NL80211_IFTYPE_STATION:
|
2010-09-16 12:58:22 +00:00
|
|
|
case NL80211_IFTYPE_P2P_CLIENT:
|
2009-08-21 12:51:05 +00:00
|
|
|
cfg80211_disconnect(rdev, dev,
|
|
|
|
WLAN_REASON_DEAUTH_LEAVING, true);
|
|
|
|
break;
|
|
|
|
case NL80211_IFTYPE_MESH_POINT:
|
|
|
|
/* mesh should be handled? */
|
|
|
|
break;
|
2021-04-28 06:39:41 +00:00
|
|
|
case NL80211_IFTYPE_OCB:
|
|
|
|
cfg80211_leave_ocb(rdev, dev);
|
|
|
|
break;
|
2009-08-21 12:51:05 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg80211_process_rdev_events(rdev);
|
2019-08-28 21:11:10 +00:00
|
|
|
cfg80211_mlme_purge_registrations(dev->ieee80211_ptr);
|
2022-04-14 14:50:57 +00:00
|
|
|
|
|
|
|
memset(&dev->ieee80211_ptr->u, 0,
|
|
|
|
sizeof(dev->ieee80211_ptr->u));
|
|
|
|
memset(&dev->ieee80211_ptr->links, 0,
|
|
|
|
sizeof(dev->ieee80211_ptr->links));
|
2009-08-21 12:51:05 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 09:23:28 +00:00
|
|
|
err = rdev_change_virtual_intf(rdev, dev, ntype, params);
|
2009-08-21 12:51:05 +00:00
|
|
|
|
|
|
|
WARN_ON(!err && dev->ieee80211_ptr->iftype != ntype);
|
|
|
|
|
2009-11-19 10:55:19 +00:00
|
|
|
if (!err && params && params->use_4addr != -1)
|
|
|
|
dev->ieee80211_ptr->use_4addr = params->use_4addr;
|
|
|
|
|
cfg80211: disallow bridging managed/adhoc interfaces
A number of people have tried to add a wireless interface
(in managed mode) to a bridge and then complained that it
doesn't work. It cannot work, however, because in 802.11
networks all packets need to be acknowledged and as such
need to be sent to the right address. Promiscuous doesn't
help here. The wireless address format used for these
links has only space for three addresses, the
* transmitter, which must be equal to the sender (origin)
* receiver (on the wireless medium), which is the AP in
the case of managed mode
* the recipient (destination), which is on the APs local
network segment
In an IBSS, it is similar, but the receiver and recipient
must match and the third address is used as the BSSID.
To avoid such mistakes in the future, disallow adding a
wireless interface to a bridge.
Felix has recently added a four-address mode to the AP
and client side that can be used (after negotiating that
it is possible, which must happen out-of-band by setting
up both sides) for bridging, so allow that case.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Acked-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-11-18 23:56:30 +00:00
|
|
|
if (!err) {
|
|
|
|
dev->priv_flags &= ~IFF_DONT_BRIDGE;
|
|
|
|
switch (ntype) {
|
|
|
|
case NL80211_IFTYPE_STATION:
|
|
|
|
if (dev->ieee80211_ptr->use_4addr)
|
|
|
|
break;
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough;
|
2014-11-03 09:33:18 +00:00
|
|
|
case NL80211_IFTYPE_OCB:
|
2010-09-16 12:58:22 +00:00
|
|
|
case NL80211_IFTYPE_P2P_CLIENT:
|
cfg80211: disallow bridging managed/adhoc interfaces
A number of people have tried to add a wireless interface
(in managed mode) to a bridge and then complained that it
doesn't work. It cannot work, however, because in 802.11
networks all packets need to be acknowledged and as such
need to be sent to the right address. Promiscuous doesn't
help here. The wireless address format used for these
links has only space for three addresses, the
* transmitter, which must be equal to the sender (origin)
* receiver (on the wireless medium), which is the AP in
the case of managed mode
* the recipient (destination), which is on the APs local
network segment
In an IBSS, it is similar, but the receiver and recipient
must match and the third address is used as the BSSID.
To avoid such mistakes in the future, disallow adding a
wireless interface to a bridge.
Felix has recently added a four-address mode to the AP
and client side that can be used (after negotiating that
it is possible, which must happen out-of-band by setting
up both sides) for bridging, so allow that case.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Acked-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-11-18 23:56:30 +00:00
|
|
|
case NL80211_IFTYPE_ADHOC:
|
|
|
|
dev->priv_flags |= IFF_DONT_BRIDGE;
|
|
|
|
break;
|
2010-09-16 12:58:22 +00:00
|
|
|
case NL80211_IFTYPE_P2P_GO:
|
cfg80211: disallow bridging managed/adhoc interfaces
A number of people have tried to add a wireless interface
(in managed mode) to a bridge and then complained that it
doesn't work. It cannot work, however, because in 802.11
networks all packets need to be acknowledged and as such
need to be sent to the right address. Promiscuous doesn't
help here. The wireless address format used for these
links has only space for three addresses, the
* transmitter, which must be equal to the sender (origin)
* receiver (on the wireless medium), which is the AP in
the case of managed mode
* the recipient (destination), which is on the APs local
network segment
In an IBSS, it is similar, but the receiver and recipient
must match and the third address is used as the BSSID.
To avoid such mistakes in the future, disallow adding a
wireless interface to a bridge.
Felix has recently added a four-address mode to the AP
and client side that can be used (after negotiating that
it is possible, which must happen out-of-band by setting
up both sides) for bridging, so allow that case.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Acked-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-11-18 23:56:30 +00:00
|
|
|
case NL80211_IFTYPE_AP:
|
|
|
|
case NL80211_IFTYPE_AP_VLAN:
|
|
|
|
case NL80211_IFTYPE_MESH_POINT:
|
|
|
|
/* bridging OK */
|
|
|
|
break;
|
|
|
|
case NL80211_IFTYPE_MONITOR:
|
|
|
|
/* monitor can't bridge anyway */
|
|
|
|
break;
|
|
|
|
case NL80211_IFTYPE_UNSPECIFIED:
|
2010-08-12 13:38:38 +00:00
|
|
|
case NUM_NL80211_IFTYPES:
|
cfg80211: disallow bridging managed/adhoc interfaces
A number of people have tried to add a wireless interface
(in managed mode) to a bridge and then complained that it
doesn't work. It cannot work, however, because in 802.11
networks all packets need to be acknowledged and as such
need to be sent to the right address. Promiscuous doesn't
help here. The wireless address format used for these
links has only space for three addresses, the
* transmitter, which must be equal to the sender (origin)
* receiver (on the wireless medium), which is the AP in
the case of managed mode
* the recipient (destination), which is on the APs local
network segment
In an IBSS, it is similar, but the receiver and recipient
must match and the third address is used as the BSSID.
To avoid such mistakes in the future, disallow adding a
wireless interface to a bridge.
Felix has recently added a four-address mode to the AP
and client side that can be used (after negotiating that
it is possible, which must happen out-of-band by setting
up both sides) for bridging, so allow that case.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Acked-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-11-18 23:56:30 +00:00
|
|
|
/* not happening */
|
|
|
|
break;
|
2012-06-15 22:19:54 +00:00
|
|
|
case NL80211_IFTYPE_P2P_DEVICE:
|
2020-11-09 09:57:47 +00:00
|
|
|
case NL80211_IFTYPE_WDS:
|
2016-09-20 14:31:13 +00:00
|
|
|
case NL80211_IFTYPE_NAN:
|
2012-06-15 22:19:54 +00:00
|
|
|
WARN_ON(1);
|
|
|
|
break;
|
cfg80211: disallow bridging managed/adhoc interfaces
A number of people have tried to add a wireless interface
(in managed mode) to a bridge and then complained that it
doesn't work. It cannot work, however, because in 802.11
networks all packets need to be acknowledged and as such
need to be sent to the right address. Promiscuous doesn't
help here. The wireless address format used for these
links has only space for three addresses, the
* transmitter, which must be equal to the sender (origin)
* receiver (on the wireless medium), which is the AP in
the case of managed mode
* the recipient (destination), which is on the APs local
network segment
In an IBSS, it is similar, but the receiver and recipient
must match and the third address is used as the BSSID.
To avoid such mistakes in the future, disallow adding a
wireless interface to a bridge.
Felix has recently added a four-address mode to the AP
and client side that can be used (after negotiating that
it is possible, which must happen out-of-band by setting
up both sides) for bridging, so allow that case.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Acked-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-11-18 23:56:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-29 10:47:01 +00:00
|
|
|
if (!err && ntype != otype && netif_running(dev)) {
|
|
|
|
cfg80211_update_iface_num(rdev, ntype, 1);
|
|
|
|
cfg80211_update_iface_num(rdev, otype, -1);
|
|
|
|
}
|
|
|
|
|
2009-08-21 12:51:05 +00:00
|
|
|
return err;
|
|
|
|
}
|
2009-12-09 21:43:52 +00:00
|
|
|
|
2017-02-15 14:02:08 +00:00
|
|
|
static u32 cfg80211_calculate_bitrate_ht(struct rate_info *rate)
|
|
|
|
{
|
|
|
|
int modulation, streams, bitrate;
|
|
|
|
|
|
|
|
/* the formula below does only work for MCS values smaller than 32 */
|
|
|
|
if (WARN_ON_ONCE(rate->mcs >= 32))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
modulation = rate->mcs & 7;
|
|
|
|
streams = (rate->mcs >> 3) + 1;
|
|
|
|
|
|
|
|
bitrate = (rate->bw == RATE_INFO_BW_40) ? 13500000 : 6500000;
|
|
|
|
|
|
|
|
if (modulation < 4)
|
|
|
|
bitrate *= (modulation + 1);
|
|
|
|
else if (modulation == 4)
|
|
|
|
bitrate *= (modulation + 2);
|
|
|
|
else
|
|
|
|
bitrate *= (modulation + 3);
|
|
|
|
|
|
|
|
bitrate *= streams;
|
|
|
|
|
|
|
|
if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
|
|
|
|
bitrate = (bitrate / 9) * 10;
|
|
|
|
|
|
|
|
/* do NOT round down here */
|
|
|
|
return (bitrate + 50000) / 100000;
|
|
|
|
}
|
|
|
|
|
2019-08-18 14:35:17 +00:00
|
|
|
static u32 cfg80211_calculate_bitrate_dmg(struct rate_info *rate)
|
2012-07-05 11:25:50 +00:00
|
|
|
{
|
|
|
|
static const u32 __mcs2bitrate[] = {
|
|
|
|
/* control PHY */
|
|
|
|
[0] = 275,
|
|
|
|
/* SC PHY */
|
|
|
|
[1] = 3850,
|
|
|
|
[2] = 7700,
|
|
|
|
[3] = 9625,
|
|
|
|
[4] = 11550,
|
|
|
|
[5] = 12512, /* 1251.25 mbps */
|
|
|
|
[6] = 15400,
|
|
|
|
[7] = 19250,
|
|
|
|
[8] = 23100,
|
|
|
|
[9] = 25025,
|
|
|
|
[10] = 30800,
|
|
|
|
[11] = 38500,
|
|
|
|
[12] = 46200,
|
|
|
|
/* OFDM PHY */
|
|
|
|
[13] = 6930,
|
|
|
|
[14] = 8662, /* 866.25 mbps */
|
|
|
|
[15] = 13860,
|
|
|
|
[16] = 17325,
|
|
|
|
[17] = 20790,
|
|
|
|
[18] = 27720,
|
|
|
|
[19] = 34650,
|
|
|
|
[20] = 41580,
|
|
|
|
[21] = 45045,
|
|
|
|
[22] = 51975,
|
|
|
|
[23] = 62370,
|
|
|
|
[24] = 67568, /* 6756.75 mbps */
|
|
|
|
/* LP-SC PHY */
|
|
|
|
[25] = 6260,
|
|
|
|
[26] = 8340,
|
|
|
|
[27] = 11120,
|
|
|
|
[28] = 12510,
|
|
|
|
[29] = 16680,
|
|
|
|
[30] = 22240,
|
|
|
|
[31] = 25030,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (WARN_ON_ONCE(rate->mcs >= ARRAY_SIZE(__mcs2bitrate)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return __mcs2bitrate[rate->mcs];
|
|
|
|
}
|
|
|
|
|
2021-01-06 23:50:49 +00:00
|
|
|
static u32 cfg80211_calculate_bitrate_extended_sc_dmg(struct rate_info *rate)
|
|
|
|
{
|
|
|
|
static const u32 __mcs2bitrate[] = {
|
|
|
|
[6 - 6] = 26950, /* MCS 9.1 : 2695.0 mbps */
|
|
|
|
[7 - 6] = 50050, /* MCS 12.1 */
|
|
|
|
[8 - 6] = 53900,
|
|
|
|
[9 - 6] = 57750,
|
|
|
|
[10 - 6] = 63900,
|
|
|
|
[11 - 6] = 75075,
|
|
|
|
[12 - 6] = 80850,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Extended SC MCS not defined for base MCS below 6 or above 12 */
|
|
|
|
if (WARN_ON_ONCE(rate->mcs < 6 || rate->mcs > 12))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return __mcs2bitrate[rate->mcs - 6];
|
|
|
|
}
|
|
|
|
|
2019-08-18 14:35:17 +00:00
|
|
|
static u32 cfg80211_calculate_bitrate_edmg(struct rate_info *rate)
|
|
|
|
{
|
|
|
|
static const u32 __mcs2bitrate[] = {
|
|
|
|
/* control PHY */
|
|
|
|
[0] = 275,
|
|
|
|
/* SC PHY */
|
|
|
|
[1] = 3850,
|
|
|
|
[2] = 7700,
|
|
|
|
[3] = 9625,
|
|
|
|
[4] = 11550,
|
|
|
|
[5] = 12512, /* 1251.25 mbps */
|
|
|
|
[6] = 13475,
|
|
|
|
[7] = 15400,
|
|
|
|
[8] = 19250,
|
|
|
|
[9] = 23100,
|
|
|
|
[10] = 25025,
|
|
|
|
[11] = 26950,
|
|
|
|
[12] = 30800,
|
|
|
|
[13] = 38500,
|
|
|
|
[14] = 46200,
|
|
|
|
[15] = 50050,
|
|
|
|
[16] = 53900,
|
|
|
|
[17] = 57750,
|
|
|
|
[18] = 69300,
|
|
|
|
[19] = 75075,
|
|
|
|
[20] = 80850,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (WARN_ON_ONCE(rate->mcs >= ARRAY_SIZE(__mcs2bitrate)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return __mcs2bitrate[rate->mcs] * rate->n_bonded_ch;
|
|
|
|
}
|
|
|
|
|
2012-11-09 13:56:41 +00:00
|
|
|
static u32 cfg80211_calculate_bitrate_vht(struct rate_info *rate)
|
|
|
|
{
|
2021-01-05 10:58:39 +00:00
|
|
|
static const u32 base[4][12] = {
|
2012-11-09 13:56:41 +00:00
|
|
|
{ 6500000,
|
|
|
|
13000000,
|
|
|
|
19500000,
|
|
|
|
26000000,
|
|
|
|
39000000,
|
|
|
|
52000000,
|
|
|
|
58500000,
|
|
|
|
65000000,
|
|
|
|
78000000,
|
2016-10-31 18:28:40 +00:00
|
|
|
/* not in the spec, but some devices use this: */
|
2021-01-05 10:58:39 +00:00
|
|
|
86700000,
|
|
|
|
97500000,
|
|
|
|
108300000,
|
2012-11-09 13:56:41 +00:00
|
|
|
},
|
|
|
|
{ 13500000,
|
|
|
|
27000000,
|
|
|
|
40500000,
|
|
|
|
54000000,
|
|
|
|
81000000,
|
|
|
|
108000000,
|
|
|
|
121500000,
|
|
|
|
135000000,
|
|
|
|
162000000,
|
|
|
|
180000000,
|
2021-01-05 10:58:39 +00:00
|
|
|
202500000,
|
|
|
|
225000000,
|
2012-11-09 13:56:41 +00:00
|
|
|
},
|
|
|
|
{ 29300000,
|
|
|
|
58500000,
|
|
|
|
87800000,
|
|
|
|
117000000,
|
|
|
|
175500000,
|
|
|
|
234000000,
|
|
|
|
263300000,
|
|
|
|
292500000,
|
|
|
|
351000000,
|
|
|
|
390000000,
|
2021-01-05 10:58:39 +00:00
|
|
|
438800000,
|
|
|
|
487500000,
|
2012-11-09 13:56:41 +00:00
|
|
|
},
|
|
|
|
{ 58500000,
|
|
|
|
117000000,
|
|
|
|
175500000,
|
|
|
|
234000000,
|
|
|
|
351000000,
|
|
|
|
468000000,
|
|
|
|
526500000,
|
|
|
|
585000000,
|
|
|
|
702000000,
|
|
|
|
780000000,
|
2021-01-05 10:58:39 +00:00
|
|
|
877500000,
|
|
|
|
975000000,
|
2012-11-09 13:56:41 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
u32 bitrate;
|
|
|
|
int idx;
|
|
|
|
|
2021-01-05 10:58:39 +00:00
|
|
|
if (rate->mcs > 11)
|
2017-05-04 05:52:10 +00:00
|
|
|
goto warn;
|
2012-11-09 13:56:41 +00:00
|
|
|
|
2015-01-15 15:14:02 +00:00
|
|
|
switch (rate->bw) {
|
|
|
|
case RATE_INFO_BW_160:
|
|
|
|
idx = 3;
|
|
|
|
break;
|
|
|
|
case RATE_INFO_BW_80:
|
|
|
|
idx = 2;
|
|
|
|
break;
|
|
|
|
case RATE_INFO_BW_40:
|
|
|
|
idx = 1;
|
|
|
|
break;
|
|
|
|
case RATE_INFO_BW_5:
|
|
|
|
case RATE_INFO_BW_10:
|
|
|
|
default:
|
2017-05-04 05:52:10 +00:00
|
|
|
goto warn;
|
2015-01-15 15:14:02 +00:00
|
|
|
case RATE_INFO_BW_20:
|
|
|
|
idx = 0;
|
|
|
|
}
|
2012-11-09 13:56:41 +00:00
|
|
|
|
|
|
|
bitrate = base[idx][rate->mcs];
|
|
|
|
bitrate *= rate->nss;
|
|
|
|
|
|
|
|
if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
|
|
|
|
bitrate = (bitrate / 9) * 10;
|
|
|
|
|
|
|
|
/* do NOT round down here */
|
|
|
|
return (bitrate + 50000) / 100000;
|
2017-05-04 05:52:10 +00:00
|
|
|
warn:
|
|
|
|
WARN_ONCE(1, "invalid rate bw=%d, mcs=%d, nss=%d\n",
|
|
|
|
rate->bw, rate->mcs, rate->nss);
|
|
|
|
return 0;
|
2012-11-09 13:56:41 +00:00
|
|
|
}
|
|
|
|
|
2018-06-09 06:14:42 +00:00
|
|
|
static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate)
|
|
|
|
{
|
2020-10-29 18:34:57 +00:00
|
|
|
#define SCALE 6144
|
|
|
|
u32 mcs_divisors[14] = {
|
|
|
|
102399, /* 16.666666... */
|
|
|
|
51201, /* 8.333333... */
|
|
|
|
34134, /* 5.555555... */
|
|
|
|
25599, /* 4.166666... */
|
|
|
|
17067, /* 2.777777... */
|
|
|
|
12801, /* 2.083333... */
|
2022-09-08 18:10:34 +00:00
|
|
|
11377, /* 1.851725... */
|
2020-10-29 18:34:57 +00:00
|
|
|
10239, /* 1.666666... */
|
|
|
|
8532, /* 1.388888... */
|
|
|
|
7680, /* 1.250000... */
|
|
|
|
6828, /* 1.111111... */
|
|
|
|
6144, /* 1.000000... */
|
|
|
|
5690, /* 0.926106... */
|
|
|
|
5120, /* 0.833333... */
|
2018-06-09 06:14:42 +00:00
|
|
|
};
|
|
|
|
u32 rates_160M[3] = { 960777777, 907400000, 816666666 };
|
2024-06-06 02:06:52 +00:00
|
|
|
u32 rates_996[3] = { 480388888, 453700000, 408333333 };
|
2018-06-09 06:14:42 +00:00
|
|
|
u32 rates_484[3] = { 229411111, 216666666, 195000000 };
|
|
|
|
u32 rates_242[3] = { 114711111, 108333333, 97500000 };
|
|
|
|
u32 rates_106[3] = { 40000000, 37777777, 34000000 };
|
|
|
|
u32 rates_52[3] = { 18820000, 17777777, 16000000 };
|
|
|
|
u32 rates_26[3] = { 9411111, 8888888, 8000000 };
|
|
|
|
u64 tmp;
|
|
|
|
u32 result;
|
|
|
|
|
2020-10-29 18:34:57 +00:00
|
|
|
if (WARN_ON_ONCE(rate->mcs > 13))
|
2018-06-09 06:14:42 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (WARN_ON_ONCE(rate->he_gi > NL80211_RATE_INFO_HE_GI_3_2))
|
|
|
|
return 0;
|
|
|
|
if (WARN_ON_ONCE(rate->he_ru_alloc >
|
|
|
|
NL80211_RATE_INFO_HE_RU_ALLOC_2x996))
|
|
|
|
return 0;
|
|
|
|
if (WARN_ON_ONCE(rate->nss < 1 || rate->nss > 8))
|
|
|
|
return 0;
|
|
|
|
|
2024-06-06 02:06:53 +00:00
|
|
|
if (rate->bw == RATE_INFO_BW_160 ||
|
|
|
|
(rate->bw == RATE_INFO_BW_HE_RU &&
|
|
|
|
rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_2x996))
|
2018-06-09 06:14:42 +00:00
|
|
|
result = rates_160M[rate->he_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_80 ||
|
|
|
|
(rate->bw == RATE_INFO_BW_HE_RU &&
|
|
|
|
rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_996))
|
2024-06-06 02:06:52 +00:00
|
|
|
result = rates_996[rate->he_gi];
|
2018-06-09 06:14:42 +00:00
|
|
|
else if (rate->bw == RATE_INFO_BW_40 ||
|
|
|
|
(rate->bw == RATE_INFO_BW_HE_RU &&
|
|
|
|
rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_484))
|
|
|
|
result = rates_484[rate->he_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_20 ||
|
|
|
|
(rate->bw == RATE_INFO_BW_HE_RU &&
|
|
|
|
rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_242))
|
|
|
|
result = rates_242[rate->he_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_HE_RU &&
|
|
|
|
rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_106)
|
|
|
|
result = rates_106[rate->he_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_HE_RU &&
|
|
|
|
rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_52)
|
|
|
|
result = rates_52[rate->he_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_HE_RU &&
|
|
|
|
rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_26)
|
|
|
|
result = rates_26[rate->he_gi];
|
2019-03-07 23:57:35 +00:00
|
|
|
else {
|
|
|
|
WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
|
|
|
|
rate->bw, rate->he_ru_alloc);
|
2018-06-09 06:14:42 +00:00
|
|
|
return 0;
|
2019-03-07 23:57:35 +00:00
|
|
|
}
|
2018-06-09 06:14:42 +00:00
|
|
|
|
|
|
|
/* now scale to the appropriate MCS */
|
|
|
|
tmp = result;
|
|
|
|
tmp *= SCALE;
|
|
|
|
do_div(tmp, mcs_divisors[rate->mcs]);
|
|
|
|
result = tmp;
|
|
|
|
|
|
|
|
/* and take NSS, DCM into account */
|
|
|
|
result = (result * rate->nss) / 8;
|
|
|
|
if (rate->he_dcm)
|
|
|
|
result /= 2;
|
|
|
|
|
2019-05-23 08:27:24 +00:00
|
|
|
return result / 10000;
|
2018-06-09 06:14:42 +00:00
|
|
|
}
|
|
|
|
|
2022-02-14 16:29:55 +00:00
|
|
|
static u32 cfg80211_calculate_bitrate_eht(struct rate_info *rate)
|
|
|
|
{
|
|
|
|
#define SCALE 6144
|
|
|
|
static const u32 mcs_divisors[16] = {
|
|
|
|
102399, /* 16.666666... */
|
|
|
|
51201, /* 8.333333... */
|
|
|
|
34134, /* 5.555555... */
|
|
|
|
25599, /* 4.166666... */
|
|
|
|
17067, /* 2.777777... */
|
|
|
|
12801, /* 2.083333... */
|
2022-09-08 18:10:34 +00:00
|
|
|
11377, /* 1.851725... */
|
2022-02-14 16:29:55 +00:00
|
|
|
10239, /* 1.666666... */
|
|
|
|
8532, /* 1.388888... */
|
|
|
|
7680, /* 1.250000... */
|
|
|
|
6828, /* 1.111111... */
|
|
|
|
6144, /* 1.000000... */
|
|
|
|
5690, /* 0.926106... */
|
|
|
|
5120, /* 0.833333... */
|
|
|
|
409600, /* 66.666666... */
|
|
|
|
204800, /* 33.333333... */
|
|
|
|
};
|
|
|
|
static const u32 rates_996[3] = { 480388888, 453700000, 408333333 };
|
|
|
|
static const u32 rates_484[3] = { 229411111, 216666666, 195000000 };
|
|
|
|
static const u32 rates_242[3] = { 114711111, 108333333, 97500000 };
|
|
|
|
static const u32 rates_106[3] = { 40000000, 37777777, 34000000 };
|
|
|
|
static const u32 rates_52[3] = { 18820000, 17777777, 16000000 };
|
|
|
|
static const u32 rates_26[3] = { 9411111, 8888888, 8000000 };
|
|
|
|
u64 tmp;
|
|
|
|
u32 result;
|
|
|
|
|
|
|
|
if (WARN_ON_ONCE(rate->mcs > 15))
|
|
|
|
return 0;
|
|
|
|
if (WARN_ON_ONCE(rate->eht_gi > NL80211_RATE_INFO_EHT_GI_3_2))
|
|
|
|
return 0;
|
|
|
|
if (WARN_ON_ONCE(rate->eht_ru_alloc >
|
|
|
|
NL80211_RATE_INFO_EHT_RU_ALLOC_4x996))
|
|
|
|
return 0;
|
|
|
|
if (WARN_ON_ONCE(rate->nss < 1 || rate->nss > 8))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Bandwidth checks for MCS 14 */
|
|
|
|
if (rate->mcs == 14) {
|
|
|
|
if ((rate->bw != RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->bw != RATE_INFO_BW_80 &&
|
|
|
|
rate->bw != RATE_INFO_BW_160 &&
|
|
|
|
rate->bw != RATE_INFO_BW_320) ||
|
|
|
|
(rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc != NL80211_RATE_INFO_EHT_RU_ALLOC_996 &&
|
|
|
|
rate->eht_ru_alloc != NL80211_RATE_INFO_EHT_RU_ALLOC_2x996 &&
|
|
|
|
rate->eht_ru_alloc != NL80211_RATE_INFO_EHT_RU_ALLOC_4x996)) {
|
|
|
|
WARN(1, "invalid EHT BW for MCS 14: bw:%d, ru:%d\n",
|
|
|
|
rate->bw, rate->eht_ru_alloc);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rate->bw == RATE_INFO_BW_320 ||
|
|
|
|
(rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_4x996))
|
|
|
|
result = 4 * rates_996[rate->eht_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_3x996P484)
|
|
|
|
result = 3 * rates_996[rate->eht_gi] + rates_484[rate->eht_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_3x996)
|
|
|
|
result = 3 * rates_996[rate->eht_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_2x996P484)
|
|
|
|
result = 2 * rates_996[rate->eht_gi] + rates_484[rate->eht_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_160 ||
|
|
|
|
(rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_2x996))
|
|
|
|
result = 2 * rates_996[rate->eht_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc ==
|
|
|
|
NL80211_RATE_INFO_EHT_RU_ALLOC_996P484P242)
|
|
|
|
result = rates_996[rate->eht_gi] + rates_484[rate->eht_gi]
|
|
|
|
+ rates_242[rate->eht_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_996P484)
|
|
|
|
result = rates_996[rate->eht_gi] + rates_484[rate->eht_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_80 ||
|
|
|
|
(rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_996))
|
|
|
|
result = rates_996[rate->eht_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_484P242)
|
|
|
|
result = rates_484[rate->eht_gi] + rates_242[rate->eht_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_40 ||
|
|
|
|
(rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_484))
|
|
|
|
result = rates_484[rate->eht_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_20 ||
|
|
|
|
(rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_242))
|
|
|
|
result = rates_242[rate->eht_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_106P26)
|
|
|
|
result = rates_106[rate->eht_gi] + rates_26[rate->eht_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_106)
|
|
|
|
result = rates_106[rate->eht_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_52P26)
|
|
|
|
result = rates_52[rate->eht_gi] + rates_26[rate->eht_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_52)
|
|
|
|
result = rates_52[rate->eht_gi];
|
|
|
|
else if (rate->bw == RATE_INFO_BW_EHT_RU &&
|
|
|
|
rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_26)
|
|
|
|
result = rates_26[rate->eht_gi];
|
|
|
|
else {
|
|
|
|
WARN(1, "invalid EHT MCS: bw:%d, ru:%d\n",
|
|
|
|
rate->bw, rate->eht_ru_alloc);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now scale to the appropriate MCS */
|
|
|
|
tmp = result;
|
|
|
|
tmp *= SCALE;
|
|
|
|
do_div(tmp, mcs_divisors[rate->mcs]);
|
|
|
|
|
|
|
|
/* and take NSS */
|
wifi: cfg80211: Fix bitrates overflow issue
When invoking function cfg80211_calculate_bitrate_eht about
(320 MHz, EHT-MCS 13, EHT-NSS 2, EHT-GI 0), which means the
parameters as flags: 0x80, bw: 7, mcs: 13, eht_gi: 0, nss: 2,
this formula (result * rate->nss) will overflow and causes
the returned bitrate to be 3959 when it should be 57646.
Here is the explanation:
u64 tmp;
u32 result;
…
/* tmp = result = 4 * rates_996[0]
* = 4 * 480388888 = 0x72889c60
*/
tmp = result;
/* tmp = 0x72889c60 * 6144 = 0xabccea90000 */
tmp *= SCALE;
/* tmp = 0xabccea90000 / mcs_divisors[13]
* = 0xabccea90000 / 5120 = 0x8970bba6
*/
do_div(tmp, mcs_divisors[rate->mcs]);
/* result = 0x8970bba6 */
result = tmp;
/* normally (result * rate->nss) = 0x8970bba6 * 2 = 0x112e1774c,
* but since result is u32, (result * rate->nss) = 0x12e1774c,
* overflow happens and it loses the highest bit.
* Then result = 0x12e1774c / 8 = 39595753,
*/
result = (result * rate->nss) / 8;
Signed-off-by: Paul Zhang <quic_paulz@quicinc.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
2022-10-11 13:04:28 +00:00
|
|
|
tmp *= rate->nss;
|
|
|
|
do_div(tmp, 8);
|
|
|
|
|
|
|
|
result = tmp;
|
2022-02-14 16:29:55 +00:00
|
|
|
|
|
|
|
return result / 10000;
|
|
|
|
}
|
|
|
|
|
2023-05-18 00:07:23 +00:00
|
|
|
static u32 cfg80211_calculate_bitrate_s1g(struct rate_info *rate)
|
|
|
|
{
|
|
|
|
/* For 1, 2, 4, 8 and 16 MHz channels */
|
|
|
|
static const u32 base[5][11] = {
|
|
|
|
{ 300000,
|
|
|
|
600000,
|
|
|
|
900000,
|
|
|
|
1200000,
|
|
|
|
1800000,
|
|
|
|
2400000,
|
|
|
|
2700000,
|
|
|
|
3000000,
|
|
|
|
3600000,
|
|
|
|
4000000,
|
|
|
|
/* MCS 10 supported in 1 MHz only */
|
|
|
|
150000,
|
|
|
|
},
|
|
|
|
{ 650000,
|
|
|
|
1300000,
|
|
|
|
1950000,
|
|
|
|
2600000,
|
|
|
|
3900000,
|
|
|
|
5200000,
|
|
|
|
5850000,
|
|
|
|
6500000,
|
|
|
|
7800000,
|
|
|
|
/* MCS 9 not valid */
|
|
|
|
},
|
|
|
|
{ 1350000,
|
|
|
|
2700000,
|
|
|
|
4050000,
|
|
|
|
5400000,
|
|
|
|
8100000,
|
|
|
|
10800000,
|
|
|
|
12150000,
|
|
|
|
13500000,
|
|
|
|
16200000,
|
|
|
|
18000000,
|
|
|
|
},
|
|
|
|
{ 2925000,
|
|
|
|
5850000,
|
|
|
|
8775000,
|
|
|
|
11700000,
|
|
|
|
17550000,
|
|
|
|
23400000,
|
|
|
|
26325000,
|
|
|
|
29250000,
|
|
|
|
35100000,
|
|
|
|
39000000,
|
|
|
|
},
|
|
|
|
{ 8580000,
|
|
|
|
11700000,
|
|
|
|
17550000,
|
|
|
|
23400000,
|
|
|
|
35100000,
|
|
|
|
46800000,
|
|
|
|
52650000,
|
|
|
|
58500000,
|
|
|
|
70200000,
|
|
|
|
78000000,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
u32 bitrate;
|
|
|
|
/* default is 1 MHz index */
|
|
|
|
int idx = 0;
|
|
|
|
|
|
|
|
if (rate->mcs >= 11)
|
|
|
|
goto warn;
|
|
|
|
|
|
|
|
switch (rate->bw) {
|
|
|
|
case RATE_INFO_BW_16:
|
|
|
|
idx = 4;
|
|
|
|
break;
|
|
|
|
case RATE_INFO_BW_8:
|
|
|
|
idx = 3;
|
|
|
|
break;
|
|
|
|
case RATE_INFO_BW_4:
|
|
|
|
idx = 2;
|
|
|
|
break;
|
|
|
|
case RATE_INFO_BW_2:
|
|
|
|
idx = 1;
|
|
|
|
break;
|
|
|
|
case RATE_INFO_BW_1:
|
|
|
|
idx = 0;
|
|
|
|
break;
|
|
|
|
case RATE_INFO_BW_5:
|
|
|
|
case RATE_INFO_BW_10:
|
|
|
|
case RATE_INFO_BW_20:
|
|
|
|
case RATE_INFO_BW_40:
|
|
|
|
case RATE_INFO_BW_80:
|
|
|
|
case RATE_INFO_BW_160:
|
|
|
|
default:
|
|
|
|
goto warn;
|
|
|
|
}
|
|
|
|
|
|
|
|
bitrate = base[idx][rate->mcs];
|
|
|
|
bitrate *= rate->nss;
|
|
|
|
|
|
|
|
if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
|
|
|
|
bitrate = (bitrate / 9) * 10;
|
|
|
|
/* do NOT round down here */
|
|
|
|
return (bitrate + 50000) / 100000;
|
|
|
|
warn:
|
|
|
|
WARN_ONCE(1, "invalid rate bw=%d, mcs=%d, nss=%d\n",
|
|
|
|
rate->bw, rate->mcs, rate->nss);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-05 11:25:49 +00:00
|
|
|
u32 cfg80211_calculate_bitrate(struct rate_info *rate)
|
2009-12-09 21:43:52 +00:00
|
|
|
{
|
2017-02-15 14:02:08 +00:00
|
|
|
if (rate->flags & RATE_INFO_FLAGS_MCS)
|
|
|
|
return cfg80211_calculate_bitrate_ht(rate);
|
2019-08-18 14:35:17 +00:00
|
|
|
if (rate->flags & RATE_INFO_FLAGS_DMG)
|
|
|
|
return cfg80211_calculate_bitrate_dmg(rate);
|
2021-01-06 23:50:49 +00:00
|
|
|
if (rate->flags & RATE_INFO_FLAGS_EXTENDED_SC_DMG)
|
|
|
|
return cfg80211_calculate_bitrate_extended_sc_dmg(rate);
|
2019-08-18 14:35:17 +00:00
|
|
|
if (rate->flags & RATE_INFO_FLAGS_EDMG)
|
|
|
|
return cfg80211_calculate_bitrate_edmg(rate);
|
2012-11-09 13:56:41 +00:00
|
|
|
if (rate->flags & RATE_INFO_FLAGS_VHT_MCS)
|
|
|
|
return cfg80211_calculate_bitrate_vht(rate);
|
2018-06-09 06:14:42 +00:00
|
|
|
if (rate->flags & RATE_INFO_FLAGS_HE_MCS)
|
|
|
|
return cfg80211_calculate_bitrate_he(rate);
|
2022-02-14 16:29:55 +00:00
|
|
|
if (rate->flags & RATE_INFO_FLAGS_EHT_MCS)
|
|
|
|
return cfg80211_calculate_bitrate_eht(rate);
|
2023-05-18 00:07:23 +00:00
|
|
|
if (rate->flags & RATE_INFO_FLAGS_S1G_MCS)
|
|
|
|
return cfg80211_calculate_bitrate_s1g(rate);
|
2009-12-09 21:43:52 +00:00
|
|
|
|
2017-02-15 14:02:08 +00:00
|
|
|
return rate->legacy;
|
2009-12-09 21:43:52 +00:00
|
|
|
}
|
2012-03-05 23:31:47 +00:00
|
|
|
EXPORT_SYMBOL(cfg80211_calculate_bitrate);
|
2011-05-09 16:41:15 +00:00
|
|
|
|
2012-11-25 18:13:28 +00:00
|
|
|
int cfg80211_get_p2p_attr(const u8 *ies, unsigned int len,
|
|
|
|
enum ieee80211_p2p_attr_id attr,
|
|
|
|
u8 *buf, unsigned int bufsize)
|
2012-10-29 18:48:40 +00:00
|
|
|
{
|
|
|
|
u8 *out = buf;
|
|
|
|
u16 attr_remaining = 0;
|
|
|
|
bool desired_attr = false;
|
|
|
|
u16 desired_len = 0;
|
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
unsigned int iedatalen;
|
|
|
|
unsigned int copy;
|
|
|
|
const u8 *iedata;
|
|
|
|
|
|
|
|
if (len < 2)
|
|
|
|
return -EILSEQ;
|
|
|
|
iedatalen = ies[1];
|
|
|
|
if (iedatalen + 2 > len)
|
|
|
|
return -EILSEQ;
|
|
|
|
|
|
|
|
if (ies[0] != WLAN_EID_VENDOR_SPECIFIC)
|
|
|
|
goto cont;
|
|
|
|
|
|
|
|
if (iedatalen < 4)
|
|
|
|
goto cont;
|
|
|
|
|
|
|
|
iedata = ies + 2;
|
|
|
|
|
|
|
|
/* check WFA OUI, P2P subtype */
|
|
|
|
if (iedata[0] != 0x50 || iedata[1] != 0x6f ||
|
|
|
|
iedata[2] != 0x9a || iedata[3] != 0x09)
|
|
|
|
goto cont;
|
|
|
|
|
|
|
|
iedatalen -= 4;
|
|
|
|
iedata += 4;
|
|
|
|
|
|
|
|
/* check attribute continuation into this IE */
|
|
|
|
copy = min_t(unsigned int, attr_remaining, iedatalen);
|
|
|
|
if (copy && desired_attr) {
|
|
|
|
desired_len += copy;
|
|
|
|
if (out) {
|
|
|
|
memcpy(out, iedata, min(bufsize, copy));
|
|
|
|
out += min(bufsize, copy);
|
|
|
|
bufsize -= min(bufsize, copy);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (copy == attr_remaining)
|
|
|
|
return desired_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
attr_remaining -= copy;
|
|
|
|
if (attr_remaining)
|
|
|
|
goto cont;
|
|
|
|
|
|
|
|
iedatalen -= copy;
|
|
|
|
iedata += copy;
|
|
|
|
|
|
|
|
while (iedatalen > 0) {
|
|
|
|
u16 attr_len;
|
|
|
|
|
|
|
|
/* P2P attribute ID & size must fit */
|
|
|
|
if (iedatalen < 3)
|
|
|
|
return -EILSEQ;
|
|
|
|
desired_attr = iedata[0] == attr;
|
|
|
|
attr_len = get_unaligned_le16(iedata + 1);
|
|
|
|
iedatalen -= 3;
|
|
|
|
iedata += 3;
|
|
|
|
|
|
|
|
copy = min_t(unsigned int, attr_len, iedatalen);
|
|
|
|
|
|
|
|
if (desired_attr) {
|
|
|
|
desired_len += copy;
|
|
|
|
if (out) {
|
|
|
|
memcpy(out, iedata, min(bufsize, copy));
|
|
|
|
out += min(bufsize, copy);
|
|
|
|
bufsize -= min(bufsize, copy);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copy == attr_len)
|
|
|
|
return desired_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
iedata += copy;
|
|
|
|
iedatalen -= copy;
|
|
|
|
attr_remaining = attr_len - copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
cont:
|
|
|
|
len -= ies[1] + 2;
|
|
|
|
ies += ies[1] + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr_remaining && desired_attr)
|
|
|
|
return -EILSEQ;
|
|
|
|
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cfg80211_get_p2p_attr);
|
|
|
|
|
2017-08-05 08:44:31 +00:00
|
|
|
static bool ieee80211_id_in_list(const u8 *ids, int n_ids, u8 id, bool id_ext)
|
2015-03-31 13:36:22 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2017-08-05 08:44:31 +00:00
|
|
|
/* Make sure array values are legal */
|
|
|
|
if (WARN_ON(ids[n_ids - 1] == WLAN_EID_EXTENSION))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < n_ids) {
|
|
|
|
if (ids[i] == WLAN_EID_EXTENSION) {
|
|
|
|
if (id_ext && (ids[i + 1] == id))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
i += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ids[i] == id && !id_ext)
|
2015-03-31 13:36:22 +00:00
|
|
|
return true;
|
2017-08-05 08:44:31 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2015-03-31 13:36:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-04 18:03:23 +00:00
|
|
|
static size_t skip_ie(const u8 *ies, size_t ielen, size_t pos)
|
|
|
|
{
|
|
|
|
/* we assume a validly formed IEs buffer */
|
|
|
|
u8 len = ies[pos + 1];
|
|
|
|
|
|
|
|
pos += 2 + len;
|
|
|
|
|
|
|
|
/* the IE itself must have 255 bytes for fragments to follow */
|
|
|
|
if (len < 255)
|
|
|
|
return pos;
|
|
|
|
|
|
|
|
while (pos < ielen && ies[pos] == WLAN_EID_FRAGMENT) {
|
|
|
|
len = ies[pos + 1];
|
|
|
|
pos += 2 + len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2015-03-31 13:36:22 +00:00
|
|
|
size_t ieee80211_ie_split_ric(const u8 *ies, size_t ielen,
|
|
|
|
const u8 *ids, int n_ids,
|
|
|
|
const u8 *after_ric, int n_after_ric,
|
|
|
|
size_t offset)
|
|
|
|
{
|
|
|
|
size_t pos = offset;
|
|
|
|
|
2017-08-05 08:44:31 +00:00
|
|
|
while (pos < ielen) {
|
|
|
|
u8 ext = 0;
|
|
|
|
|
|
|
|
if (ies[pos] == WLAN_EID_EXTENSION)
|
|
|
|
ext = 2;
|
|
|
|
if ((pos + ext) >= ielen)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!ieee80211_id_in_list(ids, n_ids, ies[pos + ext],
|
|
|
|
ies[pos] == WLAN_EID_EXTENSION))
|
|
|
|
break;
|
|
|
|
|
2015-03-31 13:36:22 +00:00
|
|
|
if (ies[pos] == WLAN_EID_RIC_DATA && n_after_ric) {
|
2015-09-04 18:03:23 +00:00
|
|
|
pos = skip_ie(ies, ielen, pos);
|
2015-03-31 13:36:22 +00:00
|
|
|
|
2017-08-05 08:44:31 +00:00
|
|
|
while (pos < ielen) {
|
|
|
|
if (ies[pos] == WLAN_EID_EXTENSION)
|
|
|
|
ext = 2;
|
|
|
|
else
|
|
|
|
ext = 0;
|
|
|
|
|
|
|
|
if ((pos + ext) >= ielen)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!ieee80211_id_in_list(after_ric,
|
|
|
|
n_after_ric,
|
|
|
|
ies[pos + ext],
|
|
|
|
ext == 2))
|
|
|
|
pos = skip_ie(ies, ielen, pos);
|
2018-12-05 10:55:54 +00:00
|
|
|
else
|
|
|
|
break;
|
2017-08-05 08:44:31 +00:00
|
|
|
}
|
2015-03-31 13:36:22 +00:00
|
|
|
} else {
|
2015-09-04 18:03:23 +00:00
|
|
|
pos = skip_ie(ies, ielen, pos);
|
2015-03-31 13:36:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee80211_ie_split_ric);
|
|
|
|
|
2023-08-27 11:05:22 +00:00
|
|
|
void ieee80211_fragment_element(struct sk_buff *skb, u8 *len_pos, u8 frag_id)
|
|
|
|
{
|
|
|
|
unsigned int elem_len;
|
|
|
|
|
|
|
|
if (!len_pos)
|
|
|
|
return;
|
|
|
|
|
|
|
|
elem_len = skb->data + skb->len - len_pos - 1;
|
|
|
|
|
|
|
|
while (elem_len > 255) {
|
|
|
|
/* this one is 255 */
|
|
|
|
*len_pos = 255;
|
|
|
|
/* remaining data gets smaller */
|
|
|
|
elem_len -= 255;
|
|
|
|
/* make space for the fragment ID/len in SKB */
|
|
|
|
skb_put(skb, 2);
|
|
|
|
/* shift back the remaining data to place fragment ID/len */
|
|
|
|
memmove(len_pos + 255 + 3, len_pos + 255 + 1, elem_len);
|
|
|
|
/* place the fragment ID */
|
|
|
|
len_pos += 255 + 1;
|
|
|
|
*len_pos = frag_id;
|
|
|
|
/* and point to fragment length to update later */
|
|
|
|
len_pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*len_pos = elem_len;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee80211_fragment_element);
|
|
|
|
|
2012-08-01 15:00:55 +00:00
|
|
|
bool ieee80211_operating_class_to_band(u8 operating_class,
|
2016-04-12 13:56:15 +00:00
|
|
|
enum nl80211_band *band)
|
2012-08-01 15:00:55 +00:00
|
|
|
{
|
|
|
|
switch (operating_class) {
|
|
|
|
case 112:
|
|
|
|
case 115 ... 127:
|
2015-03-01 07:10:01 +00:00
|
|
|
case 128 ... 130:
|
2016-04-12 13:56:15 +00:00
|
|
|
*band = NL80211_BAND_5GHZ;
|
2012-08-01 15:00:55 +00:00
|
|
|
return true;
|
2019-08-02 11:31:01 +00:00
|
|
|
case 131 ... 135:
|
2023-09-28 14:35:28 +00:00
|
|
|
case 137:
|
2019-08-02 11:31:01 +00:00
|
|
|
*band = NL80211_BAND_6GHZ;
|
|
|
|
return true;
|
2012-08-01 15:00:55 +00:00
|
|
|
case 81:
|
|
|
|
case 82:
|
|
|
|
case 83:
|
|
|
|
case 84:
|
2016-04-12 13:56:15 +00:00
|
|
|
*band = NL80211_BAND_2GHZ;
|
2012-08-01 15:00:55 +00:00
|
|
|
return true;
|
2013-04-23 06:54:21 +00:00
|
|
|
case 180:
|
2016-04-12 13:56:15 +00:00
|
|
|
*band = NL80211_BAND_60GHZ;
|
2013-04-23 06:54:21 +00:00
|
|
|
return true;
|
2012-08-01 15:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee80211_operating_class_to_band);
|
|
|
|
|
2023-12-22 01:09:13 +00:00
|
|
|
bool ieee80211_operating_class_to_chandef(u8 operating_class,
|
|
|
|
struct ieee80211_channel *chan,
|
|
|
|
struct cfg80211_chan_def *chandef)
|
|
|
|
{
|
|
|
|
u32 control_freq, offset = 0;
|
|
|
|
enum nl80211_band band;
|
|
|
|
|
|
|
|
if (!ieee80211_operating_class_to_band(operating_class, &band) ||
|
|
|
|
!chan || band != chan->band)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
control_freq = chan->center_freq;
|
|
|
|
chandef->chan = chan;
|
|
|
|
|
|
|
|
if (control_freq >= 5955)
|
|
|
|
offset = control_freq - 5955;
|
|
|
|
else if (control_freq >= 5745)
|
|
|
|
offset = control_freq - 5745;
|
|
|
|
else if (control_freq >= 5180)
|
|
|
|
offset = control_freq - 5180;
|
|
|
|
offset /= 20;
|
|
|
|
|
|
|
|
switch (operating_class) {
|
|
|
|
case 81: /* 2 GHz band; 20 MHz; channels 1..13 */
|
|
|
|
case 82: /* 2 GHz band; 20 MHz; channel 14 */
|
|
|
|
case 115: /* 5 GHz band; 20 MHz; channels 36,40,44,48 */
|
|
|
|
case 118: /* 5 GHz band; 20 MHz; channels 52,56,60,64 */
|
|
|
|
case 121: /* 5 GHz band; 20 MHz; channels 100..144 */
|
|
|
|
case 124: /* 5 GHz band; 20 MHz; channels 149,153,157,161 */
|
|
|
|
case 125: /* 5 GHz band; 20 MHz; channels 149..177 */
|
|
|
|
case 131: /* 6 GHz band; 20 MHz; channels 1..233*/
|
|
|
|
case 136: /* 6 GHz band; 20 MHz; channel 2 */
|
|
|
|
chandef->center_freq1 = control_freq;
|
|
|
|
chandef->width = NL80211_CHAN_WIDTH_20;
|
|
|
|
return true;
|
|
|
|
case 83: /* 2 GHz band; 40 MHz; channels 1..9 */
|
|
|
|
case 116: /* 5 GHz band; 40 MHz; channels 36,44 */
|
|
|
|
case 119: /* 5 GHz band; 40 MHz; channels 52,60 */
|
|
|
|
case 122: /* 5 GHz band; 40 MHz; channels 100,108,116,124,132,140 */
|
|
|
|
case 126: /* 5 GHz band; 40 MHz; channels 149,157,165,173 */
|
|
|
|
chandef->center_freq1 = control_freq + 10;
|
|
|
|
chandef->width = NL80211_CHAN_WIDTH_40;
|
|
|
|
return true;
|
|
|
|
case 84: /* 2 GHz band; 40 MHz; channels 5..13 */
|
|
|
|
case 117: /* 5 GHz band; 40 MHz; channels 40,48 */
|
|
|
|
case 120: /* 5 GHz band; 40 MHz; channels 56,64 */
|
|
|
|
case 123: /* 5 GHz band; 40 MHz; channels 104,112,120,128,136,144 */
|
|
|
|
case 127: /* 5 GHz band; 40 MHz; channels 153,161,169,177 */
|
|
|
|
chandef->center_freq1 = control_freq - 10;
|
|
|
|
chandef->width = NL80211_CHAN_WIDTH_40;
|
|
|
|
return true;
|
|
|
|
case 132: /* 6 GHz band; 40 MHz; channels 1,5,..,229*/
|
|
|
|
chandef->center_freq1 = control_freq + 10 - (offset & 1) * 20;
|
|
|
|
chandef->width = NL80211_CHAN_WIDTH_40;
|
|
|
|
return true;
|
|
|
|
case 128: /* 5 GHz band; 80 MHz; channels 36..64,100..144,149..177 */
|
|
|
|
case 133: /* 6 GHz band; 80 MHz; channels 1,5,..,229 */
|
|
|
|
chandef->center_freq1 = control_freq + 30 - (offset & 3) * 20;
|
|
|
|
chandef->width = NL80211_CHAN_WIDTH_80;
|
|
|
|
return true;
|
|
|
|
case 129: /* 5 GHz band; 160 MHz; channels 36..64,100..144,149..177 */
|
|
|
|
case 134: /* 6 GHz band; 160 MHz; channels 1,5,..,229 */
|
|
|
|
chandef->center_freq1 = control_freq + 70 - (offset & 7) * 20;
|
|
|
|
chandef->width = NL80211_CHAN_WIDTH_160;
|
|
|
|
return true;
|
|
|
|
case 130: /* 5 GHz band; 80+80 MHz; channels 36..64,100..144,149..177 */
|
|
|
|
case 135: /* 6 GHz band; 80+80 MHz; channels 1,5,..,229 */
|
|
|
|
/* The center_freq2 of 80+80 MHz is unknown */
|
|
|
|
case 137: /* 6 GHz band; 320 MHz; channels 1,5,..,229 */
|
|
|
|
/* 320-1 or 320-2 channelization is unknown */
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee80211_operating_class_to_chandef);
|
|
|
|
|
2015-03-18 06:46:08 +00:00
|
|
|
bool ieee80211_chandef_to_operating_class(struct cfg80211_chan_def *chandef,
|
|
|
|
u8 *op_class)
|
|
|
|
{
|
|
|
|
u8 vht_opclass;
|
2018-08-31 08:10:55 +00:00
|
|
|
u32 freq = chandef->center_freq1;
|
2015-03-18 06:46:08 +00:00
|
|
|
|
|
|
|
if (freq >= 2412 && freq <= 2472) {
|
|
|
|
if (chandef->width > NL80211_CHAN_WIDTH_40)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* 2.407 GHz, channels 1..13 */
|
|
|
|
if (chandef->width == NL80211_CHAN_WIDTH_40) {
|
|
|
|
if (freq > chandef->chan->center_freq)
|
|
|
|
*op_class = 83; /* HT40+ */
|
|
|
|
else
|
|
|
|
*op_class = 84; /* HT40- */
|
|
|
|
} else {
|
|
|
|
*op_class = 81;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (freq == 2484) {
|
2019-10-21 07:50:45 +00:00
|
|
|
/* channel 14 is only for IEEE 802.11b */
|
|
|
|
if (chandef->width != NL80211_CHAN_WIDTH_20_NOHT)
|
2015-03-18 06:46:08 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
*op_class = 82; /* channel 14 */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (chandef->width) {
|
|
|
|
case NL80211_CHAN_WIDTH_80:
|
|
|
|
vht_opclass = 128;
|
|
|
|
break;
|
|
|
|
case NL80211_CHAN_WIDTH_160:
|
|
|
|
vht_opclass = 129;
|
|
|
|
break;
|
|
|
|
case NL80211_CHAN_WIDTH_80P80:
|
|
|
|
vht_opclass = 130;
|
|
|
|
break;
|
|
|
|
case NL80211_CHAN_WIDTH_10:
|
|
|
|
case NL80211_CHAN_WIDTH_5:
|
|
|
|
return false; /* unsupported for now */
|
|
|
|
default:
|
|
|
|
vht_opclass = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 5 GHz, channels 36..48 */
|
|
|
|
if (freq >= 5180 && freq <= 5240) {
|
|
|
|
if (vht_opclass) {
|
|
|
|
*op_class = vht_opclass;
|
|
|
|
} else if (chandef->width == NL80211_CHAN_WIDTH_40) {
|
|
|
|
if (freq > chandef->chan->center_freq)
|
|
|
|
*op_class = 116;
|
|
|
|
else
|
|
|
|
*op_class = 117;
|
|
|
|
} else {
|
|
|
|
*op_class = 115;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 5 GHz, channels 52..64 */
|
|
|
|
if (freq >= 5260 && freq <= 5320) {
|
|
|
|
if (vht_opclass) {
|
|
|
|
*op_class = vht_opclass;
|
|
|
|
} else if (chandef->width == NL80211_CHAN_WIDTH_40) {
|
|
|
|
if (freq > chandef->chan->center_freq)
|
|
|
|
*op_class = 119;
|
|
|
|
else
|
|
|
|
*op_class = 120;
|
|
|
|
} else {
|
|
|
|
*op_class = 118;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 5 GHz, channels 100..144 */
|
|
|
|
if (freq >= 5500 && freq <= 5720) {
|
|
|
|
if (vht_opclass) {
|
|
|
|
*op_class = vht_opclass;
|
|
|
|
} else if (chandef->width == NL80211_CHAN_WIDTH_40) {
|
|
|
|
if (freq > chandef->chan->center_freq)
|
|
|
|
*op_class = 122;
|
|
|
|
else
|
|
|
|
*op_class = 123;
|
|
|
|
} else {
|
|
|
|
*op_class = 121;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 5 GHz, channels 149..169 */
|
|
|
|
if (freq >= 5745 && freq <= 5845) {
|
|
|
|
if (vht_opclass) {
|
|
|
|
*op_class = vht_opclass;
|
|
|
|
} else if (chandef->width == NL80211_CHAN_WIDTH_40) {
|
|
|
|
if (freq > chandef->chan->center_freq)
|
|
|
|
*op_class = 126;
|
|
|
|
else
|
|
|
|
*op_class = 127;
|
|
|
|
} else if (freq <= 5805) {
|
|
|
|
*op_class = 124;
|
|
|
|
} else {
|
|
|
|
*op_class = 125;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 56.16 GHz, channel 1..4 */
|
2018-08-13 12:33:00 +00:00
|
|
|
if (freq >= 56160 + 2160 * 1 && freq <= 56160 + 2160 * 6) {
|
2015-03-18 06:46:08 +00:00
|
|
|
if (chandef->width >= NL80211_CHAN_WIDTH_40)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*op_class = 180;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not supported yet */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee80211_chandef_to_operating_class);
|
|
|
|
|
2022-04-14 14:50:57 +00:00
|
|
|
static int cfg80211_wdev_bi(struct wireless_dev *wdev)
|
|
|
|
{
|
|
|
|
switch (wdev->iftype) {
|
|
|
|
case NL80211_IFTYPE_AP:
|
|
|
|
case NL80211_IFTYPE_P2P_GO:
|
|
|
|
WARN_ON(wdev->valid_links);
|
|
|
|
return wdev->links[0].ap.beacon_interval;
|
|
|
|
case NL80211_IFTYPE_MESH_POINT:
|
|
|
|
return wdev->u.mesh.beacon_interval;
|
|
|
|
case NL80211_IFTYPE_ADHOC:
|
|
|
|
return wdev->u.ibss.beacon_interval;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-21 12:25:13 +00:00
|
|
|
static void cfg80211_calculate_bi_data(struct wiphy *wiphy, u32 new_beacon_int,
|
|
|
|
u32 *beacon_int_gcd,
|
2024-07-09 08:38:31 +00:00
|
|
|
bool *beacon_int_different,
|
|
|
|
int radio_idx)
|
2011-05-09 16:41:15 +00:00
|
|
|
{
|
2024-07-09 08:38:31 +00:00
|
|
|
struct cfg80211_registered_device *rdev;
|
2011-05-09 16:41:15 +00:00
|
|
|
struct wireless_dev *wdev;
|
|
|
|
|
2016-10-21 12:25:13 +00:00
|
|
|
*beacon_int_gcd = 0;
|
|
|
|
*beacon_int_different = false;
|
2011-05-09 16:41:15 +00:00
|
|
|
|
2024-07-09 08:38:31 +00:00
|
|
|
rdev = wiphy_to_rdev(wiphy);
|
2016-10-21 12:25:13 +00:00
|
|
|
list_for_each_entry(wdev, &wiphy->wdev_list, list) {
|
2022-04-14 14:50:57 +00:00
|
|
|
int wdev_bi;
|
|
|
|
|
|
|
|
/* this feature isn't supported with MLO */
|
|
|
|
if (wdev->valid_links)
|
|
|
|
continue;
|
|
|
|
|
2024-07-09 08:38:31 +00:00
|
|
|
/* skip wdevs not active on the given wiphy radio */
|
|
|
|
if (radio_idx >= 0 &&
|
|
|
|
!(rdev_get_radio_mask(rdev, wdev->netdev) & BIT(radio_idx)))
|
|
|
|
continue;
|
|
|
|
|
2022-04-14 14:50:57 +00:00
|
|
|
wdev_bi = cfg80211_wdev_bi(wdev);
|
|
|
|
|
|
|
|
if (!wdev_bi)
|
2011-05-09 16:41:15 +00:00
|
|
|
continue;
|
2016-10-12 12:56:51 +00:00
|
|
|
|
2016-10-21 12:25:13 +00:00
|
|
|
if (!*beacon_int_gcd) {
|
2022-04-14 14:50:57 +00:00
|
|
|
*beacon_int_gcd = wdev_bi;
|
2016-10-12 12:56:51 +00:00
|
|
|
continue;
|
2016-10-21 12:25:13 +00:00
|
|
|
}
|
2016-10-12 12:56:51 +00:00
|
|
|
|
2022-04-14 14:50:57 +00:00
|
|
|
if (wdev_bi == *beacon_int_gcd)
|
2016-10-12 12:56:51 +00:00
|
|
|
continue;
|
|
|
|
|
2016-10-21 12:25:13 +00:00
|
|
|
*beacon_int_different = true;
|
2022-04-14 14:50:57 +00:00
|
|
|
*beacon_int_gcd = gcd(*beacon_int_gcd, wdev_bi);
|
2016-10-21 12:25:13 +00:00
|
|
|
}
|
2016-10-12 12:56:51 +00:00
|
|
|
|
2016-10-21 12:25:13 +00:00
|
|
|
if (new_beacon_int && *beacon_int_gcd != new_beacon_int) {
|
|
|
|
if (*beacon_int_gcd)
|
|
|
|
*beacon_int_different = true;
|
|
|
|
*beacon_int_gcd = gcd(*beacon_int_gcd, new_beacon_int);
|
2011-05-09 16:41:15 +00:00
|
|
|
}
|
2016-10-21 12:25:13 +00:00
|
|
|
}
|
2011-05-09 16:41:15 +00:00
|
|
|
|
2016-10-21 12:25:13 +00:00
|
|
|
int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
|
|
|
|
enum nl80211_iftype iftype, u32 beacon_int)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This is just a basic pre-condition check; if interface combinations
|
|
|
|
* are possible the driver must already be checking those with a call
|
|
|
|
* to cfg80211_check_combinations(), in which case we'll validate more
|
|
|
|
* through the cfg80211_calculate_bi_data() call and code in
|
|
|
|
* cfg80211_iter_combinations().
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (beacon_int < 10 || beacon_int > 10000)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
2011-05-09 16:41:15 +00:00
|
|
|
}
|
2011-05-13 08:58:57 +00:00
|
|
|
|
2014-04-09 13:29:22 +00:00
|
|
|
int cfg80211_iter_combinations(struct wiphy *wiphy,
|
2016-10-12 12:55:35 +00:00
|
|
|
struct iface_combination_params *params,
|
2014-04-09 13:29:22 +00:00
|
|
|
void (*iter)(const struct ieee80211_iface_combination *c,
|
|
|
|
void *data),
|
|
|
|
void *data)
|
2014-02-17 14:52:35 +00:00
|
|
|
{
|
2024-07-09 08:38:31 +00:00
|
|
|
const struct wiphy_radio *radio = NULL;
|
|
|
|
const struct ieee80211_iface_combination *c, *cs;
|
2014-05-05 09:48:40 +00:00
|
|
|
const struct ieee80211_regdomain *regdom;
|
|
|
|
enum nl80211_dfs_regions region = 0;
|
2024-07-09 08:38:31 +00:00
|
|
|
int i, j, n, iftype;
|
2014-02-17 14:52:35 +00:00
|
|
|
int num_interfaces = 0;
|
|
|
|
u32 used_iftypes = 0;
|
2016-10-21 12:25:13 +00:00
|
|
|
u32 beacon_int_gcd;
|
|
|
|
bool beacon_int_different;
|
|
|
|
|
2024-07-09 08:38:31 +00:00
|
|
|
if (params->radio_idx >= 0)
|
|
|
|
radio = &wiphy->radio[params->radio_idx];
|
|
|
|
|
2016-10-21 12:25:13 +00:00
|
|
|
/*
|
|
|
|
* This is a bit strange, since the iteration used to rely only on
|
|
|
|
* the data given by the driver, but here it now relies on context,
|
|
|
|
* in form of the currently operating interfaces.
|
|
|
|
* This is OK for all current users, and saves us from having to
|
|
|
|
* push the GCD calculations into all the drivers.
|
|
|
|
* In the future, this should probably rely more on data that's in
|
|
|
|
* cfg80211 already - the only thing not would appear to be any new
|
|
|
|
* interfaces (while being brought up) and channel/radar data.
|
|
|
|
*/
|
|
|
|
cfg80211_calculate_bi_data(wiphy, params->new_beacon_int,
|
2024-07-09 08:38:31 +00:00
|
|
|
&beacon_int_gcd, &beacon_int_different,
|
|
|
|
params->radio_idx);
|
2014-02-17 14:52:35 +00:00
|
|
|
|
2016-10-12 12:55:35 +00:00
|
|
|
if (params->radar_detect) {
|
2014-05-05 09:48:40 +00:00
|
|
|
rcu_read_lock();
|
|
|
|
regdom = rcu_dereference(cfg80211_regdomain);
|
|
|
|
if (regdom)
|
|
|
|
region = regdom->dfs_region;
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
|
|
|
|
2014-02-17 14:52:35 +00:00
|
|
|
for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) {
|
2016-10-12 12:55:35 +00:00
|
|
|
num_interfaces += params->iftype_num[iftype];
|
|
|
|
if (params->iftype_num[iftype] > 0 &&
|
2019-07-22 07:14:50 +00:00
|
|
|
!cfg80211_iftype_allowed(wiphy, iftype, 0, 1))
|
2014-02-17 14:52:35 +00:00
|
|
|
used_iftypes |= BIT(iftype);
|
|
|
|
}
|
|
|
|
|
2024-07-09 08:38:31 +00:00
|
|
|
if (radio) {
|
|
|
|
cs = radio->iface_combinations;
|
|
|
|
n = radio->n_iface_combinations;
|
|
|
|
} else {
|
|
|
|
cs = wiphy->iface_combinations;
|
|
|
|
n = wiphy->n_iface_combinations;
|
|
|
|
}
|
|
|
|
for (i = 0; i < n; i++) {
|
2014-02-17 14:52:35 +00:00
|
|
|
struct ieee80211_iface_limit *limits;
|
|
|
|
u32 all_iftypes = 0;
|
|
|
|
|
2024-07-09 08:38:31 +00:00
|
|
|
c = &cs[i];
|
2014-02-17 14:52:35 +00:00
|
|
|
if (num_interfaces > c->max_interfaces)
|
|
|
|
continue;
|
2016-10-12 12:55:35 +00:00
|
|
|
if (params->num_different_channels > c->num_different_channels)
|
2014-02-17 14:52:35 +00:00
|
|
|
continue;
|
|
|
|
|
2024-08-22 07:47:43 +00:00
|
|
|
limits = kmemdup_array(c->limits, c->n_limits, sizeof(*limits),
|
|
|
|
GFP_KERNEL);
|
2014-02-17 14:52:35 +00:00
|
|
|
if (!limits)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) {
|
2019-07-22 07:14:50 +00:00
|
|
|
if (cfg80211_iftype_allowed(wiphy, iftype, 0, 1))
|
2014-02-17 14:52:35 +00:00
|
|
|
continue;
|
|
|
|
for (j = 0; j < c->n_limits; j++) {
|
|
|
|
all_iftypes |= limits[j].types;
|
|
|
|
if (!(limits[j].types & BIT(iftype)))
|
|
|
|
continue;
|
2016-10-12 12:55:35 +00:00
|
|
|
if (limits[j].max < params->iftype_num[iftype])
|
2014-02-17 14:52:35 +00:00
|
|
|
goto cont;
|
2016-10-12 12:55:35 +00:00
|
|
|
limits[j].max -= params->iftype_num[iftype];
|
2014-02-17 14:52:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-12 12:55:35 +00:00
|
|
|
if (params->radar_detect !=
|
|
|
|
(c->radar_detect_widths & params->radar_detect))
|
2014-02-17 14:52:35 +00:00
|
|
|
goto cont;
|
|
|
|
|
2016-10-12 12:55:35 +00:00
|
|
|
if (params->radar_detect && c->radar_detect_regions &&
|
2014-05-05 09:48:40 +00:00
|
|
|
!(c->radar_detect_regions & BIT(region)))
|
|
|
|
goto cont;
|
|
|
|
|
2014-02-17 14:52:35 +00:00
|
|
|
/* Finally check that all iftypes that we're currently
|
|
|
|
* using are actually part of this combination. If they
|
|
|
|
* aren't then we can't use this combination and have
|
|
|
|
* to continue to the next.
|
|
|
|
*/
|
|
|
|
if ((all_iftypes & used_iftypes) != used_iftypes)
|
|
|
|
goto cont;
|
|
|
|
|
2016-10-21 12:25:13 +00:00
|
|
|
if (beacon_int_gcd) {
|
2016-10-12 12:56:51 +00:00
|
|
|
if (c->beacon_int_min_gcd &&
|
2016-10-21 12:25:13 +00:00
|
|
|
beacon_int_gcd < c->beacon_int_min_gcd)
|
2016-10-21 10:15:00 +00:00
|
|
|
goto cont;
|
2016-10-21 12:25:13 +00:00
|
|
|
if (!c->beacon_int_min_gcd && beacon_int_different)
|
2016-10-12 12:56:51 +00:00
|
|
|
goto cont;
|
|
|
|
}
|
|
|
|
|
2014-02-17 14:52:35 +00:00
|
|
|
/* This combination covered all interface types and
|
|
|
|
* supported the requested numbers, so we're good.
|
|
|
|
*/
|
2014-04-09 13:29:22 +00:00
|
|
|
|
|
|
|
(*iter)(c, data);
|
2014-02-17 14:52:35 +00:00
|
|
|
cont:
|
|
|
|
kfree(limits);
|
|
|
|
}
|
|
|
|
|
2014-04-09 13:29:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cfg80211_iter_combinations);
|
|
|
|
|
|
|
|
static void
|
|
|
|
cfg80211_iter_sum_ifcombs(const struct ieee80211_iface_combination *c,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
int *num = data;
|
|
|
|
(*num)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cfg80211_check_combinations(struct wiphy *wiphy,
|
2016-10-12 12:55:35 +00:00
|
|
|
struct iface_combination_params *params)
|
2014-04-09 13:29:22 +00:00
|
|
|
{
|
|
|
|
int err, num = 0;
|
|
|
|
|
2016-10-12 12:55:35 +00:00
|
|
|
err = cfg80211_iter_combinations(wiphy, params,
|
2014-04-09 13:29:22 +00:00
|
|
|
cfg80211_iter_sum_ifcombs, &num);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
if (num == 0)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
return 0;
|
2014-02-17 14:52:35 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cfg80211_check_combinations);
|
|
|
|
|
2011-07-18 16:08:35 +00:00
|
|
|
int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,
|
|
|
|
const u8 *rates, unsigned int n_rates,
|
|
|
|
u32 *mask)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
2011-07-19 22:52:16 +00:00
|
|
|
if (!sband)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-07-18 16:08:35 +00:00
|
|
|
if (n_rates == 0 || n_rates > NL80211_MAX_SUPP_RATES)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
*mask = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < n_rates; i++) {
|
|
|
|
int rate = (rates[i] & 0x7f) * 5;
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for (j = 0; j < sband->n_bitrates; j++) {
|
|
|
|
if (sband->bitrates[j].bitrate == rate) {
|
|
|
|
found = true;
|
|
|
|
*mask |= BIT(j);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mask must have at least one bit set here since we
|
|
|
|
* didn't accept a 0-length rates array nor allowed
|
|
|
|
* entries in the array that didn't exist
|
|
|
|
*/
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-11-21 10:09:22 +00:00
|
|
|
|
2014-01-09 09:37:23 +00:00
|
|
|
unsigned int ieee80211_get_num_supported_channels(struct wiphy *wiphy)
|
|
|
|
{
|
2016-04-12 13:56:15 +00:00
|
|
|
enum nl80211_band band;
|
2014-01-09 09:37:23 +00:00
|
|
|
unsigned int n_channels = 0;
|
|
|
|
|
2016-04-12 13:56:15 +00:00
|
|
|
for (band = 0; band < NUM_NL80211_BANDS; band++)
|
2014-01-09 09:37:23 +00:00
|
|
|
if (wiphy->bands[band])
|
|
|
|
n_channels += wiphy->bands[band]->n_channels;
|
|
|
|
|
|
|
|
return n_channels;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee80211_get_num_supported_channels);
|
|
|
|
|
2014-05-19 19:53:21 +00:00
|
|
|
int cfg80211_get_station(struct net_device *dev, const u8 *mac_addr,
|
|
|
|
struct station_info *sinfo)
|
|
|
|
{
|
|
|
|
struct cfg80211_registered_device *rdev;
|
|
|
|
struct wireless_dev *wdev;
|
wifi: cfg80211: Lock wiphy in cfg80211_get_station
Wiphy should be locked before calling rdev_get_station() (see lockdep
assert in ieee80211_get_station()).
This fixes the following kernel NULL dereference:
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000050
Mem abort info:
ESR = 0x0000000096000006
EC = 0x25: DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
FSC = 0x06: level 2 translation fault
Data abort info:
ISV = 0, ISS = 0x00000006
CM = 0, WnR = 0
user pgtable: 4k pages, 48-bit VAs, pgdp=0000000003001000
[0000000000000050] pgd=0800000002dca003, p4d=0800000002dca003, pud=08000000028e9003, pmd=0000000000000000
Internal error: Oops: 0000000096000006 [#1] SMP
Modules linked in: netconsole dwc3_meson_g12a dwc3_of_simple dwc3 ip_gre gre ath10k_pci ath10k_core ath9k ath9k_common ath9k_hw ath
CPU: 0 PID: 1091 Comm: kworker/u8:0 Not tainted 6.4.0-02144-g565f9a3a7911-dirty #705
Hardware name: RPT (r1) (DT)
Workqueue: bat_events batadv_v_elp_throughput_metric_update
pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : ath10k_sta_statistics+0x10/0x2dc [ath10k_core]
lr : sta_set_sinfo+0xcc/0xbd4
sp : ffff000007b43ad0
x29: ffff000007b43ad0 x28: ffff0000071fa900 x27: ffff00000294ca98
x26: ffff000006830880 x25: ffff000006830880 x24: ffff00000294c000
x23: 0000000000000001 x22: ffff000007b43c90 x21: ffff800008898acc
x20: ffff00000294c6e8 x19: ffff000007b43c90 x18: 0000000000000000
x17: 445946354d552d78 x16: 62661f7200000000 x15: 57464f445946354d
x14: 0000000000000000 x13: 00000000000000e3 x12: d5f0acbcebea978e
x11: 00000000000000e3 x10: 000000010048fe41 x9 : 0000000000000000
x8 : ffff000007b43d90 x7 : 000000007a1e2125 x6 : 0000000000000000
x5 : ffff0000024e0900 x4 : ffff800000a0250c x3 : ffff000007b43c90
x2 : ffff00000294ca98 x1 : ffff000006831920 x0 : 0000000000000000
Call trace:
ath10k_sta_statistics+0x10/0x2dc [ath10k_core]
sta_set_sinfo+0xcc/0xbd4
ieee80211_get_station+0x2c/0x44
cfg80211_get_station+0x80/0x154
batadv_v_elp_get_throughput+0x138/0x1fc
batadv_v_elp_throughput_metric_update+0x1c/0xa4
process_one_work+0x1ec/0x414
worker_thread+0x70/0x46c
kthread+0xdc/0xe0
ret_from_fork+0x10/0x20
Code: a9bb7bfd 910003fd a90153f3 f9411c40 (f9402814)
This happens because STA has time to disconnect and reconnect before
batadv_v_elp_throughput_metric_update() delayed work gets scheduled. In
this situation, ath10k_sta_state() can be in the middle of resetting
arsta data when the work queue get chance to be scheduled and ends up
accessing it. Locking wiphy prevents that.
Fixes: 7406353d43c8 ("cfg80211: implement cfg80211_get_station cfg80211 API")
Signed-off-by: Remi Pommarel <repk@triplefau.lt>
Reviewed-by: Nicolas Escande <nico.escande@gmail.com>
Acked-by: Antonio Quartulli <a@unstable.cc>
Link: https://msgid.link/983b24a6a176e0800c01aedcd74480d9b551cb13.1716046653.git.repk@triplefau.lt
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
2024-05-21 19:47:26 +00:00
|
|
|
int ret;
|
2014-05-19 19:53:21 +00:00
|
|
|
|
|
|
|
wdev = dev->ieee80211_ptr;
|
|
|
|
if (!wdev)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
rdev = wiphy_to_rdev(wdev->wiphy);
|
|
|
|
if (!rdev->ops->get_station)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2018-06-06 08:53:55 +00:00
|
|
|
memset(sinfo, 0, sizeof(*sinfo));
|
|
|
|
|
wifi: cfg80211: Lock wiphy in cfg80211_get_station
Wiphy should be locked before calling rdev_get_station() (see lockdep
assert in ieee80211_get_station()).
This fixes the following kernel NULL dereference:
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000050
Mem abort info:
ESR = 0x0000000096000006
EC = 0x25: DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
FSC = 0x06: level 2 translation fault
Data abort info:
ISV = 0, ISS = 0x00000006
CM = 0, WnR = 0
user pgtable: 4k pages, 48-bit VAs, pgdp=0000000003001000
[0000000000000050] pgd=0800000002dca003, p4d=0800000002dca003, pud=08000000028e9003, pmd=0000000000000000
Internal error: Oops: 0000000096000006 [#1] SMP
Modules linked in: netconsole dwc3_meson_g12a dwc3_of_simple dwc3 ip_gre gre ath10k_pci ath10k_core ath9k ath9k_common ath9k_hw ath
CPU: 0 PID: 1091 Comm: kworker/u8:0 Not tainted 6.4.0-02144-g565f9a3a7911-dirty #705
Hardware name: RPT (r1) (DT)
Workqueue: bat_events batadv_v_elp_throughput_metric_update
pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : ath10k_sta_statistics+0x10/0x2dc [ath10k_core]
lr : sta_set_sinfo+0xcc/0xbd4
sp : ffff000007b43ad0
x29: ffff000007b43ad0 x28: ffff0000071fa900 x27: ffff00000294ca98
x26: ffff000006830880 x25: ffff000006830880 x24: ffff00000294c000
x23: 0000000000000001 x22: ffff000007b43c90 x21: ffff800008898acc
x20: ffff00000294c6e8 x19: ffff000007b43c90 x18: 0000000000000000
x17: 445946354d552d78 x16: 62661f7200000000 x15: 57464f445946354d
x14: 0000000000000000 x13: 00000000000000e3 x12: d5f0acbcebea978e
x11: 00000000000000e3 x10: 000000010048fe41 x9 : 0000000000000000
x8 : ffff000007b43d90 x7 : 000000007a1e2125 x6 : 0000000000000000
x5 : ffff0000024e0900 x4 : ffff800000a0250c x3 : ffff000007b43c90
x2 : ffff00000294ca98 x1 : ffff000006831920 x0 : 0000000000000000
Call trace:
ath10k_sta_statistics+0x10/0x2dc [ath10k_core]
sta_set_sinfo+0xcc/0xbd4
ieee80211_get_station+0x2c/0x44
cfg80211_get_station+0x80/0x154
batadv_v_elp_get_throughput+0x138/0x1fc
batadv_v_elp_throughput_metric_update+0x1c/0xa4
process_one_work+0x1ec/0x414
worker_thread+0x70/0x46c
kthread+0xdc/0xe0
ret_from_fork+0x10/0x20
Code: a9bb7bfd 910003fd a90153f3 f9411c40 (f9402814)
This happens because STA has time to disconnect and reconnect before
batadv_v_elp_throughput_metric_update() delayed work gets scheduled. In
this situation, ath10k_sta_state() can be in the middle of resetting
arsta data when the work queue get chance to be scheduled and ends up
accessing it. Locking wiphy prevents that.
Fixes: 7406353d43c8 ("cfg80211: implement cfg80211_get_station cfg80211 API")
Signed-off-by: Remi Pommarel <repk@triplefau.lt>
Reviewed-by: Nicolas Escande <nico.escande@gmail.com>
Acked-by: Antonio Quartulli <a@unstable.cc>
Link: https://msgid.link/983b24a6a176e0800c01aedcd74480d9b551cb13.1716046653.git.repk@triplefau.lt
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
2024-05-21 19:47:26 +00:00
|
|
|
wiphy_lock(&rdev->wiphy);
|
|
|
|
ret = rdev_get_station(rdev, dev, mac_addr, sinfo);
|
|
|
|
wiphy_unlock(&rdev->wiphy);
|
|
|
|
|
|
|
|
return ret;
|
2014-05-19 19:53:21 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cfg80211_get_station);
|
|
|
|
|
2016-09-20 14:31:15 +00:00
|
|
|
void cfg80211_free_nan_func(struct cfg80211_nan_func *f)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
kfree(f->serv_spec_info);
|
|
|
|
kfree(f->srf_bf);
|
|
|
|
kfree(f->srf_macs);
|
|
|
|
for (i = 0; i < f->num_rx_filters; i++)
|
|
|
|
kfree(f->rx_filters[i].filter);
|
|
|
|
|
|
|
|
for (i = 0; i < f->num_tx_filters; i++)
|
|
|
|
kfree(f->tx_filters[i].filter);
|
|
|
|
|
|
|
|
kfree(f->rx_filters);
|
|
|
|
kfree(f->tx_filters);
|
|
|
|
kfree(f);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cfg80211_free_nan_func);
|
|
|
|
|
2017-01-04 17:58:30 +00:00
|
|
|
bool cfg80211_does_bw_fit_range(const struct ieee80211_freq_range *freq_range,
|
|
|
|
u32 center_freq_khz, u32 bw_khz)
|
|
|
|
{
|
|
|
|
u32 start_freq_khz, end_freq_khz;
|
|
|
|
|
|
|
|
start_freq_khz = center_freq_khz - (bw_khz / 2);
|
|
|
|
end_freq_khz = center_freq_khz + (bw_khz / 2);
|
|
|
|
|
|
|
|
if (start_freq_khz >= freq_range->start_freq_khz &&
|
|
|
|
end_freq_khz <= freq_range->end_freq_khz)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-10 11:50:12 +00:00
|
|
|
int cfg80211_sinfo_alloc_tid_stats(struct station_info *sinfo, gfp_t gfp)
|
|
|
|
{
|
2018-05-23 12:53:41 +00:00
|
|
|
sinfo->pertid = kcalloc(IEEE80211_NUM_TIDS + 1,
|
|
|
|
sizeof(*(sinfo->pertid)),
|
|
|
|
gfp);
|
2018-05-10 11:50:12 +00:00
|
|
|
if (!sinfo->pertid)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cfg80211_sinfo_alloc_tid_stats);
|
|
|
|
|
2011-11-21 10:09:22 +00:00
|
|
|
/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
|
|
|
|
/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
|
|
|
|
const unsigned char rfc1042_header[] __aligned(2) =
|
|
|
|
{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
|
|
|
|
EXPORT_SYMBOL(rfc1042_header);
|
|
|
|
|
|
|
|
/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
|
|
|
|
const unsigned char bridge_tunnel_header[] __aligned(2) =
|
|
|
|
{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
|
|
|
|
EXPORT_SYMBOL(bridge_tunnel_header);
|
2018-07-29 11:59:16 +00:00
|
|
|
|
|
|
|
/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
|
|
|
|
struct iapp_layer2_update {
|
|
|
|
u8 da[ETH_ALEN]; /* broadcast */
|
|
|
|
u8 sa[ETH_ALEN]; /* STA addr */
|
|
|
|
__be16 len; /* 6 */
|
|
|
|
u8 dsap; /* 0 */
|
|
|
|
u8 ssap; /* 0 */
|
|
|
|
u8 control;
|
|
|
|
u8 xid_info[3];
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
void cfg80211_send_layer2_update(struct net_device *dev, const u8 *addr)
|
|
|
|
{
|
|
|
|
struct iapp_layer2_update *msg;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
/* Send Level 2 Update Frame to update forwarding tables in layer 2
|
|
|
|
* bridge devices */
|
|
|
|
|
|
|
|
skb = dev_alloc_skb(sizeof(*msg));
|
|
|
|
if (!skb)
|
|
|
|
return;
|
|
|
|
msg = skb_put(skb, sizeof(*msg));
|
|
|
|
|
|
|
|
/* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
|
|
|
|
* Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
|
|
|
|
|
|
|
|
eth_broadcast_addr(msg->da);
|
|
|
|
ether_addr_copy(msg->sa, addr);
|
|
|
|
msg->len = htons(6);
|
|
|
|
msg->dsap = 0;
|
|
|
|
msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
|
|
|
|
msg->control = 0xaf; /* XID response lsb.1111F101.
|
|
|
|
* F=0 (no poll command; unsolicited frame) */
|
|
|
|
msg->xid_info[0] = 0x81; /* XID format identifier */
|
|
|
|
msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
|
|
|
|
msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
|
|
|
|
|
|
|
|
skb->dev = dev;
|
|
|
|
skb->protocol = eth_type_trans(skb, dev);
|
|
|
|
memset(skb->cb, 0, sizeof(skb->cb));
|
2022-03-05 22:12:52 +00:00
|
|
|
netif_rx(skb);
|
2018-07-29 11:59:16 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cfg80211_send_layer2_update);
|
2018-08-31 08:31:16 +00:00
|
|
|
|
|
|
|
int ieee80211_get_vht_max_nss(struct ieee80211_vht_cap *cap,
|
|
|
|
enum ieee80211_vht_chanwidth bw,
|
2020-03-26 13:09:32 +00:00
|
|
|
int mcs, bool ext_nss_bw_capable,
|
|
|
|
unsigned int max_vht_nss)
|
2018-08-31 08:31:16 +00:00
|
|
|
{
|
|
|
|
u16 map = le16_to_cpu(cap->supp_mcs.rx_mcs_map);
|
|
|
|
int ext_nss_bw;
|
|
|
|
int supp_width;
|
|
|
|
int i, mcs_encoding;
|
|
|
|
|
|
|
|
if (map == 0xffff)
|
|
|
|
return 0;
|
|
|
|
|
2020-03-26 13:09:32 +00:00
|
|
|
if (WARN_ON(mcs > 9 || max_vht_nss > 8))
|
2018-08-31 08:31:16 +00:00
|
|
|
return 0;
|
|
|
|
if (mcs <= 7)
|
|
|
|
mcs_encoding = 0;
|
|
|
|
else if (mcs == 8)
|
|
|
|
mcs_encoding = 1;
|
|
|
|
else
|
|
|
|
mcs_encoding = 2;
|
|
|
|
|
2020-03-26 13:09:32 +00:00
|
|
|
if (!max_vht_nss) {
|
|
|
|
/* find max_vht_nss for the given MCS */
|
|
|
|
for (i = 7; i >= 0; i--) {
|
|
|
|
int supp = (map >> (2 * i)) & 3;
|
2018-08-31 08:31:16 +00:00
|
|
|
|
2020-03-26 13:09:32 +00:00
|
|
|
if (supp == 3)
|
|
|
|
continue;
|
2018-08-31 08:31:16 +00:00
|
|
|
|
2020-03-26 13:09:32 +00:00
|
|
|
if (supp >= mcs_encoding) {
|
|
|
|
max_vht_nss = i + 1;
|
|
|
|
break;
|
|
|
|
}
|
2018-08-31 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(cap->supp_mcs.tx_mcs_map &
|
|
|
|
cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE)))
|
|
|
|
return max_vht_nss;
|
|
|
|
|
|
|
|
ext_nss_bw = le32_get_bits(cap->vht_cap_info,
|
|
|
|
IEEE80211_VHT_CAP_EXT_NSS_BW_MASK);
|
|
|
|
supp_width = le32_get_bits(cap->vht_cap_info,
|
|
|
|
IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK);
|
|
|
|
|
|
|
|
/* if not capable, treat ext_nss_bw as 0 */
|
|
|
|
if (!ext_nss_bw_capable)
|
|
|
|
ext_nss_bw = 0;
|
|
|
|
|
|
|
|
/* This is invalid */
|
|
|
|
if (supp_width == 3)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* This is an invalid combination so pretend nothing is supported */
|
|
|
|
if (supp_width == 2 && (ext_nss_bw == 1 || ext_nss_bw == 2))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cover all the special cases according to IEEE 802.11-2016
|
|
|
|
* Table 9-250. All other cases are either factor of 1 or not
|
|
|
|
* valid/supported.
|
|
|
|
*/
|
|
|
|
switch (bw) {
|
|
|
|
case IEEE80211_VHT_CHANWIDTH_USE_HT:
|
|
|
|
case IEEE80211_VHT_CHANWIDTH_80MHZ:
|
|
|
|
if ((supp_width == 1 || supp_width == 2) &&
|
|
|
|
ext_nss_bw == 3)
|
|
|
|
return 2 * max_vht_nss;
|
|
|
|
break;
|
|
|
|
case IEEE80211_VHT_CHANWIDTH_160MHZ:
|
|
|
|
if (supp_width == 0 &&
|
|
|
|
(ext_nss_bw == 1 || ext_nss_bw == 2))
|
2018-12-15 09:03:16 +00:00
|
|
|
return max_vht_nss / 2;
|
2018-08-31 08:31:16 +00:00
|
|
|
if (supp_width == 0 &&
|
|
|
|
ext_nss_bw == 3)
|
2018-12-15 09:03:16 +00:00
|
|
|
return (3 * max_vht_nss) / 4;
|
2018-08-31 08:31:16 +00:00
|
|
|
if (supp_width == 1 &&
|
|
|
|
ext_nss_bw == 3)
|
|
|
|
return 2 * max_vht_nss;
|
|
|
|
break;
|
|
|
|
case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
|
2018-12-15 09:03:16 +00:00
|
|
|
if (supp_width == 0 && ext_nss_bw == 1)
|
2018-08-31 08:31:16 +00:00
|
|
|
return 0; /* not possible */
|
|
|
|
if (supp_width == 0 &&
|
|
|
|
ext_nss_bw == 2)
|
2018-12-15 09:03:16 +00:00
|
|
|
return max_vht_nss / 2;
|
2018-08-31 08:31:16 +00:00
|
|
|
if (supp_width == 0 &&
|
|
|
|
ext_nss_bw == 3)
|
2018-12-15 09:03:16 +00:00
|
|
|
return (3 * max_vht_nss) / 4;
|
2018-08-31 08:31:16 +00:00
|
|
|
if (supp_width == 1 &&
|
|
|
|
ext_nss_bw == 0)
|
|
|
|
return 0; /* not possible */
|
|
|
|
if (supp_width == 1 &&
|
|
|
|
ext_nss_bw == 1)
|
2018-12-15 09:03:16 +00:00
|
|
|
return max_vht_nss / 2;
|
2018-08-31 08:31:16 +00:00
|
|
|
if (supp_width == 1 &&
|
|
|
|
ext_nss_bw == 2)
|
2018-12-15 09:03:16 +00:00
|
|
|
return (3 * max_vht_nss) / 4;
|
2018-08-31 08:31:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not covered or invalid combination received */
|
|
|
|
return max_vht_nss;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee80211_get_vht_max_nss);
|
2019-07-22 07:14:50 +00:00
|
|
|
|
|
|
|
bool cfg80211_iftype_allowed(struct wiphy *wiphy, enum nl80211_iftype iftype,
|
|
|
|
bool is_4addr, u8 check_swif)
|
|
|
|
|
|
|
|
{
|
|
|
|
bool is_vlan = iftype == NL80211_IFTYPE_AP_VLAN;
|
|
|
|
|
|
|
|
switch (check_swif) {
|
|
|
|
case 0:
|
|
|
|
if (is_vlan && is_4addr)
|
|
|
|
return wiphy->flags & WIPHY_FLAG_4ADDR_AP;
|
|
|
|
return wiphy->interface_modes & BIT(iftype);
|
|
|
|
case 1:
|
|
|
|
if (!(wiphy->software_iftypes & BIT(iftype)) && is_vlan)
|
|
|
|
return wiphy->flags & WIPHY_FLAG_4ADDR_AP;
|
|
|
|
return wiphy->software_iftypes & BIT(iftype);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cfg80211_iftype_allowed);
|
2022-07-06 07:57:42 +00:00
|
|
|
|
|
|
|
void cfg80211_remove_link(struct wireless_dev *wdev, unsigned int link_id)
|
|
|
|
{
|
|
|
|
struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
|
|
|
|
|
2023-08-29 10:18:56 +00:00
|
|
|
lockdep_assert_wiphy(wdev->wiphy);
|
2022-07-06 07:57:42 +00:00
|
|
|
|
|
|
|
switch (wdev->iftype) {
|
|
|
|
case NL80211_IFTYPE_AP:
|
|
|
|
case NL80211_IFTYPE_P2P_GO:
|
2023-08-29 10:18:56 +00:00
|
|
|
cfg80211_stop_ap(rdev, wdev->netdev, link_id, true);
|
2022-07-06 07:57:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* per-link not relevant */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wdev->valid_links &= ~BIT(link_id);
|
|
|
|
|
|
|
|
rdev_del_intf_link(rdev, wdev, link_id);
|
|
|
|
|
|
|
|
eth_zero_addr(wdev->links[link_id].addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cfg80211_remove_links(struct wireless_dev *wdev)
|
|
|
|
{
|
|
|
|
unsigned int link_id;
|
|
|
|
|
2023-06-08 13:36:04 +00:00
|
|
|
/*
|
|
|
|
* links are controlled by upper layers (userspace/cfg)
|
|
|
|
* only for AP mode, so only remove them here for AP
|
|
|
|
*/
|
|
|
|
if (wdev->iftype != NL80211_IFTYPE_AP)
|
|
|
|
return;
|
|
|
|
|
2022-07-06 07:57:42 +00:00
|
|
|
if (wdev->valid_links) {
|
|
|
|
for_each_valid_link(wdev, link_id)
|
|
|
|
cfg80211_remove_link(wdev, link_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int cfg80211_remove_virtual_intf(struct cfg80211_registered_device *rdev,
|
|
|
|
struct wireless_dev *wdev)
|
|
|
|
{
|
|
|
|
cfg80211_remove_links(wdev);
|
|
|
|
|
|
|
|
return rdev_del_virtual_intf(rdev, wdev);
|
|
|
|
}
|
2022-07-12 16:32:49 +00:00
|
|
|
|
|
|
|
const struct wiphy_iftype_ext_capab *
|
|
|
|
cfg80211_get_iftype_ext_capa(struct wiphy *wiphy, enum nl80211_iftype type)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < wiphy->num_iftype_ext_capab; i++) {
|
|
|
|
if (wiphy->iftype_ext_capab[i].iftype == type)
|
|
|
|
return &wiphy->iftype_ext_capab[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cfg80211_get_iftype_ext_capa);
|
2024-07-09 08:38:32 +00:00
|
|
|
|
|
|
|
static bool
|
|
|
|
ieee80211_radio_freq_range_valid(const struct wiphy_radio *radio,
|
|
|
|
u32 freq, u32 width)
|
|
|
|
{
|
|
|
|
const struct wiphy_radio_freq_range *r;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < radio->n_freq_range; i++) {
|
|
|
|
r = &radio->freq_range[i];
|
|
|
|
if (freq - width / 2 >= r->start_freq &&
|
|
|
|
freq + width / 2 <= r->end_freq)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cfg80211_radio_chandef_valid(const struct wiphy_radio *radio,
|
|
|
|
const struct cfg80211_chan_def *chandef)
|
|
|
|
{
|
|
|
|
u32 freq, width;
|
|
|
|
|
|
|
|
freq = ieee80211_chandef_to_khz(chandef);
|
|
|
|
width = nl80211_chan_width_to_mhz(chandef->width);
|
|
|
|
if (!ieee80211_radio_freq_range_valid(radio, freq, width))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
freq = MHZ_TO_KHZ(chandef->center_freq2);
|
|
|
|
if (freq && !ieee80211_radio_freq_range_valid(radio, freq, width))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cfg80211_radio_chandef_valid);
|