PERFORCE change 133282 for review
Sepherosa Ziehau
sephe at FreeBSD.org
Mon Jan 14 15:16:56 PST 2008
http://perforce.freebsd.org/chv.cgi?CH=133282
Change 133282 by sephe at sephe_zealot:sam_wifi on 2008/01/14 23:16:28
- Expose ieee80211_{ack_duration,compute_duration,rate2phytype}(),
add more assertion in ieee80211_{ack_duration,rate2phytype}()
- Use these functions in rt2661 part of ral(4)
- Adjust indentation style in ieee80211_phy.h according to the rest
of header files in sys/net80211
Affected files ...
.. //depot/projects/wifi/sys/dev/ral/rt2661.c#22 edit
.. //depot/projects/wifi/sys/net80211/ieee80211_phy.c#5 edit
.. //depot/projects/wifi/sys/net80211/ieee80211_phy.h#2 edit
Differences ...
==== //depot/projects/wifi/sys/dev/ral/rt2661.c#22 (text) ====
@@ -55,6 +55,7 @@
#include <net80211/ieee80211_var.h>
#include <net80211/ieee80211_radiotap.h>
#include <net80211/ieee80211_regdomain.h>
+#include <net80211/ieee80211_phy.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@@ -106,11 +107,9 @@
static void rt2661_mcu_beacon_expire(struct rt2661_softc *);
static void rt2661_mcu_wakeup(struct rt2661_softc *);
static void rt2661_mcu_cmd_intr(struct rt2661_softc *);
-static int rt2661_ack_rate(struct ieee80211com *, int);
static void rt2661_scan_start(struct ieee80211com *);
static void rt2661_scan_end(struct ieee80211com *);
static void rt2661_set_channel(struct ieee80211com *);
-static uint16_t rt2661_txtime(int, int, uint32_t);
static uint8_t rt2661_rxrate(struct rt2661_rx_desc *);
static uint8_t rt2661_plcp_signal(int);
static void rt2661_setup_tx_desc(struct rt2661_softc *,
@@ -1266,14 +1265,6 @@
RAL_UNLOCK(sc);
}
-/* quickly determine if a given rate is CCK or OFDM */
-#define RAL_RATE_IS_OFDM(rate) ((rate) >= 12 && (rate) != 22)
-
-#define RAL_ACK_SIZE 14 /* 10 + 4(FCS) */
-#define RAL_CTS_SIZE 14 /* 10 + 4(FCS) */
-
-#define RAL_SIFS 10 /* us */
-
/*
* This function is only used by the Rx radiotap code. It returns the rate at
* which a given frame was received.
@@ -1306,66 +1297,6 @@
return 2; /* should not get there */
}
-/*
- * Return the expected ack rate for a frame transmitted at rate `rate'.
- * XXX: this should depend on the destination node basic rate set.
- */
-static int
-rt2661_ack_rate(struct ieee80211com *ic, int rate)
-{
- switch (rate) {
- /* CCK rates */
- case 2:
- return 2;
- case 4:
- case 11:
- case 22:
- return (ic->ic_curmode == IEEE80211_MODE_11B) ? 4 : rate;
-
- /* OFDM rates */
- case 12:
- case 18:
- return 12;
- case 24:
- case 36:
- return 24;
- case 48:
- case 72:
- case 96:
- case 108:
- return 48;
- }
-
- /* default to 1Mbps */
- return 2;
-}
-
-/*
- * Compute the duration (in us) needed to transmit `len' bytes at rate `rate'.
- * The function automatically determines the operating mode depending on the
- * given rate. `flags' indicates whether short preamble is in use or not.
- */
-static uint16_t
-rt2661_txtime(int len, int rate, uint32_t flags)
-{
- uint16_t txtime;
-
- if (RAL_RATE_IS_OFDM(rate)) {
- /* IEEE Std 802.11a-1999, pp. 37 */
- txtime = (8 + 4 * len + 3 + rate - 1) / rate;
- txtime = 16 + 4 + 4 * txtime + 6;
- } else {
- /* IEEE Std 802.11b-1999, pp. 28 */
- txtime = (16 * len + rate - 1) / rate;
- if (rate != 2 && (flags & IEEE80211_F_SHPREAMBLE))
- txtime += 72 + 24;
- else
- txtime += 144 + 48;
- }
-
- return txtime;
-}
-
static uint8_t
rt2661_plcp_signal(int rate)
{
@@ -1425,7 +1356,8 @@
desc->plcp_service = 4;
len += IEEE80211_CRC_LEN;
- if (RAL_RATE_IS_OFDM(rate)) {
+ if (ieee80211_rate2phytype(ic->ic_curchan->ic_rt, rate) ==
+ IEEE80211_T_OFDM) {
desc->flags |= htole32(RT2661_TX_OFDM);
plcp_length = len & 0xfff;
@@ -1511,8 +1443,8 @@
if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
flags |= RT2661_TX_NEED_ACK;
- dur = rt2661_txtime(RAL_ACK_SIZE, rate, ic->ic_flags) +
- RAL_SIFS;
+ dur = ieee80211_ack_duration(ic->ic_curchan->ic_rt,
+ rate, ic->ic_flags);
*(uint16_t *)wh->i_dur = htole16(dur);
/* tell hardware to add timestamp in probe responses */
@@ -1632,16 +1564,17 @@
m0->m_pkthdr.len > ic->ic_rtsthreshold) {
struct mbuf *m;
uint16_t dur;
- int rtsrate, ackrate;
+ int rtsrate;
rtsrate = IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan) ? 12 : 2;
- ackrate = rt2661_ack_rate(ic, rate);
- dur = rt2661_txtime(m0->m_pkthdr.len + 4, rate, ic->ic_flags) +
- rt2661_txtime(RAL_CTS_SIZE, rtsrate, ic->ic_flags) +
- /* XXX: noack (QoS)? */
- rt2661_txtime(RAL_ACK_SIZE, ackrate, ic->ic_flags) +
- 3 * RAL_SIFS;
+ dur = ieee80211_ack_duration(ic->ic_curchan->ic_rt,
+ rtsrate, ic->ic_flags)
+ + ieee80211_compute_duration(ic->ic_curchan->ic_rt,
+ m0->m_pkthdr.len + IEEE80211_CRC_LEN, rate,
+ ic->ic_flags)
+ + ieee80211_ack_duration(ic->ic_curchan->ic_rt,
+ rate, ic->ic_flags);
m = rt2661_get_rts(sc, wh, dur);
@@ -1744,8 +1677,8 @@
if (!noack && !IEEE80211_IS_MULTICAST(wh->i_addr1)) {
flags |= RT2661_TX_NEED_ACK;
- dur = rt2661_txtime(RAL_ACK_SIZE, rt2661_ack_rate(ic, rate),
- ic->ic_flags) + RAL_SIFS;
+ dur = ieee80211_ack_duration(ic->ic_curchan->ic_rt, rate,
+ ic->ic_flags);
*(uint16_t *)wh->i_dur = htole16(dur);
}
==== //depot/projects/wifi/sys/net80211/ieee80211_phy.c#5 (text+ko) ====
@@ -98,8 +98,6 @@
#ifdef notyet
uint8_t ieee80211_plcp2rate(uint8_t, int);
-enum ieee80211_phytype ieee80211_rate2phytype(
- const struct ieee80211_rate_table *, uint8_t rate);
uint8_t ieee80211_ack_rate(const struct ieee80211_rate_table *,
uint8_t rate);
#endif /* notyet */
@@ -236,8 +234,6 @@
#undef XR
static void ieee80211_setup_ratetable(struct ieee80211_rate_table *);
-static uint16_t ieee80211_compute_duration(const struct ieee80211_rate_table *,
- uint32_t frameLen, uint16_t rate, int flags);
/* Setup all rate tables */
void
@@ -394,12 +390,6 @@
return 0;
}
-enum ieee80211_phytype
-ieee80211_rate2phytype(const struct ieee80211_rate_table *rt, uint8_t rate)
-{
- return rt->info[rt->rateCodeToIndex[rate]].phy;
-}
-
uint8_t
ieee80211_ack_rate(const struct ieee80211_rate_table *rt, uint8_t rate)
{
@@ -409,12 +399,45 @@
#endif /* notyet */
+enum ieee80211_phytype
+ieee80211_rate2phytype(const struct ieee80211_rate_table *rt, uint8_t rate)
+{
+ uint8_t rix = rt->rateCodeToIndex[rate];
+
+ KASSERT(rix != (uint8_t)-1, ("rate %d has no info", rate));
+ return rt->info[rix].phy;
+}
+
/*
+ * Calculate duration field for
+ * o non-fragment data frames
+ * o management frames
+ * sent using rate, phy and short preamble setting.
+ */
+uint16_t
+ieee80211_ack_duration(const struct ieee80211_rate_table *rt,
+ uint8_t rate, int flags)
+{
+ uint8_t rix = rt->rateCodeToIndex[rate];
+
+ KASSERT(rix != (uint8_t)-1, ("rate %d has no info", rate));
+ if (flags & IEEE80211_F_SHPREAMBLE) {
+ KASSERT(rt->info[rix].spAckDuration != 0,
+ ("shpreamble ack dur is not computed!\n"));
+ return rt->info[rix].spAckDuration;
+ } else {
+ KASSERT(rt->info[rix].lpAckDuration != 0,
+ ("lgpreamble ack dur is not computed!\n"));
+ return rt->info[rix].lpAckDuration;
+ }
+}
+
+/*
* Compute the time to transmit a frame of length frameLen bytes
* using the specified rate, phy, and short preamble setting.
* SIFS is included.
*/
-static uint16_t
+uint16_t
ieee80211_compute_duration(const struct ieee80211_rate_table *rt,
uint32_t frameLen, uint16_t rate, int flags)
{
==== //depot/projects/wifi/sys/net80211/ieee80211_phy.h#2 (text+ko) ====
@@ -33,9 +33,17 @@
struct ieee80211_rate_table;
struct ieee80211_channel;
+/* Initialization functions */
void ieee80211_phy_init(void);
-const struct ieee80211_rate_table *
- ieee80211_get_ratetable(struct ieee80211_channel *);
+const struct ieee80211_rate_table *ieee80211_get_ratetable(
+ struct ieee80211_channel *);
+
+uint16_t ieee80211_ack_duration(const struct ieee80211_rate_table *,
+ uint8_t, int);
+uint16_t ieee80211_compute_duration(const struct ieee80211_rate_table *,
+ uint32_t, uint16_t, int);
+enum ieee80211_phytype ieee80211_rate2phytype(
+ const struct ieee80211_rate_table *, uint8_t);
#endif /* _KERNEL */
More information about the p4-projects
mailing list