ieee80211_freebsd.h revision 298899
1138568Ssam/*- 2178354Ssam * Copyright (c) 2003-2008 Sam Leffler, Errno Consulting 3138568Ssam * All rights reserved. 4138568Ssam * 5138568Ssam * Redistribution and use in source and binary forms, with or without 6138568Ssam * modification, are permitted provided that the following conditions 7138568Ssam * are met: 8138568Ssam * 1. Redistributions of source code must retain the above copyright 9138568Ssam * notice, this list of conditions and the following disclaimer. 10138568Ssam * 2. Redistributions in binary form must reproduce the above copyright 11138568Ssam * notice, this list of conditions and the following disclaimer in the 12138568Ssam * documentation and/or other materials provided with the distribution. 13138568Ssam * 14138568Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15138568Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16138568Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17138568Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18138568Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19138568Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20138568Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21138568Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22138568Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23138568Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24138568Ssam * 25138568Ssam * $FreeBSD: head/sys/net80211/ieee80211_freebsd.h 298899 2016-05-01 20:57:10Z avos $ 26138568Ssam */ 27138568Ssam#ifndef _NET80211_IEEE80211_FREEBSD_H_ 28138568Ssam#define _NET80211_IEEE80211_FREEBSD_H_ 29138568Ssam 30165911Ssam#ifdef _KERNEL 31298899Savos#include <sys/param.h> 32283614Sglebius#include <sys/systm.h> 33283614Sglebius#include <sys/counter.h> 34178354Ssam#include <sys/lock.h> 35178354Ssam#include <sys/mutex.h> 36178354Ssam#include <sys/rwlock.h> 37192473Ssam#include <sys/sysctl.h> 38191746Sthompsa#include <sys/taskqueue.h> 39178354Ssam 40138568Ssam/* 41170530Ssam * Common state locking definitions. 42170530Ssam */ 43179388Ssamtypedef struct { 44179388Ssam char name[16]; /* e.g. "ath0_com_lock" */ 45179388Ssam struct mtx mtx; 46179388Ssam} ieee80211_com_lock_t; 47179388Ssam#define IEEE80211_LOCK_INIT(_ic, _name) do { \ 48179388Ssam ieee80211_com_lock_t *cl = &(_ic)->ic_comlock; \ 49179388Ssam snprintf(cl->name, sizeof(cl->name), "%s_com_lock", _name); \ 50179388Ssam mtx_init(&cl->mtx, cl->name, NULL, MTX_DEF | MTX_RECURSE); \ 51179388Ssam} while (0) 52179388Ssam#define IEEE80211_LOCK_OBJ(_ic) (&(_ic)->ic_comlock.mtx) 53179388Ssam#define IEEE80211_LOCK_DESTROY(_ic) mtx_destroy(IEEE80211_LOCK_OBJ(_ic)) 54179388Ssam#define IEEE80211_LOCK(_ic) mtx_lock(IEEE80211_LOCK_OBJ(_ic)) 55179388Ssam#define IEEE80211_UNLOCK(_ic) mtx_unlock(IEEE80211_LOCK_OBJ(_ic)) 56170530Ssam#define IEEE80211_LOCK_ASSERT(_ic) \ 57179388Ssam mtx_assert(IEEE80211_LOCK_OBJ(_ic), MA_OWNED) 58243532Sadrian#define IEEE80211_UNLOCK_ASSERT(_ic) \ 59243532Sadrian mtx_assert(IEEE80211_LOCK_OBJ(_ic), MA_NOTOWNED) 60170530Ssam 61170530Ssam/* 62248069Sadrian * Transmit lock. 63248069Sadrian * 64248069Sadrian * This is a (mostly) temporary lock designed to serialise all of the 65248069Sadrian * transmission operations throughout the stack. 66248069Sadrian */ 67248069Sadriantypedef struct { 68296171Savos char name[16]; /* e.g. "ath0_tx_lock" */ 69248069Sadrian struct mtx mtx; 70248069Sadrian} ieee80211_tx_lock_t; 71248069Sadrian#define IEEE80211_TX_LOCK_INIT(_ic, _name) do { \ 72248069Sadrian ieee80211_tx_lock_t *cl = &(_ic)->ic_txlock; \ 73248069Sadrian snprintf(cl->name, sizeof(cl->name), "%s_tx_lock", _name); \ 74248069Sadrian mtx_init(&cl->mtx, cl->name, NULL, MTX_DEF); \ 75248069Sadrian} while (0) 76248069Sadrian#define IEEE80211_TX_LOCK_OBJ(_ic) (&(_ic)->ic_txlock.mtx) 77248069Sadrian#define IEEE80211_TX_LOCK_DESTROY(_ic) mtx_destroy(IEEE80211_TX_LOCK_OBJ(_ic)) 78248069Sadrian#define IEEE80211_TX_LOCK(_ic) mtx_lock(IEEE80211_TX_LOCK_OBJ(_ic)) 79248069Sadrian#define IEEE80211_TX_UNLOCK(_ic) mtx_unlock(IEEE80211_TX_LOCK_OBJ(_ic)) 80248069Sadrian#define IEEE80211_TX_LOCK_ASSERT(_ic) \ 81248069Sadrian mtx_assert(IEEE80211_TX_LOCK_OBJ(_ic), MA_OWNED) 82248069Sadrian#define IEEE80211_TX_UNLOCK_ASSERT(_ic) \ 83248069Sadrian mtx_assert(IEEE80211_TX_LOCK_OBJ(_ic), MA_NOTOWNED) 84248069Sadrian 85248069Sadrian/* 86138568Ssam * Node locking definitions. 87138568Ssam */ 88178354Ssamtypedef struct { 89178354Ssam char name[16]; /* e.g. "ath0_node_lock" */ 90178354Ssam struct mtx mtx; 91178354Ssam} ieee80211_node_lock_t; 92178354Ssam#define IEEE80211_NODE_LOCK_INIT(_nt, _name) do { \ 93178354Ssam ieee80211_node_lock_t *nl = &(_nt)->nt_nodelock; \ 94178354Ssam snprintf(nl->name, sizeof(nl->name), "%s_node_lock", _name); \ 95179388Ssam mtx_init(&nl->mtx, nl->name, NULL, MTX_DEF | MTX_RECURSE); \ 96178354Ssam} while (0) 97179388Ssam#define IEEE80211_NODE_LOCK_OBJ(_nt) (&(_nt)->nt_nodelock.mtx) 98178354Ssam#define IEEE80211_NODE_LOCK_DESTROY(_nt) \ 99179388Ssam mtx_destroy(IEEE80211_NODE_LOCK_OBJ(_nt)) 100178354Ssam#define IEEE80211_NODE_LOCK(_nt) \ 101179388Ssam mtx_lock(IEEE80211_NODE_LOCK_OBJ(_nt)) 102178354Ssam#define IEEE80211_NODE_IS_LOCKED(_nt) \ 103179388Ssam mtx_owned(IEEE80211_NODE_LOCK_OBJ(_nt)) 104178354Ssam#define IEEE80211_NODE_UNLOCK(_nt) \ 105179388Ssam mtx_unlock(IEEE80211_NODE_LOCK_OBJ(_nt)) 106178354Ssam#define IEEE80211_NODE_LOCK_ASSERT(_nt) \ 107179388Ssam mtx_assert(IEEE80211_NODE_LOCK_OBJ(_nt), MA_OWNED) 108138568Ssam 109138568Ssam/* 110178354Ssam * Node table iteration locking definitions; this protects the 111178354Ssam * scan generation # used to iterate over the station table 112178354Ssam * while grabbing+releasing the node lock. 113138568Ssam */ 114178354Ssamtypedef struct { 115178354Ssam char name[16]; /* e.g. "ath0_scan_lock" */ 116178354Ssam struct mtx mtx; 117178354Ssam} ieee80211_scan_lock_t; 118178354Ssam#define IEEE80211_NODE_ITERATE_LOCK_INIT(_nt, _name) do { \ 119178354Ssam ieee80211_scan_lock_t *sl = &(_nt)->nt_scanlock; \ 120178354Ssam snprintf(sl->name, sizeof(sl->name), "%s_scan_lock", _name); \ 121179388Ssam mtx_init(&sl->mtx, sl->name, NULL, MTX_DEF); \ 122178354Ssam} while (0) 123179388Ssam#define IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt) (&(_nt)->nt_scanlock.mtx) 124178354Ssam#define IEEE80211_NODE_ITERATE_LOCK_DESTROY(_nt) \ 125179388Ssam mtx_destroy(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt)) 126178354Ssam#define IEEE80211_NODE_ITERATE_LOCK(_nt) \ 127179388Ssam mtx_lock(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt)) 128178354Ssam#define IEEE80211_NODE_ITERATE_UNLOCK(_nt) \ 129179388Ssam mtx_unlock(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt)) 130138568Ssam 131138568Ssam/* 132184288Ssam * Power-save queue definitions. 133138568Ssam */ 134184288Ssamtypedef struct mtx ieee80211_psq_lock_t; 135184288Ssam#define IEEE80211_PSQ_INIT(_psq, _name) \ 136195379Ssam mtx_init(&(_psq)->psq_lock, _name, "802.11 ps q", MTX_DEF) 137184288Ssam#define IEEE80211_PSQ_DESTROY(_psq) mtx_destroy(&(_psq)->psq_lock) 138184288Ssam#define IEEE80211_PSQ_LOCK(_psq) mtx_lock(&(_psq)->psq_lock) 139184288Ssam#define IEEE80211_PSQ_UNLOCK(_psq) mtx_unlock(&(_psq)->psq_lock) 140138568Ssam 141167284Ssam#ifndef IF_PREPEND_LIST 142167284Ssam#define _IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \ 143167284Ssam (mtail)->m_nextpkt = (ifq)->ifq_head; \ 144167284Ssam if ((ifq)->ifq_tail == NULL) \ 145167284Ssam (ifq)->ifq_tail = (mtail); \ 146167284Ssam (ifq)->ifq_head = (mhead); \ 147167284Ssam (ifq)->ifq_len += (mcount); \ 148167284Ssam} while (0) 149167284Ssam#define IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \ 150167284Ssam IF_LOCK(ifq); \ 151167284Ssam _IF_PREPEND_LIST(ifq, mhead, mtail, mcount); \ 152167284Ssam IF_UNLOCK(ifq); \ 153167284Ssam} while (0) 154167284Ssam#endif /* IF_PREPEND_LIST */ 155195379Ssam 156195379Ssam/* 157195379Ssam * Age queue definitions. 158195379Ssam */ 159195379Ssamtypedef struct mtx ieee80211_ageq_lock_t; 160195379Ssam#define IEEE80211_AGEQ_INIT(_aq, _name) \ 161195379Ssam mtx_init(&(_aq)->aq_lock, _name, "802.11 age q", MTX_DEF) 162195379Ssam#define IEEE80211_AGEQ_DESTROY(_aq) mtx_destroy(&(_aq)->aq_lock) 163195379Ssam#define IEEE80211_AGEQ_LOCK(_aq) mtx_lock(&(_aq)->aq_lock) 164195379Ssam#define IEEE80211_AGEQ_UNLOCK(_aq) mtx_unlock(&(_aq)->aq_lock) 165167284Ssam 166138568Ssam/* 167138568Ssam * 802.1x MAC ACL database locking definitions. 168138568Ssam */ 169138568Ssamtypedef struct mtx acl_lock_t; 170138568Ssam#define ACL_LOCK_INIT(_as, _name) \ 171138568Ssam mtx_init(&(_as)->as_lock, _name, "802.11 ACL", MTX_DEF) 172138568Ssam#define ACL_LOCK_DESTROY(_as) mtx_destroy(&(_as)->as_lock) 173138568Ssam#define ACL_LOCK(_as) mtx_lock(&(_as)->as_lock) 174138568Ssam#define ACL_UNLOCK(_as) mtx_unlock(&(_as)->as_lock) 175138568Ssam#define ACL_LOCK_ASSERT(_as) \ 176138568Ssam mtx_assert((&(_as)->as_lock), MA_OWNED) 177138568Ssam 178138568Ssam/* 179206617Srpaulo * Scan table definitions. 180206617Srpaulo */ 181206617Srpaulotypedef struct mtx ieee80211_scan_table_lock_t; 182206617Srpaulo#define IEEE80211_SCAN_TABLE_LOCK_INIT(_st, _name) \ 183206617Srpaulo mtx_init(&(_st)->st_lock, _name, "802.11 scan table", MTX_DEF) 184206617Srpaulo#define IEEE80211_SCAN_TABLE_LOCK_DESTROY(_st) mtx_destroy(&(_st)->st_lock) 185206617Srpaulo#define IEEE80211_SCAN_TABLE_LOCK(_st) mtx_lock(&(_st)->st_lock) 186206617Srpaulo#define IEEE80211_SCAN_TABLE_UNLOCK(_st) mtx_unlock(&(_st)->st_lock) 187206617Srpaulo 188283556Sadriantypedef struct mtx ieee80211_scan_iter_lock_t; 189283556Sadrian#define IEEE80211_SCAN_ITER_LOCK_INIT(_st, _name) \ 190283556Sadrian mtx_init(&(_st)->st_scanlock, _name, "802.11 scangen", MTX_DEF) 191283556Sadrian#define IEEE80211_SCAN_ITER_LOCK_DESTROY(_st) mtx_destroy(&(_st)->st_scanlock) 192283556Sadrian#define IEEE80211_SCAN_ITER_LOCK(_st) mtx_lock(&(_st)->st_scanlock) 193283556Sadrian#define IEEE80211_SCAN_ITER_UNLOCK(_st) mtx_unlock(&(_st)->st_scanlock) 194283556Sadrian 195206617Srpaulo/* 196283555Sadrian * Mesh node/routing definitions. 197283555Sadrian */ 198283555Sadriantypedef struct mtx ieee80211_rte_lock_t; 199283555Sadrian#define MESH_RT_ENTRY_LOCK_INIT(_rt, _name) \ 200283555Sadrian mtx_init(&(rt)->rt_lock, _name, "802.11s route entry", MTX_DEF) 201283555Sadrian#define MESH_RT_ENTRY_LOCK_DESTROY(_rt) \ 202283555Sadrian mtx_destroy(&(_rt)->rt_lock) 203283555Sadrian#define MESH_RT_ENTRY_LOCK(rt) mtx_lock(&(rt)->rt_lock) 204283555Sadrian#define MESH_RT_ENTRY_LOCK_ASSERT(rt) mtx_assert(&(rt)->rt_lock, MA_OWNED) 205283555Sadrian#define MESH_RT_ENTRY_UNLOCK(rt) mtx_unlock(&(rt)->rt_lock) 206283555Sadrian 207283555Sadriantypedef struct mtx ieee80211_rt_lock_t; 208283555Sadrian#define MESH_RT_LOCK(ms) mtx_lock(&(ms)->ms_rt_lock) 209283555Sadrian#define MESH_RT_LOCK_ASSERT(ms) mtx_assert(&(ms)->ms_rt_lock, MA_OWNED) 210283555Sadrian#define MESH_RT_UNLOCK(ms) mtx_unlock(&(ms)->ms_rt_lock) 211283555Sadrian#define MESH_RT_LOCK_INIT(ms, name) \ 212283555Sadrian mtx_init(&(ms)->ms_rt_lock, name, "802.11s routing table", MTX_DEF) 213283555Sadrian#define MESH_RT_LOCK_DESTROY(ms) \ 214283555Sadrian mtx_destroy(&(ms)->ms_rt_lock) 215283555Sadrian 216283555Sadrian/* 217138568Ssam * Node reference counting definitions. 218138568Ssam * 219138568Ssam * ieee80211_node_initref initialize the reference count to 1 220138568Ssam * ieee80211_node_incref add a reference 221138568Ssam * ieee80211_node_decref remove a reference 222138568Ssam * ieee80211_node_dectestref remove a reference and return 1 if this 223138568Ssam * is the last reference, otherwise 0 224138568Ssam * ieee80211_node_refcnt reference count for printing (only) 225138568Ssam */ 226138568Ssam#include <machine/atomic.h> 227138568Ssam 228138568Ssam#define ieee80211_node_initref(_ni) \ 229138568Ssam do { ((_ni)->ni_refcnt = 1); } while (0) 230138568Ssam#define ieee80211_node_incref(_ni) \ 231138568Ssam atomic_add_int(&(_ni)->ni_refcnt, 1) 232138568Ssam#define ieee80211_node_decref(_ni) \ 233138568Ssam atomic_subtract_int(&(_ni)->ni_refcnt, 1) 234138568Ssamstruct ieee80211_node; 235144618Ssamint ieee80211_node_dectestref(struct ieee80211_node *ni); 236138568Ssam#define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt 237138568Ssam 238165904Ssamstruct ifqueue; 239178354Ssamstruct ieee80211vap; 240165894Ssamvoid ieee80211_drain_ifq(struct ifqueue *); 241178354Ssamvoid ieee80211_flush_ifq(struct ifqueue *, struct ieee80211vap *); 242165894Ssam 243178354Ssamvoid ieee80211_vap_destroy(struct ieee80211vap *); 244178354Ssam 245178354Ssam#define IFNET_IS_UP_RUNNING(_ifp) \ 246178354Ssam (((_ifp)->if_flags & IFF_UP) && \ 247178354Ssam ((_ifp)->if_drv_flags & IFF_DRV_RUNNING)) 248178354Ssam 249293022Sadrian/* XXX TODO: cap these at 1, as hz may not be 1000 */ 250171022Ssam#define msecs_to_ticks(ms) (((ms)*hz)/1000) 251178354Ssam#define ticks_to_msecs(t) (1000*(t) / hz) 252178354Ssam#define ticks_to_secs(t) ((t) / hz) 253293022Sadrian 254297405Sadrian#define ieee80211_time_after(a,b) ((long)(b) - (long)(a) < 0) 255297405Sadrian#define ieee80211_time_before(a,b) ieee80211_time_after(b,a) 256297405Sadrian#define ieee80211_time_after_eq(a,b) ((long)(a) - (long)(b) >= 0) 257297405Sadrian#define ieee80211_time_before_eq(a,b) ieee80211_time_after_eq(b,a) 258170530Ssam 259170530Ssamstruct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen); 260172054Ssam 261170530Ssam/* tx path usage */ 262184286Ssam#define M_ENCAP M_PROTO1 /* 802.11 encap done */ 263178354Ssam#define M_EAPOL M_PROTO3 /* PAE/EAPOL frame */ 264138568Ssam#define M_PWR_SAV M_PROTO4 /* bypass PS handling */ 265147789Ssam#define M_MORE_DATA M_PROTO5 /* more data frames to follow */ 266297594Sadrian#define M_FF M_PROTO6 /* fast frame / A-MSDU */ 267178354Ssam#define M_TXCB M_PROTO7 /* do tx complete callback */ 268183247Ssam#define M_AMPDU_MPDU M_PROTO8 /* ok for A-MPDU aggregation */ 269254526Sandre#define M_FRAG M_PROTO9 /* frame fragmentation */ 270254526Sandre#define M_FIRSTFRAG M_PROTO10 /* first frame fragment */ 271254526Sandre#define M_LASTFRAG M_PROTO11 /* last frame fragment */ 272254640Sadrian 273178354Ssam#define M_80211_TX \ 274254526Sandre (M_ENCAP|M_EAPOL|M_PWR_SAV|M_MORE_DATA|M_FF|M_TXCB| \ 275254526Sandre M_AMPDU_MPDU|M_FRAG|M_FIRSTFRAG|M_LASTFRAG) 276172054Ssam 277170530Ssam/* rx path usage */ 278183247Ssam#define M_AMPDU M_PROTO1 /* A-MPDU subframe */ 279172054Ssam#define M_WEP M_PROTO2 /* WEP done by hardware */ 280183247Ssam#if 0 281183247Ssam#define M_AMPDU_MPDU M_PROTO8 /* A-MPDU re-order done */ 282183247Ssam#endif 283183247Ssam#define M_80211_RX (M_AMPDU|M_WEP|M_AMPDU_MPDU) 284195618Srpaulo 285195618Srpaulo#define IEEE80211_MBUF_TX_FLAG_BITS \ 286254527Sandre M_FLAG_BITS \ 287254527Sandre "\15M_ENCAP\17M_EAPOL\20M_PWR_SAV\21M_MORE_DATA\22M_FF\23M_TXCB" \ 288254527Sandre "\24M_AMPDU_MPDU\25M_FRAG\26M_FIRSTFRAG\27M_LASTFRAG" 289195618Srpaulo 290195618Srpaulo#define IEEE80211_MBUF_RX_FLAG_BITS \ 291254527Sandre M_FLAG_BITS \ 292254527Sandre "\15M_AMPDU\16M_WEP\24M_AMPDU_MPDU" 293195618Srpaulo 294138568Ssam/* 295178354Ssam * Store WME access control bits in the vlan tag. 296178354Ssam * This is safe since it's done after the packet is classified 297178354Ssam * (where we use any previous tag) and because it's passed 298178354Ssam * directly in to the driver and there's no chance someone 299178354Ssam * else will clobber them on us. 300138568Ssam */ 301138568Ssam#define M_WME_SETAC(m, ac) \ 302178354Ssam ((m)->m_pkthdr.ether_vtag = (ac)) 303178354Ssam#define M_WME_GETAC(m) ((m)->m_pkthdr.ether_vtag) 304138568Ssam 305138568Ssam/* 306138568Ssam * Mbufs on the power save queue are tagged with an age and 307138568Ssam * timed out. We reuse the hardware checksum field in the 308138568Ssam * mbuf packet header to store this data. 309138568Ssam */ 310138568Ssam#define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v) 311138568Ssam#define M_AGE_GET(m) (m->m_pkthdr.csum_data) 312138568Ssam#define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj) 313138568Ssam 314191571Ssam/* 315191571Ssam * Store the sequence number. 316191571Ssam */ 317191571Ssam#define M_SEQNO_SET(m, seqno) \ 318191571Ssam ((m)->m_pkthdr.tso_segsz = (seqno)) 319191571Ssam#define M_SEQNO_GET(m) ((m)->m_pkthdr.tso_segsz) 320191571Ssam 321170530Ssam#define MTAG_ABI_NET80211 1132948340 /* net80211 ABI */ 322170530Ssam 323170530Ssamstruct ieee80211_cb { 324170530Ssam void (*func)(struct ieee80211_node *, void *, int status); 325170530Ssam void *arg; 326170530Ssam}; 327170530Ssam#define NET80211_TAG_CALLBACK 0 /* xmit complete callback */ 328170530Ssamint ieee80211_add_callback(struct mbuf *m, 329170530Ssam void (*func)(struct ieee80211_node *, void *, int), void *arg); 330170530Ssamvoid ieee80211_process_callback(struct ieee80211_node *, struct mbuf *, int); 331170530Ssam 332283980Sadrian#define NET80211_TAG_XMIT_PARAMS 1 333283980Sadrian/* See below; this is after the bpf_params definition */ 334283980Sadrian 335288245Sadrian#define NET80211_TAG_RECV_PARAMS 2 336288245Sadrian 337248069Sadrianstruct ieee80211com; 338254082Sadrianint ieee80211_parent_xmitpkt(struct ieee80211com *, struct mbuf *); 339254082Sadrianint ieee80211_vap_xmitpkt(struct ieee80211vap *, struct mbuf *); 340248069Sadrian 341144618Ssamvoid get_random_bytes(void *, size_t); 342138568Ssam 343138568Ssamvoid ieee80211_sysctl_attach(struct ieee80211com *); 344138568Ssamvoid ieee80211_sysctl_detach(struct ieee80211com *); 345178354Ssamvoid ieee80211_sysctl_vattach(struct ieee80211vap *); 346178354Ssamvoid ieee80211_sysctl_vdetach(struct ieee80211vap *); 347138568Ssam 348192473SsamSYSCTL_DECL(_net_wlan); 349192473Ssamint ieee80211_sysctl_msecs_ticks(SYSCTL_HANDLER_ARGS); 350192473Ssam 351138568Ssamvoid ieee80211_load_module(const char *); 352170530Ssam 353178354Ssam/* 354178354Ssam * A "policy module" is an adjunct module to net80211 that provides 355178354Ssam * functionality that typically includes policy decisions. This 356178354Ssam * modularity enables extensibility and vendor-supplied functionality. 357178354Ssam */ 358178354Ssam#define _IEEE80211_POLICY_MODULE(policy, name, version) \ 359178354Ssamtypedef void (*policy##_setup)(int); \ 360178354SsamSET_DECLARE(policy##_set, policy##_setup); \ 361170530Ssamstatic int \ 362178354Ssamwlan_##name##_modevent(module_t mod, int type, void *unused) \ 363170530Ssam{ \ 364178354Ssam policy##_setup * const *iter, f; \ 365170530Ssam switch (type) { \ 366170530Ssam case MOD_LOAD: \ 367178354Ssam SET_FOREACH(iter, policy##_set) { \ 368178354Ssam f = (void*) *iter; \ 369178354Ssam f(type); \ 370178354Ssam } \ 371170530Ssam return 0; \ 372170530Ssam case MOD_UNLOAD: \ 373170530Ssam case MOD_QUIESCE: \ 374170530Ssam if (nrefs) { \ 375282406Sadrian printf("wlan_" #name ": still in use " \ 376282406Sadrian "(%u dynamic refs)\n", nrefs); \ 377170530Ssam return EBUSY; \ 378170530Ssam } \ 379178354Ssam if (type == MOD_UNLOAD) { \ 380178354Ssam SET_FOREACH(iter, policy##_set) { \ 381178354Ssam f = (void*) *iter; \ 382178354Ssam f(type); \ 383178354Ssam } \ 384178354Ssam } \ 385170530Ssam return 0; \ 386170530Ssam } \ 387170530Ssam return EINVAL; \ 388170530Ssam} \ 389170530Ssamstatic moduledata_t name##_mod = { \ 390170530Ssam "wlan_" #name, \ 391178354Ssam wlan_##name##_modevent, \ 392241394Skevlo 0 \ 393170530Ssam}; \ 394170530SsamDECLARE_MODULE(wlan_##name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\ 395170530SsamMODULE_VERSION(wlan_##name, version); \ 396170530SsamMODULE_DEPEND(wlan_##name, wlan, 1, 1, 1) 397178354Ssam 398178354Ssam/* 399178354Ssam * Crypto modules implement cipher support. 400178354Ssam */ 401178354Ssam#define IEEE80211_CRYPTO_MODULE(name, version) \ 402178354Ssam_IEEE80211_POLICY_MODULE(crypto, name, version); \ 403178354Ssamstatic void \ 404178354Ssamname##_modevent(int type) \ 405178354Ssam{ \ 406178354Ssam if (type == MOD_LOAD) \ 407178354Ssam ieee80211_crypto_register(&name); \ 408178354Ssam else \ 409178354Ssam ieee80211_crypto_unregister(&name); \ 410178354Ssam} \ 411178354SsamTEXT_SET(crypto##_set, name##_modevent) 412178354Ssam 413178354Ssam/* 414178354Ssam * Scanner modules provide scanning policy. 415178354Ssam */ 416178354Ssam#define IEEE80211_SCANNER_MODULE(name, version) \ 417178354Ssam _IEEE80211_POLICY_MODULE(scanner, name, version) 418178354Ssam 419178354Ssam#define IEEE80211_SCANNER_ALG(name, alg, v) \ 420178354Ssamstatic void \ 421178354Ssamname##_modevent(int type) \ 422178354Ssam{ \ 423178354Ssam if (type == MOD_LOAD) \ 424178354Ssam ieee80211_scanner_register(alg, &v); \ 425178354Ssam else \ 426178354Ssam ieee80211_scanner_unregister(alg, &v); \ 427178354Ssam} \ 428178354SsamTEXT_SET(scanner_set, name##_modevent); \ 429178354Ssam 430178354Ssam/* 431178354Ssam * ACL modules implement acl policy. 432178354Ssam */ 433178354Ssam#define IEEE80211_ACL_MODULE(name, alg, version) \ 434178354Ssam_IEEE80211_POLICY_MODULE(acl, name, version); \ 435178354Ssamstatic void \ 436178354Ssamalg##_modevent(int type) \ 437178354Ssam{ \ 438178354Ssam if (type == MOD_LOAD) \ 439178354Ssam ieee80211_aclator_register(&alg); \ 440178354Ssam else \ 441178354Ssam ieee80211_aclator_unregister(&alg); \ 442178354Ssam} \ 443178354SsamTEXT_SET(acl_set, alg##_modevent); \ 444178354Ssam 445178354Ssam/* 446178354Ssam * Authenticator modules handle 802.1x/WPA authentication. 447178354Ssam */ 448178354Ssam#define IEEE80211_AUTH_MODULE(name, version) \ 449178354Ssam _IEEE80211_POLICY_MODULE(auth, name, version) 450178354Ssam 451178354Ssam#define IEEE80211_AUTH_ALG(name, alg, v) \ 452178354Ssamstatic void \ 453178354Ssamname##_modevent(int type) \ 454178354Ssam{ \ 455178354Ssam if (type == MOD_LOAD) \ 456178354Ssam ieee80211_authenticator_register(alg, &v); \ 457178354Ssam else \ 458178354Ssam ieee80211_authenticator_unregister(alg); \ 459178354Ssam} \ 460178354SsamTEXT_SET(auth_set, name##_modevent) 461178354Ssam 462178354Ssam/* 463178354Ssam * Rate control modules provide tx rate control support. 464178354Ssam */ 465206358Srpaulo#define IEEE80211_RATECTL_MODULE(alg, version) \ 466206358Srpaulo _IEEE80211_POLICY_MODULE(ratectl, alg, version); \ 467206358Srpaulo 468206358Srpaulo#define IEEE80211_RATECTL_ALG(name, alg, v) \ 469178354Ssamstatic void \ 470178354Ssamalg##_modevent(int type) \ 471178354Ssam{ \ 472206358Srpaulo if (type == MOD_LOAD) \ 473206358Srpaulo ieee80211_ratectl_register(alg, &v); \ 474206358Srpaulo else \ 475206358Srpaulo ieee80211_ratectl_unregister(alg); \ 476178354Ssam} \ 477206358SrpauloTEXT_SET(ratectl##_set, alg##_modevent) 478138568Ssam 479190384Ssamstruct ieee80211req; 480190384Ssamtypedef int ieee80211_ioctl_getfunc(struct ieee80211vap *, 481190384Ssam struct ieee80211req *); 482190384SsamSET_DECLARE(ieee80211_ioctl_getset, ieee80211_ioctl_getfunc); 483190384Ssam#define IEEE80211_IOCTL_GET(_name, _get) TEXT_SET(ieee80211_ioctl_getset, _get) 484190384Ssam 485190384Ssamtypedef int ieee80211_ioctl_setfunc(struct ieee80211vap *, 486190384Ssam struct ieee80211req *); 487190384SsamSET_DECLARE(ieee80211_ioctl_setset, ieee80211_ioctl_setfunc); 488190384Ssam#define IEEE80211_IOCTL_SET(_name, _set) TEXT_SET(ieee80211_ioctl_setset, _set) 489190394Ssam#endif /* _KERNEL */ 490190384Ssam 491138568Ssam/* XXX this stuff belongs elsewhere */ 492138568Ssam/* 493138568Ssam * Message formats for messages from the net80211 layer to user 494138568Ssam * applications via the routing socket. These messages are appended 495138568Ssam * to an if_announcemsghdr structure. 496138568Ssam */ 497138568Ssamstruct ieee80211_join_event { 498138568Ssam uint8_t iev_addr[6]; 499138568Ssam}; 500138568Ssam 501138568Ssamstruct ieee80211_leave_event { 502138568Ssam uint8_t iev_addr[6]; 503138568Ssam}; 504138568Ssam 505138568Ssamstruct ieee80211_replay_event { 506138568Ssam uint8_t iev_src[6]; /* src MAC */ 507138568Ssam uint8_t iev_dst[6]; /* dst MAC */ 508138568Ssam uint8_t iev_cipher; /* cipher type */ 509138568Ssam uint8_t iev_keyix; /* key id/index */ 510138568Ssam uint64_t iev_keyrsc; /* RSC from key */ 511138568Ssam uint64_t iev_rsc; /* RSC from frame */ 512138568Ssam}; 513138568Ssam 514138568Ssamstruct ieee80211_michael_event { 515138568Ssam uint8_t iev_src[6]; /* src MAC */ 516138568Ssam uint8_t iev_dst[6]; /* dst MAC */ 517138568Ssam uint8_t iev_cipher; /* cipher type */ 518138568Ssam uint8_t iev_keyix; /* key id/index */ 519138568Ssam}; 520138568Ssam 521178354Ssamstruct ieee80211_wds_event { 522178354Ssam uint8_t iev_addr[6]; 523178354Ssam}; 524178354Ssam 525178354Ssamstruct ieee80211_csa_event { 526178354Ssam uint32_t iev_flags; /* channel flags */ 527178354Ssam uint16_t iev_freq; /* setting in Mhz */ 528178354Ssam uint8_t iev_ieee; /* IEEE channel number */ 529178354Ssam uint8_t iev_mode; /* CSA mode */ 530178354Ssam uint8_t iev_count; /* CSA count */ 531178354Ssam}; 532178354Ssam 533178354Ssamstruct ieee80211_cac_event { 534178354Ssam uint32_t iev_flags; /* channel flags */ 535178354Ssam uint16_t iev_freq; /* setting in Mhz */ 536178354Ssam uint8_t iev_ieee; /* IEEE channel number */ 537178354Ssam /* XXX timestamp? */ 538178354Ssam uint8_t iev_type; /* IEEE80211_NOTIFY_CAC_* */ 539178354Ssam}; 540178354Ssam 541178354Ssamstruct ieee80211_radar_event { 542178354Ssam uint32_t iev_flags; /* channel flags */ 543178354Ssam uint16_t iev_freq; /* setting in Mhz */ 544178354Ssam uint8_t iev_ieee; /* IEEE channel number */ 545178354Ssam /* XXX timestamp? */ 546178354Ssam}; 547178354Ssam 548178354Ssamstruct ieee80211_auth_event { 549178354Ssam uint8_t iev_addr[6]; 550178354Ssam}; 551178354Ssam 552178354Ssamstruct ieee80211_deauth_event { 553178354Ssam uint8_t iev_addr[6]; 554178354Ssam}; 555178354Ssam 556178354Ssamstruct ieee80211_country_event { 557178354Ssam uint8_t iev_addr[6]; 558178354Ssam uint8_t iev_cc[2]; /* ISO country code */ 559178354Ssam}; 560178354Ssam 561178354Ssamstruct ieee80211_radio_event { 562178354Ssam uint8_t iev_state; /* 1 on, 0 off */ 563178354Ssam}; 564178354Ssam 565138568Ssam#define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */ 566138568Ssam#define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */ 567138568Ssam#define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */ 568138568Ssam#define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */ 569138568Ssam#define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */ 570138568Ssam#define RTM_IEEE80211_SCAN 105 /* scan complete, results available */ 571138568Ssam#define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */ 572138568Ssam#define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */ 573144302Ssam#define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */ 574178354Ssam#define RTM_IEEE80211_WDS 109 /* WDS discovery (ap mode) */ 575178354Ssam#define RTM_IEEE80211_CSA 110 /* Channel Switch Announcement event */ 576178354Ssam#define RTM_IEEE80211_RADAR 111 /* radar event */ 577178354Ssam#define RTM_IEEE80211_CAC 112 /* Channel Availability Check event */ 578178354Ssam#define RTM_IEEE80211_DEAUTH 113 /* station deauthenticate */ 579178354Ssam#define RTM_IEEE80211_AUTH 114 /* station authenticate (ap mode) */ 580178354Ssam#define RTM_IEEE80211_COUNTRY 115 /* discovered country code (sta mode) */ 581178354Ssam#define RTM_IEEE80211_RADIO 116 /* RF kill switch state change */ 582138568Ssam 583160690Ssam/* 584160690Ssam * Structure prepended to raw packets sent through the bpf 585160690Ssam * interface when set to DLT_IEEE802_11_RADIO. This allows 586160690Ssam * user applications to specify pretty much everything in 587160690Ssam * an Atheros tx descriptor. XXX need to generalize. 588160690Ssam * 589160690Ssam * XXX cannot be more than 14 bytes as it is copied to a sockaddr's 590160690Ssam * XXX sa_data area. 591160690Ssam */ 592160690Ssamstruct ieee80211_bpf_params { 593160690Ssam uint8_t ibp_vers; /* version */ 594160690Ssam#define IEEE80211_BPF_VERSION 0 595160690Ssam uint8_t ibp_len; /* header length in bytes */ 596160690Ssam uint8_t ibp_flags; 597160690Ssam#define IEEE80211_BPF_SHORTPRE 0x01 /* tx with short preamble */ 598160690Ssam#define IEEE80211_BPF_NOACK 0x02 /* tx with no ack */ 599160690Ssam#define IEEE80211_BPF_CRYPTO 0x04 /* tx with h/w encryption */ 600160690Ssam#define IEEE80211_BPF_FCS 0x10 /* frame incldues FCS */ 601160690Ssam#define IEEE80211_BPF_DATAPAD 0x20 /* frame includes data padding */ 602160690Ssam#define IEEE80211_BPF_RTS 0x40 /* tx with RTS/CTS */ 603160690Ssam#define IEEE80211_BPF_CTS 0x80 /* tx with CTS only */ 604160690Ssam uint8_t ibp_pri; /* WME/WMM AC+tx antenna */ 605160690Ssam uint8_t ibp_try0; /* series 1 try count */ 606160690Ssam uint8_t ibp_rate0; /* series 1 IEEE tx rate */ 607160690Ssam uint8_t ibp_power; /* tx power (device units) */ 608160690Ssam uint8_t ibp_ctsrate; /* IEEE tx rate for CTS */ 609160690Ssam uint8_t ibp_try1; /* series 2 try count */ 610160690Ssam uint8_t ibp_rate1; /* series 2 IEEE tx rate */ 611160690Ssam uint8_t ibp_try2; /* series 3 try count */ 612160690Ssam uint8_t ibp_rate2; /* series 3 IEEE tx rate */ 613160690Ssam uint8_t ibp_try3; /* series 4 try count */ 614160690Ssam uint8_t ibp_rate3; /* series 4 IEEE tx rate */ 615160690Ssam}; 616283538Sadrian 617283986Sandrew#ifdef _KERNEL 618283980Sadrianstruct ieee80211_tx_params { 619283980Sadrian struct ieee80211_bpf_params params; 620283980Sadrian}; 621283980Sadrianint ieee80211_add_xmit_params(struct mbuf *m, 622283980Sadrian const struct ieee80211_bpf_params *); 623283980Sadrianint ieee80211_get_xmit_params(struct mbuf *m, 624283980Sadrian struct ieee80211_bpf_params *); 625288245Sadrian 626288245Sadrian#define IEEE80211_MAX_CHAINS 3 627288245Sadrian#define IEEE80211_MAX_EVM_PILOTS 6 628288245Sadrian 629288245Sadrian#define IEEE80211_R_NF 0x0000001 /* global NF value valid */ 630288245Sadrian#define IEEE80211_R_RSSI 0x0000002 /* global RSSI value valid */ 631288245Sadrian#define IEEE80211_R_C_CHAIN 0x0000004 /* RX chain count valid */ 632288245Sadrian#define IEEE80211_R_C_NF 0x0000008 /* per-chain NF value valid */ 633288245Sadrian#define IEEE80211_R_C_RSSI 0x0000010 /* per-chain RSSI value valid */ 634288245Sadrian#define IEEE80211_R_C_EVM 0x0000020 /* per-chain EVM valid */ 635288245Sadrian#define IEEE80211_R_C_HT40 0x0000040 /* RX'ed packet is 40mhz, pilots 4,5 valid */ 636288245Sadrian#define IEEE80211_R_FREQ 0x0000080 /* Freq value populated, MHz */ 637288245Sadrian#define IEEE80211_R_IEEE 0x0000100 /* IEEE value populated */ 638288245Sadrian#define IEEE80211_R_BAND 0x0000200 /* Frequency band populated */ 639288245Sadrian 640288245Sadrianstruct ieee80211_rx_stats { 641288245Sadrian uint32_t r_flags; /* IEEE80211_R_* flags */ 642288245Sadrian uint8_t c_chain; /* number of RX chains involved */ 643288245Sadrian int16_t c_nf_ctl[IEEE80211_MAX_CHAINS]; /* per-chain NF */ 644288245Sadrian int16_t c_nf_ext[IEEE80211_MAX_CHAINS]; /* per-chain NF */ 645288245Sadrian int16_t c_rssi_ctl[IEEE80211_MAX_CHAINS]; /* per-chain RSSI */ 646288245Sadrian int16_t c_rssi_ext[IEEE80211_MAX_CHAINS]; /* per-chain RSSI */ 647288245Sadrian uint8_t nf; /* global NF */ 648288245Sadrian uint8_t rssi; /* global RSSI */ 649288245Sadrian uint8_t evm[IEEE80211_MAX_CHAINS][IEEE80211_MAX_EVM_PILOTS]; 650288245Sadrian /* per-chain, per-pilot EVM values */ 651288245Sadrian uint16_t c_freq; 652288245Sadrian uint8_t c_ieee; 653288245Sadrian}; 654288245Sadrian 655288245Sadrianstruct ieee80211_rx_params { 656288245Sadrian struct ieee80211_rx_stats params; 657288245Sadrian}; 658288245Sadrianint ieee80211_add_rx_params(struct mbuf *m, 659288245Sadrian const struct ieee80211_rx_stats *rxs); 660288245Sadrianint ieee80211_get_rx_params(struct mbuf *m, 661288245Sadrian struct ieee80211_rx_stats *rxs); 662283986Sandrew#endif /* _KERNEL */ 663283980Sadrian 664283538Sadrian/* 665283538Sadrian * Malloc API. Other BSD operating systems have slightly 666283538Sadrian * different malloc/free namings (eg DragonflyBSD.) 667283538Sadrian */ 668283538Sadrian#define IEEE80211_MALLOC malloc 669283538Sadrian#define IEEE80211_FREE free 670283538Sadrian 671283538Sadrian/* XXX TODO: get rid of WAITOK, fix all the users of it? */ 672283538Sadrian#define IEEE80211_M_NOWAIT M_NOWAIT 673283538Sadrian#define IEEE80211_M_WAITOK M_WAITOK 674283538Sadrian#define IEEE80211_M_ZERO M_ZERO 675283538Sadrian 676283538Sadrian/* XXX TODO: the type fields */ 677283538Sadrian 678138568Ssam#endif /* _NET80211_IEEE80211_FREEBSD_H_ */ 679