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