diff --git a/sys/net80211/ieee80211.c b/sys/net80211/ieee80211.c --- a/sys/net80211/ieee80211.c +++ b/sys/net80211/ieee80211.c @@ -2306,7 +2306,7 @@ * In station mode report the current transmit rate. */ imr->ifm_active |= ieee80211_rate2media(ic, - vap->iv_bss->ni_txrate, mode); + ieee80211_node_get_txrate_dot11rate(vap->iv_bss), mode); } else imr->ifm_active |= IFM_AUTO; if (imr->ifm_status & IFM_ACTIVE) diff --git a/sys/net80211/ieee80211_adhoc.c b/sys/net80211/ieee80211_adhoc.c --- a/sys/net80211/ieee80211_adhoc.c +++ b/sys/net80211/ieee80211_adhoc.c @@ -235,10 +235,9 @@ ether_sprintf(ni->ni_bssid)); ieee80211_print_essid(vap->iv_bss->ni_essid, ni->ni_esslen); - /* XXX MCS/HT */ printf(" channel %d start %uMb\n", ieee80211_chan2ieee(ic, ic->ic_curchan), - IEEE80211_RATE2MBS(ni->ni_txrate)); + ieee80211_node_get_txrate_mbit(ni) / 2); } #endif break; diff --git a/sys/net80211/ieee80211_amrr.c b/sys/net80211/ieee80211_amrr.c --- a/sys/net80211/ieee80211_amrr.c +++ b/sys/net80211/ieee80211_amrr.c @@ -207,7 +207,7 @@ rate |= IEEE80211_RATE_MCS; /* Assign initial rate from the rateset */ - ni->ni_txrate = rate; + ieee80211_node_set_txrate_dot11rate(ni, rate); amn->amn_ticks = ticks; /* XXX TODO: we really need a rate-to-string method */ @@ -321,7 +321,8 @@ /* XXX should return -1 here, but drivers may not expect this... */ if (!amn) { - ni->ni_txrate = ni->ni_rates.rs_rates[0]; + ieee80211_node_set_txrate_dot11rate(ni, + ni->ni_rates.rs_rates[0]); return 0; } @@ -338,13 +339,16 @@ if (is_enough(amn) && (ticks - amn->amn_ticks) > amrr->amrr_interval) { rix = amrr_update(amrr, amn, ni); if (rix != amn->amn_rix) { + uint8_t dot11Rate; /* update public rate */ - ni->ni_txrate = rs->rs_rates[rix]; + dot11Rate = rs->rs_rates[rix]; /* XXX strip basic rate flag from txrate, if non-11n */ if (ieee80211_ht_check_tx_ht(ni)) - ni->ni_txrate |= IEEE80211_RATE_MCS; + dot11Rate |= IEEE80211_RATE_MCS; else - ni->ni_txrate &= IEEE80211_RATE_VAL; + dot11Rate &= IEEE80211_RATE_VAL; + ieee80211_node_set_txrate_dot11rate(ni, dot11Rate); + amn->amn_rix = rix; } amn->amn_ticks = ticks; diff --git a/sys/net80211/ieee80211_hostap.c b/sys/net80211/ieee80211_hostap.c --- a/sys/net80211/ieee80211_hostap.c +++ b/sys/net80211/ieee80211_hostap.c @@ -63,8 +63,6 @@ #include #include /* for parse_wmeie */ -#define IEEE80211_RATE2MBS(r) (((r) & IEEE80211_RATE_VAL) / 2) - static void hostap_vattach(struct ieee80211vap *); static int hostap_newstate(struct ieee80211vap *, enum ieee80211_state, int); static int hostap_input(struct ieee80211_node *ni, struct mbuf *m, @@ -314,7 +312,7 @@ /* XXX MCS/HT */ printf(" channel %d start %uMb\n", ieee80211_chan2ieee(ic, ic->ic_curchan), - IEEE80211_RATE2MBS(ni->ni_txrate)); + ieee80211_node_get_txrate_mbit(ni) / 2); } #endif break; diff --git a/sys/net80211/ieee80211_ioctl.c b/sys/net80211/ieee80211_ioctl.c --- a/sys/net80211/ieee80211_ioctl.c +++ b/sys/net80211/ieee80211_ioctl.c @@ -406,23 +406,8 @@ if (si->isi_nrates > 15) si->isi_nrates = 15; memcpy(si->isi_rates, ni->ni_rates.rs_rates, si->isi_nrates); - si->isi_txrate = ni->ni_txrate; - if (si->isi_txrate & IEEE80211_RATE_MCS) { - const struct ieee80211_mcs_rates *mcs = - &ieee80211_htrates[ni->ni_txrate &~ IEEE80211_RATE_MCS]; - if (IEEE80211_IS_CHAN_HT40(ni->ni_chan)) { - if (ni->ni_flags & IEEE80211_NODE_SGI40) - si->isi_txmbps = mcs->ht40_rate_800ns; - else - si->isi_txmbps = mcs->ht40_rate_400ns; - } else { - if (ni->ni_flags & IEEE80211_NODE_SGI20) - si->isi_txmbps = mcs->ht20_rate_800ns; - else - si->isi_txmbps = mcs->ht20_rate_400ns; - } - } else - si->isi_txmbps = si->isi_txrate; + si->isi_txrate = ieee80211_node_get_txrate_dot11rate(ni); + si->isi_txmbps = ieee80211_node_get_txrate_mbit(ni); si->isi_associd = ni->ni_associd; si->isi_txpower = ni->ni_txpower; si->isi_vlan = ni->ni_vlan; diff --git a/sys/net80211/ieee80211_mesh.c b/sys/net80211/ieee80211_mesh.c --- a/sys/net80211/ieee80211_mesh.c +++ b/sys/net80211/ieee80211_mesh.c @@ -3298,7 +3298,7 @@ uint64_t res; /* Time to transmit a frame */ - rate = ni->ni_txrate; + rate = ieee80211_node_get_txrate_dot11rate(ni); overhead = ieee80211_compute_duration(ic->ic_rt, ifp->if_mtu + IEEE80211_MESH_MAXOVERHEAD, rate, 0) << M_BITS; /* Error rate in percentage */ diff --git a/sys/net80211/ieee80211_node.h b/sys/net80211/ieee80211_node.h --- a/sys/net80211/ieee80211_node.h +++ b/sys/net80211/ieee80211_node.h @@ -498,4 +498,10 @@ void ieee80211_node_leave(struct ieee80211_node *); int8_t ieee80211_getrssi(struct ieee80211vap *); void ieee80211_getsignal(struct ieee80211vap *, int8_t *, int8_t *); + +uint8_t ieee80211_node_get_txrate_dot11rate(struct ieee80211_node *); +void ieee80211_node_set_txrate_dot11rate(struct ieee80211_node *, uint8_t); +void ieee80211_node_set_txrate_ht_mcsrate(struct ieee80211_node *, uint8_t); +uint16_t ieee80211_node_get_txrate_mbit(struct ieee80211_node *); + #endif /* _NET80211_IEEE80211_NODE_H_ */ diff --git a/sys/net80211/ieee80211_node.c b/sys/net80211/ieee80211_node.c --- a/sys/net80211/ieee80211_node.c +++ b/sys/net80211/ieee80211_node.c @@ -3137,3 +3137,57 @@ if (vap->iv_opmode != IEEE80211_M_STA) *rssi = ieee80211_getrssi(vap); } + +uint8_t +ieee80211_node_get_txrate_dot11rate(struct ieee80211_node *ni) +{ + + return (ni->ni_txrate); +} + +void +ieee80211_node_set_txrate_dot11rate(struct ieee80211_node *ni, + uint8_t dot11Rate) +{ + + ni->ni_txrate = dot11Rate; +} + +void +ieee80211_node_set_txrate_ht_mcsrate(struct ieee80211_node *ni, + uint8_t mcs) +{ + + ni->ni_txrate = IEEE80211_RATE_MCS | mcs; +} + + +/* + * Fetch the rate in the net80211 units of 1/2 mbit/sec. + * + * This currently only works for CCK, OFDM and HT rates. + */ +uint16_t +ieee80211_node_get_txrate_mbit(struct ieee80211_node *ni) +{ + uint16_t mbps; + + if (ni->ni_txrate & IEEE80211_RATE_MCS) { + const struct ieee80211_mcs_rates *mcs = + &ieee80211_htrates[ni->ni_txrate &~ IEEE80211_RATE_MCS]; + if (IEEE80211_IS_CHAN_HT40(ni->ni_chan)) { + if (ni->ni_flags & IEEE80211_NODE_SGI40) + mbps = mcs->ht40_rate_800ns; + else + mbps = mcs->ht40_rate_400ns; + } else { + if (ni->ni_flags & IEEE80211_NODE_SGI20) + mbps = mcs->ht20_rate_800ns; + else + mbps = mcs->ht20_rate_400ns; + } + } else + mbps = ni->ni_txrate; + + return (mbps); +} diff --git a/sys/net80211/ieee80211_ratectl_none.c b/sys/net80211/ieee80211_ratectl_none.c --- a/sys/net80211/ieee80211_ratectl_none.c +++ b/sys/net80211/ieee80211_ratectl_none.c @@ -62,7 +62,8 @@ static void none_node_init(struct ieee80211_node *ni) { - ni->ni_txrate = ni->ni_rates.rs_rates[0] & IEEE80211_RATE_VAL; + ieee80211_node_set_txrate_dot11rate(ni, + ni->ni_rates.rs_rates[0] & IEEE80211_RATE_VAL); } static void @@ -75,7 +76,8 @@ { int rix = 0; - ni->ni_txrate = ni->ni_rates.rs_rates[rix] & IEEE80211_RATE_VAL; + ieee80211_node_set_txrate_dot11rate(ni, + ni->ni_rates.rs_rates[rix] & IEEE80211_RATE_VAL); return rix; } diff --git a/sys/net80211/ieee80211_rssadapt.c b/sys/net80211/ieee80211_rssadapt.c --- a/sys/net80211/ieee80211_rssadapt.c +++ b/sys/net80211/ieee80211_rssadapt.c @@ -203,11 +203,13 @@ ra->ra_rix > 0 && (rs->rs_rates[ra->ra_rix] & IEEE80211_RATE_VAL) > 72; ra->ra_rix--) ; - ni->ni_txrate = rs->rs_rates[ra->ra_rix] & IEEE80211_RATE_VAL; + ieee80211_node_set_txrate_dot11rate(ni, + rs->rs_rates[ra->ra_rix] & IEEE80211_RATE_VAL); ra->ra_ticks = ticks; IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, - "RSSADAPT initial rate %d", ni->ni_txrate); + "RSSADAPT initial rate %d Mb", + ieee80211_node_get_txrate_mbit(ni) / 2); } static void @@ -244,7 +246,8 @@ /* XXX should return -1 here, but drivers may not expect this... */ if (!ra) { - ni->ni_txrate = ni->ni_rates.rs_rates[0]; + ieee80211_node_set_txrate_dot11rate(ni, + ni->ni_rates.rs_rates[0]); return 0; } @@ -263,12 +266,13 @@ break; if (rix != ra->ra_rix) { /* update public rate */ - ni->ni_txrate = ni->ni_rates.rs_rates[rix] & IEEE80211_RATE_VAL; + ieee80211_node_set_txrate_dot11rate(ni, + ni->ni_rates.rs_rates[rix] & IEEE80211_RATE_VAL); ra->ra_rix = rix; IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, - "RSSADAPT new rate %d (pktlen %d rssi %d)", - ni->ni_txrate, pktlen, rssi); + "RSSADAPT new rate %d Mb (pktlen %d rssi %d)", + ieee80211_node_get_txrate_mbit(ni) / 2, pktlen, rssi); } return rix; } diff --git a/sys/net80211/ieee80211_scan_sta.c b/sys/net80211/ieee80211_scan_sta.c --- a/sys/net80211/ieee80211_scan_sta.c +++ b/sys/net80211/ieee80211_scan_sta.c @@ -1365,7 +1365,7 @@ /* NB: the most up to date rssi is in the node, not the scan cache */ curRssi = ic->ic_node_getrssi(ni); if (ucastRate == IEEE80211_FIXED_RATE_NONE) { - curRate = ni->ni_txrate; + curRate = ieee80211_node_get_txrate_dot11rate(ni); IEEE80211_DPRINTF(vap, IEEE80211_MSG_ROAM, "%s: currssi %d currate %u roamrssi %d roamrate %u\n", __func__, curRssi, curRate, roamRssi, roamRate); diff --git a/sys/net80211/ieee80211_sta.c b/sys/net80211/ieee80211_sta.c --- a/sys/net80211/ieee80211_sta.c +++ b/sys/net80211/ieee80211_sta.c @@ -64,8 +64,6 @@ #include #include -#define IEEE80211_RATE2MBS(r) (((r) & IEEE80211_RATE_VAL) / 2) - static void sta_vattach(struct ieee80211vap *); static void sta_beacon_miss(struct ieee80211vap *); static int sta_newstate(struct ieee80211vap *, enum ieee80211_state, int); @@ -417,10 +415,9 @@ ether_sprintf(ni->ni_bssid)); ieee80211_print_essid(vap->iv_bss->ni_essid, ni->ni_esslen); - /* XXX MCS/HT */ printf(" channel %d start %uMb\n", ieee80211_chan2ieee(ic, ic->ic_curchan), - IEEE80211_RATE2MBS(ni->ni_txrate)); + ieee80211_node_get_txrate_mbit(ni) / 2); } #endif ieee80211_scan_assoc_success(vap, ni->ni_macaddr); diff --git a/sys/net80211/ieee80211_superg.c b/sys/net80211/ieee80211_superg.c --- a/sys/net80211/ieee80211_superg.c +++ b/sys/net80211/ieee80211_superg.c @@ -725,6 +725,7 @@ struct ieee80211vap *vap = ni->ni_vap; uint32_t framelen; uint32_t frame_time; + uint8_t dot11rate; /* * Approximate the frame length to be transmitted. A swag to add @@ -746,15 +747,16 @@ * For now, we assume non-shortgi, 20MHz, just because I want to * at least test 802.11n. */ - if (ni->ni_txrate & IEEE80211_RATE_MCS) + dot11rate = ieee80211_node_get_txrate_dot11rate(ni); + if (dot11rate & IEEE80211_RATE_MCS) frame_time = ieee80211_compute_duration_ht(framelen, - ni->ni_txrate, - IEEE80211_HT_RC_2_STREAMS(ni->ni_txrate), + dot11rate, + IEEE80211_HT_RC_2_STREAMS(dot11rate), 0, /* isht40 */ 0); /* isshortgi */ else frame_time = ieee80211_compute_duration(ic->ic_rt, framelen, - ni->ni_txrate, 0); + dot11rate, 0); return (frame_time); }