2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
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.
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.
22 * Purpose: Implement functions for 802.11i Key management
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
45 /*--------------------- Static Definitions -------------------------*/
47 /*--------------------- Static Classes ----------------------------*/
49 /*--------------------- Static Variables --------------------------*/
50 static int msglevel =MSG_LEVEL_INFO;
51 //static int msglevel =MSG_LEVEL_DEBUG;
52 /*--------------------- Static Functions --------------------------*/
54 /*--------------------- Export Variables --------------------------*/
56 /*--------------------- Static Definitions -------------------------*/
58 /*--------------------- Static Classes ----------------------------*/
60 /*--------------------- Static Variables --------------------------*/
62 /*--------------------- Static Functions --------------------------*/
64 s_vCheckKeyTableValid (PVOID pDeviceHandler, PSKeyManagement pTable)
66 PSDevice pDevice = (PSDevice) pDeviceHandler;
69 BYTE pbyData[MAX_KEY_TABLE];
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)
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);
88 CONTROLnsRequestOut(pDevice,
89 MESSAGE_TYPE_CLRKEYENTRY,
100 /*--------------------- Export Functions --------------------------*/
104 * Description: Init Key management table
108 * pTable - Pointer to Key table
115 VOID KeyvInitTable(PVOID pDeviceHandler, PSKeyManagement pTable)
117 PSDevice pDevice = (PSDevice) pDeviceHandler;
120 BYTE pbyData[MAX_KEY_TABLE+1];
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;
126 pTable->KeyTable[i].PairwiseKey.pvKeyTable = (PVOID)&pTable->KeyTable[i];
127 for (jj=0; jj < MAX_GROUP_KEY; jj++) {
128 pTable->KeyTable[i].GroupKey[jj].bKeyValid = FALSE;
129 pTable->KeyTable[i].GroupKey[jj].pvKeyTable = (PVOID) &(pTable->KeyTable[i]);
131 pTable->KeyTable[i].wKeyCtl = 0;
132 pTable->KeyTable[i].dwGTKeyIndex = 0;
133 pTable->KeyTable[i].bSoftWEP = FALSE;
134 pbyData[i] = (BYTE) i;
136 pbyData[i] = (BYTE) i;
137 CONTROLnsRequestOut(pDevice,
138 MESSAGE_TYPE_CLRKEYENTRY,
145 spin_unlock_irq(&pDevice->lock);
152 * Description: Get Key from table
156 * pTable - Pointer to Key table
157 * pbyBSSID - BSSID of Key
158 * dwKeyIndex - Key Index (0xFFFFFFFF means pairwise key)
162 * Return Value: TRUE if found otherwise FALSE
166 IN PSKeyManagement pTable,
174 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetKey() \n");
177 for (i=0;i<MAX_KEY_TABLE;i++) {
178 if ((pTable->KeyTable[i].bInUse == TRUE) &&
179 IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) {
180 if (dwKeyIndex == 0xFFFFFFFF) {
181 if (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE) {
182 *pKey = &(pTable->KeyTable[i].PairwiseKey);
188 } else if (dwKeyIndex < MAX_GROUP_KEY) {
189 if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid == TRUE) {
190 *pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex]);
207 * Description: Set Key to table
211 * pTable - Pointer to Key table
212 * pbyBSSID - BSSID of Key
213 * dwKeyIndex - Key index (reference to NDIS DDK)
214 * uKeyLength - Key length
216 * pbyKey - Pointer to key
220 * Return Value: TRUE if success otherwise FALSE
224 PVOID pDeviceHandler,
225 PSKeyManagement pTable,
234 PSDevice pDevice = (PSDevice) pDeviceHandler;
240 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetKey: %lX\n", dwKeyIndex);
242 j = (MAX_KEY_TABLE-1);
243 for (i=0;i<(MAX_KEY_TABLE-1);i++) {
244 if ((pTable->KeyTable[i].bInUse == FALSE) &&
245 (j == (MAX_KEY_TABLE-1))) {
249 if ((pTable->KeyTable[i].bInUse == TRUE) &&
250 IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) {
251 // found table already exist
252 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
254 pKey = &(pTable->KeyTable[i].PairwiseKey);
255 pTable->KeyTable[i].wKeyCtl &= 0xFFF0; // clear pairwise key control filed
256 pTable->KeyTable[i].wKeyCtl |= byKeyDecMode;
257 uKeyIdx = 4; // use HW key entry 4 for pairwise key
260 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
262 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
263 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
264 // Group transmit key
265 pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
266 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i);
268 pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed
269 pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
270 pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address
271 uKeyIdx = (dwKeyIndex & 0x000000FF);
273 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly
275 pKey->bKeyValid = TRUE;
276 pKey->uKeyLength = uKeyLength;
277 pKey->dwKeyIndex = dwKeyIndex;
278 pKey->byCipherSuite = byKeyDecMode;
279 memcpy(pKey->abyKey, pbyKey, uKeyLength);
280 if (byKeyDecMode == KEY_CTL_WEP) {
281 if (uKeyLength == WLAN_WEP40_KEYLEN)
282 pKey->abyKey[15] &= 0x7F;
283 if (uKeyLength == WLAN_WEP104_KEYLEN)
284 pKey->abyKey[15] |= 0x80;
286 MACvSetKeyEntry(pDevice, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey);
288 if ((dwKeyIndex & USE_KEYRSC) == 0) {
290 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
293 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
295 pKey->dwTSC47_16 = 0;
298 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
299 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
300 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", pKey->uKeyLength);
301 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
302 for (ii = 0; ii < pKey->uKeyLength; ii++) {
303 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
305 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
307 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16);
308 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
309 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex);
314 if (j < (MAX_KEY_TABLE-1)) {
315 memcpy(pTable->KeyTable[j].abyBSSID,pbyBSSID,U_ETHER_ADDR_LEN);
316 pTable->KeyTable[j].bInUse = TRUE;
317 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
319 pKey = &(pTable->KeyTable[j].PairwiseKey);
320 pTable->KeyTable[j].wKeyCtl &= 0xFFF0; // clear pairwise key control filed
321 pTable->KeyTable[j].wKeyCtl |= byKeyDecMode;
322 uKeyIdx = 4; // use HW key entry 4 for pairwise key
325 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
327 pKey = &(pTable->KeyTable[j].GroupKey[dwKeyIndex & 0x000000FF]);
328 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
329 // Group transmit key
330 pTable->KeyTable[j].dwGTKeyIndex = dwKeyIndex;
331 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(N)[%lX]: %d\n", pTable->KeyTable[j].dwGTKeyIndex, j);
333 pTable->KeyTable[j].wKeyCtl &= 0xFF0F; // clear group key control filed
334 pTable->KeyTable[j].wKeyCtl |= (byKeyDecMode << 4);
335 pTable->KeyTable[j].wKeyCtl |= 0x0040; // use group key for group address
336 uKeyIdx = (dwKeyIndex & 0x000000FF);
338 pTable->KeyTable[j].wKeyCtl |= 0x8000; // enable on-fly
340 pKey->bKeyValid = TRUE;
341 pKey->uKeyLength = uKeyLength;
342 pKey->dwKeyIndex = dwKeyIndex;
343 pKey->byCipherSuite = byKeyDecMode;
344 memcpy(pKey->abyKey, pbyKey, uKeyLength);
345 if (byKeyDecMode == KEY_CTL_WEP) {
346 if (uKeyLength == WLAN_WEP40_KEYLEN)
347 pKey->abyKey[15] &= 0x7F;
348 if (uKeyLength == WLAN_WEP104_KEYLEN)
349 pKey->abyKey[15] |= 0x80;
351 MACvSetKeyEntry(pDevice, pTable->KeyTable[j].wKeyCtl, j, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey);
353 if ((dwKeyIndex & USE_KEYRSC) == 0) {
355 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
358 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
360 pKey->dwTSC47_16 = 0;
363 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(N): \n");
364 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
365 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
366 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
367 for (ii = 0; ii < pKey->uKeyLength; ii++) {
368 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
370 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
372 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16);
373 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
374 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex);
383 * Description: Remove Key from table
387 * pTable - Pointer to Key table
388 * pbyBSSID - BSSID of Key
389 * dwKeyIndex - Key Index (reference to NDIS DDK)
393 * Return Value: TRUE if success otherwise FALSE
397 PVOID pDeviceHandler,
398 PSKeyManagement pTable,
403 PSDevice pDevice = (PSDevice) pDeviceHandler;
405 BOOL bReturnValue = FALSE;
407 if (IS_BROADCAST_ADDRESS(pbyBSSID)) {
409 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
410 for (i=0;i<MAX_KEY_TABLE;i++) {
411 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE;
415 else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
416 for (i=0;i<MAX_KEY_TABLE;i++) {
417 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE;
418 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
419 // remove Group transmit key
420 pTable->KeyTable[i].dwGTKeyIndex = 0;
426 bReturnValue = FALSE;
430 for (i=0;i<MAX_KEY_TABLE;i++) {
431 if ( (pTable->KeyTable[i].bInUse == TRUE) &&
432 IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) {
434 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
435 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE;
439 else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
440 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE;
441 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
442 // remove Group transmit key
443 pTable->KeyTable[i].dwGTKeyIndex = 0;
449 bReturnValue = FALSE;
452 } //pTable->KeyTable[i].bInUse == TRUE
457 s_vCheckKeyTableValid(pDevice,pTable);
465 * Description: Remove Key from table
469 * pTable - Pointer to Key table
470 * pbyBSSID - BSSID of Key
474 * Return Value: TRUE if success otherwise FALSE
477 BOOL KeybRemoveAllKey (
478 PVOID pDeviceHandler,
479 PSKeyManagement pTable,
483 PSDevice pDevice = (PSDevice) pDeviceHandler;
486 for (i=0;i<MAX_KEY_TABLE;i++) {
487 if ((pTable->KeyTable[i].bInUse == TRUE) &&
488 IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) {
489 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE;
490 for(u=0;u<MAX_GROUP_KEY;u++) {
491 pTable->KeyTable[i].GroupKey[u].bKeyValid = FALSE;
493 pTable->KeyTable[i].dwGTKeyIndex = 0;
494 s_vCheckKeyTableValid(pDevice, pTable);
502 * Description: Remove WEP Key from table
506 * pTable - Pointer to Key table
510 * Return Value: TRUE if success otherwise FALSE
513 VOID KeyvRemoveWEPKey (
514 PVOID pDeviceHandler,
515 PSKeyManagement pTable,
519 PSDevice pDevice = (PSDevice) pDeviceHandler;
521 if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
522 if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == TRUE) {
523 if (pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].byCipherSuite == KEY_CTL_WEP) {
524 pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE;
525 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex & 0x7FFFFFFF)) {
526 // remove Group transmit key
527 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = 0;
531 s_vCheckKeyTableValid(pDevice, pTable);
536 VOID KeyvRemoveAllWEPKey (
537 PVOID pDeviceHandler,
538 PSKeyManagement pTable
541 PSDevice pDevice = (PSDevice) pDeviceHandler;
545 for(i=0;i<MAX_GROUP_KEY;i++) {
546 KeyvRemoveWEPKey(pDevice,pTable, i);
552 * Description: Get Transmit Key from table
556 * pTable - Pointer to Key table
557 * pbyBSSID - BSSID of Key
561 * Return Value: TRUE if found otherwise FALSE
564 BOOL KeybGetTransmitKey (
565 IN PSKeyManagement pTable,
574 for (i=0;i<MAX_KEY_TABLE;i++) {
575 if ((pTable->KeyTable[i].bInUse == TRUE) &&
576 IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) {
578 if (dwKeyType == PAIRWISE_KEY) {
580 if (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE) {
581 *pKey = &(pTable->KeyTable[i].PairwiseKey);
583 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:");
584 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PAIRWISE_KEY: KeyTable.abyBSSID: ");
585 for (ii = 0; ii < 6; ii++) {
586 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x ", pTable->KeyTable[i].abyBSSID[ii]);
588 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
594 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PairwiseKey.bKeyValid == FALSE\n");
597 } // End of Type == PAIRWISE
599 if (pTable->KeyTable[i].dwGTKeyIndex == 0) {
600 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: dwGTKeyIndex == 0 !!!\n");
603 if (pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)].bKeyValid == TRUE) {
604 *pKey = &(pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)]);
606 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:");
607 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GROUP_KEY: KeyTable.abyBSSID\n");
608 for (ii = 0; ii < 6; ii++) {
609 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x ", pTable->KeyTable[i].abyBSSID[ii]);
611 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
612 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"dwGTKeyIndex: %lX\n", pTable->KeyTable[i].dwGTKeyIndex);
617 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GroupKey.bKeyValid == FALSE\n");
620 } // End of Type = GROUP
623 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: NO Match BSSID !!! ");
624 for (ii = 0; ii < 6; ii++) {
625 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(pbyBSSID+ii));
627 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
633 * Description: Check Pairewise Key
637 * pTable - Pointer to Key table
641 * Return Value: TRUE if found otherwise FALSE
644 BOOL KeybCheckPairewiseKey (
645 IN PSKeyManagement pTable,
652 for (i=0;i<MAX_KEY_TABLE;i++) {
653 if ((pTable->KeyTable[i].bInUse == TRUE) &&
654 (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE)) {
655 *pKey = &(pTable->KeyTable[i].PairwiseKey);
663 * Description: Set Key to table
667 * pTable - Pointer to Key table
668 * dwKeyIndex - Key index (reference to NDIS DDK)
669 * uKeyLength - Key length
671 * pbyKey - Pointer to key
675 * Return Value: TRUE if success otherwise FALSE
678 BOOL KeybSetDefaultKey (
679 PVOID pDeviceHandler,
680 PSKeyManagement pTable,
688 PSDevice pDevice = (PSDevice) pDeviceHandler;
693 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetDefaultKey: %1x, %d \n", (int)dwKeyIndex, (int)uKeyLength);
696 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key
698 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
702 pTable->KeyTable[MAX_KEY_TABLE-1].bInUse = TRUE;
703 for(ii=0;ii<U_ETHER_ADDR_LEN;ii++)
704 pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID[ii] = 0xFF;
707 pKey = &(pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF]);
708 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
709 // Group transmit key
710 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = dwKeyIndex;
711 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 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl &= 0x7F00; // clear all key control filed
715 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode << 4);
716 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode);
717 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x0044; // use group key for all address
718 uKeyIdx = (dwKeyIndex & 0x000000FF);
720 if ((uKeyLength == WLAN_WEP232_KEYLEN) &&
721 (byKeyDecMode == KEY_CTL_WEP)) {
722 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x4000; // disable on-fly disable address match
723 pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP = TRUE;
725 if (pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP == FALSE)
726 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0xC000; // enable on-fly disable address match
729 pKey->bKeyValid = TRUE;
730 pKey->uKeyLength = uKeyLength;
731 pKey->dwKeyIndex = dwKeyIndex;
732 pKey->byCipherSuite = byKeyDecMode;
733 memcpy(pKey->abyKey, pbyKey, uKeyLength);
734 if (byKeyDecMode == KEY_CTL_WEP) {
735 if (uKeyLength == WLAN_WEP40_KEYLEN)
736 pKey->abyKey[15] &= 0x7F;
737 if (uKeyLength == WLAN_WEP104_KEYLEN)
738 pKey->abyKey[15] |= 0x80;
741 MACvSetKeyEntry(pDevice, pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl, MAX_KEY_TABLE-1, uKeyIdx, pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID, (PDWORD) pKey->abyKey);
743 if ((dwKeyIndex & USE_KEYRSC) == 0) {
745 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
747 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
749 pKey->dwTSC47_16 = 0;
753 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
754 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n", pKey->bKeyValid);
755 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n", (int)pKey->uKeyLength);
756 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: \n");
757 for (ii = 0; ii < pKey->uKeyLength; ii++) {
758 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x", pKey->abyKey[ii]);
760 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
762 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n", pKey->dwTSC47_16);
763 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n", pKey->wTSC15_0);
764 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n", pKey->dwKeyIndex);
771 * Description: Set Key to table
775 * pTable - Pointer to Key table
776 * dwKeyIndex - Key index (reference to NDIS DDK)
777 * uKeyLength - Key length
779 * pbyKey - Pointer to key
783 * Return Value: TRUE if success otherwise FALSE
786 BOOL KeybSetAllGroupKey (
787 PVOID pDeviceHandler,
788 PSKeyManagement pTable,
796 PSDevice pDevice = (PSDevice) pDeviceHandler;
802 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetAllGroupKey: %lX\n", dwKeyIndex);
805 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key
807 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
811 for (i=0; i < MAX_KEY_TABLE-1; i++) {
812 if (pTable->KeyTable[i].bInUse == TRUE) {
813 // found table already exist
815 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
816 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
817 // Group transmit key
818 pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
819 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i);
822 pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed
823 pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
824 pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address
825 uKeyIdx = (dwKeyIndex & 0x000000FF);
827 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly
829 pKey->bKeyValid = TRUE;
830 pKey->uKeyLength = uKeyLength;
831 pKey->dwKeyIndex = dwKeyIndex;
832 pKey->byCipherSuite = byKeyDecMode;
833 memcpy(pKey->abyKey, pbyKey, uKeyLength);
834 if (byKeyDecMode == KEY_CTL_WEP) {
835 if (uKeyLength == WLAN_WEP40_KEYLEN)
836 pKey->abyKey[15] &= 0x7F;
837 if (uKeyLength == WLAN_WEP104_KEYLEN)
838 pKey->abyKey[15] |= 0x80;
841 MACvSetKeyEntry(pDevice, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pTable->KeyTable[i].abyBSSID, (PDWORD) pKey->abyKey);
843 if ((dwKeyIndex & USE_KEYRSC) == 0) {
845 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
848 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
850 pKey->dwTSC47_16 = 0;
853 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
854 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
855 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
856 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
857 for (ii = 0; ii < pKey->uKeyLength; ii++) {
858 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", pKey->abyKey[ii]);
860 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
862 //DBG_PRN_GRP12(("pKey->dwTSC47_16: %lX\n ", pKey->dwTSC47_16));
863 //DBG_PRN_GRP12(("pKey->wTSC15_0: %X\n ", pKey->wTSC15_0));
864 //DBG_PRN_GRP12(("pKey->dwKeyIndex: %lX\n ", pKey->dwKeyIndex));
866 } // (pTable->KeyTable[i].bInUse == TRUE)