13147Sxc151355 /*
2*4126Szf162725  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
33147Sxc151355  * Use is subject to license terms.
43147Sxc151355  */
53147Sxc151355 
63147Sxc151355 /*
73147Sxc151355  * Copyright (c) 2001 Atsushi Onoe
83147Sxc151355  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
93147Sxc151355  * All rights reserved.
103147Sxc151355  *
113147Sxc151355  * Redistribution and use in source and binary forms, with or without
123147Sxc151355  * modification, are permitted provided that the following conditions
133147Sxc151355  * are met:
143147Sxc151355  * 1. Redistributions of source code must retain the above copyright
153147Sxc151355  *    notice, this list of conditions and the following disclaimer.
163147Sxc151355  * 2. Redistributions in binary form must reproduce the above copyright
173147Sxc151355  *    notice, this list of conditions and the following disclaimer in the
183147Sxc151355  *    documentation and/or other materials provided with the distribution.
193147Sxc151355  * 3. The name of the author may not be used to endorse or promote products
203147Sxc151355  *    derived from this software without specific prior written permission.
213147Sxc151355  *
223147Sxc151355  * Alternatively, this software may be distributed under the terms of the
233147Sxc151355  * GNU General Public License ("GPL") version 2 as published by the Free
243147Sxc151355  * Software Foundation.
253147Sxc151355  *
263147Sxc151355  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
273147Sxc151355  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
283147Sxc151355  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
293147Sxc151355  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
303147Sxc151355  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
313147Sxc151355  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
323147Sxc151355  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
333147Sxc151355  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
343147Sxc151355  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
353147Sxc151355  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
363147Sxc151355  */
373147Sxc151355 
383147Sxc151355 #pragma ident	"%Z%%M%	%I%	%E% SMI"
393147Sxc151355 
403147Sxc151355 #ifndef _SYS_NET80211_IMPL_H
413147Sxc151355 #define	_SYS_NET80211_IMPL_H
423147Sxc151355 
433147Sxc151355 #include <sys/sysmacros.h>
443147Sxc151355 #include <sys/list.h>
453147Sxc151355 #include <sys/note.h>
463147Sxc151355 #include <sys/net80211_proto.h>
473147Sxc151355 #include <sys/net80211.h>
483147Sxc151355 #include <sys/mac_wifi.h>
493147Sxc151355 
503147Sxc151355 /*
513147Sxc151355  * IEEE802.11 kernel support module
523147Sxc151355  */
533147Sxc151355 
543147Sxc151355 #ifdef	__cplusplus
553147Sxc151355 extern "C" {
563147Sxc151355 #endif
573147Sxc151355 
583147Sxc151355 #define	IEEE80211_TXPOWER_MAX	100	/* .5 dbM */
593147Sxc151355 #define	IEEE80211_TXPOWER_MIN	0	/* kill radio */
603147Sxc151355 
613147Sxc151355 #define	IEEE80211_DTIM_MAX	15	/* max DTIM period */
623147Sxc151355 #define	IEEE80211_DTIM_MIN	1	/* min DTIM period */
633147Sxc151355 #define	IEEE80211_DTIM_DEFAULT	1	/* default DTIM period */
643147Sxc151355 
653147Sxc151355 /* NB: min+max come from WiFi requirements */
663147Sxc151355 #define	IEEE80211_BINTVAL_MAX	1000	/* max beacon interval (TU's) */
673147Sxc151355 #define	IEEE80211_BINTVAL_MIN	25	/* min beacon interval (TU's) */
683147Sxc151355 #define	IEEE80211_BINTVAL_DEFAULT 100	/* default beacon interval (TU's) */
693147Sxc151355 
703147Sxc151355 #define	IEEE80211_BMISS_MAX	2	/* maximum consecutive bmiss allowed */
713147Sxc151355 #define	IEEE80211_SWBMISS_THRESHOLD 50	/* s/w bmiss threshold (TU's) */
723147Sxc151355 #define	IEEE80211_HWBMISS_DEFAULT 7	/* h/w bmiss threshold (beacons) */
733147Sxc151355 
743147Sxc151355 #define	IEEE80211_PS_SLEEP	0x1	/* STA is in power saving mode */
753147Sxc151355 #define	IEEE80211_PS_MAX_QUEUE	50	/* maximum saved packets */
763147Sxc151355 
773147Sxc151355 #define	IEEE80211_RTS_DEFAULT	IEEE80211_RTS_MAX
783147Sxc151355 #define	IEEE80211_FRAG_DEFAULT	IEEE80211_FRAG_MAX
793147Sxc151355 
803147Sxc151355 /*
813147Sxc151355  * The RSSI values of two node are taken as almost the same when
823147Sxc151355  * the difference between these two node's RSSI values is within
833147Sxc151355  * IEEE80211_RSSI_CMP_THRESHOLD
843147Sxc151355  */
853147Sxc151355 #define	IEEE80211_RSSI_CMP_THRESHOLD	5
863147Sxc151355 
873147Sxc151355 /*
883147Sxc151355  * Each ieee80211com instance has a single timer that fires once a
893147Sxc151355  * second.  This is used to initiate various work depending on the
903147Sxc151355  * state of the instance: scanning (passive or active), ``transition''
913147Sxc151355  * (waiting for a response to a management frame when operating
923147Sxc151355  * as a station), and node inactivity processing (when operating
933147Sxc151355  * as an AP).  For inactivity processing each node has a timeout
943147Sxc151355  * set in it's in_inact field that is decremented on each timeout
953147Sxc151355  * and the node is reclaimed when the counter goes to zero.  We
963147Sxc151355  * use different inactivity timeout values depending on whether
973147Sxc151355  * the node is associated and authorized (either by 802.1x or
983147Sxc151355  * open/shared key authentication) or associated but yet to be
993147Sxc151355  * authorized.  The latter timeout is shorter to more aggressively
1003147Sxc151355  * reclaim nodes that leave part way through the 802.1x exchange.
1013147Sxc151355  *
1023147Sxc151355  * IEEE80211_INACT_WAIT defines node table's inactivity interval in
1033147Sxc151355  * seconds. On timeout, node table's registered nt_timeout callback
1043147Sxc151355  * function is executed. Each node in the node table has a timeout
1053147Sxc151355  * set in its in_inact field with IEEE80211_INACT_<state>. In
1063147Sxc151355  * nt_timeout function, node table is iterated and each node's
1073147Sxc151355  * in_inact is decremented. So IEEE80211_INACT_<state> is defined in
1083147Sxc151355  * the form [inact_sec]/IEEE80211_INACT_WAIT.
1093147Sxc151355  *
1103147Sxc151355  */
1113147Sxc151355 #define	IEEE80211_INACT_WAIT	15	/* inactivity interval (secs) */
1123147Sxc151355 #define	IEEE80211_INACT_INIT	(30/IEEE80211_INACT_WAIT)	/* initial */
1133147Sxc151355 #define	IEEE80211_INACT_ASSOC	(180/IEEE80211_INACT_WAIT)
1143147Sxc151355 					/* associated but not authorized */
1153147Sxc151355 #define	IEEE80211_INACT_RUN	(300/IEEE80211_INACT_WAIT)	/* authorized */
1163147Sxc151355 #define	IEEE80211_INACT_PROBE	(30/IEEE80211_INACT_WAIT)	/* probe */
1173147Sxc151355 #define	IEEE80211_INACT_SCAN	(300/IEEE80211_INACT_WAIT)	/* scanned */
1183147Sxc151355 
1193147Sxc151355 #define	IEEE80211_TRANS_WAIT 	5	/* mgt frame tx timer (secs) */
1203147Sxc151355 
1213147Sxc151355 /*
1223147Sxc151355  * Useful combinations of channel characteristics.
1233147Sxc151355  */
1243147Sxc151355 #define	IEEE80211_CHAN_FHSS	\
1253147Sxc151355 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK)
1263147Sxc151355 #define	IEEE80211_CHAN_A	\
1273147Sxc151355 	(IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
1283147Sxc151355 #define	IEEE80211_CHAN_B	\
1293147Sxc151355 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
1303147Sxc151355 #define	IEEE80211_CHAN_PUREG	\
1313147Sxc151355 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM)
1323147Sxc151355 #define	IEEE80211_CHAN_G	\
1333147Sxc151355 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
1343147Sxc151355 #define	IEEE80211_CHAN_T	\
1353147Sxc151355 	(IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
1363147Sxc151355 #define	IEEE80211_CHAN_108G	\
1373147Sxc151355 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
1383147Sxc151355 
1393147Sxc151355 #define	IEEE80211_CHAN_ALL	\
1403147Sxc151355 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_GFSK | \
1413147Sxc151355 	IEEE80211_CHAN_CCK | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_DYN)
1423147Sxc151355 #define	IEEE80211_CHAN_ALLTURBO	\
1433147Sxc151355 	(IEEE80211_CHAN_ALL | IEEE80211_CHAN_TURBO)
1443147Sxc151355 
1453147Sxc151355 #define	IEEE80211_IS_CHAN_FHSS(_c)	\
1463147Sxc151355 	(((_c)->ich_flags & IEEE80211_CHAN_FHSS) == IEEE80211_CHAN_FHSS)
1473147Sxc151355 #define	IEEE80211_IS_CHAN_A(_c)		\
1483147Sxc151355 	(((_c)->ich_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A)
1493147Sxc151355 #define	IEEE80211_IS_CHAN_B(_c)		\
1503147Sxc151355 	(((_c)->ich_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B)
1513147Sxc151355 #define	IEEE80211_IS_CHAN_PUREG(_c)	\
1523147Sxc151355 	(((_c)->ich_flags & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG)
1533147Sxc151355 #define	IEEE80211_IS_CHAN_G(_c)		\
1543147Sxc151355 	(((_c)->ich_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G)
1553147Sxc151355 #define	IEEE80211_IS_CHAN_ANYG(_c)	\
1563147Sxc151355 	(IEEE80211_IS_CHAN_PUREG(_c) || IEEE80211_IS_CHAN_G(_c))
1573147Sxc151355 #define	IEEE80211_IS_CHAN_T(_c)		\
1583147Sxc151355 	(((_c)->ich_flags & IEEE80211_CHAN_T) == IEEE80211_CHAN_T)
1593147Sxc151355 #define	IEEE80211_IS_CHAN_108G(_c)	\
1603147Sxc151355 	(((_c)->ich_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G)
1613147Sxc151355 
1623147Sxc151355 #define	IEEE80211_IS_CHAN_OFDM(_c)	\
1633147Sxc151355 	((_c)->ich_flags & IEEE80211_CHAN_OFDM)
1643147Sxc151355 #define	IEEE80211_IS_CHAN_CCK(_c)	\
1653147Sxc151355 	((_c)->ich_flags & IEEE80211_CHAN_CCK)
1663147Sxc151355 #define	IEEE80211_IS_CHAN_GFSK(_c)	\
1673147Sxc151355 	((_c)->ich_flags & IEEE80211_CHAN_GFSK)
1683147Sxc151355 #define	IEEE80211_IS_CHAN_PASSIVE(_c)	\
1693147Sxc151355 	((_c)->ich_flags & IEEE80211_CHAN_PASSIVE)
1703147Sxc151355 
1713147Sxc151355 /* ni_chan encoding for FH phy */
1723147Sxc151355 #define	IEEE80211_FH_CHANMOD	80
1733147Sxc151355 #define	IEEE80211_FH_CHAN(set, pat)	\
1743147Sxc151355 	(((set) - 1) * IEEE80211_FH_CHANMOD + (pat))
1753147Sxc151355 #define	IEEE80211_FH_CHANSET(chan)	\
1763147Sxc151355 	((chan) / IEEE80211_FH_CHANMOD + 1)
1773147Sxc151355 #define	IEEE80211_FH_CHANPAT(chan)	\
1783147Sxc151355 	((chan) % IEEE80211_FH_CHANMOD)
1793147Sxc151355 
1803147Sxc151355 #define	IEEE80211_NODE_AUTH	0x0001		/* authorized for data */
1813147Sxc151355 #define	IEEE80211_NODE_QOS	0x0002		/* QoS enabled */
1823147Sxc151355 #define	IEEE80211_NODE_ERP	0x0004		/* ERP enabled */
1833147Sxc151355 #define	IEEE80211_NODE_PWR_MGT	0x0010		/* power save mode enabled */
1843147Sxc151355 #define	IEEE80211_NODE_AREF	0x0020		/* authentication ref held */
1853147Sxc151355 
1863147Sxc151355 #define	IEEE80211_MAXRSSI	127
1873147Sxc151355 
1883147Sxc151355 /* Debug Flags */
1893147Sxc151355 #define	IEEE80211_MSG_DEBUG	0x40000000	/* IFF_DEBUG equivalent */
1903147Sxc151355 #define	IEEE80211_MSG_DUMPPKTS	0x20000000	/* IFF_LINK2 equivalant */
1913147Sxc151355 #define	IEEE80211_MSG_CRYPTO	0x10000000	/* crypto work */
1923147Sxc151355 #define	IEEE80211_MSG_INPUT	0x08000000	/* input handling */
1933147Sxc151355 #define	IEEE80211_MSG_XRATE	0x04000000	/* rate set handling */
1943147Sxc151355 #define	IEEE80211_MSG_ELEMID	0x02000000	/* element id parsing */
1953147Sxc151355 #define	IEEE80211_MSG_NODE	0x01000000	/* node handling */
1963147Sxc151355 #define	IEEE80211_MSG_ASSOC	0x00800000	/* association handling */
1973147Sxc151355 #define	IEEE80211_MSG_AUTH	0x00400000	/* authentication handling */
1983147Sxc151355 #define	IEEE80211_MSG_SCAN	0x00200000	/* scanning */
1993147Sxc151355 #define	IEEE80211_MSG_OUTPUT	0x00100000	/* output handling */
2003147Sxc151355 #define	IEEE80211_MSG_STATE	0x00080000	/* state machine */
2013147Sxc151355 #define	IEEE80211_MSG_POWER	0x00040000	/* power save handling */
2023147Sxc151355 #define	IEEE80211_MSG_DOT1X	0x00020000	/* 802.1x authenticator */
2033147Sxc151355 #define	IEEE80211_MSG_DOT1XSM	0x00010000	/* 802.1x state machine */
2043147Sxc151355 #define	IEEE80211_MSG_RADIUS	0x00008000	/* 802.1x radius client */
2053147Sxc151355 #define	IEEE80211_MSG_RADDUMP	0x00004000	/* dump 802.1x radius packets */
2063147Sxc151355 #define	IEEE80211_MSG_RADKEYS	0x00002000	/* dump 802.1x keys */
2073147Sxc151355 #define	IEEE80211_MSG_WPA	0x00001000	/* WPA/RSN protocol */
2083147Sxc151355 #define	IEEE80211_MSG_ACL	0x00000800	/* ACL handling */
2093147Sxc151355 #define	IEEE80211_MSG_WME	0x00000400	/* WME protocol */
2103147Sxc151355 #define	IEEE80211_MSG_SUPERG	0x00000200	/* Atheros SuperG protocol */
2113147Sxc151355 #define	IEEE80211_MSG_DOTH	0x00000100	/* 802.11h support */
2123147Sxc151355 #define	IEEE80211_MSG_INACT	0x00000080	/* inactivity handling */
2133147Sxc151355 #define	IEEE80211_MSG_ROAM	0x00000040	/* sta-mode roaming */
2143147Sxc151355 #define	IEEE80211_MSG_CONFIG	0x00000020	/* wificonfig/dladm */
2153147Sxc151355 #define	IEEE80211_MSG_ANY	0xffffffff	/* anything */
2163147Sxc151355 
2173147Sxc151355 /* Error flags returned by ieee80211_match_bss */
2183147Sxc151355 #define	IEEE80211_BADCHAN	0x01
2193147Sxc151355 #define	IEEE80211_BADOPMODE	0x02
2203147Sxc151355 #define	IEEE80211_BADPRIVACY	0x04
2213147Sxc151355 #define	IEEE80211_BADRATE	0x08
2223147Sxc151355 #define	IEEE80211_BADESSID	0x10
2233147Sxc151355 #define	IEEE80211_BADBSSID	0x20
2243147Sxc151355 #define	IEEE80211_NODEFAIL	0x40
2253147Sxc151355 
2263147Sxc151355 typedef struct ieee80211_impl {
2273147Sxc151355 	struct ieee80211com	*ic;
2283147Sxc151355 	uint8_t			im_chan_avail[IEEE80211_CHAN_BYTES];
2293147Sxc151355 	uint8_t			im_chan_scan[IEEE80211_CHAN_BYTES];
2303147Sxc151355 
2313147Sxc151355 	uint8_t			im_bmiss_count;	/* current beacon miss count */
2323147Sxc151355 	int32_t			im_bmiss_max;	/* max bmiss before scan */
2333147Sxc151355 	timeout_id_t		im_swbmiss;
2343147Sxc151355 	uint16_t		im_swbmiss_count; /* beacons in last period */
2353147Sxc151355 	uint16_t		im_swbmiss_period;	/* s/w bmiss period */
2363147Sxc151355 
2373147Sxc151355 	int32_t			im_mgt_timer;	/* mgmt timeout, secs */
2383147Sxc151355 	int32_t			im_inact_timer;	/* inactivity timer wait, sec */
2393147Sxc151355 	int32_t			im_inact_init;	/* initial setting */
2403147Sxc151355 	int32_t			im_inact_assoc;	/* assoc but not authorized */
2413147Sxc151355 	int32_t			im_inact_run;	/* authorized setting */
2423147Sxc151355 	int32_t			im_inact_probe;	/* inactive probe time */
2433147Sxc151355 
2443147Sxc151355 	kcondvar_t		im_scan_cv;	/* wait scan complete */
2453147Sxc151355 } ieee80211_impl_t;
2463147Sxc151355 
2473147Sxc151355 /*
2483147Sxc151355  * Parameters supplied when adding/updating an entry in a
2493147Sxc151355  * scan cache.  Pointer variables should be set to NULL
2503147Sxc151355  * if no data is available.  Pointer references can be to
2513147Sxc151355  * local data; any information that is saved will be copied.
2523147Sxc151355  * All multi-byte values must be in host byte order.
2533147Sxc151355  */
2543147Sxc151355 struct ieee80211_scanparams {
2553147Sxc151355 	uint16_t		capinfo;	/* 802.11 capabilities */
2563147Sxc151355 	enum ieee80211_phytype	phytype;
2573147Sxc151355 	uint16_t		fhdwell;	/* FHSS dwell interval */
2583147Sxc151355 	uint8_t			chan;
2593147Sxc151355 	uint8_t			bchan;
2603147Sxc151355 	uint8_t			fhindex;
2613147Sxc151355 	uint8_t			erp;
2623147Sxc151355 	uint16_t		bintval;
2633147Sxc151355 	uint8_t			timoff;
2643147Sxc151355 	uint8_t			*tim;
2653147Sxc151355 	uint8_t			*tstamp;
2663147Sxc151355 	uint8_t			*country;
2673147Sxc151355 	uint8_t			*ssid;
2683147Sxc151355 	uint8_t			*rates;
2693147Sxc151355 	uint8_t			*xrates;
2703147Sxc151355 	uint8_t			*wpa;
2713147Sxc151355 	uint8_t			*wme;
2723147Sxc151355 };
2733147Sxc151355 
2743147Sxc151355 #define	IEEE80211_SEND_MGMT(_ic, _in, _type, _arg)			\
2753147Sxc151355 	((*(_ic)->ic_send_mgmt)((_ic), (_in), (_type), (_arg)))
2763147Sxc151355 
2773147Sxc151355 /* Verify the existence and length of __elem or get out. */
2783147Sxc151355 #define	IEEE80211_VERIFY_ELEMENT(__elem, __maxlen, __func) do {		\
2793147Sxc151355 	_NOTE(CONSTCOND)						\
2803147Sxc151355 	if ((__elem) == NULL) {						\
2813147Sxc151355 		ieee80211_err("ieee80211: no #__elem \n");		\
2823147Sxc151355 		__func;							\
2833147Sxc151355 	}								\
2843147Sxc151355 	if ((__elem)[1] > (__maxlen)) {					\
2853147Sxc151355 		ieee80211_err("ieee80211: bad "#__elem " len %d\n",	\
2863147Sxc151355 		    (__elem)[1]);					\
2873147Sxc151355 		__func;							\
2883147Sxc151355 	}								\
2893147Sxc151355 	_NOTE(CONSTCOND)						\
2903147Sxc151355 } while (0)
2913147Sxc151355 
2923147Sxc151355 #define	IEEE80211_VERIFY_LENGTH(_len, _minlen, _func) do {		\
2933147Sxc151355 	_NOTE(CONSTCOND)						\
2943147Sxc151355 	if ((_len) < (_minlen)) {					\
2953147Sxc151355 		ieee80211_dbg(IEEE80211_MSG_ELEMID,			\
2963147Sxc151355 		    "ie of type %s too short",				\
2973147Sxc151355 		    ieee80211_mgt_subtype_name[subtype >>		\
2983147Sxc151355 			IEEE80211_FC0_SUBTYPE_SHIFT]);			\
2993147Sxc151355 		_func;							\
3003147Sxc151355 	}								\
3013147Sxc151355 	_NOTE(CONSTCOND)						\
3023147Sxc151355 } while (0)
3033147Sxc151355 
3043147Sxc151355 #define	IEEE80211_VERIFY_SSID(_in, _ssid, _func) do {			\
3053147Sxc151355 	_NOTE(CONSTCOND)						\
3063147Sxc151355 	ASSERT((_in) != NULL);						\
3073147Sxc151355 	if ((_ssid)[1] != 0 &&						\
3083147Sxc151355 	    ((_ssid)[1] != (_in)->in_esslen ||				\
3093147Sxc151355 	    bcmp((_ssid) + 2, (_in)->in_essid, (_ssid)[1]) != 0)) {	\
3103147Sxc151355 		_func;							\
3113147Sxc151355 	}								\
3123147Sxc151355 	_NOTE(CONSTCOND)						\
3133147Sxc151355 } while (0)
3143147Sxc151355 
3153147Sxc151355 #define	ieee80211_setbit(a, i)	((a)[(i)/NBBY] |= (1 << ((i)%NBBY)))
3163147Sxc151355 #define	ieee80211_clrbit(a, i)	((a)[(i)/NBBY] &= ~(1 << ((i)%NBBY)))
3173147Sxc151355 #define	ieee80211_isset(a, i)	((a)[(i)/NBBY] & (1 << ((i)%NBBY)))
3183147Sxc151355 #define	ieee80211_isclr(a, i)	(!((a)[(i)/NBBY] & (1 << ((i)%NBBY))))
3193147Sxc151355 
3203147Sxc151355 #define	IEEE80211_N(a)		(sizeof (a) / sizeof (a[0]))
3213147Sxc151355 
3223147Sxc151355 #define	IEEE80211_LOCK(_ic)		\
3233147Sxc151355 	mutex_enter(&(_ic)->ic_genlock)
3243147Sxc151355 #define	IEEE80211_UNLOCK(_ic)		\
3253147Sxc151355 	mutex_exit(&(_ic)->ic_genlock)
3263147Sxc151355 #define	IEEE80211_IS_LOCKED(_ic)	\
3273147Sxc151355 	mutex_owned(&(_ic)->ic_genlock)
3283147Sxc151355 #define	IEEE80211_LOCK_ASSERT(_ic)	\
3293147Sxc151355 	ASSERT(mutex_owned(&(_ic)->ic_genlock))
3303147Sxc151355 
3313147Sxc151355 #define	IEEE80211_NODE_LOCK(_nt)		\
3323147Sxc151355 	mutex_enter(&(_nt)->nt_nodelock)
3333147Sxc151355 #define	IEEE80211_NODE_UNLOCK(_nt)		\
3343147Sxc151355 	mutex_exit(&(_nt)->nt_nodelock)
3353147Sxc151355 #define	IEEE80211_NODE_IS_LOCKED(_nt)		\
3363147Sxc151355 	mutex_owned(&(_nt)->nt_nodelock)
3373147Sxc151355 #define	IEEE80211_NODE_LOCK_ASSERT(_nt)		\
3383147Sxc151355 	ASSERT(mutex_owned(&(_nt)->nt_nodelock))
3393147Sxc151355 #define	ieee80211_node_hash(addr)		\
3403147Sxc151355 	(((uint8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % IEEE80211_NODE_HASHSIZE)
3413147Sxc151355 
3423147Sxc151355 #define	IEEE80211_SCAN_LOCK(_nt)	mutex_enter(&(_nt)->nt_scanlock)
3433147Sxc151355 #define	IEEE80211_SCAN_UNLOCK(_nt)	mutex_exit(&(_nt)->nt_scanlock)
3443147Sxc151355 
3453147Sxc151355 #define	IEEE80211_RV(v)			((v) & IEEE80211_RATE_VAL)
3463147Sxc151355 
3473147Sxc151355 #define	IEEE80211_SUBTYPE_NAME(subtype)		\
3483147Sxc151355 	ieee80211_mgt_subtype_name[(subtype) >> IEEE80211_FC0_SUBTYPE_SHIFT]
3493147Sxc151355 
3503147Sxc151355 extern const char *ieee80211_mgt_subtype_name[];
3513147Sxc151355 extern const char *ieee80211_phymode_name[];
3523147Sxc151355 
3533147Sxc151355 void ieee80211_err(const int8_t *, ...);
3543147Sxc151355 void ieee80211_dbg(uint32_t, const int8_t *, ...);
3553147Sxc151355 int ieee80211_hdrspace(const void *);
3563147Sxc151355 
357*4126Szf162725 void ieee80211_notify(ieee80211com_t *, wpa_event_type);
358*4126Szf162725 void ieee80211_mac_update(ieee80211com_t *);
359*4126Szf162725 
360*4126Szf162725 uint64_t ieee80211_read_6(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t);
361*4126Szf162725 
3623147Sxc151355 /* node */
3633147Sxc151355 void ieee80211_node_attach(ieee80211com_t *);
3643147Sxc151355 void ieee80211_node_lateattach(ieee80211com_t *);
3653147Sxc151355 void ieee80211_node_detach(ieee80211com_t *);
3663147Sxc151355 void ieee80211_reset_bss(ieee80211com_t *);
3673147Sxc151355 void ieee80211_cancel_scan(ieee80211com_t *);
3683147Sxc151355 void ieee80211_add_scan(ieee80211com_t *, const struct ieee80211_scanparams *,
3693147Sxc151355     const struct ieee80211_frame *, int, int, int);
3703147Sxc151355 void ieee80211_init_neighbor(ieee80211_node_t *, const struct ieee80211_frame *,
3713147Sxc151355     const struct ieee80211_scanparams *);
3723147Sxc151355 ieee80211_node_t *ieee80211_add_neighbor(ieee80211com_t *,
3733147Sxc151355     const struct ieee80211_frame *, const struct ieee80211_scanparams *);
3743147Sxc151355 void ieee80211_create_ibss(ieee80211com_t *, struct ieee80211_channel *);
3753147Sxc151355 ieee80211_node_t *ieee80211_fakeup_adhoc_node(ieee80211_node_table_t *,
3763147Sxc151355     const uint8_t *);
3773147Sxc151355 ieee80211_node_t *ieee80211_tmp_node(ieee80211com_t *, const uint8_t *);
3783147Sxc151355 
3793147Sxc151355 /* proto */
3803147Sxc151355 void ieee80211_proto_attach(ieee80211com_t *);
3813147Sxc151355 int ieee80211_fix_rate(ieee80211_node_t *, int);
3823147Sxc151355 void ieee80211_setbasicrates(struct ieee80211_rateset *,
3833147Sxc151355     enum ieee80211_phymode);
3843147Sxc151355 void ieee80211_reset_erp(ieee80211com_t *);
3853147Sxc151355 void ieee80211_set_shortslottime(ieee80211com_t *, boolean_t);
3863147Sxc151355 
3873147Sxc151355 /* input */
3883147Sxc151355 int ieee80211_setup_rates(ieee80211_node_t *, const uint8_t *,
3893147Sxc151355     const uint8_t *, int);
3903147Sxc151355 void ieee80211_recv_mgmt(ieee80211com_t *, mblk_t *, ieee80211_node_t *,
3913147Sxc151355     int, int, uint32_t);
3923147Sxc151355 
3933147Sxc151355 /* output */
3943147Sxc151355 int ieee80211_send_probereq(ieee80211_node_t *, const uint8_t *,
3953147Sxc151355     const uint8_t *, const uint8_t *, const uint8_t *, size_t, const void *,
3963147Sxc151355     size_t);
3973147Sxc151355 int ieee80211_send_mgmt(ieee80211com_t *, ieee80211_node_t *, int, int);
3983147Sxc151355 int ieee80211_send_nulldata(ieee80211_node_t *);
3993147Sxc151355 
4003147Sxc151355 /* crypto */
4013147Sxc151355 struct ieee80211_key *ieee80211_crypto_getkey(ieee80211com_t *);
4023147Sxc151355 uint8_t ieee80211_crypto_getciphertype(ieee80211com_t *);
4033147Sxc151355 
4043147Sxc151355 /* generic */
4053147Sxc151355 mblk_t *ieee80211_getmgtframe(uint8_t **, int);
4063147Sxc151355 void ieee80211_notify_node_join(ieee80211com_t *, ieee80211_node_t *);
4073147Sxc151355 void ieee80211_notify_node_leave(ieee80211com_t *, ieee80211_node_t *);
4083147Sxc151355 
4093147Sxc151355 #ifdef	__cplusplus
4103147Sxc151355 }
4113147Sxc151355 #endif
4123147Sxc151355 
4133147Sxc151355 #endif	/* _SYS_NET80211_IMPL_H */
414