/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2007-2008 Sam Leffler, Errno Consulting4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR16* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES17* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.18* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,19* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT20* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,21* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY22* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF24* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.25*/2627#ifndef _NET80211_IEEE80211_PHY_H_28#define _NET80211_IEEE80211_PHY_H_2930#ifdef _KERNEL31/*32* IEEE 802.11 PHY-related definitions.33*/3435/*36* Contention window (slots).37*/38#define IEEE80211_CW_MAX 1023 /* aCWmax */39#define IEEE80211_CW_MIN_0 31 /* DS/CCK aCWmin, ERP aCWmin(0) */40#define IEEE80211_CW_MIN_1 15 /* OFDM aCWmin, ERP aCWmin(1) */4142/*43* SIFS (microseconds).44*/45#define IEEE80211_DUR_SIFS 10 /* DS/CCK/ERP SIFS */46#define IEEE80211_DUR_OFDM_SIFS 16 /* OFDM SIFS */4748/*49* Slot time (microseconds).50*/51#define IEEE80211_DUR_SLOT 20 /* DS/CCK slottime, ERP long slottime */52#define IEEE80211_DUR_SHSLOT 9 /* ERP short slottime */53#define IEEE80211_DUR_OFDM_SLOT 9 /* OFDM slottime */5455/*56* For drivers that don't implement per-VAP slot time57* (ie, they rely on net80211 figuring out the union58* between VAPs to program a single radio) - return59* the current radio configured slot time.60*/61#define IEEE80211_GET_SLOTTIME(ic) \62((ic->ic_flags & IEEE80211_F_SHSLOT) ? \63IEEE80211_DUR_SHSLOT : IEEE80211_DUR_SLOT)6465/*66* For drivers that implement per-VAP slot time; look67* at the per-VAP flags to determine whether this VAP68* is in short or long slot time.69*/70#define IEEE80211_VAP_GET_SLOTTIME(vap) \71((vap->iv_flags & IEEE80211_F_SHSLOT) ? \72IEEE80211_DUR_SHSLOT : IEEE80211_DUR_SLOT)7374/*75* DIFS (microseconds).76*/77#define IEEE80211_DUR_DIFS(sifs, slot) ((sifs) + 2 * (slot))7879struct ieee80211_channel;8081#define IEEE80211_RATE_TABLE_SIZE 1288283struct ieee80211_rate_table {84int rateCount; /* NB: for proper padding */85uint8_t rateCodeToIndex[256]; /* back mapping */86struct {87uint8_t phy; /* CCK/OFDM/TURBO */88uint32_t rateKbps; /* transfer rate in kbs */89uint8_t shortPreamble; /* mask for enabling short90* preamble in CCK rate code */91uint8_t dot11Rate; /* value for supported rates92* info element of MLME */93uint8_t ctlRateIndex; /* index of next lower basic94* rate; used for dur. calcs */95uint16_t lpAckDuration; /* long preamble ACK dur. */96uint16_t spAckDuration; /* short preamble ACK dur. */97} info[IEEE80211_RATE_TABLE_SIZE];98};99100const struct ieee80211_rate_table *ieee80211_get_ratetable(101struct ieee80211_channel *);102103static __inline__ uint8_t104ieee80211_ack_rate(const struct ieee80211_rate_table *rt, uint8_t rate)105{106/*107* XXX Assert this is for a legacy rate; not for an MCS rate.108* If the caller wishes to use it for a basic rate, they should109* clear the high bit first.110*/111KASSERT(! (rate & 0x80), ("rate %d is basic/mcs?", rate));112113uint8_t cix = rt->info[rt->rateCodeToIndex[rate & IEEE80211_RATE_VAL]].ctlRateIndex;114KASSERT(cix != (uint8_t)-1, ("rate %d has no info", rate));115return rt->info[cix].dot11Rate;116}117118static __inline__ uint8_t119ieee80211_ctl_rate(const struct ieee80211_rate_table *rt, uint8_t rate)120{121/*122* XXX Assert this is for a legacy rate; not for an MCS rate.123* If the caller wishes to use it for a basic rate, they should124* clear the high bit first.125*/126KASSERT(! (rate & 0x80), ("rate %d is basic/mcs?", rate));127128uint8_t cix = rt->info[rt->rateCodeToIndex[rate & IEEE80211_RATE_VAL]].ctlRateIndex;129KASSERT(cix != (uint8_t)-1, ("rate %d has no info", rate));130return rt->info[cix].dot11Rate;131}132133static __inline__ enum ieee80211_phytype134ieee80211_rate2phytype(const struct ieee80211_rate_table *rt, uint8_t rate)135{136/*137* XXX Assert this is for a legacy rate; not for an MCS rate.138* If the caller wishes to use it for a basic rate, they should139* clear the high bit first.140*/141KASSERT(! (rate & 0x80), ("rate %d is basic/mcs?", rate));142143uint8_t rix = rt->rateCodeToIndex[rate & IEEE80211_RATE_VAL];144KASSERT(rix != (uint8_t)-1, ("rate %d has no info", rate));145return rt->info[rix].phy;146}147148static __inline__ int149ieee80211_isratevalid(const struct ieee80211_rate_table *rt, uint8_t rate)150{151/*152* XXX Assert this is for a legacy rate; not for an MCS rate.153* If the caller wishes to use it for a basic rate, they should154* clear the high bit first.155*/156KASSERT(! (rate & 0x80), ("rate %d is basic/mcs?", rate));157158return rt->rateCodeToIndex[rate] != (uint8_t)-1;159}160161/*162* Calculate ACK field for163* o non-fragment data frames164* o management frames165* sent using rate, phy and short preamble setting.166*/167static __inline__ uint16_t168ieee80211_ack_duration(const struct ieee80211_rate_table *rt,169uint8_t rate, int isShortPreamble)170{171uint8_t rix = rt->rateCodeToIndex[rate];172173KASSERT(rix != (uint8_t)-1, ("rate %d has no info", rate));174if (isShortPreamble) {175KASSERT(rt->info[rix].spAckDuration != 0,176("shpreamble ack dur is not computed!\n"));177return rt->info[rix].spAckDuration;178} else {179KASSERT(rt->info[rix].lpAckDuration != 0,180("lgpreamble ack dur is not computed!\n"));181return rt->info[rix].lpAckDuration;182}183}184185static __inline__ uint8_t186ieee80211_legacy_rate_lookup(const struct ieee80211_rate_table *rt,187uint8_t rate)188{189190return (rt->rateCodeToIndex[rate & IEEE80211_RATE_VAL]);191}192193/*194* Compute the time to transmit a frame of length frameLen bytes195* using the specified 802.11 rate code, phy, and short preamble196* setting.197*198* NB: SIFS is included.199*/200uint16_t ieee80211_compute_duration(const struct ieee80211_rate_table *,201uint32_t frameLen, uint16_t rate, int isShortPreamble);202/*203* Convert PLCP signal/rate field to 802.11 rate code (.5Mbits/s)204*/205uint8_t ieee80211_plcp2rate(uint8_t, enum ieee80211_phytype);206/*207* Convert 802.11 rate code to PLCP signal.208*/209uint8_t ieee80211_rate2plcp(int, enum ieee80211_phytype);210211/*212* 802.11n rate manipulation.213*/214215#define IEEE80211_HT_RC_2_MCS(_rc) ((_rc) & 0x1f)216#define IEEE80211_HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1)217#define IEEE80211_IS_HT_RATE(_rc) ( (_rc) & IEEE80211_RATE_MCS)218219uint32_t ieee80211_compute_duration_ht(uint32_t frameLen,220uint16_t rate, int streams, int isht40,221int isShortGI);222223enum net80211_sta_rx_bw;224225uint16_t ieee80211_phy_vht_get_mcs_mask(enum net80211_sta_rx_bw,226uint8_t);227bool ieee80211_phy_vht_validate_mcs(enum net80211_sta_rx_bw,228uint8_t, uint8_t);229uint32_t ieee80211_phy_vht_get_mcs_kbit(enum net80211_sta_rx_bw,230uint8_t, uint8_t, bool);231232#endif /* _KERNEL */233#endif /* !_NET80211_IEEE80211_PHY_H_ */234235236