Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * |
| 20 | * File: key.c |
| 21 | * |
| 22 | * Purpose: Implement functions for 802.11i Key management |
| 23 | * |
| 24 | * Author: Jerry Chen |
| 25 | * |
| 26 | * Date: May 29, 2003 |
| 27 | * |
| 28 | * Functions: |
| 29 | * KeyvInitTable - Init Key management table |
| 30 | * KeybGetKey - Get Key from table |
| 31 | * KeybSetKey - Set Key to table |
| 32 | * KeybRemoveKey - Remove Key from table |
| 33 | * KeybGetTransmitKey - Get Transmit Key from table |
| 34 | * |
| 35 | * Revision History: |
| 36 | * |
| 37 | */ |
| 38 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 39 | #include "tmacro.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 40 | #include "key.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 41 | #include "mac.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 42 | |
| 43 | /*--------------------- Static Definitions -------------------------*/ |
| 44 | |
| 45 | /*--------------------- Static Classes ----------------------------*/ |
| 46 | |
| 47 | /*--------------------- Static Variables --------------------------*/ |
| 48 | static int msglevel =MSG_LEVEL_INFO; |
| 49 | //static int msglevel =MSG_LEVEL_DEBUG; |
| 50 | /*--------------------- Static Functions --------------------------*/ |
| 51 | |
| 52 | /*--------------------- Export Variables --------------------------*/ |
| 53 | |
| 54 | /*--------------------- Static Definitions -------------------------*/ |
| 55 | |
| 56 | /*--------------------- Static Classes ----------------------------*/ |
| 57 | |
| 58 | /*--------------------- Static Variables --------------------------*/ |
| 59 | |
| 60 | /*--------------------- Static Functions --------------------------*/ |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 61 | static void |
Charles Clément | 412b2d0 | 2010-06-22 08:54:42 -0700 | [diff] [blame] | 62 | s_vCheckKeyTableValid (PSKeyManagement pTable, unsigned long dwIoBase) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 63 | { |
| 64 | int i; |
| 65 | |
| 66 | for (i=0;i<MAX_KEY_TABLE;i++) { |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 67 | if ((pTable->KeyTable[i].bInUse == true) && |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 68 | (pTable->KeyTable[i].PairwiseKey.bKeyValid == false) && |
| 69 | (pTable->KeyTable[i].GroupKey[0].bKeyValid == false) && |
| 70 | (pTable->KeyTable[i].GroupKey[1].bKeyValid == false) && |
| 71 | (pTable->KeyTable[i].GroupKey[2].bKeyValid == false) && |
| 72 | (pTable->KeyTable[i].GroupKey[3].bKeyValid == false) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 73 | ) { |
Jim Lieb | 612822f | 2009-08-12 14:54:03 -0700 | [diff] [blame] | 74 | |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 75 | pTable->KeyTable[i].bInUse = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 76 | pTable->KeyTable[i].wKeyCtl = 0; |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 77 | pTable->KeyTable[i].bSoftWEP = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 78 | MACvDisableKeyEntry(dwIoBase, i); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | |
| 84 | /*--------------------- Export Functions --------------------------*/ |
| 85 | |
| 86 | |
| 87 | /* |
| 88 | * Description: Init Key management table |
| 89 | * |
| 90 | * Parameters: |
| 91 | * In: |
| 92 | * pTable - Pointer to Key table |
| 93 | * Out: |
| 94 | * none |
| 95 | * |
| 96 | * Return Value: none |
| 97 | * |
| 98 | */ |
Charles Clément | 412b2d0 | 2010-06-22 08:54:42 -0700 | [diff] [blame] | 99 | void KeyvInitTable (PSKeyManagement pTable, unsigned long dwIoBase) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 100 | { |
| 101 | int i; |
| 102 | int jj; |
| 103 | |
| 104 | for (i=0;i<MAX_KEY_TABLE;i++) { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 105 | pTable->KeyTable[i].bInUse = false; |
| 106 | pTable->KeyTable[i].PairwiseKey.bKeyValid = false; |
Charles Clément | 830a619 | 2010-05-07 12:30:20 -0700 | [diff] [blame] | 107 | pTable->KeyTable[i].PairwiseKey.pvKeyTable = (void *)&pTable->KeyTable[i]; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 108 | for (jj=0; jj < MAX_GROUP_KEY; jj++) { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 109 | pTable->KeyTable[i].GroupKey[jj].bKeyValid = false; |
Charles Clément | 830a619 | 2010-05-07 12:30:20 -0700 | [diff] [blame] | 110 | pTable->KeyTable[i].GroupKey[jj].pvKeyTable = (void *)&pTable->KeyTable[i]; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 111 | } |
| 112 | pTable->KeyTable[i].wKeyCtl = 0; |
| 113 | pTable->KeyTable[i].dwGTKeyIndex = 0; |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 114 | pTable->KeyTable[i].bSoftWEP = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 115 | MACvDisableKeyEntry(dwIoBase, i); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | |
| 120 | /* |
| 121 | * Description: Get Key from table |
| 122 | * |
| 123 | * Parameters: |
| 124 | * In: |
| 125 | * pTable - Pointer to Key table |
| 126 | * pbyBSSID - BSSID of Key |
| 127 | * dwKeyIndex - Key Index (0xFFFFFFFF means pairwise key) |
| 128 | * Out: |
| 129 | * pKey - Key return |
| 130 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 131 | * Return Value: true if found otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 132 | * |
| 133 | */ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 134 | bool KeybGetKey ( |
Charles Clément | 3a215e0 | 2010-05-12 20:54:39 -0700 | [diff] [blame] | 135 | PSKeyManagement pTable, |
Charles Clément | 2989e96 | 2010-06-05 15:13:47 -0700 | [diff] [blame] | 136 | unsigned char *pbyBSSID, |
Charles Clément | 0f4c60d | 2010-06-24 11:02:25 -0700 | [diff] [blame] | 137 | unsigned long dwKeyIndex, |
Charles Clément | 3cdec55 | 2010-05-12 20:54:40 -0700 | [diff] [blame] | 138 | PSKeyItem *pKey |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 139 | ) |
| 140 | { |
| 141 | int i; |
| 142 | |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 143 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetKey() \n"); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 144 | |
| 145 | *pKey = NULL; |
| 146 | for (i=0;i<MAX_KEY_TABLE;i++) { |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 147 | if ((pTable->KeyTable[i].bInUse == true) && |
Charles Clément | 2ef98c6 | 2010-05-19 11:30:54 -0700 | [diff] [blame] | 148 | !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 149 | if (dwKeyIndex == 0xFFFFFFFF) { |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 150 | if (pTable->KeyTable[i].PairwiseKey.bKeyValid == true) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 151 | *pKey = &(pTable->KeyTable[i].PairwiseKey); |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 152 | return (true); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 153 | } |
| 154 | else { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 155 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 156 | } |
| 157 | } else if (dwKeyIndex < MAX_GROUP_KEY) { |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 158 | if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid == true) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 159 | *pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex]); |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 160 | return (true); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 161 | } |
| 162 | else { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 163 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | else { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 167 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | } |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 171 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | |
| 175 | /* |
| 176 | * Description: Set Key to table |
| 177 | * |
| 178 | * Parameters: |
| 179 | * In: |
| 180 | * pTable - Pointer to Key table |
| 181 | * pbyBSSID - BSSID of Key |
| 182 | * dwKeyIndex - Key index (reference to NDIS DDK) |
| 183 | * uKeyLength - Key length |
| 184 | * KeyRSC - Key RSC |
| 185 | * pbyKey - Pointer to key |
| 186 | * Out: |
| 187 | * none |
| 188 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 189 | * Return Value: true if success otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 190 | * |
| 191 | */ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 192 | bool KeybSetKey ( |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 193 | PSKeyManagement pTable, |
Charles Clément | 2989e96 | 2010-06-05 15:13:47 -0700 | [diff] [blame] | 194 | unsigned char *pbyBSSID, |
Charles Clément | 0f4c60d | 2010-06-24 11:02:25 -0700 | [diff] [blame] | 195 | unsigned long dwKeyIndex, |
Charles Clément | e3fd16d | 2010-06-02 09:52:02 -0700 | [diff] [blame] | 196 | unsigned long uKeyLength, |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 197 | PQWORD pKeyRSC, |
Charles Clément | 2989e96 | 2010-06-05 15:13:47 -0700 | [diff] [blame] | 198 | unsigned char *pbyKey, |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 199 | unsigned char byKeyDecMode, |
Charles Clément | 412b2d0 | 2010-06-22 08:54:42 -0700 | [diff] [blame] | 200 | unsigned long dwIoBase, |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 201 | unsigned char byLocalID |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 202 | ) |
| 203 | { |
| 204 | int i,j; |
Charles Clément | b6e95cd | 2010-06-02 09:52:01 -0700 | [diff] [blame] | 205 | unsigned int ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 206 | PSKeyItem pKey; |
Charles Clément | b6e95cd | 2010-06-02 09:52:01 -0700 | [diff] [blame] | 207 | unsigned int uKeyIdx; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 208 | |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 209 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetKey: %lX\n", dwKeyIndex); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 210 | |
| 211 | j = (MAX_KEY_TABLE-1); |
| 212 | for (i=0;i<(MAX_KEY_TABLE-1);i++) { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 213 | if ((pTable->KeyTable[i].bInUse == false) && |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 214 | (j == (MAX_KEY_TABLE-1))) { |
| 215 | // found empty table |
| 216 | j = i; |
| 217 | } |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 218 | if ((pTable->KeyTable[i].bInUse == true) && |
Charles Clément | 2ef98c6 | 2010-05-19 11:30:54 -0700 | [diff] [blame] | 219 | !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 220 | // found table already exist |
| 221 | if ((dwKeyIndex & PAIRWISE_KEY) != 0) { |
| 222 | // Pairwise key |
| 223 | pKey = &(pTable->KeyTable[i].PairwiseKey); |
| 224 | pTable->KeyTable[i].wKeyCtl &= 0xFFF0; // clear pairwise key control filed |
| 225 | pTable->KeyTable[i].wKeyCtl |= byKeyDecMode; |
| 226 | uKeyIdx = 4; // use HW key entry 4 for pairwise key |
| 227 | } else { |
| 228 | // Group key |
| 229 | if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 230 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 231 | pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]); |
| 232 | if ((dwKeyIndex & TRANSMIT_KEY) != 0) { |
| 233 | // Group transmit key |
| 234 | pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex; |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 235 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 236 | } |
| 237 | pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed |
| 238 | pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4); |
| 239 | pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address |
| 240 | uKeyIdx = (dwKeyIndex & 0x000000FF); |
| 241 | } |
| 242 | pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly |
| 243 | |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 244 | pKey->bKeyValid = true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 245 | pKey->uKeyLength = uKeyLength; |
| 246 | pKey->dwKeyIndex = dwKeyIndex; |
| 247 | pKey->byCipherSuite = byKeyDecMode; |
Jim Lieb | 51b6d9c | 2009-08-12 14:54:10 -0700 | [diff] [blame] | 248 | memcpy(pKey->abyKey, pbyKey, uKeyLength); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 249 | if (byKeyDecMode == KEY_CTL_WEP) { |
| 250 | if (uKeyLength == WLAN_WEP40_KEYLEN) |
| 251 | pKey->abyKey[15] &= 0x7F; |
| 252 | if (uKeyLength == WLAN_WEP104_KEYLEN) |
| 253 | pKey->abyKey[15] |= 0x80; |
| 254 | } |
Charles Clément | 9d828c4 | 2010-06-05 15:13:49 -0700 | [diff] [blame] | 255 | MACvSetKeyEntry(dwIoBase, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pbyBSSID, (unsigned long *)pKey->abyKey, byLocalID); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 256 | |
| 257 | if ((dwKeyIndex & USE_KEYRSC) == 0) { |
| 258 | // RSC set by NIC |
Jim Lieb | 51b6d9c | 2009-08-12 14:54:10 -0700 | [diff] [blame] | 259 | memset(&(pKey->KeyRSC), 0, sizeof(QWORD)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 260 | } |
| 261 | else { |
Jim Lieb | 51b6d9c | 2009-08-12 14:54:10 -0700 | [diff] [blame] | 262 | memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 263 | } |
| 264 | pKey->dwTSC47_16 = 0; |
| 265 | pKey->wTSC15_0 = 0; |
| 266 | |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 267 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n"); |
| 268 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid); |
| 269 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", pKey->uKeyLength); |
| 270 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: "); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 271 | for (ii = 0; ii < pKey->uKeyLength; ii++) { |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 272 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 273 | } |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 274 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n"); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 275 | |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 276 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16); |
| 277 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n ", pKey->wTSC15_0); |
| 278 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 279 | |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 280 | return (true); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | if (j < (MAX_KEY_TABLE-1)) { |
Charles Clément | 078b078 | 2010-05-14 19:37:32 -0700 | [diff] [blame] | 284 | memcpy(pTable->KeyTable[j].abyBSSID,pbyBSSID,ETH_ALEN); |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 285 | pTable->KeyTable[j].bInUse = true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 286 | if ((dwKeyIndex & PAIRWISE_KEY) != 0) { |
| 287 | // Pairwise key |
| 288 | pKey = &(pTable->KeyTable[j].PairwiseKey); |
| 289 | pTable->KeyTable[j].wKeyCtl &= 0xFFF0; // clear pairwise key control filed |
| 290 | pTable->KeyTable[j].wKeyCtl |= byKeyDecMode; |
| 291 | uKeyIdx = 4; // use HW key entry 4 for pairwise key |
| 292 | } else { |
| 293 | // Group key |
| 294 | if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 295 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 296 | pKey = &(pTable->KeyTable[j].GroupKey[dwKeyIndex & 0x000000FF]); |
| 297 | if ((dwKeyIndex & TRANSMIT_KEY) != 0) { |
| 298 | // Group transmit key |
| 299 | pTable->KeyTable[j].dwGTKeyIndex = dwKeyIndex; |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 300 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(N)[%lX]: %d\n", pTable->KeyTable[j].dwGTKeyIndex, j); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 301 | } |
| 302 | pTable->KeyTable[j].wKeyCtl &= 0xFF0F; // clear group key control filed |
| 303 | pTable->KeyTable[j].wKeyCtl |= (byKeyDecMode << 4); |
| 304 | pTable->KeyTable[j].wKeyCtl |= 0x0040; // use group key for group address |
| 305 | uKeyIdx = (dwKeyIndex & 0x000000FF); |
| 306 | } |
| 307 | pTable->KeyTable[j].wKeyCtl |= 0x8000; // enable on-fly |
| 308 | |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 309 | pKey->bKeyValid = true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 310 | pKey->uKeyLength = uKeyLength; |
| 311 | pKey->dwKeyIndex = dwKeyIndex; |
| 312 | pKey->byCipherSuite = byKeyDecMode; |
Jim Lieb | 51b6d9c | 2009-08-12 14:54:10 -0700 | [diff] [blame] | 313 | memcpy(pKey->abyKey, pbyKey, uKeyLength); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 314 | if (byKeyDecMode == KEY_CTL_WEP) { |
| 315 | if (uKeyLength == WLAN_WEP40_KEYLEN) |
| 316 | pKey->abyKey[15] &= 0x7F; |
| 317 | if (uKeyLength == WLAN_WEP104_KEYLEN) |
| 318 | pKey->abyKey[15] |= 0x80; |
| 319 | } |
Charles Clément | 9d828c4 | 2010-06-05 15:13:49 -0700 | [diff] [blame] | 320 | MACvSetKeyEntry(dwIoBase, pTable->KeyTable[j].wKeyCtl, j, uKeyIdx, pbyBSSID, (unsigned long *)pKey->abyKey, byLocalID); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 321 | |
| 322 | if ((dwKeyIndex & USE_KEYRSC) == 0) { |
| 323 | // RSC set by NIC |
Jim Lieb | 51b6d9c | 2009-08-12 14:54:10 -0700 | [diff] [blame] | 324 | memset(&(pKey->KeyRSC), 0, sizeof(QWORD)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 325 | } |
| 326 | else { |
Jim Lieb | 51b6d9c | 2009-08-12 14:54:10 -0700 | [diff] [blame] | 327 | memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 328 | } |
| 329 | pKey->dwTSC47_16 = 0; |
| 330 | pKey->wTSC15_0 = 0; |
| 331 | |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 332 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(N): \n"); |
| 333 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid); |
| 334 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength); |
| 335 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: "); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 336 | for (ii = 0; ii < pKey->uKeyLength; ii++) { |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 337 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 338 | } |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 339 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n"); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 340 | |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 341 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16); |
| 342 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n ", pKey->wTSC15_0); |
| 343 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 344 | |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 345 | return (true); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 346 | } |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 347 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | |
| 351 | /* |
| 352 | * Description: Remove Key from table |
| 353 | * |
| 354 | * Parameters: |
| 355 | * In: |
| 356 | * pTable - Pointer to Key table |
| 357 | * pbyBSSID - BSSID of Key |
| 358 | * dwKeyIndex - Key Index (reference to NDIS DDK) |
| 359 | * Out: |
| 360 | * none |
| 361 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 362 | * Return Value: true if success otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 363 | * |
| 364 | */ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 365 | bool KeybRemoveKey ( |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 366 | PSKeyManagement pTable, |
Charles Clément | 2989e96 | 2010-06-05 15:13:47 -0700 | [diff] [blame] | 367 | unsigned char *pbyBSSID, |
Charles Clément | 0f4c60d | 2010-06-24 11:02:25 -0700 | [diff] [blame] | 368 | unsigned long dwKeyIndex, |
Charles Clément | 412b2d0 | 2010-06-22 08:54:42 -0700 | [diff] [blame] | 369 | unsigned long dwIoBase |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 370 | ) |
| 371 | { |
| 372 | int i; |
| 373 | |
Charles Clément | ca9e12a | 2010-05-19 11:30:52 -0700 | [diff] [blame] | 374 | if (is_broadcast_ether_addr(pbyBSSID)) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 375 | // dealte all key |
| 376 | if ((dwKeyIndex & PAIRWISE_KEY) != 0) { |
| 377 | for (i=0;i<MAX_KEY_TABLE;i++) { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 378 | pTable->KeyTable[i].PairwiseKey.bKeyValid = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 379 | } |
| 380 | s_vCheckKeyTableValid(pTable, dwIoBase); |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 381 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 382 | } |
| 383 | else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { |
| 384 | for (i=0;i<MAX_KEY_TABLE;i++) { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 385 | pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 386 | if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) { |
| 387 | // remove Group transmit key |
| 388 | pTable->KeyTable[i].dwGTKeyIndex = 0; |
| 389 | } |
| 390 | } |
| 391 | s_vCheckKeyTableValid(pTable, dwIoBase); |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 392 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 393 | } |
| 394 | else { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 395 | return false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |
| 399 | for (i=0;i<MAX_KEY_TABLE;i++) { |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 400 | if ((pTable->KeyTable[i].bInUse == true) && |
Charles Clément | 2ef98c6 | 2010-05-19 11:30:54 -0700 | [diff] [blame] | 401 | !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 402 | if ((dwKeyIndex & PAIRWISE_KEY) != 0) { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 403 | pTable->KeyTable[i].PairwiseKey.bKeyValid = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 404 | s_vCheckKeyTableValid(pTable, dwIoBase); |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 405 | return (true); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 406 | } |
| 407 | else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 408 | pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 409 | if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) { |
| 410 | // remove Group transmit key |
| 411 | pTable->KeyTable[i].dwGTKeyIndex = 0; |
| 412 | } |
| 413 | s_vCheckKeyTableValid(pTable, dwIoBase); |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 414 | return (true); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 415 | } |
| 416 | else { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 417 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | } |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 421 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | |
| 425 | /* |
| 426 | * Description: Remove Key from table |
| 427 | * |
| 428 | * Parameters: |
| 429 | * In: |
| 430 | * pTable - Pointer to Key table |
| 431 | * pbyBSSID - BSSID of Key |
| 432 | * Out: |
| 433 | * none |
| 434 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 435 | * Return Value: true if success otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 436 | * |
| 437 | */ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 438 | bool KeybRemoveAllKey ( |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 439 | PSKeyManagement pTable, |
Charles Clément | 2989e96 | 2010-06-05 15:13:47 -0700 | [diff] [blame] | 440 | unsigned char *pbyBSSID, |
Charles Clément | 412b2d0 | 2010-06-22 08:54:42 -0700 | [diff] [blame] | 441 | unsigned long dwIoBase |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 442 | ) |
| 443 | { |
| 444 | int i,u; |
| 445 | |
| 446 | for (i=0;i<MAX_KEY_TABLE;i++) { |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 447 | if ((pTable->KeyTable[i].bInUse == true) && |
Charles Clément | 2ef98c6 | 2010-05-19 11:30:54 -0700 | [diff] [blame] | 448 | !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 449 | pTable->KeyTable[i].PairwiseKey.bKeyValid = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 450 | for(u=0;u<MAX_GROUP_KEY;u++) { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 451 | pTable->KeyTable[i].GroupKey[u].bKeyValid = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 452 | } |
| 453 | pTable->KeyTable[i].dwGTKeyIndex = 0; |
| 454 | s_vCheckKeyTableValid(pTable, dwIoBase); |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 455 | return (true); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 456 | } |
| 457 | } |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 458 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | /* |
| 462 | * Description: Remove WEP Key from table |
| 463 | * |
| 464 | * Parameters: |
| 465 | * In: |
| 466 | * pTable - Pointer to Key table |
| 467 | * Out: |
| 468 | * none |
| 469 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 470 | * Return Value: true if success otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 471 | * |
| 472 | */ |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 473 | void KeyvRemoveWEPKey ( |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 474 | PSKeyManagement pTable, |
Charles Clément | 0f4c60d | 2010-06-24 11:02:25 -0700 | [diff] [blame] | 475 | unsigned long dwKeyIndex, |
Charles Clément | 412b2d0 | 2010-06-22 08:54:42 -0700 | [diff] [blame] | 476 | unsigned long dwIoBase |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 477 | ) |
| 478 | { |
| 479 | |
| 480 | if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 481 | if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == true) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 482 | if (pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].byCipherSuite == KEY_CTL_WEP) { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 483 | pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 484 | if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex & 0x7FFFFFFF)) { |
| 485 | // remove Group transmit key |
| 486 | pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = 0; |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | s_vCheckKeyTableValid(pTable, dwIoBase); |
| 491 | } |
| 492 | return; |
| 493 | } |
| 494 | |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 495 | void KeyvRemoveAllWEPKey ( |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 496 | PSKeyManagement pTable, |
Charles Clément | 412b2d0 | 2010-06-22 08:54:42 -0700 | [diff] [blame] | 497 | unsigned long dwIoBase |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 498 | ) |
| 499 | { |
| 500 | int i; |
| 501 | |
| 502 | for(i=0;i<MAX_GROUP_KEY;i++) { |
| 503 | KeyvRemoveWEPKey(pTable, i, dwIoBase); |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | /* |
| 508 | * Description: Get Transmit Key from table |
| 509 | * |
| 510 | * Parameters: |
| 511 | * In: |
| 512 | * pTable - Pointer to Key table |
| 513 | * pbyBSSID - BSSID of Key |
| 514 | * Out: |
| 515 | * pKey - Key return |
| 516 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 517 | * Return Value: true if found otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 518 | * |
| 519 | */ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 520 | bool KeybGetTransmitKey ( |
Charles Clément | 3a215e0 | 2010-05-12 20:54:39 -0700 | [diff] [blame] | 521 | PSKeyManagement pTable, |
Charles Clément | 2989e96 | 2010-06-05 15:13:47 -0700 | [diff] [blame] | 522 | unsigned char *pbyBSSID, |
Charles Clément | 0f4c60d | 2010-06-24 11:02:25 -0700 | [diff] [blame] | 523 | unsigned long dwKeyType, |
Charles Clément | 3cdec55 | 2010-05-12 20:54:40 -0700 | [diff] [blame] | 524 | PSKeyItem *pKey |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 525 | ) |
| 526 | { |
| 527 | int i, ii; |
| 528 | |
| 529 | *pKey = NULL; |
| 530 | for (i=0;i<MAX_KEY_TABLE;i++) { |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 531 | if ((pTable->KeyTable[i].bInUse == true) && |
Charles Clément | 2ef98c6 | 2010-05-19 11:30:54 -0700 | [diff] [blame] | 532 | !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 533 | |
| 534 | if (dwKeyType == PAIRWISE_KEY) { |
| 535 | |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 536 | if (pTable->KeyTable[i].PairwiseKey.bKeyValid == true) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 537 | *pKey = &(pTable->KeyTable[i].PairwiseKey); |
| 538 | |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 539 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:"); |
| 540 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PAIRWISE_KEY: KeyTable.abyBSSID: "); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 541 | for (ii = 0; ii < 6; ii++) { |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 542 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x ", pTable->KeyTable[i].abyBSSID[ii]); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 543 | } |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 544 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n"); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 545 | |
| 546 | |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 547 | return (true); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 548 | } |
| 549 | else { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 550 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PairwiseKey.bKeyValid == false\n"); |
| 551 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 552 | } |
| 553 | } // End of Type == PAIRWISE |
| 554 | else { |
| 555 | if (pTable->KeyTable[i].dwGTKeyIndex == 0) { |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 556 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: dwGTKeyIndex == 0 !!!\n"); |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 557 | return false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 558 | } |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 559 | if (pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)].bKeyValid == true) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 560 | *pKey = &(pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)]); |
| 561 | |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 562 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:"); |
| 563 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GROUP_KEY: KeyTable.abyBSSID\n"); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 564 | for (ii = 0; ii < 6; ii++) { |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 565 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x ", pTable->KeyTable[i].abyBSSID[ii]); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 566 | } |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 567 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n"); |
| 568 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"dwGTKeyIndex: %lX\n", pTable->KeyTable[i].dwGTKeyIndex); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 569 | |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 570 | return (true); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 571 | } |
| 572 | else { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 573 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GroupKey.bKeyValid == false\n"); |
| 574 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 575 | } |
| 576 | } // End of Type = GROUP |
| 577 | } // BSSID match |
| 578 | } |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 579 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: NO Match BSSID !!! "); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 580 | for (ii = 0; ii < 6; ii++) { |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 581 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(pbyBSSID+ii)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 582 | } |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 583 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n"); |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 584 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | |
| 588 | /* |
| 589 | * Description: Check Pairewise Key |
| 590 | * |
| 591 | * Parameters: |
| 592 | * In: |
| 593 | * pTable - Pointer to Key table |
| 594 | * Out: |
| 595 | * none |
| 596 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 597 | * Return Value: true if found otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 598 | * |
| 599 | */ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 600 | bool KeybCheckPairewiseKey ( |
Charles Clément | 3a215e0 | 2010-05-12 20:54:39 -0700 | [diff] [blame] | 601 | PSKeyManagement pTable, |
Charles Clément | 3cdec55 | 2010-05-12 20:54:40 -0700 | [diff] [blame] | 602 | PSKeyItem *pKey |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 603 | ) |
| 604 | { |
| 605 | int i; |
| 606 | |
| 607 | *pKey = NULL; |
| 608 | for (i=0;i<MAX_KEY_TABLE;i++) { |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 609 | if ((pTable->KeyTable[i].bInUse == true) && |
| 610 | (pTable->KeyTable[i].PairwiseKey.bKeyValid == true)) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 611 | *pKey = &(pTable->KeyTable[i].PairwiseKey); |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 612 | return (true); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 613 | } |
| 614 | } |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 615 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /* |
| 619 | * Description: Set Key to table |
| 620 | * |
| 621 | * Parameters: |
| 622 | * In: |
| 623 | * pTable - Pointer to Key table |
| 624 | * dwKeyIndex - Key index (reference to NDIS DDK) |
| 625 | * uKeyLength - Key length |
| 626 | * KeyRSC - Key RSC |
| 627 | * pbyKey - Pointer to key |
| 628 | * Out: |
| 629 | * none |
| 630 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 631 | * Return Value: true if success otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 632 | * |
| 633 | */ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 634 | bool KeybSetDefaultKey ( |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 635 | PSKeyManagement pTable, |
Charles Clément | 0f4c60d | 2010-06-24 11:02:25 -0700 | [diff] [blame] | 636 | unsigned long dwKeyIndex, |
Charles Clément | e3fd16d | 2010-06-02 09:52:02 -0700 | [diff] [blame] | 637 | unsigned long uKeyLength, |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 638 | PQWORD pKeyRSC, |
Charles Clément | 2989e96 | 2010-06-05 15:13:47 -0700 | [diff] [blame] | 639 | unsigned char *pbyKey, |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 640 | unsigned char byKeyDecMode, |
Charles Clément | 412b2d0 | 2010-06-22 08:54:42 -0700 | [diff] [blame] | 641 | unsigned long dwIoBase, |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 642 | unsigned char byLocalID |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 643 | ) |
| 644 | { |
Charles Clément | b6e95cd | 2010-06-02 09:52:01 -0700 | [diff] [blame] | 645 | unsigned int ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 646 | PSKeyItem pKey; |
Charles Clément | b6e95cd | 2010-06-02 09:52:01 -0700 | [diff] [blame] | 647 | unsigned int uKeyIdx; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 648 | |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 649 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetDefaultKey: %1x, %d \n", (int)dwKeyIndex, (int)uKeyLength); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 650 | |
| 651 | |
| 652 | if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 653 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 654 | } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 655 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 656 | } |
| 657 | |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 658 | pTable->KeyTable[MAX_KEY_TABLE-1].bInUse = true; |
Charles Clément | 078b078 | 2010-05-14 19:37:32 -0700 | [diff] [blame] | 659 | for(ii=0;ii<ETH_ALEN;ii++) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 660 | pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID[ii] = 0xFF; |
| 661 | |
| 662 | // Group key |
| 663 | pKey = &(pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF]); |
| 664 | if ((dwKeyIndex & TRANSMIT_KEY) != 0) { |
| 665 | // Group transmit key |
| 666 | pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = dwKeyIndex; |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 667 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex, MAX_KEY_TABLE-1); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 668 | |
| 669 | } |
| 670 | pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl &= 0x7F00; // clear all key control filed |
| 671 | pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode << 4); |
| 672 | pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode); |
| 673 | pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x0044; // use group key for all address |
| 674 | uKeyIdx = (dwKeyIndex & 0x000000FF); |
| 675 | |
| 676 | if ((uKeyLength == WLAN_WEP232_KEYLEN) && |
| 677 | (byKeyDecMode == KEY_CTL_WEP)) { |
| 678 | pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x4000; // disable on-fly disable address match |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 679 | pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP = true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 680 | } else { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 681 | if (pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP == false) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 682 | pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0xC000; // enable on-fly disable address match |
| 683 | } |
| 684 | |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 685 | pKey->bKeyValid = true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 686 | pKey->uKeyLength = uKeyLength; |
| 687 | pKey->dwKeyIndex = dwKeyIndex; |
| 688 | pKey->byCipherSuite = byKeyDecMode; |
Jim Lieb | 51b6d9c | 2009-08-12 14:54:10 -0700 | [diff] [blame] | 689 | memcpy(pKey->abyKey, pbyKey, uKeyLength); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 690 | if (byKeyDecMode == KEY_CTL_WEP) { |
| 691 | if (uKeyLength == WLAN_WEP40_KEYLEN) |
| 692 | pKey->abyKey[15] &= 0x7F; |
| 693 | if (uKeyLength == WLAN_WEP104_KEYLEN) |
| 694 | pKey->abyKey[15] |= 0x80; |
| 695 | } |
Charles Clément | 9d828c4 | 2010-06-05 15:13:49 -0700 | [diff] [blame] | 696 | MACvSetKeyEntry(dwIoBase, pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl, MAX_KEY_TABLE-1, uKeyIdx, pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID, (unsigned long *)pKey->abyKey, byLocalID); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 697 | |
| 698 | if ((dwKeyIndex & USE_KEYRSC) == 0) { |
| 699 | // RSC set by NIC |
Jim Lieb | 51b6d9c | 2009-08-12 14:54:10 -0700 | [diff] [blame] | 700 | memset(&(pKey->KeyRSC), 0, sizeof(QWORD)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 701 | } else { |
Jim Lieb | 51b6d9c | 2009-08-12 14:54:10 -0700 | [diff] [blame] | 702 | memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 703 | } |
| 704 | pKey->dwTSC47_16 = 0; |
| 705 | pKey->wTSC15_0 = 0; |
| 706 | |
| 707 | |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 708 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n"); |
| 709 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n", pKey->bKeyValid); |
| 710 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n", (int)pKey->uKeyLength); |
| 711 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: \n"); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 712 | for (ii = 0; ii < pKey->uKeyLength; ii++) { |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 713 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x", pKey->abyKey[ii]); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 714 | } |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 715 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n"); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 716 | |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 717 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n", pKey->dwTSC47_16); |
| 718 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n", pKey->wTSC15_0); |
| 719 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n", pKey->dwKeyIndex); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 720 | |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 721 | return (true); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | |
| 725 | /* |
| 726 | * Description: Set Key to table |
| 727 | * |
| 728 | * Parameters: |
| 729 | * In: |
| 730 | * pTable - Pointer to Key table |
| 731 | * dwKeyIndex - Key index (reference to NDIS DDK) |
| 732 | * uKeyLength - Key length |
| 733 | * KeyRSC - Key RSC |
| 734 | * pbyKey - Pointer to key |
| 735 | * Out: |
| 736 | * none |
| 737 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 738 | * Return Value: true if success otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 739 | * |
| 740 | */ |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 741 | bool KeybSetAllGroupKey ( |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 742 | PSKeyManagement pTable, |
Charles Clément | 0f4c60d | 2010-06-24 11:02:25 -0700 | [diff] [blame] | 743 | unsigned long dwKeyIndex, |
Charles Clément | e3fd16d | 2010-06-02 09:52:02 -0700 | [diff] [blame] | 744 | unsigned long uKeyLength, |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 745 | PQWORD pKeyRSC, |
Charles Clément | 2989e96 | 2010-06-05 15:13:47 -0700 | [diff] [blame] | 746 | unsigned char *pbyKey, |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 747 | unsigned char byKeyDecMode, |
Charles Clément | 412b2d0 | 2010-06-22 08:54:42 -0700 | [diff] [blame] | 748 | unsigned long dwIoBase, |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 749 | unsigned char byLocalID |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 750 | ) |
| 751 | { |
| 752 | int i; |
Charles Clément | b6e95cd | 2010-06-02 09:52:01 -0700 | [diff] [blame] | 753 | unsigned int ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 754 | PSKeyItem pKey; |
Charles Clément | b6e95cd | 2010-06-02 09:52:01 -0700 | [diff] [blame] | 755 | unsigned int uKeyIdx; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 756 | |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 757 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetAllGroupKey: %lX\n", dwKeyIndex); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 758 | |
| 759 | |
| 760 | if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 761 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 762 | } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 763 | return (false); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | for (i=0; i < MAX_KEY_TABLE-1; i++) { |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 767 | if (pTable->KeyTable[i].bInUse == true) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 768 | // found table already exist |
| 769 | // Group key |
| 770 | pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]); |
| 771 | if ((dwKeyIndex & TRANSMIT_KEY) != 0) { |
| 772 | // Group transmit key |
| 773 | pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex; |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 774 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 775 | |
| 776 | } |
| 777 | pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed |
| 778 | pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4); |
| 779 | pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address |
| 780 | uKeyIdx = (dwKeyIndex & 0x000000FF); |
| 781 | |
| 782 | pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly |
| 783 | |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 784 | pKey->bKeyValid = true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 785 | pKey->uKeyLength = uKeyLength; |
| 786 | pKey->dwKeyIndex = dwKeyIndex; |
| 787 | pKey->byCipherSuite = byKeyDecMode; |
Jim Lieb | 51b6d9c | 2009-08-12 14:54:10 -0700 | [diff] [blame] | 788 | memcpy(pKey->abyKey, pbyKey, uKeyLength); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 789 | if (byKeyDecMode == KEY_CTL_WEP) { |
| 790 | if (uKeyLength == WLAN_WEP40_KEYLEN) |
| 791 | pKey->abyKey[15] &= 0x7F; |
| 792 | if (uKeyLength == WLAN_WEP104_KEYLEN) |
| 793 | pKey->abyKey[15] |= 0x80; |
| 794 | } |
Charles Clément | 9d828c4 | 2010-06-05 15:13:49 -0700 | [diff] [blame] | 795 | MACvSetKeyEntry(dwIoBase, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pTable->KeyTable[i].abyBSSID, (unsigned long *)pKey->abyKey, byLocalID); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 796 | |
| 797 | if ((dwKeyIndex & USE_KEYRSC) == 0) { |
| 798 | // RSC set by NIC |
Jim Lieb | 51b6d9c | 2009-08-12 14:54:10 -0700 | [diff] [blame] | 799 | memset(&(pKey->KeyRSC), 0, sizeof(QWORD)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 800 | } |
| 801 | else { |
Jim Lieb | 51b6d9c | 2009-08-12 14:54:10 -0700 | [diff] [blame] | 802 | memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 803 | } |
| 804 | pKey->dwTSC47_16 = 0; |
| 805 | pKey->wTSC15_0 = 0; |
| 806 | |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 807 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n"); |
| 808 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid); |
| 809 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength); |
| 810 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: "); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 811 | for (ii = 0; ii < pKey->uKeyLength; ii++) { |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 812 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", pKey->abyKey[ii]); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 813 | } |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 814 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n"); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 815 | |
| 816 | //DBG_PRN_GRP12(("pKey->dwTSC47_16: %lX\n ", pKey->dwTSC47_16)); |
| 817 | //DBG_PRN_GRP12(("pKey->wTSC15_0: %X\n ", pKey->wTSC15_0)); |
| 818 | //DBG_PRN_GRP12(("pKey->dwKeyIndex: %lX\n ", pKey->dwKeyIndex)); |
| 819 | |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 820 | } // (pTable->KeyTable[i].bInUse == true) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 821 | } |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 822 | return (true); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 823 | } |