cfg80211.h 211.6 KB
Newer Older
1 2
#ifndef __NET_CFG80211_H
#define __NET_CFG80211_H
J
Johannes Berg 已提交
3 4 5
/*
 * 802.11 device and configuration interface
 *
6
 * Copyright 2006-2010	Johannes Berg <johannes@sipsolutions.net>
7
 * Copyright 2013-2014 Intel Mobile Communications GmbH
L
Luca Coelho 已提交
8
 * Copyright 2015-2017	Intel Deutschland GmbH
J
Johannes Berg 已提交
9 10 11 12 13
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
14

J
Johannes Berg 已提交
15 16 17
#include <linux/netdevice.h>
#include <linux/debugfs.h>
#include <linux/list.h>
18
#include <linux/bug.h>
19 20
#include <linux/netlink.h>
#include <linux/skbuff.h>
21
#include <linux/nl80211.h>
22 23
#include <linux/if_ether.h>
#include <linux/ieee80211.h>
24
#include <linux/net.h>
J
Johannes Berg 已提交
25 26
#include <net/regulatory.h>

J
Johannes Berg 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
/**
 * DOC: Introduction
 *
 * cfg80211 is the configuration API for 802.11 devices in Linux. It bridges
 * userspace and drivers, and offers some utility functionality associated
 * with 802.11. cfg80211 must, directly or indirectly via mac80211, be used
 * by all modern wireless drivers in Linux, so that they offer a consistent
 * API through nl80211. For backward compatibility, cfg80211 also offers
 * wireless extensions to userspace, but hides them from drivers completely.
 *
 * Additionally, cfg80211 contains code to help enforce regulatory spectrum
 * use restrictions.
 */


/**
 * DOC: Device registration
 *
 * In order for a driver to use cfg80211, it must register the hardware device
 * with cfg80211. This happens through a number of hardware capability structs
 * described below.
 *
 * The fundamental structure for each device is the 'wiphy', of which each
 * instance describes a physical wireless device connected to the system. Each
 * such wiphy can have zero, one, or many virtual interfaces associated with
 * it, which need to be identified as such by pointing the network interface's
 * @ieee80211_ptr pointer to a &struct wireless_dev which further describes
 * the wireless part of the interface, normally this struct is embedded in the
 * network interface's private data area. Drivers can optionally allow creating
 * or destroying virtual interfaces on the fly, but without at least one or the
 * ability to create some the wireless device isn't useful.
 *
 * Each wiphy structure contains device capability information, and also has
 * a pointer to the various operations the driver offers. The definitions and
 * structures here describe these capabilities in detail.
 */

64 65
struct wiphy;

66
/*
J
Johannes Berg 已提交
67 68 69
 * wireless hardware capability structures
 */

70
/**
J
Johannes Berg 已提交
71 72 73 74 75
 * enum ieee80211_channel_flags - channel flags
 *
 * Channel flags set by the regulatory control code.
 *
 * @IEEE80211_CHAN_DISABLED: This channel is disabled.
76 77
 * @IEEE80211_CHAN_NO_IR: do not initiate radiation, this includes
 * 	sending probe requests or beaconing.
J
Johannes Berg 已提交
78
 * @IEEE80211_CHAN_RADAR: Radar detection is required on this channel.
79
 * @IEEE80211_CHAN_NO_HT40PLUS: extension channel above this channel
J
Johannes Berg 已提交
80
 * 	is not permitted.
81
 * @IEEE80211_CHAN_NO_HT40MINUS: extension channel below this channel
J
Johannes Berg 已提交
82
 * 	is not permitted.
83
 * @IEEE80211_CHAN_NO_OFDM: OFDM is not allowed on this channel.
84 85 86 87 88 89 90 91 92 93
 * @IEEE80211_CHAN_NO_80MHZ: If the driver supports 80 MHz on the band,
 *	this flag indicates that an 80 MHz channel cannot use this
 *	channel as the control or any of the secondary channels.
 *	This may be due to the driver or due to regulatory bandwidth
 *	restrictions.
 * @IEEE80211_CHAN_NO_160MHZ: If the driver supports 160 MHz on the band,
 *	this flag indicates that an 160 MHz channel cannot use this
 *	channel as the control or any of the secondary channels.
 *	This may be due to the driver or due to regulatory bandwidth
 *	restrictions.
94
 * @IEEE80211_CHAN_INDOOR_ONLY: see %NL80211_FREQUENCY_ATTR_INDOOR_ONLY
95
 * @IEEE80211_CHAN_IR_CONCURRENT: see %NL80211_FREQUENCY_ATTR_IR_CONCURRENT
96 97 98 99
 * @IEEE80211_CHAN_NO_20MHZ: 20 MHz bandwidth is not permitted
 *	on this channel.
 * @IEEE80211_CHAN_NO_10MHZ: 10 MHz bandwidth is not permitted
 *	on this channel.
100
 *
101
 */
J
Johannes Berg 已提交
102 103
enum ieee80211_channel_flags {
	IEEE80211_CHAN_DISABLED		= 1<<0,
104 105
	IEEE80211_CHAN_NO_IR		= 1<<1,
	/* hole at 1<<2 */
J
Johannes Berg 已提交
106
	IEEE80211_CHAN_RADAR		= 1<<3,
107 108
	IEEE80211_CHAN_NO_HT40PLUS	= 1<<4,
	IEEE80211_CHAN_NO_HT40MINUS	= 1<<5,
109
	IEEE80211_CHAN_NO_OFDM		= 1<<6,
110 111
	IEEE80211_CHAN_NO_80MHZ		= 1<<7,
	IEEE80211_CHAN_NO_160MHZ	= 1<<8,
112
	IEEE80211_CHAN_INDOOR_ONLY	= 1<<9,
113
	IEEE80211_CHAN_IR_CONCURRENT	= 1<<10,
114 115
	IEEE80211_CHAN_NO_20MHZ		= 1<<11,
	IEEE80211_CHAN_NO_10MHZ		= 1<<12,
116 117
};

118
#define IEEE80211_CHAN_NO_HT40 \
119
	(IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
120

121 122 123
#define IEEE80211_DFS_MIN_CAC_TIME_MS		60000
#define IEEE80211_DFS_MIN_NOP_TIME_MS		(30 * 60 * 1000)

J
Johannes Berg 已提交
124 125 126 127 128 129 130 131 132 133 134 135 136 137
/**
 * struct ieee80211_channel - channel definition
 *
 * This structure describes a single channel for use
 * with cfg80211.
 *
 * @center_freq: center frequency in MHz
 * @hw_value: hardware-specific value for the channel
 * @flags: channel flags from &enum ieee80211_channel_flags.
 * @orig_flags: channel flags at registration time, used by regulatory
 *	code to support devices with additional restrictions
 * @band: band this channel belongs to.
 * @max_antenna_gain: maximum antenna gain in dBi
 * @max_power: maximum transmission power (in dBm)
138
 * @max_reg_power: maximum regulatory transmission power (in dBm)
J
Johannes Berg 已提交
139 140
 * @beacon_found: helper to regulatory code to indicate when a beacon
 *	has been found on this channel. Use regulatory_hint_found_beacon()
141
 *	to enable this, this is useful only on 5 GHz band.
J
Johannes Berg 已提交
142 143
 * @orig_mag: internal use
 * @orig_mpwr: internal use
144 145 146
 * @dfs_state: current state of this channel. Only relevant if radar is required
 *	on this channel.
 * @dfs_state_entered: timestamp (jiffies) when the dfs state was entered.
147
 * @dfs_cac_ms: DFS CAC time in milliseconds, this is valid for DFS channels.
A
Andy Green 已提交
148
 */
J
Johannes Berg 已提交
149
struct ieee80211_channel {
150
	enum nl80211_band band;
J
Johannes Berg 已提交
151 152 153 154 155
	u16 center_freq;
	u16 hw_value;
	u32 flags;
	int max_antenna_gain;
	int max_power;
156
	int max_reg_power;
J
Johannes Berg 已提交
157 158 159
	bool beacon_found;
	u32 orig_flags;
	int orig_mag, orig_mpwr;
160 161
	enum nl80211_dfs_state dfs_state;
	unsigned long dfs_state_entered;
162
	unsigned int dfs_cac_ms;
J
Johannes Berg 已提交
163 164
};

A
Andy Green 已提交
165
/**
J
Johannes Berg 已提交
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
 * enum ieee80211_rate_flags - rate flags
 *
 * Hardware/specification flags for rates. These are structured
 * in a way that allows using the same bitrate structure for
 * different bands/PHY modes.
 *
 * @IEEE80211_RATE_SHORT_PREAMBLE: Hardware can send with short
 *	preamble on this bitrate; only relevant in 2.4GHz band and
 *	with CCK rates.
 * @IEEE80211_RATE_MANDATORY_A: This bitrate is a mandatory rate
 *	when used with 802.11a (on the 5 GHz band); filled by the
 *	core code when registering the wiphy.
 * @IEEE80211_RATE_MANDATORY_B: This bitrate is a mandatory rate
 *	when used with 802.11b (on the 2.4 GHz band); filled by the
 *	core code when registering the wiphy.
 * @IEEE80211_RATE_MANDATORY_G: This bitrate is a mandatory rate
 *	when used with 802.11g (on the 2.4 GHz band); filled by the
 *	core code when registering the wiphy.
 * @IEEE80211_RATE_ERP_G: This is an ERP rate in 802.11g mode.
185 186
 * @IEEE80211_RATE_SUPPORTS_5MHZ: Rate can be used in 5 MHz mode
 * @IEEE80211_RATE_SUPPORTS_10MHZ: Rate can be used in 10 MHz mode
A
Andy Green 已提交
187
 */
J
Johannes Berg 已提交
188 189 190 191 192 193
enum ieee80211_rate_flags {
	IEEE80211_RATE_SHORT_PREAMBLE	= 1<<0,
	IEEE80211_RATE_MANDATORY_A	= 1<<1,
	IEEE80211_RATE_MANDATORY_B	= 1<<2,
	IEEE80211_RATE_MANDATORY_G	= 1<<3,
	IEEE80211_RATE_ERP_G		= 1<<4,
194 195
	IEEE80211_RATE_SUPPORTS_5MHZ	= 1<<5,
	IEEE80211_RATE_SUPPORTS_10MHZ	= 1<<6,
J
Johannes Berg 已提交
196
};
A
Andy Green 已提交
197

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
/**
 * enum ieee80211_bss_type - BSS type filter
 *
 * @IEEE80211_BSS_TYPE_ESS: Infrastructure BSS
 * @IEEE80211_BSS_TYPE_PBSS: Personal BSS
 * @IEEE80211_BSS_TYPE_IBSS: Independent BSS
 * @IEEE80211_BSS_TYPE_MBSS: Mesh BSS
 * @IEEE80211_BSS_TYPE_ANY: Wildcard value for matching any BSS type
 */
enum ieee80211_bss_type {
	IEEE80211_BSS_TYPE_ESS,
	IEEE80211_BSS_TYPE_PBSS,
	IEEE80211_BSS_TYPE_IBSS,
	IEEE80211_BSS_TYPE_MBSS,
	IEEE80211_BSS_TYPE_ANY
};

/**
 * enum ieee80211_privacy - BSS privacy filter
 *
 * @IEEE80211_PRIVACY_ON: privacy bit set
 * @IEEE80211_PRIVACY_OFF: privacy bit clear
 * @IEEE80211_PRIVACY_ANY: Wildcard value for matching any privacy setting
 */
enum ieee80211_privacy {
	IEEE80211_PRIVACY_ON,
	IEEE80211_PRIVACY_OFF,
	IEEE80211_PRIVACY_ANY
};

#define IEEE80211_PRIVACY(x)	\
	((x) ? IEEE80211_PRIVACY_ON : IEEE80211_PRIVACY_OFF)

J
Johannes Berg 已提交
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
/**
 * struct ieee80211_rate - bitrate definition
 *
 * This structure describes a bitrate that an 802.11 PHY can
 * operate with. The two values @hw_value and @hw_value_short
 * are only for driver use when pointers to this structure are
 * passed around.
 *
 * @flags: rate-specific flags
 * @bitrate: bitrate in units of 100 Kbps
 * @hw_value: driver/hardware value for this rate
 * @hw_value_short: driver/hardware value for this rate when
 *	short preamble is used
 */
struct ieee80211_rate {
	u32 flags;
	u16 bitrate;
	u16 hw_value, hw_value_short;
};
A
Andy Green 已提交
250

J
Johannes Berg 已提交
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
/**
 * struct ieee80211_sta_ht_cap - STA's HT capabilities
 *
 * This structure describes most essential parameters needed
 * to describe 802.11n HT capabilities for an STA.
 *
 * @ht_supported: is HT supported by the STA
 * @cap: HT capabilities map as described in 802.11n spec
 * @ampdu_factor: Maximum A-MPDU length factor
 * @ampdu_density: Minimum A-MPDU spacing
 * @mcs: Supported MCS rates
 */
struct ieee80211_sta_ht_cap {
	u16 cap; /* use IEEE80211_HT_CAP_ */
	bool ht_supported;
	u8 ampdu_factor;
	u8 ampdu_density;
	struct ieee80211_mcs_info mcs;
A
Andy Green 已提交
269 270
};

271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
/**
 * struct ieee80211_sta_vht_cap - STA's VHT capabilities
 *
 * This structure describes most essential parameters needed
 * to describe 802.11ac VHT capabilities for an STA.
 *
 * @vht_supported: is VHT supported by the STA
 * @cap: VHT capabilities map as described in 802.11ac spec
 * @vht_mcs: Supported VHT MCS rates
 */
struct ieee80211_sta_vht_cap {
	bool vht_supported;
	u32 cap; /* use IEEE80211_VHT_CAP_ */
	struct ieee80211_vht_mcs_info vht_mcs;
};

J
Johannes Berg 已提交
287 288 289 290 291 292 293 294 295 296 297 298 299 300
/**
 * struct ieee80211_supported_band - frequency band definition
 *
 * This structure describes a frequency band a wiphy
 * is able to operate in.
 *
 * @channels: Array of channels the hardware can operate in
 *	in this band.
 * @band: the band this structure represents
 * @n_channels: Number of channels in @channels
 * @bitrates: Array of bitrates the hardware can operate with
 *	in this band. Must be sorted to give a valid "supported
 *	rates" IE, i.e. CCK rates first, then OFDM.
 * @n_bitrates: Number of bitrates in @bitrates
J
Johannes Berg 已提交
301
 * @ht_cap: HT capabilities in this band
302
 * @vht_cap: VHT capabilities in this band
J
Johannes Berg 已提交
303 304 305 306
 */
struct ieee80211_supported_band {
	struct ieee80211_channel *channels;
	struct ieee80211_rate *bitrates;
307
	enum nl80211_band band;
J
Johannes Berg 已提交
308 309 310
	int n_channels;
	int n_bitrates;
	struct ieee80211_sta_ht_cap ht_cap;
311
	struct ieee80211_sta_vht_cap vht_cap;
J
Johannes Berg 已提交
312
};
A
Andy Green 已提交
313

314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
/**
 * wiphy_read_of_freq_limits - read frequency limits from device tree
 *
 * @wiphy: the wireless device to get extra limits for
 *
 * Some devices may have extra limitations specified in DT. This may be useful
 * for chipsets that normally support more bands but are limited due to board
 * design (e.g. by antennas or external power amplifier).
 *
 * This function reads info from DT and uses it to *modify* channels (disable
 * unavailable ones). It's usually a *bad* idea to use it in drivers with
 * shared channel data as DT limitations are device specific. You should make
 * sure to call it only if channels in wiphy are copied and can be modified
 * without affecting other devices.
 *
 * As this function access device node it has to be called after set_wiphy_dev.
 * It also modifies channels so they have to be set first.
 * If using this helper, call it before wiphy_register().
 */
#ifdef CONFIG_OF
void wiphy_read_of_freq_limits(struct wiphy *wiphy);
#else /* CONFIG_OF */
static inline void wiphy_read_of_freq_limits(struct wiphy *wiphy)
{
}
#endif /* !CONFIG_OF */


J
Johannes Berg 已提交
342 343 344
/*
 * Wireless hardware/device configuration structures and methods
 */
A
Andy Green 已提交
345

J
Johannes Berg 已提交
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
/**
 * DOC: Actions and configuration
 *
 * Each wireless device and each virtual interface offer a set of configuration
 * operations and other actions that are invoked by userspace. Each of these
 * actions is described in the operations structure, and the parameters these
 * operations use are described separately.
 *
 * Additionally, some operations are asynchronous and expect to get status
 * information via some functions that drivers need to call.
 *
 * Scanning and BSS list handling with its associated functionality is described
 * in a separate chapter.
 */

361 362 363
#define VHT_MUMIMO_GROUPS_DATA_LEN (WLAN_MEMBERSHIP_LEN +\
				    WLAN_USER_POSITION_LEN)

J
Johannes Berg 已提交
364 365
/**
 * struct vif_params - describes virtual interface parameters
366
 * @use_4addr: use 4-address frames
367 368 369 370 371 372
 * @macaddr: address to use for this virtual interface.
 *	If this parameter is set to zero address the driver may
 *	determine the address as needed.
 *	This feature is only fully supported by drivers that enable the
 *	%NL80211_FEATURE_MAC_ON_CREATE flag.  Others may support creating
 **	only p2p devices with specified MAC.
373 374
 * @vht_mumimo_groups: MU-MIMO groupID. used for monitoring only
 *	 packets belonging to that MU-MIMO groupID.
J
Johannes Berg 已提交
375 376
 */
struct vif_params {
377 378 379
	int use_4addr;
	u8 macaddr[ETH_ALEN];
	u8 vht_mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN];
J
Johannes Berg 已提交
380
};
A
Andy Green 已提交
381

J
Johannes Berg 已提交
382
/**
383 384 385 386 387 388 389 390 391 392
 * struct key_params - key information
 *
 * Information about a key
 *
 * @key: key material
 * @key_len: length of key material
 * @cipher: cipher suite selector
 * @seq: sequence counter (IV/PN) for TKIP and CCMP keys, only used
 *	with the get_key() callback, must be in little endian,
 *	length given by @seq_len.
J
Johannes Berg 已提交
393
 * @seq_len: length of @seq.
394 395
 */
struct key_params {
396 397
	const u8 *key;
	const u8 *seq;
398 399 400 401 402
	int key_len;
	int seq_len;
	u32 cipher;
};

403 404 405
/**
 * struct cfg80211_chan_def - channel definition
 * @chan: the (control) channel
406 407 408 409
 * @width: channel width
 * @center_freq1: center frequency of first segment
 * @center_freq2: center frequency of second segment
 *	(only with 80+80 MHz)
410 411 412
 */
struct cfg80211_chan_def {
	struct ieee80211_channel *chan;
413 414 415
	enum nl80211_chan_width width;
	u32 center_freq1;
	u32 center_freq2;
416 417
};

418 419 420 421
/**
 * cfg80211_get_chandef_type - return old channel type from chandef
 * @chandef: the channel definition
 *
422
 * Return: The old channel type (NOHT, HT20, HT40+/-) from a given
423 424
 * chandef, which must have a bandwidth allowing this conversion.
 */
425 426 427
static inline enum nl80211_channel_type
cfg80211_get_chandef_type(const struct cfg80211_chan_def *chandef)
{
428 429 430 431 432 433 434 435 436 437 438 439 440
	switch (chandef->width) {
	case NL80211_CHAN_WIDTH_20_NOHT:
		return NL80211_CHAN_NO_HT;
	case NL80211_CHAN_WIDTH_20:
		return NL80211_CHAN_HT20;
	case NL80211_CHAN_WIDTH_40:
		if (chandef->center_freq1 > chandef->chan->center_freq)
			return NL80211_CHAN_HT40PLUS;
		return NL80211_CHAN_HT40MINUS;
	default:
		WARN_ON(1);
		return NL80211_CHAN_NO_HT;
	}
441 442
}

443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
/**
 * cfg80211_chandef_create - create channel definition using channel type
 * @chandef: the channel definition struct to fill
 * @channel: the control channel
 * @chantype: the channel type
 *
 * Given a channel type, create a channel definition.
 */
void cfg80211_chandef_create(struct cfg80211_chan_def *chandef,
			     struct ieee80211_channel *channel,
			     enum nl80211_channel_type chantype);

/**
 * cfg80211_chandef_identical - check if two channel definitions are identical
 * @chandef1: first channel definition
 * @chandef2: second channel definition
 *
460
 * Return: %true if the channels defined by the channel definitions are
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
 * identical, %false otherwise.
 */
static inline bool
cfg80211_chandef_identical(const struct cfg80211_chan_def *chandef1,
			   const struct cfg80211_chan_def *chandef2)
{
	return (chandef1->chan == chandef2->chan &&
		chandef1->width == chandef2->width &&
		chandef1->center_freq1 == chandef2->center_freq1 &&
		chandef1->center_freq2 == chandef2->center_freq2);
}

/**
 * cfg80211_chandef_compatible - check if two channel definitions are compatible
 * @chandef1: first channel definition
 * @chandef2: second channel definition
 *
478
 * Return: %NULL if the given channel definitions are incompatible,
479 480 481 482 483 484
 * chandef1 or chandef2 otherwise.
 */
const struct cfg80211_chan_def *
cfg80211_chandef_compatible(const struct cfg80211_chan_def *chandef1,
			    const struct cfg80211_chan_def *chandef2);

485 486 487
/**
 * cfg80211_chandef_valid - check if a channel definition is valid
 * @chandef: the channel definition to check
488
 * Return: %true if the channel definition is valid. %false otherwise.
489 490 491 492 493 494 495
 */
bool cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef);

/**
 * cfg80211_chandef_usable - check if secondary channels can be used
 * @wiphy: the wiphy to validate against
 * @chandef: the channel definition to check
496 497
 * @prohibited_flags: the regulatory channel flags that must not be set
 * Return: %true if secondary channels are usable. %false otherwise.
498 499 500 501 502
 */
bool cfg80211_chandef_usable(struct wiphy *wiphy,
			     const struct cfg80211_chan_def *chandef,
			     u32 prohibited_flags);

503 504 505 506
/**
 * cfg80211_chandef_dfs_required - checks if radar detection is required
 * @wiphy: the wiphy to validate against
 * @chandef: the channel definition to check
507 508 509
 * @iftype: the interface type as specified in &enum nl80211_iftype
 * Returns:
 *	1 if radar detection is required, 0 if it is not, < 0 on error
510 511
 */
int cfg80211_chandef_dfs_required(struct wiphy *wiphy,
512
				  const struct cfg80211_chan_def *chandef,
L
Luciano Coelho 已提交
513
				  enum nl80211_iftype iftype);
514

515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
/**
 * ieee80211_chandef_rate_flags - returns rate flags for a channel
 *
 * In some channel types, not all rates may be used - for example CCK
 * rates may not be used in 5/10 MHz channels.
 *
 * @chandef: channel definition for the channel
 *
 * Returns: rate flags which apply for this channel
 */
static inline enum ieee80211_rate_flags
ieee80211_chandef_rate_flags(struct cfg80211_chan_def *chandef)
{
	switch (chandef->width) {
	case NL80211_CHAN_WIDTH_5:
		return IEEE80211_RATE_SUPPORTS_5MHZ;
	case NL80211_CHAN_WIDTH_10:
		return IEEE80211_RATE_SUPPORTS_10MHZ;
	default:
		break;
	}
	return 0;
}

539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
/**
 * ieee80211_chandef_max_power - maximum transmission power for the chandef
 *
 * In some regulations, the transmit power may depend on the configured channel
 * bandwidth which may be defined as dBm/MHz. This function returns the actual
 * max_power for non-standard (20 MHz) channels.
 *
 * @chandef: channel definition for the channel
 *
 * Returns: maximum allowed transmission power in dBm for the chandef
 */
static inline int
ieee80211_chandef_max_power(struct cfg80211_chan_def *chandef)
{
	switch (chandef->width) {
	case NL80211_CHAN_WIDTH_5:
		return min(chandef->chan->max_reg_power - 6,
			   chandef->chan->max_power);
	case NL80211_CHAN_WIDTH_10:
		return min(chandef->chan->max_reg_power - 3,
			   chandef->chan->max_power);
	default:
		break;
	}
	return chandef->chan->max_power;
}

566 567 568
/**
 * enum survey_info_flags - survey information flags
 *
J
Johannes Berg 已提交
569
 * @SURVEY_INFO_NOISE_DBM: noise (in dBm) was filled in
570
 * @SURVEY_INFO_IN_USE: channel is currently being used
571 572 573 574 575
 * @SURVEY_INFO_TIME: active time (in ms) was filled in
 * @SURVEY_INFO_TIME_BUSY: busy time was filled in
 * @SURVEY_INFO_TIME_EXT_BUSY: extension channel busy time was filled in
 * @SURVEY_INFO_TIME_RX: receive time was filled in
 * @SURVEY_INFO_TIME_TX: transmit time was filled in
576
 * @SURVEY_INFO_TIME_SCAN: scan time was filled in
J
Johannes Berg 已提交
577
 *
578 579 580 581
 * Used by the driver to indicate which info in &struct survey_info
 * it has filled in during the get_survey().
 */
enum survey_info_flags {
582 583 584 585 586 587 588
	SURVEY_INFO_NOISE_DBM		= BIT(0),
	SURVEY_INFO_IN_USE		= BIT(1),
	SURVEY_INFO_TIME		= BIT(2),
	SURVEY_INFO_TIME_BUSY		= BIT(3),
	SURVEY_INFO_TIME_EXT_BUSY	= BIT(4),
	SURVEY_INFO_TIME_RX		= BIT(5),
	SURVEY_INFO_TIME_TX		= BIT(6),
589
	SURVEY_INFO_TIME_SCAN		= BIT(7),
590 591 592 593 594
};

/**
 * struct survey_info - channel survey response
 *
595 596
 * @channel: the channel this survey record reports, may be %NULL for a single
 *	record to report global statistics
597 598
 * @filled: bitflag of flags from &enum survey_info_flags
 * @noise: channel noise in dBm. This and all following fields are
599
 *	optional
600 601 602 603 604
 * @time: amount of time in ms the radio was turn on (on the channel)
 * @time_busy: amount of time the primary channel was sensed busy
 * @time_ext_busy: amount of time the extension channel was sensed busy
 * @time_rx: amount of time the radio spent receiving data
 * @time_tx: amount of time the radio spent transmitting data
605
 * @time_scan: amount of time the radio spent for scanning
606
 *
J
Johannes Berg 已提交
607 608
 * Used by dump_survey() to report back per-channel survey information.
 *
609 610 611 612 613
 * This structure can later be expanded with things like
 * channel duty cycle etc.
 */
struct survey_info {
	struct ieee80211_channel *channel;
614 615 616 617 618
	u64 time;
	u64 time_busy;
	u64 time_ext_busy;
	u64 time_rx;
	u64 time_tx;
619
	u64 time_scan;
620 621 622 623
	u32 filled;
	s8 noise;
};

624 625
#define CFG80211_MAX_WEP_KEYS	4

626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
/**
 * struct cfg80211_crypto_settings - Crypto settings
 * @wpa_versions: indicates which, if any, WPA versions are enabled
 *	(from enum nl80211_wpa_versions)
 * @cipher_group: group key cipher suite (or 0 if unset)
 * @n_ciphers_pairwise: number of AP supported unicast ciphers
 * @ciphers_pairwise: unicast key cipher suites
 * @n_akm_suites: number of AKM suites
 * @akm_suites: AKM suites
 * @control_port: Whether user space controls IEEE 802.1X port, i.e.,
 *	sets/clears %NL80211_STA_FLAG_AUTHORIZED. If true, the driver is
 *	required to assume that the port is unauthorized until authorized by
 *	user space. Otherwise, port is marked authorized by default.
 * @control_port_ethertype: the control port protocol that should be
 *	allowed through even on unauthorized ports
 * @control_port_no_encrypt: TRUE to prevent encryption of control port
 *	protocol frames.
643 644 645
 * @wep_keys: static WEP keys, if not NULL points to an array of
 *	CFG80211_MAX_WEP_KEYS WEP keys
 * @wep_tx_key: key index (0..3) of the default TX static WEP key
646 647 648 649 650 651 652 653 654 655 656
 */
struct cfg80211_crypto_settings {
	u32 wpa_versions;
	u32 cipher_group;
	int n_ciphers_pairwise;
	u32 ciphers_pairwise[NL80211_MAX_NR_CIPHER_SUITES];
	int n_akm_suites;
	u32 akm_suites[NL80211_MAX_NR_AKM_SUITES];
	bool control_port;
	__be16 control_port_ethertype;
	bool control_port_no_encrypt;
657 658
	struct key_params *wep_keys;
	int wep_tx_key;
659 660
};

661
/**
662
 * struct cfg80211_beacon_data - beacon data
663
 * @head: head portion of beacon (before TIM IE)
664
 *	or %NULL if not changed
665
 * @tail: tail portion of beacon (after TIM IE)
666
 *	or %NULL if not changed
667 668
 * @head_len: length of @head
 * @tail_len: length of @tail
669 670 671 672 673 674 675 676
 * @beacon_ies: extra information element(s) to add into Beacon frames or %NULL
 * @beacon_ies_len: length of beacon_ies in octets
 * @proberesp_ies: extra information element(s) to add into Probe Response
 *	frames or %NULL
 * @proberesp_ies_len: length of proberesp_ies in octets
 * @assocresp_ies: extra information element(s) to add into (Re)Association
 *	Response frames or %NULL
 * @assocresp_ies_len: length of assocresp_ies in octets
677 678
 * @probe_resp_len: length of probe response template (@probe_resp)
 * @probe_resp: probe response template (AP mode only)
679
 */
680 681 682 683 684 685 686 687 688 689 690 691 692 693
struct cfg80211_beacon_data {
	const u8 *head, *tail;
	const u8 *beacon_ies;
	const u8 *proberesp_ies;
	const u8 *assocresp_ies;
	const u8 *probe_resp;

	size_t head_len, tail_len;
	size_t beacon_ies_len;
	size_t proberesp_ies_len;
	size_t assocresp_ies_len;
	size_t probe_resp_len;
};

694 695 696 697
struct mac_address {
	u8 addr[ETH_ALEN];
};

698 699 700 701
/**
 * struct cfg80211_acl_data - Access control list data
 *
 * @acl_policy: ACL policy to be applied on the station's
J
Johannes Berg 已提交
702
 *	entry specified by mac_addr
703 704 705 706 707 708 709 710 711 712 713
 * @n_acl_entries: Number of MAC address entries passed
 * @mac_addrs: List of MAC addresses of stations to be used for ACL
 */
struct cfg80211_acl_data {
	enum nl80211_acl_policy acl_policy;
	int n_acl_entries;

	/* Keep it last */
	struct mac_address mac_addrs[];
};

714 715 716 717 718 719 720 721 722 723 724 725
/*
 * cfg80211_bitrate_mask - masks for bitrate control
 */
struct cfg80211_bitrate_mask {
	struct {
		u32 legacy;
		u8 ht_mcs[IEEE80211_HT_MCS_MASK_LEN];
		u16 vht_mcs[NL80211_VHT_NSS_MAX];
		enum nl80211_txrate_gi gi;
	} control[NUM_NL80211_BANDS];
};

726 727 728 729 730
/**
 * struct cfg80211_ap_settings - AP configuration
 *
 * Used to configure an AP interface.
 *
731
 * @chandef: defines the channel to use
732 733 734 735 736 737 738 739 740 741
 * @beacon: beacon data
 * @beacon_interval: beacon interval
 * @dtim_period: DTIM period
 * @ssid: SSID to be used in the BSS (note: may be %NULL if not provided from
 *	user space)
 * @ssid_len: length of @ssid
 * @hidden_ssid: whether to hide the SSID in Beacon/Probe Response frames
 * @crypto: crypto settings
 * @privacy: the BSS uses privacy
 * @auth_type: Authentication type (algorithm)
742
 * @smps_mode: SMPS mode
743
 * @inactivity_timeout: time in seconds to determine station's inactivity.
744 745
 * @p2p_ctwindow: P2P CT Window
 * @p2p_opp_ps: P2P opportunistic PS
746 747
 * @acl: ACL configuration used by the drivers which has support for
 *	MAC address based access control
748 749
 * @pbss: If set, start as a PCP instead of AP. Relevant for DMG
 *	networks.
750
 * @beacon_rate: bitrate to be used for beacons
751 752 753 754
 * @ht_cap: HT capabilities (or %NULL if HT isn't enabled)
 * @vht_cap: VHT capabilities (or %NULL if VHT isn't enabled)
 * @ht_required: stations must support HT
 * @vht_required: stations must support VHT
755 756
 */
struct cfg80211_ap_settings {
757
	struct cfg80211_chan_def chandef;
758

759 760 761
	struct cfg80211_beacon_data beacon;

	int beacon_interval, dtim_period;
762 763 764
	const u8 *ssid;
	size_t ssid_len;
	enum nl80211_hidden_ssid hidden_ssid;
765 766 767
	struct cfg80211_crypto_settings crypto;
	bool privacy;
	enum nl80211_auth_type auth_type;
768
	enum nl80211_smps_mode smps_mode;
769
	int inactivity_timeout;
770 771
	u8 p2p_ctwindow;
	bool p2p_opp_ps;
772
	const struct cfg80211_acl_data *acl;
773
	bool pbss;
774
	struct cfg80211_bitrate_mask beacon_rate;
775 776 777 778

	const struct ieee80211_ht_cap *ht_cap;
	const struct ieee80211_vht_cap *vht_cap;
	bool ht_required, vht_required;
779 780
};

781 782 783 784 785 786 787
/**
 * struct cfg80211_csa_settings - channel switch settings
 *
 * Used for channel switch
 *
 * @chandef: defines the channel to use after the switch
 * @beacon_csa: beacon data while performing the switch
788 789 790 791
 * @counter_offsets_beacon: offsets of the counters within the beacon (tail)
 * @counter_offsets_presp: offsets of the counters within the probe response
 * @n_counter_offsets_beacon: number of csa counters the beacon (tail)
 * @n_counter_offsets_presp: number of csa counters in the probe response
792 793 794 795 796 797 798 799
 * @beacon_after: beacon data to be used on the new channel
 * @radar_required: whether radar detection is required on the new channel
 * @block_tx: whether transmissions should be blocked while changing
 * @count: number of beacons until switch
 */
struct cfg80211_csa_settings {
	struct cfg80211_chan_def chandef;
	struct cfg80211_beacon_data beacon_csa;
800 801 802 803
	const u16 *counter_offsets_beacon;
	const u16 *counter_offsets_presp;
	unsigned int n_counter_offsets_beacon;
	unsigned int n_counter_offsets_presp;
804 805 806 807 808 809
	struct cfg80211_beacon_data beacon_after;
	bool radar_required;
	bool block_tx;
	u8 count;
};

810 811 812 813 814 815 816 817 818 819 820 821 822
/**
 * struct iface_combination_params - input parameters for interface combinations
 *
 * Used to pass interface combination parameters
 *
 * @num_different_channels: the number of different channels we want
 *	to use for verification
 * @radar_detect: a bitmap where each bit corresponds to a channel
 *	width where radar detection is needed, as in the definition of
 *	&struct ieee80211_iface_combination.@radar_detect_widths
 * @iftype_num: array with the number of interfaces of each interface
 *	type.  The index is the interface type as specified in &enum
 *	nl80211_iftype.
823 824 825
 * @new_beacon_int: set this to the beacon interval of a new interface
 *	that's not operating yet, if such is to be checked as part of
 *	the verification
826 827 828 829 830
 */
struct iface_combination_params {
	int num_different_channels;
	u8 radar_detect;
	int iftype_num[NUM_NL80211_IFTYPES];
831
	u32 new_beacon_int;
832 833
};

834 835 836
/**
 * enum station_parameters_apply_mask - station parameter values to apply
 * @STATION_PARAM_APPLY_UAPSD: apply new uAPSD parameters (uapsd_queues, max_sp)
837
 * @STATION_PARAM_APPLY_CAPABILITY: apply new capability
838
 * @STATION_PARAM_APPLY_PLINK_STATE: apply new plink state
839 840 841 842 843 844
 *
 * Not all station parameters have in-band "no change" signalling,
 * for those that don't these flags will are used.
 */
enum station_parameters_apply_mask {
	STATION_PARAM_APPLY_UAPSD = BIT(0),
845
	STATION_PARAM_APPLY_CAPABILITY = BIT(1),
846
	STATION_PARAM_APPLY_PLINK_STATE = BIT(2),
847 848
};

849 850 851 852 853 854 855 856 857
/**
 * struct station_parameters - station parameters
 *
 * Used to change and create a new station.
 *
 * @vlan: vlan interface station should belong to
 * @supported_rates: supported rates in IEEE 802.11 format
 *	(or NULL for no change)
 * @supported_rates_len: number of supported rates
858
 * @sta_flags_mask: station flags that changed
859
 *	(bitmask of BIT(%NL80211_STA_FLAG_...))
860
 * @sta_flags_set: station flags values
861
 *	(bitmask of BIT(%NL80211_STA_FLAG_...))
862 863
 * @listen_interval: listen interval or -1 for no change
 * @aid: AID or zero for no change
864
 * @peer_aid: mesh peer AID or zero for no change
J
Johannes Berg 已提交
865
 * @plink_action: plink action to take
866
 * @plink_state: set the peer link state for a station
J
Johannes Berg 已提交
867
 * @ht_capa: HT capabilities of station
M
Mahesh Palivela 已提交
868
 * @vht_capa: VHT capabilities of station
869 870 871 872
 * @uapsd_queues: bitmap of queues configured for uapsd. same format
 *	as the AC bitmap in the QoS info field
 * @max_sp: max Service Period. same format as the MAX_SP in the
 *	QoS info field (but already shifted down)
J
Johannes Berg 已提交
873 874 875
 * @sta_modify_mask: bitmap indicating which parameters changed
 *	(for those that don't have a natural "no change" value),
 *	see &enum station_parameters_apply_mask
876 877
 * @local_pm: local link-specific mesh power save mode (no change when set
 *	to unknown)
878 879 880
 * @capability: station capability
 * @ext_capab: extended capabilities of the station
 * @ext_capab_len: number of extended capabilities
881 882 883 884
 * @supported_channels: supported channels in IEEE 802.11 format
 * @supported_channels_len: number of supported channels
 * @supported_oper_classes: supported oper classes in IEEE 802.11 format
 * @supported_oper_classes_len: number of supported operating classes
885 886
 * @opmode_notif: operating mode field from Operating Mode Notification
 * @opmode_notif_used: information if operating mode field is used
887
 * @support_p2p_ps: information if station supports P2P PS mechanism
888 889
 */
struct station_parameters {
890
	const u8 *supported_rates;
891
	struct net_device *vlan;
892
	u32 sta_flags_mask, sta_flags_set;
893
	u32 sta_modify_mask;
894 895
	int listen_interval;
	u16 aid;
896
	u16 peer_aid;
897
	u8 supported_rates_len;
898
	u8 plink_action;
899
	u8 plink_state;
900 901
	const struct ieee80211_ht_cap *ht_capa;
	const struct ieee80211_vht_cap *vht_capa;
902 903
	u8 uapsd_queues;
	u8 max_sp;
904
	enum nl80211_mesh_power_mode local_pm;
905
	u16 capability;
906
	const u8 *ext_capab;
907
	u8 ext_capab_len;
908 909 910 911
	const u8 *supported_channels;
	u8 supported_channels_len;
	const u8 *supported_oper_classes;
	u8 supported_oper_classes_len;
912 913
	u8 opmode_notif;
	bool opmode_notif_used;
914
	int support_p2p_ps;
915 916
};

917 918 919 920 921 922
/**
 * struct station_del_parameters - station deletion parameters
 *
 * Used to delete a station entry (or all stations).
 *
 * @mac: MAC address of the station to remove or NULL to remove all stations
923 924 925
 * @subtype: Management frame subtype to use for indicating removal
 *	(10 = Disassociation, 12 = Deauthentication)
 * @reason_code: Reason code for the Disassociation/Deauthentication frame
926 927 928
 */
struct station_del_parameters {
	const u8 *mac;
929 930
	u8 subtype;
	u16 reason_code;
931 932
};

933 934 935
/**
 * enum cfg80211_station_type - the type of station being modified
 * @CFG80211_STA_AP_CLIENT: client of an AP interface
936 937
 * @CFG80211_STA_AP_CLIENT_UNASSOC: client of an AP interface that is still
 *	unassociated (update properties for this type of client is permitted)
938 939 940 941 942 943 944 945 946 947
 * @CFG80211_STA_AP_MLME_CLIENT: client of an AP interface that has
 *	the AP MLME in the device
 * @CFG80211_STA_AP_STA: AP station on managed interface
 * @CFG80211_STA_IBSS: IBSS station
 * @CFG80211_STA_TDLS_PEER_SETUP: TDLS peer on managed interface (dummy entry
 *	while TDLS setup is in progress, it moves out of this state when
 *	being marked authorized; use this only if TDLS with external setup is
 *	supported/used)
 * @CFG80211_STA_TDLS_PEER_ACTIVE: TDLS peer on managed interface (active
 *	entry that is operating, has been marked authorized by userspace)
948 949
 * @CFG80211_STA_MESH_PEER_KERNEL: peer on mesh interface (kernel managed)
 * @CFG80211_STA_MESH_PEER_USER: peer on mesh interface (user managed)
950 951 952
 */
enum cfg80211_station_type {
	CFG80211_STA_AP_CLIENT,
953
	CFG80211_STA_AP_CLIENT_UNASSOC,
954 955 956 957 958
	CFG80211_STA_AP_MLME_CLIENT,
	CFG80211_STA_AP_STA,
	CFG80211_STA_IBSS,
	CFG80211_STA_TDLS_PEER_SETUP,
	CFG80211_STA_TDLS_PEER_ACTIVE,
959 960
	CFG80211_STA_MESH_PEER_KERNEL,
	CFG80211_STA_MESH_PEER_USER,
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
};

/**
 * cfg80211_check_station_change - validate parameter changes
 * @wiphy: the wiphy this operates on
 * @params: the new parameters for a station
 * @statype: the type of station being modified
 *
 * Utility function for the @change_station driver method. Call this function
 * with the appropriate station type looking up the station (and checking that
 * it exists). It will verify whether the station change is acceptable, and if
 * not will return an error code. Note that it may modify the parameters for
 * backward compatibility reasons, so don't use them before calling this.
 */
int cfg80211_check_station_change(struct wiphy *wiphy,
				  struct station_parameters *params,
				  enum cfg80211_station_type statype);

979 980 981 982 983 984
/**
 * enum station_info_rate_flags - bitrate info flags
 *
 * Used by the driver to indicate the specific rate transmission
 * type for 802.11n transmissions.
 *
985 986
 * @RATE_INFO_FLAGS_MCS: mcs field filled with HT MCS
 * @RATE_INFO_FLAGS_VHT_MCS: mcs field filled with VHT MCS
987
 * @RATE_INFO_FLAGS_SHORT_GI: 400ns guard interval
988
 * @RATE_INFO_FLAGS_60G: 60GHz MCS
989 990
 */
enum rate_info_flags {
991 992
	RATE_INFO_FLAGS_MCS			= BIT(0),
	RATE_INFO_FLAGS_VHT_MCS			= BIT(1),
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
	RATE_INFO_FLAGS_SHORT_GI		= BIT(2),
	RATE_INFO_FLAGS_60G			= BIT(3),
};

/**
 * enum rate_info_bw - rate bandwidth information
 *
 * Used by the driver to indicate the rate bandwidth.
 *
 * @RATE_INFO_BW_5: 5 MHz bandwidth
 * @RATE_INFO_BW_10: 10 MHz bandwidth
 * @RATE_INFO_BW_20: 20 MHz bandwidth
 * @RATE_INFO_BW_40: 40 MHz bandwidth
 * @RATE_INFO_BW_80: 80 MHz bandwidth
 * @RATE_INFO_BW_160: 160 MHz bandwidth
 */
enum rate_info_bw {
	RATE_INFO_BW_5,
	RATE_INFO_BW_10,
	RATE_INFO_BW_20,
	RATE_INFO_BW_40,
	RATE_INFO_BW_80,
	RATE_INFO_BW_160,
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
};

/**
 * struct rate_info - bitrate information
 *
 * Information about a receiving or transmitting bitrate
 *
 * @flags: bitflag of flags from &enum rate_info_flags
 * @mcs: mcs index if struct describes a 802.11n bitrate
 * @legacy: bitrate in 100kbit/s for 802.11abg
1026
 * @nss: number of streams (VHT only)
1027
 * @bw: bandwidth (from &enum rate_info_bw)
1028 1029 1030 1031 1032
 */
struct rate_info {
	u8 flags;
	u8 mcs;
	u16 legacy;
1033
	u8 nss;
1034
	u8 bw;
1035 1036
};

1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
/**
 * enum station_info_rate_flags - bitrate info flags
 *
 * Used by the driver to indicate the specific rate transmission
 * type for 802.11n transmissions.
 *
 * @BSS_PARAM_FLAGS_CTS_PROT: whether CTS protection is enabled
 * @BSS_PARAM_FLAGS_SHORT_PREAMBLE: whether short preamble is enabled
 * @BSS_PARAM_FLAGS_SHORT_SLOT_TIME: whether short slot time is enabled
 */
enum bss_param_flags {
	BSS_PARAM_FLAGS_CTS_PROT	= 1<<0,
	BSS_PARAM_FLAGS_SHORT_PREAMBLE	= 1<<1,
	BSS_PARAM_FLAGS_SHORT_SLOT_TIME	= 1<<2,
};

/**
 * struct sta_bss_parameters - BSS parameters for the attached station
 *
 * Information about the currently associated BSS
 *
 * @flags: bitflag of flags from &enum bss_param_flags
 * @dtim_period: DTIM period for the BSS
 * @beacon_interval: beacon interval
 */
struct sta_bss_parameters {
	u8 flags;
	u8 dtim_period;
	u16 beacon_interval;
};

1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
/**
 * struct cfg80211_tid_stats - per-TID statistics
 * @filled: bitmap of flags using the bits of &enum nl80211_tid_stats to
 *	indicate the relevant values in this struct are filled
 * @rx_msdu: number of received MSDUs
 * @tx_msdu: number of (attempted) transmitted MSDUs
 * @tx_msdu_retries: number of retries (not counting the first) for
 *	transmitted MSDUs
 * @tx_msdu_failed: number of failed transmitted MSDUs
 */
struct cfg80211_tid_stats {
	u32 filled;
	u64 rx_msdu;
	u64 tx_msdu;
	u64 tx_msdu_retries;
	u64 tx_msdu_failed;
};

1086 1087
#define IEEE80211_MAX_CHAINS	4

1088
/**
1089
 * struct station_info - station information
1090
 *
1091
 * Station information filled by driver for get_station() and dump_station.
1092
 *
1093 1094
 * @filled: bitflag of flags using the bits of &enum nl80211_sta_info to
 *	indicate the relevant values in this struct for them
1095
 * @connected_time: time(in secs) since a station is last connected
1096
 * @inactive_time: time since last station activity (tx/rx) in milliseconds
1097 1098
 * @rx_bytes: bytes (size of MPDUs) received from this station
 * @tx_bytes: bytes (size of MPDUs) transmitted to this station
1099 1100 1101
 * @llid: mesh local link id
 * @plid: mesh peer link id
 * @plink_state: mesh peer link state
J
Johannes Berg 已提交
1102 1103 1104 1105
 * @signal: The signal strength, type depends on the wiphy's signal_type.
 *	For CFG80211_SIGNAL_TYPE_MBM, value is expressed in _dBm_.
 * @signal_avg: Average signal strength, type depends on the wiphy's signal_type.
 *	For CFG80211_SIGNAL_TYPE_MBM, value is expressed in _dBm_.
1106 1107 1108
 * @chains: bitmask for filled values in @chain_signal, @chain_signal_avg
 * @chain_signal: per-chain signal strength of last received packet in dBm
 * @chain_signal_avg: per-chain signal strength average in dBm
1109 1110
 * @txrate: current unicast bitrate from this station
 * @rxrate: current unicast bitrate to this station
1111 1112 1113 1114
 * @rx_packets: packets (MSDUs & MMPDUs) received from this station
 * @tx_packets: packets (MSDUs & MMPDUs) transmitted to this station
 * @tx_retries: cumulative retry counts (MPDUs)
 * @tx_failed: number of failed transmissions (MPDUs) (retries exceeded, no ACK)
1115
 * @rx_dropped_misc:  Dropped for un-specified reason.
1116
 * @bss_param: current BSS parameters
1117 1118 1119 1120
 * @generation: generation number for nl80211 dumps.
 *	This number should increase every time the list of stations
 *	changes, i.e. when a station is added or removed, so that
 *	userspace can tell whether it got a consistent snapshot.
1121 1122 1123 1124 1125
 * @assoc_req_ies: IEs from (Re)Association Request.
 *	This is used only when in AP mode with drivers that do not use
 *	user space MLME/SME implementation. The information is provided for
 *	the cfg80211_new_sta() calls to notify user space of the IEs.
 * @assoc_req_ies_len: Length of assoc_req_ies buffer in octets.
J
Johannes Berg 已提交
1126
 * @sta_flags: station flags mask & values
1127
 * @beacon_loss_count: Number of times beacon loss event has triggered.
1128
 * @t_offset: Time offset of the station relative to this host.
1129 1130 1131
 * @local_pm: local mesh STA power save mode
 * @peer_pm: peer mesh STA power save mode
 * @nonpeer_pm: non-peer mesh STA power save mode
1132 1133
 * @expected_throughput: expected throughput in kbps (including 802.11 headers)
 *	towards this station.
1134 1135 1136
 * @rx_beacon: number of beacons received from this peer
 * @rx_beacon_signal_avg: signal strength average (in dBm) for beacons received
 *	from this peer
1137
 * @rx_duration: aggregate PPDU duration(usecs) for all the frames from a peer
1138 1139
 * @pertid: per-TID statistics, see &struct cfg80211_tid_stats, using the last
 *	(IEEE80211_NUM_TIDS) index for MSDUs not encapsulated in QoS-MPDUs.
1140
 */
1141
struct station_info {
1142
	u64 filled;
1143
	u32 connected_time;
1144
	u32 inactive_time;
1145 1146
	u64 rx_bytes;
	u64 tx_bytes;
1147 1148 1149
	u16 llid;
	u16 plid;
	u8 plink_state;
1150
	s8 signal;
1151
	s8 signal_avg;
1152 1153 1154 1155 1156

	u8 chains;
	s8 chain_signal[IEEE80211_MAX_CHAINS];
	s8 chain_signal_avg[IEEE80211_MAX_CHAINS];

1157
	struct rate_info txrate;
1158
	struct rate_info rxrate;
1159 1160
	u32 rx_packets;
	u32 tx_packets;
1161 1162
	u32 tx_retries;
	u32 tx_failed;
1163
	u32 rx_dropped_misc;
1164
	struct sta_bss_parameters bss_param;
1165
	struct nl80211_sta_flag_update sta_flags;
1166 1167

	int generation;
1168 1169 1170

	const u8 *assoc_req_ies;
	size_t assoc_req_ies_len;
1171

1172
	u32 beacon_loss_count;
1173
	s64 t_offset;
1174 1175 1176
	enum nl80211_mesh_power_mode local_pm;
	enum nl80211_mesh_power_mode peer_pm;
	enum nl80211_mesh_power_mode nonpeer_pm;
1177

1178
	u32 expected_throughput;
1179 1180

	u64 rx_beacon;
1181
	u64 rx_duration;
1182
	u8 rx_beacon_signal_avg;
1183
	struct cfg80211_tid_stats pertid[IEEE80211_NUM_TIDS + 1];
1184 1185
};

1186
#if IS_ENABLED(CONFIG_CFG80211)
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
/**
 * cfg80211_get_station - retrieve information about a given station
 * @dev: the device where the station is supposed to be connected to
 * @mac_addr: the mac address of the station of interest
 * @sinfo: pointer to the structure to fill with the information
 *
 * Returns 0 on success and sinfo is filled with the available information
 * otherwise returns a negative error code and the content of sinfo has to be
 * considered undefined.
 */
int cfg80211_get_station(struct net_device *dev, const u8 *mac_addr,
			 struct station_info *sinfo);
1199 1200 1201 1202 1203 1204 1205 1206
#else
static inline int cfg80211_get_station(struct net_device *dev,
				       const u8 *mac_addr,
				       struct station_info *sinfo)
{
	return -ENOENT;
}
#endif
1207

1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218
/**
 * enum monitor_flags - monitor flags
 *
 * Monitor interface configuration flags. Note that these must be the bits
 * according to the nl80211 flags.
 *
 * @MONITOR_FLAG_FCSFAIL: pass frames with bad FCS
 * @MONITOR_FLAG_PLCPFAIL: pass frames with bad PLCP
 * @MONITOR_FLAG_CONTROL: pass control frames
 * @MONITOR_FLAG_OTHER_BSS: disable BSSID filtering
 * @MONITOR_FLAG_COOK_FRAMES: report frames after processing
1219
 * @MONITOR_FLAG_ACTIVE: active monitor, ACKs frames on its MAC address
1220 1221 1222 1223 1224 1225 1226
 */
enum monitor_flags {
	MONITOR_FLAG_FCSFAIL		= 1<<NL80211_MNTR_FLAG_FCSFAIL,
	MONITOR_FLAG_PLCPFAIL		= 1<<NL80211_MNTR_FLAG_PLCPFAIL,
	MONITOR_FLAG_CONTROL		= 1<<NL80211_MNTR_FLAG_CONTROL,
	MONITOR_FLAG_OTHER_BSS		= 1<<NL80211_MNTR_FLAG_OTHER_BSS,
	MONITOR_FLAG_COOK_FRAMES	= 1<<NL80211_MNTR_FLAG_COOK_FRAMES,
1227
	MONITOR_FLAG_ACTIVE		= 1<<NL80211_MNTR_FLAG_ACTIVE,
1228 1229
};

1230 1231 1232 1233 1234 1235
/**
 * enum mpath_info_flags -  mesh path information flags
 *
 * Used by the driver to indicate which info in &struct mpath_info it has filled
 * in during get_station() or dump_station().
 *
J
Johannes Berg 已提交
1236 1237 1238 1239 1240 1241 1242
 * @MPATH_INFO_FRAME_QLEN: @frame_qlen filled
 * @MPATH_INFO_SN: @sn filled
 * @MPATH_INFO_METRIC: @metric filled
 * @MPATH_INFO_EXPTIME: @exptime filled
 * @MPATH_INFO_DISCOVERY_TIMEOUT: @discovery_timeout filled
 * @MPATH_INFO_DISCOVERY_RETRIES: @discovery_retries filled
 * @MPATH_INFO_FLAGS: @flags filled
1243 1244 1245
 */
enum mpath_info_flags {
	MPATH_INFO_FRAME_QLEN		= BIT(0),
1246
	MPATH_INFO_SN			= BIT(1),
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260
	MPATH_INFO_METRIC		= BIT(2),
	MPATH_INFO_EXPTIME		= BIT(3),
	MPATH_INFO_DISCOVERY_TIMEOUT	= BIT(4),
	MPATH_INFO_DISCOVERY_RETRIES	= BIT(5),
	MPATH_INFO_FLAGS		= BIT(6),
};

/**
 * struct mpath_info - mesh path information
 *
 * Mesh path information filled by driver for get_mpath() and dump_mpath().
 *
 * @filled: bitfield of flags from &enum mpath_info_flags
 * @frame_qlen: number of queued frames for this destination
1261
 * @sn: target sequence number
1262 1263 1264 1265 1266
 * @metric: metric (cost) of this mesh path
 * @exptime: expiration time for the mesh path from now, in msecs
 * @flags: mesh path flags
 * @discovery_timeout: total mesh path discovery timeout, in msecs
 * @discovery_retries: mesh path discovery retries
1267 1268 1269 1270
 * @generation: generation number for nl80211 dumps.
 *	This number should increase every time the list of mesh paths
 *	changes, i.e. when a station is added or removed, so that
 *	userspace can tell whether it got a consistent snapshot.
1271 1272 1273 1274
 */
struct mpath_info {
	u32 filled;
	u32 frame_qlen;
1275
	u32 sn;
1276 1277 1278 1279 1280
	u32 metric;
	u32 exptime;
	u32 discovery_timeout;
	u8 discovery_retries;
	u8 flags;
1281 1282

	int generation;
1283 1284
};

1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
/**
 * struct bss_parameters - BSS parameters
 *
 * Used to change BSS parameters (mainly for AP mode).
 *
 * @use_cts_prot: Whether to use CTS protection
 *	(0 = no, 1 = yes, -1 = do not change)
 * @use_short_preamble: Whether the use of short preambles is allowed
 *	(0 = no, 1 = yes, -1 = do not change)
 * @use_short_slot_time: Whether the use of short slot time is allowed
 *	(0 = no, 1 = yes, -1 = do not change)
1296 1297 1298
 * @basic_rates: basic rates in IEEE 802.11 format
 *	(or NULL for no change)
 * @basic_rates_len: number of basic rates
1299
 * @ap_isolate: do not forward packets between connected stations
1300 1301
 * @ht_opmode: HT Operation mode
 * 	(u16 = opmode, -1 = do not change)
1302 1303
 * @p2p_ctwindow: P2P CT Window (-1 = no change)
 * @p2p_opp_ps: P2P opportunistic PS (-1 = no change)
1304 1305 1306 1307 1308
 */
struct bss_parameters {
	int use_cts_prot;
	int use_short_preamble;
	int use_short_slot_time;
1309
	const u8 *basic_rates;
1310
	u8 basic_rates_len;
1311
	int ap_isolate;
1312
	int ht_opmode;
1313
	s8 p2p_ctwindow, p2p_opp_ps;
1314
};
1315

1316
/**
1317 1318 1319
 * struct mesh_config - 802.11s mesh configuration
 *
 * These parameters can be changed while the mesh is active.
1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367
 *
 * @dot11MeshRetryTimeout: the initial retry timeout in millisecond units used
 *	by the Mesh Peering Open message
 * @dot11MeshConfirmTimeout: the initial retry timeout in millisecond units
 *	used by the Mesh Peering Open message
 * @dot11MeshHoldingTimeout: the confirm timeout in millisecond units used by
 *	the mesh peering management to close a mesh peering
 * @dot11MeshMaxPeerLinks: the maximum number of peer links allowed on this
 *	mesh interface
 * @dot11MeshMaxRetries: the maximum number of peer link open retries that can
 *	be sent to establish a new peer link instance in a mesh
 * @dot11MeshTTL: the value of TTL field set at a source mesh STA
 * @element_ttl: the value of TTL field set at a mesh STA for path selection
 *	elements
 * @auto_open_plinks: whether we should automatically open peer links when we
 *	detect compatible mesh peers
 * @dot11MeshNbrOffsetMaxNeighbor: the maximum number of neighbors to
 *	synchronize to for 11s default synchronization method
 * @dot11MeshHWMPmaxPREQretries: the number of action frames containing a PREQ
 *	that an originator mesh STA can send to a particular path target
 * @path_refresh_time: how frequently to refresh mesh paths in milliseconds
 * @min_discovery_timeout: the minimum length of time to wait until giving up on
 *	a path discovery in milliseconds
 * @dot11MeshHWMPactivePathTimeout: the time (in TUs) for which mesh STAs
 *	receiving a PREQ shall consider the forwarding information from the
 *	root to be valid. (TU = time unit)
 * @dot11MeshHWMPpreqMinInterval: the minimum interval of time (in TUs) during
 *	which a mesh STA can send only one action frame containing a PREQ
 *	element
 * @dot11MeshHWMPperrMinInterval: the minimum interval of time (in TUs) during
 *	which a mesh STA can send only one Action frame containing a PERR
 *	element
 * @dot11MeshHWMPnetDiameterTraversalTime: the interval of time (in TUs) that
 *	it takes for an HWMP information element to propagate across the mesh
 * @dot11MeshHWMPRootMode: the configuration of a mesh STA as root mesh STA
 * @dot11MeshHWMPRannInterval: the interval of time (in TUs) between root
 *	announcements are transmitted
 * @dot11MeshGateAnnouncementProtocol: whether to advertise that this mesh
 *	station has access to a broader network beyond the MBSS. (This is
 *	missnamed in draft 12.0: dot11MeshGateAnnouncementProtocol set to true
 *	only means that the station will announce others it's a mesh gate, but
 *	not necessarily using the gate announcement protocol. Still keeping the
 *	same nomenclature to be in sync with the spec)
 * @dot11MeshForwarding: whether the Mesh STA is forwarding or non-forwarding
 *	entity (default is TRUE - forwarding entity)
 * @rssi_threshold: the threshold for average signal strength of candidate
 *	station to establish a peer link
 * @ht_opmode: mesh HT protection mode
1368 1369 1370 1371 1372 1373 1374
 *
 * @dot11MeshHWMPactivePathToRootTimeout: The time (in TUs) for which mesh STAs
 *	receiving a proactive PREQ shall consider the forwarding information to
 *	the root mesh STA to be valid.
 *
 * @dot11MeshHWMProotInterval: The interval of time (in TUs) between proactive
 *	PREQs are transmitted.
1375 1376 1377
 * @dot11MeshHWMPconfirmationInterval: The minimum interval of time (in TUs)
 *	during which a mesh STA can send only one Action frame containing
 *	a PREQ element for root path confirmation.
1378 1379 1380 1381
 * @power_mode: The default mesh power save mode which will be the initial
 *	setting for new peer links.
 * @dot11MeshAwakeWindowDuration: The duration in TUs the STA will remain awake
 *	after transmitting its beacon.
1382 1383 1384
 * @plink_timeout: If no tx activity is seen from a STA we've established
 *	peering with for longer than this time (in seconds), then remove it
 *	from the STA's list of peers.  Default is 30 minutes.
1385
 */
1386 1387 1388 1389 1390
struct mesh_config {
	u16 dot11MeshRetryTimeout;
	u16 dot11MeshConfirmTimeout;
	u16 dot11MeshHoldingTimeout;
	u16 dot11MeshMaxPeerLinks;
1391 1392 1393
	u8 dot11MeshMaxRetries;
	u8 dot11MeshTTL;
	u8 element_ttl;
1394
	bool auto_open_plinks;
1395
	u32 dot11MeshNbrOffsetMaxNeighbor;
1396
	u8 dot11MeshHWMPmaxPREQretries;
1397 1398 1399 1400
	u32 path_refresh_time;
	u16 min_discovery_timeout;
	u32 dot11MeshHWMPactivePathTimeout;
	u16 dot11MeshHWMPpreqMinInterval;
1401
	u16 dot11MeshHWMPperrMinInterval;
1402
	u16 dot11MeshHWMPnetDiameterTraversalTime;
1403
	u8 dot11MeshHWMPRootMode;
1404
	u16 dot11MeshHWMPRannInterval;
1405
	bool dot11MeshGateAnnouncementProtocol;
1406
	bool dot11MeshForwarding;
1407
	s32 rssi_threshold;
1408
	u16 ht_opmode;
1409 1410
	u32 dot11MeshHWMPactivePathToRootTimeout;
	u16 dot11MeshHWMProotInterval;
1411
	u16 dot11MeshHWMPconfirmationInterval;
1412 1413
	enum nl80211_mesh_power_mode power_mode;
	u16 dot11MeshAwakeWindowDuration;
1414
	u32 plink_timeout;
1415 1416
};

1417 1418
/**
 * struct mesh_setup - 802.11s mesh setup configuration
1419
 * @chandef: defines the channel to use
1420 1421
 * @mesh_id: the mesh ID
 * @mesh_id_len: length of the mesh ID, at least 1 and at most 32 bytes
1422
 * @sync_method: which synchronization method to use
1423 1424
 * @path_sel_proto: which path selection protocol to use
 * @path_metric: which metric to use
1425
 * @auth_id: which authentication method this mesh is using
1426 1427
 * @ie: vendor information elements (optional)
 * @ie_len: length of vendor information elements
1428 1429
 * @is_authenticated: this mesh requires authentication
 * @is_secure: this mesh uses security
1430
 * @user_mpm: userspace handles all MPM functions
1431 1432
 * @dtim_period: DTIM period to use
 * @beacon_interval: beacon interval to use
1433
 * @mcast_rate: multicat rate for Mesh Node [6Mbps is the default for 802.11a]
1434
 * @basic_rates: basic rates to use when creating the mesh
1435
 * @beacon_rate: bitrate to be used for beacons
1436 1437 1438 1439
 *
 * These parameters are fixed when the mesh is created.
 */
struct mesh_setup {
1440
	struct cfg80211_chan_def chandef;
1441 1442
	const u8 *mesh_id;
	u8 mesh_id_len;
1443 1444 1445
	u8 sync_method;
	u8 path_sel_proto;
	u8 path_metric;
1446
	u8 auth_id;
1447 1448
	const u8 *ie;
	u8 ie_len;
1449
	bool is_authenticated;
1450
	bool is_secure;
1451
	bool user_mpm;
1452 1453
	u8 dtim_period;
	u16 beacon_interval;
1454
	int mcast_rate[NUM_NL80211_BANDS];
1455
	u32 basic_rates;
1456
	struct cfg80211_bitrate_mask beacon_rate;
1457 1458
};

1459 1460 1461 1462 1463 1464 1465 1466 1467 1468
/**
 * struct ocb_setup - 802.11p OCB mode setup configuration
 * @chandef: defines the channel to use
 *
 * These parameters are fixed when connecting to the network
 */
struct ocb_setup {
	struct cfg80211_chan_def chandef;
};

1469 1470
/**
 * struct ieee80211_txq_params - TX queue parameters
1471
 * @ac: AC identifier
1472 1473 1474 1475 1476 1477 1478 1479
 * @txop: Maximum burst time in units of 32 usecs, 0 meaning disabled
 * @cwmin: Minimum contention window [a value of the form 2^n-1 in the range
 *	1..32767]
 * @cwmax: Maximum contention window [a value of the form 2^n-1 in the range
 *	1..32767]
 * @aifs: Arbitration interframe space [0..255]
 */
struct ieee80211_txq_params {
1480
	enum nl80211_ac ac;
1481 1482 1483 1484 1485 1486
	u16 txop;
	u16 cwmin;
	u16 cwmax;
	u8 aifs;
};

J
Johannes Berg 已提交
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508
/**
 * DOC: Scanning and BSS list handling
 *
 * The scanning process itself is fairly simple, but cfg80211 offers quite
 * a bit of helper functionality. To start a scan, the scan operation will
 * be invoked with a scan definition. This scan definition contains the
 * channels to scan, and the SSIDs to send probe requests for (including the
 * wildcard, if desired). A passive scan is indicated by having no SSIDs to
 * probe. Additionally, a scan request may contain extra information elements
 * that should be added to the probe request. The IEs are guaranteed to be
 * well-formed, and will not exceed the maximum length the driver advertised
 * in the wiphy structure.
 *
 * When scanning finds a BSS, cfg80211 needs to be notified of that, because
 * it is responsible for maintaining the BSS list; the driver should not
 * maintain a list itself. For this notification, various functions exist.
 *
 * Since drivers do not maintain a BSS list, there are also a number of
 * functions to search for a BSS and obtain information about it from the
 * BSS structure cfg80211 maintains. The BSS list is also made available
 * to userspace.
 */
1509

1510 1511 1512 1513 1514 1515 1516 1517 1518 1519
/**
 * struct cfg80211_ssid - SSID description
 * @ssid: the SSID
 * @ssid_len: length of the ssid
 */
struct cfg80211_ssid {
	u8 ssid[IEEE80211_MAX_SSID_LEN];
	u8 ssid_len;
};

1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534
/**
 * struct cfg80211_scan_info - information about completed scan
 * @scan_start_tsf: scan start time in terms of the TSF of the BSS that the
 *	wireless device that requested the scan is connected to. If this
 *	information is not available, this field is left zero.
 * @tsf_bssid: the BSSID according to which %scan_start_tsf is set.
 * @aborted: set to true if the scan was aborted for any reason,
 *	userspace will be notified of that
 */
struct cfg80211_scan_info {
	u64 scan_start_tsf;
	u8 tsf_bssid[ETH_ALEN] __aligned(2);
	bool aborted;
};

1535 1536 1537 1538 1539 1540
/**
 * struct cfg80211_scan_request - scan request description
 *
 * @ssids: SSIDs to scan for (active scan only)
 * @n_ssids: number of SSIDs
 * @channels: channels to scan on.
1541
 * @n_channels: total number of channels to scan
1542
 * @scan_width: channel width for scanning
1543 1544
 * @ie: optional information element(s) to add into Probe Request or %NULL
 * @ie_len: length of ie in octets
1545 1546 1547 1548 1549
 * @duration: how long to listen on each channel, in TUs. If
 *	%duration_mandatory is not set, this is the maximum dwell time and
 *	the actual dwell time may be shorter.
 * @duration_mandatory: if set, the scan duration must be as specified by the
 *	%duration field.
1550
 * @flags: bit field of flags controlling operation
1551
 * @rates: bitmap of rates to advertise for each band
1552
 * @wiphy: the wiphy this was for
1553
 * @scan_start: time (in jiffies) when the scan started
J
Johannes Berg 已提交
1554
 * @wdev: the wireless device to scan for
1555
 * @info: (internal) information about completed scan
1556
 * @notified: (internal) scan request was notified as done or aborted
1557
 * @no_cck: used to send probe requests at non CCK rate in 2GHz band
1558 1559 1560 1561
 * @mac_addr: MAC address used with randomisation
 * @mac_addr_mask: MAC address mask used with randomisation, bits that
 *	are 0 in the mask should be randomised, bits that are 1 should
 *	be taken from the @mac_addr
1562
 * @bssid: BSSID to scan for (most commonly, the wildcard BSSID)
1563 1564 1565 1566 1567
 */
struct cfg80211_scan_request {
	struct cfg80211_ssid *ssids;
	int n_ssids;
	u32 n_channels;
1568
	enum nl80211_bss_scan_width scan_width;
1569
	const u8 *ie;
1570
	size_t ie_len;
1571 1572
	u16 duration;
	bool duration_mandatory;
1573
	u32 flags;
1574

1575
	u32 rates[NUM_NL80211_BANDS];
1576

J
Johannes Berg 已提交
1577 1578
	struct wireless_dev *wdev;

1579 1580
	u8 mac_addr[ETH_ALEN] __aligned(2);
	u8 mac_addr_mask[ETH_ALEN] __aligned(2);
1581
	u8 bssid[ETH_ALEN] __aligned(2);
1582

1583 1584
	/* internal */
	struct wiphy *wiphy;
1585
	unsigned long scan_start;
1586 1587
	struct cfg80211_scan_info info;
	bool notified;
1588
	bool no_cck;
1589 1590 1591

	/* keep last */
	struct ieee80211_channel *channels[0];
1592 1593
};

1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604
static inline void get_random_mask_addr(u8 *buf, const u8 *addr, const u8 *mask)
{
	int i;

	get_random_bytes(buf, ETH_ALEN);
	for (i = 0; i < ETH_ALEN; i++) {
		buf[i] &= ~mask[i];
		buf[i] |= addr[i] & mask[i];
	}
}

1605 1606 1607
/**
 * struct cfg80211_match_set - sets of attributes to match
 *
1608 1609
 * @ssid: SSID to be matched; may be zero-length for no match (RSSI only)
 * @rssi_thold: don't report scan results below this threshold (in s32 dBm)
1610 1611 1612
 */
struct cfg80211_match_set {
	struct cfg80211_ssid ssid;
1613
	s32 rssi_thold;
1614 1615
};

1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629
/**
 * struct cfg80211_sched_scan_plan - scan plan for scheduled scan
 *
 * @interval: interval between scheduled scan iterations. In seconds.
 * @iterations: number of scan iterations in this scan plan. Zero means
 *	infinite loop.
 *	The last scan plan will always have this parameter set to zero,
 *	all other scan plans will have a finite number of iterations.
 */
struct cfg80211_sched_scan_plan {
	u32 interval;
	u32 iterations;
};

1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640
/**
 * struct cfg80211_bss_select_adjust - BSS selection with RSSI adjustment.
 *
 * @band: band of BSS which should match for RSSI level adjustment.
 * @delta: value of RSSI level adjustment.
 */
struct cfg80211_bss_select_adjust {
	enum nl80211_band band;
	s8 delta;
};

1641 1642 1643 1644 1645 1646
/**
 * struct cfg80211_sched_scan_request - scheduled scan request description
 *
 * @ssids: SSIDs to scan for (passed in the probe_reqs in active scans)
 * @n_ssids: number of SSIDs
 * @n_channels: total number of channels to scan
1647
 * @scan_width: channel width for scanning
1648 1649
 * @ie: optional information element(s) to add into Probe Request or %NULL
 * @ie_len: length of ie in octets
1650
 * @flags: bit field of flags controlling operation
1651 1652 1653 1654 1655
 * @match_sets: sets of parameters to be matched for a scan result
 * 	entry to be considered valid and to be passed to the host
 * 	(others are filtered out).
 *	If ommited, all results are passed.
 * @n_match_sets: number of match sets
1656 1657
 * @wiphy: the wiphy this was for
 * @dev: the interface
J
Johannes Berg 已提交
1658
 * @scan_start: start time of the scheduled scan
1659
 * @channels: channels to scan
1660 1661
 * @min_rssi_thold: for drivers only supporting a single threshold, this
 *	contains the minimum over all matchsets
1662 1663 1664 1665
 * @mac_addr: MAC address used with randomisation
 * @mac_addr_mask: MAC address mask used with randomisation, bits that
 *	are 0 in the mask should be randomised, bits that are 1 should
 *	be taken from the @mac_addr
1666 1667 1668
 * @scan_plans: scan plans to be executed in this scheduled scan. Lowest
 *	index must be executed first.
 * @n_scan_plans: number of scan plans, at least 1.
1669
 * @rcu_head: RCU callback used to free the struct
1670 1671
 * @owner_nlportid: netlink portid of owner (if this should is a request
 *	owned by a particular socket)
1672 1673 1674 1675
 * @delay: delay in seconds to use before starting the first scan
 *	cycle.  The driver may ignore this parameter and start
 *	immediately (or at any other time), if this feature is not
 *	supported.
1676 1677 1678 1679 1680 1681 1682 1683 1684 1685
 * @relative_rssi_set: Indicates whether @relative_rssi is set or not.
 * @relative_rssi: Relative RSSI threshold in dB to restrict scan result
 *	reporting in connected state to cases where a matching BSS is determined
 *	to have better or slightly worse RSSI than the current connected BSS.
 *	The relative RSSI threshold values are ignored in disconnected state.
 * @rssi_adjust: delta dB of RSSI preference to be given to the BSSs that belong
 *	to the specified band while deciding whether a better BSS is reported
 *	using @relative_rssi. If delta is a negative number, the BSSs that
 *	belong to the specified band will be penalized by delta dB in relative
 *	comparisions.
1686 1687 1688 1689 1690
 */
struct cfg80211_sched_scan_request {
	struct cfg80211_ssid *ssids;
	int n_ssids;
	u32 n_channels;
1691
	enum nl80211_bss_scan_width scan_width;
1692 1693
	const u8 *ie;
	size_t ie_len;
1694
	u32 flags;
1695 1696
	struct cfg80211_match_set *match_sets;
	int n_match_sets;
1697
	s32 min_rssi_thold;
1698
	u32 delay;
1699 1700
	struct cfg80211_sched_scan_plan *scan_plans;
	int n_scan_plans;
1701

1702 1703 1704
	u8 mac_addr[ETH_ALEN] __aligned(2);
	u8 mac_addr_mask[ETH_ALEN] __aligned(2);

1705 1706 1707 1708
	bool relative_rssi_set;
	s8 relative_rssi;
	struct cfg80211_bss_select_adjust rssi_adjust;

1709 1710 1711
	/* internal */
	struct wiphy *wiphy;
	struct net_device *dev;
1712
	unsigned long scan_start;
1713
	struct rcu_head rcu_head;
1714
	u32 owner_nlportid;
1715 1716 1717 1718 1719

	/* keep last */
	struct ieee80211_channel *channels[0];
};

1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732
/**
 * enum cfg80211_signal_type - signal type
 *
 * @CFG80211_SIGNAL_TYPE_NONE: no signal strength information available
 * @CFG80211_SIGNAL_TYPE_MBM: signal strength in mBm (100*dBm)
 * @CFG80211_SIGNAL_TYPE_UNSPEC: signal strength, increasing from 0 through 100
 */
enum cfg80211_signal_type {
	CFG80211_SIGNAL_TYPE_NONE,
	CFG80211_SIGNAL_TYPE_MBM,
	CFG80211_SIGNAL_TYPE_UNSPEC,
};

1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744
/**
 * struct cfg80211_inform_bss - BSS inform data
 * @chan: channel the frame was received on
 * @scan_width: scan width that was used
 * @signal: signal strength value, according to the wiphy's
 *	signal type
 * @boottime_ns: timestamp (CLOCK_BOOTTIME) when the information was
 *	received; should match the time when the frame was actually
 *	received by the device (not just by the host, in case it was
 *	buffered on the device) and be accurate to about 10ms.
 *	If the frame isn't buffered, just passing the return value of
 *	ktime_get_boot_ns() is likely appropriate.
1745 1746 1747 1748 1749
 * @parent_tsf: the time at the start of reception of the first octet of the
 *	timestamp field of the frame. The time is the TSF of the BSS specified
 *	by %parent_bssid.
 * @parent_bssid: the BSS according to which %parent_tsf is set. This is set to
 *	the BSS that requested the scan in which the beacon/probe was received.
1750 1751 1752 1753 1754 1755
 */
struct cfg80211_inform_bss {
	struct ieee80211_channel *chan;
	enum nl80211_bss_scan_width scan_width;
	s32 signal;
	u64 boottime_ns;
1756 1757
	u64 parent_tsf;
	u8 parent_bssid[ETH_ALEN] __aligned(2);
1758 1759
};

1760
/**
1761
 * struct cfg80211_bss_ies - BSS entry IE data
J
Johannes Berg 已提交
1762
 * @tsf: TSF contained in the frame that carried these IEs
1763 1764
 * @rcu_head: internal use, for freeing
 * @len: length of the IEs
1765
 * @from_beacon: these IEs are known to come from a beacon
1766 1767 1768
 * @data: IE data
 */
struct cfg80211_bss_ies {
J
Johannes Berg 已提交
1769
	u64 tsf;
1770 1771
	struct rcu_head rcu_head;
	int len;
1772
	bool from_beacon;
1773 1774 1775
	u8 data[];
};

1776 1777 1778 1779 1780 1781
/**
 * struct cfg80211_bss - BSS description
 *
 * This structure describes a BSS (which may also be a mesh network)
 * for use in scan results and similar.
 *
J
Johannes Berg 已提交
1782
 * @channel: channel this BSS is on
1783
 * @scan_width: width of the control channel
1784 1785 1786
 * @bssid: BSSID of the BSS
 * @beacon_interval: the beacon interval as from the frame
 * @capability: the capability field in host byte order
1787 1788 1789 1790
 * @ies: the information elements (Note that there is no guarantee that these
 *	are well-formed!); this is a pointer to either the beacon_ies or
 *	proberesp_ies depending on whether Probe Response frame has been
 *	received. It is always non-%NULL.
1791
 * @beacon_ies: the information elements from the last Beacon frame
1792 1793 1794
 *	(implementation note: if @hidden_beacon_bss is set this struct doesn't
 *	own the beacon_ies, but they're just pointers to the ones from the
 *	@hidden_beacon_bss struct)
1795
 * @proberesp_ies: the information elements from the last Probe Response frame
1796 1797 1798 1799
 * @hidden_beacon_bss: in case this BSS struct represents a probe response from
 *	a BSS that hides the SSID in its beacon, this points to the BSS struct
 *	that holds the beacon data. @beacon_ies is still valid, of course, and
 *	points to the same data as hidden_beacon_bss->beacon_ies in that case.
J
Johannes Berg 已提交
1800
 * @signal: signal strength value (type depends on the wiphy's signal_type)
1801 1802 1803 1804
 * @priv: private area for driver use, has at least wiphy->bss_priv_size bytes
 */
struct cfg80211_bss {
	struct ieee80211_channel *channel;
1805
	enum nl80211_bss_scan_width scan_width;
1806

1807 1808 1809 1810
	const struct cfg80211_bss_ies __rcu *ies;
	const struct cfg80211_bss_ies __rcu *beacon_ies;
	const struct cfg80211_bss_ies __rcu *proberesp_ies;

1811
	struct cfg80211_bss *hidden_beacon_bss;
1812 1813 1814

	s32 signal;

1815 1816 1817
	u16 beacon_interval;
	u16 capability;

1818
	u8 bssid[ETH_ALEN];
1819

J
Johannes Berg 已提交
1820
	u8 priv[0] __aligned(sizeof(void *));
1821 1822
};

1823 1824 1825 1826
/**
 * ieee80211_bss_get_ie - find IE with given ID
 * @bss: the bss to search
 * @ie: the IE ID
1827 1828 1829
 *
 * Note that the return value is an RCU-protected pointer, so
 * rcu_read_lock() must be held when calling this function.
1830
 * Return: %NULL if not found.
1831 1832 1833 1834
 */
const u8 *ieee80211_bss_get_ie(struct cfg80211_bss *bss, u8 ie);


1835 1836 1837 1838 1839
/**
 * struct cfg80211_auth_request - Authentication request data
 *
 * This structure provides information needed to complete IEEE 802.11
 * authentication.
J
Johannes Berg 已提交
1840
 *
1841 1842
 * @bss: The BSS to authenticate with, the callee must obtain a reference
 *	to it if it needs to keep it.
1843 1844 1845
 * @auth_type: Authentication type (algorithm)
 * @ie: Extra IEs to add to Authentication frame or %NULL
 * @ie_len: Length of ie buffer in octets
J
Johannes Berg 已提交
1846 1847 1848
 * @key_len: length of WEP key for shared key authentication
 * @key_idx: index of WEP key for shared key authentication
 * @key: WEP key for shared key authentication
1849 1850 1851 1852 1853
 * @auth_data: Fields and elements in Authentication frames. This contains
 *	the authentication frame body (non-IE and IE data), excluding the
 *	Authentication algorithm number, i.e., starting at the Authentication
 *	transaction sequence number field.
 * @auth_data_len: Length of auth_data buffer in octets
1854 1855
 */
struct cfg80211_auth_request {
J
Johannes Berg 已提交
1856
	struct cfg80211_bss *bss;
1857 1858
	const u8 *ie;
	size_t ie_len;
J
Johannes Berg 已提交
1859
	enum nl80211_auth_type auth_type;
J
Johannes Berg 已提交
1860 1861
	const u8 *key;
	u8 key_len, key_idx;
1862 1863
	const u8 *auth_data;
	size_t auth_data_len;
1864 1865
};

1866 1867 1868 1869
/**
 * enum cfg80211_assoc_req_flags - Over-ride default behaviour in association.
 *
 * @ASSOC_REQ_DISABLE_HT:  Disable HT (802.11n)
1870
 * @ASSOC_REQ_DISABLE_VHT:  Disable VHT
1871
 * @ASSOC_REQ_USE_RRM: Declare RRM capability in this association
1872 1873 1874
 */
enum cfg80211_assoc_req_flags {
	ASSOC_REQ_DISABLE_HT		= BIT(0),
1875
	ASSOC_REQ_DISABLE_VHT		= BIT(1),
1876
	ASSOC_REQ_USE_RRM		= BIT(2),
1877 1878
};

1879 1880 1881 1882 1883
/**
 * struct cfg80211_assoc_request - (Re)Association request data
 *
 * This structure provides information needed to complete IEEE 802.11
 * (re)association.
1884 1885 1886 1887
 * @bss: The BSS to associate with. If the call is successful the driver is
 *	given a reference that it must give back to cfg80211_send_rx_assoc()
 *	or to cfg80211_assoc_timeout(). To ensure proper refcounting, new
 *	association requests while already associating must be rejected.
1888 1889
 * @ie: Extra IEs to add to (Re)Association Request frame or %NULL
 * @ie_len: Length of ie buffer in octets
1890
 * @use_mfp: Use management frame protection (IEEE 802.11w) in this association
S
Samuel Ortiz 已提交
1891
 * @crypto: crypto settings
1892 1893 1894 1895 1896 1897
 * @prev_bssid: previous BSSID, if not %NULL use reassociate frame. This is used
 *	to indicate a request to reassociate within the ESS instead of a request
 *	do the initial association with the ESS. When included, this is set to
 *	the BSSID of the current association, i.e., to the value that is
 *	included in the Current AP address field of the Reassociation Request
 *	frame.
1898 1899
 * @flags:  See &enum cfg80211_assoc_req_flags
 * @ht_capa:  HT Capabilities over-rides.  Values set in ht_capa_mask
1900
 *	will be used in ht_capa.  Un-supported values will be ignored.
1901
 * @ht_capa_mask:  The bits of ht_capa which are to be used.
1902 1903
 * @vht_capa: VHT capability override
 * @vht_capa_mask: VHT capability mask indicating which fields to use
1904 1905 1906 1907 1908 1909
 * @fils_kek: FILS KEK for protecting (Re)Association Request/Response frame or
 *	%NULL if FILS is not used.
 * @fils_kek_len: Length of fils_kek in octets
 * @fils_nonces: FILS nonces (part of AAD) for protecting (Re)Association
 *	Request/Response frame or %NULL if FILS is not used. This field starts
 *	with 16 octets of STA Nonce followed by 16 octets of AP Nonce.
1910 1911
 */
struct cfg80211_assoc_request {
J
Johannes Berg 已提交
1912
	struct cfg80211_bss *bss;
1913
	const u8 *ie, *prev_bssid;
1914
	size_t ie_len;
S
Samuel Ortiz 已提交
1915
	struct cfg80211_crypto_settings crypto;
J
Johannes Berg 已提交
1916
	bool use_mfp;
1917 1918 1919
	u32 flags;
	struct ieee80211_ht_cap ht_capa;
	struct ieee80211_ht_cap ht_capa_mask;
1920
	struct ieee80211_vht_cap vht_capa, vht_capa_mask;
1921 1922 1923
	const u8 *fils_kek;
	size_t fils_kek_len;
	const u8 *fils_nonces;
1924 1925 1926 1927 1928 1929 1930 1931
};

/**
 * struct cfg80211_deauth_request - Deauthentication request data
 *
 * This structure provides information needed to complete IEEE 802.11
 * deauthentication.
 *
1932
 * @bssid: the BSSID of the BSS to deauthenticate from
1933 1934
 * @ie: Extra IEs to add to Deauthentication frame or %NULL
 * @ie_len: Length of ie buffer in octets
J
Johannes Berg 已提交
1935
 * @reason_code: The reason code for the deauthentication
J
Johannes Berg 已提交
1936 1937
 * @local_state_change: if set, change local state only and
 *	do not set a deauth frame
1938 1939
 */
struct cfg80211_deauth_request {
1940
	const u8 *bssid;
1941 1942
	const u8 *ie;
	size_t ie_len;
J
Johannes Berg 已提交
1943
	u16 reason_code;
1944
	bool local_state_change;
1945 1946 1947 1948 1949 1950
};

/**
 * struct cfg80211_disassoc_request - Disassociation request data
 *
 * This structure provides information needed to complete IEEE 802.11
1951
 * disassociation.
1952
 *
J
Johannes Berg 已提交
1953
 * @bss: the BSS to disassociate from
1954 1955
 * @ie: Extra IEs to add to Disassociation frame or %NULL
 * @ie_len: Length of ie buffer in octets
J
Johannes Berg 已提交
1956
 * @reason_code: The reason code for the disassociation
1957 1958
 * @local_state_change: This is a request for a local state only, i.e., no
 *	Disassociation frame is to be transmitted.
1959 1960
 */
struct cfg80211_disassoc_request {
J
Johannes Berg 已提交
1961
	struct cfg80211_bss *bss;
1962 1963
	const u8 *ie;
	size_t ie_len;
J
Johannes Berg 已提交
1964
	u16 reason_code;
1965
	bool local_state_change;
1966 1967
};

J
Johannes Berg 已提交
1968 1969 1970 1971 1972 1973 1974 1975 1976 1977
/**
 * struct cfg80211_ibss_params - IBSS parameters
 *
 * This structure defines the IBSS parameters for the join_ibss()
 * method.
 *
 * @ssid: The SSID, will always be non-null.
 * @ssid_len: The length of the SSID, will always be non-zero.
 * @bssid: Fixed BSSID requested, maybe be %NULL, if set do not
 *	search for IBSSs with a different BSSID.
1978
 * @chandef: defines the channel to use if no other IBSS to join can be found
J
Johannes Berg 已提交
1979 1980 1981 1982
 * @channel_fixed: The channel should be fixed -- do not search for
 *	IBSSs to join on other channels.
 * @ie: information element(s) to include in the beacon
 * @ie_len: length of that
1983
 * @beacon_interval: beacon interval to use
J
Johannes Berg 已提交
1984 1985
 * @privacy: this is a protected network, keys will be configured
 *	after joining
1986 1987 1988 1989
 * @control_port: whether user space controls IEEE 802.1X port, i.e.,
 *	sets/clears %NL80211_STA_FLAG_AUTHORIZED. If true, the driver is
 *	required to assume that the port is unauthorized until authorized by
 *	user space. Otherwise, port is marked authorized by default.
1990 1991 1992
 * @userspace_handles_dfs: whether user space controls DFS operation, i.e.
 *	changes the channel when a radar is detected. This is required
 *	to operate on DFS channels.
1993
 * @basic_rates: bitmap of basic rates to use when creating the IBSS
1994
 * @mcast_rate: per-band multicast rate index + 1 (0: disabled)
1995
 * @ht_capa:  HT Capabilities over-rides.  Values set in ht_capa_mask
1996
 *	will be used in ht_capa.  Un-supported values will be ignored.
1997
 * @ht_capa_mask:  The bits of ht_capa which are to be used.
J
Johannes Berg 已提交
1998 1999
 */
struct cfg80211_ibss_params {
2000 2001
	const u8 *ssid;
	const u8 *bssid;
2002
	struct cfg80211_chan_def chandef;
2003
	const u8 *ie;
J
Johannes Berg 已提交
2004
	u8 ssid_len, ie_len;
2005
	u16 beacon_interval;
2006
	u32 basic_rates;
J
Johannes Berg 已提交
2007
	bool channel_fixed;
J
Johannes Berg 已提交
2008
	bool privacy;
2009
	bool control_port;
2010
	bool userspace_handles_dfs;
2011
	int mcast_rate[NUM_NL80211_BANDS];
2012 2013
	struct ieee80211_ht_cap ht_capa;
	struct ieee80211_ht_cap ht_capa_mask;
J
Johannes Berg 已提交
2014 2015
};

2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026
/**
 * struct cfg80211_bss_selection - connection parameters for BSS selection.
 *
 * @behaviour: requested BSS selection behaviour.
 * @param: parameters for requestion behaviour.
 * @band_pref: preferred band for %NL80211_BSS_SELECT_ATTR_BAND_PREF.
 * @adjust: parameters for %NL80211_BSS_SELECT_ATTR_RSSI_ADJUST.
 */
struct cfg80211_bss_selection {
	enum nl80211_bss_select_attr behaviour;
	union {
2027
		enum nl80211_band band_pref;
2028 2029 2030 2031
		struct cfg80211_bss_select_adjust adjust;
	} param;
};

S
Samuel Ortiz 已提交
2032 2033 2034 2035 2036 2037 2038 2039
/**
 * struct cfg80211_connect_params - Connection parameters
 *
 * This structure provides information needed to complete IEEE 802.11
 * authentication and association.
 *
 * @channel: The channel to use or %NULL if not specified (auto-select based
 *	on scan results)
2040 2041
 * @channel_hint: The channel of the recommended BSS for initial connection or
 *	%NULL if not specified
S
Samuel Ortiz 已提交
2042 2043
 * @bssid: The AP BSSID or %NULL if not specified (auto-select based on scan
 *	results)
2044 2045 2046 2047
 * @bssid_hint: The recommended AP BSSID for initial connection to the BSS or
 *	%NULL if not specified. Unlike the @bssid parameter, the driver is
 *	allowed to ignore this @bssid_hint if it has knowledge of a better BSS
 *	to use.
S
Samuel Ortiz 已提交
2048 2049 2050
 * @ssid: SSID
 * @ssid_len: Length of ssid in octets
 * @auth_type: Authentication type (algorithm)
J
Johannes Berg 已提交
2051 2052
 * @ie: IEs for association request
 * @ie_len: Length of assoc_ie in octets
S
Samuel Ortiz 已提交
2053
 * @privacy: indicates whether privacy-enabled APs should be used
2054
 * @mfp: indicate whether management frame protection is used
S
Samuel Ortiz 已提交
2055
 * @crypto: crypto settings
J
Johannes Berg 已提交
2056 2057 2058
 * @key_len: length of WEP key for shared key authentication
 * @key_idx: index of WEP key for shared key authentication
 * @key: WEP key for shared key authentication
2059
 * @flags:  See &enum cfg80211_assoc_req_flags
2060
 * @bg_scan_period:  Background scan period in seconds
2061
 *	or -1 to indicate that default value is to be used.
2062
 * @ht_capa:  HT Capabilities over-rides.  Values set in ht_capa_mask
2063
 *	will be used in ht_capa.  Un-supported values will be ignored.
2064
 * @ht_capa_mask:  The bits of ht_capa which are to be used.
2065 2066
 * @vht_capa:  VHT Capability overrides
 * @vht_capa_mask: The bits of vht_capa which are to be used.
2067 2068
 * @pbss: if set, connect to a PCP instead of AP. Valid for DMG
 *	networks.
2069
 * @bss_select: criteria to be used for BSS selection.
2070 2071 2072 2073 2074 2075
 * @prev_bssid: previous BSSID, if not %NULL use reassociate frame. This is used
 *	to indicate a request to reassociate within the ESS instead of a request
 *	do the initial association with the ESS. When included, this is set to
 *	the BSSID of the current association, i.e., to the value that is
 *	included in the Current AP address field of the Reassociation Request
 *	frame.
S
Samuel Ortiz 已提交
2076 2077 2078
 */
struct cfg80211_connect_params {
	struct ieee80211_channel *channel;
2079
	struct ieee80211_channel *channel_hint;
2080
	const u8 *bssid;
2081
	const u8 *bssid_hint;
2082
	const u8 *ssid;
S
Samuel Ortiz 已提交
2083 2084
	size_t ssid_len;
	enum nl80211_auth_type auth_type;
2085
	const u8 *ie;
S
Samuel Ortiz 已提交
2086 2087
	size_t ie_len;
	bool privacy;
2088
	enum nl80211_mfp mfp;
S
Samuel Ortiz 已提交
2089
	struct cfg80211_crypto_settings crypto;
J
Johannes Berg 已提交
2090 2091
	const u8 *key;
	u8 key_len, key_idx;
2092
	u32 flags;
2093
	int bg_scan_period;
2094 2095
	struct ieee80211_ht_cap ht_capa;
	struct ieee80211_ht_cap ht_capa_mask;
2096 2097
	struct ieee80211_vht_cap vht_capa;
	struct ieee80211_vht_cap vht_capa_mask;
2098
	bool pbss;
2099
	struct cfg80211_bss_selection bss_select;
2100
	const u8 *prev_bssid;
S
Samuel Ortiz 已提交
2101 2102
};

2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114
/**
 * enum cfg80211_connect_params_changed - Connection parameters being updated
 *
 * This enum provides information of all connect parameters that
 * have to be updated as part of update_connect_params() call.
 *
 * @UPDATE_ASSOC_IES: Indicates whether association request IEs are updated
 */
enum cfg80211_connect_params_changed {
	UPDATE_ASSOC_IES		= BIT(0),
};

2115 2116
/**
 * enum wiphy_params_flags - set_wiphy_params bitfield values
J
Johannes Berg 已提交
2117 2118 2119 2120 2121
 * @WIPHY_PARAM_RETRY_SHORT: wiphy->retry_short has changed
 * @WIPHY_PARAM_RETRY_LONG: wiphy->retry_long has changed
 * @WIPHY_PARAM_FRAG_THRESHOLD: wiphy->frag_threshold has changed
 * @WIPHY_PARAM_RTS_THRESHOLD: wiphy->rts_threshold has changed
 * @WIPHY_PARAM_COVERAGE_CLASS: coverage class changed
2122
 * @WIPHY_PARAM_DYN_ACK: dynack has been enabled
2123 2124 2125 2126 2127 2128
 */
enum wiphy_params_flags {
	WIPHY_PARAM_RETRY_SHORT		= 1 << 0,
	WIPHY_PARAM_RETRY_LONG		= 1 << 1,
	WIPHY_PARAM_FRAG_THRESHOLD	= 1 << 2,
	WIPHY_PARAM_RTS_THRESHOLD	= 1 << 3,
2129
	WIPHY_PARAM_COVERAGE_CLASS	= 1 << 4,
2130
	WIPHY_PARAM_DYN_ACK		= 1 << 5,
2131 2132
};

S
Samuel Ortiz 已提交
2133 2134 2135 2136 2137 2138 2139 2140 2141 2142
/**
 * struct cfg80211_pmksa - PMK Security Association
 *
 * This structure is passed to the set/del_pmksa() method for PMKSA
 * caching.
 *
 * @bssid: The AP's BSSID.
 * @pmkid: The PMK material itself.
 */
struct cfg80211_pmksa {
2143 2144
	const u8 *bssid;
	const u8 *pmkid;
S
Samuel Ortiz 已提交
2145
};
J
Johannes Berg 已提交
2146

J
Johannes Berg 已提交
2147
/**
2148
 * struct cfg80211_pkt_pattern - packet pattern
J
Johannes Berg 已提交
2149 2150 2151 2152
 * @mask: bitmask where to match pattern and where to ignore bytes,
 *	one bit per byte, in same format as nl80211
 * @pattern: bytes to match where bitmask is 1
 * @pattern_len: length of pattern (in bytes)
2153
 * @pkt_offset: packet offset (in bytes)
J
Johannes Berg 已提交
2154 2155 2156 2157
 *
 * Internal note: @mask and @pattern are allocated in one chunk of
 * memory, free @mask only!
 */
2158
struct cfg80211_pkt_pattern {
2159
	const u8 *mask, *pattern;
J
Johannes Berg 已提交
2160
	int pattern_len;
2161
	int pkt_offset;
J
Johannes Berg 已提交
2162 2163
};

2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196
/**
 * struct cfg80211_wowlan_tcp - TCP connection parameters
 *
 * @sock: (internal) socket for source port allocation
 * @src: source IP address
 * @dst: destination IP address
 * @dst_mac: destination MAC address
 * @src_port: source port
 * @dst_port: destination port
 * @payload_len: data payload length
 * @payload: data payload buffer
 * @payload_seq: payload sequence stamping configuration
 * @data_interval: interval at which to send data packets
 * @wake_len: wakeup payload match length
 * @wake_data: wakeup payload match data
 * @wake_mask: wakeup payload match mask
 * @tokens_size: length of the tokens buffer
 * @payload_tok: payload token usage configuration
 */
struct cfg80211_wowlan_tcp {
	struct socket *sock;
	__be32 src, dst;
	u16 src_port, dst_port;
	u8 dst_mac[ETH_ALEN];
	int payload_len;
	const u8 *payload;
	struct nl80211_wowlan_tcp_data_seq payload_seq;
	u32 data_interval;
	u32 wake_len;
	const u8 *wake_data, *wake_mask;
	u32 tokens_size;
	/* must be last, variable member */
	struct nl80211_wowlan_tcp_data_token payload_tok;
J
Johannes Berg 已提交
2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208
};

/**
 * struct cfg80211_wowlan - Wake on Wireless-LAN support info
 *
 * This structure defines the enabled WoWLAN triggers for the device.
 * @any: wake up on any activity -- special trigger if device continues
 *	operating as normal during suspend
 * @disconnect: wake up if getting disconnected
 * @magic_pkt: wake up on receiving magic packet
 * @patterns: wake up on receiving packet matching a pattern
 * @n_patterns: number of patterns
2209 2210 2211 2212
 * @gtk_rekey_failure: wake up on GTK rekey failure
 * @eap_identity_req: wake up on EAP identity request packet
 * @four_way_handshake: wake up on 4-way handshake
 * @rfkill_release: wake up when rfkill is released
2213 2214
 * @tcp: TCP connection establishment/wakeup parameters, see nl80211.h.
 *	NULL if not configured.
2215
 * @nd_config: configuration for the scan to be used for net detect wake.
J
Johannes Berg 已提交
2216 2217
 */
struct cfg80211_wowlan {
2218 2219 2220
	bool any, disconnect, magic_pkt, gtk_rekey_failure,
	     eap_identity_req, four_way_handshake,
	     rfkill_release;
2221
	struct cfg80211_pkt_pattern *patterns;
2222
	struct cfg80211_wowlan_tcp *tcp;
J
Johannes Berg 已提交
2223
	int n_patterns;
2224
	struct cfg80211_sched_scan_request *nd_config;
J
Johannes Berg 已提交
2225 2226
};

2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255
/**
 * struct cfg80211_coalesce_rules - Coalesce rule parameters
 *
 * This structure defines coalesce rule for the device.
 * @delay: maximum coalescing delay in msecs.
 * @condition: condition for packet coalescence.
 *	see &enum nl80211_coalesce_condition.
 * @patterns: array of packet patterns
 * @n_patterns: number of patterns
 */
struct cfg80211_coalesce_rules {
	int delay;
	enum nl80211_coalesce_condition condition;
	struct cfg80211_pkt_pattern *patterns;
	int n_patterns;
};

/**
 * struct cfg80211_coalesce - Packet coalescing settings
 *
 * This structure defines coalescing settings.
 * @rules: array of coalesce rules
 * @n_rules: number of rules
 */
struct cfg80211_coalesce {
	struct cfg80211_coalesce_rules *rules;
	int n_rules;
};

2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284
/**
 * struct cfg80211_wowlan_nd_match - information about the match
 *
 * @ssid: SSID of the match that triggered the wake up
 * @n_channels: Number of channels where the match occurred.  This
 *	value may be zero if the driver can't report the channels.
 * @channels: center frequencies of the channels where a match
 *	occurred (in MHz)
 */
struct cfg80211_wowlan_nd_match {
	struct cfg80211_ssid ssid;
	int n_channels;
	u32 channels[];
};

/**
 * struct cfg80211_wowlan_nd_info - net detect wake up information
 *
 * @n_matches: Number of match information instances provided in
 *	@matches.  This value may be zero if the driver can't provide
 *	match information.
 * @matches: Array of pointers to matches containing information about
 *	the matches that triggered the wake up.
 */
struct cfg80211_wowlan_nd_info {
	int n_matches;
	struct cfg80211_wowlan_nd_match *matches[];
};

2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300
/**
 * struct cfg80211_wowlan_wakeup - wakeup report
 * @disconnect: woke up by getting disconnected
 * @magic_pkt: woke up by receiving magic packet
 * @gtk_rekey_failure: woke up by GTK rekey failure
 * @eap_identity_req: woke up by EAP identity request packet
 * @four_way_handshake: woke up by 4-way handshake
 * @rfkill_release: woke up by rfkill being released
 * @pattern_idx: pattern that caused wakeup, -1 if not due to pattern
 * @packet_present_len: copied wakeup packet data
 * @packet_len: original wakeup packet length
 * @packet: The packet causing the wakeup, if any.
 * @packet_80211:  For pattern match, magic packet and other data
 *	frame triggers an 802.3 frame should be reported, for
 *	disconnect due to deauth 802.11 frame. This indicates which
 *	it is.
2301 2302 2303
 * @tcp_match: TCP wakeup packet received
 * @tcp_connlost: TCP connection lost or failed to establish
 * @tcp_nomoretokens: TCP data ran out of tokens
2304
 * @net_detect: if not %NULL, woke up because of net detect
2305 2306 2307 2308
 */
struct cfg80211_wowlan_wakeup {
	bool disconnect, magic_pkt, gtk_rekey_failure,
	     eap_identity_req, four_way_handshake,
2309 2310
	     rfkill_release, packet_80211,
	     tcp_match, tcp_connlost, tcp_nomoretokens;
2311 2312 2313
	s32 pattern_idx;
	u32 packet_present_len, packet_len;
	const void *packet;
2314
	struct cfg80211_wowlan_nd_info *net_detect;
2315 2316
};

2317 2318
/**
 * struct cfg80211_gtk_rekey_data - rekey data
2319 2320 2321
 * @kek: key encryption key (NL80211_KEK_LEN bytes)
 * @kck: key confirmation key (NL80211_KCK_LEN bytes)
 * @replay_ctr: replay counter (NL80211_REPLAY_CTR_LEN bytes)
2322 2323
 */
struct cfg80211_gtk_rekey_data {
2324
	const u8 *kek, *kck, *replay_ctr;
2325 2326
};

2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341
/**
 * struct cfg80211_update_ft_ies_params - FT IE Information
 *
 * This structure provides information needed to update the fast transition IE
 *
 * @md: The Mobility Domain ID, 2 Octet value
 * @ie: Fast Transition IEs
 * @ie_len: Length of ft_ie in octets
 */
struct cfg80211_update_ft_ies_params {
	u16 md;
	const u8 *ie;
	size_t ie_len;
};

2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353
/**
 * struct cfg80211_mgmt_tx_params - mgmt tx parameters
 *
 * This structure provides information needed to transmit a mgmt frame
 *
 * @chan: channel to use
 * @offchan: indicates wether off channel operation is required
 * @wait: duration for ROC
 * @buf: buffer to transmit
 * @len: buffer length
 * @no_cck: don't use cck rates for this frame
 * @dont_wait_for_ack: tells the low level not to wait for an ack
2354 2355
 * @n_csa_offsets: length of csa_offsets array
 * @csa_offsets: array of all the csa offsets in the frame
2356 2357 2358 2359 2360 2361 2362 2363 2364
 */
struct cfg80211_mgmt_tx_params {
	struct ieee80211_channel *chan;
	bool offchan;
	unsigned int wait;
	const u8 *buf;
	size_t len;
	bool no_cck;
	bool dont_wait_for_ack;
2365 2366
	int n_csa_offsets;
	const u16 *csa_offsets;
2367 2368
};

2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412
/**
 * struct cfg80211_dscp_exception - DSCP exception
 *
 * @dscp: DSCP value that does not adhere to the user priority range definition
 * @up: user priority value to which the corresponding DSCP value belongs
 */
struct cfg80211_dscp_exception {
	u8 dscp;
	u8 up;
};

/**
 * struct cfg80211_dscp_range - DSCP range definition for user priority
 *
 * @low: lowest DSCP value of this user priority range, inclusive
 * @high: highest DSCP value of this user priority range, inclusive
 */
struct cfg80211_dscp_range {
	u8 low;
	u8 high;
};

/* QoS Map Set element length defined in IEEE Std 802.11-2012, 8.4.2.97 */
#define IEEE80211_QOS_MAP_MAX_EX	21
#define IEEE80211_QOS_MAP_LEN_MIN	16
#define IEEE80211_QOS_MAP_LEN_MAX \
	(IEEE80211_QOS_MAP_LEN_MIN + 2 * IEEE80211_QOS_MAP_MAX_EX)

/**
 * struct cfg80211_qos_map - QoS Map Information
 *
 * This struct defines the Interworking QoS map setting for DSCP values
 *
 * @num_des: number of DSCP exceptions (0..21)
 * @dscp_exception: optionally up to maximum of 21 DSCP exceptions from
 *	the user priority DSCP range definition
 * @up: DSCP range definition for a particular user priority
 */
struct cfg80211_qos_map {
	u8 num_des;
	struct cfg80211_dscp_exception dscp_exception[IEEE80211_QOS_MAP_MAX_EX];
	struct cfg80211_dscp_range up[8];
};

2413 2414 2415 2416 2417 2418
/**
 * struct cfg80211_nan_conf - NAN configuration
 *
 * This struct defines NAN configuration parameters
 *
 * @master_pref: master preference (1 - 255)
L
Luca Coelho 已提交
2419 2420 2421
 * @bands: operating bands, a bitmap of &enum nl80211_band values.
 *	For instance, for NL80211_BAND_2GHZ, bit 0 would be set
 *	(i.e. BIT(NL80211_BAND_2GHZ)).
2422 2423 2424
 */
struct cfg80211_nan_conf {
	u8 master_pref;
L
Luca Coelho 已提交
2425
	u8 bands;
2426 2427
};

2428 2429 2430 2431 2432
/**
 * enum cfg80211_nan_conf_changes - indicates changed fields in NAN
 * configuration
 *
 * @CFG80211_NAN_CONF_CHANGED_PREF: master preference
L
Luca Coelho 已提交
2433
 * @CFG80211_NAN_CONF_CHANGED_BANDS: operating bands
2434 2435 2436
 */
enum cfg80211_nan_conf_changes {
	CFG80211_NAN_CONF_CHANGED_PREF = BIT(0),
L
Luca Coelho 已提交
2437
	CFG80211_NAN_CONF_CHANGED_BANDS = BIT(1),
2438 2439
};

2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506
/**
 * struct cfg80211_nan_func_filter - a NAN function Rx / Tx filter
 *
 * @filter: the content of the filter
 * @len: the length of the filter
 */
struct cfg80211_nan_func_filter {
	const u8 *filter;
	u8 len;
};

/**
 * struct cfg80211_nan_func - a NAN function
 *
 * @type: &enum nl80211_nan_function_type
 * @service_id: the service ID of the function
 * @publish_type: &nl80211_nan_publish_type
 * @close_range: if true, the range should be limited. Threshold is
 *	implementation specific.
 * @publish_bcast: if true, the solicited publish should be broadcasted
 * @subscribe_active: if true, the subscribe is active
 * @followup_id: the instance ID for follow up
 * @followup_reqid: the requestor instance ID for follow up
 * @followup_dest: MAC address of the recipient of the follow up
 * @ttl: time to live counter in DW.
 * @serv_spec_info: Service Specific Info
 * @serv_spec_info_len: Service Specific Info length
 * @srf_include: if true, SRF is inclusive
 * @srf_bf: Bloom Filter
 * @srf_bf_len: Bloom Filter length
 * @srf_bf_idx: Bloom Filter index
 * @srf_macs: SRF MAC addresses
 * @srf_num_macs: number of MAC addresses in SRF
 * @rx_filters: rx filters that are matched with corresponding peer's tx_filter
 * @tx_filters: filters that should be transmitted in the SDF.
 * @num_rx_filters: length of &rx_filters.
 * @num_tx_filters: length of &tx_filters.
 * @instance_id: driver allocated id of the function.
 * @cookie: unique NAN function identifier.
 */
struct cfg80211_nan_func {
	enum nl80211_nan_function_type type;
	u8 service_id[NL80211_NAN_FUNC_SERVICE_ID_LEN];
	u8 publish_type;
	bool close_range;
	bool publish_bcast;
	bool subscribe_active;
	u8 followup_id;
	u8 followup_reqid;
	struct mac_address followup_dest;
	u32 ttl;
	const u8 *serv_spec_info;
	u8 serv_spec_info_len;
	bool srf_include;
	const u8 *srf_bf;
	u8 srf_bf_len;
	u8 srf_bf_idx;
	struct mac_address *srf_macs;
	int srf_num_macs;
	struct cfg80211_nan_func_filter *rx_filters;
	struct cfg80211_nan_func_filter *tx_filters;
	u8 num_tx_filters;
	u8 num_rx_filters;
	u8 instance_id;
	u64 cookie;
};

2507 2508 2509 2510 2511 2512 2513 2514 2515
/**
 * struct cfg80211_ops - backend description for wireless configuration
 *
 * This struct is registered by fullmac card drivers and/or wireless stacks
 * in order to handle configuration requests on their interfaces.
 *
 * All callbacks except where otherwise noted should return 0
 * on success or a negative error code.
 *
2516 2517 2518 2519
 * All operations are currently invoked under rtnl for consistency with the
 * wireless extensions but this is subject to reevaluation as soon as this
 * code is used more widely and we have a first user without wext.
 *
J
Johannes Berg 已提交
2520 2521 2522
 * @suspend: wiphy device needs to be suspended. The variable @wow will
 *	be %NULL or contain the enabled Wake-on-Wireless triggers that are
 *	configured for the device.
J
Johannes Berg 已提交
2523
 * @resume: wiphy device needs to be resumed
2524 2525 2526
 * @set_wakeup: Called when WoWLAN is enabled/disabled, use this callback
 *	to call device_set_wakeup_enable() to enable/disable wakeup from
 *	the device.
J
Johannes Berg 已提交
2527
 *
J
Johannes Berg 已提交
2528
 * @add_virtual_intf: create a new virtual interface with the given name,
2529
 *	must set the struct wireless_dev's iftype. Beware: You must create
2530
 *	the new netdev in the wiphy's network namespace! Returns the struct
2531 2532
 *	wireless_dev, or an ERR_PTR. For P2P device wdevs, the driver must
 *	also set the address member in the wdev.
2533
 *
2534
 * @del_virtual_intf: remove the virtual interface
2535
 *
J
Johannes Berg 已提交
2536 2537
 * @change_virtual_intf: change type/configuration of virtual interface,
 *	keep the struct wireless_dev's iftype updated.
2538
 *
2539 2540 2541 2542 2543 2544
 * @add_key: add a key with the given parameters. @mac_addr will be %NULL
 *	when adding a group key.
 *
 * @get_key: get information about the key with the given parameters.
 *	@mac_addr will be %NULL when requesting information for a group
 *	key. All pointers given to the @callback function need not be valid
2545 2546
 *	after it returns. This function should return an error if it is
 *	not possible to retrieve the key, -ENOENT if it doesn't exist.
2547 2548
 *
 * @del_key: remove a key given the @mac_addr (%NULL for a group key)
2549
 *	and @key_index, return -ENOENT if the key doesn't exist.
2550 2551
 *
 * @set_default_key: set the default key on an interface
2552
 *
2553 2554
 * @set_default_mgmt_key: set the default management frame key on an interface
 *
2555 2556
 * @set_rekey_data: give the data necessary for GTK rekeying to the driver
 *
J
Johannes Berg 已提交
2557 2558 2559 2560
 * @start_ap: Start acting in AP mode defined by the parameters.
 * @change_beacon: Change the beacon parameters for an access point mode
 *	interface. This should reject the call when AP mode wasn't started.
 * @stop_ap: Stop being an AP, including stopping beaconing.
2561 2562
 *
 * @add_station: Add a new station.
2563
 * @del_station: Remove a station
2564 2565 2566
 * @change_station: Modify a given station. Note that flags changes are not much
 *	validated in cfg80211, in particular the auth/assoc/authorized flags
 *	might come to the driver in invalid combinations -- make sure to check
2567 2568
 *	them, also against the existing state! Drivers must call
 *	cfg80211_check_station_change() to validate the information.
J
Johannes Berg 已提交
2569 2570 2571 2572 2573 2574 2575 2576
 * @get_station: get station information for the station identified by @mac
 * @dump_station: dump station callback -- resume dump at index @idx
 *
 * @add_mpath: add a fixed mesh path
 * @del_mpath: delete a given mesh path
 * @change_mpath: change a given mesh path
 * @get_mpath: get a mesh path for the given parameters
 * @dump_mpath: dump mesh path callback -- resume dump at index @idx
2577 2578
 * @get_mpp: get a mesh proxy path for the given parameters
 * @dump_mpp: dump mesh proxy path callback -- resume dump at index @idx
2579
 * @join_mesh: join the mesh network with the specified parameters
2580
 *	(invoked with the wireless_dev mutex held)
2581
 * @leave_mesh: leave the current mesh network
2582
 *	(invoked with the wireless_dev mutex held)
2583
 *
2584
 * @get_mesh_config: Get the current mesh configuration
2585
 *
2586
 * @update_mesh_config: Update mesh parameters on a running mesh.
2587 2588 2589
 *	The mask is a bitfield which tells us which parameters to
 *	set, and which to leave alone.
 *
2590
 * @change_bss: Modify parameters for a given BSS.
2591 2592
 *
 * @set_txq_params: Set TX queue parameters
2593
 *
2594 2595 2596 2597 2598 2599 2600 2601
 * @libertas_set_mesh_channel: Only for backward compatibility for libertas,
 *	as it doesn't implement join_mesh and needs to set the channel to
 *	join the mesh instead.
 *
 * @set_monitor_channel: Set the monitor mode channel for the device. If other
 *	interfaces are active this callback should reject the configuration.
 *	If no interfaces are active or the device is down, the channel should
 *	be stored for when a monitor interface becomes active.
2602
 *
2603 2604 2605 2606
 * @scan: Request to do a scan. If returning zero, the scan request is given
 *	the driver, and will be valid until passed to cfg80211_scan_done().
 *	For scan results, call cfg80211_inform_bss(); you can call this outside
 *	the scan/scan_done bracket too.
2607 2608
 * @abort_scan: Tell the driver to abort an ongoing scan. The driver shall
 *	indicate the status of the scan through cfg80211_scan_done().
2609 2610
 *
 * @auth: Request to authenticate with the specified peer
2611
 *	(invoked with the wireless_dev mutex held)
2612
 * @assoc: Request to (re)associate with the specified peer
2613
 *	(invoked with the wireless_dev mutex held)
2614
 * @deauth: Request to deauthenticate from the specified peer
2615
 *	(invoked with the wireless_dev mutex held)
2616
 * @disassoc: Request to disassociate from the specified peer
2617
 *	(invoked with the wireless_dev mutex held)
J
Johannes Berg 已提交
2618
 *
S
Samuel Ortiz 已提交
2619
 * @connect: Connect to the ESS with the specified parameters. When connected,
2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631
 *	call cfg80211_connect_result()/cfg80211_connect_bss() with status code
 *	%WLAN_STATUS_SUCCESS. If the connection fails for some reason, call
 *	cfg80211_connect_result()/cfg80211_connect_bss() with the status code
 *	from the AP or cfg80211_connect_timeout() if no frame with status code
 *	was received.
 *	The driver is allowed to roam to other BSSes within the ESS when the
 *	other BSS matches the connect parameters. When such roaming is initiated
 *	by the driver, the driver is expected to verify that the target matches
 *	the configured security parameters and to use Reassociation Request
 *	frame instead of Association Request frame.
 *	The connect function can also be used to request the driver to perform a
 *	specific roam when connected to an ESS. In that case, the prev_bssid
2632
 *	parameter is set to the BSSID of the currently associated BSS as an
2633 2634 2635 2636
 *	indication of requesting reassociation.
 *	In both the driver-initiated and new connect() call initiated roaming
 *	cases, the result of roaming is indicated with a call to
 *	cfg80211_roamed() or cfg80211_roamed_bss().
2637
 *	(invoked with the wireless_dev mutex held)
2638 2639 2640 2641 2642 2643 2644 2645
 * @update_connect_params: Update the connect parameters while connected to a
 *	BSS. The updated parameters can be used by driver/firmware for
 *	subsequent BSS selection (roaming) decisions and to form the
 *	Authentication/(Re)Association Request frames. This call does not
 *	request an immediate disassociation or reassociation with the current
 *	BSS, i.e., this impacts only subsequent (re)associations. The bits in
 *	changed are defined in &enum cfg80211_connect_params_changed.
 *	(invoked with the wireless_dev mutex held)
2646 2647 2648 2649
 * @disconnect: Disconnect from the BSS/ESS or stop connection attempts if
 *      connection is in progress. Once done, call cfg80211_disconnected() in
 *      case connection was already established (invoked with the
 *      wireless_dev mutex held), otherwise call cfg80211_connect_timeout().
S
Samuel Ortiz 已提交
2650
 *
J
Johannes Berg 已提交
2651 2652 2653
 * @join_ibss: Join the specified IBSS (or create if necessary). Once done, call
 *	cfg80211_ibss_joined(), also call that function when changing BSSID due
 *	to a merge.
2654
 *	(invoked with the wireless_dev mutex held)
J
Johannes Berg 已提交
2655
 * @leave_ibss: Leave the IBSS.
2656
 *	(invoked with the wireless_dev mutex held)
2657
 *
2658 2659 2660
 * @set_mcast_rate: Set the specified multicast rate (only if vif is in ADHOC or
 *	MESH mode)
 *
2661 2662 2663 2664
 * @set_wiphy_params: Notify that wiphy parameters have changed;
 *	@changed bitfield (see &enum wiphy_params_flags) describes which values
 *	have changed. The actual parameter values are available in
 *	struct wiphy. If returning an error, no value should be changed.
2665
 *
2666
 * @set_tx_power: set the transmit power according to the parameters,
2667 2668 2669 2670
 *	the power passed is in mBm, to get dBm use MBM_TO_DBM(). The
 *	wdev may be %NULL if power was set for the wiphy, and will
 *	always be %NULL unless the driver supports per-vif TX power
 *	(as advertised by the nl80211 feature flag.)
2671
 * @get_tx_power: store the current TX power into the dbm variable;
J
Johannes Berg 已提交
2672 2673
 *	return 0 if successful
 *
J
Johannes Berg 已提交
2674 2675
 * @set_wds_peer: set the WDS peer for a WDS interface
 *
J
Johannes Berg 已提交
2676 2677
 * @rfkill_poll: polls the hw rfkill line, use cfg80211 reporting
 *	functions to adjust rfkill hw state
2678
 *
2679 2680
 * @dump_survey: get site survey information.
 *
2681 2682 2683 2684 2685 2686 2687 2688
 * @remain_on_channel: Request the driver to remain awake on the specified
 *	channel for the specified duration to complete an off-channel
 *	operation (e.g., public action frame exchange). When the driver is
 *	ready on the requested channel, it must indicate this with an event
 *	notification by calling cfg80211_ready_on_channel().
 * @cancel_remain_on_channel: Cancel an on-going remain-on-channel operation.
 *	This allows the operation to be terminated prior to timeout based on
 *	the duration value.
2689 2690 2691
 * @mgmt_tx: Transmit a management frame.
 * @mgmt_tx_cancel_wait: Cancel the wait time from transmitting a management
 *	frame on another channel
2692
 *
2693
 * @testmode_cmd: run a test mode command; @wdev may be %NULL
W
Wey-Yi Guy 已提交
2694 2695 2696 2697 2698 2699
 * @testmode_dump: Implement a test mode dump. The cb->args[2] and up may be
 *	used by the function, but 0 and 1 must not be touched. Additionally,
 *	return error codes other than -ENOBUFS and -ENOENT will terminate the
 *	dump and return to userspace with an error, so be careful. If any data
 *	was passed in from userspace then the data/len arguments will be present
 *	and point to the data contained in %NL80211_ATTR_TESTDATA.
S
Samuel Ortiz 已提交
2700
 *
J
Johannes Berg 已提交
2701 2702
 * @set_bitrate_mask: set the bitrate mask configuration
 *
S
Samuel Ortiz 已提交
2703 2704 2705 2706 2707
 * @set_pmksa: Cache a PMKID for a BSSID. This is mostly useful for fullmac
 *	devices running firmwares capable of generating the (re) association
 *	RSN IE. It allows for faster roaming between WPA2 BSSIDs.
 * @del_pmksa: Delete a cached PMKID.
 * @flush_pmksa: Flush all cached PMKIDs.
2708 2709
 * @set_power_mgmt: Configure WLAN power management. A timeout value of -1
 *	allows the driver to adjust the dynamic ps timeout value.
2710
 * @set_cqm_rssi_config: Configure connection quality monitor RSSI threshold.
2711 2712 2713 2714
 *	After configuration, the driver should (soon) send an event indicating
 *	the current level is above/below the configured threshold; this may
 *	need some care when the configuration is changed (without first being
 *	disabled.)
2715 2716 2717 2718 2719
 * @set_cqm_rssi_range_config: Configure two RSSI thresholds in the
 *	connection quality monitor.  An event is to be sent only when the
 *	signal level is found to be outside the two values.  The driver should
 *	set %NL80211_EXT_FEATURE_CQM_RSSI_LIST if this method is implemented.
 *	If it is provided then there's no point providing @set_cqm_rssi_config.
2720 2721
 * @set_cqm_txe_config: Configure connection quality monitor TX error
 *	thresholds.
2722
 * @sched_scan_start: Tell the driver to start a scheduled scan.
2723 2724 2725 2726 2727 2728
 * @sched_scan_stop: Tell the driver to stop an ongoing scheduled scan. This
 *	call must stop the scheduled scan and be ready for starting a new one
 *	before it returns, i.e. @sched_scan_start may be called immediately
 *	after that again and should not fail in that case. The driver should
 *	not call cfg80211_sched_scan_stopped() for a requested stop (when this
 *	method returns 0.)
S
Samuel Ortiz 已提交
2729
 *
2730
 * @mgmt_frame_register: Notify driver that a management frame type was
2731
 *	registered. The callback is allowed to sleep.
2732 2733 2734 2735 2736 2737 2738
 *
 * @set_antenna: Set antenna configuration (tx_ant, rx_ant) on the device.
 *	Parameters are bitmaps of allowed antennas to use for TX/RX. Drivers may
 *	reject TX/RX mask combinations they cannot support by returning -EINVAL
 *	(also see nl80211.h @NL80211_ATTR_WIPHY_ANTENNA_TX).
 *
 * @get_antenna: Get current antenna configuration from device (tx_ant, rx_ant).
2739
 *
2740 2741
 * @tdls_mgmt: Transmit a TDLS management frame.
 * @tdls_oper: Perform a high-level TDLS operation (e.g. TDLS link setup).
J
Johannes Berg 已提交
2742 2743 2744
 *
 * @probe_client: probe an associated client, must return a cookie that it
 *	later passes to cfg80211_probe_status().
2745 2746
 *
 * @set_noack_map: Set the NoAck Map for the TIDs.
2747
 *
2748 2749 2750
 * @get_channel: Get the current operating channel for the virtual interface.
 *	For monitor interfaces, it should return %NULL unless there's a single
 *	current monitoring channel.
2751 2752 2753
 *
 * @start_p2p_device: Start the given P2P device.
 * @stop_p2p_device: Stop the given P2P device.
2754 2755 2756 2757 2758 2759 2760
 *
 * @set_mac_acl: Sets MAC address control list in AP and P2P GO mode.
 *	Parameters include ACL policy, an array of MAC address of stations
 *	and the number of MAC addresses. If there is already a list in driver
 *	this new list replaces the existing one. Driver has to clear its ACL
 *	when number of MAC addresses entries is passed as 0. Drivers which
 *	advertise the support for MAC based ACL have to implement this callback.
2761 2762
 *
 * @start_radar_detection: Start radar detection in the driver.
2763 2764 2765 2766
 *
 * @update_ft_ies: Provide updated Fast BSS Transition information to the
 *	driver. If the SME is in the driver/firmware, this information can be
 *	used in building Authentication and Reassociation Request frames.
2767 2768 2769 2770 2771 2772
 *
 * @crit_proto_start: Indicates a critical protocol needs more link reliability
 *	for a given duration (milliseconds). The protocol is provided so the
 *	driver can take the most appropriate actions.
 * @crit_proto_stop: Indicates critical protocol no longer needs increased link
 *	reliability. This operation can not fail.
2773
 * @set_coalesce: Set coalesce parameters.
2774
 *
2775 2776 2777 2778 2779 2780
 * @channel_switch: initiate channel-switch procedure (with CSA). Driver is
 *	responsible for veryfing if the switch is possible. Since this is
 *	inherently tricky driver may decide to disconnect an interface later
 *	with cfg80211_stop_iface(). This doesn't mean driver can accept
 *	everything. It should do it's best to verify requests and reject them
 *	as soon as possible.
2781 2782
 *
 * @set_qos_map: Set QoS mapping information to the driver
2783 2784 2785 2786
 *
 * @set_ap_chanwidth: Set the AP (including P2P GO) mode channel width for the
 *	given interface This is used e.g. for dynamic HT 20/40 MHz channel width
 *	changes during the lifetime of the BSS.
2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797
 *
 * @add_tx_ts: validate (if admitted_time is 0) or add a TX TS to the device
 *	with the given parameters; action frame exchange has been handled by
 *	userspace so this just has to modify the TX path to take the TS into
 *	account.
 *	If the admitted time is 0 just validate the parameters to make sure
 *	the session can be created at all; it is valid to just always return
 *	success for that but that may result in inefficient behaviour (handshake
 *	with the peer followed by immediate teardown when the addition is later
 *	rejected)
 * @del_tx_ts: remove an existing TX TS
2798 2799 2800 2801 2802
 *
 * @join_ocb: join the OCB network with the specified parameters
 *	(invoked with the wireless_dev mutex held)
 * @leave_ocb: leave the current OCB network
 *	(invoked with the wireless_dev mutex held)
2803 2804 2805 2806 2807 2808
 *
 * @tdls_channel_switch: Start channel-switching with a TDLS peer. The driver
 *	is responsible for continually initiating channel-switching operations
 *	and returning to the base channel for communication with the AP.
 * @tdls_cancel_channel_switch: Stop channel-switching with a TDLS peer. Both
 *	peers must be on the base channel when the call completes.
2809 2810
 * @start_nan: Start the NAN interface.
 * @stop_nan: Stop the NAN interface.
2811 2812 2813 2814 2815 2816 2817 2818
 * @add_nan_func: Add a NAN function. Returns negative value on failure.
 *	On success @nan_func ownership is transferred to the driver and
 *	it may access it outside of the scope of this function. The driver
 *	should free the @nan_func when no longer needed by calling
 *	cfg80211_free_nan_func().
 *	On success the driver should assign an instance_id in the
 *	provided @nan_func.
 * @del_nan_func: Delete a NAN function.
2819 2820 2821
 * @nan_change_conf: changes NAN configuration. The changed parameters must
 *	be specified in @changes (using &enum cfg80211_nan_conf_changes);
 *	All other parameters must be ignored.
2822 2823
 *
 * @set_multicast_to_unicast: configure multicast to unicast conversion for BSS
2824 2825
 */
struct cfg80211_ops {
J
Johannes Berg 已提交
2826
	int	(*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
J
Johannes Berg 已提交
2827
	int	(*resume)(struct wiphy *wiphy);
2828
	void	(*set_wakeup)(struct wiphy *wiphy, bool enabled);
J
Johannes Berg 已提交
2829

2830
	struct wireless_dev * (*add_virtual_intf)(struct wiphy *wiphy,
2831
						  const char *name,
2832
						  unsigned char name_assign_type,
2833 2834 2835 2836 2837
						  enum nl80211_iftype type,
						  u32 *flags,
						  struct vif_params *params);
	int	(*del_virtual_intf)(struct wiphy *wiphy,
				    struct wireless_dev *wdev);
2838 2839
	int	(*change_virtual_intf)(struct wiphy *wiphy,
				       struct net_device *dev,
2840 2841
				       enum nl80211_iftype type, u32 *flags,
				       struct vif_params *params);
2842 2843

	int	(*add_key)(struct wiphy *wiphy, struct net_device *netdev,
2844
			   u8 key_index, bool pairwise, const u8 *mac_addr,
2845 2846
			   struct key_params *params);
	int	(*get_key)(struct wiphy *wiphy, struct net_device *netdev,
2847 2848
			   u8 key_index, bool pairwise, const u8 *mac_addr,
			   void *cookie,
2849 2850
			   void (*callback)(void *cookie, struct key_params*));
	int	(*del_key)(struct wiphy *wiphy, struct net_device *netdev,
2851
			   u8 key_index, bool pairwise, const u8 *mac_addr);
2852 2853
	int	(*set_default_key)(struct wiphy *wiphy,
				   struct net_device *netdev,
2854
				   u8 key_index, bool unicast, bool multicast);
2855 2856 2857
	int	(*set_default_mgmt_key)(struct wiphy *wiphy,
					struct net_device *netdev,
					u8 key_index);
2858

2859 2860 2861 2862 2863
	int	(*start_ap)(struct wiphy *wiphy, struct net_device *dev,
			    struct cfg80211_ap_settings *settings);
	int	(*change_beacon)(struct wiphy *wiphy, struct net_device *dev,
				 struct cfg80211_beacon_data *info);
	int	(*stop_ap)(struct wiphy *wiphy, struct net_device *dev);
2864 2865 2866


	int	(*add_station)(struct wiphy *wiphy, struct net_device *dev,
2867 2868
			       const u8 *mac,
			       struct station_parameters *params);
2869
	int	(*del_station)(struct wiphy *wiphy, struct net_device *dev,
2870
			       struct station_del_parameters *params);
2871
	int	(*change_station)(struct wiphy *wiphy, struct net_device *dev,
2872 2873
				  const u8 *mac,
				  struct station_parameters *params);
2874
	int	(*get_station)(struct wiphy *wiphy, struct net_device *dev,
2875
			       const u8 *mac, struct station_info *sinfo);
2876
	int	(*dump_station)(struct wiphy *wiphy, struct net_device *dev,
2877
				int idx, u8 *mac, struct station_info *sinfo);
2878 2879

	int	(*add_mpath)(struct wiphy *wiphy, struct net_device *dev,
2880
			       const u8 *dst, const u8 *next_hop);
2881
	int	(*del_mpath)(struct wiphy *wiphy, struct net_device *dev,
2882
			       const u8 *dst);
2883
	int	(*change_mpath)(struct wiphy *wiphy, struct net_device *dev,
2884
				  const u8 *dst, const u8 *next_hop);
2885
	int	(*get_mpath)(struct wiphy *wiphy, struct net_device *dev,
2886
			     u8 *dst, u8 *next_hop, struct mpath_info *pinfo);
2887
	int	(*dump_mpath)(struct wiphy *wiphy, struct net_device *dev,
2888 2889
			      int idx, u8 *dst, u8 *next_hop,
			      struct mpath_info *pinfo);
2890 2891 2892 2893 2894
	int	(*get_mpp)(struct wiphy *wiphy, struct net_device *dev,
			   u8 *dst, u8 *mpp, struct mpath_info *pinfo);
	int	(*dump_mpp)(struct wiphy *wiphy, struct net_device *dev,
			    int idx, u8 *dst, u8 *mpp,
			    struct mpath_info *pinfo);
2895
	int	(*get_mesh_config)(struct wiphy *wiphy,
2896 2897
				struct net_device *dev,
				struct mesh_config *conf);
2898
	int	(*update_mesh_config)(struct wiphy *wiphy,
2899 2900 2901 2902 2903 2904 2905
				      struct net_device *dev, u32 mask,
				      const struct mesh_config *nconf);
	int	(*join_mesh)(struct wiphy *wiphy, struct net_device *dev,
			     const struct mesh_config *conf,
			     const struct mesh_setup *setup);
	int	(*leave_mesh)(struct wiphy *wiphy, struct net_device *dev);

2906 2907 2908 2909
	int	(*join_ocb)(struct wiphy *wiphy, struct net_device *dev,
			    struct ocb_setup *setup);
	int	(*leave_ocb)(struct wiphy *wiphy, struct net_device *dev);

2910 2911
	int	(*change_bss)(struct wiphy *wiphy, struct net_device *dev,
			      struct bss_parameters *params);
2912

2913
	int	(*set_txq_params)(struct wiphy *wiphy, struct net_device *dev,
2914
				  struct ieee80211_txq_params *params);
2915

2916 2917 2918 2919 2920
	int	(*libertas_set_mesh_channel)(struct wiphy *wiphy,
					     struct net_device *dev,
					     struct ieee80211_channel *chan);

	int	(*set_monitor_channel)(struct wiphy *wiphy,
2921
				       struct cfg80211_chan_def *chandef);
2922

J
Johannes Berg 已提交
2923
	int	(*scan)(struct wiphy *wiphy,
2924
			struct cfg80211_scan_request *request);
2925
	void	(*abort_scan)(struct wiphy *wiphy, struct wireless_dev *wdev);
2926 2927 2928 2929 2930 2931

	int	(*auth)(struct wiphy *wiphy, struct net_device *dev,
			struct cfg80211_auth_request *req);
	int	(*assoc)(struct wiphy *wiphy, struct net_device *dev,
			 struct cfg80211_assoc_request *req);
	int	(*deauth)(struct wiphy *wiphy, struct net_device *dev,
2932
			  struct cfg80211_deauth_request *req);
2933
	int	(*disassoc)(struct wiphy *wiphy, struct net_device *dev,
2934
			    struct cfg80211_disassoc_request *req);
J
Johannes Berg 已提交
2935

S
Samuel Ortiz 已提交
2936 2937
	int	(*connect)(struct wiphy *wiphy, struct net_device *dev,
			   struct cfg80211_connect_params *sme);
2938 2939 2940 2941
	int	(*update_connect_params)(struct wiphy *wiphy,
					 struct net_device *dev,
					 struct cfg80211_connect_params *sme,
					 u32 changed);
S
Samuel Ortiz 已提交
2942 2943 2944
	int	(*disconnect)(struct wiphy *wiphy, struct net_device *dev,
			      u16 reason_code);

J
Johannes Berg 已提交
2945 2946 2947
	int	(*join_ibss)(struct wiphy *wiphy, struct net_device *dev,
			     struct cfg80211_ibss_params *params);
	int	(*leave_ibss)(struct wiphy *wiphy, struct net_device *dev);
2948

2949
	int	(*set_mcast_rate)(struct wiphy *wiphy, struct net_device *dev,
2950
				  int rate[NUM_NL80211_BANDS]);
2951

2952
	int	(*set_wiphy_params)(struct wiphy *wiphy, u32 changed);
2953

2954
	int	(*set_tx_power)(struct wiphy *wiphy, struct wireless_dev *wdev,
2955
				enum nl80211_tx_power_setting type, int mbm);
2956 2957
	int	(*get_tx_power)(struct wiphy *wiphy, struct wireless_dev *wdev,
				int *dbm);
J
Johannes Berg 已提交
2958

J
Johannes Berg 已提交
2959
	int	(*set_wds_peer)(struct wiphy *wiphy, struct net_device *dev,
J
Johannes Berg 已提交
2960
				const u8 *addr);
J
Johannes Berg 已提交
2961

J
Johannes Berg 已提交
2962
	void	(*rfkill_poll)(struct wiphy *wiphy);
2963 2964

#ifdef CONFIG_NL80211_TESTMODE
2965 2966
	int	(*testmode_cmd)(struct wiphy *wiphy, struct wireless_dev *wdev,
				void *data, int len);
W
Wey-Yi Guy 已提交
2967 2968 2969
	int	(*testmode_dump)(struct wiphy *wiphy, struct sk_buff *skb,
				 struct netlink_callback *cb,
				 void *data, int len);
2970
#endif
J
Johannes Berg 已提交
2971

J
Johannes Berg 已提交
2972 2973 2974 2975 2976
	int	(*set_bitrate_mask)(struct wiphy *wiphy,
				    struct net_device *dev,
				    const u8 *peer,
				    const struct cfg80211_bitrate_mask *mask);

2977 2978 2979
	int	(*dump_survey)(struct wiphy *wiphy, struct net_device *netdev,
			int idx, struct survey_info *info);

S
Samuel Ortiz 已提交
2980 2981 2982 2983 2984 2985
	int	(*set_pmksa)(struct wiphy *wiphy, struct net_device *netdev,
			     struct cfg80211_pmksa *pmksa);
	int	(*del_pmksa)(struct wiphy *wiphy, struct net_device *netdev,
			     struct cfg80211_pmksa *pmksa);
	int	(*flush_pmksa)(struct wiphy *wiphy, struct net_device *netdev);

2986
	int	(*remain_on_channel)(struct wiphy *wiphy,
2987
				     struct wireless_dev *wdev,
2988 2989 2990 2991
				     struct ieee80211_channel *chan,
				     unsigned int duration,
				     u64 *cookie);
	int	(*cancel_remain_on_channel)(struct wiphy *wiphy,
2992
					    struct wireless_dev *wdev,
2993 2994
					    u64 cookie);

2995
	int	(*mgmt_tx)(struct wiphy *wiphy, struct wireless_dev *wdev,
2996 2997
			   struct cfg80211_mgmt_tx_params *params,
			   u64 *cookie);
2998
	int	(*mgmt_tx_cancel_wait)(struct wiphy *wiphy,
2999
				       struct wireless_dev *wdev,
3000
				       u64 cookie);
3001

J
Johannes Berg 已提交
3002 3003
	int	(*set_power_mgmt)(struct wiphy *wiphy, struct net_device *dev,
				  bool enabled, int timeout);
3004 3005 3006 3007

	int	(*set_cqm_rssi_config)(struct wiphy *wiphy,
				       struct net_device *dev,
				       s32 rssi_thold, u32 rssi_hyst);
3008

3009 3010 3011 3012
	int	(*set_cqm_rssi_range_config)(struct wiphy *wiphy,
					     struct net_device *dev,
					     s32 rssi_low, s32 rssi_high);

3013 3014 3015 3016
	int	(*set_cqm_txe_config)(struct wiphy *wiphy,
				      struct net_device *dev,
				      u32 rate, u32 pkts, u32 intvl);

3017
	void	(*mgmt_frame_register)(struct wiphy *wiphy,
3018
				       struct wireless_dev *wdev,
3019
				       u16 frame_type, bool reg);
3020 3021 3022

	int	(*set_antenna)(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant);
	int	(*get_antenna)(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant);
3023

3024 3025 3026
	int	(*sched_scan_start)(struct wiphy *wiphy,
				struct net_device *dev,
				struct cfg80211_sched_scan_request *request);
3027
	int	(*sched_scan_stop)(struct wiphy *wiphy, struct net_device *dev);
3028 3029 3030

	int	(*set_rekey_data)(struct wiphy *wiphy, struct net_device *dev,
				  struct cfg80211_gtk_rekey_data *data);
3031 3032

	int	(*tdls_mgmt)(struct wiphy *wiphy, struct net_device *dev,
3033
			     const u8 *peer, u8 action_code,  u8 dialog_token,
3034
			     u16 status_code, u32 peer_capability,
3035
			     bool initiator, const u8 *buf, size_t len);
3036
	int	(*tdls_oper)(struct wiphy *wiphy, struct net_device *dev,
3037
			     const u8 *peer, enum nl80211_tdls_operation oper);
J
Johannes Berg 已提交
3038 3039 3040

	int	(*probe_client)(struct wiphy *wiphy, struct net_device *dev,
				const u8 *peer, u64 *cookie);
3041

3042 3043 3044 3045
	int	(*set_noack_map)(struct wiphy *wiphy,
				  struct net_device *dev,
				  u16 noack_map);

3046
	int	(*get_channel)(struct wiphy *wiphy,
3047
			       struct wireless_dev *wdev,
3048
			       struct cfg80211_chan_def *chandef);
3049 3050 3051 3052 3053

	int	(*start_p2p_device)(struct wiphy *wiphy,
				    struct wireless_dev *wdev);
	void	(*stop_p2p_device)(struct wiphy *wiphy,
				   struct wireless_dev *wdev);
3054 3055 3056

	int	(*set_mac_acl)(struct wiphy *wiphy, struct net_device *dev,
			       const struct cfg80211_acl_data *params);
3057 3058 3059

	int	(*start_radar_detection)(struct wiphy *wiphy,
					 struct net_device *dev,
3060 3061
					 struct cfg80211_chan_def *chandef,
					 u32 cac_time_ms);
3062 3063
	int	(*update_ft_ies)(struct wiphy *wiphy, struct net_device *dev,
				 struct cfg80211_update_ft_ies_params *ftie);
3064 3065 3066 3067 3068 3069
	int	(*crit_proto_start)(struct wiphy *wiphy,
				    struct wireless_dev *wdev,
				    enum nl80211_crit_proto_id protocol,
				    u16 duration);
	void	(*crit_proto_stop)(struct wiphy *wiphy,
				   struct wireless_dev *wdev);
3070 3071
	int	(*set_coalesce)(struct wiphy *wiphy,
				struct cfg80211_coalesce *coalesce);
3072 3073 3074 3075

	int	(*channel_switch)(struct wiphy *wiphy,
				  struct net_device *dev,
				  struct cfg80211_csa_settings *params);
3076

3077 3078 3079
	int     (*set_qos_map)(struct wiphy *wiphy,
			       struct net_device *dev,
			       struct cfg80211_qos_map *qos_map);
3080 3081 3082

	int	(*set_ap_chanwidth)(struct wiphy *wiphy, struct net_device *dev,
				    struct cfg80211_chan_def *chandef);
3083 3084 3085 3086 3087 3088

	int	(*add_tx_ts)(struct wiphy *wiphy, struct net_device *dev,
			     u8 tsid, const u8 *peer, u8 user_prio,
			     u16 admitted_time);
	int	(*del_tx_ts)(struct wiphy *wiphy, struct net_device *dev,
			     u8 tsid, const u8 *peer);
3089 3090 3091 3092 3093 3094 3095 3096

	int	(*tdls_channel_switch)(struct wiphy *wiphy,
				       struct net_device *dev,
				       const u8 *addr, u8 oper_class,
				       struct cfg80211_chan_def *chandef);
	void	(*tdls_cancel_channel_switch)(struct wiphy *wiphy,
					      struct net_device *dev,
					      const u8 *addr);
3097 3098 3099
	int	(*start_nan)(struct wiphy *wiphy, struct wireless_dev *wdev,
			     struct cfg80211_nan_conf *conf);
	void	(*stop_nan)(struct wiphy *wiphy, struct wireless_dev *wdev);
3100 3101 3102 3103
	int	(*add_nan_func)(struct wiphy *wiphy, struct wireless_dev *wdev,
				struct cfg80211_nan_func *nan_func);
	void	(*del_nan_func)(struct wiphy *wiphy, struct wireless_dev *wdev,
			       u64 cookie);
3104 3105 3106 3107
	int	(*nan_change_conf)(struct wiphy *wiphy,
				   struct wireless_dev *wdev,
				   struct cfg80211_nan_conf *conf,
				   u32 changes);
3108 3109 3110 3111

	int	(*set_multicast_to_unicast)(struct wiphy *wiphy,
					    struct net_device *dev,
					    const bool enabled);
3112 3113
};

J
Johannes Berg 已提交
3114 3115 3116 3117 3118 3119
/*
 * wireless hardware and networking interfaces structures
 * and registration/helper functions
 */

/**
J
Johannes Berg 已提交
3120 3121 3122 3123 3124 3125 3126 3127
 * enum wiphy_flags - wiphy capability flags
 *
 * @WIPHY_FLAG_NETNS_OK: if not set, do not allow changing the netns of this
 *	wiphy at all
 * @WIPHY_FLAG_PS_ON_BY_DEFAULT: if set to true, powersave will be enabled
 *	by default -- this flag will be set depending on the kernel's default
 *	on wiphy_new(), but can be changed by the driver if it has a good
 *	reason to override the default
3128 3129 3130
 * @WIPHY_FLAG_4ADDR_AP: supports 4addr mode even on AP (with a single station
 *	on a VLAN interface)
 * @WIPHY_FLAG_4ADDR_STATION: supports 4addr mode even as a station
3131 3132 3133
 * @WIPHY_FLAG_CONTROL_PORT_PROTOCOL: This device supports setting the
 *	control port protocol ethertype. The device also honours the
 *	control_port_no_encrypt flag.
3134
 * @WIPHY_FLAG_IBSS_RSN: The device supports IBSS RSN.
3135 3136
 * @WIPHY_FLAG_MESH_AUTH: The device supports mesh authentication by routing
 *	auth frames to userspace. See @NL80211_MESH_SETUP_USERSPACE_AUTH.
3137
 * @WIPHY_FLAG_SUPPORTS_SCHED_SCAN: The device supports scheduled scans.
3138 3139
 * @WIPHY_FLAG_SUPPORTS_FW_ROAM: The device supports roaming feature in the
 *	firmware.
3140
 * @WIPHY_FLAG_AP_UAPSD: The device supports uapsd on AP.
3141 3142 3143 3144 3145 3146
 * @WIPHY_FLAG_SUPPORTS_TDLS: The device supports TDLS (802.11z) operation.
 * @WIPHY_FLAG_TDLS_EXTERNAL_SETUP: The device does not handle TDLS (802.11z)
 *	link setup/discovery operations internally. Setup, discovery and
 *	teardown packets should be sent through the @NL80211_CMD_TDLS_MGMT
 *	command. When this flag is not set, @NL80211_CMD_TDLS_OPER should be
 *	used for asking the driver/firmware to perform a TDLS operation.
J
Johannes Berg 已提交
3147
 * @WIPHY_FLAG_HAVE_AP_SME: device integrates AP SME
3148 3149 3150
 * @WIPHY_FLAG_REPORTS_OBSS: the device will report beacons from other BSSes
 *	when there are virtual interfaces in AP mode by calling
 *	cfg80211_report_obss_beacon().
3151 3152
 * @WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD: When operating as an AP, the device
 *	responds to probe-requests in hardware.
3153 3154
 * @WIPHY_FLAG_OFFCHAN_TX: Device supports direct off-channel TX.
 * @WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL: Device supports remain-on-channel call.
3155
 * @WIPHY_FLAG_SUPPORTS_5_10_MHZ: Device supports 5 MHz and 10 MHz channels.
3156 3157
 * @WIPHY_FLAG_HAS_CHANNEL_SWITCH: Device supports channel switch in
 *	beaconing mode (AP, IBSS, Mesh, ...).
3158 3159
 * @WIPHY_FLAG_HAS_STATIC_WEP: The device supports static WEP key installation
 *	before connection.
J
Johannes Berg 已提交
3160 3161
 */
enum wiphy_flags {
3162
	/* use hole at 0 */
3163 3164
	/* use hole at 1 */
	/* use hole at 2 */
3165 3166 3167 3168 3169
	WIPHY_FLAG_NETNS_OK			= BIT(3),
	WIPHY_FLAG_PS_ON_BY_DEFAULT		= BIT(4),
	WIPHY_FLAG_4ADDR_AP			= BIT(5),
	WIPHY_FLAG_4ADDR_STATION		= BIT(6),
	WIPHY_FLAG_CONTROL_PORT_PROTOCOL	= BIT(7),
3170
	WIPHY_FLAG_IBSS_RSN			= BIT(8),
3171
	WIPHY_FLAG_MESH_AUTH			= BIT(10),
3172
	WIPHY_FLAG_SUPPORTS_SCHED_SCAN		= BIT(11),
3173
	/* use hole at 12 */
3174
	WIPHY_FLAG_SUPPORTS_FW_ROAM		= BIT(13),
3175
	WIPHY_FLAG_AP_UAPSD			= BIT(14),
3176 3177
	WIPHY_FLAG_SUPPORTS_TDLS		= BIT(15),
	WIPHY_FLAG_TDLS_EXTERNAL_SETUP		= BIT(16),
J
Johannes Berg 已提交
3178
	WIPHY_FLAG_HAVE_AP_SME			= BIT(17),
3179
	WIPHY_FLAG_REPORTS_OBSS			= BIT(18),
3180
	WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD	= BIT(19),
3181 3182
	WIPHY_FLAG_OFFCHAN_TX			= BIT(20),
	WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL	= BIT(21),
3183
	WIPHY_FLAG_SUPPORTS_5_10_MHZ		= BIT(22),
3184
	WIPHY_FLAG_HAS_CHANNEL_SWITCH		= BIT(23),
3185
	WIPHY_FLAG_HAS_STATIC_WEP		= BIT(24),
3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200
};

/**
 * struct ieee80211_iface_limit - limit on certain interface types
 * @max: maximum number of interfaces of these types
 * @types: interface types (bits)
 */
struct ieee80211_iface_limit {
	u16 max;
	u16 types;
};

/**
 * struct ieee80211_iface_combination - possible interface combination
 *
3201 3202
 * With this structure the driver can describe which interface
 * combinations it supports concurrently.
3203
 *
3204 3205 3206
 * Examples:
 *
 * 1. Allow #STA <= 1, #AP <= 1, matching BI, channels = 1, 2 total:
3207
 *
3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219
 *    .. code-block:: c
 *
 *	struct ieee80211_iface_limit limits1[] = {
 *		{ .max = 1, .types = BIT(NL80211_IFTYPE_STATION), },
 *		{ .max = 1, .types = BIT(NL80211_IFTYPE_AP}, },
 *	};
 *	struct ieee80211_iface_combination combination1 = {
 *		.limits = limits1,
 *		.n_limits = ARRAY_SIZE(limits1),
 *		.max_interfaces = 2,
 *		.beacon_int_infra_match = true,
 *	};
3220 3221
 *
 *
3222
 * 2. Allow #{AP, P2P-GO} <= 8, channels = 1, 8 total:
3223
 *
3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235
 *    .. code-block:: c
 *
 *	struct ieee80211_iface_limit limits2[] = {
 *		{ .max = 8, .types = BIT(NL80211_IFTYPE_AP) |
 *				     BIT(NL80211_IFTYPE_P2P_GO), },
 *	};
 *	struct ieee80211_iface_combination combination2 = {
 *		.limits = limits2,
 *		.n_limits = ARRAY_SIZE(limits2),
 *		.max_interfaces = 8,
 *		.num_different_channels = 1,
 *	};
3236 3237
 *
 *
3238 3239
 * 3. Allow #STA <= 1, #{P2P-client,P2P-GO} <= 3 on two channels, 4 total.
 *
3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254
 *    This allows for an infrastructure connection and three P2P connections.
 *
 *    .. code-block:: c
 *
 *	struct ieee80211_iface_limit limits3[] = {
 *		{ .max = 1, .types = BIT(NL80211_IFTYPE_STATION), },
 *		{ .max = 3, .types = BIT(NL80211_IFTYPE_P2P_GO) |
 *				     BIT(NL80211_IFTYPE_P2P_CLIENT), },
 *	};
 *	struct ieee80211_iface_combination combination3 = {
 *		.limits = limits3,
 *		.n_limits = ARRAY_SIZE(limits3),
 *		.max_interfaces = 4,
 *		.num_different_channels = 2,
 *	};
3255 3256 3257
 *
 */
struct ieee80211_iface_combination {
3258 3259 3260 3261
	/**
	 * @limits:
	 * limits for the given interface types
	 */
3262
	const struct ieee80211_iface_limit *limits;
3263 3264 3265 3266 3267

	/**
	 * @num_different_channels:
	 * can use up to this many different channels
	 */
3268
	u32 num_different_channels;
3269 3270 3271 3272 3273

	/**
	 * @max_interfaces:
	 * maximum number of interfaces in total allowed in this group
	 */
3274
	u16 max_interfaces;
3275 3276 3277 3278 3279

	/**
	 * @n_limits:
	 * number of limitations
	 */
3280
	u8 n_limits;
3281 3282 3283 3284 3285 3286

	/**
	 * @beacon_int_infra_match:
	 * In this combination, the beacon intervals between infrastructure
	 * and AP types must match. This is required only in special cases.
	 */
3287
	bool beacon_int_infra_match;
3288 3289 3290 3291 3292

	/**
	 * @radar_detect_widths:
	 * bitmap of channel widths supported for radar detection
	 */
3293
	u8 radar_detect_widths;
3294 3295 3296 3297 3298

	/**
	 * @radar_detect_regions:
	 * bitmap of regions supported for radar detection
	 */
3299
	u8 radar_detect_regions;
3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311

	/**
	 * @beacon_int_min_gcd:
	 * This interface combination supports different beacon intervals.
	 *
	 * = 0
	 *   all beacon intervals for different interface must be same.
	 * > 0
	 *   any beacon interval for the interface part of this combination AND
	 *   GCD of all beacon intervals from beaconing interfaces of this
	 *   combination must be greater or equal to this value.
	 */
3312
	u32 beacon_int_min_gcd;
J
Johannes Berg 已提交
3313 3314
};

3315 3316 3317 3318
struct ieee80211_txrx_stypes {
	u16 tx, rx;
};

J
Johannes Berg 已提交
3319 3320 3321 3322 3323 3324 3325 3326 3327 3328
/**
 * enum wiphy_wowlan_support_flags - WoWLAN support flags
 * @WIPHY_WOWLAN_ANY: supports wakeup for the special "any"
 *	trigger that keeps the device operating as-is and
 *	wakes up the host on any activity, for example a
 *	received packet that passed filtering; note that the
 *	packet should be preserved in that case
 * @WIPHY_WOWLAN_MAGIC_PKT: supports wakeup on magic packet
 *	(see nl80211.h)
 * @WIPHY_WOWLAN_DISCONNECT: supports wakeup on disconnect
3329 3330 3331 3332 3333
 * @WIPHY_WOWLAN_SUPPORTS_GTK_REKEY: supports GTK rekeying while asleep
 * @WIPHY_WOWLAN_GTK_REKEY_FAILURE: supports wakeup on GTK rekey failure
 * @WIPHY_WOWLAN_EAP_IDENTITY_REQ: supports wakeup on EAP identity request
 * @WIPHY_WOWLAN_4WAY_HANDSHAKE: supports wakeup on 4-way handshake failure
 * @WIPHY_WOWLAN_RFKILL_RELEASE: supports wakeup on RF-kill release
3334
 * @WIPHY_WOWLAN_NET_DETECT: supports wakeup on network detection
J
Johannes Berg 已提交
3335 3336
 */
enum wiphy_wowlan_support_flags {
3337 3338 3339 3340 3341 3342 3343 3344
	WIPHY_WOWLAN_ANY		= BIT(0),
	WIPHY_WOWLAN_MAGIC_PKT		= BIT(1),
	WIPHY_WOWLAN_DISCONNECT		= BIT(2),
	WIPHY_WOWLAN_SUPPORTS_GTK_REKEY	= BIT(3),
	WIPHY_WOWLAN_GTK_REKEY_FAILURE	= BIT(4),
	WIPHY_WOWLAN_EAP_IDENTITY_REQ	= BIT(5),
	WIPHY_WOWLAN_4WAY_HANDSHAKE	= BIT(6),
	WIPHY_WOWLAN_RFKILL_RELEASE	= BIT(7),
3345
	WIPHY_WOWLAN_NET_DETECT		= BIT(8),
J
Johannes Berg 已提交
3346 3347
};

3348 3349 3350 3351 3352 3353 3354 3355
struct wiphy_wowlan_tcp_support {
	const struct nl80211_wowlan_tcp_data_token_feature *tok;
	u32 data_payload_max;
	u32 data_interval_max;
	u32 wake_payload_max;
	bool seq;
};

J
Johannes Berg 已提交
3356 3357 3358 3359 3360 3361 3362
/**
 * struct wiphy_wowlan_support - WoWLAN support data
 * @flags: see &enum wiphy_wowlan_support_flags
 * @n_patterns: number of supported wakeup patterns
 *	(see nl80211.h for the pattern definition)
 * @pattern_max_len: maximum length of each pattern
 * @pattern_min_len: minimum length of each pattern
3363
 * @max_pkt_offset: maximum Rx packet offset
3364 3365 3366 3367 3368
 * @max_nd_match_sets: maximum number of matchsets for net-detect,
 *	similar, but not necessarily identical, to max_match_sets for
 *	scheduled scans.
 *	See &struct cfg80211_sched_scan_request.@match_sets for more
 *	details.
3369
 * @tcp: TCP wakeup support information
J
Johannes Berg 已提交
3370 3371 3372 3373 3374 3375
 */
struct wiphy_wowlan_support {
	u32 flags;
	int n_patterns;
	int pattern_max_len;
	int pattern_min_len;
3376
	int max_pkt_offset;
3377
	int max_nd_match_sets;
3378
	const struct wiphy_wowlan_tcp_support *tcp;
J
Johannes Berg 已提交
3379 3380
};

3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399
/**
 * struct wiphy_coalesce_support - coalesce support data
 * @n_rules: maximum number of coalesce rules
 * @max_delay: maximum supported coalescing delay in msecs
 * @n_patterns: number of supported patterns in a rule
 *	(see nl80211.h for the pattern definition)
 * @pattern_max_len: maximum length of each pattern
 * @pattern_min_len: minimum length of each pattern
 * @max_pkt_offset: maximum Rx packet offset
 */
struct wiphy_coalesce_support {
	int n_rules;
	int max_delay;
	int n_patterns;
	int pattern_max_len;
	int pattern_min_len;
	int max_pkt_offset;
};

J
Johannes Berg 已提交
3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419
/**
 * enum wiphy_vendor_command_flags - validation flags for vendor commands
 * @WIPHY_VENDOR_CMD_NEED_WDEV: vendor command requires wdev
 * @WIPHY_VENDOR_CMD_NEED_NETDEV: vendor command requires netdev
 * @WIPHY_VENDOR_CMD_NEED_RUNNING: interface/wdev must be up & running
 *	(must be combined with %_WDEV or %_NETDEV)
 */
enum wiphy_vendor_command_flags {
	WIPHY_VENDOR_CMD_NEED_WDEV = BIT(0),
	WIPHY_VENDOR_CMD_NEED_NETDEV = BIT(1),
	WIPHY_VENDOR_CMD_NEED_RUNNING = BIT(2),
};

/**
 * struct wiphy_vendor_command - vendor command definition
 * @info: vendor command identifying information, as used in nl80211
 * @flags: flags, see &enum wiphy_vendor_command_flags
 * @doit: callback for the operation, note that wdev is %NULL if the
 *	flags didn't ask for a wdev and non-%NULL otherwise; the data
 *	pointer may be %NULL if userspace provided no data at all
3420 3421 3422 3423 3424 3425
 * @dumpit: dump callback, for transferring bigger/multiple items. The
 *	@storage points to cb->args[5], ie. is preserved over the multiple
 *	dumpit calls.
 * It's recommended to not have the same sub command with both @doit and
 * @dumpit, so that userspace can assume certain ones are get and others
 * are used with dump requests.
J
Johannes Berg 已提交
3426 3427 3428 3429 3430 3431
 */
struct wiphy_vendor_command {
	struct nl80211_vendor_cmd_info info;
	u32 flags;
	int (*doit)(struct wiphy *wiphy, struct wireless_dev *wdev,
		    const void *data, int data_len);
3432 3433 3434
	int (*dumpit)(struct wiphy *wiphy, struct wireless_dev *wdev,
		      struct sk_buff *skb, const void *data, int data_len,
		      unsigned long *storage);
J
Johannes Berg 已提交
3435 3436
};

3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454
/**
 * struct wiphy_iftype_ext_capab - extended capabilities per interface type
 * @iftype: interface type
 * @extended_capabilities: extended capabilities supported by the driver,
 *	additional capabilities might be supported by userspace; these are the
 *	802.11 extended capabilities ("Extended Capabilities element") and are
 *	in the same format as in the information element. See IEEE Std
 *	802.11-2012 8.4.2.29 for the defined fields.
 * @extended_capabilities_mask: mask of the valid values
 * @extended_capabilities_len: length of the extended capabilities
 */
struct wiphy_iftype_ext_capab {
	enum nl80211_iftype iftype;
	const u8 *extended_capabilities;
	const u8 *extended_capabilities_mask;
	u8 extended_capabilities_len;
};

J
Johannes Berg 已提交
3455 3456
/**
 * struct wiphy - wireless hardware description
3457 3458 3459
 * @reg_notifier: the driver's regulatory notification callback,
 *	note that if your driver uses wiphy_apply_custom_regulatory()
 *	the reg_notifier's request can be passed as NULL
J
Johannes Berg 已提交
3460 3461 3462 3463 3464 3465 3466
 * @regd: the driver's regulatory domain, if one was requested via
 * 	the regulatory_hint() API. This can be used by the driver
 *	on the reg_notifier() if it chooses to ignore future
 *	regulatory domain changes caused by other drivers.
 * @signal_type: signal type reported in &struct cfg80211_bss.
 * @cipher_suites: supported cipher suites
 * @n_cipher_suites: number of supported cipher suites
3467 3468 3469 3470 3471
 * @retry_short: Retry limit for short frames (dot11ShortRetryLimit)
 * @retry_long: Retry limit for long frames (dot11LongRetryLimit)
 * @frag_threshold: Fragmentation threshold (dot11FragmentationThreshold);
 *	-1 = fragmentation disabled, only odd values >= 256 used
 * @rts_threshold: RTS threshold (dot11RTSThreshold); -1 = RTS/CTS disabled
J
Johannes Berg 已提交
3472
 * @_net: the network namespace this wiphy currently lives in
3473 3474 3475
 * @perm_addr: permanent MAC address of this device
 * @addr_mask: If the device supports multiple MAC addresses by masking,
 *	set this to a mask with variable bits set to 1, e.g. if the last
3476
 *	four bits are variable then set it to 00-00-00-00-00-0f. The actual
3477 3478 3479 3480 3481 3482 3483 3484
 *	variable bits shall be determined by the interfaces added, with
 *	interfaces not matching the mask being rejected to be brought up.
 * @n_addresses: number of addresses in @addresses.
 * @addresses: If the device has more than one address, set this pointer
 *	to a list of addresses (6 bytes each). The first one will be used
 *	by default for perm_addr. In this case, the mask should be set to
 *	all-zeroes. In this case it is assumed that the device can handle
 *	the same number of arbitrary MAC addresses.
3485 3486
 * @registered: protects ->resume and ->suspend sysfs callbacks against
 *	unregister hardware
J
Johannes Berg 已提交
3487 3488 3489
 * @debugfsdir: debugfs directory used for this wiphy, will be renamed
 *	automatically on wiphy renames
 * @dev: (virtual) struct device for this wiphy
3490
 * @registered: helps synchronize suspend/resume with wiphy unregister
J
Johannes Berg 已提交
3491 3492 3493 3494
 * @wext: wireless extension handlers
 * @priv: driver private data (sized according to wiphy_new() parameter)
 * @interface_modes: bitmask of interfaces types valid for this wiphy,
 *	must be set by driver
3495 3496 3497 3498 3499
 * @iface_combinations: Valid interface combinations array, should not
 *	list single interface types.
 * @n_iface_combinations: number of entries in @iface_combinations array.
 * @software_iftypes: bitmask of software interface types, these are not
 *	subject to any restrictions since they are purely managed in SW.
J
Johannes Berg 已提交
3500
 * @flags: wiphy flags, see &enum wiphy_flags
3501 3502
 * @regulatory_flags: wiphy regulatory flags, see
 *	&enum ieee80211_regulatory_flags
3503
 * @features: features advertised to nl80211, see &enum nl80211_feature_flags.
3504 3505
 * @ext_features: extended features advertised to nl80211, see
 *	&enum nl80211_ext_feature_index.
J
Johannes Berg 已提交
3506 3507 3508 3509
 * @bss_priv_size: each BSS struct has private data allocated with it,
 *	this variable determines its size
 * @max_scan_ssids: maximum number of SSIDs the device can scan for in
 *	any given scan
3510 3511
 * @max_sched_scan_ssids: maximum number of SSIDs the device can scan
 *	for in any given scheduled scan
3512 3513 3514
 * @max_match_sets: maximum number of match sets the device can handle
 *	when performing a scheduled scan, 0 if filtering is not
 *	supported.
J
Johannes Berg 已提交
3515 3516 3517
 * @max_scan_ie_len: maximum length of user-controlled IEs device can
 *	add to probe request frames transmitted during a scan, must not
 *	include fixed IEs like supported rates
3518 3519
 * @max_sched_scan_ie_len: same as max_scan_ie_len, but for scheduled
 *	scans
3520 3521 3522 3523 3524 3525
 * @max_sched_scan_plans: maximum number of scan plans (scan interval and number
 *	of iterations) for scheduled scan supported by the device.
 * @max_sched_scan_plan_interval: maximum interval (in seconds) for a
 *	single scan plan supported by the device.
 * @max_sched_scan_plan_iterations: maximum number of iterations for a single
 *	scan plan supported by the device.
J
Johannes Berg 已提交
3526 3527 3528 3529 3530 3531 3532
 * @coverage_class: current coverage class
 * @fw_version: firmware version for ethtool reporting
 * @hw_version: hardware version for ethtool reporting
 * @max_num_pmkids: maximum number of PMKIDs supported by device
 * @privid: a pointer that drivers can use to identify if an arbitrary
 *	wiphy is theirs, e.g. in global notifiers
 * @bands: information about bands/channels supported by this device
3533 3534 3535 3536
 *
 * @mgmt_stypes: bitmasks of frame subtypes that can be subscribed to or
 *	transmitted through nl80211, points to an array indexed by interface
 *	type
3537
 *
3538 3539 3540 3541 3542 3543 3544
 * @available_antennas_tx: bitmap of antennas which are available to be
 *	configured as TX antennas. Antenna configuration commands will be
 *	rejected unless this or @available_antennas_rx is set.
 *
 * @available_antennas_rx: bitmap of antennas which are available to be
 *	configured as RX antennas. Antenna configuration commands will be
 *	rejected unless this or @available_antennas_tx is set.
3545
 *
3546 3547 3548 3549 3550
 * @probe_resp_offload:
 *	 Bitmap of supported protocols for probe response offloading.
 *	 See &enum nl80211_probe_resp_offload_support_attr. Only valid
 *	 when the wiphy flag @WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD is set.
 *
3551 3552
 * @max_remain_on_channel_duration: Maximum time a remain-on-channel operation
 *	may request, if implemented.
J
Johannes Berg 已提交
3553 3554
 *
 * @wowlan: WoWLAN support information
3555 3556 3557
 * @wowlan_config: current WoWLAN configuration; this should usually not be
 *	used since access to it is necessarily racy, use the parameter passed
 *	to the suspend() operation instead.
J
Johannes Berg 已提交
3558 3559
 *
 * @ap_sme_capa: AP SME capabilities, flags from &enum nl80211_ap_sme_features.
3560 3561
 * @ht_capa_mod_mask:  Specify what ht_cap values can be over-ridden.
 *	If null, then none can be over-ridden.
3562 3563
 * @vht_capa_mod_mask:  Specify what VHT capabilities can be over-ridden.
 *	If null, then none can be over-ridden.
3564
 *
3565 3566 3567
 * @wdev_list: the list of associated (virtual) interfaces; this list must
 *	not be modified by the driver, but can be read with RTNL/RCU protection.
 *
3568 3569
 * @max_acl_mac_addrs: Maximum number of MAC addresses that the device
 *	supports for ACL.
3570 3571 3572 3573 3574
 *
 * @extended_capabilities: extended capabilities supported by the driver,
 *	additional capabilities might be supported by userspace; these are
 *	the 802.11 extended capabilities ("Extended Capabilities element")
 *	and are in the same format as in the information element. See
3575 3576 3577
 *	802.11-2012 8.4.2.29 for the defined fields. These are the default
 *	extended capabilities to be used if the capabilities are not specified
 *	for a specific interface type in iftype_ext_capab.
3578 3579
 * @extended_capabilities_mask: mask of the valid values
 * @extended_capabilities_len: length of the extended capabilities
3580 3581 3582
 * @iftype_ext_capab: array of extended capabilities per interface type
 * @num_iftype_ext_capab: number of interface types for which extended
 *	capabilities are specified separately.
3583
 * @coalesce: packet coalescing support information
J
Johannes Berg 已提交
3584 3585 3586
 *
 * @vendor_commands: array of vendor commands supported by the hardware
 * @n_vendor_commands: number of vendor commands
3587 3588
 * @vendor_events: array of vendor events supported by the hardware
 * @n_vendor_events: number of vendor events
3589 3590 3591 3592 3593
 *
 * @max_ap_assoc_sta: maximum number of associated stations supported in AP mode
 *	(including P2P GO) or 0 to indicate no such limit is advertised. The
 *	driver is allowed to advertise a theoretical limit that it can reach in
 *	some cases, but may not always reach.
3594 3595 3596 3597 3598
 *
 * @max_num_csa_counters: Number of supported csa_counters in beacons
 *	and probe responses.  This value should be set if the driver
 *	wishes to limit the number of csa counters. Default (0) means
 *	infinite.
3599 3600 3601 3602 3603 3604
 * @max_adj_channel_rssi_comp: max offset of between the channel on which the
 *	frame was sent and the channel on which the frame was heard for which
 *	the reported rssi is still valid. If a driver is able to compensate the
 *	low rssi when a frame is heard on different channel, then it should set
 *	this variable to the maximal offset for which it can compensate.
 *	This value should be set in MHz.
3605 3606 3607
 * @bss_select_support: bitmask indicating the BSS selection criteria supported
 *	by the driver in the .connect() callback. The bit position maps to the
 *	attribute indices defined in &enum nl80211_bss_select_attr.
3608 3609
 *
 * @cookie_counter: unique generic cookie counter, used to identify objects.
L
Luca Coelho 已提交
3610 3611 3612 3613
 * @nan_supported_bands: bands supported by the device in NAN mode, a
 *	bitmap of &enum nl80211_band values.  For instance, for
 *	NL80211_BAND_2GHZ, bit 0 would be set
 *	(i.e. BIT(NL80211_BAND_2GHZ)).
J
Johannes Berg 已提交
3614 3615 3616 3617
 */
struct wiphy {
	/* assign these fields before you register the wiphy */

3618
	/* permanent MAC address(es) */
J
Johannes Berg 已提交
3619
	u8 perm_addr[ETH_ALEN];
3620 3621 3622
	u8 addr_mask[ETH_ALEN];

	struct mac_address *addresses;
J
Johannes Berg 已提交
3623

3624 3625
	const struct ieee80211_txrx_stypes *mgmt_stypes;

3626 3627 3628 3629
	const struct ieee80211_iface_combination *iface_combinations;
	int n_iface_combinations;
	u16 software_iftypes;

3630 3631
	u16 n_addresses;

J
Johannes Berg 已提交
3632 3633 3634
	/* Supported interface modes, OR together BIT(NL80211_IFTYPE_...) */
	u16 interface_modes;

3635 3636
	u16 max_acl_mac_addrs;

3637
	u32 flags, regulatory_flags, features;
3638
	u8 ext_features[DIV_ROUND_UP(NUM_NL80211_EXT_FEATURES, 8)];
3639

J
Johannes Berg 已提交
3640 3641
	u32 ap_sme_capa;

J
Johannes Berg 已提交
3642 3643 3644 3645
	enum cfg80211_signal_type signal_type;

	int bss_priv_size;
	u8 max_scan_ssids;
3646
	u8 max_sched_scan_ssids;
3647
	u8 max_match_sets;
J
Johannes Berg 已提交
3648
	u16 max_scan_ie_len;
3649
	u16 max_sched_scan_ie_len;
3650 3651 3652
	u32 max_sched_scan_plans;
	u32 max_sched_scan_plan_interval;
	u32 max_sched_scan_plan_iterations;
J
Johannes Berg 已提交
3653 3654 3655 3656

	int n_cipher_suites;
	const u32 *cipher_suites;

3657 3658 3659 3660
	u8 retry_short;
	u8 retry_long;
	u32 frag_threshold;
	u32 rts_threshold;
3661
	u8 coverage_class;
3662

3663
	char fw_version[ETHTOOL_FWVERS_LEN];
3664 3665
	u32 hw_version;

3666
#ifdef CONFIG_PM
3667
	const struct wiphy_wowlan_support *wowlan;
3668
	struct cfg80211_wowlan *wowlan_config;
3669
#endif
J
Johannes Berg 已提交
3670

3671 3672
	u16 max_remain_on_channel_duration;

S
Samuel Ortiz 已提交
3673 3674
	u8 max_num_pmkids;

3675 3676
	u32 available_antennas_tx;
	u32 available_antennas_rx;
3677

3678 3679 3680 3681 3682 3683 3684
	/*
	 * Bitmap of supported protocols for probe response offloading
	 * see &enum nl80211_probe_resp_offload_support_attr. Only valid
	 * when the wiphy flag @WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD is set.
	 */
	u32 probe_resp_offload;

3685 3686 3687
	const u8 *extended_capabilities, *extended_capabilities_mask;
	u8 extended_capabilities_len;

3688 3689 3690
	const struct wiphy_iftype_ext_capab *iftype_ext_capab;
	unsigned int num_iftype_ext_capab;

J
Johannes Berg 已提交
3691 3692 3693 3694 3695
	/* If multiple wiphys are registered and you're handed e.g.
	 * a regular netdev with assigned ieee80211_ptr, you won't
	 * know whether it points to a wiphy your driver has registered
	 * or not. Assign this to something global to your driver to
	 * help determine whether you own this wiphy or not. */
3696
	const void *privid;
J
Johannes Berg 已提交
3697

3698
	struct ieee80211_supported_band *bands[NUM_NL80211_BANDS];
J
Johannes Berg 已提交
3699 3700

	/* Lets us get back the wiphy on the callback */
3701 3702
	void (*reg_notifier)(struct wiphy *wiphy,
			     struct regulatory_request *request);
J
Johannes Berg 已提交
3703 3704 3705

	/* fields below are read-only, assigned by cfg80211 */

3706
	const struct ieee80211_regdomain __rcu *regd;
J
Johannes Berg 已提交
3707 3708 3709 3710 3711

	/* the item in /sys/class/ieee80211/ points to this,
	 * you need use set_wiphy_dev() (see below) */
	struct device dev;

3712 3713 3714
	/* protects ->resume, ->suspend sysfs callbacks against unregister hw */
	bool registered;

J
Johannes Berg 已提交
3715 3716 3717
	/* dir in debugfs: ieee80211/<wiphyname> */
	struct dentry *debugfsdir;

3718
	const struct ieee80211_ht_cap *ht_capa_mod_mask;
3719
	const struct ieee80211_vht_cap *vht_capa_mod_mask;
3720

3721 3722
	struct list_head wdev_list;

3723
	/* the network namespace this phy lives in currently */
3724
	possible_net_t _net;
3725

J
Johannes Berg 已提交
3726 3727 3728 3729
#ifdef CONFIG_CFG80211_WEXT
	const struct iw_handler_def *wext;
#endif

3730 3731
	const struct wiphy_coalesce_support *coalesce;

J
Johannes Berg 已提交
3732
	const struct wiphy_vendor_command *vendor_commands;
3733 3734
	const struct nl80211_vendor_cmd_info *vendor_events;
	int n_vendor_commands, n_vendor_events;
J
Johannes Berg 已提交
3735

3736 3737
	u16 max_ap_assoc_sta;

3738
	u8 max_num_csa_counters;
3739
	u8 max_adj_channel_rssi_comp;
3740

3741 3742
	u32 bss_select_support;

3743 3744
	u64 cookie_counter;

L
Luca Coelho 已提交
3745 3746
	u8 nan_supported_bands;

J
Johannes Berg 已提交
3747
	char priv[0] __aligned(NETDEV_ALIGN);
J
Johannes Berg 已提交
3748 3749
};

3750 3751
static inline struct net *wiphy_net(struct wiphy *wiphy)
{
E
Eric Dumazet 已提交
3752
	return read_pnet(&wiphy->_net);
3753 3754 3755 3756
}

static inline void wiphy_net_set(struct wiphy *wiphy, struct net *net)
{
E
Eric Dumazet 已提交
3757
	write_pnet(&wiphy->_net, net);
3758 3759
}

J
Johannes Berg 已提交
3760 3761 3762 3763
/**
 * wiphy_priv - return priv from wiphy
 *
 * @wiphy: the wiphy whose priv pointer to return
3764
 * Return: The priv of @wiphy.
J
Johannes Berg 已提交
3765 3766 3767 3768 3769 3770 3771
 */
static inline void *wiphy_priv(struct wiphy *wiphy)
{
	BUG_ON(!wiphy);
	return &wiphy->priv;
}

3772 3773 3774 3775
/**
 * priv_to_wiphy - return the wiphy containing the priv
 *
 * @priv: a pointer previously returned by wiphy_priv
3776
 * Return: The wiphy of @priv.
3777 3778 3779 3780 3781 3782 3783
 */
static inline struct wiphy *priv_to_wiphy(void *priv)
{
	BUG_ON(!priv);
	return container_of(priv, struct wiphy, priv);
}

J
Johannes Berg 已提交
3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798
/**
 * set_wiphy_dev - set device pointer for wiphy
 *
 * @wiphy: The wiphy whose device to bind
 * @dev: The device to parent it to
 */
static inline void set_wiphy_dev(struct wiphy *wiphy, struct device *dev)
{
	wiphy->dev.parent = dev;
}

/**
 * wiphy_dev - get wiphy dev pointer
 *
 * @wiphy: The wiphy whose device struct to look up
3799
 * Return: The dev of @wiphy.
J
Johannes Berg 已提交
3800 3801 3802 3803 3804 3805 3806 3807 3808 3809
 */
static inline struct device *wiphy_dev(struct wiphy *wiphy)
{
	return wiphy->dev.parent;
}

/**
 * wiphy_name - get wiphy name
 *
 * @wiphy: The wiphy whose name to return
3810
 * Return: The name of @wiphy.
J
Johannes Berg 已提交
3811
 */
3812
static inline const char *wiphy_name(const struct wiphy *wiphy)
J
Johannes Berg 已提交
3813 3814 3815 3816
{
	return dev_name(&wiphy->dev);
}

3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833
/**
 * wiphy_new_nm - create a new wiphy for use with cfg80211
 *
 * @ops: The configuration operations for this device
 * @sizeof_priv: The size of the private area to allocate
 * @requested_name: Request a particular name.
 *	NULL is valid value, and means use the default phy%d naming.
 *
 * Create a new wiphy and associate the given operations with it.
 * @sizeof_priv bytes are allocated for private use.
 *
 * Return: A pointer to the new wiphy. This pointer must be
 * assigned to each netdev's ieee80211_ptr for proper operation.
 */
struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv,
			   const char *requested_name);

J
Johannes Berg 已提交
3834 3835 3836 3837 3838 3839 3840 3841 3842
/**
 * wiphy_new - create a new wiphy for use with cfg80211
 *
 * @ops: The configuration operations for this device
 * @sizeof_priv: The size of the private area to allocate
 *
 * Create a new wiphy and associate the given operations with it.
 * @sizeof_priv bytes are allocated for private use.
 *
3843 3844
 * Return: A pointer to the new wiphy. This pointer must be
 * assigned to each netdev's ieee80211_ptr for proper operation.
J
Johannes Berg 已提交
3845
 */
3846 3847 3848 3849 3850
static inline struct wiphy *wiphy_new(const struct cfg80211_ops *ops,
				      int sizeof_priv)
{
	return wiphy_new_nm(ops, sizeof_priv, NULL);
}
J
Johannes Berg 已提交
3851 3852 3853 3854 3855 3856

/**
 * wiphy_register - register a wiphy with cfg80211
 *
 * @wiphy: The wiphy to register.
 *
3857
 * Return: A non-negative wiphy index or a negative error code.
J
Johannes Berg 已提交
3858
 */
3859
int wiphy_register(struct wiphy *wiphy);
J
Johannes Berg 已提交
3860 3861 3862 3863 3864 3865 3866 3867 3868 3869

/**
 * wiphy_unregister - deregister a wiphy from cfg80211
 *
 * @wiphy: The wiphy to unregister.
 *
 * After this call, no more requests can be made with this priv
 * pointer, but the call may sleep to wait for an outstanding
 * request that is being handled.
 */
3870
void wiphy_unregister(struct wiphy *wiphy);
J
Johannes Berg 已提交
3871 3872 3873 3874 3875 3876

/**
 * wiphy_free - free wiphy
 *
 * @wiphy: The wiphy to free
 */
3877
void wiphy_free(struct wiphy *wiphy);
J
Johannes Berg 已提交
3878

J
Johannes Berg 已提交
3879
/* internal structs */
3880
struct cfg80211_conn;
J
Johannes Berg 已提交
3881
struct cfg80211_internal_bss;
J
Johannes Berg 已提交
3882
struct cfg80211_cached_keys;
3883
struct cfg80211_cqm_config;
J
Johannes Berg 已提交
3884

J
Johannes Berg 已提交
3885
/**
3886
 * struct wireless_dev - wireless device state
J
Johannes Berg 已提交
3887
 *
3888 3889 3890 3891 3892 3893 3894 3895 3896 3897
 * For netdevs, this structure must be allocated by the driver
 * that uses the ieee80211_ptr field in struct net_device (this
 * is intentional so it can be allocated along with the netdev.)
 * It need not be registered then as netdev registration will
 * be intercepted by cfg80211 to see the new wireless device.
 *
 * For non-netdev uses, it must also be allocated by the driver
 * in response to the cfg80211 callbacks that require it, as
 * there's no netdev registration in that case it may not be
 * allocated outside of callback operations that return it.
J
Johannes Berg 已提交
3898 3899 3900 3901
 *
 * @wiphy: pointer to hardware description
 * @iftype: interface type
 * @list: (private) Used to collect the interfaces
3902 3903 3904
 * @netdev: (private) Used to reference back to the netdev, may be %NULL
 * @identifier: (private) Identifier used in nl80211 to identify this
 *	wireless device if it has no netdev
J
Johannes Berg 已提交
3905
 * @current_bss: (private) Used by the internal configuration code
3906 3907
 * @chandef: (private) Used by the internal configuration code to track
 *	the user-set channel definition.
J
Johannes Berg 已提交
3908
 * @preset_chandef: (private) Used by the internal configuration code to
3909
 *	track the channel to be used for AP later
J
Johannes Berg 已提交
3910 3911 3912
 * @bssid: (private) Used by the internal configuration code
 * @ssid: (private) Used by the internal configuration code
 * @ssid_len: (private) Used by the internal configuration code
3913 3914
 * @mesh_id_len: (private) Used by the internal configuration code
 * @mesh_id_up_len: (private) Used by the internal configuration code
J
Johannes Berg 已提交
3915
 * @wext: (private) Used by the internal wireless extensions compat code
3916 3917 3918 3919
 * @use_4addr: indicates 4addr mode is used on this interface, must be
 *	set by driver (if supported) on add_interface BEFORE registering the
 *	netdev and may otherwise be used by driver read-only, will be update
 *	by cfg80211 on change_interface
3920 3921
 * @mgmt_registrations: list of registrations for management frames
 * @mgmt_registrations_lock: lock for the list
3922 3923
 * @mtx: mutex used to lock data in this struct, may be used by drivers
 *	and some API functions require it held
3924 3925
 * @beacon_interval: beacon interval used on this device for transmitting
 *	beacons, 0 when not valid
3926
 * @address: The address for this device, valid only if @netdev is %NULL
3927 3928
 * @is_running: true if this is a non-netdev device that has been started, e.g.
 *	the P2P Device.
3929 3930
 * @cac_started: true if DFS channel availability check has been started
 * @cac_start_time: timestamp (jiffies) when the dfs state was entered.
3931
 * @cac_time_ms: CAC time in ms
J
Johannes Berg 已提交
3932 3933 3934 3935 3936 3937
 * @ps: powersave mode is enabled
 * @ps_timeout: dynamic powersave timeout
 * @ap_unexpected_nlportid: (private) netlink port ID of application
 *	registered for unexpected class 3 frames (AP mode)
 * @conn: (private) cfg80211 software SME connection state machine data
 * @connect_keys: (private) keys to set after connection is established
3938
 * @conn_bss_type: connecting/connected BSS type
3939 3940 3941
 * @conn_owner_nlportid: (private) connection owner socket port ID
 * @disconnect_wk: (private) auto-disconnect work
 * @disconnect_bssid: (private) the BSSID to use for auto-disconnect
J
Johannes Berg 已提交
3942
 * @ibss_fixed: (private) IBSS is using fixed BSSID
3943
 * @ibss_dfs_possible: (private) IBSS may change to a DFS channel
J
Johannes Berg 已提交
3944 3945
 * @event_list: (private) list for internal event processing
 * @event_lock: (private) lock for event list
3946
 * @owner_nlportid: (private) owner socket port ID
3947
 * @cqm_config: (private) nl80211 RSSI monitor state
J
Johannes Berg 已提交
3948 3949 3950 3951 3952
 */
struct wireless_dev {
	struct wiphy *wiphy;
	enum nl80211_iftype iftype;

J
Johannes Berg 已提交
3953
	/* the remainder of this struct should be private to cfg80211 */
J
Johannes Berg 已提交
3954 3955 3956
	struct list_head list;
	struct net_device *netdev;

3957 3958
	u32 identifier;

3959 3960
	struct list_head mgmt_registrations;
	spinlock_t mgmt_registrations_lock;
3961

J
Johannes Berg 已提交
3962 3963
	struct mutex mtx;

3964
	bool use_4addr, is_running;
3965 3966

	u8 address[ETH_ALEN] __aligned(sizeof(u16));
3967

S
Samuel Ortiz 已提交
3968
	/* currently used for IBSS and SME - might be rearranged later */
J
Johannes Berg 已提交
3969
	u8 ssid[IEEE80211_MAX_SSID_LEN];
3970
	u8 ssid_len, mesh_id_len, mesh_id_up_len;
3971
	struct cfg80211_conn *conn;
J
Johannes Berg 已提交
3972
	struct cfg80211_cached_keys *connect_keys;
3973
	enum ieee80211_bss_type conn_bss_type;
3974 3975 3976 3977
	u32 conn_owner_nlportid;

	struct work_struct disconnect_wk;
	u8 disconnect_bssid[ETH_ALEN];
J
Johannes Berg 已提交
3978

J
Johannes Berg 已提交
3979 3980 3981
	struct list_head event_list;
	spinlock_t event_lock;

J
Johannes Berg 已提交
3982
	struct cfg80211_internal_bss *current_bss; /* associated / joined */
3983
	struct cfg80211_chan_def preset_chandef;
3984
	struct cfg80211_chan_def chandef;
3985

3986
	bool ibss_fixed;
3987
	bool ibss_dfs_possible;
3988

K
Kalle Valo 已提交
3989 3990 3991
	bool ps;
	int ps_timeout;

3992 3993
	int beacon_interval;

3994
	u32 ap_unexpected_nlportid;
3995

3996 3997
	bool cac_started;
	unsigned long cac_start_time;
3998
	unsigned int cac_time_ms;
3999

4000 4001
	u32 owner_nlportid;

J
Johannes Berg 已提交
4002
#ifdef CONFIG_CFG80211_WEXT
J
Johannes Berg 已提交
4003
	/* wext data */
4004
	struct {
4005 4006
		struct cfg80211_ibss_params ibss;
		struct cfg80211_connect_params connect;
J
Johannes Berg 已提交
4007
		struct cfg80211_cached_keys *keys;
4008
		const u8 *ie;
4009
		size_t ie_len;
4010
		u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
4011
		u8 ssid[IEEE80211_MAX_SSID_LEN];
4012
		s8 default_key, default_mgmt_key;
K
Kalle Valo 已提交
4013
		bool prev_bssid_valid;
4014
	} wext;
J
Johannes Berg 已提交
4015
#endif
4016 4017

	struct cfg80211_cqm_config *cqm_config;
J
Johannes Berg 已提交
4018 4019
};

4020 4021 4022 4023 4024 4025 4026
static inline u8 *wdev_address(struct wireless_dev *wdev)
{
	if (wdev->netdev)
		return wdev->netdev->dev_addr;
	return wdev->address;
}

4027 4028 4029 4030 4031 4032 4033
static inline bool wdev_running(struct wireless_dev *wdev)
{
	if (wdev->netdev)
		return netif_running(wdev->netdev);
	return wdev->is_running;
}

J
Johannes Berg 已提交
4034 4035 4036 4037
/**
 * wdev_priv - return wiphy priv from wireless_dev
 *
 * @wdev: The wireless device whose wiphy's priv pointer to return
4038
 * Return: The wiphy priv of @wdev.
J
Johannes Berg 已提交
4039 4040 4041 4042 4043 4044 4045
 */
static inline void *wdev_priv(struct wireless_dev *wdev)
{
	BUG_ON(!wdev);
	return wiphy_priv(wdev->wiphy);
}

J
Johannes Berg 已提交
4046 4047 4048 4049
/**
 * DOC: Utility functions
 *
 * cfg80211 offers a number of utility functions that can be useful.
J
Johannes Berg 已提交
4050 4051 4052 4053
 */

/**
 * ieee80211_channel_to_frequency - convert channel number to frequency
J
Johannes Berg 已提交
4054
 * @chan: channel number
4055
 * @band: band, necessary due to channel number overlap
4056
 * Return: The corresponding frequency (in MHz), or 0 if the conversion failed.
J
Johannes Berg 已提交
4057
 */
4058
int ieee80211_channel_to_frequency(int chan, enum nl80211_band band);
J
Johannes Berg 已提交
4059 4060 4061

/**
 * ieee80211_frequency_to_channel - convert frequency to channel number
J
Johannes Berg 已提交
4062
 * @freq: center frequency
4063
 * Return: The corresponding channel, or 0 if the conversion failed.
J
Johannes Berg 已提交
4064
 */
4065
int ieee80211_frequency_to_channel(int freq);
J
Johannes Berg 已提交
4066 4067 4068

/**
 * ieee80211_get_channel - get channel struct from wiphy for specified frequency
4069
 *
J
Johannes Berg 已提交
4070 4071
 * @wiphy: the struct wiphy to get the channel for
 * @freq: the center frequency of the channel
4072
 *
4073
 * Return: The channel struct from @wiphy at @freq.
J
Johannes Berg 已提交
4074
 */
4075
struct ieee80211_channel *ieee80211_get_channel(struct wiphy *wiphy, int freq);
J
Johannes Berg 已提交
4076 4077 4078 4079 4080 4081 4082 4083

/**
 * ieee80211_get_response_rate - get basic rate for a given rate
 *
 * @sband: the band to look for rates in
 * @basic_rates: bitmap of basic rates
 * @bitrate: the bitrate for which to find the basic rate
 *
4084 4085 4086 4087
 * Return: The basic rate corresponding to a given bitrate, that
 * is the next lower bitrate contained in the basic rate map,
 * which is, for this function, given as a bitmap of indices of
 * rates in the band's bitrate table.
J
Johannes Berg 已提交
4088 4089 4090 4091 4092
 */
struct ieee80211_rate *
ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
			    u32 basic_rates, int bitrate);

4093 4094 4095
/**
 * ieee80211_mandatory_rates - get mandatory rates for a given band
 * @sband: the band to look for rates in
4096
 * @scan_width: width of the control channel
4097 4098 4099 4100
 *
 * This function returns a bitmap of the mandatory rates for the given
 * band, bits are set according to the rate position in the bitrates array.
 */
4101 4102
u32 ieee80211_mandatory_rates(struct ieee80211_supported_band *sband,
			      enum nl80211_bss_scan_width scan_width);
4103

J
Johannes Berg 已提交
4104 4105 4106 4107 4108 4109 4110
/*
 * Radiotap parsing functions -- for controlled injection support
 *
 * Implemented in net/wireless/radiotap.c
 * Documentation in Documentation/networking/radiotap-headers.txt
 */

J
Johannes Berg 已提交
4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126
struct radiotap_align_size {
	uint8_t align:4, size:4;
};

struct ieee80211_radiotap_namespace {
	const struct radiotap_align_size *align_size;
	int n_bits;
	uint32_t oui;
	uint8_t subns;
};

struct ieee80211_radiotap_vendor_namespaces {
	const struct ieee80211_radiotap_namespace *ns;
	int n_ns;
};

J
Johannes Berg 已提交
4127 4128
/**
 * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args
J
Johannes Berg 已提交
4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153
 * @this_arg_index: index of current arg, valid after each successful call
 *	to ieee80211_radiotap_iterator_next()
 * @this_arg: pointer to current radiotap arg; it is valid after each
 *	call to ieee80211_radiotap_iterator_next() but also after
 *	ieee80211_radiotap_iterator_init() where it will point to
 *	the beginning of the actual data portion
 * @this_arg_size: length of the current arg, for convenience
 * @current_namespace: pointer to the current namespace definition
 *	(or internally %NULL if the current namespace is unknown)
 * @is_radiotap_ns: indicates whether the current namespace is the default
 *	radiotap namespace or not
 *
 * @_rtheader: pointer to the radiotap header we are walking through
 * @_max_length: length of radiotap header in cpu byte ordering
 * @_arg_index: next argument index
 * @_arg: next argument pointer
 * @_next_bitmap: internal pointer to next present u32
 * @_bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present
 * @_vns: vendor namespace definitions
 * @_next_ns_data: beginning of the next namespace's data
 * @_reset_on_ext: internal; reset the arg index to 0 when going to the
 *	next bitmap word
 *
 * Describes the radiotap parser state. Fields prefixed with an underscore
 * must not be used by users of the parser, only by the parser internally.
J
Johannes Berg 已提交
4154 4155 4156
 */

struct ieee80211_radiotap_iterator {
J
Johannes Berg 已提交
4157 4158 4159 4160 4161
	struct ieee80211_radiotap_header *_rtheader;
	const struct ieee80211_radiotap_vendor_namespaces *_vns;
	const struct ieee80211_radiotap_namespace *current_namespace;

	unsigned char *_arg, *_next_ns_data;
4162
	__le32 *_next_bitmap;
J
Johannes Berg 已提交
4163 4164

	unsigned char *this_arg;
J
Johannes Berg 已提交
4165
	int this_arg_index;
J
Johannes Berg 已提交
4166
	int this_arg_size;
J
Johannes Berg 已提交
4167

J
Johannes Berg 已提交
4168 4169 4170 4171 4172 4173
	int is_radiotap_ns;

	int _max_length;
	int _arg_index;
	uint32_t _bitmap_shifter;
	int _reset_on_ext;
J
Johannes Berg 已提交
4174 4175
};

4176 4177 4178 4179 4180
int
ieee80211_radiotap_iterator_init(struct ieee80211_radiotap_iterator *iterator,
				 struct ieee80211_radiotap_header *radiotap_header,
				 int max_length,
				 const struct ieee80211_radiotap_vendor_namespaces *vns);
J
Johannes Berg 已提交
4181

4182 4183
int
ieee80211_radiotap_iterator_next(struct ieee80211_radiotap_iterator *iterator);
J
Johannes Berg 已提交
4184

J
Johannes Berg 已提交
4185

4186 4187 4188 4189 4190 4191
extern const unsigned char rfc1042_header[6];
extern const unsigned char bridge_tunnel_header[6];

/**
 * ieee80211_get_hdrlen_from_skb - get header length from data
 *
4192 4193
 * @skb: the frame
 *
4194
 * Given an skb with a raw 802.11 header at the data pointer this function
4195
 * returns the 802.11 header length.
4196
 *
4197 4198 4199
 * Return: The 802.11 header length in bytes (not including encryption
 * headers). Or 0 if the data in the sk_buff is too short to contain a valid
 * 802.11 header.
4200 4201 4202 4203 4204 4205
 */
unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb);

/**
 * ieee80211_hdrlen - get header length in bytes from frame control
 * @fc: frame control field in little-endian format
4206
 * Return: The header length in bytes.
4207
 */
4208
unsigned int __attribute_const__ ieee80211_hdrlen(__le16 fc);
4209

4210 4211 4212 4213
/**
 * ieee80211_get_mesh_hdrlen - get mesh extension header length
 * @meshhdr: the mesh extension header, only the flags field
 *	(first byte) will be accessed
4214
 * Return: The length of the extension header, which is always at
4215 4216 4217 4218
 * least 6 bytes and at most 18 if address 5 and 6 are present.
 */
unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr);

J
Johannes Berg 已提交
4219 4220 4221 4222 4223 4224 4225 4226
/**
 * DOC: Data path helpers
 *
 * In addition to generic utilities, cfg80211 also offers
 * functions that help implement the data path for devices
 * that do not do the 802.11/802.3 conversion on the device.
 */

4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238
/**
 * ieee80211_data_to_8023_exthdr - convert an 802.11 data frame to 802.3
 * @skb: the 802.11 data frame
 * @ehdr: pointer to a &struct ethhdr that will get the header, instead
 *	of it being pushed into the SKB
 * @addr: the device MAC address
 * @iftype: the virtual interface type
 * Return: 0 on success. Non-zero on error.
 */
int ieee80211_data_to_8023_exthdr(struct sk_buff *skb, struct ethhdr *ehdr,
				  const u8 *addr, enum nl80211_iftype iftype);

4239 4240 4241 4242 4243
/**
 * ieee80211_data_to_8023 - convert an 802.11 data frame to 802.3
 * @skb: the 802.11 data frame
 * @addr: the device MAC address
 * @iftype: the virtual interface type
4244
 * Return: 0 on success. Non-zero on error.
4245
 */
4246 4247 4248 4249 4250
static inline int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
					 enum nl80211_iftype iftype)
{
	return ieee80211_data_to_8023_exthdr(skb, NULL, addr, iftype);
}
4251 4252 4253 4254 4255 4256 4257 4258

/**
 * ieee80211_data_from_8023 - convert an 802.3 frame to 802.11
 * @skb: the 802.3 frame
 * @addr: the device MAC address
 * @iftype: the virtual interface type
 * @bssid: the network bssid (used only for iftype STATION and ADHOC)
 * @qos: build 802.11 QoS data frame
4259
 * Return: 0 on success, or a negative error code.
4260
 */
Z
Zhu Yi 已提交
4261
int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr,
4262 4263
			     enum nl80211_iftype iftype, const u8 *bssid,
			     bool qos);
4264

Z
Zhu Yi 已提交
4265 4266 4267
/**
 * ieee80211_amsdu_to_8023s - decode an IEEE 802.11n A-MSDU frame
 *
4268 4269 4270
 * Decode an IEEE 802.11 A-MSDU and convert it to a list of 802.3 frames.
 * The @list will be empty if the decode fails. The @skb must be fully
 * header-less before being passed in here; it is freed in this function.
Z
Zhu Yi 已提交
4271
 *
4272
 * @skb: The input A-MSDU frame without any headers.
Z
Zhu Yi 已提交
4273 4274 4275 4276 4277
 * @list: The output list of 802.3 frames. It must be allocated and
 *	initialized by by the caller.
 * @addr: The device MAC address.
 * @iftype: The device interface type.
 * @extra_headroom: The hardware extra headroom for SKBs in the @list.
4278 4279
 * @check_da: DA to check in the inner ethernet header, or NULL
 * @check_sa: SA to check in the inner ethernet header, or NULL
Z
Zhu Yi 已提交
4280 4281 4282
 */
void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
			      const u8 *addr, enum nl80211_iftype iftype,
4283
			      const unsigned int extra_headroom,
4284
			      const u8 *check_da, const u8 *check_sa);
Z
Zhu Yi 已提交
4285

4286 4287 4288
/**
 * cfg80211_classify8021d - determine the 802.1p/1d tag for a data frame
 * @skb: the data frame
4289
 * @qos_map: Interworking QoS mapping or %NULL if not in use
4290
 * Return: The 802.1p/1d tag.
4291
 */
4292 4293
unsigned int cfg80211_classify8021d(struct sk_buff *skb,
				    struct cfg80211_qos_map *qos_map);
4294

4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322
/**
 * cfg80211_find_ie_match - match information element and byte array in data
 *
 * @eid: element ID
 * @ies: data consisting of IEs
 * @len: length of data
 * @match: byte array to match
 * @match_len: number of bytes in the match array
 * @match_offset: offset in the IE where the byte array should match.
 *	If match_len is zero, this must also be set to zero.
 *	Otherwise this must be set to 2 or more, because the first
 *	byte is the element id, which is already compared to eid, and
 *	the second byte is the IE length.
 *
 * Return: %NULL if the element ID could not be found or if
 * the element is invalid (claims to be longer than the given
 * data) or if the byte array doesn't match, or a pointer to the first
 * byte of the requested element, that is the byte containing the
 * element ID.
 *
 * Note: There are no checks on the element length other than
 * having to fit into the given data and being large enough for the
 * byte array to match.
 */
const u8 *cfg80211_find_ie_match(u8 eid, const u8 *ies, int len,
				 const u8 *match, int match_len,
				 int match_offset);

4323 4324 4325 4326 4327 4328 4329
/**
 * cfg80211_find_ie - find information element in data
 *
 * @eid: element ID
 * @ies: data consisting of IEs
 * @len: length of data
 *
4330 4331 4332 4333 4334 4335 4336
 * Return: %NULL if the element ID could not be found or if
 * the element is invalid (claims to be longer than the given
 * data), or a pointer to the first byte of the requested
 * element, that is the byte containing the element ID.
 *
 * Note: There are no checks on the element length other than
 * having to fit into the given data.
4337
 */
4338 4339 4340 4341
static inline const u8 *cfg80211_find_ie(u8 eid, const u8 *ies, int len)
{
	return cfg80211_find_ie_match(eid, ies, len, NULL, 0, 0);
}
4342

4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363
/**
 * cfg80211_find_ext_ie - find information element with EID Extension in data
 *
 * @ext_eid: element ID Extension
 * @ies: data consisting of IEs
 * @len: length of data
 *
 * Return: %NULL if the extended element ID could not be found or if
 * the element is invalid (claims to be longer than the given
 * data), or a pointer to the first byte of the requested
 * element, that is the byte containing the element ID.
 *
 * Note: There are no checks on the element length other than
 * having to fit into the given data.
 */
static inline const u8 *cfg80211_find_ext_ie(u8 ext_eid, const u8 *ies, int len)
{
	return cfg80211_find_ie_match(WLAN_EID_EXTENSION, ies, len,
				      &ext_eid, 1, 2);
}

4364 4365 4366 4367
/**
 * cfg80211_find_vendor_ie - find vendor specific information element in data
 *
 * @oui: vendor OUI
4368
 * @oui_type: vendor-specific OUI type (must be < 0xff), negative means any
4369 4370 4371
 * @ies: data consisting of IEs
 * @len: length of data
 *
4372 4373 4374 4375 4376 4377 4378
 * Return: %NULL if the vendor specific element ID could not be found or if the
 * element is invalid (claims to be longer than the given data), or a pointer to
 * the first byte of the requested element, that is the byte containing the
 * element ID.
 *
 * Note: There are no checks on the element length other than having to fit into
 * the given data.
4379
 */
4380
const u8 *cfg80211_find_vendor_ie(unsigned int oui, int oui_type,
4381 4382
				  const u8 *ies, int len);

J
Johannes Berg 已提交
4383 4384 4385 4386
/**
 * DOC: Regulatory enforcement infrastructure
 *
 * TODO
J
Johannes Berg 已提交
4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410
 */

/**
 * regulatory_hint - driver hint to the wireless core a regulatory domain
 * @wiphy: the wireless device giving the hint (used only for reporting
 *	conflicts)
 * @alpha2: the ISO/IEC 3166 alpha2 the driver claims its regulatory domain
 * 	should be in. If @rd is set this should be NULL. Note that if you
 * 	set this to NULL you should still set rd->alpha2 to some accepted
 * 	alpha2.
 *
 * Wireless drivers can use this function to hint to the wireless core
 * what it believes should be the current regulatory domain by
 * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory
 * domain should be in or by providing a completely build regulatory domain.
 * If the driver provides an ISO/IEC 3166 alpha2 userspace will be queried
 * for a regulatory domain structure for the respective country.
 *
 * The wiphy must have been registered to cfg80211 prior to this call.
 * For cfg80211 drivers this means you must first use wiphy_register(),
 * for mac80211 drivers you must first use ieee80211_register_hw().
 *
 * Drivers should check the return value, its possible you can get
 * an -ENOMEM.
4411 4412
 *
 * Return: 0 on success. -ENOMEM.
J
Johannes Berg 已提交
4413
 */
4414
int regulatory_hint(struct wiphy *wiphy, const char *alpha2);
J
Johannes Berg 已提交
4415

4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429
/**
 * regulatory_set_wiphy_regd - set regdom info for self managed drivers
 * @wiphy: the wireless device we want to process the regulatory domain on
 * @rd: the regulatory domain informatoin to use for this wiphy
 *
 * Set the regulatory domain information for self-managed wiphys, only they
 * may use this function. See %REGULATORY_WIPHY_SELF_MANAGED for more
 * information.
 *
 * Return: 0 on success. -EINVAL, -EPERM
 */
int regulatory_set_wiphy_regd(struct wiphy *wiphy,
			      struct ieee80211_regdomain *rd);

4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443
/**
 * regulatory_set_wiphy_regd_sync_rtnl - set regdom for self-managed drivers
 * @wiphy: the wireless device we want to process the regulatory domain on
 * @rd: the regulatory domain information to use for this wiphy
 *
 * This functions requires the RTNL to be held and applies the new regdomain
 * synchronously to this wiphy. For more details see
 * regulatory_set_wiphy_regd().
 *
 * Return: 0 on success. -EINVAL, -EPERM
 */
int regulatory_set_wiphy_regd_sync_rtnl(struct wiphy *wiphy,
					struct ieee80211_regdomain *rd);

J
Johannes Berg 已提交
4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454
/**
 * wiphy_apply_custom_regulatory - apply a custom driver regulatory domain
 * @wiphy: the wireless device we want to process the regulatory domain on
 * @regd: the custom regulatory domain to use for this wiphy
 *
 * Drivers can sometimes have custom regulatory domains which do not apply
 * to a specific country. Drivers can use this to apply such custom regulatory
 * domains. This routine must be called prior to wiphy registration. The
 * custom regulatory domain will be trusted completely and as such previous
 * default channel settings will be disregarded. If no rule is found for a
 * channel on the regulatory domain the channel will be disabled.
4455
 * Drivers using this for a wiphy should also set the wiphy flag
4456
 * REGULATORY_CUSTOM_REG or cfg80211 will set it for the wiphy
4457
 * that called this helper.
J
Johannes Berg 已提交
4458
 */
4459 4460
void wiphy_apply_custom_regulatory(struct wiphy *wiphy,
				   const struct ieee80211_regdomain *regd);
J
Johannes Berg 已提交
4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471

/**
 * freq_reg_info - get regulatory information for the given frequency
 * @wiphy: the wiphy for which we want to process this rule for
 * @center_freq: Frequency in KHz for which we want regulatory information for
 *
 * Use this function to get the regulatory rule for a specific frequency on
 * a given wireless device. If the device has a specific regulatory domain
 * it wants to follow we respect that unless a country IE has been received
 * and processed already.
 *
4472 4473 4474 4475 4476 4477 4478
 * Return: A valid pointer, or, when an error occurs, for example if no rule
 * can be found, the return value is encoded using ERR_PTR(). Use IS_ERR() to
 * check and PTR_ERR() to obtain the numeric return value. The numeric return
 * value will be -ERANGE if we determine the given center_freq does not even
 * have a regulatory rule for a frequency range in the center_freq's band.
 * See freq_in_rule_band() for our current definition of a band -- this is
 * purely subjective and right now it's 802.11 specific.
J
Johannes Berg 已提交
4479
 */
4480 4481
const struct ieee80211_reg_rule *freq_reg_info(struct wiphy *wiphy,
					       u32 center_freq);
J
Johannes Berg 已提交
4482

4483 4484 4485 4486 4487 4488 4489 4490 4491
/**
 * reg_initiator_name - map regulatory request initiator enum to name
 * @initiator: the regulatory request initiator
 *
 * You can use this to map the regulatory request initiator enum to a
 * proper string representation.
 */
const char *reg_initiator_name(enum nl80211_reg_initiator initiator);

J
Johannes Berg 已提交
4492 4493 4494 4495 4496
/*
 * callbacks for asynchronous cfg80211 methods, notification
 * functions and BSS handling helpers
 */

4497 4498 4499 4500
/**
 * cfg80211_scan_done - notify that scan finished
 *
 * @request: the corresponding scan request
4501
 * @info: information about the completed scan
4502
 */
4503 4504
void cfg80211_scan_done(struct cfg80211_scan_request *request,
			struct cfg80211_scan_info *info);
4505

4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523
/**
 * cfg80211_sched_scan_results - notify that new scan results are available
 *
 * @wiphy: the wiphy which got scheduled scan results
 */
void cfg80211_sched_scan_results(struct wiphy *wiphy);

/**
 * cfg80211_sched_scan_stopped - notify that the scheduled scan has stopped
 *
 * @wiphy: the wiphy on which the scheduled scan stopped
 *
 * The driver can call this function to inform cfg80211 that the
 * scheduled scan had to be stopped, for whatever reason.  The driver
 * is then called back via the sched_scan_stop operation when done.
 */
void cfg80211_sched_scan_stopped(struct wiphy *wiphy);

4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534
/**
 * cfg80211_sched_scan_stopped_rtnl - notify that the scheduled scan has stopped
 *
 * @wiphy: the wiphy on which the scheduled scan stopped
 *
 * The driver can call this function to inform cfg80211 that the
 * scheduled scan had to be stopped, for whatever reason.  The driver
 * is then called back via the sched_scan_stop operation when done.
 * This function should be called with rtnl locked.
 */
void cfg80211_sched_scan_stopped_rtnl(struct wiphy *wiphy);
4535

4536
/**
4537
 * cfg80211_inform_bss_frame_data - inform cfg80211 of a received BSS frame
4538
 * @wiphy: the wiphy reporting the BSS
4539
 * @data: the BSS metadata
J
Johannes Berg 已提交
4540 4541
 * @mgmt: the management frame (probe response or beacon)
 * @len: length of the management frame
4542 4543 4544 4545
 * @gfp: context flags
 *
 * This informs cfg80211 that BSS information was found and
 * the BSS should be updated/added.
4546
 *
4547 4548
 * Return: A referenced struct, must be released with cfg80211_put_bss()!
 * Or %NULL on error.
4549
 */
4550
struct cfg80211_bss * __must_check
4551 4552 4553 4554 4555 4556
cfg80211_inform_bss_frame_data(struct wiphy *wiphy,
			       struct cfg80211_inform_bss *data,
			       struct ieee80211_mgmt *mgmt, size_t len,
			       gfp_t gfp);

static inline struct cfg80211_bss * __must_check
4557
cfg80211_inform_bss_width_frame(struct wiphy *wiphy,
4558
				struct ieee80211_channel *rx_channel,
4559 4560
				enum nl80211_bss_scan_width scan_width,
				struct ieee80211_mgmt *mgmt, size_t len,
4561 4562 4563 4564 4565 4566 4567 4568 4569 4570
				s32 signal, gfp_t gfp)
{
	struct cfg80211_inform_bss data = {
		.chan = rx_channel,
		.scan_width = scan_width,
		.signal = signal,
	};

	return cfg80211_inform_bss_frame_data(wiphy, &data, mgmt, len, gfp);
}
4571 4572

static inline struct cfg80211_bss * __must_check
4573
cfg80211_inform_bss_frame(struct wiphy *wiphy,
4574
			  struct ieee80211_channel *rx_channel,
4575
			  struct ieee80211_mgmt *mgmt, size_t len,
4576 4577
			  s32 signal, gfp_t gfp)
{
4578 4579 4580 4581 4582 4583 4584
	struct cfg80211_inform_bss data = {
		.chan = rx_channel,
		.scan_width = NL80211_BSS_CHAN_WIDTH_20,
		.signal = signal,
	};

	return cfg80211_inform_bss_frame_data(wiphy, &data, mgmt, len, gfp);
4585
}
4586

J
Johannes Berg 已提交
4587
/**
4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600
 * enum cfg80211_bss_frame_type - frame type that the BSS data came from
 * @CFG80211_BSS_FTYPE_UNKNOWN: driver doesn't know whether the data is
 *	from a beacon or probe response
 * @CFG80211_BSS_FTYPE_BEACON: data comes from a beacon
 * @CFG80211_BSS_FTYPE_PRESP: data comes from a probe response
 */
enum cfg80211_bss_frame_type {
	CFG80211_BSS_FTYPE_UNKNOWN,
	CFG80211_BSS_FTYPE_BEACON,
	CFG80211_BSS_FTYPE_PRESP,
};

/**
4601
 * cfg80211_inform_bss_data - inform cfg80211 of a new BSS
J
Johannes Berg 已提交
4602 4603
 *
 * @wiphy: the wiphy reporting the BSS
4604
 * @data: the BSS metadata
4605
 * @ftype: frame type (if known)
J
Johannes Berg 已提交
4606
 * @bssid: the BSSID of the BSS
4607
 * @tsf: the TSF sent by the peer in the beacon/probe response (or 0)
J
Johannes Berg 已提交
4608 4609 4610 4611 4612 4613 4614 4615
 * @capability: the capability field sent by the peer
 * @beacon_interval: the beacon interval announced by the peer
 * @ie: additional IEs sent by the peer
 * @ielen: length of the additional IEs
 * @gfp: context flags
 *
 * This informs cfg80211 that BSS information was found and
 * the BSS should be updated/added.
4616
 *
4617 4618
 * Return: A referenced struct, must be released with cfg80211_put_bss()!
 * Or %NULL on error.
J
Johannes Berg 已提交
4619
 */
4620
struct cfg80211_bss * __must_check
4621 4622 4623 4624 4625 4626 4627 4628
cfg80211_inform_bss_data(struct wiphy *wiphy,
			 struct cfg80211_inform_bss *data,
			 enum cfg80211_bss_frame_type ftype,
			 const u8 *bssid, u64 tsf, u16 capability,
			 u16 beacon_interval, const u8 *ie, size_t ielen,
			 gfp_t gfp);

static inline struct cfg80211_bss * __must_check
4629
cfg80211_inform_bss_width(struct wiphy *wiphy,
4630
			  struct ieee80211_channel *rx_channel,
4631
			  enum nl80211_bss_scan_width scan_width,
4632
			  enum cfg80211_bss_frame_type ftype,
4633 4634
			  const u8 *bssid, u64 tsf, u16 capability,
			  u16 beacon_interval, const u8 *ie, size_t ielen,
4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646
			  s32 signal, gfp_t gfp)
{
	struct cfg80211_inform_bss data = {
		.chan = rx_channel,
		.scan_width = scan_width,
		.signal = signal,
	};

	return cfg80211_inform_bss_data(wiphy, &data, ftype, bssid, tsf,
					capability, beacon_interval, ie, ielen,
					gfp);
}
4647 4648

static inline struct cfg80211_bss * __must_check
4649
cfg80211_inform_bss(struct wiphy *wiphy,
4650
		    struct ieee80211_channel *rx_channel,
4651
		    enum cfg80211_bss_frame_type ftype,
4652 4653
		    const u8 *bssid, u64 tsf, u16 capability,
		    u16 beacon_interval, const u8 *ie, size_t ielen,
4654 4655
		    s32 signal, gfp_t gfp)
{
4656 4657 4658 4659 4660 4661 4662 4663 4664
	struct cfg80211_inform_bss data = {
		.chan = rx_channel,
		.scan_width = NL80211_BSS_CHAN_WIDTH_20,
		.signal = signal,
	};

	return cfg80211_inform_bss_data(wiphy, &data, ftype, bssid, tsf,
					capability, beacon_interval, ie, ielen,
					gfp);
4665
}
4666

4667 4668 4669
struct cfg80211_bss *cfg80211_get_bss(struct wiphy *wiphy,
				      struct ieee80211_channel *channel,
				      const u8 *bssid,
4670
				      const u8 *ssid, size_t ssid_len,
4671 4672
				      enum ieee80211_bss_type bss_type,
				      enum ieee80211_privacy);
4673 4674 4675 4676 4677 4678
static inline struct cfg80211_bss *
cfg80211_get_ibss(struct wiphy *wiphy,
		  struct ieee80211_channel *channel,
		  const u8 *ssid, size_t ssid_len)
{
	return cfg80211_get_bss(wiphy, channel, NULL, ssid, ssid_len,
4679 4680
				IEEE80211_BSS_TYPE_IBSS,
				IEEE80211_PRIVACY_ANY);
4681 4682
}

4683 4684
/**
 * cfg80211_ref_bss - reference BSS struct
4685
 * @wiphy: the wiphy this BSS struct belongs to
4686 4687 4688 4689
 * @bss: the BSS struct to reference
 *
 * Increments the refcount of the given BSS struct.
 */
4690
void cfg80211_ref_bss(struct wiphy *wiphy, struct cfg80211_bss *bss);
4691 4692 4693

/**
 * cfg80211_put_bss - unref BSS struct
4694
 * @wiphy: the wiphy this BSS struct belongs to
4695 4696 4697 4698
 * @bss: the BSS struct
 *
 * Decrements the refcount of the given BSS struct.
 */
4699
void cfg80211_put_bss(struct wiphy *wiphy, struct cfg80211_bss *bss);
J
Johannes Berg 已提交
4700

4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711
/**
 * cfg80211_unlink_bss - unlink BSS from internal data structures
 * @wiphy: the wiphy
 * @bss: the bss to remove
 *
 * This function removes the given BSS from the internal data structures
 * thereby making it no longer show up in scan results etc. Use this
 * function when you detect a BSS is gone. Normally BSSes will also time
 * out, so it is not necessary to use this function at all.
 */
void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *bss);
J
Johannes Berg 已提交
4712

4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725
static inline enum nl80211_bss_scan_width
cfg80211_chandef_to_scan_width(const struct cfg80211_chan_def *chandef)
{
	switch (chandef->width) {
	case NL80211_CHAN_WIDTH_5:
		return NL80211_BSS_CHAN_WIDTH_5;
	case NL80211_CHAN_WIDTH_10:
		return NL80211_BSS_CHAN_WIDTH_10;
	default:
		return NL80211_BSS_CHAN_WIDTH_20;
	}
}

4726
/**
4727
 * cfg80211_rx_mlme_mgmt - notification of processed MLME management frame
4728 4729 4730 4731
 * @dev: network device
 * @buf: authentication frame (header + body)
 * @len: length of the frame data
 *
4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743
 * This function is called whenever an authentication, disassociation or
 * deauthentication frame has been received and processed in station mode.
 * After being asked to authenticate via cfg80211_ops::auth() the driver must
 * call either this function or cfg80211_auth_timeout().
 * After being asked to associate via cfg80211_ops::assoc() the driver must
 * call either this function or cfg80211_auth_timeout().
 * While connected, the driver must calls this for received and processed
 * disassociation and deauthentication frames. If the frame couldn't be used
 * because it was unprotected, the driver must call the function
 * cfg80211_rx_unprot_mlme_mgmt() instead.
 *
 * This function may sleep. The caller must hold the corresponding wdev's mutex.
4744
 */
4745
void cfg80211_rx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len);
4746

4747
/**
4748
 * cfg80211_auth_timeout - notification of timed out authentication
4749 4750
 * @dev: network device
 * @addr: The MAC address of the device with which the authentication timed out
4751
 *
4752 4753
 * This function may sleep. The caller must hold the corresponding wdev's
 * mutex.
4754
 */
4755
void cfg80211_auth_timeout(struct net_device *dev, const u8 *addr);
4756

4757
/**
4758
 * cfg80211_rx_assoc_resp - notification of processed association response
4759
 * @dev: network device
4760 4761 4762
 * @bss: the BSS that association was requested with, ownership of the pointer
 *	moves to cfg80211 in this call
 * @buf: authentication frame (header + body)
4763
 * @len: length of the frame data
4764 4765
 * @uapsd_queues: bitmap of queues configured for uapsd. Same format
 *	as the AC bitmap in the QoS info field
4766
 *
4767 4768 4769 4770
 * After being asked to associate via cfg80211_ops::assoc() the driver must
 * call either this function or cfg80211_auth_timeout().
 *
 * This function may sleep. The caller must hold the corresponding wdev's mutex.
4771
 */
4772 4773
void cfg80211_rx_assoc_resp(struct net_device *dev,
			    struct cfg80211_bss *bss,
4774 4775
			    const u8 *buf, size_t len,
			    int uapsd_queues);
4776

4777
/**
4778
 * cfg80211_assoc_timeout - notification of timed out association
4779
 * @dev: network device
4780
 * @bss: The BSS entry with which association timed out.
4781
 *
4782
 * This function may sleep. The caller must hold the corresponding wdev's mutex.
4783
 */
4784
void cfg80211_assoc_timeout(struct net_device *dev, struct cfg80211_bss *bss);
4785

4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796
/**
 * cfg80211_abandon_assoc - notify cfg80211 of abandoned association attempt
 * @dev: network device
 * @bss: The BSS entry with which association was abandoned.
 *
 * Call this whenever - for reasons reported through other API, like deauth RX,
 * an association attempt was abandoned.
 * This function may sleep. The caller must hold the corresponding wdev's mutex.
 */
void cfg80211_abandon_assoc(struct net_device *dev, struct cfg80211_bss *bss);

4797
/**
4798
 * cfg80211_tx_mlme_mgmt - notification of transmitted deauth/disassoc frame
4799
 * @dev: network device
4800
 * @buf: 802.11 frame (header + body)
4801 4802 4803
 * @len: length of the frame data
 *
 * This function is called whenever deauthentication has been processed in
4804
 * station mode. This includes both received deauthentication frames and
4805 4806
 * locally generated ones. This function may sleep. The caller must hold the
 * corresponding wdev's mutex.
4807
 */
4808
void cfg80211_tx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len);
4809

4810
/**
4811
 * cfg80211_rx_unprot_mlme_mgmt - notification of unprotected mlme mgmt frame
4812 4813 4814 4815
 * @dev: network device
 * @buf: deauthentication frame (header + body)
 * @len: length of the frame data
 *
4816 4817
 * This function is called whenever a received deauthentication or dissassoc
 * frame has been dropped in station mode because of MFP being used but the
4818 4819
 * frame was not protected. This function may sleep.
 */
4820 4821
void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev,
				  const u8 *buf, size_t len);
4822

4823 4824 4825 4826 4827
/**
 * cfg80211_michael_mic_failure - notification of Michael MIC failure (TKIP)
 * @dev: network device
 * @addr: The source MAC address of the frame
 * @key_type: The key type that the received frame used
4828
 * @key_id: Key identifier (0..3). Can be -1 if missing.
4829
 * @tsc: The TSC value of the frame that generated the MIC failure (6 octets)
4830
 * @gfp: allocation flags
4831 4832 4833 4834 4835 4836 4837
 *
 * This function is called whenever the local MAC detects a MIC failure in a
 * received frame. This matches with MLME-MICHAELMICFAILURE.indication()
 * primitive.
 */
void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr,
				  enum nl80211_key_type key_type, int key_id,
4838
				  const u8 *tsc, gfp_t gfp);
4839

J
Johannes Berg 已提交
4840 4841 4842 4843 4844
/**
 * cfg80211_ibss_joined - notify cfg80211 that device joined an IBSS
 *
 * @dev: network device
 * @bssid: the BSSID of the IBSS joined
4845
 * @channel: the channel of the IBSS joined
J
Johannes Berg 已提交
4846 4847 4848 4849 4850 4851 4852 4853 4854
 * @gfp: allocation flags
 *
 * This function notifies cfg80211 that the device joined an IBSS or
 * switched to a different BSSID. Before this function can be called,
 * either a beacon has to have been received from the IBSS, or one of
 * the cfg80211_inform_bss{,_frame} functions must have been called
 * with the locally generated beacon -- this guarantees that there is
 * always a scan result for this IBSS. cfg80211 will handle the rest.
 */
4855 4856
void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid,
			  struct ieee80211_channel *channel, gfp_t gfp);
J
Johannes Berg 已提交
4857

4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873
/**
 * cfg80211_notify_new_candidate - notify cfg80211 of a new mesh peer candidate
 *
 * @dev: network device
 * @macaddr: the MAC address of the new candidate
 * @ie: information elements advertised by the peer candidate
 * @ie_len: lenght of the information elements buffer
 * @gfp: allocation flags
 *
 * This function notifies cfg80211 that the mesh peer candidate has been
 * detected, most likely via a beacon or, less likely, via a probe response.
 * cfg80211 then sends a notification to userspace.
 */
void cfg80211_notify_new_peer_candidate(struct net_device *dev,
		const u8 *macaddr, const u8 *ie, u8 ie_len, gfp_t gfp);

J
Johannes Berg 已提交
4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887
/**
 * DOC: RFkill integration
 *
 * RFkill integration in cfg80211 is almost invisible to drivers,
 * as cfg80211 automatically registers an rfkill instance for each
 * wireless device it knows about. Soft kill is also translated
 * into disconnecting and turning all interfaces off, drivers are
 * expected to turn off the device when all interfaces are down.
 *
 * However, devices may have a hard RFkill line, in which case they
 * also need to interact with the rfkill subsystem, via cfg80211.
 * They can do this with a few helper functions documented here.
 */

J
Johannes Berg 已提交
4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906
/**
 * wiphy_rfkill_set_hw_state - notify cfg80211 about hw block state
 * @wiphy: the wiphy
 * @blocked: block status
 */
void wiphy_rfkill_set_hw_state(struct wiphy *wiphy, bool blocked);

/**
 * wiphy_rfkill_start_polling - start polling rfkill
 * @wiphy: the wiphy
 */
void wiphy_rfkill_start_polling(struct wiphy *wiphy);

/**
 * wiphy_rfkill_stop_polling - stop polling rfkill
 * @wiphy: the wiphy
 */
void wiphy_rfkill_stop_polling(struct wiphy *wiphy);

J
Johannes Berg 已提交
4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931
/**
 * DOC: Vendor commands
 *
 * Occasionally, there are special protocol or firmware features that
 * can't be implemented very openly. For this and similar cases, the
 * vendor command functionality allows implementing the features with
 * (typically closed-source) userspace and firmware, using nl80211 as
 * the configuration mechanism.
 *
 * A driver supporting vendor commands must register them as an array
 * in struct wiphy, with handlers for each one, each command has an
 * OUI and sub command ID to identify it.
 *
 * Note that this feature should not be (ab)used to implement protocol
 * features that could openly be shared across drivers. In particular,
 * it must never be required to use vendor commands to implement any
 * "normal" functionality that higher-level userspace like connection
 * managers etc. need.
 */

struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
					   enum nl80211_commands cmd,
					   enum nl80211_attrs attr,
					   int approxlen);

4932
struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
4933
					   struct wireless_dev *wdev,
4934 4935 4936 4937 4938 4939 4940
					   enum nl80211_commands cmd,
					   enum nl80211_attrs attr,
					   int vendor_event_idx,
					   int approxlen, gfp_t gfp);

void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp);

J
Johannes Berg 已提交
4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984
/**
 * cfg80211_vendor_cmd_alloc_reply_skb - allocate vendor command reply
 * @wiphy: the wiphy
 * @approxlen: an upper bound of the length of the data that will
 *	be put into the skb
 *
 * This function allocates and pre-fills an skb for a reply to
 * a vendor command. Since it is intended for a reply, calling
 * it outside of a vendor command's doit() operation is invalid.
 *
 * The returned skb is pre-filled with some identifying data in
 * a way that any data that is put into the skb (with skb_put(),
 * nla_put() or similar) will end up being within the
 * %NL80211_ATTR_VENDOR_DATA attribute, so all that needs to be done
 * with the skb is adding data for the corresponding userspace tool
 * which can then read that data out of the vendor data attribute.
 * You must not modify the skb in any other way.
 *
 * When done, call cfg80211_vendor_cmd_reply() with the skb and return
 * its error code as the result of the doit() operation.
 *
 * Return: An allocated and pre-filled skb. %NULL if any errors happen.
 */
static inline struct sk_buff *
cfg80211_vendor_cmd_alloc_reply_skb(struct wiphy *wiphy, int approxlen)
{
	return __cfg80211_alloc_reply_skb(wiphy, NL80211_CMD_VENDOR,
					  NL80211_ATTR_VENDOR_DATA, approxlen);
}

/**
 * cfg80211_vendor_cmd_reply - send the reply skb
 * @skb: The skb, must have been allocated with
 *	cfg80211_vendor_cmd_alloc_reply_skb()
 *
 * Since calling this function will usually be the last thing
 * before returning from the vendor command doit() you should
 * return the error code.  Note that this function consumes the
 * skb regardless of the return value.
 *
 * Return: An error code or 0 on success.
 */
int cfg80211_vendor_cmd_reply(struct sk_buff *skb);

4985 4986 4987
/**
 * cfg80211_vendor_event_alloc - allocate vendor-specific event skb
 * @wiphy: the wiphy
4988
 * @wdev: the wireless device
4989 4990 4991 4992 4993 4994 4995 4996
 * @event_idx: index of the vendor event in the wiphy's vendor_events
 * @approxlen: an upper bound of the length of the data that will
 *	be put into the skb
 * @gfp: allocation flags
 *
 * This function allocates and pre-fills an skb for an event on the
 * vendor-specific multicast group.
 *
4997 4998 4999 5000
 * If wdev != NULL, both the ifindex and identifier of the specified
 * wireless device are added to the event message before the vendor data
 * attribute.
 *
5001 5002 5003 5004 5005 5006
 * When done filling the skb, call cfg80211_vendor_event() with the
 * skb to send the event.
 *
 * Return: An allocated and pre-filled skb. %NULL if any errors happen.
 */
static inline struct sk_buff *
5007 5008
cfg80211_vendor_event_alloc(struct wiphy *wiphy, struct wireless_dev *wdev,
			     int approxlen, int event_idx, gfp_t gfp)
5009
{
5010
	return __cfg80211_alloc_event_skb(wiphy, wdev, NL80211_CMD_VENDOR,
5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027
					  NL80211_ATTR_VENDOR_DATA,
					  event_idx, approxlen, gfp);
}

/**
 * cfg80211_vendor_event - send the event
 * @skb: The skb, must have been allocated with cfg80211_vendor_event_alloc()
 * @gfp: allocation flags
 *
 * This function sends the given @skb, which must have been allocated
 * by cfg80211_vendor_event_alloc(), as an event. It always consumes it.
 */
static inline void cfg80211_vendor_event(struct sk_buff *skb, gfp_t gfp)
{
	__cfg80211_send_event_skb(skb, gfp);
}

5028
#ifdef CONFIG_NL80211_TESTMODE
J
Johannes Berg 已提交
5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039
/**
 * DOC: Test mode
 *
 * Test mode is a set of utility functions to allow drivers to
 * interact with driver-specific tools to aid, for instance,
 * factory programming.
 *
 * This chapter describes how drivers interact with it, for more
 * information see the nl80211 book's chapter on it.
 */

5040 5041 5042 5043 5044 5045 5046 5047 5048 5049
/**
 * cfg80211_testmode_alloc_reply_skb - allocate testmode reply
 * @wiphy: the wiphy
 * @approxlen: an upper bound of the length of the data that will
 *	be put into the skb
 *
 * This function allocates and pre-fills an skb for a reply to
 * the testmode command. Since it is intended for a reply, calling
 * it outside of the @testmode_cmd operation is invalid.
 *
5050 5051 5052 5053 5054 5055 5056
 * The returned skb is pre-filled with the wiphy index and set up in
 * a way that any data that is put into the skb (with skb_put(),
 * nla_put() or similar) will end up being within the
 * %NL80211_ATTR_TESTDATA attribute, so all that needs to be done
 * with the skb is adding data for the corresponding userspace tool
 * which can then read that data out of the testdata attribute. You
 * must not modify the skb in any other way.
5057 5058 5059
 *
 * When done, call cfg80211_testmode_reply() with the skb and return
 * its error code as the result of the @testmode_cmd operation.
5060 5061
 *
 * Return: An allocated and pre-filled skb. %NULL if any errors happen.
5062
 */
J
Johannes Berg 已提交
5063 5064 5065 5066 5067 5068
static inline struct sk_buff *
cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, int approxlen)
{
	return __cfg80211_alloc_reply_skb(wiphy, NL80211_CMD_TESTMODE,
					  NL80211_ATTR_TESTDATA, approxlen);
}
5069 5070 5071 5072 5073 5074

/**
 * cfg80211_testmode_reply - send the reply skb
 * @skb: The skb, must have been allocated with
 *	cfg80211_testmode_alloc_reply_skb()
 *
5075 5076 5077 5078 5079 5080
 * Since calling this function will usually be the last thing
 * before returning from the @testmode_cmd you should return
 * the error code.  Note that this function consumes the skb
 * regardless of the return value.
 *
 * Return: An error code or 0 on success.
5081
 */
J
Johannes Berg 已提交
5082 5083 5084 5085
static inline int cfg80211_testmode_reply(struct sk_buff *skb)
{
	return cfg80211_vendor_cmd_reply(skb);
}
5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096

/**
 * cfg80211_testmode_alloc_event_skb - allocate testmode event
 * @wiphy: the wiphy
 * @approxlen: an upper bound of the length of the data that will
 *	be put into the skb
 * @gfp: allocation flags
 *
 * This function allocates and pre-fills an skb for an event on the
 * testmode multicast group.
 *
5097 5098 5099 5100 5101
 * The returned skb is set up in the same way as with
 * cfg80211_testmode_alloc_reply_skb() but prepared for an event. As
 * there, you should simply add data to it that will then end up in the
 * %NL80211_ATTR_TESTDATA attribute. Again, you must not modify the skb
 * in any other way.
5102 5103 5104
 *
 * When done filling the skb, call cfg80211_testmode_event() with the
 * skb to send the event.
5105 5106
 *
 * Return: An allocated and pre-filled skb. %NULL if any errors happen.
5107
 */
5108 5109 5110
static inline struct sk_buff *
cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, int approxlen, gfp_t gfp)
{
5111
	return __cfg80211_alloc_event_skb(wiphy, NULL, NL80211_CMD_TESTMODE,
5112 5113 5114
					  NL80211_ATTR_TESTDATA, -1,
					  approxlen, gfp);
}
5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125

/**
 * cfg80211_testmode_event - send the event
 * @skb: The skb, must have been allocated with
 *	cfg80211_testmode_alloc_event_skb()
 * @gfp: allocation flags
 *
 * This function sends the given @skb, which must have been allocated
 * by cfg80211_testmode_alloc_event_skb(), as an event. It always
 * consumes it.
 */
5126 5127 5128 5129
static inline void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
{
	__cfg80211_send_event_skb(skb, gfp);
}
5130 5131

#define CFG80211_TESTMODE_CMD(cmd)	.testmode_cmd = (cmd),
W
Wey-Yi Guy 已提交
5132
#define CFG80211_TESTMODE_DUMP(cmd)	.testmode_dump = (cmd),
5133 5134
#else
#define CFG80211_TESTMODE_CMD(cmd)
W
Wey-Yi Guy 已提交
5135
#define CFG80211_TESTMODE_DUMP(cmd)
5136 5137
#endif

5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148
/**
 * cfg80211_connect_bss - notify cfg80211 of connection result
 *
 * @dev: network device
 * @bssid: the BSSID of the AP
 * @bss: entry of bss to which STA got connected to, can be obtained
 *	through cfg80211_get_bss (may be %NULL)
 * @req_ie: association request IEs (maybe be %NULL)
 * @req_ie_len: association request IEs length
 * @resp_ie: association response IEs (may be %NULL)
 * @resp_ie_len: assoc response IEs length
5149 5150 5151 5152 5153 5154 5155 5156
 * @status: status code, %WLAN_STATUS_SUCCESS for successful connection, use
 *	%WLAN_STATUS_UNSPECIFIED_FAILURE if your device cannot give you
 *	the real status code for failures. If this call is used to report a
 *	failure due to a timeout (e.g., not receiving an Authentication frame
 *	from the AP) instead of an explicit rejection by the AP, -1 is used to
 *	indicate that this is a failure, but without a status code.
 *	@timeout_reason is used to report the reason for the timeout in that
 *	case.
5157
 * @gfp: allocation flags
5158 5159 5160 5161 5162 5163
 * @timeout_reason: reason for connection timeout. This is used when the
 *	connection fails due to a timeout instead of an explicit rejection from
 *	the AP. %NL80211_TIMEOUT_UNSPECIFIED is used when the timeout reason is
 *	not known. This value is used only if @status < 0 to indicate that the
 *	failure is due to a timeout and not due to explicit rejection by the AP.
 *	This value is ignored in other cases (@status >= 0).
5164
 *
5165 5166 5167 5168
 * It should be called by the underlying driver once execution of the connection
 * request from connect() has been completed. This is similar to
 * cfg80211_connect_result(), but with the option of identifying the exact bss
 * entry for the connection. Only one of these functions should be called.
5169 5170 5171 5172
 */
void cfg80211_connect_bss(struct net_device *dev, const u8 *bssid,
			  struct cfg80211_bss *bss, const u8 *req_ie,
			  size_t req_ie_len, const u8 *resp_ie,
5173 5174
			  size_t resp_ie_len, int status, gfp_t gfp,
			  enum nl80211_timeout_reason timeout_reason);
5175

S
Samuel Ortiz 已提交
5176 5177 5178 5179 5180 5181 5182 5183 5184
/**
 * cfg80211_connect_result - notify cfg80211 of connection result
 *
 * @dev: network device
 * @bssid: the BSSID of the AP
 * @req_ie: association request IEs (maybe be %NULL)
 * @req_ie_len: association request IEs length
 * @resp_ie: association response IEs (may be %NULL)
 * @resp_ie_len: assoc response IEs length
5185
 * @status: status code, %WLAN_STATUS_SUCCESS for successful connection, use
S
Samuel Ortiz 已提交
5186 5187 5188 5189
 *	%WLAN_STATUS_UNSPECIFIED_FAILURE if your device cannot give you
 *	the real status code for failures.
 * @gfp: allocation flags
 *
5190 5191 5192 5193
 * It should be called by the underlying driver once execution of the connection
 * request from connect() has been completed. This is similar to
 * cfg80211_connect_bss() which allows the exact bss entry to be specified. Only
 * one of these functions should be called.
S
Samuel Ortiz 已提交
5194
 */
5195 5196 5197 5198 5199 5200 5201
static inline void
cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
			const u8 *req_ie, size_t req_ie_len,
			const u8 *resp_ie, size_t resp_ie_len,
			u16 status, gfp_t gfp)
{
	cfg80211_connect_bss(dev, bssid, NULL, req_ie, req_ie_len, resp_ie,
5202 5203
			     resp_ie_len, status, gfp,
			     NL80211_TIMEOUT_UNSPECIFIED);
5204 5205 5206 5207 5208 5209 5210 5211 5212 5213
}

/**
 * cfg80211_connect_timeout - notify cfg80211 of connection timeout
 *
 * @dev: network device
 * @bssid: the BSSID of the AP
 * @req_ie: association request IEs (maybe be %NULL)
 * @req_ie_len: association request IEs length
 * @gfp: allocation flags
5214
 * @timeout_reason: reason for connection timeout.
5215 5216 5217 5218 5219 5220 5221 5222 5223
 *
 * It should be called by the underlying driver whenever connect() has failed
 * in a sequence where no explicit authentication/association rejection was
 * received from the AP. This could happen, e.g., due to not being able to send
 * out the Authentication or Association Request frame or timing out while
 * waiting for the response.
 */
static inline void
cfg80211_connect_timeout(struct net_device *dev, const u8 *bssid,
5224 5225
			 const u8 *req_ie, size_t req_ie_len, gfp_t gfp,
			 enum nl80211_timeout_reason timeout_reason)
5226 5227
{
	cfg80211_connect_bss(dev, bssid, NULL, req_ie, req_ie_len, NULL, 0, -1,
5228
			     gfp, timeout_reason);
5229
}
S
Samuel Ortiz 已提交
5230 5231 5232 5233 5234

/**
 * cfg80211_roamed - notify cfg80211 of roaming
 *
 * @dev: network device
5235
 * @channel: the channel of the new AP
S
Samuel Ortiz 已提交
5236 5237 5238 5239 5240 5241 5242 5243 5244 5245
 * @bssid: the BSSID of the new AP
 * @req_ie: association request IEs (maybe be %NULL)
 * @req_ie_len: association request IEs length
 * @resp_ie: association response IEs (may be %NULL)
 * @resp_ie_len: assoc response IEs length
 * @gfp: allocation flags
 *
 * It should be called by the underlying driver whenever it roamed
 * from one AP to another while connected.
 */
5246 5247 5248
void cfg80211_roamed(struct net_device *dev,
		     struct ieee80211_channel *channel,
		     const u8 *bssid,
S
Samuel Ortiz 已提交
5249 5250 5251
		     const u8 *req_ie, size_t req_ie_len,
		     const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp);

5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277
/**
 * cfg80211_roamed_bss - notify cfg80211 of roaming
 *
 * @dev: network device
 * @bss: entry of bss to which STA got roamed
 * @req_ie: association request IEs (maybe be %NULL)
 * @req_ie_len: association request IEs length
 * @resp_ie: association response IEs (may be %NULL)
 * @resp_ie_len: assoc response IEs length
 * @gfp: allocation flags
 *
 * This is just a wrapper to notify cfg80211 of roaming event with driver
 * passing bss to avoid a race in timeout of the bss entry. It should be
 * called by the underlying driver whenever it roamed from one AP to another
 * while connected. Drivers which have roaming implemented in firmware
 * may use this function to avoid a race in bss entry timeout where the bss
 * entry of the new AP is seen in the driver, but gets timed out by the time
 * it is accessed in __cfg80211_roamed() due to delay in scheduling
 * rdev->event_work. In case of any failures, the reference is released
 * either in cfg80211_roamed_bss() or in __cfg80211_romed(), Otherwise,
 * it will be released while diconneting from the current bss.
 */
void cfg80211_roamed_bss(struct net_device *dev, struct cfg80211_bss *bss,
			 const u8 *req_ie, size_t req_ie_len,
			 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp);

S
Samuel Ortiz 已提交
5278 5279 5280 5281 5282 5283 5284
/**
 * cfg80211_disconnected - notify cfg80211 that connection was dropped
 *
 * @dev: network device
 * @ie: information elements of the deauth/disassoc frame (may be %NULL)
 * @ie_len: length of IEs
 * @reason: reason code for the disconnection, set it to 0 if unknown
5285
 * @locally_generated: disconnection was requested locally
S
Samuel Ortiz 已提交
5286 5287 5288 5289 5290 5291
 * @gfp: allocation flags
 *
 * After it calls this function, the driver should enter an idle state
 * and not try to connect to any AP any more.
 */
void cfg80211_disconnected(struct net_device *dev, u16 reason,
5292 5293
			   const u8 *ie, size_t ie_len,
			   bool locally_generated, gfp_t gfp);
S
Samuel Ortiz 已提交
5294

5295 5296
/**
 * cfg80211_ready_on_channel - notification of remain_on_channel start
5297
 * @wdev: wireless device
5298 5299 5300 5301 5302 5303
 * @cookie: the request cookie
 * @chan: The current channel (from remain_on_channel request)
 * @duration: Duration in milliseconds that the driver intents to remain on the
 *	channel
 * @gfp: allocation flags
 */
5304
void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
5305 5306 5307 5308 5309
			       struct ieee80211_channel *chan,
			       unsigned int duration, gfp_t gfp);

/**
 * cfg80211_remain_on_channel_expired - remain_on_channel duration expired
5310
 * @wdev: wireless device
5311 5312 5313 5314
 * @cookie: the request cookie
 * @chan: The current channel (from remain_on_channel request)
 * @gfp: allocation flags
 */
5315
void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
5316 5317
					struct ieee80211_channel *chan,
					gfp_t gfp);
S
Samuel Ortiz 已提交
5318

5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330

/**
 * cfg80211_new_sta - notify userspace about station
 *
 * @dev: the netdev
 * @mac_addr: the station's address
 * @sinfo: the station information
 * @gfp: allocation flags
 */
void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
		      struct station_info *sinfo, gfp_t gfp);

5331 5332 5333 5334 5335 5336 5337 5338 5339 5340
/**
 * cfg80211_del_sta_sinfo - notify userspace about deletion of a station
 * @dev: the netdev
 * @mac_addr: the station's address
 * @sinfo: the station information/statistics
 * @gfp: allocation flags
 */
void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
			    struct station_info *sinfo, gfp_t gfp);

5341 5342 5343 5344 5345 5346 5347
/**
 * cfg80211_del_sta - notify userspace about deletion of a station
 *
 * @dev: the netdev
 * @mac_addr: the station's address
 * @gfp: allocation flags
 */
5348 5349 5350 5351 5352
static inline void cfg80211_del_sta(struct net_device *dev,
				    const u8 *mac_addr, gfp_t gfp)
{
	cfg80211_del_sta_sinfo(dev, mac_addr, NULL, gfp);
}
5353

5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372
/**
 * cfg80211_conn_failed - connection request failed notification
 *
 * @dev: the netdev
 * @mac_addr: the station's address
 * @reason: the reason for connection failure
 * @gfp: allocation flags
 *
 * Whenever a station tries to connect to an AP and if the station
 * could not connect to the AP as the AP has rejected the connection
 * for some reasons, this function is called.
 *
 * The reason for connection failure can be any of the value from
 * nl80211_connect_failed_reason enum
 */
void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
			  enum nl80211_connect_failed_reason reason,
			  gfp_t gfp);

5373
/**
5374
 * cfg80211_rx_mgmt - notification of received, unprocessed management frame
5375
 * @wdev: wireless device receiving the frame
5376
 * @freq: Frequency on which the frame was received in MHz
5377
 * @sig_dbm: signal strength in mBm, or 0 if unknown
5378
 * @buf: Management frame (header + body)
5379
 * @len: length of the frame data
5380
 * @flags: flags, as defined in enum nl80211_rxmgmt_flags
5381
 *
5382 5383 5384 5385
 * This function is called whenever an Action frame is received for a station
 * mode interface, but is not processed in kernel.
 *
 * Return: %true if a user space application has registered for this frame.
5386 5387 5388
 * For action frames, that makes it responsible for rejecting unrecognized
 * action frames; %false otherwise, in which case for action frames the
 * driver is responsible for rejecting the frame.
5389
 */
5390
bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int sig_dbm,
5391
		      const u8 *buf, size_t len, u32 flags);
5392 5393

/**
5394
 * cfg80211_mgmt_tx_status - notification of TX status for management frame
5395
 * @wdev: wireless device receiving the frame
5396 5397
 * @cookie: Cookie returned by cfg80211_ops::mgmt_tx()
 * @buf: Management frame (header + body)
5398 5399 5400 5401
 * @len: length of the frame data
 * @ack: Whether frame was acknowledged
 * @gfp: context flags
 *
5402 5403
 * This function is called whenever a management frame was requested to be
 * transmitted with cfg80211_ops::mgmt_tx() to report the TX status of the
5404 5405
 * transmission attempt.
 */
5406
void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
5407
			     const u8 *buf, size_t len, bool ack, gfp_t gfp);
5408

5409 5410 5411 5412 5413

/**
 * cfg80211_cqm_rssi_notify - connection quality monitoring rssi event
 * @dev: network device
 * @rssi_event: the triggered RSSI event
5414
 * @rssi_level: new RSSI level value or 0 if not available
5415 5416 5417 5418 5419 5420 5421
 * @gfp: context flags
 *
 * This function is called when a configured connection quality monitoring
 * rssi threshold reached event occurs.
 */
void cfg80211_cqm_rssi_notify(struct net_device *dev,
			      enum nl80211_cqm_rssi_threshold_event rssi_event,
5422
			      s32 rssi_level, gfp_t gfp);
5423

5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435
/**
 * cfg80211_cqm_pktloss_notify - notify userspace about packetloss to peer
 * @dev: network device
 * @peer: peer's MAC address
 * @num_packets: how many packets were lost -- should be a fixed threshold
 *	but probably no less than maybe 50, or maybe a throughput dependent
 *	threshold (to account for temporary interference)
 * @gfp: context flags
 */
void cfg80211_cqm_pktloss_notify(struct net_device *dev,
				 const u8 *peer, u32 num_packets, gfp_t gfp);

5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450
/**
 * cfg80211_cqm_txe_notify - TX error rate event
 * @dev: network device
 * @peer: peer's MAC address
 * @num_packets: how many packets were lost
 * @rate: % of packets which failed transmission
 * @intvl: interval (in s) over which the TX failure threshold was breached.
 * @gfp: context flags
 *
 * Notify userspace when configured % TX failures over number of packets in a
 * given interval is exceeded.
 */
void cfg80211_cqm_txe_notify(struct net_device *dev, const u8 *peer,
			     u32 num_packets, u32 rate, u32 intvl, gfp_t gfp);

5451 5452 5453 5454 5455 5456 5457 5458 5459
/**
 * cfg80211_cqm_beacon_loss_notify - beacon loss event
 * @dev: network device
 * @gfp: context flags
 *
 * Notify userspace about beacon loss from the connected AP.
 */
void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp);

5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486
/**
 * cfg80211_radar_event - radar detection event
 * @wiphy: the wiphy
 * @chandef: chandef for the current channel
 * @gfp: context flags
 *
 * This function is called when a radar is detected on the current chanenl.
 */
void cfg80211_radar_event(struct wiphy *wiphy,
			  struct cfg80211_chan_def *chandef, gfp_t gfp);

/**
 * cfg80211_cac_event - Channel availability check (CAC) event
 * @netdev: network device
 * @chandef: chandef for the current channel
 * @event: type of event
 * @gfp: context flags
 *
 * This function is called when a Channel availability check (CAC) is finished
 * or aborted. This must be called to notify the completion of a CAC process,
 * also by full-MAC drivers.
 */
void cfg80211_cac_event(struct net_device *netdev,
			const struct cfg80211_chan_def *chandef,
			enum nl80211_radar_event event, gfp_t gfp);


5487 5488 5489 5490 5491
/**
 * cfg80211_gtk_rekey_notify - notify userspace about driver rekeying
 * @dev: network device
 * @bssid: BSSID of AP (to avoid races)
 * @replay_ctr: new replay counter
J
Johannes Berg 已提交
5492
 * @gfp: allocation flags
5493 5494 5495 5496
 */
void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
			       const u8 *replay_ctr, gfp_t gfp);

5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507
/**
 * cfg80211_pmksa_candidate_notify - notify about PMKSA caching candidate
 * @dev: network device
 * @index: candidate index (the smaller the index, the higher the priority)
 * @bssid: BSSID of AP
 * @preauth: Whether AP advertises support for RSN pre-authentication
 * @gfp: allocation flags
 */
void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
				     const u8 *bssid, bool preauth, gfp_t gfp);

5508 5509 5510 5511 5512 5513 5514 5515 5516
/**
 * cfg80211_rx_spurious_frame - inform userspace about a spurious frame
 * @dev: The device the frame matched to
 * @addr: the transmitter address
 * @gfp: context flags
 *
 * This function is used in AP mode (only!) to inform userspace that
 * a spurious class 3 frame was received, to be able to deauth the
 * sender.
5517
 * Return: %true if the frame was passed to userspace (or this failed
5518 5519 5520 5521 5522
 * for a reason other than not having a subscription.)
 */
bool cfg80211_rx_spurious_frame(struct net_device *dev,
				const u8 *addr, gfp_t gfp);

5523 5524 5525 5526 5527 5528 5529 5530 5531 5532
/**
 * cfg80211_rx_unexpected_4addr_frame - inform about unexpected WDS frame
 * @dev: The device the frame matched to
 * @addr: the transmitter address
 * @gfp: context flags
 *
 * This function is used in AP mode (only!) to inform userspace that
 * an associated station sent a 4addr frame but that wasn't expected.
 * It is allowed and desirable to send this event only once for each
 * station to avoid event flooding.
5533
 * Return: %true if the frame was passed to userspace (or this failed
5534 5535 5536 5537 5538
 * for a reason other than not having a subscription.)
 */
bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
					const u8 *addr, gfp_t gfp);

J
Johannes Berg 已提交
5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549
/**
 * cfg80211_probe_status - notify userspace about probe status
 * @dev: the device the probe was sent on
 * @addr: the address of the peer
 * @cookie: the cookie filled in @probe_client previously
 * @acked: indicates whether probe was acked or not
 * @gfp: allocation flags
 */
void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
			   u64 cookie, bool acked, gfp_t gfp);

5550 5551 5552 5553 5554 5555
/**
 * cfg80211_report_obss_beacon - report beacon from other APs
 * @wiphy: The wiphy that received the beacon
 * @frame: the frame
 * @len: length of the frame
 * @freq: frequency the frame was received on
5556
 * @sig_dbm: signal strength in mBm, or 0 if unknown
5557 5558 5559 5560 5561 5562 5563
 *
 * Use this function to report to userspace when a beacon was
 * received. It is not useful to call this when there is no
 * netdev that is in AP/GO mode.
 */
void cfg80211_report_obss_beacon(struct wiphy *wiphy,
				 const u8 *frame, size_t len,
5564
				 int freq, int sig_dbm);
5565

5566
/**
5567
 * cfg80211_reg_can_beacon - check if beaconing is allowed
5568
 * @wiphy: the wiphy
5569
 * @chandef: the channel definition
5570
 * @iftype: interface type
5571
 *
5572 5573
 * Return: %true if there is no secondary channel or the secondary channel(s)
 * can be used for beaconing (i.e. is not a radar channel etc.)
5574
 */
5575
bool cfg80211_reg_can_beacon(struct wiphy *wiphy,
5576 5577
			     struct cfg80211_chan_def *chandef,
			     enum nl80211_iftype iftype);
5578

5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595
/**
 * cfg80211_reg_can_beacon_relax - check if beaconing is allowed with relaxation
 * @wiphy: the wiphy
 * @chandef: the channel definition
 * @iftype: interface type
 *
 * Return: %true if there is no secondary channel or the secondary channel(s)
 * can be used for beaconing (i.e. is not a radar channel etc.). This version
 * also checks if IR-relaxation conditions apply, to allow beaconing under
 * more permissive conditions.
 *
 * Requires the RTNL to be held.
 */
bool cfg80211_reg_can_beacon_relax(struct wiphy *wiphy,
				   struct cfg80211_chan_def *chandef,
				   enum nl80211_iftype iftype);

5596 5597 5598
/*
 * cfg80211_ch_switch_notify - update wdev channel and notify userspace
 * @dev: the device which switched channels
5599
 * @chandef: the new channel definition
5600
 *
5601 5602
 * Caller must acquire wdev_lock, therefore must only be called from sleepable
 * driver context!
5603
 */
5604 5605
void cfg80211_ch_switch_notify(struct net_device *dev,
			       struct cfg80211_chan_def *chandef);
5606

5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620
/*
 * cfg80211_ch_switch_started_notify - notify channel switch start
 * @dev: the device on which the channel switch started
 * @chandef: the future channel definition
 * @count: the number of TBTTs until the channel switch happens
 *
 * Inform the userspace about the channel switch that has just
 * started, so that it can take appropriate actions (eg. starting
 * channel switch on other vifs), if necessary.
 */
void cfg80211_ch_switch_started_notify(struct net_device *dev,
				       struct cfg80211_chan_def *chandef,
				       u8 count);

5621 5622 5623 5624 5625 5626 5627 5628 5629
/**
 * ieee80211_operating_class_to_band - convert operating class to band
 *
 * @operating_class: the operating class to convert
 * @band: band pointer to fill
 *
 * Returns %true if the conversion was successful, %false otherwise.
 */
bool ieee80211_operating_class_to_band(u8 operating_class,
5630
				       enum nl80211_band *band);
5631

5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642
/**
 * ieee80211_chandef_to_operating_class - convert chandef to operation class
 *
 * @chandef: the chandef to convert
 * @op_class: a pointer to the resulting operating class
 *
 * Returns %true if the conversion was successful, %false otherwise.
 */
bool ieee80211_chandef_to_operating_class(struct cfg80211_chan_def *chandef,
					  u8 *op_class);

5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661
/*
 * cfg80211_tdls_oper_request - request userspace to perform TDLS operation
 * @dev: the device on which the operation is requested
 * @peer: the MAC address of the peer device
 * @oper: the requested TDLS operation (NL80211_TDLS_SETUP or
 *	NL80211_TDLS_TEARDOWN)
 * @reason_code: the reason code for teardown request
 * @gfp: allocation flags
 *
 * This function is used to request userspace to perform TDLS operation that
 * requires knowledge of keys, i.e., link setup or teardown when the AP
 * connection uses encryption. This is optional mechanism for the driver to use
 * if it can automatically determine when a TDLS link could be useful (e.g.,
 * based on traffic and signal strength for a peer).
 */
void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
				enum nl80211_tdls_operation oper,
				u16 reason_code, gfp_t gfp);

5662 5663 5664 5665 5666 5667
/*
 * cfg80211_calculate_bitrate - calculate actual bitrate (in 100Kbps units)
 * @rate: given rate_info to calculate bitrate from
 *
 * return 0 if MCS index >= 32
 */
5668
u32 cfg80211_calculate_bitrate(struct rate_info *rate);
5669

5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685
/**
 * cfg80211_unregister_wdev - remove the given wdev
 * @wdev: struct wireless_dev to remove
 *
 * Call this function only for wdevs that have no netdev assigned,
 * e.g. P2P Devices. It removes the device from the list so that
 * it can no longer be used. It is necessary to call this function
 * even when cfg80211 requests the removal of the interface by
 * calling the del_virtual_intf() callback. The function must also
 * be called when the driver wishes to unregister the wdev, e.g.
 * when the device is unbound from the driver.
 *
 * Requires the RTNL to be held.
 */
void cfg80211_unregister_wdev(struct wireless_dev *wdev);

5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709
/**
 * struct cfg80211_ft_event - FT Information Elements
 * @ies: FT IEs
 * @ies_len: length of the FT IE in bytes
 * @target_ap: target AP's MAC address
 * @ric_ies: RIC IE
 * @ric_ies_len: length of the RIC IE in bytes
 */
struct cfg80211_ft_event_params {
	const u8 *ies;
	size_t ies_len;
	const u8 *target_ap;
	const u8 *ric_ies;
	size_t ric_ies_len;
};

/**
 * cfg80211_ft_event - notify userspace about FT IE and RIC IE
 * @netdev: network device
 * @ft_event: IE information
 */
void cfg80211_ft_event(struct net_device *netdev,
		       struct cfg80211_ft_event_params *ft_event);

5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721
/**
 * cfg80211_get_p2p_attr - find and copy a P2P attribute from IE buffer
 * @ies: the input IE buffer
 * @len: the input length
 * @attr: the attribute ID to find
 * @buf: output buffer, can be %NULL if the data isn't needed, e.g.
 *	if the function is only called to get the needed buffer size
 * @bufsize: size of the output buffer
 *
 * The function finds a given P2P attribute in the (vendor) IEs and
 * copies its contents to the given buffer.
 *
5722 5723 5724
 * Return: A negative error code (-%EILSEQ or -%ENOENT) if the data is
 * malformed or the attribute can't be found (respectively), or the
 * length of the found attribute (which can be zero).
5725
 */
5726 5727 5728
int cfg80211_get_p2p_attr(const u8 *ies, unsigned int len,
			  enum ieee80211_p2p_attr_id attr,
			  u8 *buf, unsigned int bufsize);
5729

5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784
/**
 * ieee80211_ie_split_ric - split an IE buffer according to ordering (with RIC)
 * @ies: the IE buffer
 * @ielen: the length of the IE buffer
 * @ids: an array with element IDs that are allowed before
 *	the split
 * @n_ids: the size of the element ID array
 * @after_ric: array IE types that come after the RIC element
 * @n_after_ric: size of the @after_ric array
 * @offset: offset where to start splitting in the buffer
 *
 * This function splits an IE buffer by updating the @offset
 * variable to point to the location where the buffer should be
 * split.
 *
 * It assumes that the given IE buffer is well-formed, this
 * has to be guaranteed by the caller!
 *
 * It also assumes that the IEs in the buffer are ordered
 * correctly, if not the result of using this function will not
 * be ordered correctly either, i.e. it does no reordering.
 *
 * The function returns the offset where the next part of the
 * buffer starts, which may be @ielen if the entire (remainder)
 * of the buffer should be used.
 */
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);

/**
 * ieee80211_ie_split - split an IE buffer according to ordering
 * @ies: the IE buffer
 * @ielen: the length of the IE buffer
 * @ids: an array with element IDs that are allowed before
 *	the split
 * @n_ids: the size of the element ID array
 * @offset: offset where to start splitting in the buffer
 *
 * This function splits an IE buffer by updating the @offset
 * variable to point to the location where the buffer should be
 * split.
 *
 * It assumes that the given IE buffer is well-formed, this
 * has to be guaranteed by the caller!
 *
 * It also assumes that the IEs in the buffer are ordered
 * correctly, if not the result of using this function will not
 * be ordered correctly either, i.e. it does no reordering.
 *
 * The function returns the offset where the next part of the
 * buffer starts, which may be @ielen if the entire (remainder)
 * of the buffer should be used.
 */
5785 5786 5787 5788 5789
static inline size_t ieee80211_ie_split(const u8 *ies, size_t ielen,
					const u8 *ids, int n_ids, size_t offset)
{
	return ieee80211_ie_split_ric(ies, ielen, ids, n_ids, NULL, 0, offset);
}
5790

5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805
/**
 * cfg80211_report_wowlan_wakeup - report wakeup from WoWLAN
 * @wdev: the wireless device reporting the wakeup
 * @wakeup: the wakeup report
 * @gfp: allocation flags
 *
 * This function reports that the given device woke up. If it
 * caused the wakeup, report the reason(s), otherwise you may
 * pass %NULL as the @wakeup parameter to advertise that something
 * else caused the wakeup.
 */
void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
				   struct cfg80211_wowlan_wakeup *wakeup,
				   gfp_t gfp);

5806 5807 5808 5809
/**
 * cfg80211_crit_proto_stopped() - indicate critical protocol stopped by driver.
 *
 * @wdev: the wireless device for which critical protocol is stopped.
5810
 * @gfp: allocation flags
5811 5812 5813 5814 5815 5816 5817
 *
 * This function can be called by the driver to indicate it has reverted
 * operation back to normal. One reason could be that the duration given
 * by .crit_proto_start() has expired.
 */
void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp);

5818 5819 5820 5821 5822 5823 5824 5825
/**
 * ieee80211_get_num_supported_channels - get number of channels device has
 * @wiphy: the wiphy
 *
 * Return: the number of channels supported by the device.
 */
unsigned int ieee80211_get_num_supported_channels(struct wiphy *wiphy);

5826 5827 5828 5829
/**
 * cfg80211_check_combinations - check interface combinations
 *
 * @wiphy: the wiphy
5830
 * @params: the interface combinations parameter
5831 5832 5833 5834 5835 5836
 *
 * This function can be called by the driver to check whether a
 * combination of interfaces and their types are allowed according to
 * the interface combinations.
 */
int cfg80211_check_combinations(struct wiphy *wiphy,
5837
				struct iface_combination_params *params);
5838

5839 5840 5841 5842
/**
 * cfg80211_iter_combinations - iterate over matching combinations
 *
 * @wiphy: the wiphy
5843
 * @params: the interface combinations parameter
5844 5845 5846 5847 5848 5849 5850 5851
 * @iter: function to call for each matching combination
 * @data: pointer to pass to iter function
 *
 * This function can be called by the driver to check what possible
 * combinations it fits in at a given moment, e.g. for channel switching
 * purposes.
 */
int cfg80211_iter_combinations(struct wiphy *wiphy,
5852
			       struct iface_combination_params *params,
5853 5854 5855 5856
			       void (*iter)(const struct ieee80211_iface_combination *c,
					    void *data),
			       void *data);

5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871
/*
 * cfg80211_stop_iface - trigger interface disconnection
 *
 * @wiphy: the wiphy
 * @wdev: wireless device
 * @gfp: context flags
 *
 * Trigger interface to be stopped as if AP was stopped, IBSS/mesh left, STA
 * disconnected.
 *
 * Note: This doesn't need any locks and is asynchronous.
 */
void cfg80211_stop_iface(struct wiphy *wiphy, struct wireless_dev *wdev,
			 gfp_t gfp);

5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885
/**
 * cfg80211_shutdown_all_interfaces - shut down all interfaces for a wiphy
 * @wiphy: the wiphy to shut down
 *
 * This function shuts down all interfaces belonging to this wiphy by
 * calling dev_close() (and treating non-netdev interfaces as needed).
 * It shouldn't really be used unless there are some fatal device errors
 * that really can't be recovered in any other way.
 *
 * Callers must hold the RTNL and be able to deal with callbacks into
 * the driver while the function is running.
 */
void cfg80211_shutdown_all_interfaces(struct wiphy *wiphy);

5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921
/**
 * wiphy_ext_feature_set - set the extended feature flag
 *
 * @wiphy: the wiphy to modify.
 * @ftidx: extended feature bit index.
 *
 * The extended features are flagged in multiple bytes (see
 * &struct wiphy.@ext_features)
 */
static inline void wiphy_ext_feature_set(struct wiphy *wiphy,
					 enum nl80211_ext_feature_index ftidx)
{
	u8 *ft_byte;

	ft_byte = &wiphy->ext_features[ftidx / 8];
	*ft_byte |= BIT(ftidx % 8);
}

/**
 * wiphy_ext_feature_isset - check the extended feature flag
 *
 * @wiphy: the wiphy to modify.
 * @ftidx: extended feature bit index.
 *
 * The extended features are flagged in multiple bytes (see
 * &struct wiphy.@ext_features)
 */
static inline bool
wiphy_ext_feature_isset(struct wiphy *wiphy,
			enum nl80211_ext_feature_index ftidx)
{
	u8 ft_byte;

	ft_byte = wiphy->ext_features[ftidx / 8];
	return (ft_byte & BIT(ftidx % 8)) != 0;
}
5922

5923 5924 5925 5926 5927 5928 5929 5930
/**
 * cfg80211_free_nan_func - free NAN function
 * @f: NAN function that should be freed
 *
 * Frees all the NAN function and all it's allocated members.
 */
void cfg80211_free_nan_func(struct cfg80211_nan_func *f);

5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967
/**
 * struct cfg80211_nan_match_params - NAN match parameters
 * @type: the type of the function that triggered a match. If it is
 *	 %NL80211_NAN_FUNC_SUBSCRIBE it means that we replied to a subscriber.
 *	 If it is %NL80211_NAN_FUNC_PUBLISH, it means that we got a discovery
 *	 result.
 *	 If it is %NL80211_NAN_FUNC_FOLLOW_UP, we received a follow up.
 * @inst_id: the local instance id
 * @peer_inst_id: the instance id of the peer's function
 * @addr: the MAC address of the peer
 * @info_len: the length of the &info
 * @info: the Service Specific Info from the peer (if any)
 * @cookie: unique identifier of the corresponding function
 */
struct cfg80211_nan_match_params {
	enum nl80211_nan_function_type type;
	u8 inst_id;
	u8 peer_inst_id;
	const u8 *addr;
	u8 info_len;
	const u8 *info;
	u64 cookie;
};

/**
 * cfg80211_nan_match - report a match for a NAN function.
 * @wdev: the wireless device reporting the match
 * @match: match notification parameters
 * @gfp: allocation flags
 *
 * This function reports that the a NAN function had a match. This
 * can be a subscribe that had a match or a solicited publish that
 * was sent. It can also be a follow up that was received.
 */
void cfg80211_nan_match(struct wireless_dev *wdev,
			struct cfg80211_nan_match_params *match, gfp_t gfp);

5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983
/**
 * cfg80211_nan_func_terminated - notify about NAN function termination.
 *
 * @wdev: the wireless device reporting the match
 * @inst_id: the local instance id
 * @reason: termination reason (one of the NL80211_NAN_FUNC_TERM_REASON_*)
 * @cookie: unique NAN function identifier
 * @gfp: allocation flags
 *
 * This function reports that the a NAN function is terminated.
 */
void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
				  u8 inst_id,
				  enum nl80211_nan_func_term_reason reason,
				  u64 cookie, gfp_t gfp);

5984 5985 5986
/* ethtool helper */
void cfg80211_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info);

5987 5988 5989 5990 5991
/* Logging, debugging and troubleshooting/diagnostic helpers. */

/* wiphy_printk helpers, similar to dev_printk */

#define wiphy_printk(level, wiphy, format, args...)		\
5992
	dev_printk(level, &(wiphy)->dev, format, ##args)
5993
#define wiphy_emerg(wiphy, format, args...)			\
5994
	dev_emerg(&(wiphy)->dev, format, ##args)
5995
#define wiphy_alert(wiphy, format, args...)			\
5996
	dev_alert(&(wiphy)->dev, format, ##args)
5997
#define wiphy_crit(wiphy, format, args...)			\
5998
	dev_crit(&(wiphy)->dev, format, ##args)
5999
#define wiphy_err(wiphy, format, args...)			\
6000
	dev_err(&(wiphy)->dev, format, ##args)
6001
#define wiphy_warn(wiphy, format, args...)			\
6002
	dev_warn(&(wiphy)->dev, format, ##args)
6003
#define wiphy_notice(wiphy, format, args...)			\
6004
	dev_notice(&(wiphy)->dev, format, ##args)
6005
#define wiphy_info(wiphy, format, args...)			\
6006
	dev_info(&(wiphy)->dev, format, ##args)
6007

6008
#define wiphy_debug(wiphy, format, args...)			\
6009
	wiphy_printk(KERN_DEBUG, wiphy, format, ##args)
6010

6011
#define wiphy_dbg(wiphy, format, args...)			\
6012
	dev_dbg(&(wiphy)->dev, format, ##args)
6013 6014 6015 6016 6017 6018 6019 6020

#if defined(VERBOSE_DEBUG)
#define wiphy_vdbg	wiphy_dbg
#else
#define wiphy_vdbg(wiphy, format, args...)				\
({									\
	if (0)								\
		wiphy_printk(KERN_DEBUG, wiphy, format, ##args);	\
6021
	0;								\
6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032
})
#endif

/*
 * wiphy_WARN() acts like wiphy_printk(), but with the key difference
 * of using a WARN/WARN_ON to get the message out, including the
 * file/line information and a backtrace.
 */
#define wiphy_WARN(wiphy, format, args...)			\
	WARN(1, "wiphy: %s\n" format, wiphy_name(wiphy), ##args);

6033
#endif /* __NET_CFG80211_H */