xref: /netbsd-src/sys/net80211/ieee80211_node.h (revision 21e37cc72a480a47828990a439cde7ac9ffaf0c6)
1 /*	$NetBSD: ieee80211_node.h,v 1.9 2004/04/30 22:57:32 dyoung Exp $	*/
2 /*-
3  * Copyright (c) 2001 Atsushi Onoe
4  * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * Alternatively, this software may be distributed under the terms of the
19  * GNU General Public License ("GPL") version 2 as published by the Free
20  * Software Foundation.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * $FreeBSD: src/sys/net80211/ieee80211_node.h,v 1.10 2004/04/05 22:10:26 sam Exp $
34  */
35 #ifndef _NET80211_IEEE80211_NODE_H_
36 #define _NET80211_IEEE80211_NODE_H_
37 
38 #define	IEEE80211_PSCAN_WAIT 	5		/* passive scan wait */
39 #define	IEEE80211_TRANS_WAIT 	5		/* transition wait */
40 #define	IEEE80211_INACT_WAIT	5		/* inactivity timer interval */
41 #define	IEEE80211_INACT_MAX	(300/IEEE80211_INACT_WAIT)
42 
43 #define	IEEE80211_NODE_HASHSIZE	32
44 /* simple hash is enough for variation of macaddr */
45 #define	IEEE80211_NODE_HASH(addr)	\
46 	(((u_int8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % IEEE80211_NODE_HASHSIZE)
47 
48 #define	IEEE80211_RATE_SIZE	8		/* 802.11 standard */
49 #define	IEEE80211_RATE_MAXSIZE	15		/* max rates we'll handle */
50 
51 struct ieee80211_rateset {
52 	u_int8_t		rs_nrates;
53 	u_int8_t		rs_rates[IEEE80211_RATE_MAXSIZE];
54 };
55 
56 /*
57  * Node specific information.  Note that drivers are expected
58  * to derive from this structure to add device-specific per-node
59  * state.  This is done by overriding the ic_node_* methods in
60  * the ieee80211com structure.
61  */
62 struct ieee80211_node {
63 	TAILQ_ENTRY(ieee80211_node)	ni_list;
64 	LIST_ENTRY(ieee80211_node)	ni_hash;
65 	u_int			ni_refcnt;
66 	u_int			ni_scangen;	/* gen# for timeout scan */
67 
68 	/* hardware */
69 	u_int32_t		ni_rstamp;	/* recv timestamp */
70 	u_int8_t		ni_rssi;	/* recv ssi */
71 
72 	/* header */
73 	u_int8_t		ni_macaddr[IEEE80211_ADDR_LEN];
74 	u_int8_t		ni_bssid[IEEE80211_ADDR_LEN];
75 
76 	/* beacon, probe response */
77 	u_int8_t		ni_tstamp[8];	/* from last rcv'd beacon */
78 	u_int16_t		ni_intval;	/* beacon interval */
79 	u_int16_t		ni_capinfo;	/* capabilities */
80 	u_int8_t		ni_esslen;
81 	u_int8_t		ni_essid[IEEE80211_NWID_LEN];
82 	struct ieee80211_rateset ni_rates;	/* negotiated rate set */
83 	u_int8_t		*ni_country;	/* country information XXX */
84 	struct ieee80211_channel *ni_chan;
85 	u_int16_t		ni_fhdwell;	/* FH only */
86 	u_int8_t		ni_fhindex;	/* FH only */
87 	u_int8_t		ni_erp;		/* 11g only */
88 
89 #ifdef notyet
90 	/* DTIM and contention free period (CFP) */
91 	u_int8_t		ni_dtimperiod;
92 	u_int8_t		ni_cfpperiod;	/* # of DTIMs between CFPs */
93 	u_int16_t		ni_cfpduremain;	/* remaining cfp duration */
94 	u_int16_t		ni_cfpmaxduration;/* max CFP duration in TU */
95 	u_int16_t		ni_nextdtim;	/* time to next DTIM */
96 	u_int16_t		ni_timoffset;
97 #endif
98 
99 	/* power saving mode */
100 
101 	u_int8_t		ni_pwrsave;
102 	struct ifqueue		ni_savedq;	/* packets queued for pspoll */
103 
104 	/* others */
105 	u_int16_t		ni_associd;	/* assoc response */
106 	u_int16_t		ni_txseq;	/* seq to be transmitted */
107 	u_int16_t		ni_rxseq;	/* seq previous received */
108 	int			ni_fails;	/* failure count to associate */
109 	int			ni_inact;	/* inactivity mark count */
110 	int			ni_txrate;	/* index to ni_rates[] */
111 	u_int32_t		*ni_challenge;	/* shared-key challenge */
112 };
113 
114 #ifdef __NetBSD__
115 #define ieee80211_node_incref(ni)			\
116 	do {						\
117 		int _s = splnet();			\
118 		(ni)->ni_refcnt++;			\
119 		splx(_s);				\
120 	} while (0)
121 
122 static __inline int
123 ieee80211_node_decref(struct ieee80211_node *ni)
124 {
125 	int refcnt, s;
126 	s = splnet();
127 	refcnt = --ni->ni_refcnt;
128 	splx(s);
129 	return refcnt;
130 }
131 
132 #else
133 #define ieee80211_node_incref(ni) atomic_add_int(&(ni)->ni_refcnt, 1)
134 static __inline int
135 ieee80211_node_decref(struct ieee80211_node *ni)
136 {
137 	int orefcnt;
138 	do {
139 		orefcnt = ni->ni_refcnt;
140 	} while (atomic_cmpset_int(&ni->ni_refcnt, orefcnt, orefcnt - 1) == 0);
141 	return orefcnt - 1;
142 }
143 #endif
144 
145 static __inline struct ieee80211_node *
146 ieee80211_ref_node(struct ieee80211_node *ni)
147 {
148 	ieee80211_node_incref(ni);
149 	return ni;
150 }
151 
152 static __inline void
153 ieee80211_unref_node(struct ieee80211_node **ni)
154 {
155 	ieee80211_node_decref(*ni);
156 	*ni = NULL;			/* guard against use */
157 }
158 
159 #define	IEEE80211_NODE_LOCK_INIT(_ic, _name) \
160 	mtx_init(&(_ic)->ic_nodelock, _name, "802.11 node table", MTX_DEF)
161 #define	IEEE80211_NODE_LOCK_DESTROY(_ic)	mtx_destroy(&(_ic)->ic_nodelock)
162 #define	IEEE80211_NODE_LOCK(_ic)		mtx_lock(&(_ic)->ic_nodelock)
163 #define	IEEE80211_NODE_UNLOCK(_ic)		mtx_unlock(&(_ic)->ic_nodelock)
164 #define	IEEE80211_NODE_LOCK_ASSERT(_ic) \
165 	mtx_assert(&(_ic)->ic_nodelock, MA_OWNED)
166 
167 struct ieee80211com;
168 
169 #ifdef MALLOC_DECLARE
170 MALLOC_DECLARE(M_80211_NODE);
171 #endif
172 
173 extern	void ieee80211_node_attach(struct ifnet *);
174 extern	void ieee80211_node_lateattach(struct ifnet *);
175 extern	void ieee80211_node_detach(struct ifnet *);
176 
177 extern	void ieee80211_begin_scan(struct ifnet *);
178 extern	void ieee80211_next_scan(struct ifnet *);
179 extern	void ieee80211_end_scan(struct ifnet *);
180 extern	struct ieee80211_node *ieee80211_alloc_node(struct ieee80211com *,
181 		u_int8_t *);
182 extern	struct ieee80211_node *ieee80211_dup_bss(struct ieee80211com *,
183 		u_int8_t *);
184 extern	struct ieee80211_node *ieee80211_find_node(struct ieee80211com *,
185 		u_int8_t *);
186 extern	struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *,
187 		struct ieee80211_frame *);
188 extern	struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *,
189 		u_int8_t *);
190 extern	struct ieee80211_node * ieee80211_lookup_node(struct ieee80211com *,
191 		u_int8_t *macaddr, struct ieee80211_channel *);
192 extern	void ieee80211_free_node(struct ieee80211com *,
193 		struct ieee80211_node *);
194 extern	void ieee80211_free_allnodes(struct ieee80211com *);
195 typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
196 extern	void ieee80211_iterate_nodes(struct ieee80211com *ic,
197 		ieee80211_iter_func *, void *);
198 extern	void ieee80211_timeout_nodes(struct ieee80211com *);
199 
200 extern	int ieee80211_match_bss(struct ieee80211com *,
201 		struct ieee80211_node *);
202 extern	void ieee80211_create_ibss(struct ieee80211com* ,
203 		struct ieee80211_channel *);
204 #endif /* _NET80211_IEEE80211_NODE_H_ */
205