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.
20 #include <linux/if_ether.h> /* for ETH_ALEN */
25 /* Maximum # of keys that wl driver supports in S/W.
26 * Keys supported in H/W is less than or equal to WSEC_MAX_KEYS.
28 #define WSEC_MAX_KEYS 54 /* Max # of keys (50 + 4 default keys) */
29 #define WLC_DEFAULT_KEYS 4 /* Default # of keys */
31 #define WSEC_MAX_WOWL_KEYS 5 /* Max keys in WOWL mode (1 + 4 default keys) */
33 #define WPA2_GTK_MAX 3
36 * Max # of keys currently supported:
38 * s/w keys if WSEC_SW(wlc->wsec).
41 #define WLC_MAX_WSEC_KEYS(wlc) WSEC_MAX_KEYS
43 /* number of 802.11 default (non-paired, group keys) */
44 #define WSEC_MAX_DEFAULT_KEYS 4 /* # of default keys */
46 /* Max # of hardware keys supported */
47 #define WLC_MAX_WSEC_HW_KEYS(wlc) WSEC_MAX_RCMTA_KEYS
49 /* Max # of hardware TKIP MIC keys supported */
50 #define WLC_MAX_TKMIC_HW_KEYS(wlc) (WSEC_MAX_TKMIC_ENGINE_KEYS)
52 #define WSEC_HW_TKMIC_KEY(wlc, key, bsscfg) \
53 ((((wlc)->machwcap & MCAP_TKIPMIC)) && \
54 (key) && ((key)->algo == CRYPTO_ALGO_TKIP) && \
55 !WSEC_SOFTKEY(wlc, key, bsscfg) && \
56 WSEC_KEY_INDEX(wlc, key) >= WLC_DEFAULT_KEYS && \
57 (WSEC_KEY_INDEX(wlc, key) < WSEC_MAX_TKMIC_ENGINE_KEYS))
59 /* index of key in key table */
60 #define WSEC_KEY_INDEX(wlc, key) ((key)->idx)
62 #define WSEC_SOFTKEY(wlc, key, bsscfg) (WLC_SW_KEYS(wlc, bsscfg) || \
63 WSEC_KEY_INDEX(wlc, key) >= WLC_MAX_WSEC_HW_KEYS(wlc))
65 /* get a key, non-NULL only if key allocated and not clear */
66 #define WSEC_KEY(wlc, i) (((wlc)->wsec_keys[i] && (wlc)->wsec_keys[i]->len) ? \
67 (wlc)->wsec_keys[i] : NULL)
69 #define WSEC_SCB_KEY_VALID(scb) (((scb)->key && (scb)->key->len) ? true : false)
72 #define WSEC_BSS_DEFAULT_KEY(bsscfg) (((bsscfg)->wsec_index == -1) ? \
73 (struct wsec_key *)NULL:(bsscfg)->bss_def_keys[(bsscfg)->wsec_index])
75 /* Macros for key management in IBSS mode */
76 #define WSEC_IBSS_MAX_PEERS 16 /* Max # of IBSS Peers */
77 #define WSEC_IBSS_RCMTA_INDEX(idx) \
78 (((idx - WSEC_MAX_DEFAULT_KEYS) % WSEC_IBSS_MAX_PEERS) + WSEC_MAX_DEFAULT_KEYS)
80 /* contiguous # key slots for infrastructure mode STA */
81 #define WSEC_BSS_STA_KEY_GROUP_SIZE 5
83 typedef struct wsec_iv {
84 u32 hi; /* upper 32 bits of IV */
85 u16 lo; /* lower 16 bits of IV */
88 #define WLC_NUMRXIVS 16 /* # rx IVs (one per 802.11e TID) */
90 typedef struct wsec_key {
91 u8 ea[ETH_ALEN]; /* per station */
92 u8 idx; /* key index in wsec_keys array */
93 u8 id; /* key ID [0-3] */
94 u8 algo; /* CRYPTO_ALGO_AES_CCM, CRYPTO_ALGO_WEP128, etc */
95 u8 rcmta; /* rcmta entry index, same as idx by default */
96 u16 flags; /* misc flags */
97 u8 algo_hw; /* cache for hw register */
98 u8 aes_mode; /* cache for hw register */
99 s8 iv_len; /* IV length */
100 s8 icv_len; /* ICV length */
101 u32 len; /* key length..don't move this var */
102 /* data is 4byte aligned */
103 u8 data[WLAN_MAX_KEY_LEN]; /* key data */
104 wsec_iv_t rxiv[WLC_NUMRXIVS]; /* Rx IV (one per TID) */
105 wsec_iv_t txiv; /* Tx IV */
109 #define broken_roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
111 /* For use with wsec_key_t.flags */
113 #define WSEC_BS_UPDATE (1 << 0) /* Indicates hw needs key update on BS switch */
114 #define WSEC_PRIMARY_KEY (1 << 1) /* Indicates this key is the primary (ie tx) key */
115 #define WSEC_TKIP_ERROR (1 << 2) /* Provoke deliberate MIC error */
116 #define WSEC_REPLAY_ERROR (1 << 3) /* Provoke deliberate replay */
117 #define WSEC_IBSS_PEER_GROUP_KEY (1 << 7) /* Flag: group key for a IBSS PEER */
118 #define WSEC_ICV_ERROR (1 << 8) /* Provoke deliberate ICV error */
120 #define wlc_key_insert(a, b, c, d, e, f, g, h, i, j) (-EBADE)
121 #define wlc_key_update(a, b, c) do {} while (0)
122 #define wlc_key_remove(a, b, c) do {} while (0)
123 #define wlc_key_remove_all(a, b) do {} while (0)
124 #define wlc_key_delete(a, b, c) do {} while (0)
125 #define wlc_scb_key_delete(a, b) do {} while (0)
126 #define wlc_key_lookup(a, b, c, d, e) (NULL)
127 #define wlc_key_hw_init_all(a) do {} while (0)
128 #define wlc_key_hw_init(a, b, c) do {} while (0)
129 #define wlc_key_hw_wowl_init(a, b, c, d) do {} while (0)
130 #define wlc_key_sw_wowl_update(a, b, c, d, e) do {} while (0)
131 #define wlc_key_sw_wowl_create(a, b, c) (-EBADE)
132 #define wlc_key_iv_update(a, b, c, d, e) do {(void)e; } while (0)
133 #define wlc_key_iv_init(a, b, c) do {} while (0)
134 #define wlc_key_set_error(a, b, c) (-EBADE)
135 #define wlc_key_dump_hw(a, b) (-EBADE)
136 #define wlc_key_dump_sw(a, b) (-EBADE)
137 #define wlc_key_defkeyflag(a) (0)
138 #define wlc_rcmta_add_bssid(a, b) do {} while (0)
139 #define wlc_rcmta_del_bssid(a, b) do {} while (0)
140 #define wlc_key_scb_delete(a, b) do {} while (0)
142 #endif /* _BRCM_KEY_H_ */