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
&&
68 !pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
&&
69 !pTable
->KeyTable
[i
].GroupKey
[0].bKeyValid
&&
70 !pTable
->KeyTable
[i
].GroupKey
[1].bKeyValid
&&
71 !pTable
->KeyTable
[i
].GroupKey
[2].bKeyValid
&&
72 !pTable
->KeyTable
[i
].GroupKey
[3].bKeyValid
) {
73 pTable
->KeyTable
[i
].bInUse
= false;
74 pTable
->KeyTable
[i
].wKeyCtl
= 0;
75 pTable
->KeyTable
[i
].bSoftWEP
= false;
76 MACvDisableKeyEntry(dwIoBase
, i
);
81 /*--------------------- Export Functions --------------------------*/
84 * Description: Init Key management table
88 * pTable - Pointer to Key table
95 void KeyvInitTable(PSKeyManagement pTable
, unsigned long dwIoBase
)
100 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
101 pTable
->KeyTable
[i
].bInUse
= false;
102 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= false;
103 pTable
->KeyTable
[i
].PairwiseKey
.pvKeyTable
= (void *)&pTable
->KeyTable
[i
];
104 for (jj
= 0; jj
< MAX_GROUP_KEY
; jj
++) {
105 pTable
->KeyTable
[i
].GroupKey
[jj
].bKeyValid
= false;
106 pTable
->KeyTable
[i
].GroupKey
[jj
].pvKeyTable
= (void *)&pTable
->KeyTable
[i
];
108 pTable
->KeyTable
[i
].wKeyCtl
= 0;
109 pTable
->KeyTable
[i
].dwGTKeyIndex
= 0;
110 pTable
->KeyTable
[i
].bSoftWEP
= false;
111 MACvDisableKeyEntry(dwIoBase
, i
);
116 * Description: Get Key from table
120 * pTable - Pointer to Key table
121 * pbyBSSID - BSSID of Key
122 * dwKeyIndex - Key Index (0xFFFFFFFF means pairwise key)
126 * Return Value: true if found otherwise false
130 PSKeyManagement pTable
,
131 unsigned char *pbyBSSID
,
132 unsigned long dwKeyIndex
,
138 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybGetKey() \n");
141 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
142 if (pTable
->KeyTable
[i
].bInUse
&&
143 ether_addr_equal(pTable
->KeyTable
[i
].abyBSSID
, pbyBSSID
)) {
144 if (dwKeyIndex
== 0xFFFFFFFF) {
145 if (pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
) {
146 *pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
151 } else if (dwKeyIndex
< MAX_GROUP_KEY
) {
152 if (pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
].bKeyValid
) {
153 *pKey
= &(pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
]);
167 * Description: Set Key to table
171 * pTable - Pointer to Key table
172 * pbyBSSID - BSSID of Key
173 * dwKeyIndex - Key index (reference to NDIS DDK)
174 * uKeyLength - Key length
176 * pbyKey - Pointer to key
180 * Return Value: true if success otherwise false
184 PSKeyManagement pTable
,
185 unsigned char *pbyBSSID
,
186 unsigned long dwKeyIndex
,
187 unsigned long uKeyLength
,
189 unsigned char *pbyKey
,
190 unsigned char byKeyDecMode
,
191 unsigned long dwIoBase
,
192 unsigned char byLocalID
198 unsigned int uKeyIdx
;
200 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enter KeybSetKey: %lX\n", dwKeyIndex
);
202 j
= (MAX_KEY_TABLE
-1);
203 for (i
= 0; i
< (MAX_KEY_TABLE
- 1); i
++) {
204 if (!pTable
->KeyTable
[i
].bInUse
&& (j
== (MAX_KEY_TABLE
-1))) {
208 if (pTable
->KeyTable
[i
].bInUse
&&
209 ether_addr_equal(pTable
->KeyTable
[i
].abyBSSID
, pbyBSSID
)) {
210 // found table already exist
211 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
213 pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
214 pTable
->KeyTable
[i
].wKeyCtl
&= 0xFFF0; // clear pairwise key control filed
215 pTable
->KeyTable
[i
].wKeyCtl
|= byKeyDecMode
;
216 uKeyIdx
= 4; // use HW key entry 4 for pairwise key
219 if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
)
221 pKey
= &(pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
& 0x000000FF]);
222 if ((dwKeyIndex
& TRANSMIT_KEY
) != 0) {
223 // Group transmit key
224 pTable
->KeyTable
[i
].dwGTKeyIndex
= dwKeyIndex
;
225 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Group transmit key(R)[%lX]: %d\n", pTable
->KeyTable
[i
].dwGTKeyIndex
, i
);
227 pTable
->KeyTable
[i
].wKeyCtl
&= 0xFF0F; // clear group key control filed
228 pTable
->KeyTable
[i
].wKeyCtl
|= (byKeyDecMode
<< 4);
229 pTable
->KeyTable
[i
].wKeyCtl
|= 0x0040; // use group key for group address
230 uKeyIdx
= (dwKeyIndex
& 0x000000FF);
232 pTable
->KeyTable
[i
].wKeyCtl
|= 0x8000; // enable on-fly
234 pKey
->bKeyValid
= true;
235 pKey
->uKeyLength
= uKeyLength
;
236 pKey
->dwKeyIndex
= dwKeyIndex
;
237 pKey
->byCipherSuite
= byKeyDecMode
;
238 memcpy(pKey
->abyKey
, pbyKey
, uKeyLength
);
239 if (byKeyDecMode
== KEY_CTL_WEP
) {
240 if (uKeyLength
== WLAN_WEP40_KEYLEN
)
241 pKey
->abyKey
[15] &= 0x7F;
242 if (uKeyLength
== WLAN_WEP104_KEYLEN
)
243 pKey
->abyKey
[15] |= 0x80;
245 MACvSetKeyEntry(dwIoBase
, pTable
->KeyTable
[i
].wKeyCtl
, i
, uKeyIdx
, pbyBSSID
, (unsigned long *)pKey
->abyKey
, byLocalID
);
247 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
249 memset(&(pKey
->KeyRSC
), 0, sizeof(QWORD
));
251 memcpy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
253 pKey
->dwTSC47_16
= 0;
256 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybSetKey(R): \n");
257 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->bKeyValid: %d\n ", pKey
->bKeyValid
);
258 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->uKeyLength: %d\n ", pKey->uKeyLength);
259 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->abyKey: ");
260 for (ii
= 0; ii
< pKey
->uKeyLength
; ii
++) {
261 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pKey
->abyKey
[ii
]);
263 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
265 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwTSC47_16: %lx\n ", pKey
->dwTSC47_16
);
266 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->wTSC15_0: %x\n ", pKey
->wTSC15_0
);
267 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwKeyIndex: %lx\n ", pKey
->dwKeyIndex
);
272 if (j
< (MAX_KEY_TABLE
-1)) {
273 memcpy(pTable
->KeyTable
[j
].abyBSSID
, pbyBSSID
, ETH_ALEN
);
274 pTable
->KeyTable
[j
].bInUse
= true;
275 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
277 pKey
= &(pTable
->KeyTable
[j
].PairwiseKey
);
278 pTable
->KeyTable
[j
].wKeyCtl
&= 0xFFF0; // clear pairwise key control filed
279 pTable
->KeyTable
[j
].wKeyCtl
|= byKeyDecMode
;
280 uKeyIdx
= 4; // use HW key entry 4 for pairwise key
283 if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
)
285 pKey
= &(pTable
->KeyTable
[j
].GroupKey
[dwKeyIndex
& 0x000000FF]);
286 if ((dwKeyIndex
& TRANSMIT_KEY
) != 0) {
287 // Group transmit key
288 pTable
->KeyTable
[j
].dwGTKeyIndex
= dwKeyIndex
;
289 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Group transmit key(N)[%lX]: %d\n", pTable
->KeyTable
[j
].dwGTKeyIndex
, j
);
291 pTable
->KeyTable
[j
].wKeyCtl
&= 0xFF0F; // clear group key control filed
292 pTable
->KeyTable
[j
].wKeyCtl
|= (byKeyDecMode
<< 4);
293 pTable
->KeyTable
[j
].wKeyCtl
|= 0x0040; // use group key for group address
294 uKeyIdx
= (dwKeyIndex
& 0x000000FF);
296 pTable
->KeyTable
[j
].wKeyCtl
|= 0x8000; // enable on-fly
298 pKey
->bKeyValid
= true;
299 pKey
->uKeyLength
= uKeyLength
;
300 pKey
->dwKeyIndex
= dwKeyIndex
;
301 pKey
->byCipherSuite
= byKeyDecMode
;
302 memcpy(pKey
->abyKey
, pbyKey
, uKeyLength
);
303 if (byKeyDecMode
== KEY_CTL_WEP
) {
304 if (uKeyLength
== WLAN_WEP40_KEYLEN
)
305 pKey
->abyKey
[15] &= 0x7F;
306 if (uKeyLength
== WLAN_WEP104_KEYLEN
)
307 pKey
->abyKey
[15] |= 0x80;
309 MACvSetKeyEntry(dwIoBase
, pTable
->KeyTable
[j
].wKeyCtl
, j
, uKeyIdx
, pbyBSSID
, (unsigned long *)pKey
->abyKey
, byLocalID
);
311 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
313 memset(&(pKey
->KeyRSC
), 0, sizeof(QWORD
));
315 memcpy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
317 pKey
->dwTSC47_16
= 0;
320 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybSetKey(N): \n");
321 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->bKeyValid: %d\n ", pKey
->bKeyValid
);
322 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->uKeyLength: %d\n ", (int)pKey
->uKeyLength
);
323 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->abyKey: ");
324 for (ii
= 0; ii
< pKey
->uKeyLength
; ii
++) {
325 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pKey
->abyKey
[ii
]);
327 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
329 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwTSC47_16: %lx\n ", pKey
->dwTSC47_16
);
330 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->wTSC15_0: %x\n ", pKey
->wTSC15_0
);
331 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwKeyIndex: %lx\n ", pKey
->dwKeyIndex
);
339 * Description: Remove Key from table
343 * pTable - Pointer to Key table
344 * pbyBSSID - BSSID of Key
345 * dwKeyIndex - Key Index (reference to NDIS DDK)
349 * Return Value: true if success otherwise false
353 PSKeyManagement pTable
,
354 unsigned char *pbyBSSID
,
355 unsigned long dwKeyIndex
,
356 unsigned long dwIoBase
361 if (is_broadcast_ether_addr(pbyBSSID
)) {
363 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
364 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
365 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= false;
367 s_vCheckKeyTableValid(pTable
, dwIoBase
);
369 } else if ((dwKeyIndex
& 0x000000FF) < MAX_GROUP_KEY
) {
370 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
371 pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
& 0x000000FF].bKeyValid
= false;
372 if ((dwKeyIndex
& 0x7FFFFFFF) == (pTable
->KeyTable
[i
].dwGTKeyIndex
& 0x7FFFFFFF)) {
373 // remove Group transmit key
374 pTable
->KeyTable
[i
].dwGTKeyIndex
= 0;
377 s_vCheckKeyTableValid(pTable
, dwIoBase
);
384 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
385 if (pTable
->KeyTable
[i
].bInUse
&&
386 ether_addr_equal(pTable
->KeyTable
[i
].abyBSSID
, pbyBSSID
)) {
387 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
388 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= false;
389 s_vCheckKeyTableValid(pTable
, dwIoBase
);
391 } else if ((dwKeyIndex
& 0x000000FF) < MAX_GROUP_KEY
) {
392 pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
& 0x000000FF].bKeyValid
= false;
393 if ((dwKeyIndex
& 0x7FFFFFFF) == (pTable
->KeyTable
[i
].dwGTKeyIndex
& 0x7FFFFFFF)) {
394 // remove Group transmit key
395 pTable
->KeyTable
[i
].dwGTKeyIndex
= 0;
397 s_vCheckKeyTableValid(pTable
, dwIoBase
);
408 * Description: Remove Key from table
412 * pTable - Pointer to Key table
413 * pbyBSSID - BSSID of Key
417 * Return Value: true if success otherwise false
420 bool KeybRemoveAllKey(
421 PSKeyManagement pTable
,
422 unsigned char *pbyBSSID
,
423 unsigned long dwIoBase
428 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
429 if (pTable
->KeyTable
[i
].bInUse
&&
430 ether_addr_equal(pTable
->KeyTable
[i
].abyBSSID
, pbyBSSID
)) {
431 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= false;
432 for (u
= 0; u
< MAX_GROUP_KEY
; u
++) {
433 pTable
->KeyTable
[i
].GroupKey
[u
].bKeyValid
= false;
435 pTable
->KeyTable
[i
].dwGTKeyIndex
= 0;
436 s_vCheckKeyTableValid(pTable
, dwIoBase
);
444 * Description: Remove WEP Key from table
448 * pTable - Pointer to Key table
452 * Return Value: true if success otherwise false
455 void KeyvRemoveWEPKey(
456 PSKeyManagement pTable
,
457 unsigned long dwKeyIndex
,
458 unsigned long dwIoBase
461 if ((dwKeyIndex
& 0x000000FF) < MAX_GROUP_KEY
) {
462 if (pTable
->KeyTable
[MAX_KEY_TABLE
-1].bInUse
) {
463 if (pTable
->KeyTable
[MAX_KEY_TABLE
-1].GroupKey
[dwKeyIndex
& 0x000000FF].byCipherSuite
== KEY_CTL_WEP
) {
464 pTable
->KeyTable
[MAX_KEY_TABLE
-1].GroupKey
[dwKeyIndex
& 0x000000FF].bKeyValid
= false;
465 if ((dwKeyIndex
& 0x7FFFFFFF) == (pTable
->KeyTable
[MAX_KEY_TABLE
-1].dwGTKeyIndex
& 0x7FFFFFFF)) {
466 // remove Group transmit key
467 pTable
->KeyTable
[MAX_KEY_TABLE
-1].dwGTKeyIndex
= 0;
471 s_vCheckKeyTableValid(pTable
, dwIoBase
);
476 void KeyvRemoveAllWEPKey(
477 PSKeyManagement pTable
,
478 unsigned long dwIoBase
483 for (i
= 0; i
< MAX_GROUP_KEY
; i
++) {
484 KeyvRemoveWEPKey(pTable
, i
, dwIoBase
);
489 * Description: Get Transmit Key from table
493 * pTable - Pointer to Key table
494 * pbyBSSID - BSSID of Key
498 * Return Value: true if found otherwise false
501 bool KeybGetTransmitKey(
502 PSKeyManagement pTable
,
503 unsigned char *pbyBSSID
,
504 unsigned long dwKeyType
,
511 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
512 if (pTable
->KeyTable
[i
].bInUse
&&
513 ether_addr_equal(pTable
->KeyTable
[i
].abyBSSID
, pbyBSSID
)) {
514 if (dwKeyType
== PAIRWISE_KEY
) {
515 if (pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
) {
516 *pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
518 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybGetTransmitKey:");
519 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PAIRWISE_KEY: KeyTable.abyBSSID: ");
520 for (ii
= 0; ii
< 6; ii
++) {
521 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%x ", pTable
->KeyTable
[i
].abyBSSID
[ii
]);
523 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
527 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PairwiseKey.bKeyValid == false\n");
530 } // End of Type == PAIRWISE
532 if (pTable
->KeyTable
[i
].dwGTKeyIndex
== 0) {
533 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ERROR: dwGTKeyIndex == 0 !!!\n");
536 if (pTable
->KeyTable
[i
].GroupKey
[(pTable
->KeyTable
[i
].dwGTKeyIndex
&0x000000FF)].bKeyValid
) {
537 *pKey
= &(pTable
->KeyTable
[i
].GroupKey
[(pTable
->KeyTable
[i
].dwGTKeyIndex
&0x000000FF)]);
539 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybGetTransmitKey:");
540 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GROUP_KEY: KeyTable.abyBSSID\n");
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");
545 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dwGTKeyIndex: %lX\n", pTable
->KeyTable
[i
].dwGTKeyIndex
);
549 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GroupKey.bKeyValid == false\n");
552 } // End of Type = GROUP
555 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ERROR: NO Match BSSID !!! ");
556 for (ii
= 0; ii
< 6; ii
++) {
557 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", *(pbyBSSID
+ii
));
559 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
564 * Description: Check Pairewise Key
568 * pTable - Pointer to Key table
572 * Return Value: true if found otherwise false
575 bool KeybCheckPairewiseKey(
576 PSKeyManagement pTable
,
583 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
584 if (pTable
->KeyTable
[i
].bInUse
&&
585 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
) {
586 *pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
594 * Description: Set Key to table
598 * pTable - Pointer to Key table
599 * dwKeyIndex - Key index (reference to NDIS DDK)
600 * uKeyLength - Key length
602 * pbyKey - Pointer to key
606 * Return Value: true if success otherwise false
609 bool KeybSetDefaultKey(
610 PSKeyManagement pTable
,
611 unsigned long dwKeyIndex
,
612 unsigned long uKeyLength
,
614 unsigned char *pbyKey
,
615 unsigned char byKeyDecMode
,
616 unsigned long dwIoBase
,
617 unsigned char byLocalID
622 unsigned int uKeyIdx
;
624 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enter KeybSetDefaultKey: %1x, %d \n", (int)dwKeyIndex
, (int)uKeyLength
);
626 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) { // Pairwise key
628 } else if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
) {
632 if (uKeyLength
> MAX_KEY_LEN
)
635 pTable
->KeyTable
[MAX_KEY_TABLE
- 1].bInUse
= true;
636 for (ii
= 0; ii
< ETH_ALEN
; ii
++)
637 pTable
->KeyTable
[MAX_KEY_TABLE
- 1].abyBSSID
[ii
] = 0xFF;
640 pKey
= &(pTable
->KeyTable
[MAX_KEY_TABLE
- 1].GroupKey
[dwKeyIndex
& 0x000000FF]);
641 if ((dwKeyIndex
& TRANSMIT_KEY
) != 0) {
642 // Group transmit key
643 pTable
->KeyTable
[MAX_KEY_TABLE
-1].dwGTKeyIndex
= dwKeyIndex
;
644 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);
647 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
&= 0x7F00; // clear all key control filed
648 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= (byKeyDecMode
<< 4);
649 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= (byKeyDecMode
);
650 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= 0x0044; // use group key for all address
651 uKeyIdx
= (dwKeyIndex
& 0x000000FF);
653 if ((uKeyLength
== WLAN_WEP232_KEYLEN
) &&
654 (byKeyDecMode
== KEY_CTL_WEP
)) {
655 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= 0x4000; // disable on-fly disable address match
656 pTable
->KeyTable
[MAX_KEY_TABLE
-1].bSoftWEP
= true;
658 if (!pTable
->KeyTable
[MAX_KEY_TABLE
-1].bSoftWEP
)
659 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= 0xC000; // enable on-fly disable address match
662 pKey
->bKeyValid
= true;
663 pKey
->uKeyLength
= uKeyLength
;
664 pKey
->dwKeyIndex
= dwKeyIndex
;
665 pKey
->byCipherSuite
= byKeyDecMode
;
666 memcpy(pKey
->abyKey
, pbyKey
, uKeyLength
);
667 if (byKeyDecMode
== KEY_CTL_WEP
) {
668 if (uKeyLength
== WLAN_WEP40_KEYLEN
)
669 pKey
->abyKey
[15] &= 0x7F;
670 if (uKeyLength
== WLAN_WEP104_KEYLEN
)
671 pKey
->abyKey
[15] |= 0x80;
673 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
);
675 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
677 memset(&(pKey
->KeyRSC
), 0, sizeof(QWORD
));
679 memcpy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
681 pKey
->dwTSC47_16
= 0;
684 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybSetKey(R): \n");
685 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->bKeyValid: %d\n", pKey
->bKeyValid
);
686 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->uKeyLength: %d\n", (int)pKey
->uKeyLength
);
687 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->abyKey: \n");
688 for (ii
= 0; ii
< pKey
->uKeyLength
; ii
++) {
689 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%x", pKey
->abyKey
[ii
]);
691 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
693 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwTSC47_16: %lx\n", pKey
->dwTSC47_16
);
694 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->wTSC15_0: %x\n", pKey
->wTSC15_0
);
695 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwKeyIndex: %lx\n", pKey
->dwKeyIndex
);
701 * Description: Set Key to table
705 * pTable - Pointer to Key table
706 * dwKeyIndex - Key index (reference to NDIS DDK)
707 * uKeyLength - Key length
709 * pbyKey - Pointer to key
713 * Return Value: true if success otherwise false
716 bool KeybSetAllGroupKey(
717 PSKeyManagement pTable
,
718 unsigned long dwKeyIndex
,
719 unsigned long uKeyLength
,
721 unsigned char *pbyKey
,
722 unsigned char byKeyDecMode
,
723 unsigned long dwIoBase
,
724 unsigned char byLocalID
730 unsigned int uKeyIdx
;
732 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enter KeybSetAllGroupKey: %lX\n", dwKeyIndex
);
734 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) { // Pairwise key
736 } else if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
) {
740 for (i
= 0; i
< MAX_KEY_TABLE
- 1; i
++) {
741 if (pTable
->KeyTable
[i
].bInUse
) {
742 // found table already exist
744 pKey
= &(pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
& 0x000000FF]);
745 if ((dwKeyIndex
& TRANSMIT_KEY
) != 0) {
746 // Group transmit key
747 pTable
->KeyTable
[i
].dwGTKeyIndex
= dwKeyIndex
;
748 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Group transmit key(R)[%lX]: %d\n", pTable
->KeyTable
[i
].dwGTKeyIndex
, i
);
751 pTable
->KeyTable
[i
].wKeyCtl
&= 0xFF0F; // clear group key control filed
752 pTable
->KeyTable
[i
].wKeyCtl
|= (byKeyDecMode
<< 4);
753 pTable
->KeyTable
[i
].wKeyCtl
|= 0x0040; // use group key for group address
754 uKeyIdx
= (dwKeyIndex
& 0x000000FF);
756 pTable
->KeyTable
[i
].wKeyCtl
|= 0x8000; // enable on-fly
758 pKey
->bKeyValid
= true;
759 pKey
->uKeyLength
= uKeyLength
;
760 pKey
->dwKeyIndex
= dwKeyIndex
;
761 pKey
->byCipherSuite
= byKeyDecMode
;
762 memcpy(pKey
->abyKey
, pbyKey
, uKeyLength
);
763 if (byKeyDecMode
== KEY_CTL_WEP
) {
764 if (uKeyLength
== WLAN_WEP40_KEYLEN
)
765 pKey
->abyKey
[15] &= 0x7F;
766 if (uKeyLength
== WLAN_WEP104_KEYLEN
)
767 pKey
->abyKey
[15] |= 0x80;
769 MACvSetKeyEntry(dwIoBase
, pTable
->KeyTable
[i
].wKeyCtl
, i
, uKeyIdx
, pTable
->KeyTable
[i
].abyBSSID
, (unsigned long *)pKey
->abyKey
, byLocalID
);
771 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
773 memset(&(pKey
->KeyRSC
), 0, sizeof(QWORD
));
775 memcpy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
777 pKey
->dwTSC47_16
= 0;
780 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybSetKey(R): \n");
781 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->bKeyValid: %d\n ", pKey
->bKeyValid
);
782 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->uKeyLength: %d\n ", (int)pKey
->uKeyLength
);
783 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->abyKey: ");
784 for (ii
= 0; ii
< pKey
->uKeyLength
; ii
++) {
785 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pKey
->abyKey
[ii
]);
787 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
789 //DBG_PRN_GRP12(("pKey->dwTSC47_16: %lX\n ", pKey->dwTSC47_16));
790 //DBG_PRN_GRP12(("pKey->wTSC15_0: %X\n ", pKey->wTSC15_0));
791 //DBG_PRN_GRP12(("pKey->dwKeyIndex: %lX\n ", pKey->dwKeyIndex));
793 } // (pTable->KeyTable[i].bInUse == true)