All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change.
@ 2017-03-23 23:26 greearb
  2017-03-23 23:26 ` [PATCH v3 2/4] mac80211-hwsim: remove dmesg spam about get-survey greearb
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: greearb @ 2017-03-23 23:26 UTC (permalink / raw)
  To: linux-wireless; +Cc: johannes, Ben Greear

From: Ben Greear <greearb@candelatech.com>

The goal is to allow the user-space application to properly
filter packets before sending them down to the kernel.  This
should more closely mimic what a real piece of hardware would
do.

Signed-off-by: Ben Greear <greearb@candelatech.com>
---

v3:  Rebased against latest wireless-testing, renamed "CH_FREQ" to CENTER_FREQ,
don't send center_freq2 if value is zero.

Compile tested, not run-time tested since original patches were written.

 drivers/net/wireless/mac80211_hwsim.c | 70 +++++++++++++++++++++++++++++++++++
 drivers/net/wireless/mac80211_hwsim.h | 16 ++++++++
 2 files changed, 86 insertions(+)

diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index 67fc91d..f1ad908 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -533,6 +533,10 @@ struct mac80211_hwsim_data {
 		      ARRAY_SIZE(hwsim_channels_5ghz)];
 
 	struct ieee80211_channel *channel;
+	enum nl80211_chan_width ch_width;
+	u32 center_freq1;
+	u32 center_freq2;
+
 	u64 beacon_int	/* beacon interval in us */;
 	unsigned int rx_filter;
 	bool started, idle, scanning;
@@ -1004,6 +1008,65 @@ static int hwsim_unicast_netgroup(struct mac80211_hwsim_data *data,
 	return res;
 }
 
+static void mac80211_hwsim_check_nl_notify(struct mac80211_hwsim_data *data)
+{
+	struct sk_buff *skb;
+	u32 center_freq = 0;
+	u32 _portid;
+	void *msg_head;
+
+	/* wmediumd mode check */
+	_portid = READ_ONCE(data->wmediumd);
+
+	if (!_portid)
+		return;
+
+	skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC);
+	if (!skb)
+		goto err_print;
+
+	msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0,
+			       HWSIM_CMD_NOTIFY_CH_CHANGE);
+	if (!msg_head) {
+		pr_debug("mac80211_hwsim: problem with msg_head, notify-ch-change\n");
+		goto nla_put_failure;
+	}
+
+	if (nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, data->idx))
+		goto nla_put_failure;
+
+	if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER,
+		    ETH_ALEN, data->addresses[1].addr))
+		goto nla_put_failure;
+
+	if (data->channel)
+		center_freq = data->channel->center_freq;
+
+	if (nla_put_u32(skb, HWSIM_ATTR_FREQ, center_freq))
+		goto nla_put_failure;
+
+	if (nla_put_u32(skb, HWSIM_ATTR_CENTER_FREQ1, data->center_freq1))
+		goto nla_put_failure;
+
+	if (data->center_freq2)
+		if (nla_put_u32(skb, HWSIM_ATTR_CENTER_FREQ2, data->center_freq2))
+			goto nla_put_failure;
+
+	if (nla_put_u32(skb, HWSIM_ATTR_CH_WIDTH, data->ch_width))
+		goto nla_put_failure;
+
+	genlmsg_end(skb, msg_head);
+	if (genlmsg_unicast(&init_net, skb, _portid))
+		goto err_print;
+
+	return;
+
+nla_put_failure:
+	nlmsg_free(skb);
+err_print:
+	pr_debug("mac80211_hwsim: error occurred in %s\n", __func__);
+}
+
 static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
 				       struct sk_buff *my_skb,
 				       int dst_portid)
@@ -1631,6 +1694,11 @@ static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed)
 	} else {
 		data->channel = conf->chandef.chan;
 	}
+
+	data->ch_width = conf->chandef.width;
+	data->center_freq1 = conf->chandef.center_freq1;
+	data->center_freq2 = conf->chandef.center_freq2;
+
 	mutex_unlock(&data->mutex);
 
 	data->power_level = conf->power_level;
@@ -1646,6 +1714,8 @@ static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed)
 				      HRTIMER_MODE_REL);
 	}
 
+	mac80211_hwsim_check_nl_notify(data);
+
 	return 0;
 }
 
diff --git a/drivers/net/wireless/mac80211_hwsim.h b/drivers/net/wireless/mac80211_hwsim.h
index 3f5eda5..523fbc4 100644
--- a/drivers/net/wireless/mac80211_hwsim.h
+++ b/drivers/net/wireless/mac80211_hwsim.h
@@ -71,6 +71,15 @@ enum hwsim_tx_control_flags {
  * @HWSIM_CMD_DEL_RADIO: destroy a radio, reply is multicasted
  * @HWSIM_CMD_GET_RADIO: fetch information about existing radios, uses:
  *	%HWSIM_ATTR_RADIO_ID
+ * @HWSIM_CMD_NOTIFY_CH_CHANGE: notify user-space about channel-change.  This is
+ *	designed to help the user-space app better emulate radio hardware.
+ *	This command uses:
+ *	%HWSIM_ATTR_FREQ # Notify current operating center frequency.
+ *	%HWSIM_ATTR_CH_FREQ1 # Configured center-freq-1.
+ *	%HWSIM_ATTR_CH_FREQ2 # Configured center-freq-2.
+ *	%HWSIM_ATTR_CH_WIDTH # Configured channel width.
+ *	%HWSIM_ATTR_ADDR_TRANSMITTER # ID which radio we are notifying about.
+ *	%HWSIM_ATTR_ADDR_ID # Numeric Radio ID.
  * @__HWSIM_CMD_MAX: enum limit
  */
 enum {
@@ -81,6 +90,7 @@ enum {
 	HWSIM_CMD_NEW_RADIO,
 	HWSIM_CMD_DEL_RADIO,
 	HWSIM_CMD_GET_RADIO,
+	HWSIM_CMD_NOTIFY_CH_CHANGE,
 	__HWSIM_CMD_MAX,
 };
 #define HWSIM_CMD_MAX (_HWSIM_CMD_MAX - 1)
@@ -123,6 +133,9 @@ enum {
  * @HWSIM_ATTR_RADIO_NAME: Name of radio, e.g. phy666
  * @HWSIM_ATTR_NO_VIF:  Do not create vif (wlanX) when creating radio.
  * @HWSIM_ATTR_FREQ: Frequency at which packet is transmitted or received.
+ * @HWSIM_ATTR_CENTER_FREQ1: Configured center-freq-1.
+ * @HWSIM_ATTR_CENTER_FREQ2: Configured center-freq-2.  Not reported if value is zero.
+ * @HWSIM_ATTR_CH_WIDTH: Configured channel width.
  * @__HWSIM_ATTR_MAX: enum limit
  */
 
@@ -149,6 +162,9 @@ enum {
 	HWSIM_ATTR_NO_VIF,
 	HWSIM_ATTR_FREQ,
 	HWSIM_ATTR_PAD,
+	HWSIM_ATTR_CENTER_FREQ1,
+	HWSIM_ATTR_CENTER_FREQ2,
+	HWSIM_ATTR_CH_WIDTH,
 	__HWSIM_ATTR_MAX,
 };
 #define HWSIM_ATTR_MAX (__HWSIM_ATTR_MAX - 1)
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 2/4] mac80211-hwsim: remove dmesg spam about get-survey.
  2017-03-23 23:26 [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change greearb
@ 2017-03-23 23:26 ` greearb
  2017-03-29  8:46   ` Johannes Berg
  2017-03-23 23:26 ` [PATCH v3 3/4] mac80211-hwsim: add rate-limited debugging for rx-netlink greearb
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 16+ messages in thread
From: greearb @ 2017-03-23 23:26 UTC (permalink / raw)
  To: linux-wireless; +Cc: johannes, Ben Greear

From: Ben Greear <greearb@candelatech.com>

This message just fills up dmesg and/or kernel logs and does
not provide any useful information.

Signed-off-by: Ben Greear <greearb@candelatech.com>
---
 drivers/net/wireless/mac80211_hwsim.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index f1ad908..234df8c 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -1893,8 +1893,6 @@ static int mac80211_hwsim_get_survey(struct ieee80211_hw *hw, int idx,
 {
 	struct mac80211_hwsim_data *hwsim = hw->priv;
 
-	wiphy_debug(hw->wiphy, "%s (idx=%d)\n", __func__, idx);
-
 	if (idx < 0 || idx >= ARRAY_SIZE(hwsim->survey_data))
 		return -ENOENT;
 
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 3/4] mac80211-hwsim: add rate-limited debugging for rx-netlink
  2017-03-23 23:26 [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change greearb
  2017-03-23 23:26 ` [PATCH v3 2/4] mac80211-hwsim: remove dmesg spam about get-survey greearb
@ 2017-03-23 23:26 ` greearb
  2017-03-29  8:46   ` Johannes Berg
  2017-03-23 23:26 ` [PATCH v3 4/4] mac80211-hwsim: add length checks before allocating skb greearb
  2017-03-29  8:42 ` [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change Johannes Berg
  3 siblings, 1 reply; 16+ messages in thread
From: greearb @ 2017-03-23 23:26 UTC (permalink / raw)
  To: linux-wireless; +Cc: johannes, Ben Greear

From: Ben Greear <greearb@candelatech.com>

This makes it easier to understand why wmediumd (or similar)
is getting errors when sending frames to the kernel.

Signed-off-by: Ben Greear <greearb@candelatech.com>
---
 drivers/net/wireless/mac80211_hwsim.c | 55 +++++++++++++++++++++++++++--------
 1 file changed, 43 insertions(+), 12 deletions(-)

diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index 234df8c..84dcddf 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -137,6 +137,12 @@ static int regtest = HWSIM_REGTEST_DISABLED;
 module_param(regtest, int, 0444);
 MODULE_PARM_DESC(regtest, "The type of regulatory test we want to run");
 
+DEFINE_RATELIMIT_STATE(hwsim_ratelimit_state, 5 * HZ, 10);
+int hwsim_ratelimit(void)
+{
+	return __ratelimit(&hwsim_ratelimit_state);
+}
+
 static const char *hwsim_alpha2s[] = {
 	"FI",
 	"AL",
@@ -1649,7 +1655,7 @@ static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed)
 
 	if (conf->chandef.chan)
 		wiphy_debug(hw->wiphy,
-			    "%s (freq=%d(%d - %d)/%s idle=%d ps=%d smps=%s)\n",
+			    "%s (chandef-chan freq=%d(%d - %d)/%s idle=%d ps=%d smps=%s)\n",
 			    __func__,
 			    conf->chandef.chan->center_freq,
 			    conf->chandef.center_freq1,
@@ -1660,7 +1666,7 @@ static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed)
 			    smps_modes[conf->smps_mode]);
 	else
 		wiphy_debug(hw->wiphy,
-			    "%s (freq=0 idle=%d ps=%d smps=%s)\n",
+			    "%s (no-chandef-chan freq=0 idle=%d ps=%d smps=%s)\n",
 			    __func__,
 			    !!(conf->flags & IEEE80211_CONF_IDLE),
 			    !!(conf->flags & IEEE80211_CONF_PS),
@@ -3072,8 +3078,11 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,
 	if (!info->attrs[HWSIM_ATTR_ADDR_RECEIVER] ||
 	    !info->attrs[HWSIM_ATTR_FRAME] ||
 	    !info->attrs[HWSIM_ATTR_RX_RATE] ||
-	    !info->attrs[HWSIM_ATTR_SIGNAL])
+	    !info->attrs[HWSIM_ATTR_SIGNAL]) {
+		if (hwsim_ratelimit())
+			printk(KERN_DEBUG " hwsim rx-nl: Missing required attribute\n");
 		goto out;
+	}
 
 	dst = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_RECEIVER]);
 	frame_data_len = nla_len(info->attrs[HWSIM_ATTR_FRAME]);
@@ -3081,29 +3090,53 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,
 
 	/* Allocate new skb here */
 	skb = alloc_skb(frame_data_len, GFP_KERNEL);
-	if (skb == NULL)
-		goto err;
+	if (skb == NULL) {
+		if (hwsim_ratelimit())
+			printk(KERN_DEBUG " hwsim rx-nl: skb alloc failed, len: %d\n",
+			       frame_data_len);
+		goto out;
+	}
 
-	if (frame_data_len > IEEE80211_MAX_DATA_LEN)
-		goto err;
+	if (frame_data_len > IEEE80211_MAX_DATA_LEN) {
+		if (hwsim_ratelimit())
+			printk(KERN_DEBUG " hwsim rx-nl: data lenth error: %d  max: %d\n",
+			       frame_data_len, IEEE80211_MAX_DATA_LEN);
+		goto out;
+	}
 
 	/* Copy the data */
 	memcpy(skb_put(skb, frame_data_len), frame_data, frame_data_len);
 
 	data2 = get_hwsim_data_ref_from_addr(dst);
-	if (!data2)
+
+	if (!data2) {
+		if (hwsim_ratelimit())
+			printk(KERN_DEBUG " hwsim rx-nl: Cannot find radio %pM\n",
+			       dst);
 		goto out;
+	}
 
 	if (hwsim_net_get_netgroup(genl_info_net(info)) != data2->netgroup)
 		goto out;
 
-	if (info->snd_portid != data2->wmediumd)
+	if (info->snd_portid != data2->wmediumd) {
+		if (hwsim_ratelimit())
+			printk(KERN_DEBUG " hwsim rx-nl: portid mismatch, snd_portid: %d  portid %d\n",
+			       info->snd_portid, data2->wmediumd);
 		goto out;
+	}
 
 	/* check if radio is configured properly */
 
-	if (data2->idle || !data2->started)
+	if (data2->idle || !data2->started) {
+		static unsigned int cnt = 0;
+		/* This is fairly common, and usually not a bug.  So, print errors
+		   rarely. */
+		if (((cnt++ & 0x3FF) == 0x3FF) && hwsim_ratelimit())
+			printk(KERN_DEBUG " hwsim rx-nl: radio %pM idle: %d or not started: %d cnt: %d\n",
+			       dst, data2->idle, !data2->started, cnt);
 		goto out;
+	}
 
 	/* A frame is received from user space */
 	memset(&rx_status, 0, sizeof(rx_status));
@@ -3136,8 +3169,6 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,
 	ieee80211_rx_irqsafe(data2->hw, skb);
 
 	return 0;
-err:
-	printk(KERN_DEBUG "mac80211_hwsim: error occurred in %s\n", __func__);
 out:
 	dev_kfree_skb(skb);
 	return -EINVAL;
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 4/4] mac80211-hwsim: add length checks before allocating skb.
  2017-03-23 23:26 [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change greearb
  2017-03-23 23:26 ` [PATCH v3 2/4] mac80211-hwsim: remove dmesg spam about get-survey greearb
  2017-03-23 23:26 ` [PATCH v3 3/4] mac80211-hwsim: add rate-limited debugging for rx-netlink greearb
@ 2017-03-23 23:26 ` greearb
  2017-03-29  8:47   ` Johannes Berg
  2017-03-29  8:42 ` [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change Johannes Berg
  3 siblings, 1 reply; 16+ messages in thread
From: greearb @ 2017-03-23 23:26 UTC (permalink / raw)
  To: linux-wireless; +Cc: johannes, Ben Greear

From: Ben Greear <greearb@candelatech.com>

Modify the receive-from-user-space logic to do length
and 'is-down' checks before trying to allocate an skb.

And, if we are going to ignore the pkt due to radio idle,
then do not return an error code to user-space.  User-space
cannot reliably know exactly when a radio is idle or not.

Signed-off-by: Ben Greear <greearb@candelatech.com>
---
 drivers/net/wireless/mac80211_hwsim.c | 41 +++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index 84dcddf..6207d4a 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -3074,6 +3074,7 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,
 	int frame_data_len;
 	void *frame_data;
 	struct sk_buff *skb = NULL;
+	int rv = -EINVAL;
 
 	if (!info->attrs[HWSIM_ATTR_ADDR_RECEIVER] ||
 	    !info->attrs[HWSIM_ATTR_FRAME] ||
@@ -3088,25 +3089,6 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,
 	frame_data_len = nla_len(info->attrs[HWSIM_ATTR_FRAME]);
 	frame_data = (void *)nla_data(info->attrs[HWSIM_ATTR_FRAME]);
 
-	/* Allocate new skb here */
-	skb = alloc_skb(frame_data_len, GFP_KERNEL);
-	if (skb == NULL) {
-		if (hwsim_ratelimit())
-			printk(KERN_DEBUG " hwsim rx-nl: skb alloc failed, len: %d\n",
-			       frame_data_len);
-		goto out;
-	}
-
-	if (frame_data_len > IEEE80211_MAX_DATA_LEN) {
-		if (hwsim_ratelimit())
-			printk(KERN_DEBUG " hwsim rx-nl: data lenth error: %d  max: %d\n",
-			       frame_data_len, IEEE80211_MAX_DATA_LEN);
-		goto out;
-	}
-
-	/* Copy the data */
-	memcpy(skb_put(skb, frame_data_len), frame_data, frame_data_len);
-
 	data2 = get_hwsim_data_ref_from_addr(dst);
 
 	if (!data2) {
@@ -3135,9 +3117,30 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,
 		if (((cnt++ & 0x3FF) == 0x3FF) && hwsim_ratelimit())
 			printk(KERN_DEBUG " hwsim rx-nl: radio %pM idle: %d or not started: %d cnt: %d\n",
 			       dst, data2->idle, !data2->started, cnt);
+		rv = -ENETDOWN;
 		goto out;
 	}
 
+	if (frame_data_len > IEEE80211_MAX_DATA_LEN) {
+		if (hwsim_ratelimit())
+			printk(KERN_DEBUG " hwsim rx-nl: data lenth error: %d  max: %d\n",
+			       frame_data_len, IEEE80211_MAX_DATA_LEN);
+		goto out;
+	}
+
+
+	/* Allocate new skb here */
+	skb = alloc_skb(frame_data_len, GFP_KERNEL);
+	if (skb == NULL) {
+		if (hwsim_ratelimit())
+			printk(KERN_DEBUG " hwsim rx-nl: skb alloc failed, len: %d\n",
+			       frame_data_len);
+		goto out;
+	}
+
+	/* Copy the data */
+	memcpy(skb_put(skb, frame_data_len), frame_data, frame_data_len);
+
 	/* A frame is received from user space */
 	memset(&rx_status, 0, sizeof(rx_status));
 	if (info->attrs[HWSIM_ATTR_FREQ]) {
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change.
  2017-03-23 23:26 [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change greearb
                   ` (2 preceding siblings ...)
  2017-03-23 23:26 ` [PATCH v3 4/4] mac80211-hwsim: add length checks before allocating skb greearb
@ 2017-03-29  8:42 ` Johannes Berg
  2017-03-29 15:35   ` Ben Greear
  3 siblings, 1 reply; 16+ messages in thread
From: Johannes Berg @ 2017-03-29  8:42 UTC (permalink / raw)
  To: greearb, linux-wireless


> +	if (data->center_freq2)
> +		if (nla_put_u32(skb, HWSIM_ATTR_CENTER_FREQ2, data-
> >center_freq2))
> +			goto nla_put_failure;
> 

That could be simplified (but isn't really interesting)

> + * @HWSIM_ATTR_CENTER_FREQ2: Configured center-freq-2.  Not reported
> if value is zero.

The value 0 really just means "unused" - so this should say "if used"
or so.

> + * @HWSIM_ATTR_CH_WIDTH: Configured channel width.

That should point to &enum nl80211_chan_width I guess.

Anyway, all of that is minor. The biggest problem I have with this
patch upon close review is that it only handles one case, and actually
ties that case to the nl80211 API.

hwsim also can deal with channel contexts already, is there much point
in making the userspace API ignorant of that?

johannes

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 2/4] mac80211-hwsim: remove dmesg spam about get-survey.
  2017-03-23 23:26 ` [PATCH v3 2/4] mac80211-hwsim: remove dmesg spam about get-survey greearb
@ 2017-03-29  8:46   ` Johannes Berg
  0 siblings, 0 replies; 16+ messages in thread
From: Johannes Berg @ 2017-03-29  8:46 UTC (permalink / raw)
  To: greearb, linux-wireless

On Thu, 2017-03-23 at 16:26 -0700, greearb@candelatech.com wrote:
> From: Ben Greear <greearb@candelatech.com>
> 
> This message just fills up dmesg and/or kernel logs and does
> not provide any useful information.
> 
Agree, applied.

johannes

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 3/4] mac80211-hwsim: add rate-limited debugging for rx-netlink
  2017-03-23 23:26 ` [PATCH v3 3/4] mac80211-hwsim: add rate-limited debugging for rx-netlink greearb
@ 2017-03-29  8:46   ` Johannes Berg
  2017-03-29 15:39     ` Ben Greear
  0 siblings, 1 reply; 16+ messages in thread
From: Johannes Berg @ 2017-03-29  8:46 UTC (permalink / raw)
  To: greearb, linux-wireless

On Thu, 2017-03-23 at 16:26 -0700, greearb@candelatech.com wrote:
> From: Ben Greear <greearb@candelatech.com>
> 
> This makes it easier to understand why wmediumd (or similar)
> is getting errors when sending frames to the kernel.
> 
> Signed-off-by: Ben Greear <greearb@candelatech.com>
> ---
>  drivers/net/wireless/mac80211_hwsim.c | 55
> +++++++++++++++++++++++++++--------
>  1 file changed, 43 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/net/wireless/mac80211_hwsim.c
> b/drivers/net/wireless/mac80211_hwsim.c
> index 234df8c..84dcddf 100644
> --- a/drivers/net/wireless/mac80211_hwsim.c
> +++ b/drivers/net/wireless/mac80211_hwsim.c
> @@ -137,6 +137,12 @@ static int regtest = HWSIM_REGTEST_DISABLED;
>  module_param(regtest, int, 0444);
>  MODULE_PARM_DESC(regtest, "The type of regulatory test we want to
> run");
>  
> +DEFINE_RATELIMIT_STATE(hwsim_ratelimit_state, 5 * HZ, 10);
> +int hwsim_ratelimit(void)
> +{
> +	return __ratelimit(&hwsim_ratelimit_state);
> +}
> +
>  static const char *hwsim_alpha2s[] = {
>  	"FI",
>  	"AL",
> @@ -1649,7 +1655,7 @@ static int mac80211_hwsim_config(struct
> ieee80211_hw *hw, u32 changed)
>  
>  	if (conf->chandef.chan)
>  		wiphy_debug(hw->wiphy,
> -			    "%s (freq=%d(%d - %d)/%s idle=%d ps=%d
> smps=%s)\n",
> +			    "%s (chandef-chan freq=%d(%d - %d)/%s
> idle=%d ps=%d smps=%s)\n",
>  			    __func__,
>  			    conf->chandef.chan->center_freq,
>  			    conf->chandef.center_freq1,
> @@ -1660,7 +1666,7 @@ static int mac80211_hwsim_config(struct
> ieee80211_hw *hw, u32 changed)
>  			    smps_modes[conf->smps_mode]);
>  	else
>  		wiphy_debug(hw->wiphy,
> -			    "%s (freq=0 idle=%d ps=%d smps=%s)\n",
> +			    "%s (no-chandef-chan freq=0 idle=%d
> ps=%d smps=%s)\n",

This seems unrelated?

johannes

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 4/4] mac80211-hwsim: add length checks before allocating skb.
  2017-03-23 23:26 ` [PATCH v3 4/4] mac80211-hwsim: add length checks before allocating skb greearb
@ 2017-03-29  8:47   ` Johannes Berg
  0 siblings, 0 replies; 16+ messages in thread
From: Johannes Berg @ 2017-03-29  8:47 UTC (permalink / raw)
  To: greearb, linux-wireless

On Thu, 2017-03-23 at 16:26 -0700, greearb@candelatech.com wrote:
> From: Ben Greear <greearb@candelatech.com>
> 
> Modify the receive-from-user-space logic to do length
> and 'is-down' checks before trying to allocate an skb.
> 
> And, if we are going to ignore the pkt due to radio idle,
> then do not return an error code to user-space.  User-space
> cannot reliably know exactly when a radio is idle or not.
> 
Makes sense, but doesn't apply separately.

johannes

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change.
  2017-03-29  8:42 ` [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change Johannes Berg
@ 2017-03-29 15:35   ` Ben Greear
  2017-03-29 16:51     ` Johannes Berg
  0 siblings, 1 reply; 16+ messages in thread
From: Ben Greear @ 2017-03-29 15:35 UTC (permalink / raw)
  To: Johannes Berg, linux-wireless

On 03/29/2017 01:42 AM, Johannes Berg wrote:
>
>> +	if (data->center_freq2)
>> +		if (nla_put_u32(skb, HWSIM_ATTR_CENTER_FREQ2, data-
>>> center_freq2))
>> +			goto nla_put_failure;
>>
>
> That could be simplified (but isn't really interesting)
>
>> + * @HWSIM_ATTR_CENTER_FREQ2: Configured center-freq-2.  Not reported
>> if value is zero.
>
> The value 0 really just means "unused" - so this should say "if used"
> or so.
>
>> + * @HWSIM_ATTR_CH_WIDTH: Configured channel width.
>
> That should point to &enum nl80211_chan_width I guess.
>
> Anyway, all of that is minor. The biggest problem I have with this
> patch upon close review is that it only handles one case, and actually
> ties that case to the nl80211 API.
>
> hwsim also can deal with channel contexts already, is there much point
> in making the userspace API ignorant of that?

The patch appeared to solve my problem, and it seems an improvement
over what is there currently.  Whoever wants it to support even more things
can add that in the future?

If you remember, the first iteration of my patch had the NL API defines
more general, so that someone could just add more data members
as the needs grew.  It can still grow, however.

Thanks,
Ben


-- 
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc  http://www.candelatech.com

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 3/4] mac80211-hwsim: add rate-limited debugging for rx-netlink
  2017-03-29  8:46   ` Johannes Berg
@ 2017-03-29 15:39     ` Ben Greear
  2017-03-29 16:52       ` Johannes Berg
  0 siblings, 1 reply; 16+ messages in thread
From: Ben Greear @ 2017-03-29 15:39 UTC (permalink / raw)
  To: Johannes Berg, linux-wireless

On 03/29/2017 01:46 AM, Johannes Berg wrote:
> On Thu, 2017-03-23 at 16:26 -0700, greearb@candelatech.com wrote:
>> From: Ben Greear <greearb@candelatech.com>
>>
>> This makes it easier to understand why wmediumd (or similar)
>> is getting errors when sending frames to the kernel.
>>
>> Signed-off-by: Ben Greear <greearb@candelatech.com>
>> ---
>>  drivers/net/wireless/mac80211_hwsim.c | 55
>> +++++++++++++++++++++++++++--------
>>  1 file changed, 43 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/net/wireless/mac80211_hwsim.c
>> b/drivers/net/wireless/mac80211_hwsim.c
>> index 234df8c..84dcddf 100644
>> --- a/drivers/net/wireless/mac80211_hwsim.c
>> +++ b/drivers/net/wireless/mac80211_hwsim.c
>> @@ -137,6 +137,12 @@ static int regtest = HWSIM_REGTEST_DISABLED;
>>  module_param(regtest, int, 0444);
>>  MODULE_PARM_DESC(regtest, "The type of regulatory test we want to
>> run");
>>
>> +DEFINE_RATELIMIT_STATE(hwsim_ratelimit_state, 5 * HZ, 10);
>> +int hwsim_ratelimit(void)
>> +{
>> +	return __ratelimit(&hwsim_ratelimit_state);
>> +}
>> +
>>  static const char *hwsim_alpha2s[] = {
>>  	"FI",
>>  	"AL",
>> @@ -1649,7 +1655,7 @@ static int mac80211_hwsim_config(struct
>> ieee80211_hw *hw, u32 changed)
>>
>>  	if (conf->chandef.chan)
>>  		wiphy_debug(hw->wiphy,
>> -			    "%s (freq=%d(%d - %d)/%s idle=%d ps=%d
>> smps=%s)\n",
>> +			    "%s (chandef-chan freq=%d(%d - %d)/%s
>> idle=%d ps=%d smps=%s)\n",
>>  			    __func__,
>>  			    conf->chandef.chan->center_freq,
>>  			    conf->chandef.center_freq1,
>> @@ -1660,7 +1666,7 @@ static int mac80211_hwsim_config(struct
>> ieee80211_hw *hw, u32 changed)
>>  			    smps_modes[conf->smps_mode]);
>>  	else
>>  		wiphy_debug(hw->wiphy,
>> -			    "%s (freq=0 idle=%d ps=%d smps=%s)\n",
>> +			    "%s (no-chandef-chan freq=0 idle=%d
>> ps=%d smps=%s)\n",
>
> This seems unrelated?

It can be cut out of the patch.  Want me to re-send?

Thanks,
Ben

-- 
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc  http://www.candelatech.com

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change.
  2017-03-29 15:35   ` Ben Greear
@ 2017-03-29 16:51     ` Johannes Berg
  2017-03-29 17:11       ` Ben Greear
  0 siblings, 1 reply; 16+ messages in thread
From: Johannes Berg @ 2017-03-29 16:51 UTC (permalink / raw)
  To: Ben Greear, linux-wireless


> The patch appeared to solve my problem, and it seems an improvement
> over what is there currently.  Whoever wants it to support even more
> things can add that in the future?

Yes, that's kinda true. However, it also means that wmediumd (or
similar) would have to support the two APIs. It'd be simpler for them
to just have to support a single one, no?

johannes

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 3/4] mac80211-hwsim: add rate-limited debugging for rx-netlink
  2017-03-29 15:39     ` Ben Greear
@ 2017-03-29 16:52       ` Johannes Berg
  0 siblings, 0 replies; 16+ messages in thread
From: Johannes Berg @ 2017-03-29 16:52 UTC (permalink / raw)
  To: Ben Greear, linux-wireless


> > >  		wiphy_debug(hw->wiphy,
> > > -			    "%s (freq=0 idle=%d ps=%d
> > > smps=%s)\n",
> > > +			    "%s (no-chandef-chan freq=0 idle=%d
> > > ps=%d smps=%s)\n",
> > 
> > This seems unrelated?
> 
> It can be cut out of the patch.  Want me to re-send?

No objection about that change itself, but I don't think it belongs
into the same patch, so yes, please do.

johannes

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change.
  2017-03-29 16:51     ` Johannes Berg
@ 2017-03-29 17:11       ` Ben Greear
  2017-03-31 11:48         ` Johannes Berg
  0 siblings, 1 reply; 16+ messages in thread
From: Ben Greear @ 2017-03-29 17:11 UTC (permalink / raw)
  To: Johannes Berg, linux-wireless

On 03/29/2017 09:51 AM, Johannes Berg wrote:
>
>> The patch appeared to solve my problem, and it seems an improvement
>> over what is there currently.  Whoever wants it to support even more
>> things can add that in the future?
>
> Yes, that's kinda true. However, it also means that wmediumd (or
> similar) would have to support the two APIs. It'd be simpler for them
> to just have to support a single one, no?

I really don't understand what change you are suggesting.  Anything that
uses a new API needs to change, and as API is further improved, then the
app will need to change again.  Netlink's saving grace is that it is easy to
add new data members and so support new API in a forward/backward compatible manner.

Thanks,
Ben

-- 
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc  http://www.candelatech.com

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change.
  2017-03-29 17:11       ` Ben Greear
@ 2017-03-31 11:48         ` Johannes Berg
  2017-03-31 13:33           ` Ben Greear
  0 siblings, 1 reply; 16+ messages in thread
From: Johannes Berg @ 2017-03-31 11:48 UTC (permalink / raw)
  To: Ben Greear, linux-wireless


> I really don't understand what change you are suggesting.  Anything
> that uses a new API needs to change, and as API is further improved,
> then the app will need to change again.  Netlink's saving grace is
> that it is easy to add new data members and so support new API in a
> forward/backward compatible manner.

That's true, but it'd still mean you have to update all the time, and
perhaps then we'll find out it'd be easier to break the API, etc.?

OTOH, supporting (on both sides) channel contexts doesn't seem so hard
- perhaps something like
 * add chanctx
 * remove chanctx
 * change chanctx config

as hwsim commands, and then we can pretend to add/remove in start/stop
if we have non-chanctx-hwsim?

johannes

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change.
  2017-03-31 11:48         ` Johannes Berg
@ 2017-03-31 13:33           ` Ben Greear
  2017-04-18  9:58             ` Johannes Berg
  0 siblings, 1 reply; 16+ messages in thread
From: Ben Greear @ 2017-03-31 13:33 UTC (permalink / raw)
  To: Johannes Berg, linux-wireless



On 03/31/2017 04:48 AM, Johannes Berg wrote:
>
>> I really don't understand what change you are suggesting.  Anything
>> that uses a new API needs to change, and as API is further improved,
>> then the app will need to change again.  Netlink's saving grace is
>> that it is easy to add new data members and so support new API in a
>> forward/backward compatible manner.
>
> That's true, but it'd still mean you have to update all the time, and
> perhaps then we'll find out it'd be easier to break the API, etc.?

In my experience, the big problem with netlink is that if you write
a patch that cannot make it upstream (or takes forever), then the netlink
IDs conflict as upstream adds more stuff.

Other than that, it is easy to add new members, or completely new commands.

User-space can drop old API and simply not fully work against older kernels
if it wants, especially for something as specialized as a simulated
wifi radio.

 >
> OTOH, supporting (on both sides) channel contexts doesn't seem so hard
> - perhaps something like
>  * add chanctx
>  * remove chanctx
>  * change chanctx config
>
> as hwsim commands, and then we can pretend to add/remove in start/stop
> if we have non-chanctx-hwsim?

The project I did this work for is basically done and frozen.  I can tweak
some small API changes to sync up with new netlink ID numbers, but I have no
time to completely re-do the API (and more importantly, to test it all).

So, if my patch can go in as is or with small tweaks, then I'm happy to
keep working on it.  If it needs a complete re-write, then it will have to
wait for someone else or some later date.

Thanks,
Ben

-- 
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc  http://www.candelatech.com

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change.
  2017-03-31 13:33           ` Ben Greear
@ 2017-04-18  9:58             ` Johannes Berg
  0 siblings, 0 replies; 16+ messages in thread
From: Johannes Berg @ 2017-04-18  9:58 UTC (permalink / raw)
  To: Ben Greear, linux-wireless

On Fri, 2017-03-31 at 06:33 -0700, Ben Greear wrote:
> 
> In my experience, the big problem with netlink is that if you write
> a patch that cannot make it upstream (or takes forever), then the
> netlink IDs conflict as upstream adds more stuff.

Sure, that's a common problem we all run into :)

> Other than that, it is easy to add new members, or completely new
> commands.
> 
> User-space can drop old API and simply not fully work against older
> kernels if it wants, especially for something as specialized as a
> simulated wifi radio.

Yeah, but the kernel will have to maintain both versions, and strictly
speaking shouldn't be breaking old userspace - but that would be
impossible as one moves to chanctx, perhaps even by default.

This is the problem I have with it - chanctx code already exists and is
used, so there's no technical reason not to support both now.

> So, if my patch can go in as is or with small tweaks, then I'm happy
> to keep working on it.  If it needs a complete re-write, then it will
> have to wait for someone else or some later date.

Ok, that's fair. I think I'll leave it out then though, because I
really do think that we should aim to support chanctx from the start
with this, it's well-established by now.

johannes

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2017-04-18  9:58 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-23 23:26 [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change greearb
2017-03-23 23:26 ` [PATCH v3 2/4] mac80211-hwsim: remove dmesg spam about get-survey greearb
2017-03-29  8:46   ` Johannes Berg
2017-03-23 23:26 ` [PATCH v3 3/4] mac80211-hwsim: add rate-limited debugging for rx-netlink greearb
2017-03-29  8:46   ` Johannes Berg
2017-03-29 15:39     ` Ben Greear
2017-03-29 16:52       ` Johannes Berg
2017-03-23 23:26 ` [PATCH v3 4/4] mac80211-hwsim: add length checks before allocating skb greearb
2017-03-29  8:47   ` Johannes Berg
2017-03-29  8:42 ` [PATCH v3 1/4] mac80211-hwsim: notify user-space about channel change Johannes Berg
2017-03-29 15:35   ` Ben Greear
2017-03-29 16:51     ` Johannes Berg
2017-03-29 17:11       ` Ben Greear
2017-03-31 11:48         ` Johannes Berg
2017-03-31 13:33           ` Ben Greear
2017-04-18  9:58             ` Johannes Berg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.