]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - 6/sys/net80211/ieee80211_freebsd.h
Clone Kip's Xen on stable/6 tree so that I can work on improving FreeBSD/amd64
[FreeBSD/FreeBSD.git] / 6 / sys / net80211 / ieee80211_freebsd.h
1 /*-
2  * Copyright (c) 2003-2005 Sam Leffler, Errno Consulting
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 #ifndef _NET80211_IEEE80211_FREEBSD_H_
30 #define _NET80211_IEEE80211_FREEBSD_H_
31
32 #ifdef _KERNEL
33 /*
34  * Beacon locking definitions.
35  */
36 typedef struct mtx ieee80211_beacon_lock_t;
37 #define IEEE80211_BEACON_LOCK_INIT(_ic, _name) \
38         mtx_init(&(_ic)->ic_beaconlock, _name, "802.11 beacon lock", MTX_DEF)
39 #define IEEE80211_BEACON_LOCK_DESTROY(_ic) mtx_destroy(&(_ic)->ic_beaconlock)
40 #define IEEE80211_BEACON_LOCK(_ic)         mtx_lock(&(_ic)->ic_beaconlock)
41 #define IEEE80211_BEACON_UNLOCK(_ic)       mtx_unlock(&(_ic)->ic_beaconlock)
42 #define IEEE80211_BEACON_LOCK_ASSERT(_ic) \
43         mtx_assert(&(_ic)->ic_beaconlock, MA_OWNED)
44
45 /*
46  * Node locking definitions.
47  * NB: MTX_DUPOK is because we don't generate per-interface strings.
48  */
49 typedef struct mtx ieee80211_node_lock_t;
50 #define IEEE80211_NODE_LOCK_INIT(_nt, _name) \
51         mtx_init(&(_nt)->nt_nodelock, _name, "802.11 node table", \
52                 MTX_DEF | MTX_DUPOK)
53 #define IEEE80211_NODE_LOCK_DESTROY(_nt)        mtx_destroy(&(_nt)->nt_nodelock)
54 #define IEEE80211_NODE_LOCK(_nt)                mtx_lock(&(_nt)->nt_nodelock)
55 #define IEEE80211_NODE_IS_LOCKED(_nt)           mtx_owned(&(_nt)->nt_nodelock)
56 #define IEEE80211_NODE_UNLOCK(_nt)              mtx_unlock(&(_nt)->nt_nodelock)
57 #define IEEE80211_NODE_LOCK_ASSERT(_nt) \
58         mtx_assert(&(_nt)->nt_nodelock, MA_OWNED)
59
60 /*
61  * Node table scangen locking definitions.
62  */
63 typedef struct mtx ieee80211_scan_lock_t;
64 #define IEEE80211_SCAN_LOCK_INIT(_nt, _name) \
65         mtx_init(&(_nt)->nt_scanlock, _name, "802.11 scangen", MTX_DEF)
66 #define IEEE80211_SCAN_LOCK_DESTROY(_nt)        mtx_destroy(&(_nt)->nt_scanlock)
67 #define IEEE80211_SCAN_LOCK(_nt)                mtx_lock(&(_nt)->nt_scanlock)
68 #define IEEE80211_SCAN_UNLOCK(_nt)              mtx_unlock(&(_nt)->nt_scanlock)
69 #define IEEE80211_SCAN_LOCK_ASSERT(_nt) \
70         mtx_assert(&(_nt)->nt_scanlock, MA_OWNED)
71
72 /*
73  * Per-node power-save queue definitions. 
74  */
75 #define IEEE80211_NODE_SAVEQ_INIT(_ni, _name) do {              \
76         mtx_init(&(_ni)->ni_savedq.ifq_mtx, _name, "802.11 ps queue", MTX_DEF);\
77         (_ni)->ni_savedq.ifq_maxlen = IEEE80211_PS_MAX_QUEUE;   \
78 } while (0)
79 #define IEEE80211_NODE_SAVEQ_DESTROY(_ni) \
80         mtx_destroy(&(_ni)->ni_savedq.ifq_mtx)
81 #define IEEE80211_NODE_SAVEQ_QLEN(_ni) \
82         _IF_QLEN(&(_ni)->ni_savedq)
83 #define IEEE80211_NODE_SAVEQ_LOCK(_ni) do {     \
84         IF_LOCK(&(_ni)->ni_savedq);                             \
85 } while (0)
86 #define IEEE80211_NODE_SAVEQ_UNLOCK(_ni) do {   \
87         IF_UNLOCK(&(_ni)->ni_savedq);                           \
88 } while (0)
89 #define IEEE80211_NODE_SAVEQ_DEQUEUE(_ni, _m, _qlen) do {       \
90         IEEE80211_NODE_SAVEQ_LOCK(_ni);                         \
91         _IF_DEQUEUE(&(_ni)->ni_savedq, _m);                     \
92         (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni);               \
93         IEEE80211_NODE_SAVEQ_UNLOCK(_ni);                       \
94 } while (0)
95 #define IEEE80211_NODE_SAVEQ_DRAIN(_ni, _qlen) do {             \
96         IEEE80211_NODE_SAVEQ_LOCK(_ni);                         \
97         (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni);               \
98         _IF_DRAIN(&(_ni)->ni_savedq);                           \
99         IEEE80211_NODE_SAVEQ_UNLOCK(_ni);                       \
100 } while (0)
101 /* XXX could be optimized */
102 #define _IEEE80211_NODE_SAVEQ_DEQUEUE_HEAD(_ni, _m) do {        \
103         _IF_DEQUEUE(&(_ni)->ni_savedq, m);                      \
104 } while (0)
105 #define _IEEE80211_NODE_SAVEQ_ENQUEUE(_ni, _m, _qlen, _age) do {\
106         (_m)->m_nextpkt = NULL;                                 \
107         if ((_ni)->ni_savedq.ifq_tail != NULL) {                \
108                 _age -= M_AGE_GET((_ni)->ni_savedq.ifq_tail);   \
109                 (_ni)->ni_savedq.ifq_tail->m_nextpkt = (_m);    \
110         } else {                                                \
111                 (_ni)->ni_savedq.ifq_head = (_m);               \
112         }                                                       \
113         M_AGE_SET(_m, _age);                                    \
114         (_ni)->ni_savedq.ifq_tail = (_m);                       \
115         (_qlen) = ++(_ni)->ni_savedq.ifq_len;                   \
116 } while (0)
117
118 #ifndef IF_PREPEND_LIST
119 #define _IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do {        \
120         (mtail)->m_nextpkt = (ifq)->ifq_head;                   \
121         if ((ifq)->ifq_tail == NULL)                            \
122                 (ifq)->ifq_tail = (mtail);                      \
123         (ifq)->ifq_head = (mhead);                              \
124         (ifq)->ifq_len += (mcount);                             \
125 } while (0)
126 #define IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do {         \
127         IF_LOCK(ifq);                                           \
128         _IF_PREPEND_LIST(ifq, mhead, mtail, mcount);            \
129         IF_UNLOCK(ifq);                                         \
130 } while (0)
131 #endif /* IF_PREPEND_LIST */
132
133 /*
134  * 802.1x MAC ACL database locking definitions.
135  */
136 typedef struct mtx acl_lock_t;
137 #define ACL_LOCK_INIT(_as, _name) \
138         mtx_init(&(_as)->as_lock, _name, "802.11 ACL", MTX_DEF)
139 #define ACL_LOCK_DESTROY(_as)           mtx_destroy(&(_as)->as_lock)
140 #define ACL_LOCK(_as)                   mtx_lock(&(_as)->as_lock)
141 #define ACL_UNLOCK(_as)                 mtx_unlock(&(_as)->as_lock)
142 #define ACL_LOCK_ASSERT(_as) \
143         mtx_assert((&(_as)->as_lock), MA_OWNED)
144
145 /*
146  * Node reference counting definitions.
147  *
148  * ieee80211_node_initref       initialize the reference count to 1
149  * ieee80211_node_incref        add a reference
150  * ieee80211_node_decref        remove a reference
151  * ieee80211_node_dectestref    remove a reference and return 1 if this
152  *                              is the last reference, otherwise 0
153  * ieee80211_node_refcnt        reference count for printing (only)
154  */
155 #include <machine/atomic.h>
156
157 #define ieee80211_node_initref(_ni) \
158         do { ((_ni)->ni_refcnt = 1); } while (0)
159 #define ieee80211_node_incref(_ni) \
160         atomic_add_int(&(_ni)->ni_refcnt, 1)
161 #define ieee80211_node_decref(_ni) \
162         atomic_subtract_int(&(_ni)->ni_refcnt, 1)
163 struct ieee80211_node;
164 int     ieee80211_node_dectestref(struct ieee80211_node *ni);
165 #define ieee80211_node_refcnt(_ni)      (_ni)->ni_refcnt
166
167 void    ieee80211_drain_ifq(struct ifqueue *);
168
169 struct mbuf *ieee80211_getmgtframe(u_int8_t **frm, u_int pktlen);
170 #define M_LINK0         M_PROTO1                /* WEP requested */
171 #define M_PWR_SAV       M_PROTO4                /* bypass PS handling */
172 #define M_MORE_DATA     M_PROTO5                /* more data frames to follow */
173 /*
174  * Encode WME access control bits in the PROTO flags.
175  * This is safe since it's passed directly in to the
176  * driver and there's no chance someone else will clobber
177  * them on us.
178  */
179 #define M_WME_AC_MASK   (M_PROTO2|M_PROTO3)
180 /* XXX 5 is wrong if M_PROTO* are redefined */
181 #define M_WME_AC_SHIFT  5
182
183 #define M_WME_SETAC(m, ac) \
184         ((m)->m_flags = ((m)->m_flags &~ M_WME_AC_MASK) | \
185                 ((ac) << M_WME_AC_SHIFT))
186 #define M_WME_GETAC(m)  (((m)->m_flags >> M_WME_AC_SHIFT) & 0x3)
187
188 /*
189  * Mbufs on the power save queue are tagged with an age and
190  * timed out.  We reuse the hardware checksum field in the
191  * mbuf packet header to store this data.
192  */
193 #define M_AGE_SET(m,v)          (m->m_pkthdr.csum_data = v)
194 #define M_AGE_GET(m)            (m->m_pkthdr.csum_data)
195 #define M_AGE_SUB(m,adj)        (m->m_pkthdr.csum_data -= adj)
196
197 void    get_random_bytes(void *, size_t);
198
199 struct ieee80211com;
200
201 void    ieee80211_sysctl_attach(struct ieee80211com *);
202 void    ieee80211_sysctl_detach(struct ieee80211com *);
203
204 void    ieee80211_load_module(const char *);
205 #endif /* _KERNEL */
206
207 /* XXX this stuff belongs elsewhere */
208 /*
209  * Message formats for messages from the net80211 layer to user
210  * applications via the routing socket.  These messages are appended
211  * to an if_announcemsghdr structure.
212  */
213 struct ieee80211_join_event {
214         uint8_t         iev_addr[6];
215 };
216
217 struct ieee80211_leave_event {
218         uint8_t         iev_addr[6];
219 };
220
221 struct ieee80211_replay_event {
222         uint8_t         iev_src[6];     /* src MAC */
223         uint8_t         iev_dst[6];     /* dst MAC */
224         uint8_t         iev_cipher;     /* cipher type */
225         uint8_t         iev_keyix;      /* key id/index */
226         uint64_t        iev_keyrsc;     /* RSC from key */
227         uint64_t        iev_rsc;        /* RSC from frame */
228 };
229
230 struct ieee80211_michael_event {
231         uint8_t         iev_src[6];     /* src MAC */
232         uint8_t         iev_dst[6];     /* dst MAC */
233         uint8_t         iev_cipher;     /* cipher type */
234         uint8_t         iev_keyix;      /* key id/index */
235 };
236
237 #define RTM_IEEE80211_ASSOC     100     /* station associate (bss mode) */
238 #define RTM_IEEE80211_REASSOC   101     /* station re-associate (bss mode) */
239 #define RTM_IEEE80211_DISASSOC  102     /* station disassociate (bss mode) */
240 #define RTM_IEEE80211_JOIN      103     /* station join (ap mode) */
241 #define RTM_IEEE80211_LEAVE     104     /* station leave (ap mode) */
242 #define RTM_IEEE80211_SCAN      105     /* scan complete, results available */
243 #define RTM_IEEE80211_REPLAY    106     /* sequence counter replay detected */
244 #define RTM_IEEE80211_MICHAEL   107     /* Michael MIC failure detected */
245 #define RTM_IEEE80211_REJOIN    108     /* station re-associate (ap mode) */
246
247 #endif /* _NET80211_IEEE80211_FREEBSD_H_ */