Re: [PATCH 09/10] mac80211_hwsim: Add command to control rx status RSSI

2017-09-29 Thread Luca Coelho
On Wed, 2017-09-06 at 12:33 +0200, Johannes Berg wrote:
> On Sat, 2017-08-05 at 11:44 +0300, Luca Coelho wrote:
> > 
> > +static int hwsim_fops_rx_rssi_write(void *dat, u64 val)
> > +{
> > +   struct mac80211_hwsim_data *data = dat;
> > +   int rssi = (int)val;
> 
> That cast is wrong - you should go to s64, do the range check, and
> only
> then restrict to int. Basically, just do
> 
> s64 rssi = val;
> 
> in this line instead.
> 
> 
> > +   debugfs_create_file("rx_rssi", 0666, data->debugfs, data,
> > +   &hwsim_fops_rx_rssi);
> 
> I also can't say I'm really happy with this, since there's no such
> thing as an "RX RSSI".
> 
> Also, wmediumd already allows changing this - I'd rather people start
> using the infrastructure better than papering over more.
> 
> IOW - do we really need this? Why can't you do the (simple) wmediumd
> setup? There's even a hwsim test in wpa_s with wmediumd, it's not all
> that difficult.

Beni,

Can you answer Johannes here? I'm removing this patch from my pending
list, so I won't take any action anymore until further notice.

--
Cheers,
Luca.


Re: [PATCH 09/10] mac80211_hwsim: Add command to control rx status RSSI

2017-09-06 Thread Johannes Berg
On Sat, 2017-08-05 at 11:44 +0300, Luca Coelho wrote:
> 
> +static int hwsim_fops_rx_rssi_write(void *dat, u64 val)
> +{
> + struct mac80211_hwsim_data *data = dat;
> + int rssi = (int)val;

That cast is wrong - you should go to s64, do the range check, and only
then restrict to int. Basically, just do

s64 rssi = val;

in this line instead.


> + debugfs_create_file("rx_rssi", 0666, data->debugfs, data,
> + &hwsim_fops_rx_rssi);

I also can't say I'm really happy with this, since there's no such
thing as an "RX RSSI".

Also, wmediumd already allows changing this - I'd rather people start
using the infrastructure better than papering over more.

IOW - do we really need this? Why can't you do the (simple) wmediumd
setup? There's even a hwsim test in wpa_s with wmediumd, it's not all
that difficult.

johannes


[PATCH 09/10] mac80211_hwsim: Add command to control rx status RSSI

2017-08-05 Thread Luca Coelho
From: Beni Lev 

Set the base RSSI of a TX frame. The final RSSI of the frame will be
the base RSSI + the radio's TX power

Signed-off-by: Beni Lev 
Signed-off-by: Luca Coelho 
---
 drivers/net/wireless/mac80211_hwsim.c | 36 +--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/mac80211_hwsim.c 
b/drivers/net/wireless/mac80211_hwsim.c
index 6467ffac9811..7c3811f0c730 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -368,6 +368,8 @@ static const struct ieee80211_rate hwsim_rates[] = {
{ .bitrate = 540 }
 };
 
+#define DEFAULT_RX_RSSI -50
+
 #define OUI_QCA 0x001374
 #define QCA_NL80211_SUBCMD_TEST 1
 enum qca_nl80211_vendor_subcmds {
@@ -571,6 +573,9 @@ struct mac80211_hwsim_data {
u64 rx_bytes;
u64 tx_dropped;
u64 tx_failed;
+
+   /* RSSI in rx status of the receiver */
+   int rx_rssi;
 };
 
 
@@ -783,6 +788,29 @@ DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_group,
hwsim_fops_group_read, hwsim_fops_group_write,
"%llx\n");
 
+static int hwsim_fops_rx_rssi_read(void *dat, u64 *val)
+{
+   struct mac80211_hwsim_data *data = dat;
+   *val = data->rx_rssi;
+   return 0;
+}
+
+static int hwsim_fops_rx_rssi_write(void *dat, u64 val)
+{
+   struct mac80211_hwsim_data *data = dat;
+   int rssi = (int)val;
+
+   if (rssi >= 0 || rssi < -100)
+   return -EINVAL;
+
+   data->rx_rssi = rssi;
+   return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_rx_rssi,
+   hwsim_fops_rx_rssi_read, hwsim_fops_rx_rssi_write,
+   "%lld\n");
+
 static netdev_tx_t hwsim_mon_xmit(struct sk_buff *skb,
struct net_device *dev)
 {
@@ -1210,8 +1238,8 @@ static bool mac80211_hwsim_tx_frame_no_nl(struct 
ieee80211_hw *hw,
rx_status.bw = RATE_INFO_BW_20;
if (info->control.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
rx_status.enc_flags |= RX_ENC_FLAG_SHORT_GI;
-   /* TODO: simulate real signal strength (and optional packet loss) */
-   rx_status.signal = -50;
+   /* TODO: simulate optional packet loss */
+   rx_status.signal = data->rx_rssi;
if (info->control.vif)
rx_status.signal += info->control.vif->bss_conf.txpower;
 
@@ -2554,6 +2582,8 @@ static int mac80211_hwsim_new_radio(struct genl_info 
*info,
hw->wiphy->n_iface_combinations = ARRAY_SIZE(hwsim_if_comb);
}
 
+   data->rx_rssi = DEFAULT_RX_RSSI;
+
INIT_DELAYED_WORK(&data->roc_start, hw_roc_start);
INIT_DELAYED_WORK(&data->roc_done, hw_roc_done);
INIT_DELAYED_WORK(&data->hw_scan, hw_scan_work);
@@ -2715,6 +2745,8 @@ static int mac80211_hwsim_new_radio(struct genl_info 
*info,
debugfs_create_file("ps", 0666, data->debugfs, data, &hwsim_fops_ps);
debugfs_create_file("group", 0666, data->debugfs, data,
&hwsim_fops_group);
+   debugfs_create_file("rx_rssi", 0666, data->debugfs, data,
+   &hwsim_fops_rx_rssi);
if (!data->use_chanctx)
debugfs_create_file("dfs_simulate_radar", 0222,
data->debugfs,
-- 
2.13.2