ieee80211_node.h revision 120483
1116742Ssam/*-
2116904Ssam * Copyright (c) 2001 Atsushi Onoe
3116742Ssam * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting
4116742Ssam * All rights reserved.
5116742Ssam *
6116742Ssam * Redistribution and use in source and binary forms, with or without
7116742Ssam * modification, are permitted provided that the following conditions
8116742Ssam * are met:
9116742Ssam * 1. Redistributions of source code must retain the above copyright
10116742Ssam *    notice, this list of conditions and the following disclaimer.
11116742Ssam * 2. Redistributions in binary form must reproduce the above copyright
12116742Ssam *    notice, this list of conditions and the following disclaimer in the
13116742Ssam *    documentation and/or other materials provided with the distribution.
14116904Ssam * 3. The name of the author may not be used to endorse or promote products
15116904Ssam *    derived from this software without specific prior written permission.
16116742Ssam *
17116904Ssam * Alternatively, this software may be distributed under the terms of the
18116904Ssam * GNU General Public License ("GPL") version 2 as published by the Free
19116904Ssam * Software Foundation.
20116742Ssam *
21116904Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22116904Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23116904Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24116904Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25116904Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26116904Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27116904Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28116904Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29116904Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30116904Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31116904Ssam *
32116742Ssam * $FreeBSD: head/sys/net80211/ieee80211_node.h 120483 2003-09-26 17:00:44Z sam $
33116742Ssam */
34116742Ssam#ifndef _NET80211_IEEE80211_NODE_H_
35116742Ssam#define _NET80211_IEEE80211_NODE_H_
36116742Ssam
37116742Ssam#define	IEEE80211_PSCAN_WAIT 	5		/* passive scan wait */
38116742Ssam#define	IEEE80211_TRANS_WAIT 	5		/* transition wait */
39116742Ssam#define	IEEE80211_INACT_WAIT	5		/* inactivity timer interval */
40116742Ssam#define	IEEE80211_INACT_MAX	(300/IEEE80211_INACT_WAIT)
41116742Ssam
42116742Ssam#define	IEEE80211_NODE_HASHSIZE	32
43116742Ssam/* simple hash is enough for variation of macaddr */
44116742Ssam#define	IEEE80211_NODE_HASH(addr)	\
45116742Ssam	(((u_int8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % IEEE80211_NODE_HASHSIZE)
46116742Ssam
47116742Ssam#define	IEEE80211_RATE_SIZE	8		/* 802.11 standard */
48116742Ssam#define	IEEE80211_RATE_MAXSIZE	15		/* max rates we'll handle */
49116742Ssam
50116742Ssamstruct ieee80211_rateset {
51116742Ssam	u_int8_t		rs_nrates;
52116742Ssam	u_int8_t		rs_rates[IEEE80211_RATE_MAXSIZE];
53116742Ssam};
54116742Ssam
55116742Ssam/*
56116742Ssam * Node specific information.  Note that drivers are expected
57116742Ssam * to derive from this structure to add device-specific per-node
58116742Ssam * state.  This is done by overriding the ic_node_* methods in
59116742Ssam * the ieee80211com structure.
60116742Ssam */
61116742Ssamstruct ieee80211_node {
62116742Ssam	TAILQ_ENTRY(ieee80211_node)	ni_list;
63116742Ssam	LIST_ENTRY(ieee80211_node)	ni_hash;
64116742Ssam	u_int			ni_refcnt;
65120483Ssam	u_int			ni_scangen;	/* gen# for timeout scan */
66116742Ssam
67116742Ssam	/* hardware */
68119150Ssam	u_int32_t		ni_rstamp;	/* recv timestamp */
69116742Ssam	u_int8_t		ni_rssi;	/* recv ssi */
70116742Ssam
71116742Ssam	/* header */
72116742Ssam	u_int8_t		ni_macaddr[IEEE80211_ADDR_LEN];
73116742Ssam	u_int8_t		ni_bssid[IEEE80211_ADDR_LEN];
74116742Ssam
75116742Ssam	/* beacon, probe response */
76116742Ssam	u_int8_t		ni_tstamp[8];	/* from last rcv'd beacon */
77116742Ssam	u_int16_t		ni_intval;	/* beacon interval */
78116742Ssam	u_int16_t		ni_capinfo;	/* capabilities */
79116742Ssam	u_int8_t		ni_esslen;
80116742Ssam	u_int8_t		ni_essid[IEEE80211_NWID_LEN];
81116742Ssam	struct ieee80211_rateset ni_rates;	/* negotiated rate set */
82116742Ssam	u_int8_t		*ni_country;	/* country information XXX */
83116742Ssam	struct ieee80211_channel *ni_chan;
84116742Ssam	u_int16_t		ni_fhdwell;	/* FH only */
85116742Ssam	u_int8_t		ni_fhindex;	/* FH only */
86116742Ssam	u_int8_t		ni_erp;		/* 11g only */
87116742Ssam
88116742Ssam#ifdef notyet
89116742Ssam	/* DTIM and contention free period (CFP) */
90116742Ssam	u_int8_t		ni_dtimperiod;
91116742Ssam	u_int8_t		ni_cfpperiod;	/* # of DTIMs between CFPs */
92116742Ssam	u_int16_t		ni_cfpduremain;	/* remaining cfp duration */
93116742Ssam	u_int16_t		ni_cfpmaxduration;/* max CFP duration in TU */
94116742Ssam	u_int16_t		ni_nextdtim;	/* time to next DTIM */
95116742Ssam	u_int16_t		ni_timoffset;
96116742Ssam#endif
97116742Ssam
98116742Ssam	/* others */
99116742Ssam	u_int16_t		ni_associd;	/* assoc response */
100116742Ssam	u_int16_t		ni_txseq;	/* seq to be transmitted */
101116742Ssam	u_int16_t		ni_rxseq;	/* seq previous received */
102116742Ssam	int			ni_fails;	/* failure count to associate */
103116742Ssam	int			ni_inact;	/* inactivity mark count */
104116742Ssam	int			ni_txrate;	/* index to ni_rates[] */
105116742Ssam};
106116742Ssam
107116742Ssamstatic __inline struct ieee80211_node *
108116742Ssamieee80211_ref_node(struct ieee80211_node *ni)
109116742Ssam{
110116742Ssam	atomic_add_int(&ni->ni_refcnt, 1);
111116742Ssam	return ni;
112116742Ssam}
113116742Ssam
114116742Ssamstatic __inline void
115116742Ssamieee80211_unref_node(struct ieee80211_node **ni)
116116742Ssam{
117116742Ssam	atomic_subtract_int(&(*ni)->ni_refcnt, 1);
118116742Ssam	*ni = NULL;			/* guard against use */
119116742Ssam}
120116742Ssam
121116742Ssamstruct ieee80211com;
122116742Ssam
123116742Ssamextern	void ieee80211_node_attach(struct ifnet *);
124118887Ssamextern	void ieee80211_node_lateattach(struct ifnet *);
125116742Ssamextern	void ieee80211_node_detach(struct ifnet *);
126116742Ssam
127117811Ssamextern	void ieee80211_begin_scan(struct ifnet *);
128116742Ssamextern	void ieee80211_next_scan(struct ifnet *);
129116742Ssamextern	void ieee80211_end_scan(struct ifnet *);
130116742Ssamextern	struct ieee80211_node *ieee80211_alloc_node(struct ieee80211com *,
131116742Ssam		u_int8_t *);
132116742Ssamextern	struct ieee80211_node *ieee80211_dup_bss(struct ieee80211com *,
133116742Ssam		u_int8_t *);
134116742Ssamextern	struct ieee80211_node *ieee80211_find_node(struct ieee80211com *,
135116742Ssam		u_int8_t *);
136116742Ssamextern	struct ieee80211_node * ieee80211_lookup_node(struct ieee80211com *,
137116742Ssam		u_int8_t *macaddr, struct ieee80211_channel *);
138116742Ssamextern	void ieee80211_free_node(struct ieee80211com *,
139116742Ssam		struct ieee80211_node *);
140116742Ssamextern	void ieee80211_free_allnodes(struct ieee80211com *);
141116742Ssamtypedef void ieee80211_iter_func(void *, struct ieee80211_node *);
142116742Ssamextern	void ieee80211_iterate_nodes(struct ieee80211com *ic,
143116742Ssam		ieee80211_iter_func *, void *);
144116742Ssamextern	void ieee80211_timeout_nodes(struct ieee80211com *);
145116742Ssam
146116742Ssamextern	void ieee80211_create_ibss(struct ieee80211com* ,
147116742Ssam		struct ieee80211_channel *);
148116742Ssam#endif /* _NET80211_IEEE80211_NODE_H_ */
149