drm: Add linux/vmalloc.h
[dragonfly.git] / sys / netproto / 802_11 / ieee80211_phy.h
blobbf39cddbe9161fa278bae1590256508b2de8da05
1 /*-
2 * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 * $FreeBSD$
28 #ifndef _NET80211_IEEE80211_PHY_H_
29 #define _NET80211_IEEE80211_PHY_H_
31 #ifdef _KERNEL
33 * IEEE 802.11 PHY-related definitions.
37 * Contention window (slots).
39 #define IEEE80211_CW_MAX 1023 /* aCWmax */
40 #define IEEE80211_CW_MIN_0 31 /* DS/CCK aCWmin, ERP aCWmin(0) */
41 #define IEEE80211_CW_MIN_1 15 /* OFDM aCWmin, ERP aCWmin(1) */
44 * SIFS (microseconds).
46 #define IEEE80211_DUR_SIFS 10 /* DS/CCK/ERP SIFS */
47 #define IEEE80211_DUR_OFDM_SIFS 16 /* OFDM SIFS */
50 * Slot time (microseconds).
52 #define IEEE80211_DUR_SLOT 20 /* DS/CCK slottime, ERP long slottime */
53 #define IEEE80211_DUR_SHSLOT 9 /* ERP short slottime */
54 #define IEEE80211_DUR_OFDM_SLOT 9 /* OFDM slottime */
57 * DIFS (microseconds).
59 #define IEEE80211_DUR_DIFS(sifs, slot) ((sifs) + 2 * (slot))
61 struct ieee80211_channel;
63 #define IEEE80211_RATE_TABLE_SIZE 128
65 struct ieee80211_rate_table {
66 int rateCount; /* NB: for proper padding */
67 uint8_t rateCodeToIndex[256]; /* back mapping */
68 struct {
69 uint8_t phy; /* CCK/OFDM/TURBO */
70 uint32_t rateKbps; /* transfer rate in kbs */
71 uint8_t shortPreamble; /* mask for enabling short
72 * preamble in CCK rate code */
73 uint8_t dot11Rate; /* value for supported rates
74 * info element of MLME */
75 uint8_t ctlRateIndex; /* index of next lower basic
76 * rate; used for dur. calcs */
77 uint16_t lpAckDuration; /* long preamble ACK dur. */
78 uint16_t spAckDuration; /* short preamble ACK dur. */
79 } info[IEEE80211_RATE_TABLE_SIZE];
82 const struct ieee80211_rate_table *ieee80211_get_ratetable(
83 struct ieee80211_channel *);
85 static __inline__ uint8_t
86 ieee80211_ack_rate(const struct ieee80211_rate_table *rt, uint8_t rate)
89 * XXX Assert this is for a legacy rate; not for an MCS rate.
90 * If the caller wishes to use it for a basic rate, they should
91 * clear the high bit first.
93 KASSERT(! (rate & 0x80), ("rate %d is basic/mcs?", rate));
95 uint8_t cix = rt->info[rt->rateCodeToIndex[rate & IEEE80211_RATE_VAL]].ctlRateIndex;
96 KASSERT(cix != (uint8_t)-1, ("rate %d has no info", rate));
97 return rt->info[cix].dot11Rate;
100 static __inline__ uint8_t
101 ieee80211_ctl_rate(const struct ieee80211_rate_table *rt, uint8_t rate)
104 * XXX Assert this is for a legacy rate; not for an MCS rate.
105 * If the caller wishes to use it for a basic rate, they should
106 * clear the high bit first.
108 KASSERT(! (rate & 0x80), ("rate %d is basic/mcs?", rate));
110 uint8_t cix = rt->info[rt->rateCodeToIndex[rate & IEEE80211_RATE_VAL]].ctlRateIndex;
111 KASSERT(cix != (uint8_t)-1, ("rate %d has no info", rate));
112 return rt->info[cix].dot11Rate;
115 static __inline__ enum ieee80211_phytype
116 ieee80211_rate2phytype(const struct ieee80211_rate_table *rt, uint8_t rate)
119 * XXX Assert this is for a legacy rate; not for an MCS rate.
120 * If the caller wishes to use it for a basic rate, they should
121 * clear the high bit first.
123 KASSERT(! (rate & 0x80), ("rate %d is basic/mcs?", rate));
125 uint8_t rix = rt->rateCodeToIndex[rate & IEEE80211_RATE_VAL];
126 KASSERT(rix != (uint8_t)-1, ("rate %d has no info", rate));
127 return rt->info[rix].phy;
130 static __inline__ int
131 ieee80211_isratevalid(const struct ieee80211_rate_table *rt, uint8_t rate)
134 * XXX Assert this is for a legacy rate; not for an MCS rate.
135 * If the caller wishes to use it for a basic rate, they should
136 * clear the high bit first.
138 KASSERT(! (rate & 0x80), ("rate %d is basic/mcs?", rate));
140 return rt->rateCodeToIndex[rate] != (uint8_t)-1;
144 * Calculate ACK field for
145 * o non-fragment data frames
146 * o management frames
147 * sent using rate, phy and short preamble setting.
149 static __inline__ uint16_t
150 ieee80211_ack_duration(const struct ieee80211_rate_table *rt,
151 uint8_t rate, int isShortPreamble)
153 uint8_t rix = rt->rateCodeToIndex[rate];
155 KASSERT(rix != (uint8_t)-1, ("rate %d has no info", rate));
156 if (isShortPreamble) {
157 KASSERT(rt->info[rix].spAckDuration != 0,
158 ("shpreamble ack dur is not computed!\n"));
159 return rt->info[rix].spAckDuration;
160 } else {
161 KASSERT(rt->info[rix].lpAckDuration != 0,
162 ("lgpreamble ack dur is not computed!\n"));
163 return rt->info[rix].lpAckDuration;
167 static __inline__ uint8_t
168 ieee80211_legacy_rate_lookup(const struct ieee80211_rate_table *rt,
169 uint8_t rate)
172 return (rt->rateCodeToIndex[rate & IEEE80211_RATE_VAL]);
176 * Compute the time to transmit a frame of length frameLen bytes
177 * using the specified 802.11 rate code, phy, and short preamble
178 * setting.
180 * NB: SIFS is included.
182 uint16_t ieee80211_compute_duration(const struct ieee80211_rate_table *,
183 uint32_t frameLen, uint16_t rate, int isShortPreamble);
185 * Convert PLCP signal/rate field to 802.11 rate code (.5Mbits/s)
187 uint8_t ieee80211_plcp2rate(uint8_t, enum ieee80211_phytype);
189 * Convert 802.11 rate code to PLCP signal.
191 uint8_t ieee80211_rate2plcp(int, enum ieee80211_phytype);
193 uint32_t ieee80211_compute_duration_ht(uint32_t frameLen,
194 uint16_t rate, int streams, int isht40,
195 int isShortGI);
197 #endif /* _KERNEL */
198 #endif /* !_NET80211_IEEE80211_PHY_H_ */