All of lore.kernel.org
 help / color / mirror / Atom feed
From: Javier Cardona <javier@cozybit.com>
To: "John W. Linville" <linville@tuxdriver.com>
Cc: Javier Cardona <javier@cozybit.com>,
	devel@lists.open80211s.org,
	Johannes Berg <johannes@sipsolutions.net>,
	linux-wireless@vger.kernel.org
Subject: [PATCHv3 1/2] mac80211_hwsim:  Add tsf to beacons, probe responses and radiotap header.
Date: Fri,  2 Mar 2012 13:04:39 -0800	[thread overview]
Message-ID: <1330722280-28879-1-git-send-email-javier@cozybit.com> (raw)

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)
v3: Drop poorly implemented tx_last_beacon patch
    TSF in microsecs, not TUs!    (Johannes)
    Use high-resolution timer, not jiffies (Johannes)

 drivers/net/wireless/mac80211_hwsim.c |   39 +++++++++++++++++++++++++++++---
 1 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index ba16f05..597f804 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -321,11 +321,15 @@ struct mac80211_hwsim_data {
 	struct dentry *debugfs_group;
 
 	int power_level;
+
+	/* difference between this hw's clock and the real clock, in usecs */
+	u64 tsf_offset;
 };
 
 
 struct hwsim_radiotap_hdr {
 	struct ieee80211_radiotap_header hdr;
+	u64 rt_tsft;
 	u8 rt_flags;
 	u8 rt_rate;
 	__le16 rt_channel;
@@ -367,6 +371,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 +400,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 +621,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 +679,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 +710,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 +786,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 +805,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


             reply	other threads:[~2012-03-02 21:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-02 21:04 Javier Cardona [this message]
2012-03-02 21:04 ` [PATCHv3 2/2] mac80211: Modify tsf via debugfs in mesh interfaces Javier Cardona
2012-03-02 21:11   ` Johannes Berg
2012-03-02 21:17     ` Javier Cardona
2012-03-02 21:10 ` [PATCHv3 1/2] mac80211_hwsim: Add tsf to beacons, probe responses and radiotap header Johannes Berg
2012-03-02 21:39 ` Johannes Berg
2012-03-02 21:43 ` Johannes Berg
2012-03-02 21:46   ` Javier Cardona

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1330722280-28879-1-git-send-email-javier@cozybit.com \
    --to=javier@cozybit.com \
    --cc=devel@lists.open80211s.org \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.