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 --------------------------*/
63 static void s_vCheckKeyTableValid(void *pDeviceHandler,
64 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(void *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 =
127 (void *)&pTable->KeyTable[i];
128 for (jj=0; jj < MAX_GROUP_KEY; jj++) {
129 pTable->KeyTable[i].GroupKey[jj].bKeyValid = FALSE;
130 pTable->KeyTable[i].GroupKey[jj].pvKeyTable =
131 (void *) &(pTable->KeyTable[i]);
133 pTable->KeyTable[i].wKeyCtl = 0;
134 pTable->KeyTable[i].dwGTKeyIndex = 0;
135 pTable->KeyTable[i].bSoftWEP = FALSE;
136 pbyData[i] = (BYTE) i;
138 pbyData[i] = (BYTE) i;
139 CONTROLnsRequestOut(pDevice,
140 MESSAGE_TYPE_CLRKEYENTRY,
147 spin_unlock_irq(&pDevice->lock);
154 * Description: Get Key from table
158 * pTable - Pointer to Key table
159 * pbyBSSID - BSSID of Key
160 * dwKeyIndex - Key Index (0xFFFFFFFF means pairwise key)
164 * Return Value: TRUE if found otherwise FALSE
167 BOOL KeybGetKey(PSKeyManagement pTable, PBYTE pbyBSSID, DWORD dwKeyIndex,
172 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetKey() \n");
175 for (i=0;i<MAX_KEY_TABLE;i++) {
176 if ((pTable->KeyTable[i].bInUse == TRUE) &&
177 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
178 if (dwKeyIndex == 0xFFFFFFFF) {
179 if (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE) {
180 *pKey = &(pTable->KeyTable[i].PairwiseKey);
186 } else if (dwKeyIndex < MAX_GROUP_KEY) {
187 if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid == TRUE) {
188 *pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex]);
205 * Description: Set Key to table
209 * pTable - Pointer to Key table
210 * pbyBSSID - BSSID of Key
211 * dwKeyIndex - Key index (reference to NDIS DDK)
212 * uKeyLength - Key length
214 * pbyKey - Pointer to key
218 * Return Value: TRUE if success otherwise FALSE
222 void *pDeviceHandler,
223 PSKeyManagement pTable,
232 PSDevice pDevice = (PSDevice) pDeviceHandler;
236 unsigned int uKeyIdx;
238 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
239 "Enter KeybSetKey: %X\n", dwKeyIndex);
241 j = (MAX_KEY_TABLE-1);
242 for (i=0;i<(MAX_KEY_TABLE-1);i++) {
243 if ((pTable->KeyTable[i].bInUse == FALSE) &&
244 (j == (MAX_KEY_TABLE-1))) {
248 if ((pTable->KeyTable[i].bInUse == TRUE) &&
249 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
250 // found table already exist
251 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
253 pKey = &(pTable->KeyTable[i].PairwiseKey);
254 pTable->KeyTable[i].wKeyCtl &= 0xFFF0; // clear pairwise key control filed
255 pTable->KeyTable[i].wKeyCtl |= byKeyDecMode;
256 uKeyIdx = 4; // use HW key entry 4 for pairwise key
259 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
261 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
262 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
263 // Group transmit key
264 pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
265 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
266 "Group transmit key(R)[%X]: %d\n",
267 pTable->KeyTable[i].dwGTKeyIndex, i);
269 pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed
270 pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
271 pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address
272 uKeyIdx = (dwKeyIndex & 0x000000FF);
274 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly
276 pKey->bKeyValid = TRUE;
277 pKey->uKeyLength = uKeyLength;
278 pKey->dwKeyIndex = dwKeyIndex;
279 pKey->byCipherSuite = byKeyDecMode;
280 memcpy(pKey->abyKey, pbyKey, uKeyLength);
281 if (byKeyDecMode == KEY_CTL_WEP) {
282 if (uKeyLength == WLAN_WEP40_KEYLEN)
283 pKey->abyKey[15] &= 0x7F;
284 if (uKeyLength == WLAN_WEP104_KEYLEN)
285 pKey->abyKey[15] |= 0x80;
287 MACvSetKeyEntry(pDevice, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey);
289 if ((dwKeyIndex & USE_KEYRSC) == 0) {
291 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
294 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
296 pKey->dwTSC47_16 = 0;
299 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
300 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
301 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", pKey->uKeyLength);
302 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
303 for (ii = 0; ii < pKey->uKeyLength; ii++) {
304 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
306 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
308 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %x\n ",
310 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n ",
312 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %x\n ",
318 if (j < (MAX_KEY_TABLE-1)) {
319 memcpy(pTable->KeyTable[j].abyBSSID, pbyBSSID, ETH_ALEN);
320 pTable->KeyTable[j].bInUse = TRUE;
321 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
323 pKey = &(pTable->KeyTable[j].PairwiseKey);
324 pTable->KeyTable[j].wKeyCtl &= 0xFFF0; // clear pairwise key control filed
325 pTable->KeyTable[j].wKeyCtl |= byKeyDecMode;
326 uKeyIdx = 4; // use HW key entry 4 for pairwise key
329 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
331 pKey = &(pTable->KeyTable[j].GroupKey[dwKeyIndex & 0x000000FF]);
332 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
333 // Group transmit key
334 pTable->KeyTable[j].dwGTKeyIndex = dwKeyIndex;
335 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
336 "Group transmit key(N)[%X]: %d\n",
337 pTable->KeyTable[j].dwGTKeyIndex, j);
339 pTable->KeyTable[j].wKeyCtl &= 0xFF0F; // clear group key control filed
340 pTable->KeyTable[j].wKeyCtl |= (byKeyDecMode << 4);
341 pTable->KeyTable[j].wKeyCtl |= 0x0040; // use group key for group address
342 uKeyIdx = (dwKeyIndex & 0x000000FF);
344 pTable->KeyTable[j].wKeyCtl |= 0x8000; // enable on-fly
346 pKey->bKeyValid = TRUE;
347 pKey->uKeyLength = uKeyLength;
348 pKey->dwKeyIndex = dwKeyIndex;
349 pKey->byCipherSuite = byKeyDecMode;
350 memcpy(pKey->abyKey, pbyKey, uKeyLength);
351 if (byKeyDecMode == KEY_CTL_WEP) {
352 if (uKeyLength == WLAN_WEP40_KEYLEN)
353 pKey->abyKey[15] &= 0x7F;
354 if (uKeyLength == WLAN_WEP104_KEYLEN)
355 pKey->abyKey[15] |= 0x80;
357 MACvSetKeyEntry(pDevice, pTable->KeyTable[j].wKeyCtl, j, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey);
359 if ((dwKeyIndex & USE_KEYRSC) == 0) {
361 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
364 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
366 pKey->dwTSC47_16 = 0;
369 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(N): \n");
370 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
371 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
372 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
373 for (ii = 0; ii < pKey->uKeyLength; ii++) {
374 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
376 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
378 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %x\n ",
380 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %x\n ",
391 * Description: Remove Key from table
395 * pTable - Pointer to Key table
396 * pbyBSSID - BSSID of Key
397 * dwKeyIndex - Key Index (reference to NDIS DDK)
401 * Return Value: TRUE if success otherwise FALSE
405 void *pDeviceHandler,
406 PSKeyManagement pTable,
411 PSDevice pDevice = (PSDevice) pDeviceHandler;
413 BOOL bReturnValue = FALSE;
415 if (is_broadcast_ether_addr(pbyBSSID)) {
417 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
418 for (i=0;i<MAX_KEY_TABLE;i++) {
419 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE;
423 else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
424 for (i=0;i<MAX_KEY_TABLE;i++) {
425 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE;
426 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
427 // remove Group transmit key
428 pTable->KeyTable[i].dwGTKeyIndex = 0;
434 bReturnValue = FALSE;
438 for (i=0;i<MAX_KEY_TABLE;i++) {
439 if ( (pTable->KeyTable[i].bInUse == TRUE) &&
440 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
442 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
443 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE;
447 else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
448 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE;
449 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
450 // remove Group transmit key
451 pTable->KeyTable[i].dwGTKeyIndex = 0;
457 bReturnValue = FALSE;
460 } //pTable->KeyTable[i].bInUse == TRUE
465 s_vCheckKeyTableValid(pDevice,pTable);
473 * Description: Remove Key from table
477 * pTable - Pointer to Key table
478 * pbyBSSID - BSSID of Key
482 * Return Value: TRUE if success otherwise FALSE
485 BOOL KeybRemoveAllKey(
486 void *pDeviceHandler,
487 PSKeyManagement pTable,
491 PSDevice pDevice = (PSDevice) pDeviceHandler;
494 for (i=0;i<MAX_KEY_TABLE;i++) {
495 if ((pTable->KeyTable[i].bInUse == TRUE) &&
496 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
497 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE;
498 for (u = 0; u < MAX_GROUP_KEY; u++)
499 pTable->KeyTable[i].GroupKey[u].bKeyValid = FALSE;
501 pTable->KeyTable[i].dwGTKeyIndex = 0;
502 s_vCheckKeyTableValid(pDevice, pTable);
510 * Description: Remove WEP Key from table
514 * pTable - Pointer to Key table
518 * Return Value: TRUE if success otherwise FALSE
521 void KeyvRemoveWEPKey(
522 void *pDeviceHandler,
523 PSKeyManagement pTable,
527 PSDevice pDevice = (PSDevice) pDeviceHandler;
529 if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
530 if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == TRUE) {
531 if (pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].byCipherSuite == KEY_CTL_WEP) {
532 pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE;
533 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex & 0x7FFFFFFF)) {
534 // remove Group transmit key
535 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = 0;
539 s_vCheckKeyTableValid(pDevice, pTable);
544 void KeyvRemoveAllWEPKey(void *pDeviceHandler, PSKeyManagement pTable)
546 PSDevice pDevice = (PSDevice) pDeviceHandler;
549 for (i = 0; i < MAX_GROUP_KEY; i++)
550 KeyvRemoveWEPKey(pDevice, pTable, i);
554 * Description: Get Transmit Key from table
558 * pTable - Pointer to Key table
559 * pbyBSSID - BSSID of Key
563 * Return Value: TRUE if found otherwise FALSE
566 BOOL KeybGetTransmitKey(PSKeyManagement pTable, PBYTE pbyBSSID, DWORD dwKeyType,
572 for (i = 0; i < MAX_KEY_TABLE; i++) {
573 if ((pTable->KeyTable[i].bInUse == TRUE) &&
574 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
576 if (dwKeyType == PAIRWISE_KEY) {
578 if (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE) {
579 *pKey = &(pTable->KeyTable[i].PairwiseKey);
581 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:");
582 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PAIRWISE_KEY: KeyTable.abyBSSID: ");
583 for (ii = 0; ii < 6; ii++) {
584 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x ", pTable->KeyTable[i].abyBSSID[ii]);
586 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
592 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PairwiseKey.bKeyValid == FALSE\n");
595 } // End of Type == PAIRWISE
597 if (pTable->KeyTable[i].dwGTKeyIndex == 0) {
598 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: dwGTKeyIndex == 0 !!!\n");
601 if (pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)].bKeyValid == TRUE) {
602 *pKey = &(pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)]);
604 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:");
605 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GROUP_KEY: KeyTable.abyBSSID\n");
606 for (ii = 0; ii < 6; ii++) {
607 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x ", pTable->KeyTable[i].abyBSSID[ii]);
609 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
610 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"dwGTKeyIndex: %X\n",
611 pTable->KeyTable[i].dwGTKeyIndex);
616 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GroupKey.bKeyValid == FALSE\n");
619 } // End of Type = GROUP
622 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: NO Match BSSID !!! ");
623 for (ii = 0; ii < 6; ii++) {
624 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(pbyBSSID+ii));
626 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
632 * Description: Check Pairewise Key
636 * pTable - Pointer to Key table
640 * Return Value: TRUE if found otherwise FALSE
643 BOOL KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey)
648 for (i=0;i<MAX_KEY_TABLE;i++) {
649 if ((pTable->KeyTable[i].bInUse == TRUE) &&
650 (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE)) {
651 *pKey = &(pTable->KeyTable[i].PairwiseKey);
659 * Description: Set Key to table
663 * pTable - Pointer to Key table
664 * dwKeyIndex - Key index (reference to NDIS DDK)
665 * uKeyLength - Key length
667 * pbyKey - Pointer to key
671 * Return Value: TRUE if success otherwise FALSE
674 BOOL KeybSetDefaultKey(
675 void *pDeviceHandler,
676 PSKeyManagement pTable,
684 PSDevice pDevice = (PSDevice) pDeviceHandler;
687 unsigned int uKeyIdx;
689 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enter KeybSetDefaultKey: %1x, %d\n",
690 (int) dwKeyIndex, (int) uKeyLength);
692 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key
694 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
698 pTable->KeyTable[MAX_KEY_TABLE-1].bInUse = TRUE;
699 for (ii = 0; ii < ETH_ALEN; ii++)
700 pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID[ii] = 0xFF;
703 pKey = &(pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF]);
704 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
705 // Group transmit key
706 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = dwKeyIndex;
707 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
708 "Group transmit key(R)[%X]: %d\n",
709 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex,
713 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl &= 0x7F00; // clear all key control filed
714 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode << 4);
715 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode);
716 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x0044; // use group key for all address
717 uKeyIdx = (dwKeyIndex & 0x000000FF);
719 if ((uKeyLength == WLAN_WEP232_KEYLEN) &&
720 (byKeyDecMode == KEY_CTL_WEP)) {
721 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x4000; // disable on-fly disable address match
722 pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP = TRUE;
724 if (pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP == FALSE)
725 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0xC000; // enable on-fly disable address match
728 pKey->bKeyValid = TRUE;
729 pKey->uKeyLength = uKeyLength;
730 pKey->dwKeyIndex = dwKeyIndex;
731 pKey->byCipherSuite = byKeyDecMode;
732 memcpy(pKey->abyKey, pbyKey, uKeyLength);
733 if (byKeyDecMode == KEY_CTL_WEP) {
734 if (uKeyLength == WLAN_WEP40_KEYLEN)
735 pKey->abyKey[15] &= 0x7F;
736 if (uKeyLength == WLAN_WEP104_KEYLEN)
737 pKey->abyKey[15] |= 0x80;
740 MACvSetKeyEntry(pDevice, pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl, MAX_KEY_TABLE-1, uKeyIdx, pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID, (PDWORD) pKey->abyKey);
742 if ((dwKeyIndex & USE_KEYRSC) == 0) {
744 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
746 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
748 pKey->dwTSC47_16 = 0;
752 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
753 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n", pKey->bKeyValid);
754 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n", (int)pKey->uKeyLength);
755 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: \n");
756 for (ii = 0; ii < pKey->uKeyLength; ii++) {
757 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x", pKey->abyKey[ii]);
759 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
761 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %x\n",
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: %x\n",
772 * Description: Set Key to table
776 * pTable - Pointer to Key table
777 * dwKeyIndex - Key index (reference to NDIS DDK)
778 * uKeyLength - Key length
780 * pbyKey - Pointer to key
784 * Return Value: TRUE if success otherwise FALSE
787 BOOL KeybSetAllGroupKey(
788 void *pDeviceHandler,
789 PSKeyManagement pTable,
797 PSDevice pDevice = (PSDevice) pDeviceHandler;
801 unsigned int uKeyIdx;
803 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetAllGroupKey: %X\n",
807 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key
809 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
813 for (i=0; i < MAX_KEY_TABLE-1; i++) {
814 if (pTable->KeyTable[i].bInUse == TRUE) {
815 // found table already exist
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
822 "Group transmit key(R)[%X]: %d\n",
823 pTable->KeyTable[i].dwGTKeyIndex, i);
826 pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed
827 pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
828 pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address
829 uKeyIdx = (dwKeyIndex & 0x000000FF);
831 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly
833 pKey->bKeyValid = TRUE;
834 pKey->uKeyLength = uKeyLength;
835 pKey->dwKeyIndex = dwKeyIndex;
836 pKey->byCipherSuite = byKeyDecMode;
837 memcpy(pKey->abyKey, pbyKey, uKeyLength);
838 if (byKeyDecMode == KEY_CTL_WEP) {
839 if (uKeyLength == WLAN_WEP40_KEYLEN)
840 pKey->abyKey[15] &= 0x7F;
841 if (uKeyLength == WLAN_WEP104_KEYLEN)
842 pKey->abyKey[15] |= 0x80;
845 MACvSetKeyEntry(pDevice, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pTable->KeyTable[i].abyBSSID, (PDWORD) pKey->abyKey);
847 if ((dwKeyIndex & USE_KEYRSC) == 0) {
849 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
852 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
854 pKey->dwTSC47_16 = 0;
857 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
858 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
859 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
860 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
861 for (ii = 0; ii < pKey->uKeyLength; ii++) {
862 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", pKey->abyKey[ii]);
864 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
866 //DBG_PRN_GRP12(("pKey->dwTSC47_16: %lX\n ", pKey->dwTSC47_16));
867 //DBG_PRN_GRP12(("pKey->wTSC15_0: %X\n ", pKey->wTSC15_0));
868 //DBG_PRN_GRP12(("pKey->dwKeyIndex: %lX\n ", pKey->dwKeyIndex));
870 } // (pTable->KeyTable[i].bInUse == TRUE)