Skip to content

Commit 6e3d6ca

Browse files
BenjaminBeichlerjmberg-intel
authored andcommitted
mac80211_hwsim: add hwsim_tx_rate_flags to netlink attributes
For correct interpretation of a tx rate, the corresponding rate flags are needed (e.g. whether a HT-MCS rate or a legacy rate) and moreover for more correct simulation the other infos of the flags are important (like short-GI). Keeping compatibility, the flags are not integrated into the existing hwsim_tx_rate, but transmitted as an additional netlink attribute. Signed-off-by: Benjamin Beichler <[email protected]> Signed-off-by: Johannes Berg <[email protected]>
1 parent c6509cc commit 6e3d6ca

File tree

2 files changed

+107
-2
lines changed

2 files changed

+107
-2
lines changed

drivers/net/wireless/mac80211_hwsim.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,36 @@ static int hwsim_unicast_netgroup(struct mac80211_hwsim_data *data,
10181018
return res;
10191019
}
10201020

1021+
static inline u16 trans_tx_rate_flags_ieee2hwsim(struct ieee80211_tx_rate *rate)
1022+
{
1023+
u16 result = 0;
1024+
1025+
if (rate->flags & IEEE80211_TX_RC_USE_RTS_CTS)
1026+
result |= MAC80211_HWSIM_TX_RC_USE_RTS_CTS;
1027+
if (rate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
1028+
result |= MAC80211_HWSIM_TX_RC_USE_CTS_PROTECT;
1029+
if (rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
1030+
result |= MAC80211_HWSIM_TX_RC_USE_SHORT_PREAMBLE;
1031+
if (rate->flags & IEEE80211_TX_RC_MCS)
1032+
result |= MAC80211_HWSIM_TX_RC_MCS;
1033+
if (rate->flags & IEEE80211_TX_RC_GREEN_FIELD)
1034+
result |= MAC80211_HWSIM_TX_RC_GREEN_FIELD;
1035+
if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
1036+
result |= MAC80211_HWSIM_TX_RC_40_MHZ_WIDTH;
1037+
if (rate->flags & IEEE80211_TX_RC_DUP_DATA)
1038+
result |= MAC80211_HWSIM_TX_RC_DUP_DATA;
1039+
if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
1040+
result |= MAC80211_HWSIM_TX_RC_SHORT_GI;
1041+
if (rate->flags & IEEE80211_TX_RC_VHT_MCS)
1042+
result |= MAC80211_HWSIM_TX_RC_VHT_MCS;
1043+
if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
1044+
result |= MAC80211_HWSIM_TX_RC_80_MHZ_WIDTH;
1045+
if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
1046+
result |= MAC80211_HWSIM_TX_RC_160_MHZ_WIDTH;
1047+
1048+
return result;
1049+
}
1050+
10211051
static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
10221052
struct sk_buff *my_skb,
10231053
int dst_portid)
@@ -1030,6 +1060,7 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
10301060
unsigned int hwsim_flags = 0;
10311061
int i;
10321062
struct hwsim_tx_rate tx_attempts[IEEE80211_TX_MAX_RATES];
1063+
struct hwsim_tx_rate_flag tx_attempts_flags[IEEE80211_TX_MAX_RATES];
10331064
uintptr_t cookie;
10341065

10351066
if (data->ps != PS_DISABLED)
@@ -1081,14 +1112,23 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
10811112

10821113
for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
10831114
tx_attempts[i].idx = info->status.rates[i].idx;
1115+
tx_attempts_flags[i].idx = info->status.rates[i].idx;
10841116
tx_attempts[i].count = info->status.rates[i].count;
1117+
tx_attempts_flags[i].flags =
1118+
trans_tx_rate_flags_ieee2hwsim(
1119+
&info->status.rates[i]);
10851120
}
10861121

10871122
if (nla_put(skb, HWSIM_ATTR_TX_INFO,
10881123
sizeof(struct hwsim_tx_rate)*IEEE80211_TX_MAX_RATES,
10891124
tx_attempts))
10901125
goto nla_put_failure;
10911126

1127+
if (nla_put(skb, HWSIM_ATTR_TX_INFO_FLAGS,
1128+
sizeof(struct hwsim_tx_rate_flag) * IEEE80211_TX_MAX_RATES,
1129+
tx_attempts_flags))
1130+
goto nla_put_failure;
1131+
10921132
/* We create a cookie to identify this skb */
10931133
data->pending_cookie++;
10941134
cookie = data->pending_cookie;
@@ -2983,7 +3023,6 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2,
29833023
for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
29843024
txi->status.rates[i].idx = tx_attempts[i].idx;
29853025
txi->status.rates[i].count = tx_attempts[i].count;
2986-
/*txi->status.rates[i].flags = 0;*/
29873026
}
29883027

29893028
txi->status.ack_signal = nla_get_u32(info->attrs[HWSIM_ATTR_SIGNAL]);

drivers/net/wireless/mac80211_hwsim.h

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ enum hwsim_tx_control_flags {
6464
* @HWSIM_CMD_TX_INFO_FRAME: Transmission info report from user space to
6565
* kernel, uses:
6666
* %HWSIM_ATTR_ADDR_TRANSMITTER, %HWSIM_ATTR_FLAGS,
67-
* %HWSIM_ATTR_TX_INFO, %HWSIM_ATTR_SIGNAL, %HWSIM_ATTR_COOKIE
67+
* %HWSIM_ATTR_TX_INFO, %WSIM_ATTR_TX_INFO_FLAGS,
68+
* %HWSIM_ATTR_SIGNAL, %HWSIM_ATTR_COOKIE
6869
* @HWSIM_CMD_NEW_RADIO: create a new radio with the given parameters,
6970
* returns the radio ID (>= 0) or negative on errors, if successful
7071
* then multicast the result
@@ -123,6 +124,8 @@ enum {
123124
* @HWSIM_ATTR_RADIO_NAME: Name of radio, e.g. phy666
124125
* @HWSIM_ATTR_NO_VIF: Do not create vif (wlanX) when creating radio.
125126
* @HWSIM_ATTR_FREQ: Frequency at which packet is transmitted or received.
127+
* @HWSIM_ATTR_TX_INFO_FLAGS: additional flags for corresponding
128+
* rates of %HWSIM_ATTR_TX_INFO
126129
* @__HWSIM_ATTR_MAX: enum limit
127130
*/
128131

@@ -149,6 +152,7 @@ enum {
149152
HWSIM_ATTR_NO_VIF,
150153
HWSIM_ATTR_FREQ,
151154
HWSIM_ATTR_PAD,
155+
HWSIM_ATTR_TX_INFO_FLAGS,
152156
__HWSIM_ATTR_MAX,
153157
};
154158
#define HWSIM_ATTR_MAX (__HWSIM_ATTR_MAX - 1)
@@ -171,4 +175,66 @@ struct hwsim_tx_rate {
171175
u8 count;
172176
} __packed;
173177

178+
/**
179+
* enum hwsim_tx_rate_flags - per-rate flags set by the rate control algorithm.
180+
* Inspired by structure mac80211_rate_control_flags. New flags may be
181+
* appended, but old flags not deleted, to keep compatibility for
182+
* userspace.
183+
*
184+
* These flags are set by the Rate control algorithm for each rate during tx,
185+
* in the @flags member of struct ieee80211_tx_rate.
186+
*
187+
* @MAC80211_HWSIM_TX_RC_USE_RTS_CTS: Use RTS/CTS exchange for this rate.
188+
* @MAC80211_HWSIM_TX_RC_USE_CTS_PROTECT: CTS-to-self protection is required.
189+
* This is set if the current BSS requires ERP protection.
190+
* @MAC80211_HWSIM_TX_RC_USE_SHORT_PREAMBLE: Use short preamble.
191+
* @MAC80211_HWSIM_TX_RC_MCS: HT rate.
192+
* @MAC80211_HWSIM_TX_RC_VHT_MCS: VHT MCS rate, in this case the idx field is
193+
* split into a higher 4 bits (Nss) and lower 4 bits (MCS number)
194+
* @MAC80211_HWSIM_TX_RC_GREEN_FIELD: Indicates whether this rate should be used
195+
* in Greenfield mode.
196+
* @MAC80211_HWSIM_TX_RC_40_MHZ_WIDTH: Indicates if the Channel Width should be
197+
* 40 MHz.
198+
* @MAC80211_HWSIM_TX_RC_80_MHZ_WIDTH: Indicates 80 MHz transmission
199+
* @MAC80211_HWSIM_TX_RC_160_MHZ_WIDTH: Indicates 160 MHz transmission
200+
* (80+80 isn't supported yet)
201+
* @MAC80211_HWSIM_TX_RC_DUP_DATA: The frame should be transmitted on both of
202+
* the adjacent 20 MHz channels, if the current channel type is
203+
* NL80211_CHAN_HT40MINUS or NL80211_CHAN_HT40PLUS.
204+
* @MAC80211_HWSIM_TX_RC_SHORT_GI: Short Guard interval should be used for this
205+
* rate.
206+
*/
207+
enum hwsim_tx_rate_flags {
208+
MAC80211_HWSIM_TX_RC_USE_RTS_CTS = BIT(0),
209+
MAC80211_HWSIM_TX_RC_USE_CTS_PROTECT = BIT(1),
210+
MAC80211_HWSIM_TX_RC_USE_SHORT_PREAMBLE = BIT(2),
211+
212+
/* rate index is an HT/VHT MCS instead of an index */
213+
MAC80211_HWSIM_TX_RC_MCS = BIT(3),
214+
MAC80211_HWSIM_TX_RC_GREEN_FIELD = BIT(4),
215+
MAC80211_HWSIM_TX_RC_40_MHZ_WIDTH = BIT(5),
216+
MAC80211_HWSIM_TX_RC_DUP_DATA = BIT(6),
217+
MAC80211_HWSIM_TX_RC_SHORT_GI = BIT(7),
218+
MAC80211_HWSIM_TX_RC_VHT_MCS = BIT(8),
219+
MAC80211_HWSIM_TX_RC_80_MHZ_WIDTH = BIT(9),
220+
MAC80211_HWSIM_TX_RC_160_MHZ_WIDTH = BIT(10),
221+
};
222+
223+
/**
224+
* struct hwsim_tx_rate - rate selection/status
225+
*
226+
* @idx: rate index to attempt to send with
227+
* @count: number of tries in this rate before going to the next rate
228+
*
229+
* A value of -1 for @idx indicates an invalid rate and, if used
230+
* in an array of retry rates, that no more rates should be tried.
231+
*
232+
* When used for transmit status reporting, the driver should
233+
* always report the rate and number of retries used.
234+
*
235+
*/
236+
struct hwsim_tx_rate_flag {
237+
s8 idx;
238+
u16 flags;
239+
} __packed;
174240
#endif /* __MAC80211_HWSIM_H */

0 commit comments

Comments
 (0)