xref: /dflybsd-src/sys/netproto/802_11/ieee80211_phy.h (revision 32176cfd8803dac7f65c423373f231a378375c86)
1*32176cfdSRui Paulo /*-
2*32176cfdSRui Paulo  * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting
3*32176cfdSRui Paulo  * All rights reserved.
4*32176cfdSRui Paulo  *
5*32176cfdSRui Paulo  * Redistribution and use in source and binary forms, with or without
6*32176cfdSRui Paulo  * modification, are permitted provided that the following conditions
7*32176cfdSRui Paulo  * are met:
8*32176cfdSRui Paulo  * 1. Redistributions of source code must retain the above copyright
9*32176cfdSRui Paulo  *    notice, this list of conditions and the following disclaimer.
10*32176cfdSRui Paulo  * 2. Redistributions in binary form must reproduce the above copyright
11*32176cfdSRui Paulo  *    notice, this list of conditions and the following disclaimer in the
12*32176cfdSRui Paulo  *    documentation and/or other materials provided with the distribution.
13*32176cfdSRui Paulo  *
14*32176cfdSRui Paulo  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15*32176cfdSRui Paulo  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16*32176cfdSRui Paulo  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17*32176cfdSRui Paulo  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18*32176cfdSRui Paulo  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19*32176cfdSRui Paulo  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20*32176cfdSRui Paulo  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21*32176cfdSRui Paulo  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22*32176cfdSRui Paulo  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23*32176cfdSRui Paulo  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*32176cfdSRui Paulo  *
25*32176cfdSRui Paulo  * $FreeBSD: head/sys/net80211/ieee80211_phy.h 193072 2009-05-29 23:39:16Z sam $
26*32176cfdSRui Paulo  * $DragonFly$
27*32176cfdSRui Paulo  */
28*32176cfdSRui Paulo 
29*32176cfdSRui Paulo #ifndef _NET80211_IEEE80211_PHY_H_
30*32176cfdSRui Paulo #define _NET80211_IEEE80211_PHY_H_
31*32176cfdSRui Paulo 
32*32176cfdSRui Paulo #ifdef _KERNEL
33*32176cfdSRui Paulo /*
34*32176cfdSRui Paulo  * IEEE 802.11 PHY-related definitions.
35*32176cfdSRui Paulo  */
36*32176cfdSRui Paulo 
37*32176cfdSRui Paulo /*
38*32176cfdSRui Paulo  * Contention window (slots).
39*32176cfdSRui Paulo  */
40*32176cfdSRui Paulo #define IEEE80211_CW_MAX	1023	/* aCWmax */
41*32176cfdSRui Paulo #define IEEE80211_CW_MIN_0	31	/* DS/CCK aCWmin, ERP aCWmin(0) */
42*32176cfdSRui Paulo #define IEEE80211_CW_MIN_1	15	/* OFDM aCWmin, ERP aCWmin(1) */
43*32176cfdSRui Paulo 
44*32176cfdSRui Paulo /*
45*32176cfdSRui Paulo  * SIFS (microseconds).
46*32176cfdSRui Paulo  */
47*32176cfdSRui Paulo #define IEEE80211_DUR_SIFS	10	/* DS/CCK/ERP SIFS */
48*32176cfdSRui Paulo #define IEEE80211_DUR_OFDM_SIFS	16	/* OFDM SIFS */
49*32176cfdSRui Paulo 
50*32176cfdSRui Paulo /*
51*32176cfdSRui Paulo  * Slot time (microseconds).
52*32176cfdSRui Paulo  */
53*32176cfdSRui Paulo #define IEEE80211_DUR_SLOT	20	/* DS/CCK slottime, ERP long slottime */
54*32176cfdSRui Paulo #define IEEE80211_DUR_SHSLOT	9	/* ERP short slottime */
55*32176cfdSRui Paulo #define IEEE80211_DUR_OFDM_SLOT	9	/* OFDM slottime */
56*32176cfdSRui Paulo 
57*32176cfdSRui Paulo /*
58*32176cfdSRui Paulo  * DIFS (microseconds).
59*32176cfdSRui Paulo  */
60*32176cfdSRui Paulo #define IEEE80211_DUR_DIFS(sifs, slot)	((sifs) + 2 * (slot))
61*32176cfdSRui Paulo 
62*32176cfdSRui Paulo struct ieee80211_channel;
63*32176cfdSRui Paulo 
64*32176cfdSRui Paulo struct ieee80211_rate_table {
65*32176cfdSRui Paulo 	int		rateCount;		/* NB: for proper padding */
66*32176cfdSRui Paulo 	uint8_t		rateCodeToIndex[256];	/* back mapping */
67*32176cfdSRui Paulo 	struct {
68*32176cfdSRui Paulo 		uint8_t		phy;		/* CCK/OFDM/TURBO */
69*32176cfdSRui Paulo 		uint32_t	rateKbps;	/* transfer rate in kbs */
70*32176cfdSRui Paulo 		uint8_t		shortPreamble;	/* mask for enabling short
71*32176cfdSRui Paulo 						 * preamble in CCK rate code */
72*32176cfdSRui Paulo 		uint8_t		dot11Rate;	/* value for supported rates
73*32176cfdSRui Paulo 						 * info element of MLME */
74*32176cfdSRui Paulo 		uint8_t		ctlRateIndex;	/* index of next lower basic
75*32176cfdSRui Paulo 						 * rate; used for dur. calcs */
76*32176cfdSRui Paulo 		uint16_t	lpAckDuration;	/* long preamble ACK dur. */
77*32176cfdSRui Paulo 		uint16_t	spAckDuration;	/* short preamble ACK dur. */
78*32176cfdSRui Paulo 	} info[32];
79*32176cfdSRui Paulo };
80*32176cfdSRui Paulo 
81*32176cfdSRui Paulo const struct ieee80211_rate_table *ieee80211_get_ratetable(
82*32176cfdSRui Paulo 			struct ieee80211_channel *);
83*32176cfdSRui Paulo 
84*32176cfdSRui Paulo static __inline__ uint8_t
85*32176cfdSRui Paulo ieee80211_ack_rate(const struct ieee80211_rate_table *rt, uint8_t rate)
86*32176cfdSRui Paulo {
87*32176cfdSRui Paulo 	uint8_t cix = rt->info[rt->rateCodeToIndex[rate]].ctlRateIndex;
88*32176cfdSRui Paulo 	KASSERT(cix != (uint8_t)-1, ("rate %d has no info", rate));
89*32176cfdSRui Paulo 	return rt->info[cix].dot11Rate;
90*32176cfdSRui Paulo }
91*32176cfdSRui Paulo 
92*32176cfdSRui Paulo static __inline__ uint8_t
93*32176cfdSRui Paulo ieee80211_ctl_rate(const struct ieee80211_rate_table *rt, uint8_t rate)
94*32176cfdSRui Paulo {
95*32176cfdSRui Paulo 	uint8_t cix = rt->info[rt->rateCodeToIndex[rate]].ctlRateIndex;
96*32176cfdSRui Paulo 	KASSERT(cix != (uint8_t)-1, ("rate %d has no info", rate));
97*32176cfdSRui Paulo 	return rt->info[cix].dot11Rate;
98*32176cfdSRui Paulo }
99*32176cfdSRui Paulo 
100*32176cfdSRui Paulo static __inline__ enum ieee80211_phytype
101*32176cfdSRui Paulo ieee80211_rate2phytype(const struct ieee80211_rate_table *rt, uint8_t rate)
102*32176cfdSRui Paulo {
103*32176cfdSRui Paulo 	uint8_t rix = rt->rateCodeToIndex[rate];
104*32176cfdSRui Paulo 	KASSERT(rix != (uint8_t)-1, ("rate %d has no info", rate));
105*32176cfdSRui Paulo 	return rt->info[rix].phy;
106*32176cfdSRui Paulo }
107*32176cfdSRui Paulo 
108*32176cfdSRui Paulo static __inline__ int
109*32176cfdSRui Paulo ieee80211_isratevalid(const struct ieee80211_rate_table *rt, uint8_t rate)
110*32176cfdSRui Paulo {
111*32176cfdSRui Paulo 	return rt->rateCodeToIndex[rate] != (uint8_t)-1;
112*32176cfdSRui Paulo }
113*32176cfdSRui Paulo 
114*32176cfdSRui Paulo /*
115*32176cfdSRui Paulo  * Calculate ACK field for
116*32176cfdSRui Paulo  * o  non-fragment data frames
117*32176cfdSRui Paulo  * o  management frames
118*32176cfdSRui Paulo  * sent using rate, phy and short preamble setting.
119*32176cfdSRui Paulo  */
120*32176cfdSRui Paulo static __inline__ uint16_t
121*32176cfdSRui Paulo ieee80211_ack_duration(const struct ieee80211_rate_table *rt,
122*32176cfdSRui Paulo     uint8_t rate, int isShortPreamble)
123*32176cfdSRui Paulo {
124*32176cfdSRui Paulo 	uint8_t rix = rt->rateCodeToIndex[rate];
125*32176cfdSRui Paulo 
126*32176cfdSRui Paulo 	KASSERT(rix != (uint8_t)-1, ("rate %d has no info", rate));
127*32176cfdSRui Paulo 	if (isShortPreamble) {
128*32176cfdSRui Paulo 		KASSERT(rt->info[rix].spAckDuration != 0,
129*32176cfdSRui Paulo 			("shpreamble ack dur is not computed!\n"));
130*32176cfdSRui Paulo 		return rt->info[rix].spAckDuration;
131*32176cfdSRui Paulo 	} else {
132*32176cfdSRui Paulo 		KASSERT(rt->info[rix].lpAckDuration != 0,
133*32176cfdSRui Paulo 			("lgpreamble ack dur is not computed!\n"));
134*32176cfdSRui Paulo 		return rt->info[rix].lpAckDuration;
135*32176cfdSRui Paulo 	}
136*32176cfdSRui Paulo }
137*32176cfdSRui Paulo 
138*32176cfdSRui Paulo /*
139*32176cfdSRui Paulo  * Compute the time to transmit a frame of length frameLen bytes
140*32176cfdSRui Paulo  * using the specified 802.11 rate code, phy, and short preamble
141*32176cfdSRui Paulo  * setting.
142*32176cfdSRui Paulo  *
143*32176cfdSRui Paulo  * NB: SIFS is included.
144*32176cfdSRui Paulo  */
145*32176cfdSRui Paulo uint16_t	ieee80211_compute_duration(const struct ieee80211_rate_table *,
146*32176cfdSRui Paulo 			uint32_t frameLen, uint16_t rate, int isShortPreamble);
147*32176cfdSRui Paulo /*
148*32176cfdSRui Paulo  * Convert PLCP signal/rate field to 802.11 rate code (.5Mbits/s)
149*32176cfdSRui Paulo  */
150*32176cfdSRui Paulo uint8_t		ieee80211_plcp2rate(uint8_t, enum ieee80211_phytype);
151*32176cfdSRui Paulo /*
152*32176cfdSRui Paulo  * Convert 802.11 rate code to PLCP signal.
153*32176cfdSRui Paulo  */
154*32176cfdSRui Paulo uint8_t		ieee80211_rate2plcp(int, enum ieee80211_phytype);
155*32176cfdSRui Paulo #endif	/* _KERNEL */
156*32176cfdSRui Paulo #endif	/* !_NET80211_IEEE80211_PHY_H_ */
157