1 /* $NetBSD: ieee80211_node.h,v 1.14 2004/08/10 00:57:22 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 u_int8_t ni_tstamp[8]; /* from last rcv'd beacon */ 99 u_int16_t ni_intval; /* beacon interval */ 100 u_int16_t ni_capinfo; /* capabilities */ 101 u_int8_t ni_esslen; 102 u_int8_t ni_essid[IEEE80211_NWID_LEN]; 103 struct ieee80211_rateset ni_rates; /* negotiated rate set */ 104 u_int8_t *ni_country; /* country information XXX */ 105 struct ieee80211_channel *ni_chan; 106 u_int16_t ni_fhdwell; /* FH only */ 107 u_int8_t ni_fhindex; /* FH only */ 108 u_int8_t ni_erp; /* 11g only */ 109 110 #ifdef notyet 111 /* DTIM and contention free period (CFP) */ 112 u_int8_t ni_dtimperiod; 113 u_int8_t ni_cfpperiod; /* # of DTIMs between CFPs */ 114 u_int16_t ni_cfpduremain; /* remaining cfp duration */ 115 u_int16_t ni_cfpmaxduration;/* max CFP duration in TU */ 116 u_int16_t ni_nextdtim; /* time to next DTIM */ 117 u_int16_t ni_timoffset; 118 #endif 119 120 /* power saving mode */ 121 122 u_int8_t ni_pwrsave; 123 struct ifqueue ni_savedq; /* packets queued for pspoll */ 124 125 /* others */ 126 u_int16_t ni_associd; /* assoc response */ 127 u_int16_t ni_txseq; /* seq to be transmitted */ 128 u_int16_t ni_rxseq; /* seq previous received */ 129 int ni_fails; /* failure count to associate */ 130 int ni_inact; /* inactivity mark count */ 131 int ni_txrate; /* index to ni_rates[] */ 132 int ni_state; 133 u_int32_t *ni_challenge; /* shared-key challenge */ 134 }; 135 136 #ifdef __NetBSD__ 137 #define ieee80211_node_incref(ni) \ 138 do { \ 139 int _s = splnet(); \ 140 (ni)->ni_refcnt++; \ 141 splx(_s); \ 142 } while (0) 143 144 static __inline int 145 ieee80211_node_decref(struct ieee80211_node *ni) 146 { 147 int refcnt, s; 148 s = splnet(); 149 refcnt = --ni->ni_refcnt; 150 splx(s); 151 return refcnt; 152 } 153 154 #else 155 #define ieee80211_node_incref(ni) atomic_add_int(&(ni)->ni_refcnt, 1) 156 static __inline int 157 ieee80211_node_decref(struct ieee80211_node *ni) 158 { 159 int orefcnt; 160 do { 161 orefcnt = ni->ni_refcnt; 162 } while (atomic_cmpset_int(&ni->ni_refcnt, orefcnt, orefcnt - 1) == 0); 163 return orefcnt - 1; 164 } 165 #endif 166 167 static __inline struct ieee80211_node * 168 ieee80211_ref_node(struct ieee80211_node *ni) 169 { 170 ieee80211_node_incref(ni); 171 return ni; 172 } 173 174 static __inline void 175 ieee80211_unref_node(struct ieee80211_node **ni) 176 { 177 ieee80211_node_decref(*ni); 178 *ni = NULL; /* guard against use */ 179 } 180 181 struct ieee80211com; 182 183 #ifdef MALLOC_DECLARE 184 MALLOC_DECLARE(M_80211_NODE); 185 #endif 186 187 extern void ieee80211_node_attach(struct ieee80211com *); 188 extern void ieee80211_node_lateattach(struct ieee80211com *); 189 extern void ieee80211_node_detach(struct ieee80211com *); 190 191 extern void ieee80211_begin_scan(struct ieee80211com *); 192 extern void ieee80211_next_scan(struct ieee80211com *); 193 extern void ieee80211_create_ibss(struct ieee80211com *, 194 struct ieee80211_channel *); 195 extern void ieee80211_end_scan(struct ieee80211com *); 196 extern struct ieee80211_node *ieee80211_alloc_node(struct ieee80211com *, 197 u_int8_t *); 198 extern struct ieee80211_node *ieee80211_dup_bss(struct ieee80211com *, 199 u_int8_t *); 200 extern struct ieee80211_node *ieee80211_find_node(struct ieee80211com *, 201 u_int8_t *); 202 extern struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *, 203 struct ieee80211_frame *); 204 extern struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *, 205 u_int8_t *); 206 extern struct ieee80211_node *ieee80211_find_node_for_beacon( 207 struct ieee80211com *, u_int8_t *macaddr, 208 struct ieee80211_channel *, char *ssid); 209 extern void ieee80211_release_node(struct ieee80211com *, 210 struct ieee80211_node *); 211 extern void ieee80211_free_allnodes(struct ieee80211com *); 212 213 typedef void ieee80211_iter_func(void *, struct ieee80211_node *); 214 extern void ieee80211_iterate_nodes(struct ieee80211com *ic, 215 ieee80211_iter_func *, void *); 216 extern void ieee80211_clean_nodes(struct ieee80211com *); 217 218 extern void ieee80211_node_join(struct ieee80211com *, 219 struct ieee80211_node *, int); 220 extern void ieee80211_node_leave(struct ieee80211com *, 221 struct ieee80211_node *); 222 223 extern int ieee80211_match_bss(struct ieee80211com *, struct ieee80211_node *); 224 #endif /* _KERNEL */ 225 #endif /* _NET80211_IEEE80211_NODE_H_ */ 226