Merge branch 'vendor/ACPICA-UNIX'
[dragonfly.git] / sys / netproto / 802_11 / ieee80211_dragonfly.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: src/sys/net80211/ieee80211_freebsd.h,v 1.5.2.1 2005/09/03 22:40:02 sam Exp $
28  * $DragonFly: src/sys/netproto/802_11/ieee80211_dragonfly.h,v 1.4 2007/08/22 13:24:44 sephe Exp $
29  */
30 #ifndef _NET80211_IEEE80211_DRAGONFLY_H_
31 #define _NET80211_IEEE80211_DRAGONFLY_H_
32
33 /*
34  * Per-node power-save queue definitions. 
35  */
36 #define IEEE80211_NODE_SAVEQ_INIT(_ni, _name) do {              \
37         (_ni)->ni_savedq.ifq_maxlen = IEEE80211_PS_MAX_QUEUE;   \
38 } while (0)
39 #define IEEE80211_NODE_SAVEQ_DESTROY(_ni)       ((void)0)
40 #define IEEE80211_NODE_SAVEQ_QLEN(_ni)          IF_QLEN(&(_ni)->ni_savedq)
41 #define IEEE80211_NODE_SAVEQ_DEQUEUE(_ni, _m, _qlen) do {       \
42         IF_DEQUEUE(&(_ni)->ni_savedq, _m);                      \
43         (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni);               \
44 } while (0)
45 #define IEEE80211_NODE_SAVEQ_DRAIN(_ni, _qlen) do {             \
46         (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni);               \
47         IF_DRAIN(&(_ni)->ni_savedq);                            \
48 } while (0)
49 /* XXX could be optimized */
50 #define _IEEE80211_NODE_SAVEQ_DEQUEUE_HEAD(_ni, _m) do {        \
51         IF_DEQUEUE(&(_ni)->ni_savedq, m);                       \
52 } while (0)
53 #define _IEEE80211_NODE_SAVEQ_ENQUEUE(_ni, _m, _qlen, _age) do {\
54         (_m)->m_nextpkt = NULL;                                 \
55         if ((_ni)->ni_savedq.ifq_tail != NULL) {                \
56                 _age -= M_AGE_GET((_ni)->ni_savedq.ifq_tail);   \
57                 (_ni)->ni_savedq.ifq_tail->m_nextpkt = (_m);    \
58         } else {                                                \
59                 (_ni)->ni_savedq.ifq_head = (_m);               \
60         }                                                       \
61         M_AGE_SET(_m, _age);                                    \
62         (_ni)->ni_savedq.ifq_tail = (_m);                       \
63         (_qlen) = ++(_ni)->ni_savedq.ifq_len;                   \
64 } while (0)
65
66 /*
67  * Node reference counting definitions.
68  *
69  * ieee80211_node_initref       initialize the reference count to 1
70  * ieee80211_node_incref        add a reference
71  * ieee80211_node_decref        remove a reference
72  * ieee80211_node_dectestref    remove a reference and return 1 if this
73  *                              is the last reference, otherwise 0
74  * ieee80211_node_refcnt        reference count for printing (only)
75  */
76 #include <machine/atomic.h>
77
78 #define ieee80211_node_initref(_ni) \
79         do { ((_ni)->ni_refcnt = 1); } while (0)
80 #define ieee80211_node_incref(_ni) \
81         atomic_add_int(&(_ni)->ni_refcnt, 1)
82 #define ieee80211_node_decref(_ni) \
83         atomic_subtract_int(&(_ni)->ni_refcnt, 1)
84 struct ieee80211_node;
85 int     ieee80211_node_dectestref(struct ieee80211_node *ni);
86 #define ieee80211_node_refcnt(_ni)      (_ni)->ni_refcnt
87
88 struct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, u_int pktlen);
89
90 /* M_PROTO1 unused */
91 #define M_PWR_SAV       M_PROTO4                /* bypass PS handling */
92 #define M_MORE_DATA     M_PROTO5                /* more data frames to follow */
93 /*
94  * Encode WME access control bits in the PROTO flags.
95  * This is safe since it's passed directly in to the
96  * driver and there's no chance someone else will clobber
97  * them on us.
98  */
99 #define M_WME_AC_MASK   (M_PROTO2|M_PROTO3)
100 /* XXX 5 is wrong if M_PROTO* are redefined */
101 #define M_WME_AC_SHIFT  5
102
103 #define M_IEEE80211     (M_PROTO2|M_PROTO3|M_PROTO4|M_PROTO5)
104
105 #define M_WME_SETAC(m, ac) \
106         ((m)->m_flags = ((m)->m_flags &~ M_WME_AC_MASK) | \
107                 ((ac) << M_WME_AC_SHIFT))
108 #define M_WME_GETAC(m)  (((m)->m_flags >> M_WME_AC_SHIFT) & 0x3)
109
110 /*
111  * Mbufs on the power save queue are tagged with an age and
112  * timed out.  We reuse the hardware checksum field in the
113  * mbuf packet header to store this data.
114  */
115 #define M_AGE_SET(m,v)          (m->m_pkthdr.csum_data = v)
116 #define M_AGE_GET(m)            (m->m_pkthdr.csum_data)
117 #define M_AGE_SUB(m,adj)        (m->m_pkthdr.csum_data -= adj)
118
119 void    get_random_bytes(void *, size_t);
120
121 struct ieee80211com;
122
123 void    ieee80211_sysctl_attach(struct ieee80211com *);
124 void    ieee80211_sysctl_detach(struct ieee80211com *);
125
126 void    ieee80211_load_module(const char *);
127 int     ieee80211_mbuf_append(struct mbuf *, int, const uint8_t *);
128 struct mbuf *ieee80211_mbuf_clone(struct mbuf *, int);
129 void    ieee80211_drain_mgtq(struct ifqueue *);
130
131 /* XXX this stuff belongs elsewhere */
132 /*
133  * Message formats for messages from the net80211 layer to user
134  * applications via the routing socket.  These messages are appended
135  * to an if_announcemsghdr structure.
136  */
137 struct ieee80211_join_event {
138         uint8_t         iev_addr[6];
139 };
140
141 struct ieee80211_leave_event {
142         uint8_t         iev_addr[6];
143 };
144
145 struct ieee80211_replay_event {
146         uint8_t         iev_src[6];     /* src MAC */
147         uint8_t         iev_dst[6];     /* dst MAC */
148         uint8_t         iev_cipher;     /* cipher type */
149         uint8_t         iev_keyix;      /* key id/index */
150         uint64_t        iev_keyrsc;     /* RSC from key */
151         uint64_t        iev_rsc;        /* RSC from frame */
152 };
153
154 struct ieee80211_michael_event {
155         uint8_t         iev_src[6];     /* src MAC */
156         uint8_t         iev_dst[6];     /* dst MAC */
157         uint8_t         iev_cipher;     /* cipher type */
158         uint8_t         iev_keyix;      /* key id/index */
159 };
160
161 #define RTM_IEEE80211_ASSOC     100     /* station associate (bss mode) */
162 #define RTM_IEEE80211_REASSOC   101     /* station re-associate (bss mode) */
163 #define RTM_IEEE80211_DISASSOC  102     /* station disassociate (bss mode) */
164 #define RTM_IEEE80211_JOIN      103     /* station join (ap mode) */
165 #define RTM_IEEE80211_LEAVE     104     /* station leave (ap mode) */
166 #define RTM_IEEE80211_SCAN      105     /* scan complete, results available */
167 #define RTM_IEEE80211_REPLAY    106     /* sequence counter replay detected */
168 #define RTM_IEEE80211_MICHAEL   107     /* Michael MIC failure detected */
169 #define RTM_IEEE80211_REJOIN    108     /* station re-associate (ap mode) */
170
171 #endif /* _NET80211_IEEE80211_DRAGONFLY_H_ */