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