From: Bruno Randolf <bruno@thinktube.com>
To: ath5k-devel@lists.ath5k.org
Cc: mcgrof@gmail.com, jirislaby@gmail.com, mickflemm@gmail.com,
linux-wireless@vger.kernel.org, linville@tuxdriver.com,
johannes@sipsolutions.net, flamingice@sourmilk.net,
jbenc@suse.cz
Subject: [PATCH] mac80211: enable IBSS merging
Date: Sat, 16 Feb 2008 11:29:19 +0900 [thread overview]
Message-ID: <20080216022918.18775.59888.stgit@one> (raw)
In-Reply-To: <1203088151.8931.197.camel@johannes.berg>
enable IBSS cell merging. if an IBSS beacon with the same channel, same=
ESSID
and a TSF higher than the local TSF (mactime) is received, we have to j=
oin its
BSSID. while this might not be immediately apparent from reading the 80=
2.11
standard it is compliant and necessary to make IBSS mode functional in =
many
cases. most drivers have a similar behaviour.
* move the relevant code section (previously only containing debug code=
) down
to the end of the function, so we can reuse the bss structure.
* we have to compare the mactime (TSF at the time of packet receive) ra=
ther
than the current TSF. since mactime is defined as the time the first da=
ta
symbol arrived we add the time until byte 24 where the timestamp reside=
s, since
this is how the beacon timestamp is defined. as some some drivers are n=
ot able
to give a reliable mactime we fall back to use the current TSF, which w=
ill be
enough to catch most (but not all) cases where an IBSS merge is necessa=
ry.
* in IBSS mode we want to allow beacons to override probe response info=
so we
can correctly do merges.
* we don't only configure beacons based on scan results, so change that
message.
* to enable this we have to let all beacons thru in IBSS mode, even if =
they
have a different BSSID.
Signed-off-by: Bruno Randolf <bruno@thinktube.com>
---
include/net/mac80211.h | 3 +
net/mac80211/ieee80211_sta.c | 90 ++++++++++++++++++++++++++++------=
--------
net/mac80211/rx.c | 5 ++
3 files changed, 67 insertions(+), 31 deletions(-)
diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index 1b807f4..c634607 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -276,7 +276,8 @@ struct ieee80211_tx_control {
* @RX_FLAG_FAILED_PLCP_CRC: Set this flag if the PCLP check failed on
* the frame.
* @RX_FLAG_TSFT: The timestamp passed in the RX status (@mactime fiel=
d)
- * is valid.
+ * is valid. This is useful in monitor mode and necessary for beacon f=
rames
+ * to enable IBSS merging.
*/
enum mac80211_rx_flags {
RX_FLAG_MMIC_ERROR =3D 1<<0,
diff --git a/net/mac80211/ieee80211_sta.c b/net/mac80211/ieee80211_sta.=
c
index 72d7a86..fb96b51 100644
--- a/net/mac80211/ieee80211_sta.c
+++ b/net/mac80211/ieee80211_sta.c
@@ -2202,7 +2202,7 @@ static void ieee80211_rx_bss_info(struct net_devi=
ce *dev,
struct ieee80211_sta_bss *bss;
struct sta_info *sta;
struct ieee80211_sub_if_data *sdata =3D IEEE80211_DEV_TO_SUB_IF(dev);
- u64 timestamp;
+ u64 beacon_timestamp, rx_timestamp;
DECLARE_MAC_BUF(mac);
DECLARE_MAC_BUF(mac2);
=20
@@ -2219,31 +2219,7 @@ static void ieee80211_rx_bss_info(struct net_dev=
ice *dev,
if (baselen > len)
return;
=20
- timestamp =3D le64_to_cpu(mgmt->u.beacon.timestamp);
-
- if (sdata->vif.type =3D=3D IEEE80211_IF_TYPE_IBSS && beacon &&
- memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) =3D=3D 0) {
-#ifdef CONFIG_MAC80211_IBSS_DEBUG
- static unsigned long last_tsf_debug =3D 0;
- u64 tsf;
- if (local->ops->get_tsf)
- tsf =3D local->ops->get_tsf(local_to_hw(local));
- else
- tsf =3D -1LLU;
- if (time_after(jiffies, last_tsf_debug + 5 * HZ)) {
- printk(KERN_DEBUG "RX beacon SA=3D%s BSSID=3D"
- "%s TSF=3D0x%llx BCN=3D0x%llx diff=3D%lld "
- "@%lu\n",
- print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->bssid),
- (unsigned long long)tsf,
- (unsigned long long)timestamp,
- (unsigned long long)(tsf - timestamp),
- jiffies);
- last_tsf_debug =3D jiffies;
- }
-#endif /* CONFIG_MAC80211_IBSS_DEBUG */
- }
-
+ beacon_timestamp =3D le64_to_cpu(mgmt->u.beacon.timestamp);
ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems=
);
=20
if (sdata->vif.type =3D=3D IEEE80211_IF_TYPE_IBSS && elems.supp_rates=
&&
@@ -2329,8 +2305,10 @@ static void ieee80211_rx_bss_info(struct net_dev=
ice *dev,
=20
bss->band =3D rx_status->band;
=20
- if (bss->probe_resp && beacon) {
- /* Do not allow beacon to override data from Probe Response. */
+ if (sdata->vif.type !=3D IEEE80211_IF_TYPE_IBSS &&
+ bss->probe_resp && beacon) {
+ /* STA mode:
+ * Do not allow beacon to override data from Probe Response. */
ieee80211_rx_bss_put(dev, bss);
return;
}
@@ -2427,13 +2405,67 @@ static void ieee80211_rx_bss_info(struct net_de=
vice *dev,
bss->ht_ie_len =3D 0;
}
=20
- bss->timestamp =3D timestamp;
+ bss->timestamp =3D beacon_timestamp;
bss->last_update =3D jiffies;
bss->rssi =3D rx_status->ssi;
bss->signal =3D rx_status->signal;
bss->noise =3D rx_status->noise;
if (!beacon)
bss->probe_resp++;
+
+ /* check if we need to merge IBSS */
+ if (sdata->vif.type =3D=3D IEEE80211_IF_TYPE_IBSS && beacon &&
+ !local->sta_sw_scanning && !local->sta_hw_scanning &&
+ mgmt->u.beacon.capab_info & WLAN_CAPABILITY_IBSS &&
+ bss->freq =3D=3D local->oper_channel->center_freq &&
+ elems.ssid_len =3D=3D sdata->u.sta.ssid_len &&
+ memcmp(elems.ssid, sdata->u.sta.ssid, sdata->u.sta.ssid_len) =3D=3D=
0) {
+ if (rx_status->flag & RX_FLAG_TSFT) {
+ /* in order for correct IBSS merging we need mactime
+ *
+ * since mactime is defined as the time the first data
+ * symbol of the frame hits the PHY, and the timestamp
+ * of the beacon is defined as "the time that the data
+ * symbol containing the first bit of the timestamp is
+ * transmitted to the PHY plus the transmitting STA=E2=80=99s
+ * delays through its local PHY from the MAC-PHY
+ * interface to its interface with the WM"
+ * (802.11 11.1.2) - equals the time this bit arrives at
+ * the receiver - we have to take into account the
+ * offset between the two.
+ * e.g: at 1 MBit that means mactime is 192 usec earlier
+ * (=3D24 bytes * 8 usecs/byte) than the beacon timestamp.
+ */
+ int rate =3D local->hw.wiphy->bands[rx_status->band]->
+ bitrates[rx_status->rate_idx].bitrate;
+ rx_timestamp =3D rx_status->mactime + (24 * 8 * 10 / rate);
+ } else if (local && local->ops && local->ops->get_tsf)
+ /* second best option: get current TSF */
+ rx_timestamp =3D local->ops->get_tsf(local_to_hw(local));
+ else
+ /* can't merge without knowing the TSF */
+ rx_timestamp =3D -1LLU;
+#ifdef CONFIG_MAC80211_IBSS_DEBUG
+ printk(KERN_DEBUG "RX beacon SA=3D%s BSSID=3D"
+ "%s TSF=3D0x%llx BCN=3D0x%llx diff=3D%lld @%lu\n",
+ print_mac(mac, mgmt->sa),
+ print_mac(mac2, mgmt->bssid),
+ (unsigned long long)rx_timestamp,
+ (unsigned long long)beacon_timestamp,
+ (unsigned long long)(rx_timestamp - beacon_timestamp),
+ jiffies);
+#endif /* CONFIG_MAC80211_IBSS_DEBUG */
+ if (beacon_timestamp > rx_timestamp) {
+ if (CONFIG_MAC80211_IBSS_DEBUG || net_ratelimit())
+ printk(KERN_DEBUG "%s: beacon TSF higher than "
+ "local TSF - IBSS merge with BSSID %s\n",
+ dev->name, print_mac(mac, mgmt->bssid));
+ ieee80211_sta_join_ibss(dev, &sdata->u.sta, bss);
+ ieee80211_ibss_add_sta(dev, NULL,
+ mgmt->bssid, mgmt->sa);
+ }
+ }
+
ieee80211_rx_bss_put(dev, bss);
}
=20
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 943ba90..5dfe6f2 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -1694,7 +1694,10 @@ static int prepare_for_handlers(struct ieee80211=
_sub_if_data *sdata,
case IEEE80211_IF_TYPE_IBSS:
if (!bssid)
return 0;
- if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
+ if ((rx->fc & IEEE80211_FCTL_FTYPE) =3D=3D IEEE80211_FTYPE_MGMT &&
+ (rx->fc & IEEE80211_FCTL_STYPE) =3D=3D IEEE80211_STYPE_BEACON)
+ return 1;
+ else if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
return 0;
rx->flags &=3D ~IEEE80211_TXRXD_RXRA_MATCH;
-
To unsubscribe from this list: send the line "unsubscribe linux-wireles=
s" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2008-02-16 2:29 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-15 7:01 [PATCH 1/3] mac80211: better definition of mactime Bruno Randolf
2008-02-15 7:01 ` [PATCH 2/3] mac80211: move function ieee80211_sta_join_ibss() Bruno Randolf
2008-02-15 12:52 ` Johannes Berg
2008-02-15 7:02 ` [PATCH 3/3] mac80211: enable IBSS merging Bruno Randolf
2008-02-15 15:09 ` Johannes Berg
2008-02-16 2:29 ` Bruno Randolf [this message]
2008-02-17 9:11 ` [PATCH] " Johannes Berg
2008-02-18 1:42 ` bruno randolf
2008-02-18 11:15 ` Johannes Berg
2008-02-18 2:03 ` bruno randolf
2008-02-18 11:16 ` Johannes Berg
2008-02-15 12:52 ` [PATCH 1/3] mac80211: better definition of mactime Johannes Berg
-- strict thread matches above, loose matches on Subject: below --
2008-02-08 9:41 [PATCH] mac80211: enable IBSS merging Joerg Pommnitz
2008-02-05 11:08 [PATCH 2/2] " Johannes Berg
2008-02-06 2:49 ` [PATCH] " Bruno Randolf
2008-02-06 23:52 ` Johannes Berg
2008-02-08 9:25 ` Luis R. Rodriguez
2008-02-12 3:25 ` bruno randolf
2008-02-12 9:50 ` Johannes Berg
2008-02-14 6:19 ` bruno randolf
2008-02-14 14:12 ` Johannes Berg
2008-02-12 9:52 ` Johannes Berg
2008-02-14 10:19 ` bruno randolf
2008-01-18 12:52 Bruno Randolf
2008-01-20 10:17 ` Luis R. Rodriguez
2008-01-20 10:43 ` Ivo van Doorn
2008-01-21 1:52 ` bruno randolf
2008-01-21 16:05 ` Ivo van Doorn
2008-01-22 19:47 ` Luis R. Rodriguez
2008-01-22 19:54 ` Ivo van Doorn
2008-01-22 20:32 ` Luis R. Rodriguez
2008-01-22 20:51 ` Ivo van Doorn
2008-01-22 23:16 ` Adam Baker
2008-01-22 23:25 ` Ivo van Doorn
2008-01-23 14:49 ` Johannes Berg
2008-01-24 5:51 ` bruno randolf
2008-01-21 1:57 ` bruno randolf
2008-01-23 14:48 ` Johannes Berg
2008-01-23 17:22 ` Dan Williams
2008-01-24 3:49 ` bruno randolf
2008-01-24 3:26 ` bruno randolf
2008-01-24 16:55 ` Johannes Berg
2008-01-25 8:01 ` bruno randolf
2008-02-02 23:22 ` Luis R. Rodriguez
2008-02-05 1:50 ` bruno randolf
2008-02-05 1:56 ` Luis R. Rodriguez
2008-02-06 10:01 ` Johannes Berg
2008-02-06 4:34 ` Jouni Malinen
2008-02-06 18:33 ` Luis R. Rodriguez
2008-02-06 20:10 ` John W. Linville
2008-02-07 3:58 ` Jouni Malinen
2008-02-08 9:22 ` Luis R. Rodriguez
2008-02-12 2:00 ` bruno randolf
2008-02-15 1:06 ` Luis R. Rodriguez
2008-02-15 1:40 ` bruno randolf
2008-02-07 3:52 ` Jouni Malinen
2008-02-08 9:10 ` Luis R. Rodriguez
2008-01-24 5:43 ` bruno randolf
2008-01-24 8:51 ` Kalle Valo
2008-01-24 14:27 ` Johannes Berg
2008-01-24 14:30 ` Johannes Berg
2008-01-25 6:16 ` bruno randolf
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=20080216022918.18775.59888.stgit@one \
--to=bruno@thinktube.com \
--cc=ath5k-devel@lists.ath5k.org \
--cc=flamingice@sourmilk.net \
--cc=jbenc@suse.cz \
--cc=jirislaby@gmail.com \
--cc=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
--cc=linville@tuxdriver.com \
--cc=mcgrof@gmail.com \
--cc=mickflemm@gmail.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 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).