2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 /* Maximum # of keys that wl driver supports in S/W.
24 * Keys supported in H/W is less than or equal to WSEC_MAX_KEYS.
26 #define WSEC_MAX_KEYS 54 /* Max # of keys (50 + 4 default keys) */
27 #define WLC_DEFAULT_KEYS 4 /* Default # of keys */
29 #define WSEC_MAX_WOWL_KEYS 5 /* Max keys in WOWL mode (1 + 4 default keys) */
31 #define WPA2_GTK_MAX 3
34 * Max # of keys currently supported:
36 * s/w keys if WSEC_SW(wlc->wsec).
39 #define WLC_MAX_WSEC_KEYS(wlc) WSEC_MAX_KEYS
41 /* number of 802.11 default (non-paired, group keys) */
42 #define WSEC_MAX_DEFAULT_KEYS 4 /* # of default keys */
44 /* Max # of hardware keys supported */
45 #define WLC_MAX_WSEC_HW_KEYS(wlc) WSEC_MAX_RCMTA_KEYS
47 /* Max # of hardware TKIP MIC keys supported */
48 #define WLC_MAX_TKMIC_HW_KEYS(wlc) ((D11REV_GE((wlc)->pub->corerev, 13)) ? \
49 WSEC_MAX_TKMIC_ENGINE_KEYS : 0)
51 #define WSEC_HW_TKMIC_KEY(wlc, key, bsscfg) \
52 (((D11REV_GE((wlc)->pub->corerev, 13)) && ((wlc)->machwcap & MCAP_TKIPMIC)) && \
53 (key) && ((key)->algo == CRYPTO_ALGO_TKIP) && \
54 !WSEC_SOFTKEY(wlc, key, bsscfg) && \
55 WSEC_KEY_INDEX(wlc, key) >= WLC_DEFAULT_KEYS && \
56 (WSEC_KEY_INDEX(wlc, key) < WSEC_MAX_TKMIC_ENGINE_KEYS))
58 /* index of key in key table */
59 #define WSEC_KEY_INDEX(wlc, key) ((key)->idx)
61 #define WSEC_SOFTKEY(wlc, key, bsscfg) (WLC_SW_KEYS(wlc, bsscfg) || \
62 WSEC_KEY_INDEX(wlc, key) >= WLC_MAX_WSEC_HW_KEYS(wlc))
64 /* get a key, non-NULL only if key allocated and not clear */
65 #define WSEC_KEY(wlc, i) (((wlc)->wsec_keys[i] && (wlc)->wsec_keys[i]->len) ? \
66 (wlc)->wsec_keys[i] : NULL)
68 #define WSEC_SCB_KEY_VALID(scb) (((scb)->key && (scb)->key->len) ? TRUE : FALSE)
71 #define WSEC_BSS_DEFAULT_KEY(bsscfg) (((bsscfg)->wsec_index == -1) ? \
72 (struct wsec_key *)NULL : (bsscfg)->bss_def_keys[(bsscfg)->wsec_index])
74 /* Macros for key management in IBSS mode */
75 #define WSEC_IBSS_MAX_PEERS 16 /* Max # of IBSS Peers */
76 #define WSEC_IBSS_RCMTA_INDEX(idx) \
77 (((idx - WSEC_MAX_DEFAULT_KEYS) % WSEC_IBSS_MAX_PEERS) + WSEC_MAX_DEFAULT_KEYS)
79 /* contiguous # key slots for infrastructure mode STA */
80 #define WSEC_BSS_STA_KEY_GROUP_SIZE 5
82 typedef struct wsec_iv {
83 uint32 hi; /* upper 32 bits of IV */
84 uint16 lo; /* lower 16 bits of IV */
87 #define WLC_NUMRXIVS 16 /* # rx IVs (one per 802.11e TID) */
89 typedef struct wsec_key {
90 struct ether_addr ea; /* per station */
91 uint8 idx; /* key index in wsec_keys array */
92 uint8 id; /* key ID [0-3] */
93 uint8 algo; /* CRYPTO_ALGO_AES_CCM, CRYPTO_ALGO_WEP128, etc */
94 uint8 rcmta; /* rcmta entry index, same as idx by default */
95 uint16 flags; /* misc flags */
96 uint8 algo_hw; /* cache for hw register */
97 uint8 aes_mode; /* cache for hw register */
98 int8 iv_len; /* IV length */
99 int8 icv_len; /* ICV length */
100 uint32 len; /* key length..don't move this var */
101 /* data is 4byte aligned */
102 uint8 data[DOT11_MAX_KEY_SIZE]; /* key data */
103 wsec_iv_t rxiv[WLC_NUMRXIVS]; /* Rx IV (one per TID) */
104 wsec_iv_t txiv; /* Tx IV */
109 uint8 vec[ROUNDUP(WSEC_MAX_KEYS, NBBY) / NBBY]; /* bitvec of wsec_key indexes */
112 /* For use with wsec_key_t.flags */
114 #define WSEC_BS_UPDATE (1 << 0) /* Indicates hw needs key update on BS switch */
115 #define WSEC_PRIMARY_KEY (1 << 1) /* Indicates this key is the primary (ie tx) key */
116 #define WSEC_TKIP_ERROR (1 << 2) /* Provoke deliberate MIC error */
117 #define WSEC_REPLAY_ERROR (1 << 3) /* Provoke deliberate replay */
118 #define WSEC_IBSS_PEER_GROUP_KEY (1 << 7) /* Flag: group key for a IBSS PEER */
119 #define WSEC_ICV_ERROR (1 << 8) /* Provoke deliberate ICV error */
121 #define wlc_key_insert(a, b, c, d, e, f, g, h, i, j) (BCME_ERROR)
122 #define wlc_key_update(a, b, c) do {} while (0)
123 #define wlc_key_remove(a, b, c) do {} while (0)
124 #define wlc_key_remove_all(a, b) do {} while (0)
125 #define wlc_key_delete(a, b, c) do {} while (0)
126 #define wlc_scb_key_delete(a, b) do {} while (0)
127 #define wlc_key_lookup(a, b, c, d, e) (NULL)
128 #define wlc_key_hw_init_all(a) do {} while (0)
129 #define wlc_key_hw_init(a, b, c) do {} while (0)
130 #define wlc_key_hw_wowl_init(a, b, c, d) do {} while (0)
131 #define wlc_key_sw_wowl_update(a, b, c, d, e) do {} while (0)
132 #define wlc_key_sw_wowl_create(a, b, c) (BCME_ERROR)
133 #define wlc_key_iv_update(a, b, c, d, e) do {(void)e;} while (0)
134 #define wlc_key_iv_init(a, b, c) do {} while (0)
135 #define wlc_key_set_error(a, b, c) (BCME_ERROR)
136 #define wlc_key_dump_hw(a, b) (BCME_ERROR)
137 #define wlc_key_dump_sw(a, b) (BCME_ERROR)
138 #define wlc_key_defkeyflag(a) (0)
139 #define wlc_rcmta_add_bssid(a, b) do {} while (0)
140 #define wlc_rcmta_del_bssid(a, b) do {} while (0)
141 #define wlc_key_scb_delete(a, b) do {} while (0)
143 #endif /* _wlc_key_h_ */