* [PATCHv2 1/3] mac80211_hwsim: Add tsf to beacons, probe responses and radiotap header.
@ 2012-03-01 23:40 Javier Cardona
2012-03-01 23:40 ` [PATCHv2 2/3] mac80211: Modify tsf via debugfs in mesh interfaces Javier Cardona
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Javier Cardona @ 2012-03-01 23:40 UTC (permalink / raw)
To: John W. Linville; +Cc: Javier Cardona, devel, Johannes Berg, linux-wireless
Generate a tsf from jiffies. Prepare the path for having different tsf
offsets on the each phy. This will be useful for testing mesh
synchronization algorithms.
Signed-off-by: Javier Cardona <javier@cozybit.com>
---
v2: Added timestamp to probe responses, as suggested by Johannes
Also implement tx_last_beacon, useful for testing (new patch 1/3)
drivers/net/wireless/mac80211_hwsim.c | 37 +++++++++++++++++++++++++++++---
1 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index ba16f05..f44b3f6 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -321,11 +321,13 @@ struct mac80211_hwsim_data {
struct dentry *debugfs_group;
int power_level;
+ int tsf_offset; /* in TUs */
};
struct hwsim_radiotap_hdr {
struct ieee80211_radiotap_header hdr;
+ u64 rt_tsft;
u8 rt_flags;
u8 rt_rate;
__le16 rt_channel;
@@ -367,6 +369,11 @@ static netdev_tx_t hwsim_mon_xmit(struct sk_buff *skb,
return NETDEV_TX_OK;
}
+static __le64 __mac80211_hwsim_get_tsf(struct mac80211_hwsim_data *data)
+{
+ return cpu_to_le64(jiffies_to_msecs(jiffies)*1000/1024 +
+ data->tsf_offset);
+}
static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw,
struct sk_buff *tx_skb)
@@ -391,7 +398,9 @@ static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw,
hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr));
hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
(1 << IEEE80211_RADIOTAP_RATE) |
+ (1 << IEEE80211_RADIOTAP_TSFT) |
(1 << IEEE80211_RADIOTAP_CHANNEL));
+ hdr->rt_tsft = __mac80211_hwsim_get_tsf(data);
hdr->rt_flags = 0;
hdr->rt_rate = txrate->bitrate / 5;
hdr->rt_channel = cpu_to_le16(data->channel->center_freq);
@@ -610,7 +619,8 @@ static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw,
}
memset(&rx_status, 0, sizeof(rx_status));
- /* TODO: set mactime */
+ rx_status.mactime = le64_to_cpu(__mac80211_hwsim_get_tsf(data));
+ rx_status.flag |= RX_FLAG_MACTIME_MPDU;
rx_status.freq = data->channel->center_freq;
rx_status.band = data->channel->band;
rx_status.rate_idx = info->control.rates[0].idx;
@@ -667,6 +677,19 @@ static void mac80211_hwsim_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
bool ack;
struct ieee80211_tx_info *txi;
u32 _pid;
+ struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+ struct mac80211_hwsim_data *data = hw->priv;
+ __le64 *tsfpos;
+ u16 fc = le16_to_cpu(hdr->frame_control);
+ u16 fctypes = fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE);
+
+ if (fctypes == (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP) ||
+ fctypes == (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON)) {
+ struct ieee80211_hdr_3addr *hdr3 =
+ (struct ieee80211_hdr_3addr *) skb->data;
+ tsfpos = (__le64 *) (hdr3 + 1);
+ put_unaligned(__mac80211_hwsim_get_tsf(data), tsfpos);
+ }
mac80211_hwsim_monitor_rx(hw, skb);
@@ -685,10 +708,8 @@ static void mac80211_hwsim_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
/* NO wmediumd detected, perfect medium simulation */
ack = mac80211_hwsim_tx_frame_no_nl(hw, skb);
- if (ack && skb->len >= 16) {
- struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+ if (ack && skb->len >= 16)
mac80211_hwsim_monitor_ack(hw, hdr->addr2);
- }
txi = IEEE80211_SKB_CB(skb);
@@ -763,9 +784,12 @@ static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac,
struct ieee80211_vif *vif)
{
struct ieee80211_hw *hw = arg;
+ struct mac80211_hwsim_data *data = hw->priv;
struct sk_buff *skb;
struct ieee80211_tx_info *info;
u32 _pid;
+ struct ieee80211_hdr_3addr *hdr;
+ __le64 *tsfpos;
hwsim_check_magic(vif);
@@ -779,6 +803,11 @@ static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac,
return;
info = IEEE80211_SKB_CB(skb);
+ /* add the timestamp to the beacon */
+ hdr = (struct ieee80211_hdr_3addr *) skb->data;
+ tsfpos = (__le64 *) (hdr + 1);
+ put_unaligned(__mac80211_hwsim_get_tsf(data), tsfpos);
+
mac80211_hwsim_monitor_rx(hw, skb);
/* wmediumd mode check */
--
1.7.6
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCHv2 2/3] mac80211: Modify tsf via debugfs in mesh interfaces
2012-03-01 23:40 [PATCHv2 1/3] mac80211_hwsim: Add tsf to beacons, probe responses and radiotap header Javier Cardona
@ 2012-03-01 23:40 ` Javier Cardona
2012-03-01 23:40 ` [PATCHv2 3/3] mac80211_hwsim: Implement ieee80211_ops:tx_last_beacon Javier Cardona
2012-03-02 7:49 ` [PATCHv2 1/3] mac80211_hwsim: Add tsf to beacons, probe responses and radiotap header Johannes Berg
2 siblings, 0 replies; 6+ messages in thread
From: Javier Cardona @ 2012-03-01 23:40 UTC (permalink / raw)
To: John W. Linville; +Cc: Javier Cardona, devel, Johannes Berg, linux-wireless
Signed-off-by: Javier Cardona <javier@cozybit.com>
---
drivers/net/wireless/mac80211_hwsim.c | 16 ++++++++++++++++
net/mac80211/debugfs_netdev.c | 7 ++++++-
2 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index f44b3f6..deed95f 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -375,6 +375,20 @@ static __le64 __mac80211_hwsim_get_tsf(struct mac80211_hwsim_data *data)
data->tsf_offset);
}
+static u64 mac80211_hwsim_get_tsf(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif)
+{
+ struct mac80211_hwsim_data *data = hw->priv;
+ return le64_to_cpu(__mac80211_hwsim_get_tsf(data));
+}
+
+static void mac80211_hwsim_set_tsf(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif, u64 tsf)
+{
+ struct mac80211_hwsim_data *data = hw->priv;
+ data->tsf_offset = tsf - jiffies_to_msecs(jiffies)*1000/1024;
+}
+
static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw,
struct sk_buff *tx_skb)
{
@@ -1228,6 +1242,8 @@ static struct ieee80211_ops mac80211_hwsim_ops =
.sw_scan_start = mac80211_hwsim_sw_scan,
.sw_scan_complete = mac80211_hwsim_sw_scan_complete,
.flush = mac80211_hwsim_flush,
+ .get_tsf = mac80211_hwsim_get_tsf,
+ .set_tsf = mac80211_hwsim_set_tsf,
};
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index 510ed1d..416b906 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -537,11 +537,15 @@ static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
#ifdef CONFIG_MAC80211_MESH
+static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
+{
+ DEBUGFS_ADD_MODE(tsf, 0600);
+}
+
static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
{
struct dentry *dir = debugfs_create_dir("mesh_stats",
sdata->debugfs.dir);
-
#define MESHSTATS_ADD(name)\
debugfs_create_file(#name, 0400, dir, sdata, &name##_ops);
@@ -593,6 +597,7 @@ static void add_files(struct ieee80211_sub_if_data *sdata)
switch (sdata->vif.type) {
case NL80211_IFTYPE_MESH_POINT:
#ifdef CONFIG_MAC80211_MESH
+ add_mesh_files(sdata);
add_mesh_stats(sdata);
add_mesh_config(sdata);
#endif
--
1.7.6
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCHv2 3/3] mac80211_hwsim: Implement ieee80211_ops:tx_last_beacon
2012-03-01 23:40 [PATCHv2 1/3] mac80211_hwsim: Add tsf to beacons, probe responses and radiotap header Javier Cardona
2012-03-01 23:40 ` [PATCHv2 2/3] mac80211: Modify tsf via debugfs in mesh interfaces Javier Cardona
@ 2012-03-01 23:40 ` Javier Cardona
2012-03-02 7:50 ` Johannes Berg
2012-03-02 7:49 ` [PATCHv2 1/3] mac80211_hwsim: Add tsf to beacons, probe responses and radiotap header Johannes Berg
2 siblings, 1 reply; 6+ messages in thread
From: Javier Cardona @ 2012-03-01 23:40 UTC (permalink / raw)
To: John W. Linville; +Cc: Javier Cardona, devel, Johannes Berg, linux-wireless
Without this you won't see probe responses in an IBSS/hwsim network,
which is convenient for testing.
Signed-off-by: Javier Cardona <javier@cozybit.com>
---
drivers/net/wireless/mac80211_hwsim.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index deed95f..e4b6ca6 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -47,6 +47,8 @@ static bool fake_hw_scan;
module_param(fake_hw_scan, bool, 0444);
MODULE_PARM_DESC(fake_hw_scan, "Install fake (no-op) hw-scan handler");
+static struct ieee80211_hw *txed_last_beacon;
+
/**
* enum hwsim_regtest - the type of regulatory tests we offer
*
@@ -821,6 +823,7 @@ static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac,
hdr = (struct ieee80211_hdr_3addr *) skb->data;
tsfpos = (__le64 *) (hdr + 1);
put_unaligned(__mac80211_hwsim_get_tsf(data), tsfpos);
+ txed_last_beacon = hw;
mac80211_hwsim_monitor_rx(hw, skb);
@@ -1220,6 +1223,11 @@ static void mac80211_hwsim_sw_scan_complete(struct ieee80211_hw *hw)
mutex_unlock(&hwsim->mutex);
}
+static int mac80211_hwsim_tx_last_beacon(struct ieee80211_hw *hw)
+{
+ return (hw == txed_last_beacon);
+}
+
static struct ieee80211_ops mac80211_hwsim_ops =
{
.tx = mac80211_hwsim_tx,
@@ -1244,6 +1252,7 @@ static struct ieee80211_ops mac80211_hwsim_ops =
.flush = mac80211_hwsim_flush,
.get_tsf = mac80211_hwsim_get_tsf,
.set_tsf = mac80211_hwsim_set_tsf,
+ .tx_last_beacon = mac80211_hwsim_tx_last_beacon,
};
--
1.7.6
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCHv2 1/3] mac80211_hwsim: Add tsf to beacons, probe responses and radiotap header.
2012-03-01 23:40 [PATCHv2 1/3] mac80211_hwsim: Add tsf to beacons, probe responses and radiotap header Javier Cardona
2012-03-01 23:40 ` [PATCHv2 2/3] mac80211: Modify tsf via debugfs in mesh interfaces Javier Cardona
2012-03-01 23:40 ` [PATCHv2 3/3] mac80211_hwsim: Implement ieee80211_ops:tx_last_beacon Javier Cardona
@ 2012-03-02 7:49 ` Johannes Berg
2 siblings, 0 replies; 6+ messages in thread
From: Johannes Berg @ 2012-03-02 7:49 UTC (permalink / raw)
To: Javier Cardona; +Cc: John W. Linville, devel, linux-wireless
On Thu, 2012-03-01 at 15:40 -0800, Javier Cardona wrote:
> Generate a tsf from jiffies. Prepare the path for having different tsf
> offsets on the each phy. This will be useful for testing mesh
> synchronization algorithms.
The fact that you used jiffies should have made me wonder earlier :)
> +static __le64 __mac80211_hwsim_get_tsf(struct mac80211_hwsim_data *data)
> +{
> + return cpu_to_le64(jiffies_to_msecs(jiffies)*1000/1024 +
> + data->tsf_offset);
> +}
This is not right? TSF is in microseconds, here you're like converting
msec to TU (I think). Also, jiffies doesn't even increase fast enough
for the timestamp, I'm pretty sure you need hrtimers.
johannes
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCHv2 3/3] mac80211_hwsim: Implement ieee80211_ops:tx_last_beacon
2012-03-01 23:40 ` [PATCHv2 3/3] mac80211_hwsim: Implement ieee80211_ops:tx_last_beacon Javier Cardona
@ 2012-03-02 7:50 ` Johannes Berg
[not found] ` <CAPjQAd9CfNiLjqQh_ONaF89o7qQpuZrhRnysNP_wDXrAe+tYgA@mail.gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Johannes Berg @ 2012-03-02 7:50 UTC (permalink / raw)
To: Javier Cardona; +Cc: John W. Linville, devel, linux-wireless
On Thu, 2012-03-01 at 15:40 -0800, Javier Cardona wrote:
> Without this you won't see probe responses in an IBSS/hwsim network,
> which is convenient for testing.
>
> Signed-off-by: Javier Cardona <javier@cozybit.com>
> ---
> drivers/net/wireless/mac80211_hwsim.c | 9 +++++++++
> 1 files changed, 9 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
> index deed95f..e4b6ca6 100644
> --- a/drivers/net/wireless/mac80211_hwsim.c
> +++ b/drivers/net/wireless/mac80211_hwsim.c
> @@ -47,6 +47,8 @@ static bool fake_hw_scan;
> module_param(fake_hw_scan, bool, 0444);
> MODULE_PARM_DESC(fake_hw_scan, "Install fake (no-op) hw-scan handler");
>
> +static struct ieee80211_hw *txed_last_beacon;
That's definitely not right.
> /**
> * enum hwsim_regtest - the type of regulatory tests we offer
> *
> @@ -821,6 +823,7 @@ static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac,
> hdr = (struct ieee80211_hdr_3addr *) skb->data;
> tsfpos = (__le64 *) (hdr + 1);
> put_unaligned(__mac80211_hwsim_get_tsf(data), tsfpos);
> + txed_last_beacon = hw;
>
> mac80211_hwsim_monitor_rx(hw, skb);
>
> @@ -1220,6 +1223,11 @@ static void mac80211_hwsim_sw_scan_complete(struct ieee80211_hw *hw)
> mutex_unlock(&hwsim->mutex);
> }
>
> +static int mac80211_hwsim_tx_last_beacon(struct ieee80211_hw *hw)
> +{
> + return (hw == txed_last_beacon);
> +}
And this is mostly a fancy way of saying "return 1" -- there's no beacon
backoff protocol in here, so why not just hardcode "return 1"?
johannes
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCHv2 3/3] mac80211_hwsim: Implement ieee80211_ops:tx_last_beacon
[not found] ` <1330711566.8542.23.camel@jlt3.sipsolutions.net>
@ 2012-03-02 18:16 ` Javier Cardona
0 siblings, 0 replies; 6+ messages in thread
From: Javier Cardona @ 2012-03-02 18:16 UTC (permalink / raw)
To: Johannes Berg; +Cc: devel, linux-wireless
On Fri, Mar 2, 2012 at 10:06 AM, Johannes Berg
<johannes@sipsolutions.net> wrote:
> On Fri, 2012-03-02 at 09:51 -0800, Javier Cardona wrote:
>> On Thu, Mar 1, 2012 at 11:50 PM, Johannes Berg
>> <johannes@sipsolutions.net> wrote:
>> > On Thu, 2012-03-01 at 15:40 -0800, Javier Cardona wrote:
>> >> Without this you won't see probe responses in an IBSS/hwsim network,
>> >> which is convenient for testing.
>> >>
>> >> Signed-off-by: Javier Cardona <javier@cozybit.com>
>> >> ---
>> >> drivers/net/wireless/mac80211_hwsim.c | 9 +++++++++
>> >> 1 files changed, 9 insertions(+), 0 deletions(-)
>> >>
>> >> diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
>> >> index deed95f..e4b6ca6 100644
>> >> --- a/drivers/net/wireless/mac80211_hwsim.c
>> >> +++ b/drivers/net/wireless/mac80211_hwsim.c
>> >> @@ -47,6 +47,8 @@ static bool fake_hw_scan;
>> >> module_param(fake_hw_scan, bool, 0444);
>> >> MODULE_PARM_DESC(fake_hw_scan, "Install fake (no-op) hw-scan handler");
>> >>
>> >> +static struct ieee80211_hw *txed_last_beacon;
>> >
>> > That's definitely not right.
>>
>> I am using that module global to save the last hw that transmitted a
>> beacon. The pointer is only tested for equality, never dereferenced.
>> And even if a read access happens during a non-atomic write, there are
>> no adverse consquences other than mac80211_hwsim_tx_last_beacon()
>> returning the wrong value. Would you rather see it protected with a
>> mutex?
>
> No, no, it's just the logic.
>
>> >> +static int mac80211_hwsim_tx_last_beacon(struct ieee80211_hw *hw)
>> >> +{
>> >> + return (hw == txed_last_beacon);
>> >> +}
>> >
>> > And this is mostly a fancy way of saying "return 1" -- there's no beacon
>> > backoff protocol in here, so why not just hardcode "return 1"?
>>
>> This only returns true if 'hw' is the last hw that transmitted a
>> beacon. Worked for me, as I was seeing 0's and 1's.
>
> Yeah, but it's nowhere near how IBSS works. You're doing this across
> different channels, no matter whether it's even in IBSS mode, and
> there's no backoff (all of them will TX anyway)
I thought that function was called only in IBSS mode, but still, you
are right. There are many things i did not consider.
>> My (maybe flawed) thinking was: I need this function to return true to
>> test my previous patch. Hardcoding a 1 would do it me, but someone
>> might complain that makes no sense. So I tried to simulate a behavior
>> that's closer to reality. In my IBSS/hwsim network I now see one
>> probe response at a time even though there are multiple phy's.
>
> It's so far from reality that I don't think we should do it :-)
>
>> What would you want me to do with this patch? I'm not particulary
>> attached to it...
>
> I don't really care -- do you want to return 1 or just leave this patch
> out?
Hmmm, I think I'll leave it out. If anyone is using hwsim to test
IBSS they'll probably know how to code this better.
Thanks for your help!
Javier
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-03-02 18:16 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-01 23:40 [PATCHv2 1/3] mac80211_hwsim: Add tsf to beacons, probe responses and radiotap header Javier Cardona
2012-03-01 23:40 ` [PATCHv2 2/3] mac80211: Modify tsf via debugfs in mesh interfaces Javier Cardona
2012-03-01 23:40 ` [PATCHv2 3/3] mac80211_hwsim: Implement ieee80211_ops:tx_last_beacon Javier Cardona
2012-03-02 7:50 ` Johannes Berg
[not found] ` <CAPjQAd9CfNiLjqQh_ONaF89o7qQpuZrhRnysNP_wDXrAe+tYgA@mail.gmail.com>
[not found] ` <1330711566.8542.23.camel@jlt3.sipsolutions.net>
2012-03-02 18:16 ` Javier Cardona
2012-03-02 7:49 ` [PATCHv2 1/3] mac80211_hwsim: Add tsf to beacons, probe responses and radiotap header Johannes Berg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).