iPXE
ath_key.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009 Atheros Communications Inc.
00003  * Copyright (c) 2010 Bruno Randolf <br1@einfach.org>
00004  *
00005  * Modified for iPXE by Scott K Logan <logans@cottsay.net> July 2011
00006  * Original from Linux kernel 3.0.1
00007  *
00008  * Permission to use, copy, modify, and/or distribute this software for any
00009  * purpose with or without fee is hereby granted, provided that the above
00010  * copyright notice and this permission notice appear in all copies.
00011  *
00012  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00013  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00014  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
00015  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00016  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00017  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00018  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00019  */
00020 
00021 #include "ath.h"
00022 #include "reg.h"
00023 
00024 #define REG_READ                        (common->ops->read)
00025 #define REG_WRITE(_ah, _reg, _val)      (common->ops->write)(_ah, _val, _reg)
00026 #define ENABLE_REGWRITE_BUFFER(_ah)                     \
00027         if (common->ops->enable_write_buffer)           \
00028                 common->ops->enable_write_buffer((_ah));
00029 
00030 #define REGWRITE_BUFFER_FLUSH(_ah)                      \
00031         if (common->ops->write_flush)                   \
00032                 common->ops->write_flush((_ah));
00033 
00034 
00035 #define IEEE80211_WEP_NKID      4       /* number of key ids */
00036 
00037 /************************/
00038 /* Key Cache Management */
00039 /************************/
00040 
00041 int ath_hw_keyreset(struct ath_common *common, u16 entry)
00042 {
00043         u32 keyType;
00044         void *ah = common->ah;
00045 
00046         if (entry >= common->keymax) {
00047                 DBG("ath: keycache entry %d out of range\n", entry);
00048                 return 0;
00049         }
00050 
00051         keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
00052 
00053         ENABLE_REGWRITE_BUFFER(ah);
00054 
00055         REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
00056         REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
00057         REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
00058         REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
00059         REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
00060         REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
00061         REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
00062         REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
00063 
00064         if (keyType == AR_KEYTABLE_TYPE_TKIP) {
00065                 u16 micentry = entry + 64;
00066 
00067                 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
00068                 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
00069                 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
00070                 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
00071                 if (common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED) {
00072                         REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
00073                         REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
00074                                   AR_KEYTABLE_TYPE_CLR);
00075                 }
00076 
00077         }
00078 
00079         REGWRITE_BUFFER_FLUSH(ah);
00080 
00081         return 1;
00082 }