2023-04-12 23:13:59

by Gilad Itzkovitch

[permalink] [raw]
Subject: [PATCH v4 1/2] wifi: cfg80211: Add short_beacon_tail/head/period

From: Kieran Frewen <[email protected]>

Support variables to handle short beacon period and adding a
separate tail/head for them. Also, add short beacon period,
head and tail attributes for user configuration.

Signed-off-by: Kieran Frewen <[email protected]>
Co-developed-by: Gilad Itzkovitch <[email protected]>
Signed-off-by: Gilad Itzkovitch <[email protected]>
---

Notes:
V4:
- squash cfg80211 commits together
- add protection for short head/tail with S1G band check
- better validation rule for short_beacon_period
and align its types

include/net/cfg80211.h | 10 +++-
include/uapi/linux/nl80211.h | 10 ++++
net/wireless/nl80211.c | 101 ++++++++++++++++++++++++++---------
3 files changed, 96 insertions(+), 25 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 9e04f69712b1..6d0a31d85888 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -1211,8 +1211,13 @@ struct cfg80211_rnr_elems {
* or %NULL if not changed
* @tail: tail portion of beacon (after TIM IE)
* or %NULL if not changed
+ * @short_head: head portion of short beacon or %NULL if not changed
+ * @short_tail: short tail portion of beacon (after TIM IE)
+ * or %NULL if not changed
* @head_len: length of @head
* @tail_len: length of @tail
+ * @short_head_len: length of @short_head
+ * @short_tail_len: length of @short_tail
* @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
@@ -1241,6 +1246,7 @@ struct cfg80211_beacon_data {
unsigned int link_id;

const u8 *head, *tail;
+ const u8 *short_head, *short_tail;
const u8 *beacon_ies;
const u8 *proberesp_ies;
const u8 *assocresp_ies;
@@ -1252,6 +1258,7 @@ struct cfg80211_beacon_data {
s8 ftm_responder;

size_t head_len, tail_len;
+ size_t short_head_len, short_tail_len;
size_t beacon_ies_len;
size_t proberesp_ies_len;
size_t assocresp_ies_len;
@@ -1324,6 +1331,7 @@ struct cfg80211_unsol_bcast_probe_resp {
* @beacon: beacon data
* @beacon_interval: beacon interval
* @dtim_period: DTIM period
+ * @short_beacon_period: S1G short beacon period
* @ssid: SSID to be used in the BSS (note: may be %NULL if not provided from
* user space)
* @ssid_len: length of @ssid
@@ -1365,7 +1373,7 @@ struct cfg80211_ap_settings {

struct cfg80211_beacon_data beacon;

- int beacon_interval, dtim_period;
+ int beacon_interval, dtim_period, short_beacon_period;
const u8 *ssid;
size_t ssid_len;
enum nl80211_hidden_ssid hidden_ssid;
diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index c59fec406da5..09ff24ed30ff 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -2787,6 +2787,12 @@ enum nl80211_commands {
* indicates that the sub-channel is punctured. Higher 16 bits are
* reserved.
*
+ * @NL80211_ATTR_SHORT_BEACON_PERIOD: (u16) period for S1G long beacon
+ * @NL80211_ATTR_SHORT_BEACON_HEAD: portion of the S1G short beacon before
+ * the TIM element
+ * @NL80211_ATTR_SHORT_BEACON_TAIL: portion of the S1G short beacon after
+ * the TIM element
+ *
* @NL80211_ATTR_MAX_HW_TIMESTAMP_PEERS: Maximum number of peers that HW
* timestamping can be enabled for concurrently (u16), a wiphy attribute.
* A value of 0xffff indicates setting for all peers (i.e. not specifying
@@ -3336,6 +3342,10 @@ enum nl80211_attrs {

NL80211_ATTR_PUNCT_BITMAP,

+ NL80211_ATTR_SHORT_BEACON_PERIOD,
+ NL80211_ATTR_SHORT_BEACON_HEAD,
+ NL80211_ATTR_SHORT_BEACON_TAIL,
+
NL80211_ATTR_MAX_HW_TIMESTAMP_PEERS,
NL80211_ATTR_HW_TIMESTAMP_ENABLED,

diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 2c9edb015652..32b648315cc6 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -231,12 +231,18 @@ static int validate_beacon_head(const struct nlattr *attr,
const struct ieee80211_mgmt *mgmt = (void *)data;
unsigned int fixedlen, hdrlen;
bool s1g_bcn;
+ bool s1g_short_bcn;

if (len < offsetofend(typeof(*mgmt), frame_control))
goto err;

s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control);
- if (s1g_bcn) {
+ s1g_short_bcn = ieee80211_is_s1g_short_beacon(mgmt->frame_control);
+ if (s1g_short_bcn) {
+ fixedlen = offsetof(struct ieee80211_ext,
+ u.s1g_short_beacon.variable);
+ hdrlen = offsetof(struct ieee80211_ext, u.s1g_short_beacon);
+ } else if (s1g_bcn) {
fixedlen = offsetof(struct ieee80211_ext,
u.s1g_beacon.variable);
hdrlen = offsetof(struct ieee80211_ext, u.s1g_beacon);
@@ -263,7 +269,12 @@ static int validate_beacon_head(const struct nlattr *attr,
return 0;

err:
- NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head");
+ if (s1g_short_bcn)
+ NL_SET_ERR_MSG_ATTR(extack, attr, "malformed S1G short beacon head");
+ else if (s1g_bcn)
+ NL_SET_ERR_MSG_ATTR(extack, attr, "malformed S1G beacon head");
+ else
+ NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head");
return -EINVAL;
}

@@ -810,6 +821,12 @@ static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
[NL80211_ATTR_MAX_HW_TIMESTAMP_PEERS] = { .type = NLA_U16 },
[NL80211_ATTR_HW_TIMESTAMP_ENABLED] = { .type = NLA_FLAG },
[NL80211_ATTR_EMA_RNR_ELEMS] = { .type = NLA_NESTED },
+
+ [NL80211_ATTR_SHORT_BEACON_PERIOD] = NLA_POLICY_MIN(NLA_U16, 1),
+ [NL80211_ATTR_SHORT_BEACON_HEAD] =
+ NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head, IEEE80211_MAX_DATA_LEN),
+ [NL80211_ATTR_SHORT_BEACON_TAIL] =
+ NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, IEEE80211_MAX_DATA_LEN),
};

/* policy for the key attributes */
@@ -5495,7 +5512,8 @@ static int nl80211_parse_he_bss_color(struct nlattr *attrs,
static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
struct nlattr *attrs[],
struct cfg80211_beacon_data *bcn,
- struct netlink_ext_ack *extack)
+ struct netlink_ext_ack *extack,
+ bool is_s1g_band)
{
bool haveinfo = false;
int err;
@@ -5505,10 +5523,18 @@ static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
bcn->link_id = nl80211_link_id(attrs);

if (attrs[NL80211_ATTR_BEACON_HEAD]) {
+ struct ieee80211_mgmt *mgmt;
+
bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
if (!bcn->head_len)
return -EINVAL;
+
+ mgmt = (void *)bcn->head;
+ if (ieee80211_is_s1g_beacon(mgmt->frame_control) && !is_s1g_band)
+ return -EINVAL;
+ else if (ieee80211_is_beacon(mgmt->frame_control) && is_s1g_band)
+ return -EINVAL;
haveinfo = true;
}

@@ -5518,6 +5544,22 @@ static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
haveinfo = true;
}

+ if (attrs[NL80211_ATTR_SHORT_BEACON_HEAD]) {
+ if (!is_s1g_band)
+ return -EINVAL;
+ bcn->short_head = nla_data(attrs[NL80211_ATTR_SHORT_BEACON_HEAD]);
+ bcn->short_head_len = nla_len(attrs[NL80211_ATTR_SHORT_BEACON_HEAD]);
+ haveinfo = true;
+ }
+
+ if (attrs[NL80211_ATTR_SHORT_BEACON_TAIL]) {
+ if (!is_s1g_band)
+ return -EINVAL;
+ bcn->short_tail = nla_data(attrs[NL80211_ATTR_SHORT_BEACON_TAIL]);
+ bcn->short_tail_len = nla_len(attrs[NL80211_ATTR_SHORT_BEACON_TAIL]);
+ haveinfo = true;
+ }
+
if (!haveinfo)
return -EINVAL;

@@ -5925,8 +5967,24 @@ static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
if (!params)
return -ENOMEM;

+ if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
+ err = nl80211_parse_chandef(rdev, info, &params->chandef);
+ if (err)
+ goto out;
+ } else if (wdev->valid_links) {
+ /* with MLD need to specify the channel configuration */
+ err = -EINVAL;
+ goto out;
+ } else if (wdev->u.ap.preset_chandef.chan) {
+ params->chandef = wdev->u.ap.preset_chandef;
+ } else if (!nl80211_get_ap_channel(rdev, params)) {
+ err = -EINVAL;
+ goto out;
+ }
+
err = nl80211_parse_beacon(rdev, info->attrs, &params->beacon,
- info->extack);
+ info->extack,
+ params->chandef.chan->band == NL80211_BAND_S1GHZ);
if (err)
goto out;

@@ -5934,6 +5992,10 @@ static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
params->dtim_period =
nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
+ params->short_beacon_period = 1;
+ if (info->attrs[NL80211_ATTR_SHORT_BEACON_PERIOD])
+ params->short_beacon_period =
+ nla_get_u16(info->attrs[NL80211_ATTR_SHORT_BEACON_PERIOD]);

err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
params->beacon_interval);
@@ -6030,21 +6092,6 @@ static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
}
}

- if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
- err = nl80211_parse_chandef(rdev, info, &params->chandef);
- if (err)
- goto out;
- } else if (wdev->valid_links) {
- /* with MLD need to specify the channel configuration */
- err = -EINVAL;
- goto out;
- } else if (wdev->u.ap.preset_chandef.chan) {
- params->chandef = wdev->u.ap.preset_chandef;
- } else if (!nl80211_get_ap_channel(rdev, params)) {
- err = -EINVAL;
- goto out;
- }
-
if (info->attrs[NL80211_ATTR_PUNCT_BITMAP]) {
err = nl80211_parse_punct_bitmap(rdev, info,
&params->chandef,
@@ -6227,7 +6274,8 @@ static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
if (!wdev->links[link_id].ap.beacon_interval)
return -EINVAL;

- err = nl80211_parse_beacon(rdev, info->attrs, &params, info->extack);
+ err = nl80211_parse_beacon(rdev, info->attrs, &params, info->extack,
+ wdev->links[link_id].ap.chandef.chan->band == NL80211_BAND_S1GHZ);
if (err)
goto out;

@@ -10098,7 +10146,8 @@ static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
goto skip_beacons;

err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon_after,
- info->extack);
+ info->extack,
+ wdev->links[link_id].ap.chandef.chan->band == NL80211_BAND_S1GHZ);
if (err)
goto free;

@@ -10116,7 +10165,8 @@ static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
goto free;

err = nl80211_parse_beacon(rdev, csa_attrs, &params.beacon_csa,
- info->extack);
+ info->extack,
+ wdev->links[link_id].ap.chandef.chan->band == NL80211_BAND_S1GHZ);
if (err)
goto free;

@@ -15931,6 +15981,7 @@ static int nl80211_color_change(struct sk_buff *skb, struct genl_info *info)
struct cfg80211_color_change_settings params = {};
struct net_device *dev = info->user_ptr[1];
struct wireless_dev *wdev = dev->ieee80211_ptr;
+ unsigned int link_id = nl80211_link_id(info->attrs);
struct nlattr **tb;
u16 offset;
int err;
@@ -15954,7 +16005,8 @@ static int nl80211_color_change(struct sk_buff *skb, struct genl_info *info)
params.color = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR]);

err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon_next,
- info->extack);
+ info->extack,
+ wdev->links[link_id].ap.chandef.chan->band == NL80211_BAND_S1GHZ);
if (err)
return err;

@@ -15969,7 +16021,8 @@ static int nl80211_color_change(struct sk_buff *skb, struct genl_info *info)
goto out;

err = nl80211_parse_beacon(rdev, tb, &params.beacon_color_change,
- info->extack);
+ info->extack,
+ wdev->links[link_id].ap.chandef.chan->band == NL80211_BAND_S1GHZ);
if (err)
goto out;


base-commit: aa2aa818cd1198cfa2498116d57cd9f13fea80e4
--
2.34.1


2023-04-13 03:14:48

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v4 1/2] wifi: cfg80211: Add short_beacon_tail/head/period

Hi Gilad,

kernel test robot noticed the following build warnings:

[auto build test WARNING on aa2aa818cd1198cfa2498116d57cd9f13fea80e4]

url: https://github.com/intel-lab-lkp/linux/commits/Gilad-Itzkovitch/wifi-mac80211-S1G-beacon-short-beacon-support/20230413-071340
base: aa2aa818cd1198cfa2498116d57cd9f13fea80e4
patch link: https://lore.kernel.org/r/20230412231241.1587517-1-gilad.itzkovitch%40virscient.com
patch subject: [PATCH v4 1/2] wifi: cfg80211: Add short_beacon_tail/head/period
config: i386-randconfig-a005-20230410 (https://download.01.org/0day-ci/archive/20230413/[email protected]/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/0559af4e4729ccb2c2f378b51d5ccc1e35bb18f3
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Gilad-Itzkovitch/wifi-mac80211-S1G-beacon-short-beacon-support/20230413-071340
git checkout 0559af4e4729ccb2c2f378b51d5ccc1e35bb18f3
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash net/wireless/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> net/wireless/nl80211.c:236:6: warning: variable 's1g_short_bcn' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (len < offsetofend(typeof(*mgmt), frame_control))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net/wireless/nl80211.c:272:6: note: uninitialized use occurs here
if (s1g_short_bcn)
^~~~~~~~~~~~~
net/wireless/nl80211.c:236:2: note: remove the 'if' if its condition is always false
if (len < offsetofend(typeof(*mgmt), frame_control))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net/wireless/nl80211.c:234:20: note: initialize the variable 's1g_short_bcn' to silence this warning
bool s1g_short_bcn;
^
= 0
1 warning generated.


vim +236 net/wireless/nl80211.c

a9455408b09395 Johannes Berg 2012-06-15 224
f88eb7c0d002a6 Johannes Berg 2019-09-20 225 static int validate_beacon_head(const struct nlattr *attr,
f88eb7c0d002a6 Johannes Berg 2019-09-20 226 struct netlink_ext_ack *extack)
f88eb7c0d002a6 Johannes Berg 2019-09-20 227 {
f88eb7c0d002a6 Johannes Berg 2019-09-20 228 const u8 *data = nla_data(attr);
f88eb7c0d002a6 Johannes Berg 2019-09-20 229 unsigned int len = nla_len(attr);
f88eb7c0d002a6 Johannes Berg 2019-09-20 230 const struct element *elem;
f88eb7c0d002a6 Johannes Berg 2019-09-20 231 const struct ieee80211_mgmt *mgmt = (void *)data;
1d47f1198d5811 Thomas Pedersen 2020-09-08 232 unsigned int fixedlen, hdrlen;
9a6847ba174785 Johannes Berg 2021-04-08 233 bool s1g_bcn;
0559af4e4729cc Kieran Frewen 2023-04-13 234 bool s1g_short_bcn;
1d47f1198d5811 Thomas Pedersen 2020-09-08 235
9a6847ba174785 Johannes Berg 2021-04-08 @236 if (len < offsetofend(typeof(*mgmt), frame_control))
9a6847ba174785 Johannes Berg 2021-04-08 237 goto err;
9a6847ba174785 Johannes Berg 2021-04-08 238
9a6847ba174785 Johannes Berg 2021-04-08 239 s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control);
0559af4e4729cc Kieran Frewen 2023-04-13 240 s1g_short_bcn = ieee80211_is_s1g_short_beacon(mgmt->frame_control);
0559af4e4729cc Kieran Frewen 2023-04-13 241 if (s1g_short_bcn) {
0559af4e4729cc Kieran Frewen 2023-04-13 242 fixedlen = offsetof(struct ieee80211_ext,
0559af4e4729cc Kieran Frewen 2023-04-13 243 u.s1g_short_beacon.variable);
0559af4e4729cc Kieran Frewen 2023-04-13 244 hdrlen = offsetof(struct ieee80211_ext, u.s1g_short_beacon);
0559af4e4729cc Kieran Frewen 2023-04-13 245 } else if (s1g_bcn) {
1d47f1198d5811 Thomas Pedersen 2020-09-08 246 fixedlen = offsetof(struct ieee80211_ext,
1d47f1198d5811 Thomas Pedersen 2020-09-08 247 u.s1g_beacon.variable);
1d47f1198d5811 Thomas Pedersen 2020-09-08 248 hdrlen = offsetof(struct ieee80211_ext, u.s1g_beacon);
1d47f1198d5811 Thomas Pedersen 2020-09-08 249 } else {
1d47f1198d5811 Thomas Pedersen 2020-09-08 250 fixedlen = offsetof(struct ieee80211_mgmt,
f88eb7c0d002a6 Johannes Berg 2019-09-20 251 u.beacon.variable);
1d47f1198d5811 Thomas Pedersen 2020-09-08 252 hdrlen = offsetof(struct ieee80211_mgmt, u.beacon);
1d47f1198d5811 Thomas Pedersen 2020-09-08 253 }
f88eb7c0d002a6 Johannes Berg 2019-09-20 254
f88eb7c0d002a6 Johannes Berg 2019-09-20 255 if (len < fixedlen)
f88eb7c0d002a6 Johannes Berg 2019-09-20 256 goto err;
f88eb7c0d002a6 Johannes Berg 2019-09-20 257
1d47f1198d5811 Thomas Pedersen 2020-09-08 258 if (ieee80211_hdrlen(mgmt->frame_control) != hdrlen)
f88eb7c0d002a6 Johannes Berg 2019-09-20 259 goto err;
f88eb7c0d002a6 Johannes Berg 2019-09-20 260
f88eb7c0d002a6 Johannes Berg 2019-09-20 261 data += fixedlen;
f88eb7c0d002a6 Johannes Berg 2019-09-20 262 len -= fixedlen;
f88eb7c0d002a6 Johannes Berg 2019-09-20 263
f88eb7c0d002a6 Johannes Berg 2019-09-20 264 for_each_element(elem, data, len) {
f88eb7c0d002a6 Johannes Berg 2019-09-20 265 /* nothing */
f88eb7c0d002a6 Johannes Berg 2019-09-20 266 }
f88eb7c0d002a6 Johannes Berg 2019-09-20 267
f88eb7c0d002a6 Johannes Berg 2019-09-20 268 if (for_each_element_completed(elem, data, len))
f88eb7c0d002a6 Johannes Berg 2019-09-20 269 return 0;
f88eb7c0d002a6 Johannes Berg 2019-09-20 270
f88eb7c0d002a6 Johannes Berg 2019-09-20 271 err:
0559af4e4729cc Kieran Frewen 2023-04-13 272 if (s1g_short_bcn)
0559af4e4729cc Kieran Frewen 2023-04-13 273 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed S1G short beacon head");
0559af4e4729cc Kieran Frewen 2023-04-13 274 else if (s1g_bcn)
0559af4e4729cc Kieran Frewen 2023-04-13 275 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed S1G beacon head");
0559af4e4729cc Kieran Frewen 2023-04-13 276 else
f88eb7c0d002a6 Johannes Berg 2019-09-20 277 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head");
f88eb7c0d002a6 Johannes Berg 2019-09-20 278 return -EINVAL;
f88eb7c0d002a6 Johannes Berg 2019-09-20 279 }
f88eb7c0d002a6 Johannes Berg 2019-09-20 280

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests