2012-03-01 00:29:48

by Javier Cardona

[permalink] [raw]
Subject: [PATCH 1/2] mac80211_hwsim: Add tsf to beacons and radiotap header.

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 <[email protected]>
---
drivers/net/wireless/mac80211_hwsim.c | 20 +++++++++++++++++++-
1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index ba16f05..b926a89 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;
@@ -763,9 +773,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 +792,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



2012-03-01 00:29:51

by Javier Cardona

[permalink] [raw]
Subject: [PATCH 2/2] mac80211: Modify tsf via debugfs in mesh interfaces

Signed-off-by: Javier Cardona <[email protected]>
---
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 b926a89..72a209f 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)
{
@@ -1217,6 +1231,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


2012-03-01 07:39:07

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 1/2] mac80211_hwsim: Add tsf to beacons and radiotap header.

On Wed, 2012-02-29 at 16:29 -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.

I think you should also add it to probe responses.

johannes