1 /* $NetBSD: ieee80211_node.h,v 1.15 2005/01/04 00:56:52 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 #ifdef _KERNEL 39 #define IEEE80211_PSCAN_WAIT 5 /* passive scan wait */ 40 #define IEEE80211_TRANS_WAIT 5 /* transition wait */ 41 #define IEEE80211_INACT_WAIT 5 /* inactivity timer interval */ 42 #define IEEE80211_INACT_MAX (300/IEEE80211_INACT_WAIT) 43 #define IEEE80211_CACHE_SIZE 100 44 45 #define IEEE80211_NODE_HASHSIZE 32 46 /* simple hash is enough for variation of macaddr */ 47 #define IEEE80211_NODE_HASH(addr) \ 48 (((u_int8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % IEEE80211_NODE_HASHSIZE) 49 #endif /* _KERNEL */ 50 51 #define IEEE80211_RATE_SIZE 8 /* 802.11 standard */ 52 #define IEEE80211_RATE_MAXSIZE 15 /* max rates we'll handle */ 53 54 struct ieee80211_rateset { 55 u_int8_t rs_nrates; 56 u_int8_t rs_rates[IEEE80211_RATE_MAXSIZE]; 57 }; 58 59 enum ieee80211_node_state { 60 IEEE80211_STA_CACHE, /* cached node */ 61 IEEE80211_STA_BSS, /* ic->ic_bss, the network we joined */ 62 IEEE80211_STA_AUTH, /* successfully authenticated */ 63 IEEE80211_STA_ASSOC, /* successfully associated */ 64 IEEE80211_STA_COLLECT /* This node remains in the cache while 65 * the driver sends a de-auth message; 66 * afterward it should be freed to make room 67 * for a new node. 68 */ 69 }; 70 71 #define ieee80211_node_newstate(__ni, __state) \ 72 do { \ 73 (__ni)->ni_state = (__state); \ 74 } while (0) 75 76 #ifdef _KERNEL 77 /* 78 * Node specific information. Note that drivers are expected 79 * to derive from this structure to add device-specific per-node 80 * state. This is done by overriding the ic_node_* methods in 81 * the ieee80211com structure. 82 */ 83 struct ieee80211_node { 84 TAILQ_ENTRY(ieee80211_node) ni_list; 85 LIST_ENTRY(ieee80211_node) ni_hash; 86 u_int ni_refcnt; 87 u_int ni_scangen; /* gen# for timeout scan */ 88 89 /* hardware */ 90 u_int32_t ni_rstamp; /* recv timestamp */ 91 u_int8_t ni_rssi; /* recv ssi */ 92 93 /* header */ 94 u_int8_t ni_macaddr[IEEE80211_ADDR_LEN]; 95 u_int8_t ni_bssid[IEEE80211_ADDR_LEN]; 96 97 /* beacon, probe response */ 98 union { 99 /* from last rcv'd beacon */ 100 u_int8_t tu_tstamp[8]; 101 uint64_t tu_tsf; 102 } ni_tstampu; 103 #define ni_tstamp ni_tstampu.tu_tstamp 104 #define ni_tsf ni_tstampu.tu_tsf 105 u_int16_t ni_intval; /* beacon interval */ 106 u_int16_t ni_capinfo; /* capabilities */ 107 u_int8_t ni_esslen; 108 u_int8_t ni_essid[IEEE80211_NWID_LEN]; 109 struct ieee80211_rateset ni_rates; /* negotiated rate set */ 110 u_int8_t *ni_country; /* country information XXX */ 111 struct ieee80211_channel *ni_chan; 112 u_int16_t ni_fhdwell; /* FH only */ 113 u_int8_t ni_fhindex; /* FH only */ 114 u_int8_t ni_erp; /* 11g only */ 115 116 #ifdef notyet 117 /* DTIM and contention free period (CFP) */ 118 u_int8_t ni_dtimperiod; 119 u_int8_t ni_cfpperiod; /* # of DTIMs between CFPs */ 120 u_int16_t ni_cfpduremain; /* remaining cfp duration */ 121 u_int16_t ni_cfpmaxduration;/* max CFP duration in TU */ 122 u_int16_t ni_nextdtim; /* time to next DTIM */ 123 u_int16_t ni_timoffset; 124 #endif 125 126 /* power saving mode */ 127 128 u_int8_t ni_pwrsave; 129 struct ifqueue ni_savedq; /* packets queued for pspoll */ 130 131 /* others */ 132 u_int16_t ni_associd; /* assoc response */ 133 u_int16_t ni_txseq; /* seq to be transmitted */ 134 u_int16_t ni_rxseq; /* seq previous received */ 135 int ni_fails; /* failure count to associate */ 136 int ni_inact; /* inactivity mark count */ 137 int ni_txrate; /* index to ni_rates[] */ 138 int ni_state; 139 u_int32_t *ni_challenge; /* shared-key challenge */ 140 }; 141 142 #ifdef __NetBSD__ 143 #define ieee80211_node_incref(ni) \ 144 do { \ 145 int _s = splnet(); \ 146 (ni)->ni_refcnt++; \ 147 splx(_s); \ 148 } while (0) 149 150 static __inline int 151 ieee80211_node_decref(struct ieee80211_node *ni) 152 { 153 int refcnt, s; 154 s = splnet(); 155 refcnt = --ni->ni_refcnt; 156 splx(s); 157 return refcnt; 158 } 159 160 #else 161 #define ieee80211_node_incref(ni) atomic_add_int(&(ni)->ni_refcnt, 1) 162 static __inline int 163 ieee80211_node_decref(struct ieee80211_node *ni) 164 { 165 int orefcnt; 166 do { 167 orefcnt = ni->ni_refcnt; 168 } while (atomic_cmpset_int(&ni->ni_refcnt, orefcnt, orefcnt - 1) == 0); 169 return orefcnt - 1; 170 } 171 #endif 172 173 static __inline struct ieee80211_node * 174 ieee80211_ref_node(struct ieee80211_node *ni) 175 { 176 ieee80211_node_incref(ni); 177 return ni; 178 } 179 180 static __inline void 181 ieee80211_unref_node(struct ieee80211_node **ni) 182 { 183 ieee80211_node_decref(*ni); 184 *ni = NULL; /* guard against use */ 185 } 186 187 struct ieee80211com; 188 189 #ifdef MALLOC_DECLARE 190 MALLOC_DECLARE(M_80211_NODE); 191 #endif 192 193 extern void ieee80211_node_attach(struct ieee80211com *); 194 extern void ieee80211_node_lateattach(struct ieee80211com *); 195 extern void ieee80211_node_detach(struct ieee80211com *); 196 197 extern void ieee80211_begin_scan(struct ieee80211com *); 198 extern void ieee80211_next_scan(struct ieee80211com *); 199 extern void ieee80211_create_ibss(struct ieee80211com *, 200 struct ieee80211_channel *); 201 extern void ieee80211_end_scan(struct ieee80211com *); 202 extern struct ieee80211_node *ieee80211_alloc_node(struct ieee80211com *, 203 u_int8_t *); 204 extern struct ieee80211_node *ieee80211_dup_bss(struct ieee80211com *, 205 u_int8_t *); 206 extern struct ieee80211_node *ieee80211_find_node(struct ieee80211com *, 207 u_int8_t *); 208 extern struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *, 209 struct ieee80211_frame *); 210 extern struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *, 211 u_int8_t *); 212 extern struct ieee80211_node *ieee80211_find_node_for_beacon( 213 struct ieee80211com *, u_int8_t *macaddr, 214 struct ieee80211_channel *, char *ssid); 215 extern void ieee80211_release_node(struct ieee80211com *, 216 struct ieee80211_node *); 217 extern void ieee80211_free_allnodes(struct ieee80211com *); 218 219 typedef void ieee80211_iter_func(void *, struct ieee80211_node *); 220 extern void ieee80211_iterate_nodes(struct ieee80211com *ic, 221 ieee80211_iter_func *, void *); 222 extern void ieee80211_clean_nodes(struct ieee80211com *); 223 224 extern void ieee80211_node_join(struct ieee80211com *, 225 struct ieee80211_node *, int); 226 extern void ieee80211_node_leave(struct ieee80211com *, 227 struct ieee80211_node *); 228 229 extern int ieee80211_match_bss(struct ieee80211com *, struct ieee80211_node *); 230 #endif /* _KERNEL */ 231 #endif /* _NET80211_IEEE80211_NODE_H_ */ 232