ieee80211_node.h 11 KB

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