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
168 PSKeyManagement pTable
,
176 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybGetKey() \n");
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
);
190 } else if (dwKeyIndex
< MAX_GROUP_KEY
) {
191 if (pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
].bKeyValid
== TRUE
) {
192 *pKey
= &(pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
]);
209 * Description: Set Key to table
213 * pTable - Pointer to Key table
214 * pbyBSSID - BSSID of Key
215 * dwKeyIndex - Key index (reference to NDIS DDK)
216 * uKeyLength - Key length
218 * pbyKey - Pointer to key
222 * Return Value: TRUE if success otherwise FALSE
226 void *pDeviceHandler
,
227 PSKeyManagement pTable
,
236 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
242 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enter KeybSetKey: %lX\n", dwKeyIndex
);
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))) {
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) {
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
262 if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
)
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
);
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);
275 pTable
->KeyTable
[i
].wKeyCtl
|= 0x8000; // enable on-fly
277 pKey
->bKeyValid
= TRUE
;
278 pKey
->uKeyLength
= uKeyLength
;
279 pKey
->dwKeyIndex
= dwKeyIndex
;
280 pKey
->byCipherSuite
= byKeyDecMode
;
281 memcpy(pKey
->abyKey
, pbyKey
, uKeyLength
);
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;
288 MACvSetKeyEntry(pDevice
, pTable
->KeyTable
[i
].wKeyCtl
, i
, uKeyIdx
, pbyBSSID
, (PDWORD
)pKey
->abyKey
);
290 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
292 memset(&(pKey
->KeyRSC
), 0, sizeof(QWORD
));
295 memcpy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
297 pKey
->dwTSC47_16
= 0;
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
]);
307 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
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
);
316 if (j
< (MAX_KEY_TABLE
-1)) {
317 memcpy(pTable
->KeyTable
[j
].abyBSSID
, pbyBSSID
, ETH_ALEN
);
318 pTable
->KeyTable
[j
].bInUse
= TRUE
;
319 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
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
327 if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
)
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
);
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);
340 pTable
->KeyTable
[j
].wKeyCtl
|= 0x8000; // enable on-fly
342 pKey
->bKeyValid
= TRUE
;
343 pKey
->uKeyLength
= uKeyLength
;
344 pKey
->dwKeyIndex
= dwKeyIndex
;
345 pKey
->byCipherSuite
= byKeyDecMode
;
346 memcpy(pKey
->abyKey
, pbyKey
, uKeyLength
);
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;
353 MACvSetKeyEntry(pDevice
, pTable
->KeyTable
[j
].wKeyCtl
, j
, uKeyIdx
, pbyBSSID
, (PDWORD
)pKey
->abyKey
);
355 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
357 memset(&(pKey
->KeyRSC
), 0, sizeof(QWORD
));
360 memcpy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
362 pKey
->dwTSC47_16
= 0;
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
]);
372 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
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
);
385 * Description: Remove Key from table
389 * pTable - Pointer to Key table
390 * pbyBSSID - BSSID of Key
391 * dwKeyIndex - Key Index (reference to NDIS DDK)
395 * Return Value: TRUE if success otherwise FALSE
399 void *pDeviceHandler
,
400 PSKeyManagement pTable
,
405 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
407 BOOL bReturnValue
= FALSE
;
409 if (IS_BROADCAST_ADDRESS(pbyBSSID
)) {
411 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
412 for (i
=0;i
<MAX_KEY_TABLE
;i
++) {
413 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= FALSE
;
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;
428 bReturnValue
= FALSE
;
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
)) {
436 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
437 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= FALSE
;
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;
451 bReturnValue
= FALSE
;
454 } //pTable->KeyTable[i].bInUse == TRUE
459 s_vCheckKeyTableValid(pDevice
,pTable
);
467 * Description: Remove Key from table
471 * pTable - Pointer to Key table
472 * pbyBSSID - BSSID of Key
476 * Return Value: TRUE if success otherwise FALSE
479 BOOL
KeybRemoveAllKey(
480 void *pDeviceHandler
,
481 PSKeyManagement pTable
,
485 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
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
;
495 pTable
->KeyTable
[i
].dwGTKeyIndex
= 0;
496 s_vCheckKeyTableValid(pDevice
, pTable
);
504 * Description: Remove WEP Key from table
508 * pTable - Pointer to Key table
512 * Return Value: TRUE if success otherwise FALSE
515 void KeyvRemoveWEPKey(
516 void *pDeviceHandler
,
517 PSKeyManagement pTable
,
521 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
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;
533 s_vCheckKeyTableValid(pDevice
, pTable
);
538 void KeyvRemoveAllWEPKey(
539 void *pDeviceHandler
,
540 PSKeyManagement pTable
543 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
547 for(i
=0;i
<MAX_GROUP_KEY
;i
++) {
548 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 (
567 PSKeyManagement pTable
,
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
)) {
580 if (dwKeyType
== PAIRWISE_KEY
) {
582 if (pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
== TRUE
) {
583 *pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
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
]);
590 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
596 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PairwiseKey.bKeyValid == FALSE\n");
599 } // End of Type == PAIRWISE
601 if (pTable
->KeyTable
[i
].dwGTKeyIndex
== 0) {
602 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ERROR: dwGTKeyIndex == 0 !!!\n");
605 if (pTable
->KeyTable
[i
].GroupKey
[(pTable
->KeyTable
[i
].dwGTKeyIndex
&0x000000FF)].bKeyValid
== TRUE
) {
606 *pKey
= &(pTable
->KeyTable
[i
].GroupKey
[(pTable
->KeyTable
[i
].dwGTKeyIndex
&0x000000FF)]);
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
]);
613 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
614 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dwGTKeyIndex: %lX\n", pTable
->KeyTable
[i
].dwGTKeyIndex
);
619 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GroupKey.bKeyValid == FALSE\n");
622 } // End of Type = GROUP
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
));
629 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
635 * Description: Check Pairewise Key
639 * pTable - Pointer to Key table
643 * Return Value: TRUE if found otherwise FALSE
646 BOOL
KeybCheckPairewiseKey (
647 PSKeyManagement pTable
,
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
);
665 * Description: Set Key to table
669 * pTable - Pointer to Key table
670 * dwKeyIndex - Key index (reference to NDIS DDK)
671 * uKeyLength - Key length
673 * pbyKey - Pointer to key
677 * Return Value: TRUE if success otherwise FALSE
680 BOOL
KeybSetDefaultKey(
681 void *pDeviceHandler
,
682 PSKeyManagement pTable
,
690 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
695 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enter KeybSetDefaultKey: %1x, %d \n", (int)dwKeyIndex
, (int)uKeyLength
);
698 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) { // Pairwise key
700 } else if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
) {
704 pTable
->KeyTable
[MAX_KEY_TABLE
-1].bInUse
= TRUE
;
705 for (ii
= 0; ii
< ETH_ALEN
; ii
++)
706 pTable
->KeyTable
[MAX_KEY_TABLE
-1].abyBSSID
[ii
] = 0xFF;
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);
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);
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
;
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
731 pKey
->bKeyValid
= TRUE
;
732 pKey
->uKeyLength
= uKeyLength
;
733 pKey
->dwKeyIndex
= dwKeyIndex
;
734 pKey
->byCipherSuite
= byKeyDecMode
;
735 memcpy(pKey
->abyKey
, pbyKey
, uKeyLength
);
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;
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
);
745 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
747 memset(&(pKey
->KeyRSC
), 0, sizeof(QWORD
));
749 memcpy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
751 pKey
->dwTSC47_16
= 0;
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
]);
762 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
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
);
773 * Description: Set Key to table
777 * pTable - Pointer to Key table
778 * dwKeyIndex - Key index (reference to NDIS DDK)
779 * uKeyLength - Key length
781 * pbyKey - Pointer to key
785 * Return Value: TRUE if success otherwise FALSE
788 BOOL
KeybSetAllGroupKey(
789 void *pDeviceHandler
,
790 PSKeyManagement pTable
,
798 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
804 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enter KeybSetAllGroupKey: %lX\n", dwKeyIndex
);
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
"Group transmit key(R)[%lX]: %d\n", pTable
->KeyTable
[i
].dwGTKeyIndex
, i
);
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);
829 pTable
->KeyTable
[i
].wKeyCtl
|= 0x8000; // enable on-fly
831 pKey
->bKeyValid
= TRUE
;
832 pKey
->uKeyLength
= uKeyLength
;
833 pKey
->dwKeyIndex
= dwKeyIndex
;
834 pKey
->byCipherSuite
= byKeyDecMode
;
835 memcpy(pKey
->abyKey
, pbyKey
, uKeyLength
);
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;
843 MACvSetKeyEntry(pDevice
, pTable
->KeyTable
[i
].wKeyCtl
, i
, uKeyIdx
, pTable
->KeyTable
[i
].abyBSSID
, (PDWORD
) pKey
->abyKey
);
845 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
847 memset(&(pKey
->KeyRSC
), 0, sizeof(QWORD
));
850 memcpy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
852 pKey
->dwTSC47_16
= 0;
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
]);
862 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
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));
868 } // (pTable->KeyTable[i].bInUse == TRUE)