10ba2cbe9Sxc /*
2*e2cf88acSQuaker Fang  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
30ba2cbe9Sxc  * Use is subject to license terms.
40ba2cbe9Sxc  */
50ba2cbe9Sxc 
60ba2cbe9Sxc /*
70ba2cbe9Sxc  * Copyright (c) 2001 Atsushi Onoe
8*e2cf88acSQuaker Fang  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
90ba2cbe9Sxc  * All rights reserved.
100ba2cbe9Sxc  *
110ba2cbe9Sxc  * Redistribution and use in source and binary forms, with or without
120ba2cbe9Sxc  * modification, are permitted provided that the following conditions
130ba2cbe9Sxc  * are met:
140ba2cbe9Sxc  * 1. Redistributions of source code must retain the above copyright
150ba2cbe9Sxc  *    notice, this list of conditions and the following disclaimer.
160ba2cbe9Sxc  * 2. Redistributions in binary form must reproduce the above copyright
170ba2cbe9Sxc  *    notice, this list of conditions and the following disclaimer in the
180ba2cbe9Sxc  *    documentation and/or other materials provided with the distribution.
190ba2cbe9Sxc  * 3. The name of the author may not be used to endorse or promote products
200ba2cbe9Sxc  *    derived from this software without specific prior written permission.
210ba2cbe9Sxc  *
220ba2cbe9Sxc  * Alternatively, this software may be distributed under the terms of the
230ba2cbe9Sxc  * GNU General Public License ("GPL") version 2 as published by the Free
240ba2cbe9Sxc  * Software Foundation.
250ba2cbe9Sxc  *
260ba2cbe9Sxc  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
270ba2cbe9Sxc  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
280ba2cbe9Sxc  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
290ba2cbe9Sxc  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
300ba2cbe9Sxc  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
310ba2cbe9Sxc  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
320ba2cbe9Sxc  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
330ba2cbe9Sxc  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
340ba2cbe9Sxc  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
350ba2cbe9Sxc  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
360ba2cbe9Sxc  */
370ba2cbe9Sxc 
380ba2cbe9Sxc #ifndef _SYS_NET80211_IMPL_H
390ba2cbe9Sxc #define	_SYS_NET80211_IMPL_H
400ba2cbe9Sxc 
410ba2cbe9Sxc #include <sys/sysmacros.h>
420ba2cbe9Sxc #include <sys/list.h>
430ba2cbe9Sxc #include <sys/note.h>
440ba2cbe9Sxc #include <sys/net80211_proto.h>
450ba2cbe9Sxc #include <sys/net80211.h>
460ba2cbe9Sxc #include <sys/mac_wifi.h>
470ba2cbe9Sxc 
480ba2cbe9Sxc /*
490ba2cbe9Sxc  * IEEE802.11 kernel support module
500ba2cbe9Sxc  */
510ba2cbe9Sxc 
520ba2cbe9Sxc #ifdef	__cplusplus
530ba2cbe9Sxc extern "C" {
540ba2cbe9Sxc #endif
550ba2cbe9Sxc 
560ba2cbe9Sxc #define	IEEE80211_TXPOWER_MAX	100	/* .5 dbM */
570ba2cbe9Sxc #define	IEEE80211_TXPOWER_MIN	0	/* kill radio */
580ba2cbe9Sxc 
590ba2cbe9Sxc #define	IEEE80211_DTIM_MAX	15	/* max DTIM period */
600ba2cbe9Sxc #define	IEEE80211_DTIM_MIN	1	/* min DTIM period */
610ba2cbe9Sxc #define	IEEE80211_DTIM_DEFAULT	1	/* default DTIM period */
620ba2cbe9Sxc 
630ba2cbe9Sxc /* NB: min+max come from WiFi requirements */
640ba2cbe9Sxc #define	IEEE80211_BINTVAL_MAX	1000	/* max beacon interval (TU's) */
650ba2cbe9Sxc #define	IEEE80211_BINTVAL_MIN	25	/* min beacon interval (TU's) */
660ba2cbe9Sxc #define	IEEE80211_BINTVAL_DEFAULT 100	/* default beacon interval (TU's) */
670ba2cbe9Sxc 
680ba2cbe9Sxc #define	IEEE80211_BMISS_MAX	2	/* maximum consecutive bmiss allowed */
690ba2cbe9Sxc #define	IEEE80211_SWBMISS_THRESHOLD 50	/* s/w bmiss threshold (TU's) */
700ba2cbe9Sxc #define	IEEE80211_HWBMISS_DEFAULT 7	/* h/w bmiss threshold (beacons) */
710ba2cbe9Sxc 
720ba2cbe9Sxc #define	IEEE80211_PS_SLEEP	0x1	/* STA is in power saving mode */
730ba2cbe9Sxc #define	IEEE80211_PS_MAX_QUEUE	50	/* maximum saved packets */
740ba2cbe9Sxc 
750ba2cbe9Sxc #define	IEEE80211_RTS_DEFAULT	IEEE80211_RTS_MAX
760ba2cbe9Sxc #define	IEEE80211_FRAG_DEFAULT	IEEE80211_FRAG_MAX
770ba2cbe9Sxc 
780ba2cbe9Sxc /*
790ba2cbe9Sxc  * The RSSI values of two node are taken as almost the same when
800ba2cbe9Sxc  * the difference between these two node's RSSI values is within
810ba2cbe9Sxc  * IEEE80211_RSSI_CMP_THRESHOLD
820ba2cbe9Sxc  */
830ba2cbe9Sxc #define	IEEE80211_RSSI_CMP_THRESHOLD	5
840ba2cbe9Sxc 
850ba2cbe9Sxc /*
860ba2cbe9Sxc  * Each ieee80211com instance has a single timer that fires once a
870ba2cbe9Sxc  * second.  This is used to initiate various work depending on the
880ba2cbe9Sxc  * state of the instance: scanning (passive or active), ``transition''
890ba2cbe9Sxc  * (waiting for a response to a management frame when operating
900ba2cbe9Sxc  * as a station), and node inactivity processing (when operating
910ba2cbe9Sxc  * as an AP).  For inactivity processing each node has a timeout
920ba2cbe9Sxc  * set in it's in_inact field that is decremented on each timeout
930ba2cbe9Sxc  * and the node is reclaimed when the counter goes to zero.  We
940ba2cbe9Sxc  * use different inactivity timeout values depending on whether
950ba2cbe9Sxc  * the node is associated and authorized (either by 802.1x or
960ba2cbe9Sxc  * open/shared key authentication) or associated but yet to be
970ba2cbe9Sxc  * authorized.  The latter timeout is shorter to more aggressively
980ba2cbe9Sxc  * reclaim nodes that leave part way through the 802.1x exchange.
990ba2cbe9Sxc  *
1000ba2cbe9Sxc  * IEEE80211_INACT_WAIT defines node table's inactivity interval in
1010ba2cbe9Sxc  * seconds. On timeout, node table's registered nt_timeout callback
1020ba2cbe9Sxc  * function is executed. Each node in the node table has a timeout
1030ba2cbe9Sxc  * set in its in_inact field with IEEE80211_INACT_<state>. In
1040ba2cbe9Sxc  * nt_timeout function, node table is iterated and each node's
1050ba2cbe9Sxc  * in_inact is decremented. So IEEE80211_INACT_<state> is defined in
1060ba2cbe9Sxc  * the form [inact_sec]/IEEE80211_INACT_WAIT.
1070ba2cbe9Sxc  *
1080ba2cbe9Sxc  */
1090ba2cbe9Sxc #define	IEEE80211_INACT_WAIT	15	/* inactivity interval (secs) */
1100ba2cbe9Sxc #define	IEEE80211_INACT_INIT	(30/IEEE80211_INACT_WAIT)	/* initial */
1110ba2cbe9Sxc #define	IEEE80211_INACT_ASSOC	(180/IEEE80211_INACT_WAIT)
1120ba2cbe9Sxc 					/* associated but not authorized */
1130ba2cbe9Sxc #define	IEEE80211_INACT_RUN	(300/IEEE80211_INACT_WAIT)	/* authorized */
1140ba2cbe9Sxc #define	IEEE80211_INACT_PROBE	(30/IEEE80211_INACT_WAIT)	/* probe */
1150ba2cbe9Sxc #define	IEEE80211_INACT_SCAN	(300/IEEE80211_INACT_WAIT)	/* scanned */
1160ba2cbe9Sxc 
1170ba2cbe9Sxc #define	IEEE80211_TRANS_WAIT 	5	/* mgt frame tx timer (secs) */
1180ba2cbe9Sxc 
1190ba2cbe9Sxc /*
1200ba2cbe9Sxc  * Useful combinations of channel characteristics.
1210ba2cbe9Sxc  */
1220ba2cbe9Sxc #define	IEEE80211_CHAN_FHSS	\
1230ba2cbe9Sxc 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK)
1240ba2cbe9Sxc #define	IEEE80211_CHAN_A	\
1250ba2cbe9Sxc 	(IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
1260ba2cbe9Sxc #define	IEEE80211_CHAN_B	\
1270ba2cbe9Sxc 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
1280ba2cbe9Sxc #define	IEEE80211_CHAN_PUREG	\
1290ba2cbe9Sxc 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM)
1300ba2cbe9Sxc #define	IEEE80211_CHAN_G	\
1310ba2cbe9Sxc 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
1320ba2cbe9Sxc #define	IEEE80211_CHAN_T	\
1330ba2cbe9Sxc 	(IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
1340ba2cbe9Sxc #define	IEEE80211_CHAN_108G	\
1350ba2cbe9Sxc 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
136*e2cf88acSQuaker Fang #define	IEEE80211_CHAN_ST	\
137*e2cf88acSQuaker Fang 	(IEEE80211_CHAN_T | IEEE80211_CHAN_STURBO)
1380ba2cbe9Sxc 
1390ba2cbe9Sxc #define	IEEE80211_CHAN_ALL	\
1400ba2cbe9Sxc 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_GFSK | \
141*e2cf88acSQuaker Fang 	IEEE80211_CHAN_CCK | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_DYN |	\
142*e2cf88acSQuaker Fang 	IEEE80211_CHAN_HT)
1430ba2cbe9Sxc #define	IEEE80211_CHAN_ALLTURBO	\
144*e2cf88acSQuaker Fang 	(IEEE80211_CHAN_ALL | IEEE80211_CHAN_TURBO | IEEE80211_CHAN_STURBO)
1450ba2cbe9Sxc 
1460ba2cbe9Sxc #define	IEEE80211_IS_CHAN_FHSS(_c)	\
1470ba2cbe9Sxc 	(((_c)->ich_flags & IEEE80211_CHAN_FHSS) == IEEE80211_CHAN_FHSS)
1480ba2cbe9Sxc #define	IEEE80211_IS_CHAN_A(_c)		\
1490ba2cbe9Sxc 	(((_c)->ich_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A)
1500ba2cbe9Sxc #define	IEEE80211_IS_CHAN_B(_c)		\
1510ba2cbe9Sxc 	(((_c)->ich_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B)
1520ba2cbe9Sxc #define	IEEE80211_IS_CHAN_PUREG(_c)	\
1530ba2cbe9Sxc 	(((_c)->ich_flags & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG)
1540ba2cbe9Sxc #define	IEEE80211_IS_CHAN_G(_c)		\
1550ba2cbe9Sxc 	(((_c)->ich_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G)
1560ba2cbe9Sxc #define	IEEE80211_IS_CHAN_ANYG(_c)	\
1570ba2cbe9Sxc 	(IEEE80211_IS_CHAN_PUREG(_c) || IEEE80211_IS_CHAN_G(_c))
1580ba2cbe9Sxc #define	IEEE80211_IS_CHAN_T(_c)		\
1590ba2cbe9Sxc 	(((_c)->ich_flags & IEEE80211_CHAN_T) == IEEE80211_CHAN_T)
160*e2cf88acSQuaker Fang 		/* IEEE80211_IS_CHAN_108A */
1610ba2cbe9Sxc #define	IEEE80211_IS_CHAN_108G(_c)	\
1620ba2cbe9Sxc 	(((_c)->ich_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G)
163*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_ST(_c)	\
164*e2cf88acSQuaker Fang 	(((_c)->ich_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST)
1650ba2cbe9Sxc 
1660ba2cbe9Sxc #define	IEEE80211_IS_CHAN_OFDM(_c)	\
1670ba2cbe9Sxc 	((_c)->ich_flags & IEEE80211_CHAN_OFDM)
1680ba2cbe9Sxc #define	IEEE80211_IS_CHAN_CCK(_c)	\
1690ba2cbe9Sxc 	((_c)->ich_flags & IEEE80211_CHAN_CCK)
1700ba2cbe9Sxc #define	IEEE80211_IS_CHAN_GFSK(_c)	\
1710ba2cbe9Sxc 	((_c)->ich_flags & IEEE80211_CHAN_GFSK)
1720ba2cbe9Sxc #define	IEEE80211_IS_CHAN_PASSIVE(_c)	\
1730ba2cbe9Sxc 	((_c)->ich_flags & IEEE80211_CHAN_PASSIVE)
1740ba2cbe9Sxc 
175*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_STURBO(_c) \
176*e2cf88acSQuaker Fang 	((_c)->ich_flags & IEEE80211_CHAN_STURBO)
177*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_DTURBO(_c) \
178*e2cf88acSQuaker Fang 	(((_c)->ich_flags & \
179*e2cf88acSQuaker Fang 	(IEEE80211_CHAN_TURBO | IEEE80211_CHAN_STURBO)) == IEEE80211_CHAN_TURBO)
180*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_HALF(_c) \
181*e2cf88acSQuaker Fang 	((_c)->ich_flags & IEEE80211_CHAN_HALF)
182*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_QUARTER(_c) \
183*e2cf88acSQuaker Fang 	((_c)->ich_flags & IEEE80211_CHAN_QUARTER)
184*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_FULL(_c) \
185*e2cf88acSQuaker Fang 	((_c)->ich_flags & (IEEE80211_CHAN_QUARTER | IEEE80211_CHAN_HALF))
186*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_GSM(_c) \
187*e2cf88acSQuaker Fang 	((_c)->ich_flags & IEEE80211_CHAN_GSM)
188*e2cf88acSQuaker Fang 
189*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_HT(_c) \
190*e2cf88acSQuaker Fang 	((_c)->ich_flags & IEEE80211_CHAN_HT)
191*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_HT20(_c) \
192*e2cf88acSQuaker Fang 	((_c)->ich_flags & IEEE80211_CHAN_HT20)
193*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_HT40(_c) \
194*e2cf88acSQuaker Fang 	((_c)->ich_flags & IEEE80211_CHAN_HT40)
195*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_HT40U(_c) \
196*e2cf88acSQuaker Fang 	((_c)->ich_flags & IEEE80211_CHAN_HT40U)
197*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_HT40D(_c) \
198*e2cf88acSQuaker Fang 	((_c)->ich_flags & IEEE80211_CHAN_HT40D)
199*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_HTA(_c) \
200*e2cf88acSQuaker Fang 	(IEEE80211_IS_CHAN_5GHZ(_c) && \
201*e2cf88acSQuaker Fang 	((_c)->ich_flags & IEEE80211_CHAN_HT))
202*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_HTG(_c) \
203*e2cf88acSQuaker Fang 	(IEEE80211_IS_CHAN_2GHZ(_c) && \
204*e2cf88acSQuaker Fang 	((_c)->ich_flags & IEEE80211_CHAN_HT))
205*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_DFS(_c) \
206*e2cf88acSQuaker Fang 	((_c)->ich_flags & IEEE80211_CHAN_DFS)
207*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_NOADHOC(_c) \
208*e2cf88acSQuaker Fang 	((_c)->ich_flags & IEEE80211_CHAN_NOADHOC)
209*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_NOHOSTAP(_c) \
210*e2cf88acSQuaker Fang 	((_c)->ich_flags & IEEE80211_CHAN_NOHOSTAP)
211*e2cf88acSQuaker Fang #define	IEEE80211_IS_CHAN_11D(_c) \
212*e2cf88acSQuaker Fang 	((_c)->ich_flags & IEEE80211_CHAN_11D)
213*e2cf88acSQuaker Fang 
2140ba2cbe9Sxc /* ni_chan encoding for FH phy */
2150ba2cbe9Sxc #define	IEEE80211_FH_CHANMOD	80
2160ba2cbe9Sxc #define	IEEE80211_FH_CHAN(set, pat)	\
2170ba2cbe9Sxc 	(((set) - 1) * IEEE80211_FH_CHANMOD + (pat))
2180ba2cbe9Sxc #define	IEEE80211_FH_CHANSET(chan)	\
2190ba2cbe9Sxc 	((chan) / IEEE80211_FH_CHANMOD + 1)
2200ba2cbe9Sxc #define	IEEE80211_FH_CHANPAT(chan)	\
2210ba2cbe9Sxc 	((chan) % IEEE80211_FH_CHANMOD)
2220ba2cbe9Sxc 
2230ba2cbe9Sxc #define	IEEE80211_NODE_AUTH	0x0001		/* authorized for data */
2240ba2cbe9Sxc #define	IEEE80211_NODE_QOS	0x0002		/* QoS enabled */
2250ba2cbe9Sxc #define	IEEE80211_NODE_ERP	0x0004		/* ERP enabled */
2260ba2cbe9Sxc #define	IEEE80211_NODE_PWR_MGT	0x0010		/* power save mode enabled */
2270ba2cbe9Sxc #define	IEEE80211_NODE_AREF	0x0020		/* authentication ref held */
2280ba2cbe9Sxc 
2290ba2cbe9Sxc #define	IEEE80211_MAXRSSI	127
2300ba2cbe9Sxc 
2310ba2cbe9Sxc /* Debug Flags */
232bcb5c89dSSowmini Varadhan #define	IEEE80211_MSG_BRUSSELS  0x80000000	/* BRUSSELS */
2330ba2cbe9Sxc #define	IEEE80211_MSG_DEBUG	0x40000000	/* IFF_DEBUG equivalent */
2340ba2cbe9Sxc #define	IEEE80211_MSG_DUMPPKTS	0x20000000	/* IFF_LINK2 equivalant */
2350ba2cbe9Sxc #define	IEEE80211_MSG_CRYPTO	0x10000000	/* crypto work */
2360ba2cbe9Sxc #define	IEEE80211_MSG_INPUT	0x08000000	/* input handling */
2370ba2cbe9Sxc #define	IEEE80211_MSG_XRATE	0x04000000	/* rate set handling */
2380ba2cbe9Sxc #define	IEEE80211_MSG_ELEMID	0x02000000	/* element id parsing */
2390ba2cbe9Sxc #define	IEEE80211_MSG_NODE	0x01000000	/* node handling */
2400ba2cbe9Sxc #define	IEEE80211_MSG_ASSOC	0x00800000	/* association handling */
2410ba2cbe9Sxc #define	IEEE80211_MSG_AUTH	0x00400000	/* authentication handling */
2420ba2cbe9Sxc #define	IEEE80211_MSG_SCAN	0x00200000	/* scanning */
2430ba2cbe9Sxc #define	IEEE80211_MSG_OUTPUT	0x00100000	/* output handling */
2440ba2cbe9Sxc #define	IEEE80211_MSG_STATE	0x00080000	/* state machine */
2450ba2cbe9Sxc #define	IEEE80211_MSG_POWER	0x00040000	/* power save handling */
2460ba2cbe9Sxc #define	IEEE80211_MSG_DOT1X	0x00020000	/* 802.1x authenticator */
2470ba2cbe9Sxc #define	IEEE80211_MSG_DOT1XSM	0x00010000	/* 802.1x state machine */
2480ba2cbe9Sxc #define	IEEE80211_MSG_RADIUS	0x00008000	/* 802.1x radius client */
2490ba2cbe9Sxc #define	IEEE80211_MSG_RADDUMP	0x00004000	/* dump 802.1x radius packets */
2500ba2cbe9Sxc #define	IEEE80211_MSG_RADKEYS	0x00002000	/* dump 802.1x keys */
2510ba2cbe9Sxc #define	IEEE80211_MSG_WPA	0x00001000	/* WPA/RSN protocol */
2520ba2cbe9Sxc #define	IEEE80211_MSG_ACL	0x00000800	/* ACL handling */
2530ba2cbe9Sxc #define	IEEE80211_MSG_WME	0x00000400	/* WME protocol */
2540ba2cbe9Sxc #define	IEEE80211_MSG_SUPERG	0x00000200	/* Atheros SuperG protocol */
2550ba2cbe9Sxc #define	IEEE80211_MSG_DOTH	0x00000100	/* 802.11h support */
2560ba2cbe9Sxc #define	IEEE80211_MSG_INACT	0x00000080	/* inactivity handling */
2570ba2cbe9Sxc #define	IEEE80211_MSG_ROAM	0x00000040	/* sta-mode roaming */
2580ba2cbe9Sxc #define	IEEE80211_MSG_CONFIG	0x00000020	/* wificonfig/dladm */
259*e2cf88acSQuaker Fang #define	IEEE80211_MSG_ACTION	0x00000010	/* action frame handling */
260*e2cf88acSQuaker Fang #define	IEEE80211_MSG_HT	0x00000008	/* 11n mode debug */
2610ba2cbe9Sxc #define	IEEE80211_MSG_ANY	0xffffffff	/* anything */
2620ba2cbe9Sxc 
2630ba2cbe9Sxc /* Error flags returned by ieee80211_match_bss */
2640ba2cbe9Sxc #define	IEEE80211_BADCHAN	0x01
2650ba2cbe9Sxc #define	IEEE80211_BADOPMODE	0x02
2660ba2cbe9Sxc #define	IEEE80211_BADPRIVACY	0x04
2670ba2cbe9Sxc #define	IEEE80211_BADRATE	0x08
2680ba2cbe9Sxc #define	IEEE80211_BADESSID	0x10
2690ba2cbe9Sxc #define	IEEE80211_BADBSSID	0x20
2700ba2cbe9Sxc #define	IEEE80211_NODEFAIL	0x40
2710ba2cbe9Sxc 
2720ba2cbe9Sxc typedef struct ieee80211_impl {
2730ba2cbe9Sxc 	struct ieee80211com	*ic;
2740ba2cbe9Sxc 	uint8_t			im_chan_avail[IEEE80211_CHAN_BYTES];
2750ba2cbe9Sxc 	uint8_t			im_chan_scan[IEEE80211_CHAN_BYTES];
2760ba2cbe9Sxc 
2770ba2cbe9Sxc 	uint8_t			im_bmiss_count;	/* current beacon miss count */
2780ba2cbe9Sxc 	int32_t			im_bmiss_max;	/* max bmiss before scan */
2790ba2cbe9Sxc 	timeout_id_t		im_swbmiss;
2800ba2cbe9Sxc 	uint16_t		im_swbmiss_count; /* beacons in last period */
2810ba2cbe9Sxc 	uint16_t		im_swbmiss_period;	/* s/w bmiss period */
2820ba2cbe9Sxc 
2830ba2cbe9Sxc 	int32_t			im_mgt_timer;	/* mgmt timeout, secs */
2840ba2cbe9Sxc 	int32_t			im_inact_timer;	/* inactivity timer wait, sec */
2850ba2cbe9Sxc 	int32_t			im_inact_init;	/* initial setting */
2860ba2cbe9Sxc 	int32_t			im_inact_assoc;	/* assoc but not authorized */
2870ba2cbe9Sxc 	int32_t			im_inact_run;	/* authorized setting */
2880ba2cbe9Sxc 	int32_t			im_inact_probe;	/* inactive probe time */
2890ba2cbe9Sxc 
2900ba2cbe9Sxc 	kcondvar_t		im_scan_cv;	/* wait scan complete */
2910ba2cbe9Sxc } ieee80211_impl_t;
2920ba2cbe9Sxc 
2930ba2cbe9Sxc /*
2940ba2cbe9Sxc  * Parameters supplied when adding/updating an entry in a
2950ba2cbe9Sxc  * scan cache.  Pointer variables should be set to NULL
2960ba2cbe9Sxc  * if no data is available.  Pointer references can be to
2970ba2cbe9Sxc  * local data; any information that is saved will be copied.
2980ba2cbe9Sxc  * All multi-byte values must be in host byte order.
2990ba2cbe9Sxc  */
3000ba2cbe9Sxc struct ieee80211_scanparams {
3010ba2cbe9Sxc 	uint16_t		capinfo;	/* 802.11 capabilities */
3020ba2cbe9Sxc 	enum ieee80211_phytype	phytype;
3030ba2cbe9Sxc 	uint16_t		fhdwell;	/* FHSS dwell interval */
3040ba2cbe9Sxc 	uint8_t			chan;
3050ba2cbe9Sxc 	uint8_t			bchan;
3060ba2cbe9Sxc 	uint8_t			fhindex;
3070ba2cbe9Sxc 	uint8_t			erp;
3080ba2cbe9Sxc 	uint16_t		bintval;
3090ba2cbe9Sxc 	uint8_t			timoff;
3100ba2cbe9Sxc 	uint8_t			*tim;
3110ba2cbe9Sxc 	uint8_t			*tstamp;
3120ba2cbe9Sxc 	uint8_t			*country;
3130ba2cbe9Sxc 	uint8_t			*ssid;
3140ba2cbe9Sxc 	uint8_t			*rates;
3150ba2cbe9Sxc 	uint8_t			*xrates;
3160ba2cbe9Sxc 	uint8_t			*wpa;
3170ba2cbe9Sxc 	uint8_t			*wme;
318*e2cf88acSQuaker Fang 	uint8_t			*htcap;
319*e2cf88acSQuaker Fang 	uint8_t			*htinfo;
3200ba2cbe9Sxc };
3210ba2cbe9Sxc 
3220ba2cbe9Sxc #define	IEEE80211_SEND_MGMT(_ic, _in, _type, _arg)			\
3230ba2cbe9Sxc 	((*(_ic)->ic_send_mgmt)((_ic), (_in), (_type), (_arg)))
3240ba2cbe9Sxc 
3250ba2cbe9Sxc /* Verify the existence and length of __elem or get out. */
3260ba2cbe9Sxc #define	IEEE80211_VERIFY_ELEMENT(__elem, __maxlen, __func) do {		\
3270ba2cbe9Sxc 	_NOTE(CONSTCOND)						\
3280ba2cbe9Sxc 	if ((__elem) == NULL) {						\
3290ba2cbe9Sxc 		ieee80211_err("ieee80211: no #__elem \n");		\
3300ba2cbe9Sxc 		__func;							\
3310ba2cbe9Sxc 	}								\
3320ba2cbe9Sxc 	if ((__elem)[1] > (__maxlen)) {					\
3330ba2cbe9Sxc 		ieee80211_err("ieee80211: bad "#__elem " len %d\n",	\
3340ba2cbe9Sxc 		    (__elem)[1]);					\
3350ba2cbe9Sxc 		__func;							\
3360ba2cbe9Sxc 	}								\
3370ba2cbe9Sxc 	_NOTE(CONSTCOND)						\
3380ba2cbe9Sxc } while (0)
3390ba2cbe9Sxc 
3400ba2cbe9Sxc #define	IEEE80211_VERIFY_LENGTH(_len, _minlen, _func) do {		\
3410ba2cbe9Sxc 	_NOTE(CONSTCOND)						\
3420ba2cbe9Sxc 	if ((_len) < (_minlen)) {					\
3430ba2cbe9Sxc 		ieee80211_dbg(IEEE80211_MSG_ELEMID,			\
3440ba2cbe9Sxc 		    "ie of type %s too short",				\
3450ba2cbe9Sxc 		    ieee80211_mgt_subtype_name[subtype >>		\
3460ba2cbe9Sxc 			IEEE80211_FC0_SUBTYPE_SHIFT]);			\
3470ba2cbe9Sxc 		_func;							\
3480ba2cbe9Sxc 	}								\
3490ba2cbe9Sxc 	_NOTE(CONSTCOND)						\
3500ba2cbe9Sxc } while (0)
3510ba2cbe9Sxc 
3520ba2cbe9Sxc #define	IEEE80211_VERIFY_SSID(_in, _ssid, _func) do {			\
3530ba2cbe9Sxc 	_NOTE(CONSTCOND)						\
3540ba2cbe9Sxc 	ASSERT((_in) != NULL);						\
3550ba2cbe9Sxc 	if ((_ssid)[1] != 0 &&						\
3560ba2cbe9Sxc 	    ((_ssid)[1] != (_in)->in_esslen ||				\
3570ba2cbe9Sxc 	    bcmp((_ssid) + 2, (_in)->in_essid, (_ssid)[1]) != 0)) {	\
3580ba2cbe9Sxc 		_func;							\
3590ba2cbe9Sxc 	}								\
3600ba2cbe9Sxc 	_NOTE(CONSTCOND)						\
3610ba2cbe9Sxc } while (0)
3620ba2cbe9Sxc 
3630ba2cbe9Sxc #define	ieee80211_setbit(a, i)	((a)[(i)/NBBY] |= (1 << ((i)%NBBY)))
3640ba2cbe9Sxc #define	ieee80211_clrbit(a, i)	((a)[(i)/NBBY] &= ~(1 << ((i)%NBBY)))
3650ba2cbe9Sxc #define	ieee80211_isset(a, i)	((a)[(i)/NBBY] & (1 << ((i)%NBBY)))
3660ba2cbe9Sxc #define	ieee80211_isclr(a, i)	(!((a)[(i)/NBBY] & (1 << ((i)%NBBY))))
3670ba2cbe9Sxc 
3680ba2cbe9Sxc #define	IEEE80211_N(a)		(sizeof (a) / sizeof (a[0]))
3690ba2cbe9Sxc 
3700ba2cbe9Sxc #define	IEEE80211_LOCK(_ic)		\
3710ba2cbe9Sxc 	mutex_enter(&(_ic)->ic_genlock)
3720ba2cbe9Sxc #define	IEEE80211_UNLOCK(_ic)		\
3730ba2cbe9Sxc 	mutex_exit(&(_ic)->ic_genlock)
3740ba2cbe9Sxc #define	IEEE80211_IS_LOCKED(_ic)	\
3750ba2cbe9Sxc 	mutex_owned(&(_ic)->ic_genlock)
3760ba2cbe9Sxc #define	IEEE80211_LOCK_ASSERT(_ic)	\
3770ba2cbe9Sxc 	ASSERT(mutex_owned(&(_ic)->ic_genlock))
3780ba2cbe9Sxc 
3790ba2cbe9Sxc #define	IEEE80211_NODE_LOCK(_nt)		\
3800ba2cbe9Sxc 	mutex_enter(&(_nt)->nt_nodelock)
3810ba2cbe9Sxc #define	IEEE80211_NODE_UNLOCK(_nt)		\
3820ba2cbe9Sxc 	mutex_exit(&(_nt)->nt_nodelock)
3830ba2cbe9Sxc #define	IEEE80211_NODE_IS_LOCKED(_nt)		\
3840ba2cbe9Sxc 	mutex_owned(&(_nt)->nt_nodelock)
3850ba2cbe9Sxc #define	IEEE80211_NODE_LOCK_ASSERT(_nt)		\
3860ba2cbe9Sxc 	ASSERT(mutex_owned(&(_nt)->nt_nodelock))
3870ba2cbe9Sxc #define	ieee80211_node_hash(addr)		\
3880ba2cbe9Sxc 	(((uint8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % IEEE80211_NODE_HASHSIZE)
3890ba2cbe9Sxc 
3900ba2cbe9Sxc #define	IEEE80211_SCAN_LOCK(_nt)	mutex_enter(&(_nt)->nt_scanlock)
3910ba2cbe9Sxc #define	IEEE80211_SCAN_UNLOCK(_nt)	mutex_exit(&(_nt)->nt_scanlock)
3920ba2cbe9Sxc 
3930ba2cbe9Sxc #define	IEEE80211_RV(v)			((v) & IEEE80211_RATE_VAL)
3940ba2cbe9Sxc 
3950ba2cbe9Sxc #define	IEEE80211_SUBTYPE_NAME(subtype)		\
3960ba2cbe9Sxc 	ieee80211_mgt_subtype_name[(subtype) >> IEEE80211_FC0_SUBTYPE_SHIFT]
3970ba2cbe9Sxc 
3980ba2cbe9Sxc extern const char *ieee80211_mgt_subtype_name[];
3990ba2cbe9Sxc extern const char *ieee80211_phymode_name[];
4000ba2cbe9Sxc 
4010ba2cbe9Sxc void ieee80211_err(const int8_t *, ...);
4020ba2cbe9Sxc void ieee80211_dbg(uint32_t, const int8_t *, ...);
4030ba2cbe9Sxc 
404a399b765Szf void ieee80211_notify(ieee80211com_t *, wpa_event_type);
405a399b765Szf void ieee80211_mac_update(ieee80211com_t *);
406a399b765Szf 
407a399b765Szf uint64_t ieee80211_read_6(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t);
408a399b765Szf 
4090ba2cbe9Sxc /* node */
4100ba2cbe9Sxc void ieee80211_node_attach(ieee80211com_t *);
4110ba2cbe9Sxc void ieee80211_node_lateattach(ieee80211com_t *);
4120ba2cbe9Sxc void ieee80211_node_detach(ieee80211com_t *);
4130ba2cbe9Sxc void ieee80211_reset_bss(ieee80211com_t *);
4140ba2cbe9Sxc void ieee80211_cancel_scan(ieee80211com_t *);
4150ba2cbe9Sxc void ieee80211_add_scan(ieee80211com_t *, const struct ieee80211_scanparams *,
4160ba2cbe9Sxc     const struct ieee80211_frame *, int, int, int);
4170ba2cbe9Sxc void ieee80211_init_neighbor(ieee80211_node_t *, const struct ieee80211_frame *,
4180ba2cbe9Sxc     const struct ieee80211_scanparams *);
4190ba2cbe9Sxc ieee80211_node_t *ieee80211_add_neighbor(ieee80211com_t *,
4200ba2cbe9Sxc     const struct ieee80211_frame *, const struct ieee80211_scanparams *);
4210ba2cbe9Sxc void ieee80211_create_ibss(ieee80211com_t *, struct ieee80211_channel *);
4220ba2cbe9Sxc ieee80211_node_t *ieee80211_fakeup_adhoc_node(ieee80211_node_table_t *,
4230ba2cbe9Sxc     const uint8_t *);
4240ba2cbe9Sxc ieee80211_node_t *ieee80211_tmp_node(ieee80211com_t *, const uint8_t *);
425*e2cf88acSQuaker Fang void ieee80211_setcurchan(ieee80211com_t *, struct ieee80211_channel *);
4260ba2cbe9Sxc 
4270ba2cbe9Sxc /* proto */
4280ba2cbe9Sxc void ieee80211_proto_attach(ieee80211com_t *);
429*e2cf88acSQuaker Fang int ieee80211_fix_rate(ieee80211_node_t *, struct ieee80211_rateset *, int);
4300ba2cbe9Sxc void ieee80211_setbasicrates(struct ieee80211_rateset *,
4310ba2cbe9Sxc     enum ieee80211_phymode);
4320ba2cbe9Sxc void ieee80211_reset_erp(ieee80211com_t *);
4330ba2cbe9Sxc void ieee80211_set_shortslottime(ieee80211com_t *, boolean_t);
4340ba2cbe9Sxc 
4350ba2cbe9Sxc /* input */
4360ba2cbe9Sxc int ieee80211_setup_rates(ieee80211_node_t *, const uint8_t *,
4370ba2cbe9Sxc     const uint8_t *, int);
4380ba2cbe9Sxc void ieee80211_recv_mgmt(ieee80211com_t *, mblk_t *, ieee80211_node_t *,
4390ba2cbe9Sxc     int, int, uint32_t);
4400ba2cbe9Sxc 
4410ba2cbe9Sxc /* output */
4420ba2cbe9Sxc int ieee80211_send_probereq(ieee80211_node_t *, const uint8_t *,
4430ba2cbe9Sxc     const uint8_t *, const uint8_t *, const uint8_t *, size_t, const void *,
4440ba2cbe9Sxc     size_t);
4450ba2cbe9Sxc int ieee80211_send_mgmt(ieee80211com_t *, ieee80211_node_t *, int, int);
4460ba2cbe9Sxc int ieee80211_send_nulldata(ieee80211_node_t *);
447*e2cf88acSQuaker Fang int ieee80211_mgmt_output(ieee80211com_t *, ieee80211_node_t *, mblk_t *,
448*e2cf88acSQuaker Fang     int, int);
4490ba2cbe9Sxc 
4500ba2cbe9Sxc /* crypto */
4510ba2cbe9Sxc struct ieee80211_key *ieee80211_crypto_getkey(ieee80211com_t *);
4520ba2cbe9Sxc uint8_t ieee80211_crypto_getciphertype(ieee80211com_t *);
4530ba2cbe9Sxc 
4540ba2cbe9Sxc /* generic */
4550ba2cbe9Sxc mblk_t *ieee80211_getmgtframe(uint8_t **, int);
4560ba2cbe9Sxc void ieee80211_notify_node_join(ieee80211com_t *, ieee80211_node_t *);
4570ba2cbe9Sxc void ieee80211_notify_node_leave(ieee80211com_t *, ieee80211_node_t *);
4580ba2cbe9Sxc 
459*e2cf88acSQuaker Fang /* WME */
460*e2cf88acSQuaker Fang void	ieee80211_wme_initparams(struct ieee80211com *);
461*e2cf88acSQuaker Fang void	ieee80211_wme_updateparams(struct ieee80211com *);
462*e2cf88acSQuaker Fang 
4630ba2cbe9Sxc #ifdef	__cplusplus
4640ba2cbe9Sxc }
4650ba2cbe9Sxc #endif
4660ba2cbe9Sxc 
4670ba2cbe9Sxc #endif	/* _SYS_NET80211_IMPL_H */
468