xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/mac80211_hwsim.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * mac80211_hwsim - software simulator of 802.11 radio(s) for mac80211
4*4882a593Smuzhiyun  * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
5*4882a593Smuzhiyun  * Copyright (c) 2011, Javier Lopez <jlopex@gmail.com>
6*4882a593Smuzhiyun  * Copyright (C) 2020 Intel Corporation
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifndef __MAC80211_HWSIM_H
10*4882a593Smuzhiyun #define __MAC80211_HWSIM_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun /**
13*4882a593Smuzhiyun  * enum hwsim_tx_control_flags - flags to describe transmission info/status
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * These flags are used to give the wmediumd extra information in order to
16*4882a593Smuzhiyun  * modify its behavior for each frame
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * @HWSIM_TX_CTL_REQ_TX_STATUS: require TX status callback for this frame.
19*4882a593Smuzhiyun  * @HWSIM_TX_CTL_NO_ACK: tell the wmediumd not to wait for an ack
20*4882a593Smuzhiyun  * @HWSIM_TX_STAT_ACK: Frame was acknowledged
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  */
23*4882a593Smuzhiyun enum hwsim_tx_control_flags {
24*4882a593Smuzhiyun 	HWSIM_TX_CTL_REQ_TX_STATUS		= BIT(0),
25*4882a593Smuzhiyun 	HWSIM_TX_CTL_NO_ACK			= BIT(1),
26*4882a593Smuzhiyun 	HWSIM_TX_STAT_ACK			= BIT(2),
27*4882a593Smuzhiyun };
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun /**
30*4882a593Smuzhiyun  * DOC: Frame transmission/registration support
31*4882a593Smuzhiyun  *
32*4882a593Smuzhiyun  * Frame transmission and registration support exists to allow userspace
33*4882a593Smuzhiyun  * entities such as wmediumd to receive and process all broadcasted
34*4882a593Smuzhiyun  * frames from a mac80211_hwsim radio device.
35*4882a593Smuzhiyun  *
36*4882a593Smuzhiyun  * This allow user space applications to decide if the frame should be
37*4882a593Smuzhiyun  * dropped or not and implement a wireless medium simulator at user space.
38*4882a593Smuzhiyun  *
39*4882a593Smuzhiyun  * Registration is done by sending a register message to the driver and
40*4882a593Smuzhiyun  * will be automatically unregistered if the user application doesn't
41*4882a593Smuzhiyun  * responds to sent frames.
42*4882a593Smuzhiyun  * Once registered the user application has to take responsibility of
43*4882a593Smuzhiyun  * broadcasting the frames to all listening mac80211_hwsim radio
44*4882a593Smuzhiyun  * interfaces.
45*4882a593Smuzhiyun  *
46*4882a593Smuzhiyun  * For more technical details, see the corresponding command descriptions
47*4882a593Smuzhiyun  * below.
48*4882a593Smuzhiyun  */
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun /**
51*4882a593Smuzhiyun  * enum hwsim_commands - supported hwsim commands
52*4882a593Smuzhiyun  *
53*4882a593Smuzhiyun  * @HWSIM_CMD_UNSPEC: unspecified command to catch errors
54*4882a593Smuzhiyun  *
55*4882a593Smuzhiyun  * @HWSIM_CMD_REGISTER: request to register and received all broadcasted
56*4882a593Smuzhiyun  *	frames by any mac80211_hwsim radio device.
57*4882a593Smuzhiyun  * @HWSIM_CMD_FRAME: send/receive a broadcasted frame from/to kernel/user
58*4882a593Smuzhiyun  *	space, uses:
59*4882a593Smuzhiyun  *	%HWSIM_ATTR_ADDR_TRANSMITTER, %HWSIM_ATTR_ADDR_RECEIVER,
60*4882a593Smuzhiyun  *	%HWSIM_ATTR_FRAME, %HWSIM_ATTR_FLAGS, %HWSIM_ATTR_RX_RATE,
61*4882a593Smuzhiyun  *	%HWSIM_ATTR_SIGNAL, %HWSIM_ATTR_COOKIE, %HWSIM_ATTR_FREQ (optional)
62*4882a593Smuzhiyun  * @HWSIM_CMD_TX_INFO_FRAME: Transmission info report from user space to
63*4882a593Smuzhiyun  *	kernel, uses:
64*4882a593Smuzhiyun  *	%HWSIM_ATTR_ADDR_TRANSMITTER, %HWSIM_ATTR_FLAGS,
65*4882a593Smuzhiyun  *	%HWSIM_ATTR_TX_INFO, %WSIM_ATTR_TX_INFO_FLAGS,
66*4882a593Smuzhiyun  *	%HWSIM_ATTR_SIGNAL, %HWSIM_ATTR_COOKIE
67*4882a593Smuzhiyun  * @HWSIM_CMD_NEW_RADIO: create a new radio with the given parameters,
68*4882a593Smuzhiyun  *	returns the radio ID (>= 0) or negative on errors, if successful
69*4882a593Smuzhiyun  *	then multicast the result, uses optional parameter:
70*4882a593Smuzhiyun  *	%HWSIM_ATTR_REG_STRICT_REG, %HWSIM_ATTR_SUPPORT_P2P_DEVICE,
71*4882a593Smuzhiyun  *	%HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE, %HWSIM_ATTR_CHANNELS,
72*4882a593Smuzhiyun  *	%HWSIM_ATTR_NO_VIF, %HWSIM_ATTR_RADIO_NAME, %HWSIM_ATTR_USE_CHANCTX,
73*4882a593Smuzhiyun  *	%HWSIM_ATTR_REG_HINT_ALPHA2, %HWSIM_ATTR_REG_CUSTOM_REG,
74*4882a593Smuzhiyun  *	%HWSIM_ATTR_PERM_ADDR
75*4882a593Smuzhiyun  * @HWSIM_CMD_DEL_RADIO: destroy a radio, reply is multicasted
76*4882a593Smuzhiyun  * @HWSIM_CMD_GET_RADIO: fetch information about existing radios, uses:
77*4882a593Smuzhiyun  *	%HWSIM_ATTR_RADIO_ID
78*4882a593Smuzhiyun  * @HWSIM_CMD_ADD_MAC_ADDR: add a receive MAC address (given in the
79*4882a593Smuzhiyun  *	%HWSIM_ATTR_ADDR_RECEIVER attribute) to a device identified by
80*4882a593Smuzhiyun  *	%HWSIM_ATTR_ADDR_TRANSMITTER. This lets wmediumd forward frames
81*4882a593Smuzhiyun  *	to this receiver address for a given station.
82*4882a593Smuzhiyun  * @HWSIM_CMD_DEL_MAC_ADDR: remove the MAC address again, the attributes
83*4882a593Smuzhiyun  *	are the same as to @HWSIM_CMD_ADD_MAC_ADDR.
84*4882a593Smuzhiyun  * @__HWSIM_CMD_MAX: enum limit
85*4882a593Smuzhiyun  */
86*4882a593Smuzhiyun enum {
87*4882a593Smuzhiyun 	HWSIM_CMD_UNSPEC,
88*4882a593Smuzhiyun 	HWSIM_CMD_REGISTER,
89*4882a593Smuzhiyun 	HWSIM_CMD_FRAME,
90*4882a593Smuzhiyun 	HWSIM_CMD_TX_INFO_FRAME,
91*4882a593Smuzhiyun 	HWSIM_CMD_NEW_RADIO,
92*4882a593Smuzhiyun 	HWSIM_CMD_DEL_RADIO,
93*4882a593Smuzhiyun 	HWSIM_CMD_GET_RADIO,
94*4882a593Smuzhiyun 	HWSIM_CMD_ADD_MAC_ADDR,
95*4882a593Smuzhiyun 	HWSIM_CMD_DEL_MAC_ADDR,
96*4882a593Smuzhiyun 	__HWSIM_CMD_MAX,
97*4882a593Smuzhiyun };
98*4882a593Smuzhiyun #define HWSIM_CMD_MAX (_HWSIM_CMD_MAX - 1)
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun #define HWSIM_CMD_CREATE_RADIO   HWSIM_CMD_NEW_RADIO
101*4882a593Smuzhiyun #define HWSIM_CMD_DESTROY_RADIO  HWSIM_CMD_DEL_RADIO
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun /**
104*4882a593Smuzhiyun  * enum hwsim_attrs - hwsim netlink attributes
105*4882a593Smuzhiyun  *
106*4882a593Smuzhiyun  * @HWSIM_ATTR_UNSPEC: unspecified attribute to catch errors
107*4882a593Smuzhiyun  *
108*4882a593Smuzhiyun  * @HWSIM_ATTR_ADDR_RECEIVER: MAC address of the radio device that
109*4882a593Smuzhiyun  *	the frame is broadcasted to
110*4882a593Smuzhiyun  * @HWSIM_ATTR_ADDR_TRANSMITTER: MAC address of the radio device that
111*4882a593Smuzhiyun  *	the frame was broadcasted from
112*4882a593Smuzhiyun  * @HWSIM_ATTR_FRAME: Data array
113*4882a593Smuzhiyun  * @HWSIM_ATTR_FLAGS: mac80211 transmission flags, used to process
114*4882a593Smuzhiyun 	properly the frame at user space
115*4882a593Smuzhiyun  * @HWSIM_ATTR_RX_RATE: estimated rx rate index for this frame at user
116*4882a593Smuzhiyun 	space
117*4882a593Smuzhiyun  * @HWSIM_ATTR_SIGNAL: estimated RX signal for this frame at user
118*4882a593Smuzhiyun 	space
119*4882a593Smuzhiyun  * @HWSIM_ATTR_TX_INFO: ieee80211_tx_rate array
120*4882a593Smuzhiyun  * @HWSIM_ATTR_COOKIE: sk_buff cookie to identify the frame
121*4882a593Smuzhiyun  * @HWSIM_ATTR_CHANNELS: u32 attribute used with the %HWSIM_CMD_CREATE_RADIO
122*4882a593Smuzhiyun  *	command giving the number of channels supported by the new radio
123*4882a593Smuzhiyun  * @HWSIM_ATTR_RADIO_ID: u32 attribute used with %HWSIM_CMD_DESTROY_RADIO
124*4882a593Smuzhiyun  *	only to destroy a radio
125*4882a593Smuzhiyun  * @HWSIM_ATTR_REG_HINT_ALPHA2: alpha2 for regulatoro driver hint
126*4882a593Smuzhiyun  *	(nla string, length 2)
127*4882a593Smuzhiyun  * @HWSIM_ATTR_REG_CUSTOM_REG: custom regulatory domain index (u32 attribute)
128*4882a593Smuzhiyun  * @HWSIM_ATTR_REG_STRICT_REG: request REGULATORY_STRICT_REG (flag attribute)
129*4882a593Smuzhiyun  * @HWSIM_ATTR_SUPPORT_P2P_DEVICE: support P2P Device virtual interface (flag)
130*4882a593Smuzhiyun  * @HWSIM_ATTR_USE_CHANCTX: used with the %HWSIM_CMD_CREATE_RADIO
131*4882a593Smuzhiyun  *	command to force use of channel contexts even when only a
132*4882a593Smuzhiyun  *	single channel is supported
133*4882a593Smuzhiyun  * @HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE: used with the %HWSIM_CMD_CREATE_RADIO
134*4882a593Smuzhiyun  *	command to force radio removal when process that created the radio dies
135*4882a593Smuzhiyun  * @HWSIM_ATTR_RADIO_NAME: Name of radio, e.g. phy666
136*4882a593Smuzhiyun  * @HWSIM_ATTR_NO_VIF:  Do not create vif (wlanX) when creating radio.
137*4882a593Smuzhiyun  * @HWSIM_ATTR_FREQ: Frequency at which packet is transmitted or received.
138*4882a593Smuzhiyun  * @HWSIM_ATTR_TX_INFO_FLAGS: additional flags for corresponding
139*4882a593Smuzhiyun  *	rates of %HWSIM_ATTR_TX_INFO
140*4882a593Smuzhiyun  * @HWSIM_ATTR_PERM_ADDR: permanent mac address of new radio
141*4882a593Smuzhiyun  * @HWSIM_ATTR_IFTYPE_SUPPORT: u32 attribute of supported interface types bits
142*4882a593Smuzhiyun  * @HWSIM_ATTR_CIPHER_SUPPORT: u32 array of supported cipher types
143*4882a593Smuzhiyun  * @__HWSIM_ATTR_MAX: enum limit
144*4882a593Smuzhiyun  */
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun enum {
148*4882a593Smuzhiyun 	HWSIM_ATTR_UNSPEC,
149*4882a593Smuzhiyun 	HWSIM_ATTR_ADDR_RECEIVER,
150*4882a593Smuzhiyun 	HWSIM_ATTR_ADDR_TRANSMITTER,
151*4882a593Smuzhiyun 	HWSIM_ATTR_FRAME,
152*4882a593Smuzhiyun 	HWSIM_ATTR_FLAGS,
153*4882a593Smuzhiyun 	HWSIM_ATTR_RX_RATE,
154*4882a593Smuzhiyun 	HWSIM_ATTR_SIGNAL,
155*4882a593Smuzhiyun 	HWSIM_ATTR_TX_INFO,
156*4882a593Smuzhiyun 	HWSIM_ATTR_COOKIE,
157*4882a593Smuzhiyun 	HWSIM_ATTR_CHANNELS,
158*4882a593Smuzhiyun 	HWSIM_ATTR_RADIO_ID,
159*4882a593Smuzhiyun 	HWSIM_ATTR_REG_HINT_ALPHA2,
160*4882a593Smuzhiyun 	HWSIM_ATTR_REG_CUSTOM_REG,
161*4882a593Smuzhiyun 	HWSIM_ATTR_REG_STRICT_REG,
162*4882a593Smuzhiyun 	HWSIM_ATTR_SUPPORT_P2P_DEVICE,
163*4882a593Smuzhiyun 	HWSIM_ATTR_USE_CHANCTX,
164*4882a593Smuzhiyun 	HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE,
165*4882a593Smuzhiyun 	HWSIM_ATTR_RADIO_NAME,
166*4882a593Smuzhiyun 	HWSIM_ATTR_NO_VIF,
167*4882a593Smuzhiyun 	HWSIM_ATTR_FREQ,
168*4882a593Smuzhiyun 	HWSIM_ATTR_PAD,
169*4882a593Smuzhiyun 	HWSIM_ATTR_TX_INFO_FLAGS,
170*4882a593Smuzhiyun 	HWSIM_ATTR_PERM_ADDR,
171*4882a593Smuzhiyun 	HWSIM_ATTR_IFTYPE_SUPPORT,
172*4882a593Smuzhiyun 	HWSIM_ATTR_CIPHER_SUPPORT,
173*4882a593Smuzhiyun 	__HWSIM_ATTR_MAX,
174*4882a593Smuzhiyun };
175*4882a593Smuzhiyun #define HWSIM_ATTR_MAX (__HWSIM_ATTR_MAX - 1)
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun /**
178*4882a593Smuzhiyun  * struct hwsim_tx_rate - rate selection/status
179*4882a593Smuzhiyun  *
180*4882a593Smuzhiyun  * @idx: rate index to attempt to send with
181*4882a593Smuzhiyun  * @count: number of tries in this rate before going to the next rate
182*4882a593Smuzhiyun  *
183*4882a593Smuzhiyun  * A value of -1 for @idx indicates an invalid rate and, if used
184*4882a593Smuzhiyun  * in an array of retry rates, that no more rates should be tried.
185*4882a593Smuzhiyun  *
186*4882a593Smuzhiyun  * When used for transmit status reporting, the driver should
187*4882a593Smuzhiyun  * always report the rate and number of retries used.
188*4882a593Smuzhiyun  *
189*4882a593Smuzhiyun  */
190*4882a593Smuzhiyun struct hwsim_tx_rate {
191*4882a593Smuzhiyun 	s8 idx;
192*4882a593Smuzhiyun 	u8 count;
193*4882a593Smuzhiyun } __packed;
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun /**
196*4882a593Smuzhiyun  * enum hwsim_tx_rate_flags - per-rate flags set by the rate control algorithm.
197*4882a593Smuzhiyun  *	Inspired by structure mac80211_rate_control_flags. New flags may be
198*4882a593Smuzhiyun  *	appended, but old flags not deleted, to keep compatibility for
199*4882a593Smuzhiyun  *	userspace.
200*4882a593Smuzhiyun  *
201*4882a593Smuzhiyun  * These flags are set by the Rate control algorithm for each rate during tx,
202*4882a593Smuzhiyun  * in the @flags member of struct ieee80211_tx_rate.
203*4882a593Smuzhiyun  *
204*4882a593Smuzhiyun  * @MAC80211_HWSIM_TX_RC_USE_RTS_CTS: Use RTS/CTS exchange for this rate.
205*4882a593Smuzhiyun  * @MAC80211_HWSIM_TX_RC_USE_CTS_PROTECT: CTS-to-self protection is required.
206*4882a593Smuzhiyun  *	This is set if the current BSS requires ERP protection.
207*4882a593Smuzhiyun  * @MAC80211_HWSIM_TX_RC_USE_SHORT_PREAMBLE: Use short preamble.
208*4882a593Smuzhiyun  * @MAC80211_HWSIM_TX_RC_MCS: HT rate.
209*4882a593Smuzhiyun  * @MAC80211_HWSIM_TX_RC_VHT_MCS: VHT MCS rate, in this case the idx field is
210*4882a593Smuzhiyun  *	split into a higher 4 bits (Nss) and lower 4 bits (MCS number)
211*4882a593Smuzhiyun  * @MAC80211_HWSIM_TX_RC_GREEN_FIELD: Indicates whether this rate should be used
212*4882a593Smuzhiyun  *	in Greenfield mode.
213*4882a593Smuzhiyun  * @MAC80211_HWSIM_TX_RC_40_MHZ_WIDTH: Indicates if the Channel Width should be
214*4882a593Smuzhiyun  *	40 MHz.
215*4882a593Smuzhiyun  * @MAC80211_HWSIM_TX_RC_80_MHZ_WIDTH: Indicates 80 MHz transmission
216*4882a593Smuzhiyun  * @MAC80211_HWSIM_TX_RC_160_MHZ_WIDTH: Indicates 160 MHz transmission
217*4882a593Smuzhiyun  *	(80+80 isn't supported yet)
218*4882a593Smuzhiyun  * @MAC80211_HWSIM_TX_RC_DUP_DATA: The frame should be transmitted on both of
219*4882a593Smuzhiyun  *	the adjacent 20 MHz channels, if the current channel type is
220*4882a593Smuzhiyun  *	NL80211_CHAN_HT40MINUS or NL80211_CHAN_HT40PLUS.
221*4882a593Smuzhiyun  * @MAC80211_HWSIM_TX_RC_SHORT_GI: Short Guard interval should be used for this
222*4882a593Smuzhiyun  *	rate.
223*4882a593Smuzhiyun  */
224*4882a593Smuzhiyun enum hwsim_tx_rate_flags {
225*4882a593Smuzhiyun 	MAC80211_HWSIM_TX_RC_USE_RTS_CTS		= BIT(0),
226*4882a593Smuzhiyun 	MAC80211_HWSIM_TX_RC_USE_CTS_PROTECT		= BIT(1),
227*4882a593Smuzhiyun 	MAC80211_HWSIM_TX_RC_USE_SHORT_PREAMBLE	= BIT(2),
228*4882a593Smuzhiyun 
229*4882a593Smuzhiyun 	/* rate index is an HT/VHT MCS instead of an index */
230*4882a593Smuzhiyun 	MAC80211_HWSIM_TX_RC_MCS			= BIT(3),
231*4882a593Smuzhiyun 	MAC80211_HWSIM_TX_RC_GREEN_FIELD		= BIT(4),
232*4882a593Smuzhiyun 	MAC80211_HWSIM_TX_RC_40_MHZ_WIDTH		= BIT(5),
233*4882a593Smuzhiyun 	MAC80211_HWSIM_TX_RC_DUP_DATA		= BIT(6),
234*4882a593Smuzhiyun 	MAC80211_HWSIM_TX_RC_SHORT_GI		= BIT(7),
235*4882a593Smuzhiyun 	MAC80211_HWSIM_TX_RC_VHT_MCS			= BIT(8),
236*4882a593Smuzhiyun 	MAC80211_HWSIM_TX_RC_80_MHZ_WIDTH		= BIT(9),
237*4882a593Smuzhiyun 	MAC80211_HWSIM_TX_RC_160_MHZ_WIDTH		= BIT(10),
238*4882a593Smuzhiyun };
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun /**
241*4882a593Smuzhiyun  * struct hwsim_tx_rate - rate selection/status
242*4882a593Smuzhiyun  *
243*4882a593Smuzhiyun  * @idx: rate index to attempt to send with
244*4882a593Smuzhiyun  * @count: number of tries in this rate before going to the next rate
245*4882a593Smuzhiyun  *
246*4882a593Smuzhiyun  * A value of -1 for @idx indicates an invalid rate and, if used
247*4882a593Smuzhiyun  * in an array of retry rates, that no more rates should be tried.
248*4882a593Smuzhiyun  *
249*4882a593Smuzhiyun  * When used for transmit status reporting, the driver should
250*4882a593Smuzhiyun  * always report the rate and number of retries used.
251*4882a593Smuzhiyun  *
252*4882a593Smuzhiyun  */
253*4882a593Smuzhiyun struct hwsim_tx_rate_flag {
254*4882a593Smuzhiyun 	s8 idx;
255*4882a593Smuzhiyun 	u16 flags;
256*4882a593Smuzhiyun } __packed;
257*4882a593Smuzhiyun 
258*4882a593Smuzhiyun /**
259*4882a593Smuzhiyun  * DOC: Frame transmission support over virtio
260*4882a593Smuzhiyun  *
261*4882a593Smuzhiyun  * Frame transmission is also supported over virtio to allow communication
262*4882a593Smuzhiyun  * with external entities.
263*4882a593Smuzhiyun  */
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun /**
266*4882a593Smuzhiyun  * enum hwsim_vqs - queues for virtio frame transmission
267*4882a593Smuzhiyun  *
268*4882a593Smuzhiyun  * @HWSIM_VQ_TX: send frames to external entity
269*4882a593Smuzhiyun  * @HWSIM_VQ_RX: receive frames and transmission info reports
270*4882a593Smuzhiyun  * @HWSIM_NUM_VQS: enum limit
271*4882a593Smuzhiyun  */
272*4882a593Smuzhiyun enum {
273*4882a593Smuzhiyun 	HWSIM_VQ_TX,
274*4882a593Smuzhiyun 	HWSIM_VQ_RX,
275*4882a593Smuzhiyun 	HWSIM_NUM_VQS,
276*4882a593Smuzhiyun };
277*4882a593Smuzhiyun #endif /* __MAC80211_HWSIM_H */
278