16d0f2b48SAugustin Cavalier/*
26d0f2b48SAugustin Cavalier * Copyright 2009, Colin G��nther, coling@gmx.de. All rights reserved.
36d0f2b48SAugustin Cavalier * Copyright 2018, Haiku, Inc. All rights reserved.
46d0f2b48SAugustin Cavalier * Distributed under the terms of the MIT License.
56d0f2b48SAugustin Cavalier */
63c410abaSAugustin Cavalier/*-
73c410abaSAugustin Cavalier * Copyright (c) 2003-2008 Sam Leffler, Errno Consulting
83c410abaSAugustin Cavalier * All rights reserved.
93c410abaSAugustin Cavalier *
103c410abaSAugustin Cavalier * Redistribution and use in source and binary forms, with or without
113c410abaSAugustin Cavalier * modification, are permitted provided that the following conditions
123c410abaSAugustin Cavalier * are met:
133c410abaSAugustin Cavalier * 1. Redistributions of source code must retain the above copyright
143c410abaSAugustin Cavalier *    notice, this list of conditions and the following disclaimer.
153c410abaSAugustin Cavalier * 2. Redistributions in binary form must reproduce the above copyright
163c410abaSAugustin Cavalier *    notice, this list of conditions and the following disclaimer in the
173c410abaSAugustin Cavalier *    documentation and/or other materials provided with the distribution.
183c410abaSAugustin Cavalier *
193c410abaSAugustin Cavalier * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
203c410abaSAugustin Cavalier * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
213c410abaSAugustin Cavalier * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223c410abaSAugustin Cavalier * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
233c410abaSAugustin Cavalier * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
243c410abaSAugustin Cavalier * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
253c410abaSAugustin Cavalier * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
263c410abaSAugustin Cavalier * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
273c410abaSAugustin Cavalier * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
283c410abaSAugustin Cavalier * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
293c410abaSAugustin Cavalier */
303c410abaSAugustin Cavalier#ifndef _FBSD_COMPAT_NET80211_IEEE80211_HAIKU_H_
313c410abaSAugustin Cavalier#define _FBSD_COMPAT_NET80211_IEEE80211_HAIKU_H_
323c410abaSAugustin Cavalier
333c410abaSAugustin Cavalier
343c410abaSAugustin Cavalier#include <stdint.h>
353c410abaSAugustin Cavalier
363c410abaSAugustin Cavalier
373c410abaSAugustin Cavalier#ifdef _KERNEL
383c410abaSAugustin Cavalier
393c410abaSAugustin Cavalier#	ifdef __cplusplus
403c410abaSAugustin Cavalier// Those includes are needed to avoid C/C++ function export clashes
41ace07f70SAugustin Cavalier#	include <new>
42ace07f70SAugustin Cavalier#	include <thread.h>
433c410abaSAugustin Cavalierextern "C" {
443c410abaSAugustin Cavalier#	endif
453c410abaSAugustin Cavalier
463c410abaSAugustin Cavalier#include <sys/kernel.h>
473c410abaSAugustin Cavalier#include <sys/mutex.h>
483c410abaSAugustin Cavalier#include <sys/sysctl.h>
493c410abaSAugustin Cavalier#include <sys/taskqueue.h>
503c410abaSAugustin Cavalier
513c410abaSAugustin Cavalier
523c410abaSAugustin Cavalier/*
533c410abaSAugustin Cavalier * Common state locking definitions.
543c410abaSAugustin Cavalier */
553c410abaSAugustin Cavaliertypedef struct {
563c410abaSAugustin Cavalier	char		name[16];		/* e.g. "ath0_com_lock" */
573c410abaSAugustin Cavalier	struct mtx	mtx;
583c410abaSAugustin Cavalier} ieee80211_com_lock_t;
593c410abaSAugustin Cavalier#define	IEEE80211_LOCK_INIT(_ic, _name) do {				\
603c410abaSAugustin Cavalier	ieee80211_com_lock_t *cl = &(_ic)->ic_comlock;			\
613c410abaSAugustin Cavalier	snprintf(cl->name, sizeof(cl->name), "%s_com_lock", _name);	\
623c410abaSAugustin Cavalier	mtx_init(&cl->mtx, cl->name, NULL, MTX_DEF | MTX_RECURSE);	\
633c410abaSAugustin Cavalier} while (0)
643c410abaSAugustin Cavalier#define	IEEE80211_LOCK_OBJ(_ic)	(&(_ic)->ic_comlock.mtx)
653c410abaSAugustin Cavalier#define	IEEE80211_LOCK_DESTROY(_ic) mtx_destroy(IEEE80211_LOCK_OBJ(_ic))
663c410abaSAugustin Cavalier#define	IEEE80211_LOCK(_ic)	   mtx_lock(IEEE80211_LOCK_OBJ(_ic))
673c410abaSAugustin Cavalier#define	IEEE80211_UNLOCK(_ic)	   mtx_unlock(IEEE80211_LOCK_OBJ(_ic))
683c410abaSAugustin Cavalier#define	IEEE80211_LOCK_ASSERT(_ic) \
693c410abaSAugustin Cavalier	mtx_assert(IEEE80211_LOCK_OBJ(_ic), MA_OWNED)
70ace07f70SAugustin Cavalier#define	IEEE80211_UNLOCK_ASSERT(_ic) \
71ace07f70SAugustin Cavalier	mtx_assert(IEEE80211_LOCK_OBJ(_ic), MA_NOTOWNED)
72ace07f70SAugustin Cavalier
73ace07f70SAugustin Cavalier/*
74ace07f70SAugustin Cavalier * Transmit lock.
75ace07f70SAugustin Cavalier *
76ace07f70SAugustin Cavalier * This is a (mostly) temporary lock designed to serialise all of the
77ace07f70SAugustin Cavalier * transmission operations throughout the stack.
78ace07f70SAugustin Cavalier */
79ace07f70SAugustin Cavaliertypedef struct {
80ace07f70SAugustin Cavalier	char		name[16];		/* e.g. "ath0_tx_lock" */
81ace07f70SAugustin Cavalier	struct mtx	mtx;
82ace07f70SAugustin Cavalier} ieee80211_tx_lock_t;
83ace07f70SAugustin Cavalier#define	IEEE80211_TX_LOCK_INIT(_ic, _name) do {				\
84ace07f70SAugustin Cavalier	ieee80211_tx_lock_t *cl = &(_ic)->ic_txlock;			\
85ace07f70SAugustin Cavalier	snprintf(cl->name, sizeof(cl->name), "%s_tx_lock", _name);	\
86ace07f70SAugustin Cavalier	mtx_init(&cl->mtx, cl->name, NULL, MTX_DEF);	\
87ace07f70SAugustin Cavalier} while (0)
88ace07f70SAugustin Cavalier#define	IEEE80211_TX_LOCK_OBJ(_ic)	(&(_ic)->ic_txlock.mtx)
89ace07f70SAugustin Cavalier#define	IEEE80211_TX_LOCK_DESTROY(_ic) mtx_destroy(IEEE80211_TX_LOCK_OBJ(_ic))
90ace07f70SAugustin Cavalier#define	IEEE80211_TX_LOCK(_ic)	   mtx_lock(IEEE80211_TX_LOCK_OBJ(_ic))
91ace07f70SAugustin Cavalier#define	IEEE80211_TX_UNLOCK(_ic)	   mtx_unlock(IEEE80211_TX_LOCK_OBJ(_ic))
92ace07f70SAugustin Cavalier#define	IEEE80211_TX_LOCK_ASSERT(_ic) \
93ace07f70SAugustin Cavalier	mtx_assert(IEEE80211_TX_LOCK_OBJ(_ic), MA_OWNED)
94ace07f70SAugustin Cavalier#define	IEEE80211_TX_UNLOCK_ASSERT(_ic) \
95ace07f70SAugustin Cavalier	mtx_assert(IEEE80211_TX_LOCK_OBJ(_ic), MA_NOTOWNED)
96ace07f70SAugustin Cavalier
97ace07f70SAugustin Cavalier/*
98ace07f70SAugustin Cavalier * Stageq / ni_tx_superg lock
99ace07f70SAugustin Cavalier */
100ace07f70SAugustin Cavaliertypedef struct {
101ace07f70SAugustin Cavalier	char		name[16];		/* e.g. "ath0_ff_lock" */
102ace07f70SAugustin Cavalier	struct mtx	mtx;
103ace07f70SAugustin Cavalier} ieee80211_ff_lock_t;
104ace07f70SAugustin Cavalier#define IEEE80211_FF_LOCK_INIT(_ic, _name) do {				\
105ace07f70SAugustin Cavalier	ieee80211_ff_lock_t *fl = &(_ic)->ic_fflock;			\
106ace07f70SAugustin Cavalier	snprintf(fl->name, sizeof(fl->name), "%s_ff_lock", _name);	\
107ace07f70SAugustin Cavalier	mtx_init(&fl->mtx, fl->name, NULL, MTX_DEF);			\
108ace07f70SAugustin Cavalier} while (0)
109ace07f70SAugustin Cavalier#define IEEE80211_FF_LOCK_OBJ(_ic)	(&(_ic)->ic_fflock.mtx)
110ace07f70SAugustin Cavalier#define IEEE80211_FF_LOCK_DESTROY(_ic)	mtx_destroy(IEEE80211_FF_LOCK_OBJ(_ic))
111ace07f70SAugustin Cavalier#define IEEE80211_FF_LOCK(_ic)		mtx_lock(IEEE80211_FF_LOCK_OBJ(_ic))
112ace07f70SAugustin Cavalier#define IEEE80211_FF_UNLOCK(_ic)	mtx_unlock(IEEE80211_FF_LOCK_OBJ(_ic))
113ace07f70SAugustin Cavalier#define IEEE80211_FF_LOCK_ASSERT(_ic) \
114ace07f70SAugustin Cavalier	mtx_assert(IEEE80211_FF_LOCK_OBJ(_ic), MA_OWNED)
1153c410abaSAugustin Cavalier
1163c410abaSAugustin Cavalier/*
1173c410abaSAugustin Cavalier * Node locking definitions.
1183c410abaSAugustin Cavalier */
1193c410abaSAugustin Cavaliertypedef struct {
1203c410abaSAugustin Cavalier	char		name[16];		/* e.g. "ath0_node_lock" */
1213c410abaSAugustin Cavalier	struct mtx	mtx;
1223c410abaSAugustin Cavalier} ieee80211_node_lock_t;
1233c410abaSAugustin Cavalier#define	IEEE80211_NODE_LOCK_INIT(_nt, _name) do {			\
1243c410abaSAugustin Cavalier	ieee80211_node_lock_t *nl = &(_nt)->nt_nodelock;		\
1253c410abaSAugustin Cavalier	snprintf(nl->name, sizeof(nl->name), "%s_node_lock", _name);	\
1263c410abaSAugustin Cavalier	mtx_init(&nl->mtx, nl->name, NULL, MTX_DEF | MTX_RECURSE);	\
1273c410abaSAugustin Cavalier} while (0)
1283c410abaSAugustin Cavalier#define	IEEE80211_NODE_LOCK_OBJ(_nt)	(&(_nt)->nt_nodelock.mtx)
1293c410abaSAugustin Cavalier#define	IEEE80211_NODE_LOCK_DESTROY(_nt) \
1303c410abaSAugustin Cavalier	mtx_destroy(IEEE80211_NODE_LOCK_OBJ(_nt))
1313c410abaSAugustin Cavalier#define	IEEE80211_NODE_LOCK(_nt) \
1323c410abaSAugustin Cavalier	mtx_lock(IEEE80211_NODE_LOCK_OBJ(_nt))
1333c410abaSAugustin Cavalier#define	IEEE80211_NODE_IS_LOCKED(_nt) \
1343c410abaSAugustin Cavalier	mtx_owned(IEEE80211_NODE_LOCK_OBJ(_nt))
1353c410abaSAugustin Cavalier#define	IEEE80211_NODE_UNLOCK(_nt) \
1363c410abaSAugustin Cavalier	mtx_unlock(IEEE80211_NODE_LOCK_OBJ(_nt))
1373c410abaSAugustin Cavalier#define	IEEE80211_NODE_LOCK_ASSERT(_nt)	\
1383c410abaSAugustin Cavalier	mtx_assert(IEEE80211_NODE_LOCK_OBJ(_nt), MA_OWNED)
1393c410abaSAugustin Cavalier
1403c410abaSAugustin Cavalier/*
1413c410abaSAugustin Cavalier * Node table iteration locking definitions; this protects the
1423c410abaSAugustin Cavalier * scan generation # used to iterate over the station table
1433c410abaSAugustin Cavalier * while grabbing+releasing the node lock.
1443c410abaSAugustin Cavalier */
1453c410abaSAugustin Cavaliertypedef struct {
1463c410abaSAugustin Cavalier	char		name[16];		/* e.g. "ath0_scan_lock" */
1473c410abaSAugustin Cavalier	struct mtx	mtx;
1483c410abaSAugustin Cavalier} ieee80211_scan_lock_t;
1493c410abaSAugustin Cavalier#define	IEEE80211_NODE_ITERATE_LOCK_INIT(_nt, _name) do {		\
1503c410abaSAugustin Cavalier	ieee80211_scan_lock_t *sl = &(_nt)->nt_scanlock;		\
1513c410abaSAugustin Cavalier	snprintf(sl->name, sizeof(sl->name), "%s_scan_lock", _name);	\
1523c410abaSAugustin Cavalier	mtx_init(&sl->mtx, sl->name, NULL, MTX_DEF);			\
1533c410abaSAugustin Cavalier} while (0)
1543c410abaSAugustin Cavalier#define	IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt)	(&(_nt)->nt_scanlock.mtx)
1553c410abaSAugustin Cavalier#define	IEEE80211_NODE_ITERATE_LOCK_DESTROY(_nt) \
1563c410abaSAugustin Cavalier	mtx_destroy(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt))
1573c410abaSAugustin Cavalier#define	IEEE80211_NODE_ITERATE_LOCK(_nt) \
1583c410abaSAugustin Cavalier	mtx_lock(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt))
1593c410abaSAugustin Cavalier#define	IEEE80211_NODE_ITERATE_UNLOCK(_nt) \
1603c410abaSAugustin Cavalier	mtx_unlock(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt))
1613c410abaSAugustin Cavalier
1623c410abaSAugustin Cavalier/*
1633c410abaSAugustin Cavalier * Power-save queue definitions.
1643c410abaSAugustin Cavalier */
1653c410abaSAugustin Cavaliertypedef struct mtx ieee80211_psq_lock_t;
1663c410abaSAugustin Cavalier#define	IEEE80211_PSQ_INIT(_psq, _name) \
1673c410abaSAugustin Cavalier	mtx_init(&(_psq)->psq_lock, _name, "802.11 ps q", MTX_DEF)
1683c410abaSAugustin Cavalier#define	IEEE80211_PSQ_DESTROY(_psq)	mtx_destroy(&(_psq)->psq_lock)
1693c410abaSAugustin Cavalier#define	IEEE80211_PSQ_LOCK(_psq)	mtx_lock(&(_psq)->psq_lock)
1703c410abaSAugustin Cavalier#define	IEEE80211_PSQ_UNLOCK(_psq)	mtx_unlock(&(_psq)->psq_lock)
1713c410abaSAugustin Cavalier
1723c410abaSAugustin Cavalier#ifndef IF_PREPEND_LIST
1733c410abaSAugustin Cavalier#define _IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do {	\
1743c410abaSAugustin Cavalier	(mtail)->m_nextpkt = (ifq)->ifq_head;			\
1753c410abaSAugustin Cavalier	if ((ifq)->ifq_tail == NULL)				\
1763c410abaSAugustin Cavalier		(ifq)->ifq_tail = (mtail);			\
1773c410abaSAugustin Cavalier	(ifq)->ifq_head = (mhead);				\
1783c410abaSAugustin Cavalier	(ifq)->ifq_len += (mcount);				\
1793c410abaSAugustin Cavalier} while (0)
1803c410abaSAugustin Cavalier#define IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do {		\
1813c410abaSAugustin Cavalier	IF_LOCK(ifq);						\
1823c410abaSAugustin Cavalier	_IF_PREPEND_LIST(ifq, mhead, mtail, mcount);		\
1833c410abaSAugustin Cavalier	IF_UNLOCK(ifq);						\
1843c410abaSAugustin Cavalier} while (0)
1853c410abaSAugustin Cavalier#endif /* IF_PREPEND_LIST */
1863c410abaSAugustin Cavalier
1873c410abaSAugustin Cavalier/*
1883c410abaSAugustin Cavalier * Age queue definitions.
1893c410abaSAugustin Cavalier */
1903c410abaSAugustin Cavaliertypedef struct mtx ieee80211_ageq_lock_t;
1913c410abaSAugustin Cavalier#define	IEEE80211_AGEQ_INIT(_aq, _name) \
1923c410abaSAugustin Cavalier	mtx_init(&(_aq)->aq_lock, _name, "802.11 age q", MTX_DEF)
1933c410abaSAugustin Cavalier#define	IEEE80211_AGEQ_DESTROY(_aq)	mtx_destroy(&(_aq)->aq_lock)
1943c410abaSAugustin Cavalier#define	IEEE80211_AGEQ_LOCK(_aq)	mtx_lock(&(_aq)->aq_lock)
1953c410abaSAugustin Cavalier#define	IEEE80211_AGEQ_UNLOCK(_aq)	mtx_unlock(&(_aq)->aq_lock)
1963c410abaSAugustin Cavalier
1973c410abaSAugustin Cavalier/*
1983c410abaSAugustin Cavalier * Scan table definitions.
1993c410abaSAugustin Cavalier */
2003c410abaSAugustin Cavaliertypedef struct mtx ieee80211_scan_table_lock_t;
2013c410abaSAugustin Cavalier#define	IEEE80211_SCAN_TABLE_LOCK_INIT(_st, _name) \
2023c410abaSAugustin Cavalier	mtx_init(&(_st)->st_lock, _name, "802.11 scan table", MTX_DEF)
2033c410abaSAugustin Cavalier#define	IEEE80211_SCAN_TABLE_LOCK_DESTROY(_st)	mtx_destroy(&(_st)->st_lock)
2043c410abaSAugustin Cavalier#define	IEEE80211_SCAN_TABLE_LOCK(_st)		mtx_lock(&(_st)->st_lock)
2053c410abaSAugustin Cavalier#define	IEEE80211_SCAN_TABLE_UNLOCK(_st)	mtx_unlock(&(_st)->st_lock)
2063c410abaSAugustin Cavalier
207ace07f70SAugustin Cavaliertypedef struct mtx ieee80211_scan_iter_lock_t;
208ace07f70SAugustin Cavalier#define	IEEE80211_SCAN_ITER_LOCK_INIT(_st, _name) \
209ace07f70SAugustin Cavalier	mtx_init(&(_st)->st_scanlock, _name, "802.11 scangen", MTX_DEF)
210ace07f70SAugustin Cavalier#define	IEEE80211_SCAN_ITER_LOCK_DESTROY(_st)	mtx_destroy(&(_st)->st_scanlock)
211ace07f70SAugustin Cavalier#define	IEEE80211_SCAN_ITER_LOCK(_st)		mtx_lock(&(_st)->st_scanlock)
212ace07f70SAugustin Cavalier#define	IEEE80211_SCAN_ITER_UNLOCK(_st)	mtx_unlock(&(_st)->st_scanlock)
213ace07f70SAugustin Cavalier
214ace07f70SAugustin Cavalier/*
215ace07f70SAugustin Cavalier * Mesh node/routing definitions.
216ace07f70SAugustin Cavalier */
217ace07f70SAugustin Cavaliertypedef struct mtx ieee80211_rte_lock_t;
218ace07f70SAugustin Cavalier#define	MESH_RT_ENTRY_LOCK_INIT(_rt, _name) \
219ace07f70SAugustin Cavalier	mtx_init(&(rt)->rt_lock, _name, "802.11s route entry", MTX_DEF)
220ace07f70SAugustin Cavalier#define	MESH_RT_ENTRY_LOCK_DESTROY(_rt) \
221ace07f70SAugustin Cavalier	mtx_destroy(&(_rt)->rt_lock)
222ace07f70SAugustin Cavalier#define	MESH_RT_ENTRY_LOCK(rt)	mtx_lock(&(rt)->rt_lock)
223ace07f70SAugustin Cavalier#define	MESH_RT_ENTRY_LOCK_ASSERT(rt) mtx_assert(&(rt)->rt_lock, MA_OWNED)
224ace07f70SAugustin Cavalier#define	MESH_RT_ENTRY_UNLOCK(rt)	mtx_unlock(&(rt)->rt_lock)
225ace07f70SAugustin Cavalier
226ace07f70SAugustin Cavaliertypedef struct mtx ieee80211_rt_lock_t;
227ace07f70SAugustin Cavalier#define	MESH_RT_LOCK(ms)	mtx_lock(&(ms)->ms_rt_lock)
228ace07f70SAugustin Cavalier#define	MESH_RT_LOCK_ASSERT(ms)	mtx_assert(&(ms)->ms_rt_lock, MA_OWNED)
229ace07f70SAugustin Cavalier#define	MESH_RT_UNLOCK(ms)	mtx_unlock(&(ms)->ms_rt_lock)
230ace07f70SAugustin Cavalier#define	MESH_RT_LOCK_INIT(ms, name) \
231ace07f70SAugustin Cavalier	mtx_init(&(ms)->ms_rt_lock, name, "802.11s routing table", MTX_DEF)
232ace07f70SAugustin Cavalier#define	MESH_RT_LOCK_DESTROY(ms) \
233ace07f70SAugustin Cavalier	mtx_destroy(&(ms)->ms_rt_lock)
234ace07f70SAugustin Cavalier
2353c410abaSAugustin Cavalier/*
2363c410abaSAugustin Cavalier * Node reference counting definitions.
2373c410abaSAugustin Cavalier *
2383c410abaSAugustin Cavalier * ieee80211_node_initref	initialize the reference count to 1
2393c410abaSAugustin Cavalier * ieee80211_node_incref	add a reference
2403c410abaSAugustin Cavalier * ieee80211_node_decref	remove a reference
2413c410abaSAugustin Cavalier * ieee80211_node_dectestref	remove a reference and return 1 if this
2423c410abaSAugustin Cavalier *				is the last reference, otherwise 0
2433c410abaSAugustin Cavalier * ieee80211_node_refcnt	reference count for printing (only)
2443c410abaSAugustin Cavalier */
2453c410abaSAugustin Cavalier#include <machine/atomic.h>
2463c410abaSAugustin Cavalier
2473c410abaSAugustin Cavalier#define ieee80211_node_initref(_ni) \
2483c410abaSAugustin Cavalier	do { ((_ni)->ni_refcnt = 1); } while (0)
2493c410abaSAugustin Cavalier#define ieee80211_node_incref(_ni) \
2503c410abaSAugustin Cavalier	atomic_add_int(&(_ni)->ni_refcnt, 1)
2513c410abaSAugustin Cavalier#define	ieee80211_node_decref(_ni) \
2523c410abaSAugustin Cavalier	atomic_subtract_int(&(_ni)->ni_refcnt, 1)
2533c410abaSAugustin Cavalierstruct ieee80211_node;
2543c410abaSAugustin Cavalierint	ieee80211_node_dectestref(struct ieee80211_node *ni);
2553c410abaSAugustin Cavalier#define	ieee80211_node_refcnt(_ni)	(_ni)->ni_refcnt
2563c410abaSAugustin Cavalier
2573c410abaSAugustin Cavalierstruct ifqueue;
2583c410abaSAugustin Cavalierstruct ieee80211vap;
2593c410abaSAugustin Cavaliervoid	ieee80211_drain_ifq(struct ifqueue *);
2603c410abaSAugustin Cavaliervoid	ieee80211_flush_ifq(struct ifqueue *, struct ieee80211vap *);
2613c410abaSAugustin Cavalier
2623c410abaSAugustin Cavaliervoid	ieee80211_vap_destroy(struct ieee80211vap *);
2633c410abaSAugustin Cavalier
2643c410abaSAugustin Cavalier#define	IFNET_IS_UP_RUNNING(_ifp) \
2653c410abaSAugustin Cavalier	(((_ifp)->if_flags & IFF_UP) && \
2663c410abaSAugustin Cavalier	 ((_ifp)->if_drv_flags & IFF_DRV_RUNNING))
2673c410abaSAugustin Cavalier
2686d0f2b48SAugustin Cavalier/* XXX TODO: cap these at 1, as hz may not be 1000 */
2693c410abaSAugustin Cavalier#define	msecs_to_ticks(ms)	(((ms)*hz)/1000)
2703c410abaSAugustin Cavalier#define	ticks_to_msecs(t)	(1000*(t) / hz)
2713c410abaSAugustin Cavalier#define	ticks_to_secs(t)	((t) / hz)
2726d0f2b48SAugustin Cavalier
273ace07f70SAugustin Cavalier#define ieee80211_time_after(a,b) 	((long)(b) - (long)(a) < 0)
274ace07f70SAugustin Cavalier#define ieee80211_time_before(a,b)	ieee80211_time_after(b,a)
275ace07f70SAugustin Cavalier#define ieee80211_time_after_eq(a,b)	((long)(a) - (long)(b) >= 0)
276ace07f70SAugustin Cavalier#define ieee80211_time_before_eq(a,b)	ieee80211_time_after_eq(b,a)
2773c410abaSAugustin Cavalier
2783c410abaSAugustin Cavalierstruct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen);
2793c410abaSAugustin Cavalier
2803c410abaSAugustin Cavalier/* tx path usage */
2813c410abaSAugustin Cavalier#define	M_ENCAP		M_PROTO1		/* 802.11 encap done */
2823c410abaSAugustin Cavalier#define	M_EAPOL		M_PROTO3		/* PAE/EAPOL frame */
2833c410abaSAugustin Cavalier#define	M_PWR_SAV	M_PROTO4		/* bypass PS handling */
2843c410abaSAugustin Cavalier#define	M_MORE_DATA	M_PROTO5		/* more data frames to follow */
2856d0f2b48SAugustin Cavalier#define	M_FF		M_PROTO6		/* fast frame / A-MSDU */
2863c410abaSAugustin Cavalier#define	M_TXCB		M_PROTO7		/* do tx complete callback */
2873c410abaSAugustin Cavalier#define	M_AMPDU_MPDU	M_PROTO8		/* ok for A-MPDU aggregation */
288ace07f70SAugustin Cavalier#define	M_FRAG		M_PROTO9		/* frame fragmentation */
289ace07f70SAugustin Cavalier#define	M_FIRSTFRAG	M_PROTO10		/* first frame fragment */
290ace07f70SAugustin Cavalier#define	M_LASTFRAG	M_PROTO11		/* last frame fragment */
2916d0f2b48SAugustin Cavalier
2923c410abaSAugustin Cavalier#define	M_80211_TX \
2936d0f2b48SAugustin Cavalier	(M_ENCAP|M_EAPOL|M_PWR_SAV|M_MORE_DATA|M_FF|M_TXCB| \
2946d0f2b48SAugustin Cavalier	 M_AMPDU_MPDU|M_FRAG|M_FIRSTFRAG|M_LASTFRAG)
2953c410abaSAugustin Cavalier
2963c410abaSAugustin Cavalier/* rx path usage */
2973c410abaSAugustin Cavalier#define	M_AMPDU		M_PROTO1		/* A-MPDU subframe */
2983c410abaSAugustin Cavalier#define	M_WEP		M_PROTO2		/* WEP done by hardware */
2993c410abaSAugustin Cavalier#if 0
3003c410abaSAugustin Cavalier#define	M_AMPDU_MPDU	M_PROTO8		/* A-MPDU re-order done */
3013c410abaSAugustin Cavalier#endif
3023c410abaSAugustin Cavalier#define	M_80211_RX	(M_AMPDU|M_WEP|M_AMPDU_MPDU)
3033c410abaSAugustin Cavalier
3046d0f2b48SAugustin Cavalier#define	IEEE80211_MBUF_TX_FLAG_BITS \
3056d0f2b48SAugustin Cavalier	M_FLAG_BITS \
3066d0f2b48SAugustin Cavalier	"\15M_ENCAP\17M_EAPOL\20M_PWR_SAV\21M_MORE_DATA\22M_FF\23M_TXCB" \
3076d0f2b48SAugustin Cavalier	"\24M_AMPDU_MPDU\25M_FRAG\26M_FIRSTFRAG\27M_LASTFRAG"
3086d0f2b48SAugustin Cavalier
3096d0f2b48SAugustin Cavalier#define	IEEE80211_MBUF_RX_FLAG_BITS \
3106d0f2b48SAugustin Cavalier	M_FLAG_BITS \
3116d0f2b48SAugustin Cavalier	"\15M_AMPDU\16M_WEP\24M_AMPDU_MPDU"
3126d0f2b48SAugustin Cavalier
3133c410abaSAugustin Cavalier/*
3143c410abaSAugustin Cavalier * Store WME access control bits in the vlan tag.
3153c410abaSAugustin Cavalier * This is safe since it's done after the packet is classified
3163c410abaSAugustin Cavalier * (where we use any previous tag) and because it's passed
3173c410abaSAugustin Cavalier * directly in to the driver and there's no chance someone
3183c410abaSAugustin Cavalier * else will clobber them on us.
3193c410abaSAugustin Cavalier */
3203c410abaSAugustin Cavalier#define	M_WME_SETAC(m, ac) \
3213c410abaSAugustin Cavalier	((m)->m_pkthdr.ether_vtag = (ac))
3223c410abaSAugustin Cavalier#define	M_WME_GETAC(m)	((m)->m_pkthdr.ether_vtag)
3233c410abaSAugustin Cavalier
3243c410abaSAugustin Cavalier/*
3253c410abaSAugustin Cavalier * Mbufs on the power save queue are tagged with an age and
3263c410abaSAugustin Cavalier * timed out.  We reuse the hardware checksum field in the
3273c410abaSAugustin Cavalier * mbuf packet header to store this data.
3283c410abaSAugustin Cavalier */
3293c410abaSAugustin Cavalier#define	M_AGE_SET(m,v)		(m->m_pkthdr.csum_data = v)
3303c410abaSAugustin Cavalier#define	M_AGE_GET(m)		(m->m_pkthdr.csum_data)
3313c410abaSAugustin Cavalier#define	M_AGE_SUB(m,adj)	(m->m_pkthdr.csum_data -= adj)
3323c410abaSAugustin Cavalier
3333c410abaSAugustin Cavalier/*
3343c410abaSAugustin Cavalier * Store the sequence number.
3353c410abaSAugustin Cavalier */
3363c410abaSAugustin Cavalier#define	M_SEQNO_SET(m, seqno) \
3373c410abaSAugustin Cavalier	((m)->m_pkthdr.tso_segsz = (seqno))
3383c410abaSAugustin Cavalier#define	M_SEQNO_GET(m)	((m)->m_pkthdr.tso_segsz)
3393c410abaSAugustin Cavalier
3403c410abaSAugustin Cavalier#define	MTAG_ABI_NET80211	1132948340	/* net80211 ABI */
3413c410abaSAugustin Cavalier
3423c410abaSAugustin Cavalierstruct ieee80211_cb {
3433c410abaSAugustin Cavalier	void	(*func)(struct ieee80211_node *, void *, int status);
3443c410abaSAugustin Cavalier	void	*arg;
3453c410abaSAugustin Cavalier};
346ace07f70SAugustin Cavalier#define	NET80211_TAG_CALLBACK		0 /* xmit complete callback */
347cf552543SAugustin Cavalier#define	NET80211_TAG_XMIT_PARAMS	1
348cf552543SAugustin Cavalier	/* See below; this is after the bpf_params definition */
349ace07f70SAugustin Cavalier#define	NET80211_TAG_RECV_PARAMS	2
350cf552543SAugustin Cavalier#define	NET80211_TAG_TOA_PARAMS		3
3513c410abaSAugustin Cavalier
3523c410abaSAugustin Cavalierint	ieee80211_add_callback(struct mbuf *m,
3533c410abaSAugustin Cavalier		void (*func)(struct ieee80211_node *, void *, int), void *arg);
3543c410abaSAugustin Cavaliervoid	ieee80211_process_callback(struct ieee80211_node *, struct mbuf *, int);
3553c410abaSAugustin Cavalier
3563c410abaSAugustin Cavaliervoid	get_random_bytes(void *, size_t);
3573c410abaSAugustin Cavalier
3583c410abaSAugustin Cavalierstruct ieee80211com;
3593c410abaSAugustin Cavalier
360ace07f70SAugustin Cavalierint ieee80211_parent_xmitpkt(struct ieee80211com *ic, struct mbuf *m);
361ace07f70SAugustin Cavalierint ieee80211_vap_xmitpkt(struct ieee80211vap *vap, struct mbuf *m);
362ace07f70SAugustin Cavalier
3633c410abaSAugustin Cavaliervoid	ieee80211_sysctl_attach(struct ieee80211com *);
3643c410abaSAugustin Cavaliervoid	ieee80211_sysctl_detach(struct ieee80211com *);
3653c410abaSAugustin Cavaliervoid	ieee80211_sysctl_vattach(struct ieee80211vap *);
3663c410abaSAugustin Cavaliervoid	ieee80211_sysctl_vdetach(struct ieee80211vap *);
3673c410abaSAugustin Cavalier
3683c410abaSAugustin Cavaliervoid	ieee80211_load_module(const char *);
3693c410abaSAugustin Cavalier
3703c410abaSAugustin Cavalier/*
3713c410abaSAugustin Cavalier * A "policy module" is an adjunct module to net80211 that provides
3723c410abaSAugustin Cavalier * functionality that typically includes policy decisions.  This
3733c410abaSAugustin Cavalier * modularity enables extensibility and vendor-supplied functionality.
3743c410abaSAugustin Cavalier */
3756d0f2b48SAugustin Cavalier#define	_IEEE80211_POLICY_MODULE(policy, name, version, load, unload) \
3766d0f2b48SAugustin Cavalier	static void ieee80211_##policy##_##name##_load() { load; } \
3776d0f2b48SAugustin Cavalier	static void ieee80211_##policy##_##name##_unload() { unload; } \
3786d0f2b48SAugustin Cavalier	SYSINIT(ieee80211_##policy##_##name, SI_SUB_DRIVERS, SI_ORDER_ANY, \
3796d0f2b48SAugustin Cavalier		ieee80211_##policy##_##name##_load, NULL); \
3806d0f2b48SAugustin Cavalier	SYSUNINIT(ieee80211_##policy##_##name, SI_SUB_DRIVERS, SI_ORDER_ANY, \
3816d0f2b48SAugustin Cavalier		ieee80211_##policy##_##name##_unload, NULL)
3823c410abaSAugustin Cavalier
3833c410abaSAugustin Cavalier/*
3843c410abaSAugustin Cavalier * Authenticator modules handle 802.1x/WPA authentication.
3853c410abaSAugustin Cavalier */
3866d0f2b48SAugustin Cavalier#define	IEEE80211_AUTH_MODULE(name, version)
3876d0f2b48SAugustin Cavalier#define	IEEE80211_AUTH_ALG(name, alg, v) \
3886d0f2b48SAugustin Cavalier	_IEEE80211_POLICY_MODULE(auth, alg, v, \
3896d0f2b48SAugustin Cavalier		ieee80211_authenticator_register(alg, &v), \
3906d0f2b48SAugustin Cavalier		ieee80211_authenticator_unregister(alg))
3916d0f2b48SAugustin Cavalier
3926d0f2b48SAugustin Cavalier/*
3936d0f2b48SAugustin Cavalier * Crypto modules implement cipher support.
3946d0f2b48SAugustin Cavalier */
3956d0f2b48SAugustin Cavalier#define IEEE80211_CRYPTO_MODULE(name, version) \
3966d0f2b48SAugustin Cavalier	_IEEE80211_POLICY_MODULE(crypto, name, version, \
3976d0f2b48SAugustin Cavalier		ieee80211_crypto_register(&name), \
3986d0f2b48SAugustin Cavalier		ieee80211_crypto_unregister(&name))
3993c410abaSAugustin Cavalier
4003c410abaSAugustin Cavalier/*
4013c410abaSAugustin Cavalier * Scanner modules provide scanning policy.
4023c410abaSAugustin Cavalier */
4033c410abaSAugustin Cavalier#define	IEEE80211_SCANNER_MODULE(name, version)
4046d0f2b48SAugustin Cavalier#define	IEEE80211_SCANNER_ALG(name, alg, v) \
4056d0f2b48SAugustin Cavalier	_IEEE80211_POLICY_MODULE(scan, alg, v, \
4066d0f2b48SAugustin Cavalier		ieee80211_scanner_register(alg, &v), \
4076d0f2b48SAugustin Cavalier		ieee80211_scanner_unregister(alg, &v))
4083c410abaSAugustin Cavalier
4093c410abaSAugustin Cavalier/*
4103c410abaSAugustin Cavalier * Rate control modules provide tx rate control support.
4113c410abaSAugustin Cavalier */
4126d0f2b48SAugustin Cavalier#define	IEEE80211_RATECTL_MODULE(alg, version)
4133c410abaSAugustin Cavalier#define IEEE80211_RATECTL_ALG(name, alg, v) \
4146d0f2b48SAugustin Cavalier	_IEEE80211_POLICY_MODULE(ratectl, alg, v, \
4156d0f2b48SAugustin Cavalier		ieee80211_ratectl_register(alg, &v), \
4166d0f2b48SAugustin Cavalier		ieee80211_ratectl_unregister(alg))
4173c410abaSAugustin Cavalier
4183c410abaSAugustin Cavalier
4193c410abaSAugustin Cavalierstruct ieee80211req;
4203c410abaSAugustin Cavaliertypedef int ieee80211_ioctl_getfunc(struct ieee80211vap *,
4213c410abaSAugustin Cavalier    struct ieee80211req *);
4223c410abaSAugustin CavalierSET_DECLARE(ieee80211_ioctl_getset, ieee80211_ioctl_getfunc);
4233c410abaSAugustin Cavalier#define	IEEE80211_IOCTL_GET(_name, _get) TEXT_SET(ieee80211_ioctl_getset, _get)
4243c410abaSAugustin Cavalier
4253c410abaSAugustin Cavaliertypedef int ieee80211_ioctl_setfunc(struct ieee80211vap *,
4263c410abaSAugustin Cavalier    struct ieee80211req *);
4273c410abaSAugustin CavalierSET_DECLARE(ieee80211_ioctl_setset, ieee80211_ioctl_setfunc);
4283c410abaSAugustin Cavalier#define	IEEE80211_IOCTL_SET(_name, _set) TEXT_SET(ieee80211_ioctl_setset, _set)
4293c410abaSAugustin Cavalier
4303c410abaSAugustin Cavalier/*
4313c410abaSAugustin Cavalier * Structure prepended to raw packets sent through the bpf
4323c410abaSAugustin Cavalier * interface when set to DLT_IEEE802_11_RADIO.  This allows
4333c410abaSAugustin Cavalier * user applications to specify pretty much everything in
4343c410abaSAugustin Cavalier * an Atheros tx descriptor.  XXX need to generalize.
4353c410abaSAugustin Cavalier *
4363c410abaSAugustin Cavalier * XXX cannot be more than 14 bytes as it is copied to a sockaddr's
4373c410abaSAugustin Cavalier * XXX sa_data area.
4383c410abaSAugustin Cavalier */
4393c410abaSAugustin Cavalierstruct ieee80211_bpf_params {
4403c410abaSAugustin Cavalier	uint8_t		ibp_vers;	/* version */
4413c410abaSAugustin Cavalier#define	IEEE80211_BPF_VERSION	0
4423c410abaSAugustin Cavalier	uint8_t		ibp_len;	/* header length in bytes */
4433c410abaSAugustin Cavalier	uint8_t		ibp_flags;
4443c410abaSAugustin Cavalier#define	IEEE80211_BPF_SHORTPRE	0x01	/* tx with short preamble */
4453c410abaSAugustin Cavalier#define	IEEE80211_BPF_NOACK	0x02	/* tx with no ack */
4463c410abaSAugustin Cavalier#define	IEEE80211_BPF_CRYPTO	0x04	/* tx with h/w encryption */
4473c410abaSAugustin Cavalier#define	IEEE80211_BPF_FCS	0x10	/* frame incldues FCS */
4483c410abaSAugustin Cavalier#define	IEEE80211_BPF_DATAPAD	0x20	/* frame includes data padding */
4493c410abaSAugustin Cavalier#define	IEEE80211_BPF_RTS	0x40	/* tx with RTS/CTS */
4503c410abaSAugustin Cavalier#define	IEEE80211_BPF_CTS	0x80	/* tx with CTS only */
4513c410abaSAugustin Cavalier	uint8_t		ibp_pri;	/* WME/WMM AC+tx antenna */
4523c410abaSAugustin Cavalier	uint8_t		ibp_try0;	/* series 1 try count */
4533c410abaSAugustin Cavalier	uint8_t		ibp_rate0;	/* series 1 IEEE tx rate */
4543c410abaSAugustin Cavalier	uint8_t		ibp_power;	/* tx power (device units) */
4553c410abaSAugustin Cavalier	uint8_t		ibp_ctsrate;	/* IEEE tx rate for CTS */
4563c410abaSAugustin Cavalier	uint8_t		ibp_try1;	/* series 2 try count */
4573c410abaSAugustin Cavalier	uint8_t		ibp_rate1;	/* series 2 IEEE tx rate */
4583c410abaSAugustin Cavalier	uint8_t		ibp_try2;	/* series 3 try count */
4593c410abaSAugustin Cavalier	uint8_t		ibp_rate2;	/* series 3 IEEE tx rate */
4603c410abaSAugustin Cavalier	uint8_t		ibp_try3;	/* series 4 try count */
4613c410abaSAugustin Cavalier	uint8_t		ibp_rate3;	/* series 4 IEEE tx rate */
4623c410abaSAugustin Cavalier};
4633c410abaSAugustin Cavalier
464ace07f70SAugustin Cavalierint ieee80211_add_xmit_params(struct mbuf *m, const struct ieee80211_bpf_params *params);
465ace07f70SAugustin Cavalierint ieee80211_get_xmit_params(struct mbuf *m, struct ieee80211_bpf_params *params);
466ace07f70SAugustin Cavalier
467ace07f70SAugustin Cavalierstruct ieee80211_tx_params {
468ace07f70SAugustin Cavalier	struct ieee80211_bpf_params params;
469ace07f70SAugustin Cavalier};
470ace07f70SAugustin Cavalier
4716d0f2b48SAugustin Cavalierstruct ieee80211_rx_params;
4726d0f2b48SAugustin Cavalierstruct ieee80211_rx_stats;
473ace07f70SAugustin Cavalier
474ace07f70SAugustin Cavalierint ieee80211_add_rx_params(struct mbuf *m, const struct ieee80211_rx_stats *rxs);
475ace07f70SAugustin Cavalierint ieee80211_get_rx_params(struct mbuf *m, struct ieee80211_rx_stats *rxs);
4766d0f2b48SAugustin Cavalierconst struct ieee80211_rx_stats * ieee80211_get_rx_params_ptr(struct mbuf *m);
477ace07f70SAugustin Cavalier
478cf552543SAugustin Cavalierstruct ieee80211_toa_params {
479cf552543SAugustin Cavalier	int request_id;
480cf552543SAugustin Cavalier};
481cf552543SAugustin Cavalierint	ieee80211_add_toa_params(struct mbuf *m, const struct ieee80211_toa_params *p);
482cf552543SAugustin Cavalierint	ieee80211_get_toa_params(struct mbuf *m, struct ieee80211_toa_params *p);
483cf552543SAugustin Cavalier
484ace07f70SAugustin Cavalier#ifdef __cplusplus
485ace07f70SAugustin Cavalier}
486ace07f70SAugustin Cavalier#endif
487ace07f70SAugustin Cavalier#endif /* _KERNEL */
488ace07f70SAugustin Cavalier
489ace07f70SAugustin Cavalier#define	IEEE80211_MALLOC	malloc
490ace07f70SAugustin Cavalier#define	IEEE80211_FREE		free
491ace07f70SAugustin Cavalier
492ace07f70SAugustin Cavalier/* XXX TODO: get rid of WAITOK, fix all the users of it? */
493ace07f70SAugustin Cavalier#define	IEEE80211_M_NOWAIT	M_NOWAIT
494ace07f70SAugustin Cavalier#define	IEEE80211_M_WAITOK	M_WAITOK
495ace07f70SAugustin Cavalier#define	IEEE80211_M_ZERO	M_ZERO
496ace07f70SAugustin Cavalier
4973c410abaSAugustin Cavalier#endif /* _FBSD_COMPAT_NET80211_IEEE80211_HAIKU_H_ */
498