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
43 /*--------------------- Static Definitions -------------------------*/
45 /*--------------------- Static Classes ----------------------------*/
47 /*--------------------- Static Variables --------------------------*/
48 static int msglevel = MSG_LEVEL_INFO;
49 //static int msglevel =MSG_LEVEL_DEBUG;
50 /*--------------------- Static Functions --------------------------*/
52 /*--------------------- Export Variables --------------------------*/
54 /*--------------------- Static Definitions -------------------------*/
56 /*--------------------- Static Classes ----------------------------*/
58 /*--------------------- Static Variables --------------------------*/
60 /*--------------------- Static Functions --------------------------*/
62 s_vCheckKeyTableValid(PSKeyManagement pTable, unsigned long dwIoBase)
66 for (i = 0; i < MAX_KEY_TABLE; i++) {
67 if ((pTable->KeyTable[i].bInUse == true) &&
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)
74 pTable->KeyTable[i].bInUse = false;
75 pTable->KeyTable[i].wKeyCtl = 0;
76 pTable->KeyTable[i].bSoftWEP = false;
77 MACvDisableKeyEntry(dwIoBase, i);
82 /*--------------------- Export Functions --------------------------*/
85 * Description: Init Key management table
89 * pTable - Pointer to Key table
96 void KeyvInitTable(PSKeyManagement pTable, unsigned long dwIoBase)
101 for (i = 0; i < MAX_KEY_TABLE; i++) {
102 pTable->KeyTable[i].bInUse = false;
103 pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
104 pTable->KeyTable[i].PairwiseKey.pvKeyTable = (void *)&pTable->KeyTable[i];
105 for (jj = 0; jj < MAX_GROUP_KEY; jj++) {
106 pTable->KeyTable[i].GroupKey[jj].bKeyValid = false;
107 pTable->KeyTable[i].GroupKey[jj].pvKeyTable = (void *)&pTable->KeyTable[i];
109 pTable->KeyTable[i].wKeyCtl = 0;
110 pTable->KeyTable[i].dwGTKeyIndex = 0;
111 pTable->KeyTable[i].bSoftWEP = false;
112 MACvDisableKeyEntry(dwIoBase, i);
117 * Description: Get Key from table
121 * pTable - Pointer to Key table
122 * pbyBSSID - BSSID of Key
123 * dwKeyIndex - Key Index (0xFFFFFFFF means pairwise key)
127 * Return Value: true if found otherwise false
131 PSKeyManagement pTable,
132 unsigned char *pbyBSSID,
133 unsigned long dwKeyIndex,
139 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybGetKey() \n");
142 for (i = 0; i < MAX_KEY_TABLE; i++) {
143 if ((pTable->KeyTable[i].bInUse == true) &&
144 ether_addr_equal(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
145 if (dwKeyIndex == 0xFFFFFFFF) {
146 if (pTable->KeyTable[i].PairwiseKey.bKeyValid == true) {
147 *pKey = &(pTable->KeyTable[i].PairwiseKey);
152 } else if (dwKeyIndex < MAX_GROUP_KEY) {
153 if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid == true) {
154 *pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex]);
168 * Description: Set Key to table
172 * pTable - Pointer to Key table
173 * pbyBSSID - BSSID of Key
174 * dwKeyIndex - Key index (reference to NDIS DDK)
175 * uKeyLength - Key length
177 * pbyKey - Pointer to key
181 * Return Value: true if success otherwise false
185 PSKeyManagement pTable,
186 unsigned char *pbyBSSID,
187 unsigned long dwKeyIndex,
188 unsigned long uKeyLength,
190 unsigned char *pbyKey,
191 unsigned char byKeyDecMode,
192 unsigned long dwIoBase,
193 unsigned char byLocalID
199 unsigned int uKeyIdx;
201 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enter KeybSetKey: %lX\n", dwKeyIndex);
203 j = (MAX_KEY_TABLE-1);
204 for (i = 0; i < (MAX_KEY_TABLE - 1); i++) {
205 if ((pTable->KeyTable[i].bInUse == false) &&
206 (j == (MAX_KEY_TABLE-1))) {
210 if ((pTable->KeyTable[i].bInUse == true) &&
211 ether_addr_equal(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
212 // found table already exist
213 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
215 pKey = &(pTable->KeyTable[i].PairwiseKey);
216 pTable->KeyTable[i].wKeyCtl &= 0xFFF0; // clear pairwise key control filed
217 pTable->KeyTable[i].wKeyCtl |= byKeyDecMode;
218 uKeyIdx = 4; // use HW key entry 4 for pairwise key
221 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
223 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
224 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
225 // Group transmit key
226 pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
227 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i);
229 pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed
230 pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
231 pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address
232 uKeyIdx = (dwKeyIndex & 0x000000FF);
234 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly
236 pKey->bKeyValid = true;
237 pKey->uKeyLength = uKeyLength;
238 pKey->dwKeyIndex = dwKeyIndex;
239 pKey->byCipherSuite = byKeyDecMode;
240 memcpy(pKey->abyKey, pbyKey, uKeyLength);
241 if (byKeyDecMode == KEY_CTL_WEP) {
242 if (uKeyLength == WLAN_WEP40_KEYLEN)
243 pKey->abyKey[15] &= 0x7F;
244 if (uKeyLength == WLAN_WEP104_KEYLEN)
245 pKey->abyKey[15] |= 0x80;
247 MACvSetKeyEntry(dwIoBase, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pbyBSSID, (unsigned long *)pKey->abyKey, byLocalID);
249 if ((dwKeyIndex & USE_KEYRSC) == 0) {
251 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
253 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
255 pKey->dwTSC47_16 = 0;
258 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybSetKey(R): \n");
259 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->bKeyValid: %d\n ", pKey->bKeyValid);
260 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->uKeyLength: %d\n ", pKey->uKeyLength);
261 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->abyKey: ");
262 for (ii = 0; ii < pKey->uKeyLength; ii++) {
263 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
265 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
267 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16);
268 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
269 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex);
274 if (j < (MAX_KEY_TABLE-1)) {
275 memcpy(pTable->KeyTable[j].abyBSSID, pbyBSSID, ETH_ALEN);
276 pTable->KeyTable[j].bInUse = true;
277 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
279 pKey = &(pTable->KeyTable[j].PairwiseKey);
280 pTable->KeyTable[j].wKeyCtl &= 0xFFF0; // clear pairwise key control filed
281 pTable->KeyTable[j].wKeyCtl |= byKeyDecMode;
282 uKeyIdx = 4; // use HW key entry 4 for pairwise key
285 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
287 pKey = &(pTable->KeyTable[j].GroupKey[dwKeyIndex & 0x000000FF]);
288 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
289 // Group transmit key
290 pTable->KeyTable[j].dwGTKeyIndex = dwKeyIndex;
291 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Group transmit key(N)[%lX]: %d\n", pTable->KeyTable[j].dwGTKeyIndex, j);
293 pTable->KeyTable[j].wKeyCtl &= 0xFF0F; // clear group key control filed
294 pTable->KeyTable[j].wKeyCtl |= (byKeyDecMode << 4);
295 pTable->KeyTable[j].wKeyCtl |= 0x0040; // use group key for group address
296 uKeyIdx = (dwKeyIndex & 0x000000FF);
298 pTable->KeyTable[j].wKeyCtl |= 0x8000; // enable on-fly
300 pKey->bKeyValid = true;
301 pKey->uKeyLength = uKeyLength;
302 pKey->dwKeyIndex = dwKeyIndex;
303 pKey->byCipherSuite = byKeyDecMode;
304 memcpy(pKey->abyKey, pbyKey, uKeyLength);
305 if (byKeyDecMode == KEY_CTL_WEP) {
306 if (uKeyLength == WLAN_WEP40_KEYLEN)
307 pKey->abyKey[15] &= 0x7F;
308 if (uKeyLength == WLAN_WEP104_KEYLEN)
309 pKey->abyKey[15] |= 0x80;
311 MACvSetKeyEntry(dwIoBase, pTable->KeyTable[j].wKeyCtl, j, uKeyIdx, pbyBSSID, (unsigned long *)pKey->abyKey, byLocalID);
313 if ((dwKeyIndex & USE_KEYRSC) == 0) {
315 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
317 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
319 pKey->dwTSC47_16 = 0;
322 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybSetKey(N): \n");
323 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->bKeyValid: %d\n ", pKey->bKeyValid);
324 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
325 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->abyKey: ");
326 for (ii = 0; ii < pKey->uKeyLength; ii++) {
327 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
329 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
331 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16);
332 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
333 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex);
341 * Description: Remove Key from table
345 * pTable - Pointer to Key table
346 * pbyBSSID - BSSID of Key
347 * dwKeyIndex - Key Index (reference to NDIS DDK)
351 * Return Value: true if success otherwise false
355 PSKeyManagement pTable,
356 unsigned char *pbyBSSID,
357 unsigned long dwKeyIndex,
358 unsigned long dwIoBase
363 if (is_broadcast_ether_addr(pbyBSSID)) {
365 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
366 for (i = 0; i < MAX_KEY_TABLE; i++) {
367 pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
369 s_vCheckKeyTableValid(pTable, dwIoBase);
371 } else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
372 for (i = 0; i < MAX_KEY_TABLE; i++) {
373 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
374 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
375 // remove Group transmit key
376 pTable->KeyTable[i].dwGTKeyIndex = 0;
379 s_vCheckKeyTableValid(pTable, dwIoBase);
386 for (i = 0; i < MAX_KEY_TABLE; i++) {
387 if ((pTable->KeyTable[i].bInUse == true) &&
388 ether_addr_equal(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
389 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
390 pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
391 s_vCheckKeyTableValid(pTable, dwIoBase);
393 } else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
394 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
395 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
396 // remove Group transmit key
397 pTable->KeyTable[i].dwGTKeyIndex = 0;
399 s_vCheckKeyTableValid(pTable, dwIoBase);
410 * Description: Remove Key from table
414 * pTable - Pointer to Key table
415 * pbyBSSID - BSSID of Key
419 * Return Value: true if success otherwise false
422 bool KeybRemoveAllKey(
423 PSKeyManagement pTable,
424 unsigned char *pbyBSSID,
425 unsigned long dwIoBase
430 for (i = 0; i < MAX_KEY_TABLE; i++) {
431 if ((pTable->KeyTable[i].bInUse == true) &&
432 ether_addr_equal(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
433 pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
434 for (u = 0; u < MAX_GROUP_KEY; u++) {
435 pTable->KeyTable[i].GroupKey[u].bKeyValid = false;
437 pTable->KeyTable[i].dwGTKeyIndex = 0;
438 s_vCheckKeyTableValid(pTable, dwIoBase);
446 * Description: Remove WEP Key from table
450 * pTable - Pointer to Key table
454 * Return Value: true if success otherwise false
457 void KeyvRemoveWEPKey(
458 PSKeyManagement pTable,
459 unsigned long dwKeyIndex,
460 unsigned long dwIoBase
463 if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
464 if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == true) {
465 if (pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].byCipherSuite == KEY_CTL_WEP) {
466 pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
467 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex & 0x7FFFFFFF)) {
468 // remove Group transmit key
469 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = 0;
473 s_vCheckKeyTableValid(pTable, dwIoBase);
478 void KeyvRemoveAllWEPKey(
479 PSKeyManagement pTable,
480 unsigned long dwIoBase
485 for (i = 0; i < MAX_GROUP_KEY; i++) {
486 KeyvRemoveWEPKey(pTable, i, dwIoBase);
491 * Description: Get Transmit Key from table
495 * pTable - Pointer to Key table
496 * pbyBSSID - BSSID of Key
500 * Return Value: true if found otherwise false
503 bool KeybGetTransmitKey(
504 PSKeyManagement pTable,
505 unsigned char *pbyBSSID,
506 unsigned long dwKeyType,
513 for (i = 0; i < MAX_KEY_TABLE; i++) {
514 if ((pTable->KeyTable[i].bInUse == true) &&
515 ether_addr_equal(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
516 if (dwKeyType == PAIRWISE_KEY) {
517 if (pTable->KeyTable[i].PairwiseKey.bKeyValid == true) {
518 *pKey = &(pTable->KeyTable[i].PairwiseKey);
520 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybGetTransmitKey:");
521 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PAIRWISE_KEY: KeyTable.abyBSSID: ");
522 for (ii = 0; ii < 6; ii++) {
523 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%x ", pTable->KeyTable[i].abyBSSID[ii]);
525 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
529 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PairwiseKey.bKeyValid == false\n");
532 } // End of Type == PAIRWISE
534 if (pTable->KeyTable[i].dwGTKeyIndex == 0) {
535 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ERROR: dwGTKeyIndex == 0 !!!\n");
538 if (pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)].bKeyValid == true) {
539 *pKey = &(pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)]);
541 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybGetTransmitKey:");
542 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP_KEY: KeyTable.abyBSSID\n");
543 for (ii = 0; ii < 6; ii++) {
544 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%x ", pTable->KeyTable[i].abyBSSID[ii]);
546 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
547 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dwGTKeyIndex: %lX\n", pTable->KeyTable[i].dwGTKeyIndex);
551 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GroupKey.bKeyValid == false\n");
554 } // End of Type = GROUP
557 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ERROR: NO Match BSSID !!! ");
558 for (ii = 0; ii < 6; ii++) {
559 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", *(pbyBSSID+ii));
561 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
566 * Description: Check Pairewise Key
570 * pTable - Pointer to Key table
574 * Return Value: true if found otherwise false
577 bool KeybCheckPairewiseKey(
578 PSKeyManagement pTable,
585 for (i = 0; i < MAX_KEY_TABLE; i++) {
586 if ((pTable->KeyTable[i].bInUse == true) &&
587 (pTable->KeyTable[i].PairwiseKey.bKeyValid == true)) {
588 *pKey = &(pTable->KeyTable[i].PairwiseKey);
596 * Description: Set Key to table
600 * pTable - Pointer to Key table
601 * dwKeyIndex - Key index (reference to NDIS DDK)
602 * uKeyLength - Key length
604 * pbyKey - Pointer to key
608 * Return Value: true if success otherwise false
611 bool KeybSetDefaultKey(
612 PSKeyManagement pTable,
613 unsigned long dwKeyIndex,
614 unsigned long uKeyLength,
616 unsigned char *pbyKey,
617 unsigned char byKeyDecMode,
618 unsigned long dwIoBase,
619 unsigned char byLocalID
624 unsigned int uKeyIdx;
626 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enter KeybSetDefaultKey: %1x, %d \n", (int)dwKeyIndex, (int)uKeyLength);
628 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key
630 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
634 if (uKeyLength > MAX_KEY_LEN)
637 pTable->KeyTable[MAX_KEY_TABLE - 1].bInUse = true;
638 for (ii = 0; ii < ETH_ALEN; ii++)
639 pTable->KeyTable[MAX_KEY_TABLE - 1].abyBSSID[ii] = 0xFF;
642 pKey = &(pTable->KeyTable[MAX_KEY_TABLE - 1].GroupKey[dwKeyIndex & 0x000000FF]);
643 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
644 // Group transmit key
645 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = dwKeyIndex;
646 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);
649 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl &= 0x7F00; // clear all key control filed
650 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode << 4);
651 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode);
652 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x0044; // use group key for all address
653 uKeyIdx = (dwKeyIndex & 0x000000FF);
655 if ((uKeyLength == WLAN_WEP232_KEYLEN) &&
656 (byKeyDecMode == KEY_CTL_WEP)) {
657 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x4000; // disable on-fly disable address match
658 pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP = true;
660 if (pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP == false)
661 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0xC000; // enable on-fly disable address match
664 pKey->bKeyValid = true;
665 pKey->uKeyLength = uKeyLength;
666 pKey->dwKeyIndex = dwKeyIndex;
667 pKey->byCipherSuite = byKeyDecMode;
668 memcpy(pKey->abyKey, pbyKey, uKeyLength);
669 if (byKeyDecMode == KEY_CTL_WEP) {
670 if (uKeyLength == WLAN_WEP40_KEYLEN)
671 pKey->abyKey[15] &= 0x7F;
672 if (uKeyLength == WLAN_WEP104_KEYLEN)
673 pKey->abyKey[15] |= 0x80;
675 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);
677 if ((dwKeyIndex & USE_KEYRSC) == 0) {
679 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
681 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
683 pKey->dwTSC47_16 = 0;
686 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybSetKey(R): \n");
687 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->bKeyValid: %d\n", pKey->bKeyValid);
688 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->uKeyLength: %d\n", (int)pKey->uKeyLength);
689 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->abyKey: \n");
690 for (ii = 0; ii < pKey->uKeyLength; ii++) {
691 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%x", pKey->abyKey[ii]);
693 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
695 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->dwTSC47_16: %lx\n", pKey->dwTSC47_16);
696 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->wTSC15_0: %x\n", pKey->wTSC15_0);
697 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->dwKeyIndex: %lx\n", pKey->dwKeyIndex);
703 * Description: Set Key to table
707 * pTable - Pointer to Key table
708 * dwKeyIndex - Key index (reference to NDIS DDK)
709 * uKeyLength - Key length
711 * pbyKey - Pointer to key
715 * Return Value: true if success otherwise false
718 bool KeybSetAllGroupKey(
719 PSKeyManagement pTable,
720 unsigned long dwKeyIndex,
721 unsigned long uKeyLength,
723 unsigned char *pbyKey,
724 unsigned char byKeyDecMode,
725 unsigned long dwIoBase,
726 unsigned char byLocalID
732 unsigned int uKeyIdx;
734 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enter KeybSetAllGroupKey: %lX\n", dwKeyIndex);
736 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key
738 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
742 for (i = 0; i < MAX_KEY_TABLE - 1; i++) {
743 if (pTable->KeyTable[i].bInUse == true) {
744 // found table already exist
746 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
747 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
748 // Group transmit key
749 pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
750 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i);
753 pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed
754 pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
755 pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address
756 uKeyIdx = (dwKeyIndex & 0x000000FF);
758 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly
760 pKey->bKeyValid = true;
761 pKey->uKeyLength = uKeyLength;
762 pKey->dwKeyIndex = dwKeyIndex;
763 pKey->byCipherSuite = byKeyDecMode;
764 memcpy(pKey->abyKey, pbyKey, uKeyLength);
765 if (byKeyDecMode == KEY_CTL_WEP) {
766 if (uKeyLength == WLAN_WEP40_KEYLEN)
767 pKey->abyKey[15] &= 0x7F;
768 if (uKeyLength == WLAN_WEP104_KEYLEN)
769 pKey->abyKey[15] |= 0x80;
771 MACvSetKeyEntry(dwIoBase, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pTable->KeyTable[i].abyBSSID, (unsigned long *)pKey->abyKey, byLocalID);
773 if ((dwKeyIndex & USE_KEYRSC) == 0) {
775 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
777 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
779 pKey->dwTSC47_16 = 0;
782 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybSetKey(R): \n");
783 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->bKeyValid: %d\n ", pKey->bKeyValid);
784 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
785 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->abyKey: ");
786 for (ii = 0; ii < pKey->uKeyLength; ii++) {
787 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
789 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
791 //DBG_PRN_GRP12(("pKey->dwTSC47_16: %lX\n ", pKey->dwTSC47_16));
792 //DBG_PRN_GRP12(("pKey->wTSC15_0: %X\n ", pKey->wTSC15_0));
793 //DBG_PRN_GRP12(("pKey->dwKeyIndex: %lX\n ", pKey->dwKeyIndex));
795 } // (pTable->KeyTable[i].bInUse == true)