Merge branch 'master' into net80211-update
[dragonfly.git] / sys / dev / netif / ath / hal / ath_hal / ar5416 / ar5416_keycache.c
1 /*
2  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3  * Copyright (c) 2002-2008 Atheros Communications, Inc.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  *
17  * $FreeBSD: head/sys/dev/ath/ath_hal/ar5416/ar5416_keycache.c 203158 2010-01-29 10:07:17Z rpaulo $
18  * $DragonFly$
19  */
20 #include "opt_ah.h"
21
22 #include "ah.h"
23 #include "ah_internal.h"
24
25 #include "ar5416/ar5416.h"
26
27 static const int keyType[] = {
28         1,      /* HAL_CIPHER_WEP */
29         0,      /* HAL_CIPHER_AES_OCB */
30         2,      /* HAL_CIPHER_AES_CCM */
31         0,      /* HAL_CIPHER_CKIP */
32         3,      /* HAL_CIPHER_TKIP */
33         0,      /* HAL_CIPHER_CLR */
34 };
35
36 /*
37  * Clear the specified key cache entry and any associated MIC entry.
38  */
39 HAL_BOOL
40 ar5416ResetKeyCacheEntry(struct ath_hal *ah, uint16_t entry)
41 {
42         struct ath_hal_5416 *ahp = AH5416(ah);
43
44         if (ar5212ResetKeyCacheEntry(ah, entry)) {
45                 ahp->ah_keytype[entry] = keyType[HAL_CIPHER_CLR];
46                 return AH_TRUE;
47         } else
48                 return AH_FALSE;
49 }
50
51 /*
52  * Sets the contents of the specified key cache entry
53  * and any associated MIC entry.
54  */
55 HAL_BOOL
56 ar5416SetKeyCacheEntry(struct ath_hal *ah, uint16_t entry,
57                        const HAL_KEYVAL *k, const uint8_t *mac,
58                        int xorKey)
59 {
60         struct ath_hal_5416 *ahp = AH5416(ah);
61
62         if (ar5212SetKeyCacheEntry(ah, entry, k, mac, xorKey)) {
63                 ahp->ah_keytype[entry] = keyType[k->kv_type];
64                 return AH_TRUE;
65         } else
66                 return AH_FALSE;
67 }