Simulate medium behavior
RFC 1/1 Simulate medium behavior
Hi,
I'm still working improving the scan behavior of NM. Yes, I'm terrible slow. One thing which would help for this work is to simulate the wireless medium.
Below is my humble try to get a knob for enabling/disabling tx/rx. The variable name 'medium' is not really good, though I didn't come up with something better.
Writing a 0 to /debug/ieee80211/phy*/hwsim/medium enables rx/tx for the specific phy. Writing anything but 0 disables rx/tx. Not a very good API. It could be made something more realistic like reception quality is 80% associated some statistical dropping algorithm. Any thoughts?
Is this the right direction I'm heading to?
thanks,
daniel
--- drivers/net/wireless/mac80211_hwsim.c | 32 +++++++++++++++++++++++++++++++- 1 files changed, 31 insertions(+), 1 deletions(-)
drivers/net/wireless/mac80211_hwsim.c +31 -1
@@ -291,6 +291,9 @@ struct mac80211_hwsim_data {bool ps_poll_pending;struct dentry *debugfs;struct dentry *debugfs_ps; + +struct dentry *debugfs_medium; +unsigned int medium; };
@@ -399,6 +402,11 @@ static bool mac80211_hwsim_tx_frame(struct ieee80211_hw *hw, rx_status.rate_idx = info->control.rates[0 ].idx;/* TODO: simulate signal strength (and optional packet drop) */ +if (data->medium !=0 ) { +/* drop packet, no ack received */ +return false; + } +if (data->ps !=PS_DISABLED ) hdr->frame_control |=cpu_to_le16 (IEEE80211_FCTL_PM );
@@ -412,7 +420,8 @@ static bool mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,if (!data2->started || !data2->radio_enabled || !hwsim_ps_rx_ok (data2, skb) || - data->channel->center_freq != data2->channel->center_freq) + data->channel->center_freq != data2->channel->center_freq || + data2->medium !=0 )continue ; nskb =skb_copy (skb,GFP_ATOMIC );
@@ -725,6 +734,7 @@ static void mac80211_hwsim_free(void)spin_unlock_bh (&hwsim_radio_lock);list_for_each_entry (data, &tmplist, list) { +debugfs_remove (data->debugfs_medium);debugfs_remove (data->debugfs_ps);debugfs_remove (data->debugfs);ieee80211_unregister_hw (data->hw);
@@ -876,6 +886,22 @@ static int hwsim_fops_ps_write(void *dat, u64 val)DEFINE_SIMPLE_ATTRIBUTE (hwsim_fops_ps, hwsim_fops_ps_read, hwsim_fops_ps_write,"%llu\n" ); +static int hwsim_fops_medium_read (void *dat,u64 *val) +{ +struct mac80211_hwsim_data *data = dat; + *val = data->medium; +return 0 ; +} + +static int hwsim_fops_medium_write (void *dat,u64 val) +{ +struct mac80211_hwsim_data *data = dat; + data->medium = val; +return 0 ; +} + +DEFINE_SIMPLE_ATTRIBUTE (hwsim_fops_medium, hwsim_fops_medium_read, hwsim_fops_medium_write, +"%llu\n" );static int __init init_mac80211_hwsim (void ) {
@@ -1106,6 +1132,10 @@ static int __init init_mac80211_hwsim(void) data->debugfs, data, &hwsim_fops_ps); + data->debugfs_medium =debugfs_create_file ("medium" ,0666 , + data->debugfs, data, + &hwsim_fops_medium); +setup_timer (&data->beacon_timer, mac80211_hwsim_beacon, (unsigned long ) hw);
Signature · 1 line
1.6.0.2.GIT
Johannes Berg
maintainerHi,
Quoted 7 lines
Writing a 0 to /debug/ieee80211/phy*/hwsim/medium enables rx/tx for the specific phy. Writing anything but 0 disables rx/tx. Not a very good API. It could be made something more realistic like reception quality is 80% associated some statistical dropping algorithm. Any thoughts?
Is this the right direction I'm heading to?
This looks like a very simple knob, just a little more work could get you much further -- have you seen this email/thread?
http://thread.gmane.org/gmane.linux.kernel.wireless.general/25001
johannes
Quoted 8 lines · Johannes Berg
Hi,
Quoted 6 lines
Writing a 0 to /debug/ieee80211/phy*/hwsim/medium enables rx/tx for the specific phy. Writing anything but 0 disables rx/tx. Not a very good API. It could be made something more realistic like reception quality is 80% associated some statistical dropping algorithm. Any thoughts?
Quoted 6 lines
Quoted 1 line
Is this the right direction I'm heading to?
This looks like a very simple knob, just a little more work could get you much further -- have you seen this email/thread?
http://thread.gmane.org/gmane.linux.kernel.wireless.general/25001
No, I haven't. Yep, my solution is really too simple. I like the virtual air grouping. I'll implement it.
thanks for the tip!
daniel
Quoted 11 lines · Daniel Wagner
Quoted 10 lines · Johannes Berg
Hi,
Quoted 7 lines
Writing a 0 to /debug/ieee80211/phy*/hwsim/medium enables rx/tx for the specific phy. Writing anything but 0 disables rx/tx. Not a very good API. It could be made something more realistic like reception quality is 80% associated some statistical dropping algorithm. Any thoughts?
Is this the right direction I'm heading to?
Quoted 7 lines
Quoted 4 lines
This looks like a very simple knob, just a little more work could get you much further -- have you seen this email/thread?
http://thread.gmane.org/gmane.linux.kernel.wireless.general/25001
No, I haven't. Yep, my solution is really too simple. I like the virtual air grouping. I'll implement it.
After a bit studying how to use configfs (and getting a bit lost) I found netconsole.c which uses configfs. So this version is a copy&past thing. Of course, this needs more work.
Is this what do did have in mind?
How it works:
# modprobe mac80211_hwsim # mount -t configfs none /config
Make phy0 radio member of group 1:
# mkdir /config/mac80211_hwsim/phy0 # echo "phy0" > /config/mac80211_hwsim/phy0/dev_name # echo 1 > /config/mac80211_hwsim/phy0/group # echo 1 > /config/mac80211_hwsim/phy0/enable
I have only tested it very short, no problems found. Works as expected :)
cheers,
daniel
--- drivers/net/wireless/Kconfig | 9 + drivers/net/wireless/mac80211_hwsim.c | 324 ++++++++++++++++++++++++++++++++- 2 files changed, 332 insertions(+), 1 deletions(-)
drivers/net/wireless/Kconfig +9 -0
@@ -481,6 +481,15 @@ config MAC80211_HWSIM To compile this driver as a module, choose M here: the module will be called mac80211_hwsim. If unsure, say N. +config MAC80211_HWSIM_VGROUP + bool "enable virtual air grouping" + depends on MAC80211_HWSIM + default y + help + This option enables virtual air grouping. + + If unsure, say N. + config MWL8K tristate "Marvell 88W8xxx PCI/PCIe Wireless support" depends on MAC80211 && PCI && WLAN_80211 && EXPERIMENTAL
drivers/net/wireless/mac80211_hwsim.c +323 -1
360 lines not on this page · raw message
Signature · 1 line
1.6.2.4
Johannes Berg
maintainerHi Daniel,
Quoted 10 lines
Quoted 4 lines
No, I haven't. Yep, my solution is really too simple. I like the virtual air grouping. I'll implement it.
After a bit studying how to use configfs (and getting a bit lost) I found
netconsole.cwhich uses configfs. So this version is a copy&past thing. Of course, this needs more work.Is this what do did have in mind?
Very cool. We had a patch at some point to add configfs support to hwsim but it seems it got lost :(
But I don't think your configfs support is optimal since you need to create those dirs for phy0 and put the name in etc. even when phy0 already exists. I'm sorry to have wasted your time with the configfs suggestion, but I think with how hwsim _currently_ behaves, without configfs support for creating new radios etc., putting this into debugfs would be nicer, since debugfs already has a dir for this from cfg80211/mac80211...
drivers/net/wireless/Kconfig config MAC80211_HWSIM · line 491
Quoted 8 lines
drivers/net/wireless/Kconfig +8
-0+config MAC80211_HWSIM_VGROUP + bool "enable virtual air grouping" + depends on MAC80211_HWSIM + default y + help + This option enables virtual air grouping. + + If unsure, say N.
I also wouldn't make it configurable, just make it default to group == 1 so that it behaves as it was.
johannes
Hi Johannes
Quoted 11 lines · Johannes Berg
Hi Daniel,
Quoted 9 lines
Quoted 4 lines
No, I haven't. Yep, my solution is really too simple. I like the virtual air grouping. I'll implement it.
After a bit studying how to use configfs (and getting a bit lost) I found
netconsole.cwhich uses configfs. So this version is a copy&past thing. Of course, this needs more work.
Quoted 8 lines
Quoted 1 line
Is this what do did have in mind?
Very cool. We had a patch at some point to add configfs support to hwsim but it seems it got lost :(
But I don't think your configfs support is optimal since you need to create those dirs for phy0 and put the name in etc. even when phy0 already exists.
Yes, that was also what I thought. If I understood it correctly that is exactly the main difference between configfs and debugfs. In configfs the userspace has the owner ship of the 'objects' (mkdir, rmdir) whereas in debugfs the kernel controls the lifetime of the 'objects'.
Quoted 5 lines
I'm sorry to have wasted your time with the configfs suggestion, but I think with how hwsim _currently_ behaves, without configfs support for creating new radios etc., putting this into debugfs would be nicer, since debugfs already has a dir for this from cfg80211/mac80211...
No problem. I was able to learn something :) Ok, I'll cook up the next version.
Quoted 11 lines
drivers/net/wireless/Kconfig config MAC80211_HWSIM · line 491
Quoted 8 lines
drivers/net/wireless/Kconfig +8
-0+config MAC80211_HWSIM_VGROUP + bool "enable virtual air grouping" + depends on MAC80211_HWSIM + default y + help + This option enables virtual air grouping. + + If unsure, say N.I also wouldn't make it configurable, just make it default to group == 1 so that it behaves as it was.
Good point.
Thanks for your comments!
cheers,
daniel
Hi Johannes,
Quoted 7 lines · Johannes Berg
But I don't think your configfs support is optimal since you need to create those dirs for phy0 and put the name in etc. even when phy0 already exists. I'm sorry to have wasted your time with the configfs suggestion, but I think with how hwsim _currently_ behaves, without configfs support for creating new radios etc., putting this into debugfs would be nicer, since debugfs already has a dir for this from cfg80211/mac80211...
Here we go (slow as usual :)
Subject: [PATCH] mac80211_hwsim: Group radios
Each bit in /debug/ieee80211/phy*/hwsim/group represents one group. By default all radios belong to the same group "1". A radio can belong to several groups.
--- drivers/net/wireless/mac80211_hwsim.c | 30 +++++++++++++++++++++++++++++- 1 files changed, 29 insertions(+), 1 deletions(-)
drivers/net/wireless/mac80211_hwsim.c +29 -1
@@ -291,6 +291,9 @@ struct mac80211_hwsim_data {bool ps_poll_pending;struct dentry *debugfs;struct dentry *debugfs_ps; + +u64 group; +struct dentry *debugfs_group; };
@@ -412,7 +415,8 @@ static bool mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,if (!data2->started || !data2->radio_enabled || !hwsim_ps_rx_ok (data2, skb) || - data->channel->center_freq != data2->channel->center_freq) + data->channel->center_freq != data2->channel->center_freq || + !(data->group & data2->group))continue ; nskb =skb_copy (skb,GFP_ATOMIC );
@@ -720,6 +724,7 @@ static void mac80211_hwsim_free(void)spin_unlock_bh (&hwsim_radio_lock);list_for_each_entry (data, &tmplist, list) { +debugfs_remove (data->debugfs_group);debugfs_remove (data->debugfs_ps);debugfs_remove (data->debugfs);ieee80211_unregister_hw (data->hw);
@@ -872,6 +877,24 @@ DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_ps, hwsim_fops_ps_read, hwsim_fops_ps_write, "%llu\n"); +static int hwsim_fops_group_read (void *dat,u64 *val) +{ +struct mac80211_hwsim_data *data = dat; + *val = data->group; +return 0 ; +} + +static int hwsim_fops_group_write (void *dat,u64 val) +{ +struct mac80211_hwsim_data *data = dat; + data->group = val; +return 0 ; +} + +DEFINE_SIMPLE_ATTRIBUTE (hwsim_fops_group, + hwsim_fops_group_read, hwsim_fops_group_write, +"%llu\n" ); +static int __init init_mac80211_hwsim (void ) {int i, err =0 ;
@@ -976,6 +999,8 @@ static int __init init_mac80211_hwsim(void) hw->wiphy->bands[band] = sband; } +/* By default all radios are belonging to the first group */ + data->group =1 ;/* Work to be done prior to ieee80211_register_hw() */ switch (regtest) {
@@ -1100,6 +1125,9 @@ static int __init init_mac80211_hwsim(void) data->debugfs_ps =debugfs_create_file ("ps" ,0666 , data->debugfs, data, &hwsim_fops_ps); + data->debugfs_group =debugfs_create_file ("group" ,0666 , + data->debugfs, data, + &hwsim_fops_group);setup_timer (&data->beacon_timer, mac80211_hwsim_beacon, (unsigned long ) hw);
Signature · 1 line
1.6.2.4
Johannes Berg
maintainerOn Thu, 2009-05-14 at 20:45 +0200, Daniel Wagner wrote:
Looks good to me, couple of comments below.
Quoted 7 lines
drivers/net/wireless/mac80211_hwsim.c +7
-0+static int hwsim_fops_group_read (void *dat,u64 *val) +{ +struct mac80211_hwsim_data *data = dat; + *val = data->group; +return 0 ; +} +
drivers/net/wireless/mac80211_hwsim.c DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_ps, hwsim_fops_ps_read, hwsim_fops_ps_write, · line 896
Quoted 10 lines
drivers/net/wireless/mac80211_hwsim.c +10
-0+static int hwsim_fops_group_write (void *dat,u64 val) +{ +struct mac80211_hwsim_data *data = dat; + data->group = val; +return 0 ; +} + +DEFINE_SIMPLE_ATTRIBUTE (hwsim_fops_group, + hwsim_fops_group_read, hwsim_fops_group_write, +"%llu\n" );
I think %llx would work better for this? At least I can do bitops better in hex :)
drivers/net/wireless/mac80211_hwsim.c static int __init init_mac80211_hwsim(void) · line 1130
Quoted 6 lines
drivers/net/wireless/mac80211_hwsim.c +3
-0data->debugfs_ps =debugfs_create_file ("ps" ,0666 , data->debugfs, data, &hwsim_fops_ps); + data->debugfs_group =debugfs_create_file ("group" ,0666 , + data->debugfs, data, + &hwsim_fops_group);
Good thing this is a test module only... debugfs files with user access permissions are a security risk. (a user can open the file and leave the fd open, if root then rmmods future reads/writes to the fd by the user crash the kernel)
Anyway looks good, please submit properly with [PATCH] etc :)
johannes
Quoted 16 lines · Johannes Berg
On Thu, 2009-05-14 at 20:45 +0200, Daniel Wagner wrote:
Looks good to me, couple of comments below.
Quoted 12 lines
drivers/net/wireless/mac80211_hwsim.c +12
-0+static int hwsim_fops_group_read (void *dat,u64 *val) +{ +struct mac80211_hwsim_data *data = dat; + *val = data->group; +return 0 ; +} + +static int hwsim_fops_group_write (void *dat,u64 val) +{ +struct mac80211_hwsim_data *data = dat; + data->group = val; +return 0 ;
Quoted 8 lines
drivers/net/wireless/mac80211_hwsim.c DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_ps, hwsim_fops_ps_read, hwsim_fops_ps_write, · line 896
Quoted 5 lines
drivers/net/wireless/mac80211_hwsim.c +5
-0+} + +DEFINE_SIMPLE_ATTRIBUTE (hwsim_fops_group, + hwsim_fops_group_read, hwsim_fops_group_write, +"%llu\n" );I think %llx would work better for this? At least I can do bitops better in hex :)
Yeah, I have to improve my copy&paste-foo :)
Quoted 12 lines
drivers/net/wireless/mac80211_hwsim.c static int __init init_mac80211_hwsim(void) · line 1130
Quoted 7 lines
drivers/net/wireless/mac80211_hwsim.c +3
-0data->debugfs_ps =debugfs_create_file ("ps" ,0666 , data->debugfs, data, &hwsim_fops_ps); + data->debugfs_group =debugfs_create_file ("group" ,0666 , + data->debugfs, data, + &hwsim_fops_group);Good thing this is a test module only... debugfs files with user access permissions are a security risk. (a user can open the file and leave the fd open, if root then rmmods future reads/writes to the fd by the user crash the kernel)
There isn't much we can do about that, right?
Quoted 1 line
Anyway looks good, please submit properly with [PATCH] etc :)
Done.
Thanks for reviewing!
cheers,
daniel
Johannes Berg
maintainerQuoted 12 lines · Daniel Wagner
Quoted 11 lines
drivers/net/wireless/mac80211_hwsim.c static int __init init_mac80211_hwsim(void) · line 1130
Quoted 6 lines
drivers/net/wireless/mac80211_hwsim.c +3
-0data->debugfs_ps =debugfs_create_file ("ps" ,0666 , data->debugfs, data, &hwsim_fops_ps); + data->debugfs_group =debugfs_create_file ("group" ,0666 , + data->debugfs, data, + &hwsim_fops_group);Good thing this is a test module only... debugfs files with user access permissions are a security risk. (a user can open the file and leave the fd open, if root then rmmods future reads/writes to the fd by the user crash the kernel)
Quoted 1 line
There isn't much we can do about that, right?
I generally just use 0600 to not allow regular users to open the files. Maybe at some point, with the revoke() discussion, we'll actually get a solution.
johannes