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
40 #if !defined(__TMACRO_H__)
43 #if !defined(__TBIT_H__)
46 #if !defined(__KEY_H__)
49 #if !defined(__UMEM_H__)
52 #if !defined(__MAC_H__)
57 /*--------------------- Static Definitions -------------------------*/
59 /*--------------------- Static Classes ----------------------------*/
61 /*--------------------- Static Variables --------------------------*/
62 static int msglevel
=MSG_LEVEL_INFO
;
63 //static int msglevel =MSG_LEVEL_DEBUG;
64 /*--------------------- Static Functions --------------------------*/
66 /*--------------------- Export Variables --------------------------*/
68 /*--------------------- Static Definitions -------------------------*/
70 /*--------------------- Static Classes ----------------------------*/
72 /*--------------------- Static Variables --------------------------*/
74 /*--------------------- Static Functions --------------------------*/
76 s_vCheckKeyTableValid (PSKeyManagement pTable
, DWORD_PTR dwIoBase
)
80 for (i
=0;i
<MAX_KEY_TABLE
;i
++) {
81 if ((pTable
->KeyTable
[i
].bInUse
== TRUE
) &&
82 (pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
== FALSE
) &&
83 (pTable
->KeyTable
[i
].GroupKey
[0].bKeyValid
== FALSE
) &&
84 (pTable
->KeyTable
[i
].GroupKey
[1].bKeyValid
== FALSE
) &&
85 (pTable
->KeyTable
[i
].GroupKey
[2].bKeyValid
== FALSE
) &&
86 (pTable
->KeyTable
[i
].GroupKey
[3].bKeyValid
== FALSE
)
88 pTable
->KeyTable
[i
].bInUse
= FALSE
;
89 pTable
->KeyTable
[i
].wKeyCtl
= 0;
90 pTable
->KeyTable
[i
].bSoftWEP
= FALSE
;
91 MACvDisableKeyEntry(dwIoBase
, i
);
97 /*--------------------- Export Functions --------------------------*/
101 * Description: Init Key management table
105 * pTable - Pointer to Key table
112 VOID
KeyvInitTable (PSKeyManagement pTable
, DWORD_PTR dwIoBase
)
117 for (i
=0;i
<MAX_KEY_TABLE
;i
++) {
118 pTable
->KeyTable
[i
].bInUse
= FALSE
;
119 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= FALSE
;
120 pTable
->KeyTable
[i
].PairwiseKey
.pvKeyTable
= (PVOID
)&pTable
->KeyTable
[i
];
121 for (jj
=0; jj
< MAX_GROUP_KEY
; jj
++) {
122 pTable
->KeyTable
[i
].GroupKey
[jj
].bKeyValid
= FALSE
;
123 pTable
->KeyTable
[i
].GroupKey
[jj
].pvKeyTable
= (PVOID
)&pTable
->KeyTable
[i
];
125 pTable
->KeyTable
[i
].wKeyCtl
= 0;
126 pTable
->KeyTable
[i
].dwGTKeyIndex
= 0;
127 pTable
->KeyTable
[i
].bSoftWEP
= FALSE
;
128 MACvDisableKeyEntry(dwIoBase
, i
);
134 * Description: Get Key from table
138 * pTable - Pointer to Key table
139 * pbyBSSID - BSSID of Key
140 * dwKeyIndex - Key Index (0xFFFFFFFF means pairwise key)
144 * Return Value: TRUE if found otherwise FALSE
148 IN PSKeyManagement pTable
,
156 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybGetKey() \n");
159 for (i
=0;i
<MAX_KEY_TABLE
;i
++) {
160 if ((pTable
->KeyTable
[i
].bInUse
== TRUE
) &&
161 IS_ETH_ADDRESS_EQUAL(pTable
->KeyTable
[i
].abyBSSID
,pbyBSSID
)) {
162 if (dwKeyIndex
== 0xFFFFFFFF) {
163 if (pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
== TRUE
) {
164 *pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
170 } else if (dwKeyIndex
< MAX_GROUP_KEY
) {
171 if (pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
].bKeyValid
== TRUE
) {
172 *pKey
= &(pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
]);
189 * Description: Set Key to table
193 * pTable - Pointer to Key table
194 * pbyBSSID - BSSID of Key
195 * dwKeyIndex - Key index (reference to NDIS DDK)
196 * uKeyLength - Key length
198 * pbyKey - Pointer to key
202 * Return Value: TRUE if success otherwise FALSE
206 PSKeyManagement pTable
,
222 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enter KeybSetKey: %lX\n", dwKeyIndex
);
224 j
= (MAX_KEY_TABLE
-1);
225 for (i
=0;i
<(MAX_KEY_TABLE
-1);i
++) {
226 if ((pTable
->KeyTable
[i
].bInUse
== FALSE
) &&
227 (j
== (MAX_KEY_TABLE
-1))) {
231 if ((pTable
->KeyTable
[i
].bInUse
== TRUE
) &&
232 IS_ETH_ADDRESS_EQUAL(pTable
->KeyTable
[i
].abyBSSID
,pbyBSSID
)) {
233 // found table already exist
234 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
236 pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
237 pTable
->KeyTable
[i
].wKeyCtl
&= 0xFFF0; // clear pairwise key control filed
238 pTable
->KeyTable
[i
].wKeyCtl
|= byKeyDecMode
;
239 uKeyIdx
= 4; // use HW key entry 4 for pairwise key
242 if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
)
244 pKey
= &(pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
& 0x000000FF]);
245 if ((dwKeyIndex
& TRANSMIT_KEY
) != 0) {
246 // Group transmit key
247 pTable
->KeyTable
[i
].dwGTKeyIndex
= dwKeyIndex
;
248 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Group transmit key(R)[%lX]: %d\n", pTable
->KeyTable
[i
].dwGTKeyIndex
, i
);
250 pTable
->KeyTable
[i
].wKeyCtl
&= 0xFF0F; // clear group key control filed
251 pTable
->KeyTable
[i
].wKeyCtl
|= (byKeyDecMode
<< 4);
252 pTable
->KeyTable
[i
].wKeyCtl
|= 0x0040; // use group key for group address
253 uKeyIdx
= (dwKeyIndex
& 0x000000FF);
255 pTable
->KeyTable
[i
].wKeyCtl
|= 0x8000; // enable on-fly
257 pKey
->bKeyValid
= TRUE
;
258 pKey
->uKeyLength
= uKeyLength
;
259 pKey
->dwKeyIndex
= dwKeyIndex
;
260 pKey
->byCipherSuite
= byKeyDecMode
;
261 MEMvCopy(pKey
->abyKey
, pbyKey
, uKeyLength
);
262 if (byKeyDecMode
== KEY_CTL_WEP
) {
263 if (uKeyLength
== WLAN_WEP40_KEYLEN
)
264 pKey
->abyKey
[15] &= 0x7F;
265 if (uKeyLength
== WLAN_WEP104_KEYLEN
)
266 pKey
->abyKey
[15] |= 0x80;
268 MACvSetKeyEntry(dwIoBase
, pTable
->KeyTable
[i
].wKeyCtl
, i
, uKeyIdx
, pbyBSSID
, (PDWORD
)pKey
->abyKey
, byLocalID
);
270 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
272 ZERO_MEMORY(&(pKey
->KeyRSC
), sizeof(QWORD
));
275 MEMvCopy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
277 pKey
->dwTSC47_16
= 0;
280 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybSetKey(R): \n");
281 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->bKeyValid: %d\n ", pKey
->bKeyValid
);
282 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", pKey->uKeyLength);
283 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->abyKey: ");
284 for (ii
= 0; ii
< pKey
->uKeyLength
; ii
++) {
285 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pKey
->abyKey
[ii
]);
287 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
289 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwTSC47_16: %lx\n ", pKey
->dwTSC47_16
);
290 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->wTSC15_0: %x\n ", pKey
->wTSC15_0
);
291 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwKeyIndex: %lx\n ", pKey
->dwKeyIndex
);
296 if (j
< (MAX_KEY_TABLE
-1)) {
297 MEMvCopy(pTable
->KeyTable
[j
].abyBSSID
,pbyBSSID
,U_ETHER_ADDR_LEN
);
298 pTable
->KeyTable
[j
].bInUse
= TRUE
;
299 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
301 pKey
= &(pTable
->KeyTable
[j
].PairwiseKey
);
302 pTable
->KeyTable
[j
].wKeyCtl
&= 0xFFF0; // clear pairwise key control filed
303 pTable
->KeyTable
[j
].wKeyCtl
|= byKeyDecMode
;
304 uKeyIdx
= 4; // use HW key entry 4 for pairwise key
307 if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
)
309 pKey
= &(pTable
->KeyTable
[j
].GroupKey
[dwKeyIndex
& 0x000000FF]);
310 if ((dwKeyIndex
& TRANSMIT_KEY
) != 0) {
311 // Group transmit key
312 pTable
->KeyTable
[j
].dwGTKeyIndex
= dwKeyIndex
;
313 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Group transmit key(N)[%lX]: %d\n", pTable
->KeyTable
[j
].dwGTKeyIndex
, j
);
315 pTable
->KeyTable
[j
].wKeyCtl
&= 0xFF0F; // clear group key control filed
316 pTable
->KeyTable
[j
].wKeyCtl
|= (byKeyDecMode
<< 4);
317 pTable
->KeyTable
[j
].wKeyCtl
|= 0x0040; // use group key for group address
318 uKeyIdx
= (dwKeyIndex
& 0x000000FF);
320 pTable
->KeyTable
[j
].wKeyCtl
|= 0x8000; // enable on-fly
322 pKey
->bKeyValid
= TRUE
;
323 pKey
->uKeyLength
= uKeyLength
;
324 pKey
->dwKeyIndex
= dwKeyIndex
;
325 pKey
->byCipherSuite
= byKeyDecMode
;
326 MEMvCopy(pKey
->abyKey
, pbyKey
, uKeyLength
);
327 if (byKeyDecMode
== KEY_CTL_WEP
) {
328 if (uKeyLength
== WLAN_WEP40_KEYLEN
)
329 pKey
->abyKey
[15] &= 0x7F;
330 if (uKeyLength
== WLAN_WEP104_KEYLEN
)
331 pKey
->abyKey
[15] |= 0x80;
333 MACvSetKeyEntry(dwIoBase
, pTable
->KeyTable
[j
].wKeyCtl
, j
, uKeyIdx
, pbyBSSID
, (PDWORD
)pKey
->abyKey
, byLocalID
);
335 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
337 ZERO_MEMORY(&(pKey
->KeyRSC
), sizeof(QWORD
));
340 MEMvCopy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
342 pKey
->dwTSC47_16
= 0;
345 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybSetKey(N): \n");
346 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->bKeyValid: %d\n ", pKey
->bKeyValid
);
347 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->uKeyLength: %d\n ", (int)pKey
->uKeyLength
);
348 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->abyKey: ");
349 for (ii
= 0; ii
< pKey
->uKeyLength
; ii
++) {
350 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pKey
->abyKey
[ii
]);
352 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
354 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwTSC47_16: %lx\n ", pKey
->dwTSC47_16
);
355 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->wTSC15_0: %x\n ", pKey
->wTSC15_0
);
356 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwKeyIndex: %lx\n ", pKey
->dwKeyIndex
);
365 * Description: Remove Key from table
369 * pTable - Pointer to Key table
370 * pbyBSSID - BSSID of Key
371 * dwKeyIndex - Key Index (reference to NDIS DDK)
375 * Return Value: TRUE if success otherwise FALSE
379 PSKeyManagement pTable
,
387 if (IS_BROADCAST_ADDRESS(pbyBSSID
)) {
389 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
390 for (i
=0;i
<MAX_KEY_TABLE
;i
++) {
391 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= FALSE
;
393 s_vCheckKeyTableValid(pTable
, dwIoBase
);
396 else if ((dwKeyIndex
& 0x000000FF) < MAX_GROUP_KEY
) {
397 for (i
=0;i
<MAX_KEY_TABLE
;i
++) {
398 pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
& 0x000000FF].bKeyValid
= FALSE
;
399 if ((dwKeyIndex
& 0x7FFFFFFF) == (pTable
->KeyTable
[i
].dwGTKeyIndex
& 0x7FFFFFFF)) {
400 // remove Group transmit key
401 pTable
->KeyTable
[i
].dwGTKeyIndex
= 0;
404 s_vCheckKeyTableValid(pTable
, dwIoBase
);
412 for (i
=0;i
<MAX_KEY_TABLE
;i
++) {
413 if ((pTable
->KeyTable
[i
].bInUse
== TRUE
) &&
414 IS_ETH_ADDRESS_EQUAL(pTable
->KeyTable
[i
].abyBSSID
,pbyBSSID
)) {
415 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
416 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= FALSE
;
417 s_vCheckKeyTableValid(pTable
, dwIoBase
);
420 else if ((dwKeyIndex
& 0x000000FF) < MAX_GROUP_KEY
) {
421 pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
& 0x000000FF].bKeyValid
= FALSE
;
422 if ((dwKeyIndex
& 0x7FFFFFFF) == (pTable
->KeyTable
[i
].dwGTKeyIndex
& 0x7FFFFFFF)) {
423 // remove Group transmit key
424 pTable
->KeyTable
[i
].dwGTKeyIndex
= 0;
426 s_vCheckKeyTableValid(pTable
, dwIoBase
);
439 * Description: Remove Key from table
443 * pTable - Pointer to Key table
444 * pbyBSSID - BSSID of Key
448 * Return Value: TRUE if success otherwise FALSE
451 BOOL
KeybRemoveAllKey (
452 PSKeyManagement pTable
,
459 for (i
=0;i
<MAX_KEY_TABLE
;i
++) {
460 if ((pTable
->KeyTable
[i
].bInUse
== TRUE
) &&
461 IS_ETH_ADDRESS_EQUAL(pTable
->KeyTable
[i
].abyBSSID
,pbyBSSID
)) {
462 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= FALSE
;
463 for(u
=0;u
<MAX_GROUP_KEY
;u
++) {
464 pTable
->KeyTable
[i
].GroupKey
[u
].bKeyValid
= FALSE
;
466 pTable
->KeyTable
[i
].dwGTKeyIndex
= 0;
467 s_vCheckKeyTableValid(pTable
, dwIoBase
);
475 * Description: Remove WEP Key from table
479 * pTable - Pointer to Key table
483 * Return Value: TRUE if success otherwise FALSE
486 VOID
KeyvRemoveWEPKey (
487 PSKeyManagement pTable
,
493 if ((dwKeyIndex
& 0x000000FF) < MAX_GROUP_KEY
) {
494 if (pTable
->KeyTable
[MAX_KEY_TABLE
-1].bInUse
== TRUE
) {
495 if (pTable
->KeyTable
[MAX_KEY_TABLE
-1].GroupKey
[dwKeyIndex
& 0x000000FF].byCipherSuite
== KEY_CTL_WEP
) {
496 pTable
->KeyTable
[MAX_KEY_TABLE
-1].GroupKey
[dwKeyIndex
& 0x000000FF].bKeyValid
= FALSE
;
497 if ((dwKeyIndex
& 0x7FFFFFFF) == (pTable
->KeyTable
[MAX_KEY_TABLE
-1].dwGTKeyIndex
& 0x7FFFFFFF)) {
498 // remove Group transmit key
499 pTable
->KeyTable
[MAX_KEY_TABLE
-1].dwGTKeyIndex
= 0;
503 s_vCheckKeyTableValid(pTable
, dwIoBase
);
508 VOID
KeyvRemoveAllWEPKey (
509 PSKeyManagement pTable
,
515 for(i
=0;i
<MAX_GROUP_KEY
;i
++) {
516 KeyvRemoveWEPKey(pTable
, i
, dwIoBase
);
521 * Description: Get Transmit Key from table
525 * pTable - Pointer to Key table
526 * pbyBSSID - BSSID of Key
530 * Return Value: TRUE if found otherwise FALSE
533 BOOL
KeybGetTransmitKey (
534 IN PSKeyManagement pTable
,
543 for (i
=0;i
<MAX_KEY_TABLE
;i
++) {
544 if ((pTable
->KeyTable
[i
].bInUse
== TRUE
) &&
545 IS_ETH_ADDRESS_EQUAL(pTable
->KeyTable
[i
].abyBSSID
,pbyBSSID
)) {
547 if (dwKeyType
== PAIRWISE_KEY
) {
549 if (pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
== TRUE
) {
550 *pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
552 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybGetTransmitKey:");
553 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PAIRWISE_KEY: KeyTable.abyBSSID: ");
554 for (ii
= 0; ii
< 6; ii
++) {
555 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%x ", pTable
->KeyTable
[i
].abyBSSID
[ii
]);
557 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
563 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PairwiseKey.bKeyValid == FALSE\n");
566 } // End of Type == PAIRWISE
568 if (pTable
->KeyTable
[i
].dwGTKeyIndex
== 0) {
569 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ERROR: dwGTKeyIndex == 0 !!!\n");
572 if (pTable
->KeyTable
[i
].GroupKey
[(pTable
->KeyTable
[i
].dwGTKeyIndex
&0x000000FF)].bKeyValid
== TRUE
) {
573 *pKey
= &(pTable
->KeyTable
[i
].GroupKey
[(pTable
->KeyTable
[i
].dwGTKeyIndex
&0x000000FF)]);
575 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybGetTransmitKey:");
576 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GROUP_KEY: KeyTable.abyBSSID\n");
577 for (ii
= 0; ii
< 6; ii
++) {
578 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%x ", pTable
->KeyTable
[i
].abyBSSID
[ii
]);
580 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
581 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dwGTKeyIndex: %lX\n", pTable
->KeyTable
[i
].dwGTKeyIndex
);
586 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GroupKey.bKeyValid == FALSE\n");
589 } // End of Type = GROUP
592 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ERROR: NO Match BSSID !!! ");
593 for (ii
= 0; ii
< 6; ii
++) {
594 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", *(pbyBSSID
+ii
));
596 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
602 * Description: Check Pairewise Key
606 * pTable - Pointer to Key table
610 * Return Value: TRUE if found otherwise FALSE
613 BOOL
KeybCheckPairewiseKey (
614 IN PSKeyManagement pTable
,
621 for (i
=0;i
<MAX_KEY_TABLE
;i
++) {
622 if ((pTable
->KeyTable
[i
].bInUse
== TRUE
) &&
623 (pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
== TRUE
)) {
624 *pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
632 * Description: Set Key to table
636 * pTable - Pointer to Key table
637 * dwKeyIndex - Key index (reference to NDIS DDK)
638 * uKeyLength - Key length
640 * pbyKey - Pointer to key
644 * Return Value: TRUE if success otherwise FALSE
647 BOOL
KeybSetDefaultKey (
648 PSKeyManagement pTable
,
662 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enter KeybSetDefaultKey: %1x, %d \n", (int)dwKeyIndex
, (int)uKeyLength
);
665 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) { // Pairwise key
667 } else if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
) {
671 pTable
->KeyTable
[MAX_KEY_TABLE
-1].bInUse
= TRUE
;
672 for(ii
=0;ii
<U_ETHER_ADDR_LEN
;ii
++)
673 pTable
->KeyTable
[MAX_KEY_TABLE
-1].abyBSSID
[ii
] = 0xFF;
676 pKey
= &(pTable
->KeyTable
[MAX_KEY_TABLE
-1].GroupKey
[dwKeyIndex
& 0x000000FF]);
677 if ((dwKeyIndex
& TRANSMIT_KEY
) != 0) {
678 // Group transmit key
679 pTable
->KeyTable
[MAX_KEY_TABLE
-1].dwGTKeyIndex
= dwKeyIndex
;
680 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Group transmit key(R)[%lX]: %d\n", pTable
->KeyTable
[MAX_KEY_TABLE
-1].dwGTKeyIndex
, MAX_KEY_TABLE
-1);
683 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
&= 0x7F00; // clear all key control filed
684 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= (byKeyDecMode
<< 4);
685 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= (byKeyDecMode
);
686 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= 0x0044; // use group key for all address
687 uKeyIdx
= (dwKeyIndex
& 0x000000FF);
689 if ((uKeyLength
== WLAN_WEP232_KEYLEN
) &&
690 (byKeyDecMode
== KEY_CTL_WEP
)) {
691 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= 0x4000; // disable on-fly disable address match
692 pTable
->KeyTable
[MAX_KEY_TABLE
-1].bSoftWEP
= TRUE
;
694 if (pTable
->KeyTable
[MAX_KEY_TABLE
-1].bSoftWEP
== FALSE
)
695 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= 0xC000; // enable on-fly disable address match
698 pKey
->bKeyValid
= TRUE
;
699 pKey
->uKeyLength
= uKeyLength
;
700 pKey
->dwKeyIndex
= dwKeyIndex
;
701 pKey
->byCipherSuite
= byKeyDecMode
;
702 MEMvCopy(pKey
->abyKey
, pbyKey
, uKeyLength
);
703 if (byKeyDecMode
== KEY_CTL_WEP
) {
704 if (uKeyLength
== WLAN_WEP40_KEYLEN
)
705 pKey
->abyKey
[15] &= 0x7F;
706 if (uKeyLength
== WLAN_WEP104_KEYLEN
)
707 pKey
->abyKey
[15] |= 0x80;
709 MACvSetKeyEntry(dwIoBase
, pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
, MAX_KEY_TABLE
-1, uKeyIdx
, pTable
->KeyTable
[MAX_KEY_TABLE
-1].abyBSSID
, (PDWORD
)pKey
->abyKey
, byLocalID
);
711 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
713 ZERO_MEMORY(&(pKey
->KeyRSC
), sizeof(QWORD
));
715 MEMvCopy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
717 pKey
->dwTSC47_16
= 0;
721 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybSetKey(R): \n");
722 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->bKeyValid: %d\n", pKey
->bKeyValid
);
723 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->uKeyLength: %d\n", (int)pKey
->uKeyLength
);
724 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->abyKey: \n");
725 for (ii
= 0; ii
< pKey
->uKeyLength
; ii
++) {
726 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%x", pKey
->abyKey
[ii
]);
728 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
730 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwTSC47_16: %lx\n", pKey
->dwTSC47_16
);
731 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->wTSC15_0: %x\n", pKey
->wTSC15_0
);
732 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwKeyIndex: %lx\n", pKey
->dwKeyIndex
);
739 * Description: Set Key to table
743 * pTable - Pointer to Key table
744 * dwKeyIndex - Key index (reference to NDIS DDK)
745 * uKeyLength - Key length
747 * pbyKey - Pointer to key
751 * Return Value: TRUE if success otherwise FALSE
754 BOOL
KeybSetAllGroupKey (
755 PSKeyManagement pTable
,
770 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enter KeybSetAllGroupKey: %lX\n", dwKeyIndex
);
773 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) { // Pairwise key
775 } else if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
) {
779 for (i
=0; i
< MAX_KEY_TABLE
-1; i
++) {
780 if (pTable
->KeyTable
[i
].bInUse
== TRUE
) {
781 // found table already exist
783 pKey
= &(pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
& 0x000000FF]);
784 if ((dwKeyIndex
& TRANSMIT_KEY
) != 0) {
785 // Group transmit key
786 pTable
->KeyTable
[i
].dwGTKeyIndex
= dwKeyIndex
;
787 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Group transmit key(R)[%lX]: %d\n", pTable
->KeyTable
[i
].dwGTKeyIndex
, i
);
790 pTable
->KeyTable
[i
].wKeyCtl
&= 0xFF0F; // clear group key control filed
791 pTable
->KeyTable
[i
].wKeyCtl
|= (byKeyDecMode
<< 4);
792 pTable
->KeyTable
[i
].wKeyCtl
|= 0x0040; // use group key for group address
793 uKeyIdx
= (dwKeyIndex
& 0x000000FF);
795 pTable
->KeyTable
[i
].wKeyCtl
|= 0x8000; // enable on-fly
797 pKey
->bKeyValid
= TRUE
;
798 pKey
->uKeyLength
= uKeyLength
;
799 pKey
->dwKeyIndex
= dwKeyIndex
;
800 pKey
->byCipherSuite
= byKeyDecMode
;
801 MEMvCopy(pKey
->abyKey
, pbyKey
, uKeyLength
);
802 if (byKeyDecMode
== KEY_CTL_WEP
) {
803 if (uKeyLength
== WLAN_WEP40_KEYLEN
)
804 pKey
->abyKey
[15] &= 0x7F;
805 if (uKeyLength
== WLAN_WEP104_KEYLEN
)
806 pKey
->abyKey
[15] |= 0x80;
808 MACvSetKeyEntry(dwIoBase
, pTable
->KeyTable
[i
].wKeyCtl
, i
, uKeyIdx
, pTable
->KeyTable
[i
].abyBSSID
, (PDWORD
)pKey
->abyKey
, byLocalID
);
810 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
812 ZERO_MEMORY(&(pKey
->KeyRSC
), sizeof(QWORD
));
815 MEMvCopy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
817 pKey
->dwTSC47_16
= 0;
820 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybSetKey(R): \n");
821 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->bKeyValid: %d\n ", pKey
->bKeyValid
);
822 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->uKeyLength: %d\n ", (int)pKey
->uKeyLength
);
823 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->abyKey: ");
824 for (ii
= 0; ii
< pKey
->uKeyLength
; ii
++) {
825 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pKey
->abyKey
[ii
]);
827 DEVICE_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
829 //DBG_PRN_GRP12(("pKey->dwTSC47_16: %lX\n ", pKey->dwTSC47_16));
830 //DBG_PRN_GRP12(("pKey->wTSC15_0: %X\n ", pKey->wTSC15_0));
831 //DBG_PRN_GRP12(("pKey->dwKeyIndex: %lX\n ", pKey->dwKeyIndex));
833 } // (pTable->KeyTable[i].bInUse == TRUE)