1*6e778a7eSPedro F. Giffuni /*-
2*6e778a7eSPedro F. Giffuni * SPDX-License-Identifier: ISC
3*6e778a7eSPedro F. Giffuni *
414779705SSam Leffler * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
514779705SSam Leffler * Copyright (c) 2002-2008 Atheros Communications, Inc.
614779705SSam Leffler *
714779705SSam Leffler * Permission to use, copy, modify, and/or distribute this software for any
814779705SSam Leffler * purpose with or without fee is hereby granted, provided that the above
914779705SSam Leffler * copyright notice and this permission notice appear in all copies.
1014779705SSam Leffler *
1114779705SSam Leffler * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1214779705SSam Leffler * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1314779705SSam Leffler * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1414779705SSam Leffler * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1514779705SSam Leffler * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1614779705SSam Leffler * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1714779705SSam Leffler * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1814779705SSam Leffler */
1914779705SSam Leffler #include "opt_ah.h"
2014779705SSam Leffler
2114779705SSam Leffler #include "ah.h"
2214779705SSam Leffler #include "ah_internal.h"
2314779705SSam Leffler
2414779705SSam Leffler #include "ar5416/ar5416.h"
2514779705SSam Leffler
2614779705SSam Leffler static const int keyType[] = {
2714779705SSam Leffler 1, /* HAL_CIPHER_WEP */
2814779705SSam Leffler 0, /* HAL_CIPHER_AES_OCB */
2914779705SSam Leffler 2, /* HAL_CIPHER_AES_CCM */
3014779705SSam Leffler 0, /* HAL_CIPHER_CKIP */
3114779705SSam Leffler 3, /* HAL_CIPHER_TKIP */
3214779705SSam Leffler 0, /* HAL_CIPHER_CLR */
3314779705SSam Leffler };
3414779705SSam Leffler
3514779705SSam Leffler /*
3614779705SSam Leffler * Clear the specified key cache entry and any associated MIC entry.
3714779705SSam Leffler */
3814779705SSam Leffler HAL_BOOL
ar5416ResetKeyCacheEntry(struct ath_hal * ah,uint16_t entry)3914779705SSam Leffler ar5416ResetKeyCacheEntry(struct ath_hal *ah, uint16_t entry)
4014779705SSam Leffler {
4114779705SSam Leffler struct ath_hal_5416 *ahp = AH5416(ah);
4214779705SSam Leffler
4314779705SSam Leffler if (ar5212ResetKeyCacheEntry(ah, entry)) {
4414779705SSam Leffler ahp->ah_keytype[entry] = keyType[HAL_CIPHER_CLR];
4514779705SSam Leffler return AH_TRUE;
4614779705SSam Leffler } else
4714779705SSam Leffler return AH_FALSE;
4814779705SSam Leffler }
4914779705SSam Leffler
5014779705SSam Leffler /*
5114779705SSam Leffler * Sets the contents of the specified key cache entry
5214779705SSam Leffler * and any associated MIC entry.
5314779705SSam Leffler */
5414779705SSam Leffler HAL_BOOL
ar5416SetKeyCacheEntry(struct ath_hal * ah,uint16_t entry,const HAL_KEYVAL * k,const uint8_t * mac,int xorKey)5514779705SSam Leffler ar5416SetKeyCacheEntry(struct ath_hal *ah, uint16_t entry,
5614779705SSam Leffler const HAL_KEYVAL *k, const uint8_t *mac,
5714779705SSam Leffler int xorKey)
5814779705SSam Leffler {
5914779705SSam Leffler struct ath_hal_5416 *ahp = AH5416(ah);
6014779705SSam Leffler
6114779705SSam Leffler if (ar5212SetKeyCacheEntry(ah, entry, k, mac, xorKey)) {
6214779705SSam Leffler ahp->ah_keytype[entry] = keyType[k->kv_type];
6314779705SSam Leffler return AH_TRUE;
6414779705SSam Leffler } else
6514779705SSam Leffler return AH_FALSE;
6614779705SSam Leffler }
67