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)
75 pTable->KeyTable[i].bInUse = false;
76 pTable->KeyTable[i].wKeyCtl = 0;
77 pTable->KeyTable[i].bSoftWEP = false;
78 MACvDisableKeyEntry(dwIoBase, i);
84 /*--------------------- Export Functions --------------------------*/
88 * Description: Init Key management table
92 * pTable - Pointer to Key table
99 void KeyvInitTable (PSKeyManagement pTable, unsigned long dwIoBase)
104 for (i=0;i<MAX_KEY_TABLE;i++) {
105 pTable->KeyTable[i].bInUse = false;
106 pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
107 pTable->KeyTable[i].PairwiseKey.pvKeyTable = (void *)&pTable->KeyTable[i];
108 for (jj=0; jj < MAX_GROUP_KEY; jj++) {
109 pTable->KeyTable[i].GroupKey[jj].bKeyValid = false;
110 pTable->KeyTable[i].GroupKey[jj].pvKeyTable = (void *)&pTable->KeyTable[i];
112 pTable->KeyTable[i].wKeyCtl = 0;
113 pTable->KeyTable[i].dwGTKeyIndex = 0;
114 pTable->KeyTable[i].bSoftWEP = false;
115 MACvDisableKeyEntry(dwIoBase, i);
121 * Description: Get Key from table
125 * pTable - Pointer to Key table
126 * pbyBSSID - BSSID of Key
127 * dwKeyIndex - Key Index (0xFFFFFFFF means pairwise key)
131 * Return Value: true if found otherwise false
135 PSKeyManagement pTable,
136 unsigned char *pbyBSSID,
137 unsigned long dwKeyIndex,
143 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetKey() \n");
146 for (i=0;i<MAX_KEY_TABLE;i++) {
147 if ((pTable->KeyTable[i].bInUse == true) &&
148 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
149 if (dwKeyIndex == 0xFFFFFFFF) {
150 if (pTable->KeyTable[i].PairwiseKey.bKeyValid == true) {
151 *pKey = &(pTable->KeyTable[i].PairwiseKey);
157 } else if (dwKeyIndex < MAX_GROUP_KEY) {
158 if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid == true) {
159 *pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex]);
176 * Description: Set Key to table
180 * pTable - Pointer to Key table
181 * pbyBSSID - BSSID of Key
182 * dwKeyIndex - Key index (reference to NDIS DDK)
183 * uKeyLength - Key length
185 * pbyKey - Pointer to key
189 * Return Value: true if success otherwise false
193 PSKeyManagement pTable,
194 unsigned char *pbyBSSID,
195 unsigned long dwKeyIndex,
196 unsigned long uKeyLength,
198 unsigned char *pbyKey,
199 unsigned char byKeyDecMode,
200 unsigned long dwIoBase,
201 unsigned char byLocalID
207 unsigned int uKeyIdx;
209 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetKey: %lX\n", dwKeyIndex);
211 j = (MAX_KEY_TABLE-1);
212 for (i=0;i<(MAX_KEY_TABLE-1);i++) {
213 if ((pTable->KeyTable[i].bInUse == false) &&
214 (j == (MAX_KEY_TABLE-1))) {
218 if ((pTable->KeyTable[i].bInUse == true) &&
219 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
220 // found table already exist
221 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
223 pKey = &(pTable->KeyTable[i].PairwiseKey);
224 pTable->KeyTable[i].wKeyCtl &= 0xFFF0; // clear pairwise key control filed
225 pTable->KeyTable[i].wKeyCtl |= byKeyDecMode;
226 uKeyIdx = 4; // use HW key entry 4 for pairwise key
229 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
231 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
232 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
233 // Group transmit key
234 pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
235 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i);
237 pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed
238 pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
239 pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address
240 uKeyIdx = (dwKeyIndex & 0x000000FF);
242 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly
244 pKey->bKeyValid = true;
245 pKey->uKeyLength = uKeyLength;
246 pKey->dwKeyIndex = dwKeyIndex;
247 pKey->byCipherSuite = byKeyDecMode;
248 memcpy(pKey->abyKey, pbyKey, uKeyLength);
249 if (byKeyDecMode == KEY_CTL_WEP) {
250 if (uKeyLength == WLAN_WEP40_KEYLEN)
251 pKey->abyKey[15] &= 0x7F;
252 if (uKeyLength == WLAN_WEP104_KEYLEN)
253 pKey->abyKey[15] |= 0x80;
255 MACvSetKeyEntry(dwIoBase, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pbyBSSID, (unsigned long *)pKey->abyKey, byLocalID);
257 if ((dwKeyIndex & USE_KEYRSC) == 0) {
259 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
262 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
264 pKey->dwTSC47_16 = 0;
267 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
268 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
269 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", pKey->uKeyLength);
270 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
271 for (ii = 0; ii < pKey->uKeyLength; ii++) {
272 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
274 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
276 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16);
277 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
278 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex);
283 if (j < (MAX_KEY_TABLE-1)) {
284 memcpy(pTable->KeyTable[j].abyBSSID,pbyBSSID,ETH_ALEN);
285 pTable->KeyTable[j].bInUse = true;
286 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
288 pKey = &(pTable->KeyTable[j].PairwiseKey);
289 pTable->KeyTable[j].wKeyCtl &= 0xFFF0; // clear pairwise key control filed
290 pTable->KeyTable[j].wKeyCtl |= byKeyDecMode;
291 uKeyIdx = 4; // use HW key entry 4 for pairwise key
294 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
296 pKey = &(pTable->KeyTable[j].GroupKey[dwKeyIndex & 0x000000FF]);
297 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
298 // Group transmit key
299 pTable->KeyTable[j].dwGTKeyIndex = dwKeyIndex;
300 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(N)[%lX]: %d\n", pTable->KeyTable[j].dwGTKeyIndex, j);
302 pTable->KeyTable[j].wKeyCtl &= 0xFF0F; // clear group key control filed
303 pTable->KeyTable[j].wKeyCtl |= (byKeyDecMode << 4);
304 pTable->KeyTable[j].wKeyCtl |= 0x0040; // use group key for group address
305 uKeyIdx = (dwKeyIndex & 0x000000FF);
307 pTable->KeyTable[j].wKeyCtl |= 0x8000; // enable on-fly
309 pKey->bKeyValid = true;
310 pKey->uKeyLength = uKeyLength;
311 pKey->dwKeyIndex = dwKeyIndex;
312 pKey->byCipherSuite = byKeyDecMode;
313 memcpy(pKey->abyKey, pbyKey, uKeyLength);
314 if (byKeyDecMode == KEY_CTL_WEP) {
315 if (uKeyLength == WLAN_WEP40_KEYLEN)
316 pKey->abyKey[15] &= 0x7F;
317 if (uKeyLength == WLAN_WEP104_KEYLEN)
318 pKey->abyKey[15] |= 0x80;
320 MACvSetKeyEntry(dwIoBase, pTable->KeyTable[j].wKeyCtl, j, uKeyIdx, pbyBSSID, (unsigned long *)pKey->abyKey, byLocalID);
322 if ((dwKeyIndex & USE_KEYRSC) == 0) {
324 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
327 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
329 pKey->dwTSC47_16 = 0;
332 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(N): \n");
333 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
334 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
335 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
336 for (ii = 0; ii < pKey->uKeyLength; ii++) {
337 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
339 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
341 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16);
342 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
343 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex);
352 * Description: Remove Key from table
356 * pTable - Pointer to Key table
357 * pbyBSSID - BSSID of Key
358 * dwKeyIndex - Key Index (reference to NDIS DDK)
362 * Return Value: true if success otherwise false
366 PSKeyManagement pTable,
367 unsigned char *pbyBSSID,
368 unsigned long dwKeyIndex,
369 unsigned long dwIoBase
374 if (is_broadcast_ether_addr(pbyBSSID)) {
376 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
377 for (i=0;i<MAX_KEY_TABLE;i++) {
378 pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
380 s_vCheckKeyTableValid(pTable, dwIoBase);
383 else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
384 for (i=0;i<MAX_KEY_TABLE;i++) {
385 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
386 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
387 // remove Group transmit key
388 pTable->KeyTable[i].dwGTKeyIndex = 0;
391 s_vCheckKeyTableValid(pTable, dwIoBase);
399 for (i=0;i<MAX_KEY_TABLE;i++) {
400 if ((pTable->KeyTable[i].bInUse == true) &&
401 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
402 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
403 pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
404 s_vCheckKeyTableValid(pTable, dwIoBase);
407 else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
408 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
409 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
410 // remove Group transmit key
411 pTable->KeyTable[i].dwGTKeyIndex = 0;
413 s_vCheckKeyTableValid(pTable, dwIoBase);
426 * Description: Remove Key from table
430 * pTable - Pointer to Key table
431 * pbyBSSID - BSSID of Key
435 * Return Value: true if success otherwise false
438 bool KeybRemoveAllKey (
439 PSKeyManagement pTable,
440 unsigned char *pbyBSSID,
441 unsigned long dwIoBase
446 for (i=0;i<MAX_KEY_TABLE;i++) {
447 if ((pTable->KeyTable[i].bInUse == true) &&
448 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
449 pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
450 for(u=0;u<MAX_GROUP_KEY;u++) {
451 pTable->KeyTable[i].GroupKey[u].bKeyValid = false;
453 pTable->KeyTable[i].dwGTKeyIndex = 0;
454 s_vCheckKeyTableValid(pTable, dwIoBase);
462 * Description: Remove WEP Key from table
466 * pTable - Pointer to Key table
470 * Return Value: true if success otherwise false
473 void KeyvRemoveWEPKey (
474 PSKeyManagement pTable,
475 unsigned long dwKeyIndex,
476 unsigned long dwIoBase
480 if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
481 if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == true) {
482 if (pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].byCipherSuite == KEY_CTL_WEP) {
483 pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
484 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex & 0x7FFFFFFF)) {
485 // remove Group transmit key
486 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = 0;
490 s_vCheckKeyTableValid(pTable, dwIoBase);
495 void KeyvRemoveAllWEPKey (
496 PSKeyManagement pTable,
497 unsigned long dwIoBase
502 for(i=0;i<MAX_GROUP_KEY;i++) {
503 KeyvRemoveWEPKey(pTable, i, dwIoBase);
508 * Description: Get Transmit Key from table
512 * pTable - Pointer to Key table
513 * pbyBSSID - BSSID of Key
517 * Return Value: true if found otherwise false
520 bool KeybGetTransmitKey (
521 PSKeyManagement pTable,
522 unsigned char *pbyBSSID,
523 unsigned long dwKeyType,
530 for (i=0;i<MAX_KEY_TABLE;i++) {
531 if ((pTable->KeyTable[i].bInUse == true) &&
532 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
534 if (dwKeyType == PAIRWISE_KEY) {
536 if (pTable->KeyTable[i].PairwiseKey.bKeyValid == true) {
537 *pKey = &(pTable->KeyTable[i].PairwiseKey);
539 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:");
540 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PAIRWISE_KEY: KeyTable.abyBSSID: ");
541 for (ii = 0; ii < 6; ii++) {
542 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x ", pTable->KeyTable[i].abyBSSID[ii]);
544 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
550 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PairwiseKey.bKeyValid == false\n");
553 } // End of Type == PAIRWISE
555 if (pTable->KeyTable[i].dwGTKeyIndex == 0) {
556 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: dwGTKeyIndex == 0 !!!\n");
559 if (pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)].bKeyValid == true) {
560 *pKey = &(pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)]);
562 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:");
563 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GROUP_KEY: KeyTable.abyBSSID\n");
564 for (ii = 0; ii < 6; ii++) {
565 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x ", pTable->KeyTable[i].abyBSSID[ii]);
567 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
568 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"dwGTKeyIndex: %lX\n", pTable->KeyTable[i].dwGTKeyIndex);
573 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GroupKey.bKeyValid == false\n");
576 } // End of Type = GROUP
579 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: NO Match BSSID !!! ");
580 for (ii = 0; ii < 6; ii++) {
581 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(pbyBSSID+ii));
583 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
589 * Description: Check Pairewise Key
593 * pTable - Pointer to Key table
597 * Return Value: true if found otherwise false
600 bool KeybCheckPairewiseKey (
601 PSKeyManagement pTable,
608 for (i=0;i<MAX_KEY_TABLE;i++) {
609 if ((pTable->KeyTable[i].bInUse == true) &&
610 (pTable->KeyTable[i].PairwiseKey.bKeyValid == true)) {
611 *pKey = &(pTable->KeyTable[i].PairwiseKey);
619 * Description: Set Key to table
623 * pTable - Pointer to Key table
624 * dwKeyIndex - Key index (reference to NDIS DDK)
625 * uKeyLength - Key length
627 * pbyKey - Pointer to key
631 * Return Value: true if success otherwise false
634 bool KeybSetDefaultKey (
635 PSKeyManagement pTable,
636 unsigned long dwKeyIndex,
637 unsigned long uKeyLength,
639 unsigned char *pbyKey,
640 unsigned char byKeyDecMode,
641 unsigned long dwIoBase,
642 unsigned char byLocalID
647 unsigned int uKeyIdx;
649 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetDefaultKey: %1x, %d \n", (int)dwKeyIndex, (int)uKeyLength);
652 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key
654 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
658 if (uKeyLength > MAX_KEY_LEN)
661 pTable->KeyTable[MAX_KEY_TABLE-1].bInUse = true;
662 for(ii=0;ii<ETH_ALEN;ii++)
663 pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID[ii] = 0xFF;
666 pKey = &(pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF]);
667 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
668 // Group transmit key
669 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = dwKeyIndex;
670 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);
673 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl &= 0x7F00; // clear all key control filed
674 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode << 4);
675 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode);
676 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x0044; // use group key for all address
677 uKeyIdx = (dwKeyIndex & 0x000000FF);
679 if ((uKeyLength == WLAN_WEP232_KEYLEN) &&
680 (byKeyDecMode == KEY_CTL_WEP)) {
681 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x4000; // disable on-fly disable address match
682 pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP = true;
684 if (pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP == false)
685 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0xC000; // enable on-fly disable address match
688 pKey->bKeyValid = true;
689 pKey->uKeyLength = uKeyLength;
690 pKey->dwKeyIndex = dwKeyIndex;
691 pKey->byCipherSuite = byKeyDecMode;
692 memcpy(pKey->abyKey, pbyKey, uKeyLength);
693 if (byKeyDecMode == KEY_CTL_WEP) {
694 if (uKeyLength == WLAN_WEP40_KEYLEN)
695 pKey->abyKey[15] &= 0x7F;
696 if (uKeyLength == WLAN_WEP104_KEYLEN)
697 pKey->abyKey[15] |= 0x80;
699 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);
701 if ((dwKeyIndex & USE_KEYRSC) == 0) {
703 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
705 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
707 pKey->dwTSC47_16 = 0;
711 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
712 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n", pKey->bKeyValid);
713 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n", (int)pKey->uKeyLength);
714 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: \n");
715 for (ii = 0; ii < pKey->uKeyLength; ii++) {
716 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x", pKey->abyKey[ii]);
718 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
720 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n", pKey->dwTSC47_16);
721 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n", pKey->wTSC15_0);
722 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n", pKey->dwKeyIndex);
729 * Description: Set Key to table
733 * pTable - Pointer to Key table
734 * dwKeyIndex - Key index (reference to NDIS DDK)
735 * uKeyLength - Key length
737 * pbyKey - Pointer to key
741 * Return Value: true if success otherwise false
744 bool KeybSetAllGroupKey (
745 PSKeyManagement pTable,
746 unsigned long dwKeyIndex,
747 unsigned long uKeyLength,
749 unsigned char *pbyKey,
750 unsigned char byKeyDecMode,
751 unsigned long dwIoBase,
752 unsigned char byLocalID
758 unsigned int uKeyIdx;
760 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetAllGroupKey: %lX\n", dwKeyIndex);
763 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key
765 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
769 for (i=0; i < MAX_KEY_TABLE-1; i++) {
770 if (pTable->KeyTable[i].bInUse == true) {
771 // found table already exist
773 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
774 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
775 // Group transmit key
776 pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
777 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i);
780 pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed
781 pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
782 pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address
783 uKeyIdx = (dwKeyIndex & 0x000000FF);
785 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly
787 pKey->bKeyValid = true;
788 pKey->uKeyLength = uKeyLength;
789 pKey->dwKeyIndex = dwKeyIndex;
790 pKey->byCipherSuite = byKeyDecMode;
791 memcpy(pKey->abyKey, pbyKey, uKeyLength);
792 if (byKeyDecMode == KEY_CTL_WEP) {
793 if (uKeyLength == WLAN_WEP40_KEYLEN)
794 pKey->abyKey[15] &= 0x7F;
795 if (uKeyLength == WLAN_WEP104_KEYLEN)
796 pKey->abyKey[15] |= 0x80;
798 MACvSetKeyEntry(dwIoBase, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pTable->KeyTable[i].abyBSSID, (unsigned long *)pKey->abyKey, byLocalID);
800 if ((dwKeyIndex & USE_KEYRSC) == 0) {
802 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
805 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
807 pKey->dwTSC47_16 = 0;
810 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
811 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
812 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
813 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
814 for (ii = 0; ii < pKey->uKeyLength; ii++) {
815 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", pKey->abyKey[ii]);
817 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
819 //DBG_PRN_GRP12(("pKey->dwTSC47_16: %lX\n ", pKey->dwTSC47_16));
820 //DBG_PRN_GRP12(("pKey->wTSC15_0: %X\n ", pKey->wTSC15_0));
821 //DBG_PRN_GRP12(("pKey->dwKeyIndex: %lX\n ", pKey->dwKeyIndex));
823 } // (pTable->KeyTable[i].bInUse == true)