1 /* $OpenBSD: ieee80211_priv.h,v 1.5 2009/01/26 19:09:41 damien Exp $ */ 2 3 /*- 4 * Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef _NET80211_IEEE80211_PRIV_H_ 20 #define _NET80211_IEEE80211_PRIV_H_ 21 22 #ifdef IEEE80211_DEBUG 23 extern int ieee80211_debug; 24 #define DPRINTF(X) do { \ 25 if (ieee80211_debug) { \ 26 printf("%s: ", __func__); \ 27 printf X; \ 28 } \ 29 } while(0) 30 #else 31 #define DPRINTF(X) 32 #endif 33 34 #define SEQ_LT(a,b) \ 35 ((((u_int16_t)(a) - (u_int16_t)(b)) & 0xfff) > 2048) 36 37 #define IEEE80211_AID_SET(b, w) \ 38 ((w)[IEEE80211_AID(b) / 32] |= (1 << (IEEE80211_AID(b) % 32))) 39 #define IEEE80211_AID_CLR(b, w) \ 40 ((w)[IEEE80211_AID(b) / 32] &= ~(1 << (IEEE80211_AID(b) % 32))) 41 #define IEEE80211_AID_ISSET(b, w) \ 42 ((w)[IEEE80211_AID(b) / 32] & (1 << (IEEE80211_AID(b) % 32))) 43 44 #define IEEE80211_RSNIE_MAXLEN \ 45 (2 + /* Version */ \ 46 4 + /* Group Data Cipher Suite */ \ 47 2 + /* Pairwise Cipher Suite Count */ \ 48 4 * 2 + /* Pairwise Cipher Suite List (max 2) */ \ 49 2 + /* AKM Suite List Count */ \ 50 4 * 4 + /* AKM Suite List (max 4) */ \ 51 2 + /* RSN Capabilities */ \ 52 2 + /* PMKID Count */ \ 53 16 * 1 + /* PMKID List (max 1) */ \ 54 4) /* 11w: Group Integrity Cipher Suite */ 55 56 #define IEEE80211_WPAIE_MAXLEN \ 57 (4 + /* MICROSOFT_OUI */ \ 58 2 + /* Version */ \ 59 4 + /* Group Cipher Suite */ \ 60 2 + /* Pairwise Cipher Suite Count */ \ 61 4 * 2 + /* Pairwise Cipher Suite List (max 2) */ \ 62 2 + /* AKM Suite List Count */ \ 63 4 * 2) /* AKM Suite List (max 2) */ 64 65 struct ieee80211_rsnparams { 66 u_int16_t rsn_nakms; 67 u_int32_t rsn_akms; 68 u_int16_t rsn_nciphers; 69 u_int32_t rsn_ciphers; 70 enum ieee80211_cipher rsn_groupcipher; 71 enum ieee80211_cipher rsn_groupmgmtcipher; 72 u_int16_t rsn_caps; 73 u_int8_t rsn_npmkids; 74 const u_int8_t *rsn_pmkids; 75 }; 76 77 /* unaligned big endian access */ 78 #define BE_READ_2(p) \ 79 ((u_int16_t) \ 80 ((((const u_int8_t *)(p))[0] << 8) | \ 81 (((const u_int8_t *)(p))[1]))) 82 83 #define BE_READ_8(p) \ 84 ((u_int64_t)(p)[0] << 56 | (u_int64_t)(p)[1] << 48 | \ 85 (u_int64_t)(p)[2] << 40 | (u_int64_t)(p)[3] << 32 | \ 86 (u_int64_t)(p)[4] << 24 | (u_int64_t)(p)[5] << 16 | \ 87 (u_int64_t)(p)[6] << 8 | (u_int64_t)(p)[7]) 88 89 #define BE_WRITE_2(p, v) do { \ 90 ((u_int8_t *)(p))[0] = (v) >> 8; \ 91 ((u_int8_t *)(p))[1] = (v) & 0xff; \ 92 } while (0) 93 94 #define BE_WRITE_8(p, v) do { \ 95 (p)[0] = (v) >> 56; (p)[1] = (v) >> 48; \ 96 (p)[2] = (v) >> 40; (p)[3] = (v) >> 32; \ 97 (p)[4] = (v) >> 24; (p)[5] = (v) >> 16; \ 98 (p)[6] = (v) >> 8; (p)[7] = (v); \ 99 } while (0) 100 101 /* unaligned little endian access */ 102 #define LE_READ_2(p) \ 103 ((u_int16_t) \ 104 ((((const u_int8_t *)(p))[0]) | \ 105 (((const u_int8_t *)(p))[1] << 8))) 106 107 #define LE_READ_4(p) \ 108 ((u_int32_t) \ 109 ((((const u_int8_t *)(p))[0]) | \ 110 (((const u_int8_t *)(p))[1] << 8) | \ 111 (((const u_int8_t *)(p))[2] << 16) | \ 112 (((const u_int8_t *)(p))[3] << 24))) 113 114 #define LE_READ_6(p) \ 115 ((u_int64_t)(p)[5] << 40 | (u_int64_t)(p)[4] << 32 | \ 116 (u_int64_t)(p)[3] << 24 | (u_int64_t)(p)[2] << 16 | \ 117 (u_int64_t)(p)[1] << 8 | (u_int64_t)(p)[0]) 118 119 #define LE_WRITE_2(p, v) do { \ 120 ((u_int8_t *)(p))[0] = (v) & 0xff; \ 121 ((u_int8_t *)(p))[1] = (v) >> 8; \ 122 } while (0) 123 124 #define LE_WRITE_4(p, v) do { \ 125 (p)[3] = (v) >> 24; (p)[2] = (v) >> 16; \ 126 (p)[1] = (v) >> 8; (p)[0] = (v); \ 127 } while (0) 128 129 #define LE_WRITE_6(p, v) do { \ 130 (p)[5] = (v) >> 40; (p)[4] = (v) >> 32; \ 131 (p)[3] = (v) >> 24; (p)[2] = (v) >> 16; \ 132 (p)[1] = (v) >> 8; (p)[0] = (v); \ 133 } while (0) 134 135 #endif /* _NET80211_IEEE80211_PRIV_H_ */ 136