1 /* $OpenBSD: ieee80211_node.h,v 1.60 2016/04/28 08:18:10 stsp 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 #include <sys/tree.h> 37 38 #define IEEE80211_PSCAN_WAIT 5 /* passive scan wait */ 39 #define IEEE80211_TRANS_WAIT 5 /* transition wait */ 40 #define IEEE80211_INACT_WAIT 5 /* inactivity timer interval */ 41 #define IEEE80211_INACT_MAX (300/IEEE80211_INACT_WAIT) 42 #define IEEE80211_CACHE_SIZE 100 43 #define IEEE80211_CACHE_WAIT 3600 44 45 struct ieee80211_rateset { 46 u_int8_t rs_nrates; 47 u_int8_t rs_rates[IEEE80211_RATE_MAXSIZE]; 48 }; 49 50 extern const struct ieee80211_rateset ieee80211_std_rateset_11a; 51 extern const struct ieee80211_rateset ieee80211_std_rateset_11b; 52 extern const struct ieee80211_rateset ieee80211_std_rateset_11g; 53 54 enum ieee80211_node_state { 55 IEEE80211_STA_CACHE, /* cached node */ 56 IEEE80211_STA_BSS, /* ic->ic_bss, the network we joined */ 57 IEEE80211_STA_AUTH, /* successfully authenticated */ 58 IEEE80211_STA_ASSOC, /* successfully associated */ 59 IEEE80211_STA_COLLECT /* This node remains in the cache while 60 * the driver sends a de-auth message; 61 * afterward it should be freed to make room 62 * for a new node. 63 */ 64 }; 65 66 #define ieee80211_node_newstate(__ni, __state) \ 67 do { \ 68 (__ni)->ni_state = (__state); \ 69 } while (0) 70 71 enum ieee80211_node_psstate { 72 IEEE80211_PS_AWAKE, 73 IEEE80211_PS_DOZE 74 }; 75 76 #define IEEE80211_PS_MAX_QUEUE 50 /* maximum saved packets */ 77 78 /* Authenticator state machine: 4-Way Handshake (see 8.5.6.1.1) */ 79 enum { 80 RSNA_INITIALIZE, 81 RSNA_AUTHENTICATION, 82 RSNA_AUTHENTICATION_2, 83 RSNA_INITPMK, 84 RSNA_INITPSK, 85 RSNA_PTKSTART, 86 RSNA_PTKCALCNEGOTIATING, 87 RSNA_PTKCALCNEGOTIATING_2, 88 RSNA_PTKINITNEGOTIATING, 89 RSNA_PTKINITDONE, 90 RSNA_DISCONNECT, 91 RSNA_DISCONNECTED 92 }; 93 94 /* Authenticator state machine: Group Key Handshake (see 8.5.6.1.2) */ 95 enum { 96 RSNA_IDLE, 97 RSNA_REKEYNEGOTIATING, 98 RSNA_REKEYESTABLISHED, 99 RSNA_KEYERROR 100 }; 101 102 struct ieee80211_rxinfo { 103 u_int32_t rxi_flags; 104 u_int32_t rxi_tstamp; 105 int rxi_rssi; 106 }; 107 #define IEEE80211_RXI_HWDEC 0x00000001 108 #define IEEE80211_RXI_AMPDU_DONE 0x00000002 109 110 /* Block Acknowledgement Record */ 111 struct ieee80211_tx_ba { 112 struct ieee80211_node *ba_ni; /* backpointer for callbacks */ 113 struct timeout ba_to; 114 int ba_timeout_val; 115 int ba_state; 116 #define IEEE80211_BA_INIT 0 117 #define IEEE80211_BA_REQUESTED 1 118 #define IEEE80211_BA_AGREED 2 119 120 /* ADDBA parameter set field for this BA agreement. */ 121 u_int16_t ba_params; 122 123 /* These values are IEEE802.11 frame sequence numbers (0x0-0xfff) */ 124 u_int16_t ba_winstart; 125 u_int16_t ba_winend; 126 127 /* Number of A-MPDU subframes in reorder buffer. */ 128 u_int16_t ba_winsize; 129 #define IEEE80211_BA_MAX_WINSZ 64 /* corresponds to maximum ADDBA BUFSZ */ 130 131 u_int8_t ba_token; 132 }; 133 134 struct ieee80211_rx_ba { 135 struct ieee80211_node *ba_ni; /* backpointer for callbacks */ 136 struct { 137 struct mbuf *m; 138 struct ieee80211_rxinfo rxi; 139 } *ba_buf; 140 struct timeout ba_to; 141 int ba_timeout_val; 142 int ba_state; 143 u_int16_t ba_params; 144 u_int16_t ba_winstart; 145 u_int16_t ba_winend; 146 u_int16_t ba_winsize; 147 u_int16_t ba_head; 148 struct timeout ba_gap_to; 149 #define IEEE80211_BA_GAP_TIMEOUT 300 /* msec */ 150 /* Counter for consecutive frames which missed the BA window. */ 151 int ba_winmiss; 152 /* Sequence number of previous frame which missed the BA window. */ 153 uint16_t ba_missedsn; 154 /* Window moves forward after this many frames have missed it. */ 155 #define IEEE80211_BA_MAX_WINMISS 8 156 }; 157 158 /* 159 * Node specific information. Note that drivers are expected 160 * to derive from this structure to add device-specific per-node 161 * state. This is done by overriding the ic_node_* methods in 162 * the ieee80211com structure. 163 */ 164 struct ieee80211_node { 165 RB_ENTRY(ieee80211_node) ni_node; 166 167 struct ieee80211com *ni_ic; /* back-pointer */ 168 169 u_int ni_refcnt; 170 u_int ni_scangen; /* gen# for timeout scan */ 171 172 /* hardware */ 173 u_int32_t ni_rstamp; /* recv timestamp */ 174 u_int8_t ni_rssi; /* recv ssi */ 175 176 /* header */ 177 u_int8_t ni_macaddr[IEEE80211_ADDR_LEN]; 178 u_int8_t ni_bssid[IEEE80211_ADDR_LEN]; 179 180 /* beacon, probe response */ 181 u_int8_t ni_tstamp[8]; /* from last rcv'd beacon */ 182 u_int16_t ni_intval; /* beacon interval */ 183 u_int16_t ni_capinfo; /* capabilities */ 184 u_int8_t ni_esslen; 185 u_int8_t ni_essid[IEEE80211_NWID_LEN]; 186 struct ieee80211_rateset ni_rates; /* negotiated rate set */ 187 u_int8_t *ni_country; /* country information XXX */ 188 struct ieee80211_channel *ni_chan; 189 u_int8_t ni_erp; /* 11g only */ 190 191 #ifdef notyet 192 /* DTIM and contention free period (CFP) */ 193 u_int8_t ni_dtimperiod; 194 u_int8_t ni_cfpperiod; /* # of DTIMs between CFPs */ 195 u_int16_t ni_cfpduremain; /* remaining cfp duration */ 196 u_int16_t ni_cfpmaxduration;/* max CFP duration in TU */ 197 u_int16_t ni_nextdtim; /* time to next DTIM */ 198 u_int16_t ni_timoffset; 199 #endif 200 201 /* power saving mode */ 202 u_int8_t ni_pwrsave; 203 struct mbuf_queue ni_savedq; /* packets queued for pspoll */ 204 205 /* RSN */ 206 struct timeout ni_eapol_to; 207 u_int ni_rsn_state; 208 u_int ni_rsn_gstate; 209 u_int ni_rsn_retries; 210 u_int ni_rsnprotos; 211 u_int ni_rsnakms; 212 u_int ni_rsnciphers; 213 enum ieee80211_cipher ni_rsngroupcipher; 214 enum ieee80211_cipher ni_rsngroupmgmtcipher; 215 u_int16_t ni_rsncaps; 216 enum ieee80211_cipher ni_rsncipher; 217 u_int8_t ni_nonce[EAPOL_KEY_NONCE_LEN]; 218 u_int8_t ni_pmk[IEEE80211_PMK_LEN]; 219 u_int8_t ni_pmkid[IEEE80211_PMKID_LEN]; 220 u_int64_t ni_replaycnt; 221 u_int8_t ni_replaycnt_ok; 222 u_int64_t ni_reqreplaycnt; 223 u_int8_t ni_reqreplaycnt_ok; 224 u_int8_t *ni_rsnie; 225 struct ieee80211_key ni_pairwise_key; 226 struct ieee80211_ptk ni_ptk; 227 u_int8_t ni_key_count; 228 int ni_port_valid; 229 230 /* SA Query */ 231 u_int16_t ni_sa_query_trid; 232 struct timeout ni_sa_query_to; 233 int ni_sa_query_count; 234 235 /* HT capabilities */ 236 uint16_t ni_htcaps; 237 uint8_t ni_ampdu_param; 238 uint8_t ni_rxmcs[howmany(80,NBBY)]; 239 uint16_t ni_max_rxrate; /* in Mb/s, 0 <= rate <= 1023 */ 240 uint8_t ni_tx_mcs_set; 241 uint16_t ni_htxcaps; 242 uint32_t ni_txbfcaps; 243 uint8_t ni_aselcaps; 244 245 /* HT operation */ 246 uint8_t ni_primary_chan; /* XXX corresponds to ni_chan */ 247 uint8_t ni_htop0; 248 uint16_t ni_htop1; 249 uint16_t ni_htop2; 250 uint8_t ni_basic_mcs[howmany(128,NBBY)]; 251 252 /* Block Ack records */ 253 struct ieee80211_tx_ba ni_tx_ba[IEEE80211_NUM_TID]; 254 struct ieee80211_rx_ba ni_rx_ba[IEEE80211_NUM_TID]; 255 256 int ni_txmcs; /* current MCS used for TX */ 257 258 /* others */ 259 u_int16_t ni_associd; /* assoc response */ 260 u_int16_t ni_txseq; /* seq to be transmitted */ 261 u_int16_t ni_rxseq; /* seq previous received */ 262 u_int16_t ni_qos_txseqs[IEEE80211_NUM_TID]; 263 u_int16_t ni_qos_rxseqs[IEEE80211_NUM_TID]; 264 int ni_fails; /* failure count to associate */ 265 int ni_inact; /* inactivity mark count */ 266 int ni_txrate; /* index to ni_rates[] */ 267 int ni_state; 268 269 u_int16_t ni_flags; /* special-purpose state */ 270 #define IEEE80211_NODE_ERP 0x0001 271 #define IEEE80211_NODE_QOS 0x0002 272 #define IEEE80211_NODE_REKEY 0x0004 /* GTK rekeying in progress */ 273 #define IEEE80211_NODE_RXPROT 0x0008 /* RX protection ON */ 274 #define IEEE80211_NODE_TXPROT 0x0010 /* TX protection ON */ 275 #define IEEE80211_NODE_TXRXPROT \ 276 (IEEE80211_NODE_TXPROT | IEEE80211_NODE_RXPROT) 277 #define IEEE80211_NODE_RXMGMTPROT 0x0020 /* RX MMPDU protection ON */ 278 #define IEEE80211_NODE_TXMGMTPROT 0x0040 /* TX MMPDU protection ON */ 279 #define IEEE80211_NODE_MFP 0x0080 /* MFP negotiated */ 280 #define IEEE80211_NODE_PMK 0x0100 /* ni_pmk set */ 281 #define IEEE80211_NODE_PMKID 0x0200 /* ni_pmkid set */ 282 #define IEEE80211_NODE_HT 0x0400 /* HT negotiated */ 283 #define IEEE80211_NODE_SA_QUERY 0x0800 /* SA Query in progress */ 284 #define IEEE80211_NODE_SA_QUERY_FAILED 0x1000 /* last SA Query failed */ 285 }; 286 287 RB_HEAD(ieee80211_tree, ieee80211_node); 288 289 static __inline void 290 ieee80211_node_incref(struct ieee80211_node *ni) 291 { 292 int s; 293 294 s = splnet(); 295 ni->ni_refcnt++; 296 splx(s); 297 } 298 299 static __inline u_int 300 ieee80211_node_decref(struct ieee80211_node *ni) 301 { 302 u_int refcnt; 303 int s; 304 305 s = splnet(); 306 refcnt = --ni->ni_refcnt; 307 splx(s); 308 return refcnt; 309 } 310 311 static __inline struct ieee80211_node * 312 ieee80211_ref_node(struct ieee80211_node *ni) 313 { 314 ieee80211_node_incref(ni); 315 return ni; 316 } 317 318 static __inline void 319 ieee80211_unref_node(struct ieee80211_node **ni) 320 { 321 ieee80211_node_decref(*ni); 322 *ni = NULL; /* guard against use */ 323 } 324 325 struct ieee80211com; 326 327 #ifdef MALLOC_DECLARE 328 MALLOC_DECLARE(M_80211_NODE); 329 #endif 330 331 extern void ieee80211_node_attach(struct ifnet *); 332 extern void ieee80211_node_lateattach(struct ifnet *); 333 extern void ieee80211_node_detach(struct ifnet *); 334 335 extern void ieee80211_begin_scan(struct ifnet *); 336 extern void ieee80211_next_scan(struct ifnet *); 337 extern void ieee80211_end_scan(struct ifnet *); 338 extern void ieee80211_reset_scan(struct ifnet *); 339 extern struct ieee80211_node *ieee80211_alloc_node(struct ieee80211com *, 340 const u_int8_t *); 341 extern struct ieee80211_node *ieee80211_dup_bss(struct ieee80211com *, 342 const u_int8_t *); 343 extern struct ieee80211_node *ieee80211_find_node(struct ieee80211com *, 344 const u_int8_t *); 345 extern struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *, 346 const struct ieee80211_frame *); 347 extern struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *, 348 const u_int8_t *); 349 extern struct ieee80211_node * 350 ieee80211_find_node_for_beacon(struct ieee80211com *, 351 const u_int8_t *, const struct ieee80211_channel *, 352 const char *, u_int8_t); 353 extern void ieee80211_release_node(struct ieee80211com *, 354 struct ieee80211_node *); 355 extern void ieee80211_free_allnodes(struct ieee80211com *); 356 typedef void ieee80211_iter_func(void *, struct ieee80211_node *); 357 extern void ieee80211_iterate_nodes(struct ieee80211com *ic, 358 ieee80211_iter_func *, void *); 359 extern void ieee80211_clean_cached(struct ieee80211com *ic); 360 extern void ieee80211_clean_nodes(struct ieee80211com *, int); 361 void ieee80211_setup_htcaps(struct ieee80211_node *, const uint8_t *, 362 uint8_t); 363 int ieee80211_setup_htop(struct ieee80211_node *, const uint8_t *, 364 uint8_t); 365 extern int ieee80211_setup_rates(struct ieee80211com *, 366 struct ieee80211_node *, const u_int8_t *, const u_int8_t *, int); 367 extern int ieee80211_iserp_sta(const struct ieee80211_node *); 368 369 extern void ieee80211_node_join(struct ieee80211com *, 370 struct ieee80211_node *, int); 371 extern void ieee80211_node_leave(struct ieee80211com *, 372 struct ieee80211_node *); 373 extern int ieee80211_match_bss(struct ieee80211com *, 374 struct ieee80211_node *); 375 extern void ieee80211_create_ibss(struct ieee80211com* , 376 struct ieee80211_channel *); 377 extern void ieee80211_notify_dtim(struct ieee80211com *); 378 extern void ieee80211_set_tim(struct ieee80211com *, int, int); 379 380 extern int ieee80211_node_cmp(const struct ieee80211_node *, 381 const struct ieee80211_node *); 382 RB_PROTOTYPE(ieee80211_tree, ieee80211_node, ni_node, ieee80211_node_cmp); 383 384 #endif /* _NET80211_IEEE80211_NODE_H_ */ 385