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