Skip to contentSkip to conversation

nl80211: add feature for BSS selection support

PATCH Superseded Arend van Spriel 3 participants 7 messages Feb 17, 2016 – Feb 24, 2016

Subsystems (2)

v7 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

PATCH v7 1/2 nl80211: add feature for BSS selection support

Introducing a new feature that the driver can use to indicate the driver/firmware supports configuration of BSS selection criteria upon CONNECT command. This can be useful when multiple BSS-es are found belonging to the same ESS, ie. Infra-BSS with same SSID. The criteria can then be used to offload selection of a preferred BSS.

---
V7:
- add validatioin using nla_ok().

---
 include/net/cfg80211.h       |  34 ++++++++++++++
 include/uapi/linux/nl80211.h |  52 ++++++++++++++++++++++
 net/wireless/core.c          |   4 ++
 net/wireless/nl80211.c       | 104 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 194 insertions(+)
include/net/cfg80211.h +34 -0
index 9e1b24c..1dfb890 100644
@@ -1857,6 +1857,33 @@ struct cfg80211_ibss_params {
 };
 
 /**
+ * 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;
+};
+
+/**
+ * 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 {
+		enum nl80211_band band_pref;
+		struct cfg80211_bss_select_adjust adjust;
+	} param;
+};
+
+/**
  * struct cfg80211_connect_params - Connection parameters
  *
  * This structure provides information needed to complete IEEE 802.11
@@ -1893,6 +1920,7 @@ struct cfg80211_ibss_params {
  * @vht_capa_mask: The bits of vht_capa which are to be used.
  * @pbss: if set, connect to a PCP instead of AP. Valid for DMG
  *	networks.
+ * @bss_select: criteria to be used for BSS selection.
  */
 struct cfg80211_connect_params {
 	struct ieee80211_channel *channel;
@@ -1916,6 +1944,7 @@ struct cfg80211_connect_params {
 	struct ieee80211_vht_cap vht_capa;
 	struct ieee80211_vht_cap vht_capa_mask;
 	bool pbss;
+	struct cfg80211_bss_selection bss_select;
 };
 
 /**
@@ -3184,6 +3213,9 @@ struct wiphy_vendor_command {
  *	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.
+ * @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.
  */
 struct wiphy {
 	/* assign these fields before you register the wiphy */
@@ -3306,6 +3338,8 @@ struct wiphy {
 	u8 max_num_csa_counters;
 	u8 max_adj_channel_rssi_comp;
 
+	u32 bss_select_support;
+
 	char priv[0] __aligned(NETDEV_ALIGN);
 };
 
include/uapi/linux/nl80211.h +52 -0

74 lines not on this page · raw message

net/wireless/core.c +4 -0
index 9f1c4aa..0256336 100644
@@ -626,6 +626,10 @@ int wiphy_register(struct wiphy *wiphy)
 		     !rdev->ops->set_mac_acl)))
 		return -EINVAL;
 
+	if (WARN_ON(wiphy->bss_select_support &&
+		    (wiphy->bss_select_support & ~(BIT(__NL80211_BSS_SELECT_ATTR_AFTER_LAST) - 2))))
+		return -EINVAL;
+
 	if (wiphy->addresses)
 		memcpy(wiphy->perm_addr, wiphy->addresses[0].addr, ETH_ALEN);
 
net/wireless/nl80211.c +104 -0

128 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw

PATCH v7 2/2 brcmfmac: add support for nl80211 BSS_SELECT feature

Announce support for nl80211 feature BSS_SELECT and process BSS selection behaviour provided in .connect() callback.

---
V7:
- add WLC_SET_ASSOC_PREFER to fix firmware behaviour.

---
 .../broadcom/brcm80211/brcmfmac/cfg80211.c         | 70 +++++++++++++++++++++-
 .../wireless/broadcom/brcm80211/brcmfmac/common.c  | 38 +++++++-----
 .../wireless/broadcom/brcm80211/brcmfmac/core.h    |  1 +
 .../wireless/broadcom/brcm80211/brcmfmac/fwil.h    |  1 +
 4 files changed, 92 insertions(+), 18 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +67 -3
index d00c5c1..593385b 100644
@@ -238,6 +238,20 @@ struct parsed_vndr_ies {
 	struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT];
 };
 
+static u8 nl80211_band_to_fwil(enum nl80211_band band)
+{
+	switch (band) {
+	case NL80211_BAND_2GHZ:
+		return WLC_BAND_2G;
+	case NL80211_BAND_5GHZ:
+		return WLC_BAND_5G;
+	default:
+		WARN_ON(1);
+		break;
+	}
+	return 0;
+}
+
 static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
 			       struct cfg80211_chan_def *ch)
 {
@@ -1734,6 +1748,50 @@ enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp,
 	return type;
 }
 
+static void brcmf_set_join_pref(struct brcmf_if *ifp,
+				struct cfg80211_bss_selection *bss_select)
+{
+	struct brcmf_join_pref_params join_pref_params[2];
+	enum nl80211_band band;
+	int err, i = 0;
+
+	join_pref_params[i].len = 2;
+	join_pref_params[i].rssi_gain = 0;
+
+	if (bss_select->behaviour != NL80211_BSS_SELECT_ATTR_BAND_PREF)
+		brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_ASSOC_PREFER, WLC_BAND_AUTO);
+
+	switch (bss_select->behaviour) {
+	case __NL80211_BSS_SELECT_ATTR_INVALID:
+		brcmf_c_set_joinpref_default(ifp);
+		return;
+	case NL80211_BSS_SELECT_ATTR_BAND_PREF:
+		join_pref_params[i].type = BRCMF_JOIN_PREF_BAND;
+		band = bss_select->param.band_pref;
+		join_pref_params[i].band = nl80211_band_to_fwil(band);
+		i++;
+		break;
+	case NL80211_BSS_SELECT_ATTR_RSSI_ADJUST:
+		join_pref_params[i].type = BRCMF_JOIN_PREF_RSSI_DELTA;
+		band = bss_select->param.adjust.band;
+		join_pref_params[i].band = nl80211_band_to_fwil(band);
+		join_pref_params[i].rssi_gain = bss_select->param.adjust.delta;
+		i++;
+		break;
+	case NL80211_BSS_SELECT_ATTR_RSSI:
+	default:
+		break;
+	}
+	join_pref_params[i].type = BRCMF_JOIN_PREF_RSSI;
+	join_pref_params[i].len = 2;
+	join_pref_params[i].rssi_gain = 0;
+	join_pref_params[i].band = 0;
+	err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params,
+				       sizeof(join_pref_params));
+	if (err)
+		brcmf_err("Set join_pref error (%d)\n", err);
+}
+
 static s32
 brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
 		       struct cfg80211_connect_params *sme)
@@ -1859,11 +1917,11 @@ brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
 	ext_join_params->scan_le.scan_type = -1;
 	ext_join_params->scan_le.home_time = cpu_to_le32(-1);
 
-	if (sme->bssid)
+	if (sme->bssid) {
 		memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN);
-	else
+	} else {
 		eth_broadcast_addr(ext_join_params->assoc_le.bssid);
-
+	}
 	if (cfg->channel) {
 		ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1);
 
@@ -1890,6 +1948,8 @@ brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
 		ext_join_params->scan_le.nprobes = cpu_to_le32(-1);
 	}
 
+	brcmf_set_join_pref(ifp, &sme->bss_select);
+
 	err  = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params,
 					 join_params_size);
 	kfree(ext_join_params);
@@ -6176,6 +6236,10 @@ static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp)
 	wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
 	wiphy->cipher_suites = __wl_cipher_suites;
 	wiphy->n_cipher_suites = ARRAY_SIZE(__wl_cipher_suites);
+	wiphy->bss_select_support = BIT(NL80211_BSS_SELECT_ATTR_RSSI) |
+				    BIT(NL80211_BSS_SELECT_ATTR_BAND_PREF) |
+				    BIT(NL80211_BSS_SELECT_ATTR_RSSI_ADJUST);
+
 	wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT |
 			WIPHY_FLAG_OFFCHAN_TX |
 			WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c +23 -15
index cfee477..f48e8d4 100644
@@ -33,7 +33,7 @@ const u8 ALLFFMAC[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 #define BRCMF_DEFAULT_SCAN_CHANNEL_TIME	40
 #define BRCMF_DEFAULT_SCAN_UNASSOC_TIME	40
 
-/* boost value for RSSI_DELTA in preferred join selection */
+/* default boost value for RSSI_DELTA in preferred join selection */
 #define BRCMF_JOIN_PREF_RSSI_BOOST	8
 
 #define BRCMF_DEFAULT_TXGLOM_SIZE	32  /* max tx frames in glom chain */
@@ -77,11 +77,31 @@ MODULE_PARM_DESC(ignore_probe_fail, "always succeed probe for debugging");
 
 struct brcmf_mp_global_t brcmf_mp_global;
 
+void brcmf_c_set_joinpref_default(struct brcmf_if *ifp)
+{
+	struct brcmf_join_pref_params join_pref_params[2];
+	int err;
+
+	/* Setup join_pref to select target by RSSI (boost on 5GHz) */
+	join_pref_params[0].type = BRCMF_JOIN_PREF_RSSI_DELTA;
+	join_pref_params[0].len = 2;
+	join_pref_params[0].rssi_gain = BRCMF_JOIN_PREF_RSSI_BOOST;
+	join_pref_params[0].band = WLC_BAND_5G;
+
+	join_pref_params[1].type = BRCMF_JOIN_PREF_RSSI;
+	join_pref_params[1].len = 2;
+	join_pref_params[1].rssi_gain = 0;
+	join_pref_params[1].band = 0;
+	err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params,
+				       sizeof(join_pref_params));
+	if (err)
+		brcmf_err("Set join_pref error (%d)\n", err);
+}
+
 int brcmf_c_preinit_dcmds(struct brcmf_if *ifp)
 {
 	s8 eventmask[BRCMF_EVENTING_MASK_LEN];
 	u8 buf[BRCMF_DCMD_SMLEN];
-	struct brcmf_join_pref_params join_pref_params[2];
 	struct brcmf_rev_info_le revinfo;
 	struct brcmf_rev_info *ri;
 	char *ptr;
@@ -148,19 +168,7 @@ int brcmf_c_preinit_dcmds(struct brcmf_if *ifp)
 		goto done;
 	}
 
-	/* Setup join_pref to select target by RSSI(with boost on 5GHz) */
-	join_pref_params[0].type = BRCMF_JOIN_PREF_RSSI_DELTA;
-	join_pref_params[0].len = 2;
-	join_pref_params[0].rssi_gain = BRCMF_JOIN_PREF_RSSI_BOOST;
-	join_pref_params[0].band = WLC_BAND_5G;
-	join_pref_params[1].type = BRCMF_JOIN_PREF_RSSI;
-	join_pref_params[1].len = 2;
-	join_pref_params[1].rssi_gain = 0;
-	join_pref_params[1].band = 0;
-	err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params,
-				       sizeof(join_pref_params));
-	if (err)
-		brcmf_err("Set join_pref error (%d)\n", err);
+	brcmf_c_set_joinpref_default(ifp);
 
 	/* Setup event_msgs, enable E_IF */
 	err = brcmf_fil_iovar_data_get(ifp, "event_msgs", eventmask,
drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h +1 -0
index 8f39435..c9a1a13 100644
@@ -220,5 +220,6 @@ void brcmf_txflowblock_if(struct brcmf_if *ifp,
 void brcmf_txfinalize(struct brcmf_if *ifp, struct sk_buff *txp, bool success);
 void brcmf_netif_rx(struct brcmf_if *ifp, struct sk_buff *skb);
 void brcmf_net_setcarrier(struct brcmf_if *ifp, bool on);
+void brcmf_c_set_joinpref_default(struct brcmf_if *ifp);
 
 #endif /* BRCMFMAC_CORE_H */
drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil.h +1 -0
index 6b72df1..3a9a76d 100644
@@ -78,6 +78,7 @@
 #define BRCMF_C_SET_SCAN_CHANNEL_TIME		185
 #define BRCMF_C_SET_SCAN_UNASSOC_TIME		187
 #define BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON	201
+#define BRCMF_C_SET_ASSOC_PREFER		205
 #define BRCMF_C_GET_VALID_CHANNELS		217
 #define BRCMF_C_GET_KEY_PRIMARY			235
 #define BRCMF_C_SET_KEY_PRIMARY			236
Signature · 1 line
1.9.1
maintainer
#2 lore raw
In reply to Arend van Spriel
Quoted 7 lines · Arend van Spriel


+ * @NL80211_ATTR_BSS_SELECT: nested attribute for driver supporting the
+ * BSS selection feature. When used with %NL80211_CMD_GET_WIPHY it contains
+ * NLA_FLAG type according &enum nl80211_bss_select_attr to indicate what
+ * BSS selection behaviours are supported. When used with %NL80211_CMD_CONNECT
+ * it contains the behaviour and parameters for BSS selection to be done by
+ * driver and/or firmware.

Maybe we should be less specific here regarding the NLA_FLAG and say that it will contain attributes for each, indicating which behaviours are supported, and say there's behaviour-dependent data inside each of those attributes?

It seems entirely plausible that future behaviours would require their own sub-capabilities; perhaps that's even the case today for having an adjustment range for example, not that I think it's really necessary now.

include/uapi/linux/nl80211.h enum nl80211_band { · line 3627

Quoted 5 lines
include/uapi/linux/nl80211.h +1 -0
@@ -3617,6 +3624,7 @@ enum nl80211_band {
  	NL80211_BAND_2GHZ,
  	NL80211_BAND_5GHZ,
  	NL80211_BAND_60GHZ,
+	NUM_NL80211_BAND,

You should use IEEE80211_NUM_BANDS and remove this.

net/wireless/nl80211.c static int validate_scan_freqs(struct nlattr *freqs) · line 5791

Quoted 4 lines
net/wireless/nl80211.c +4 -0
+static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
+{
+	return b < NUM_NL80211_BAND && wiphy->bands[b];
+}

Here.

Quoted 4 lines
(quoted diff) +2 -0
+static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
+			    struct cfg80211_bss_selection

*bss_select)

net/wireless/nl80211.c +1 -0
+{

net/wireless/nl80211.c static int validate_scan_freqs(struct nlattr *freqs) · line 5805

Quoted 10 lines
net/wireless/nl80211.c +10 -0
+	struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
+	struct nlattr *nest;
+	int err;
+	bool found = false;
+	int i;
+
+	/* only process one nested attribute */
+	nest = nla_data(nla);
+	if (!nla_ok(nest, nla_len(nest)))
+		return -EBADF;

This isn't quite clear to me. Shouldn't you do this by declaring it NLA_TESTED in the nl80211_policy?

Actually, not really? you use nla_ok() on the inner (without having checked at all that it's even long enough btw, since you didn't do the policy change), but that would already be done by nla_parse() below?

What are you trying to do here?

Regardless of that, EBADF seems like a bad error number.

net/wireless/nl80211.c static int validate_scan_freqs(struct nlattr *freqs) · line 5818

Quoted 13 lines
(quoted diff) +1 -0
+	err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX,

nla_data(nest),

net/wireless/nl80211.c +11 -0
+			nla_len(nest), nl80211_bss_select_policy);
+	if (err)
+		return err;
+
+	/* only one attribute may be given */
+	for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++)
+		if (attr[i]) {
+			if (found)
+				return -EINVAL;
+			found = true;
+		}

I'd kinda prefer braces, but maybe that's just me. Surely not a blocking issue :)

johannes

maintainer
#3 lore raw
Quoted 9 lines · Johannes Berg
Quoted 7 lines · Arend van Spriel

+ * @NL80211_ATTR_BSS_SELECT: nested attribute for driver supporting the
+ * BSS selection feature. When used with %NL80211_CMD_GET_WIPHY it contains
+ * NLA_FLAG type according &enum nl80211_bss_select_attr to indicate what
+ * BSS selection behaviours are supported. When used with %NL80211_CMD_CONNECT
+ * it contains the behaviour and parameters for BSS selection to be done by
+ * driver and/or firmware.

Quoted 4 lines

Maybe we should be less specific here regarding the NLA_FLAG and say that it will contain attributes for each, indicating which behaviours are supported, and say there's behaviour-dependent data inside each of those attributes?

For the GET_WIPHY case there will be not behaviour dependent data.

Quoted 4 lines

It seems entirely plausible that future behaviours would require their own sub-capabilities; perhaps that's even the case today for having an adjustment range for example, not that I think it's really necessary now.

At least it does not harm to take that into account.

Quoted 7 lines

include/uapi/linux/nl80211.h enum nl80211_band { · line 3627

Quoted 5 lines
include/uapi/linux/nl80211.h +1 -0
@@ -3617,6 +3624,7 @@ enum nl80211_band {
 	NL80211_BAND_2GHZ,
 	NL80211_BAND_5GHZ,
 	NL80211_BAND_60GHZ,
+	NUM_NL80211_BAND,

You should use IEEE80211_NUM_BANDS and remove this.

Ok. missed that one.

Quoted 6 lines

net/wireless/nl80211.c static int validate_scan_freqs(struct nlattr *freqs) · line 5791

Quoted 4 lines
net/wireless/nl80211.c +4 -0
+static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
+{
+	return b < NUM_NL80211_BAND && wiphy->bands[b];
+}

Here.

will change it.

Quoted 9 lines
Quoted 9 lines
(quoted diff) +2 -0
+static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
+			    struct cfg80211_bss_selection

*bss_select)

net/wireless/nl80211.c +6 -0
+{
+	struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
+	struct nlattr *nest;
+	int err;
+	bool found = false;
+	int i;
Quoted 8 lines

net/wireless/nl80211.c static int validate_scan_freqs(struct nlattr *freqs) · line 5805

Quoted 5 lines
net/wireless/nl80211.c +5 -0
+
+	/* only process one nested attribute */
+	nest = nla_data(nla);
+	if (!nla_ok(nest, nla_len(nest)))
+		return -EBADF;

This isn't quite clear to me. Shouldn't you do this by declaring it NLA_TESTED in the nl80211_policy?

Guess you mean NLA_NESTED.

Quoted 3 lines

Actually, not really? you use nla_ok() on the inner (without having checked at all that it's even long enough btw, since you didn't do the policy change), but that would already be done by nla_parse() below?

Because ATTR_BSS_SELECT is used in CMD_GET_WIPHY and CMD_CONNECT the length of the attribute is not a constant. Or do I only need to put length in nl80211_policy for userspace-2-kernel direction, ie. for ATTR_BSS_SELECT in CMD_CONNECT.

Quoted 1 line

What are you trying to do here?

ATTR_BSS_SELECT will have only a single nested attribute. So I looked at nla_for_each_nested():

1233 /**

1234  * nla_for_each_attr - iterate over a stream of attributes
1235  * @pos: loop counter, set to current attribute
1236  * @head: head of attribute stream
1237  * @len: length of attribute stream
1238  * @rem: initialized to len, holds bytes currently remaining in stream
1239  */

1240 #define nla_for_each_attr(pos, head, len, rem) \
1241 for (pos = head, rem = len; \
1242 nla_ok(pos, rem); \
1243 pos = nla_next(pos, &(rem)))
1244
1245 /**

1246  * nla_for_each_nested - iterate over nested attributes
1247  * @pos: loop counter, set to current attribute
1248  * @nla: attribute containing the nested attributes
1249  * @rem: initialized to len, holds bytes currently remaining in stream
1250  */

1251 #define nla_for_each_nested(pos, nla, rem) \
1252 nla_for_each_attr(pos, nla_data(nla), nla_len(nla), rem)

So:

nla_for_each_nested(nest, nla, rem)

becomes:
for(nest = nla_data(nla), rem = nla_len(nla); nla_ok(nest, rem); ...)

As there is no need to iterate I just do the for loop initializer and the loop condition using the if(nla_ok()).

Quoted 1 line

Regardless of that, EBADF seems like a bad error number.

Ok. Just use EINVAL here as well?

Quoted 8 lines
Quoted 8 lines
(quoted diff) +1 -0
+	err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX,

nla_data(nest),

net/wireless/nl80211.c +6 -0
+			nla_len(nest), nl80211_bss_select_policy);
+	if (err)
+		return err;
+
+	/* only one attribute may be given */
+	for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++)
Quoted 8 lines

net/wireless/nl80211.c static int validate_scan_freqs(struct nlattr *freqs) · line 5818

Quoted 5 lines
net/wireless/nl80211.c +5 -0
+		if (attr[i]) {
+			if (found)
+				return -EINVAL;
+			found = true;
+		}

I'd kinda prefer braces, but maybe that's just me. Surely not a blocking issue :)

I don't have strong opinion about it so I can change it.

Regards,
Arend

maintainer
#4 lore raw
Quoted 19 lines · Arend Van Spriel

Quoted 7 lines

Maybe we should be less specific here regarding the NLA_FLAG and say
that it will contain attributes for each, indicating which behaviours
are supported, and say there's behaviour-dependent data inside each of
those attributes?

For the GET_WIPHY case there will be not behaviour dependent data.

Quoted 7 lines

It seems entirely plausible that future behaviours would require their
own sub-capabilities; perhaps that's even the case today for having an
adjustment range for example, not that I think it's really necessary
now.

Quoted 1 line

At least it does not harm to take that into account.

Right; there isn't today, but there might be later, so for the GET_WIPHY case it might be worth just specifying that there will be an attribute, not that it's NLA_FLAG?

Not that it'll matter much - only when we actually add such could applications possibly want to parse them :)

Quoted 9 lines
Quoted 7 lines

net/wireless/nl80211.c static int validate_scan_freqs(struct nlattr *freqs) · line 5805

Quoted 4 lines
net/wireless/nl80211.c +4 -0
+	/* only process one nested attribute */
+	nest = nla_data(nla);
+	if (!nla_ok(nest, nla_len(nest)))
+		return -EBADF;

This isn't quite clear to me. Shouldn't you do this by declaring it NLA_TESTED in the nl80211_policy?

Guess you mean NLA_NESTED.

Heh, yeah.

Quoted 10 lines
Quoted 5 lines

Actually, not really? you use nla_ok() on the inner (without having checked at all that it's even long enough btw, since you didn't do the
policy change), but that would already be done by nla_parse() below?

Because ATTR_BSS_SELECT is used in CMD_GET_WIPHY and CMD_CONNECT the length of the attribute is not a constant. Or do I only need to put length in nl80211_policy for userspace-2-kernel direction, ie. for ATTR_BSS_SELECT in CMD_CONNECT.

Ah. kernel->userspace messages don't use the policy in any way, it's just for the userspace->kernel message validation, so you can put there what's needed for CMD_CONNECT and ignore GET_WIPHY.

johannes

maintainer
#5 lore raw
Quoted 20 lines · Johannes Berg
Quoted 19 lines · Arend Van Spriel
Quoted 8 lines

Maybe we should be less specific here regarding the NLA_FLAG and say
that it will contain attributes for each, indicating which behaviours
are supported, and say there's behaviour-dependent data inside each of
those attributes?

For the GET_WIPHY case there will be not behaviour dependent data.

Quoted 7 lines

It seems entirely plausible that future behaviours would require their
own sub-capabilities; perhaps that's even the case today for having an
adjustment range for example, not that I think it's really necessary
now.

Quoted 5 lines
Quoted 1 line

At least it does not harm to take that into account.

Right; there isn't today, but there might be later, so for the GET_WIPHY case it might be worth just specifying that there will be an attribute, not that it's NLA_FLAG?

Will try and be vague :-)

Quoted 2 lines

Not that it'll matter much - only when we actually add such could applications possibly want to parse them :)

That goes without saying :-p

Quoted 18 lines
Quoted 9 lines
Quoted 7 lines

net/wireless/nl80211.c static int validate_scan_freqs(struct nlattr *freqs) · line 5805

Quoted 4 lines
net/wireless/nl80211.c +4 -0
+	/* only process one nested attribute */
+	nest = nla_data(nla);
+	if (!nla_ok(nest, nla_len(nest)))
+		return -EBADF;

This isn't quite clear to me. Shouldn't you do this by declaring it NLA_TESTED in the nl80211_policy?

Guess you mean NLA_NESTED.

Heh, yeah.

Quoted 6 lines
Quoted 5 lines

Actually, not really? you use nla_ok() on the inner (without having checked at all that it's even long enough btw, since you didn't do the
policy change), but that would already be done by nla_parse() below?

Quoted 8 lines
Quoted 4 lines

Because ATTR_BSS_SELECT is used in CMD_GET_WIPHY and CMD_CONNECT the length of the attribute is not a constant. Or do I only need to put length in nl80211_policy for userspace-2-kernel direction, ie. for ATTR_BSS_SELECT in CMD_CONNECT.

Ah. kernel->userspace messages don't use the policy in any way, it's just for the userspace->kernel message validation, so you can put there what's needed for CMD_CONNECT and ignore GET_WIPHY.

I actually do not see any NLA_NESTED attributes with an explicit length. As you mentioned the nla_parse() of the nested attribute will validate the length of the stream so no need to put that in the policy.

Regards,
Arend

maintainer
#6 lore raw
Quoted 4 lines · Arend Van Spriel

I actually do not see any NLA_NESTED attributes with an explicit length. As you mentioned the nla_parse() of the nested attribute will validate the length of the stream so no need to put that in the policy.

Right, I think what you want can be achieved by just using NLA_NESTED to make sure it's long enough for nesting anything, and then nla_parse. I'm pretty sure we do the same in other places, no?

johannes