1 /* $OpenBSD: ieee80211_node.h,v 1.44 2013/03/24 17:01:23 claudio 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 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 * $FreeBSD: src/sys/net80211/ieee80211_node.h,v 1.10 2004/04/05 22:10:26 sam Exp $ 32 */ 33 #ifndef _NET80211_IEEE80211_NODE_H_ 34 #define _NET80211_IEEE80211_NODE_H_ 35 36 #define IEEE80211_PSCAN_WAIT 5 /* passive scan wait */ 37 #define IEEE80211_TRANS_WAIT 5 /* transition wait */ 38 #define IEEE80211_INACT_WAIT 5 /* inactivity timer interval */ 39 #define IEEE80211_INACT_MAX (300/IEEE80211_INACT_WAIT) 40 #define IEEE80211_CACHE_SIZE 100 41 #define IEEE80211_CACHE_WAIT 3600 42 43 struct ieee80211_rateset { 44 u_int8_t rs_nrates; 45 u_int8_t rs_rates[IEEE80211_RATE_MAXSIZE]; 46 }; 47 48 extern const struct ieee80211_rateset ieee80211_std_rateset_11a; 49 extern const struct ieee80211_rateset ieee80211_std_rateset_11b; 50 extern const struct ieee80211_rateset ieee80211_std_rateset_11g; 51 52 enum ieee80211_node_state { 53 IEEE80211_STA_CACHE, /* cached node */ 54 IEEE80211_STA_BSS, /* ic->ic_bss, the network we joined */ 55 IEEE80211_STA_AUTH, /* successfully authenticated */ 56 IEEE80211_STA_ASSOC, /* successfully associated */ 57 IEEE80211_STA_COLLECT /* This node remains in the cache while 58 * the driver sends a de-auth message; 59 * afterward it should be freed to make room 60 * for a new node. 61 */ 62 }; 63 64 #define ieee80211_node_newstate(__ni, __state) \ 65 do { \ 66 (__ni)->ni_state = (__state); \ 67 } while (0) 68 69 enum ieee80211_node_psstate { 70 IEEE80211_PS_AWAKE, 71 IEEE80211_PS_DOZE 72 }; 73 74 #define IEEE80211_PS_MAX_QUEUE 50 /* maximum saved packets */ 75 76 /* Authenticator state machine: 4-Way Handshake (see 8.5.6.1.1) */ 77 enum { 78 RSNA_INITIALIZE, 79 RSNA_AUTHENTICATION, 80 RSNA_AUTHENTICATION_2, 81 RSNA_INITPMK, 82 RSNA_INITPSK, 83 RSNA_PTKSTART, 84 RSNA_PTKCALCNEGOTIATING, 85 RSNA_PTKCALCNEGOTIATING_2, 86 RSNA_PTKINITNEGOTIATING, 87 RSNA_PTKINITDONE, 88 RSNA_DISCONNECT, 89 RSNA_DISCONNECTED 90 }; 91 92 /* Authenticator state machine: Group Key Handshake (see 8.5.6.1.2) */ 93 enum { 94 RSNA_IDLE, 95 RSNA_REKEYNEGOTIATING, 96 RSNA_REKEYESTABLISHED, 97 RSNA_KEYERROR 98 }; 99 100 struct ieee80211_rxinfo { 101 u_int32_t rxi_flags; 102 u_int32_t rxi_tstamp; 103 int rxi_rssi; 104 }; 105 #define IEEE80211_RXI_HWDEC 0x00000001 106 #define IEEE80211_RXI_AMPDU_DONE 0x00000002 107 108 /* Block Acknowledgement Record */ 109 struct ieee80211_tx_ba { 110 struct ieee80211_node *ba_ni; /* backpointer for callbacks */ 111 struct timeout ba_to; 112 int ba_timeout_val; 113 #define IEEE80211_BA_MIN_TIMEOUT (10 * 1000) /* 10msec */ 114 #define IEEE80211_BA_MAX_TIMEOUT (10 * 1000 * 1000) /* 10sec */ 115 116 int ba_state; 117 #define IEEE80211_BA_INIT 0 118 #define IEEE80211_BA_REQUESTED 1 119 #define IEEE80211_BA_AGREED 2 120 121 u_int16_t ba_winstart; 122 u_int16_t ba_winend; 123 u_int16_t ba_winsize; 124 #define IEEE80211_BA_MAX_WINSZ 128 /* maximum we will accept */ 125 126 u_int8_t ba_token; 127 }; 128 129 struct ieee80211_rx_ba { 130 struct ieee80211_node *ba_ni; /* backpointer for callbacks */ 131 struct { 132 struct mbuf *m; 133 struct ieee80211_rxinfo rxi; 134 } *ba_buf; 135 struct timeout ba_to; 136 int ba_timeout_val; 137 int ba_state; 138 u_int16_t ba_winstart; 139 u_int16_t ba_winend; 140 u_int16_t ba_winsize; 141 u_int16_t ba_head; 142 }; 143 144 /* 145 * Node specific information. Note that drivers are expected 146 * to derive from this structure to add device-specific per-node 147 * state. This is done by overriding the ic_node_* methods in 148 * the ieee80211com structure. 149 */ 150 struct ieee80211_node { 151 RB_ENTRY(ieee80211_node) ni_node; 152 153 struct ieee80211com *ni_ic; /* back-pointer */ 154 155 u_int ni_refcnt; 156 u_int ni_scangen; /* gen# for timeout scan */ 157 158 /* hardware */ 159 u_int32_t ni_rstamp; /* recv timestamp */ 160 u_int8_t ni_rssi; /* recv ssi */ 161 162 /* header */ 163 u_int8_t ni_macaddr[IEEE80211_ADDR_LEN]; 164 u_int8_t ni_bssid[IEEE80211_ADDR_LEN]; 165 166 /* beacon, probe response */ 167 u_int8_t ni_tstamp[8]; /* from last rcv'd beacon */ 168 u_int16_t ni_intval; /* beacon interval */ 169 u_int16_t ni_capinfo; /* capabilities */ 170 u_int8_t ni_esslen; 171 u_int8_t ni_essid[IEEE80211_NWID_LEN]; 172 struct ieee80211_rateset ni_rates; /* negotiated rate set */ 173 u_int8_t *ni_country; /* country information XXX */ 174 struct ieee80211_channel *ni_chan; 175 u_int8_t ni_erp; /* 11g only */ 176 177 #ifdef notyet 178 /* DTIM and contention free period (CFP) */ 179 u_int8_t ni_dtimperiod; 180 u_int8_t ni_cfpperiod; /* # of DTIMs between CFPs */ 181 u_int16_t ni_cfpduremain; /* remaining cfp duration */ 182 u_int16_t ni_cfpmaxduration;/* max CFP duration in TU */ 183 u_int16_t ni_nextdtim; /* time to next DTIM */ 184 u_int16_t ni_timoffset; 185 #endif 186 187 /* power saving mode */ 188 u_int8_t ni_pwrsave; 189 struct ifqueue ni_savedq; /* packets queued for pspoll */ 190 191 /* RSN */ 192 struct timeout ni_eapol_to; 193 u_int ni_rsn_state; 194 u_int ni_rsn_gstate; 195 u_int ni_rsn_retries; 196 u_int ni_rsnprotos; 197 u_int ni_rsnakms; 198 u_int ni_rsnciphers; 199 enum ieee80211_cipher ni_rsngroupcipher; 200 enum ieee80211_cipher ni_rsngroupmgmtcipher; 201 u_int16_t ni_rsncaps; 202 enum ieee80211_cipher ni_rsncipher; 203 u_int8_t ni_nonce[EAPOL_KEY_NONCE_LEN]; 204 u_int8_t ni_pmk[IEEE80211_PMK_LEN]; 205 u_int8_t ni_pmkid[IEEE80211_PMKID_LEN]; 206 u_int64_t ni_replaycnt; 207 u_int8_t ni_replaycnt_ok; 208 u_int64_t ni_reqreplaycnt; 209 u_int8_t ni_reqreplaycnt_ok; 210 u_int8_t *ni_rsnie; 211 struct ieee80211_key ni_pairwise_key; 212 struct ieee80211_ptk ni_ptk; 213 u_int8_t ni_key_count; 214 int ni_port_valid; 215 216 /* SA Query */ 217 u_int16_t ni_sa_query_trid; 218 struct timeout ni_sa_query_to; 219 int ni_sa_query_count; 220 221 /* Block Ack records */ 222 struct ieee80211_tx_ba ni_tx_ba[IEEE80211_NUM_TID]; 223 struct ieee80211_rx_ba ni_rx_ba[IEEE80211_NUM_TID]; 224 225 /* others */ 226 u_int16_t ni_associd; /* assoc response */ 227 u_int16_t ni_txseq; /* seq to be transmitted */ 228 u_int16_t ni_rxseq; /* seq previous received */ 229 u_int16_t ni_qos_txseqs[IEEE80211_NUM_TID]; 230 u_int16_t ni_qos_rxseqs[IEEE80211_NUM_TID]; 231 int ni_fails; /* failure count to associate */ 232 int ni_inact; /* inactivity mark count */ 233 int ni_txrate; /* index to ni_rates[] */ 234 int ni_state; 235 236 u_int16_t ni_flags; /* special-purpose state */ 237 #define IEEE80211_NODE_ERP 0x0001 238 #define IEEE80211_NODE_QOS 0x0002 239 #define IEEE80211_NODE_REKEY 0x0004 /* GTK rekeying in progress */ 240 #define IEEE80211_NODE_RXPROT 0x0008 /* RX protection ON */ 241 #define IEEE80211_NODE_TXPROT 0x0010 /* TX protection ON */ 242 #define IEEE80211_NODE_TXRXPROT \ 243 (IEEE80211_NODE_TXPROT | IEEE80211_NODE_RXPROT) 244 #define IEEE80211_NODE_RXMGMTPROT 0x0020 /* RX MMPDU protection ON */ 245 #define IEEE80211_NODE_TXMGMTPROT 0x0040 /* TX MMPDU protection ON */ 246 #define IEEE80211_NODE_MFP 0x0080 /* MFP negotiated */ 247 #define IEEE80211_NODE_PMK 0x0100 /* ni_pmk set */ 248 #define IEEE80211_NODE_PMKID 0x0200 /* ni_pmkid set */ 249 #define IEEE80211_NODE_HT 0x0400 /* HT negotiated */ 250 #define IEEE80211_NODE_SA_QUERY 0x0800 /* SA Query in progress */ 251 #define IEEE80211_NODE_SA_QUERY_FAILED 0x1000 /* last SA Query failed */ 252 }; 253 254 RB_HEAD(ieee80211_tree, ieee80211_node); 255 256 static __inline void 257 ieee80211_node_incref(struct ieee80211_node *ni) 258 { 259 int s; 260 261 s = splnet(); 262 ni->ni_refcnt++; 263 splx(s); 264 } 265 266 static __inline u_int 267 ieee80211_node_decref(struct ieee80211_node *ni) 268 { 269 u_int refcnt; 270 int s; 271 272 s = splnet(); 273 refcnt = --ni->ni_refcnt; 274 splx(s); 275 return refcnt; 276 } 277 278 static __inline struct ieee80211_node * 279 ieee80211_ref_node(struct ieee80211_node *ni) 280 { 281 ieee80211_node_incref(ni); 282 return ni; 283 } 284 285 static __inline void 286 ieee80211_unref_node(struct ieee80211_node **ni) 287 { 288 ieee80211_node_decref(*ni); 289 *ni = NULL; /* guard against use */ 290 } 291 292 struct ieee80211com; 293 294 #ifdef MALLOC_DECLARE 295 MALLOC_DECLARE(M_80211_NODE); 296 #endif 297 298 extern void ieee80211_node_attach(struct ifnet *); 299 extern void ieee80211_node_lateattach(struct ifnet *); 300 extern void ieee80211_node_detach(struct ifnet *); 301 302 extern void ieee80211_begin_scan(struct ifnet *); 303 extern void ieee80211_next_scan(struct ifnet *); 304 extern void ieee80211_end_scan(struct ifnet *); 305 extern void ieee80211_reset_scan(struct ifnet *); 306 extern struct ieee80211_node *ieee80211_alloc_node(struct ieee80211com *, 307 const u_int8_t *); 308 extern struct ieee80211_node *ieee80211_dup_bss(struct ieee80211com *, 309 const u_int8_t *); 310 extern struct ieee80211_node *ieee80211_find_node(struct ieee80211com *, 311 const u_int8_t *); 312 extern struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *, 313 const struct ieee80211_frame *); 314 extern struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *, 315 const u_int8_t *); 316 extern struct ieee80211_node * 317 ieee80211_find_node_for_beacon(struct ieee80211com *, 318 const u_int8_t *, const struct ieee80211_channel *, 319 const char *, u_int8_t); 320 extern void ieee80211_release_node(struct ieee80211com *, 321 struct ieee80211_node *); 322 extern void ieee80211_free_allnodes(struct ieee80211com *); 323 typedef void ieee80211_iter_func(void *, struct ieee80211_node *); 324 extern void ieee80211_iterate_nodes(struct ieee80211com *ic, 325 ieee80211_iter_func *, void *); 326 extern void ieee80211_clean_nodes(struct ieee80211com *, int); 327 extern int ieee80211_setup_rates(struct ieee80211com *, 328 struct ieee80211_node *, const u_int8_t *, const u_int8_t *, int); 329 extern int ieee80211_iserp_sta(const struct ieee80211_node *); 330 331 extern void ieee80211_node_join(struct ieee80211com *, 332 struct ieee80211_node *, int); 333 extern void ieee80211_node_leave(struct ieee80211com *, 334 struct ieee80211_node *); 335 extern int ieee80211_match_bss(struct ieee80211com *, 336 struct ieee80211_node *); 337 extern void ieee80211_create_ibss(struct ieee80211com* , 338 struct ieee80211_channel *); 339 extern void ieee80211_notify_dtim(struct ieee80211com *); 340 extern void ieee80211_set_tim(struct ieee80211com *, int, int); 341 342 extern int ieee80211_node_cmp(const struct ieee80211_node *, 343 const struct ieee80211_node *); 344 RB_PROTOTYPE(ieee80211_tree, ieee80211_node, ni_node, ieee80211_node_cmp); 345 346 #endif /* _NET80211_IEEE80211_NODE_H_ */ 347