1185377Ssam/*
2185377Ssam * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3185377Ssam * Copyright (c) 2002-2008 Atheros Communications, Inc.
4185377Ssam *
5185377Ssam * Permission to use, copy, modify, and/or distribute this software for any
6185377Ssam * purpose with or without fee is hereby granted, provided that the above
7185377Ssam * copyright notice and this permission notice appear in all copies.
8185377Ssam *
9185377Ssam * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10185377Ssam * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11185377Ssam * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12185377Ssam * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13185377Ssam * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14185377Ssam * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15185377Ssam * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16185377Ssam *
17203158Srpaulo * $FreeBSD$
18185377Ssam */
19185377Ssam#include "opt_ah.h"
20185377Ssam
21185377Ssam#include "ah.h"
22185377Ssam#include "ah_internal.h"
23185377Ssam
24185377Ssam#include "ar5416/ar5416.h"
25185377Ssam
26185377Ssamstatic const int keyType[] = {
27185377Ssam	1,	/* HAL_CIPHER_WEP */
28185377Ssam	0,	/* HAL_CIPHER_AES_OCB */
29185377Ssam	2,	/* HAL_CIPHER_AES_CCM */
30185377Ssam	0,	/* HAL_CIPHER_CKIP */
31185377Ssam	3,	/* HAL_CIPHER_TKIP */
32185377Ssam	0,	/* HAL_CIPHER_CLR */
33185377Ssam};
34185377Ssam
35185377Ssam/*
36185377Ssam * Clear the specified key cache entry and any associated MIC entry.
37185377Ssam */
38185377SsamHAL_BOOL
39185377Ssamar5416ResetKeyCacheEntry(struct ath_hal *ah, uint16_t entry)
40185377Ssam{
41185377Ssam	struct ath_hal_5416 *ahp = AH5416(ah);
42185377Ssam
43185377Ssam	if (ar5212ResetKeyCacheEntry(ah, entry)) {
44185377Ssam		ahp->ah_keytype[entry] = keyType[HAL_CIPHER_CLR];
45185377Ssam		return AH_TRUE;
46185377Ssam	} else
47185377Ssam		return AH_FALSE;
48185377Ssam}
49185377Ssam
50185377Ssam/*
51185377Ssam * Sets the contents of the specified key cache entry
52185377Ssam * and any associated MIC entry.
53185377Ssam */
54185377SsamHAL_BOOL
55185377Ssamar5416SetKeyCacheEntry(struct ath_hal *ah, uint16_t entry,
56185377Ssam                       const HAL_KEYVAL *k, const uint8_t *mac,
57185377Ssam                       int xorKey)
58185377Ssam{
59185377Ssam	struct ath_hal_5416 *ahp = AH5416(ah);
60185377Ssam
61185377Ssam	if (ar5212SetKeyCacheEntry(ah, entry, k, mac, xorKey)) {
62185377Ssam		ahp->ah_keytype[entry] = keyType[k->kv_type];
63185377Ssam		return AH_TRUE;
64185377Ssam	} else
65185377Ssam		return AH_FALSE;
66185377Ssam}
67