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
167 BOOL
KeybGetKey(PSKeyManagement pTable
, PBYTE pbyBSSID
, DWORD dwKeyIndex
,
172 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybGetKey() \n");
175 for (i
=0;i
<MAX_KEY_TABLE
;i
++) {
176 if ((pTable
->KeyTable
[i
].bInUse
== TRUE
) &&
177 !compare_ether_addr(pTable
->KeyTable
[i
].abyBSSID
, pbyBSSID
)) {
178 if (dwKeyIndex
== 0xFFFFFFFF) {
179 if (pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
== TRUE
) {
180 *pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
186 } else if (dwKeyIndex
< MAX_GROUP_KEY
) {
187 if (pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
].bKeyValid
== TRUE
) {
188 *pKey
= &(pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
]);
205 * Description: Set Key to table
209 * pTable - Pointer to Key table
210 * pbyBSSID - BSSID of Key
211 * dwKeyIndex - Key index (reference to NDIS DDK)
212 * uKeyLength - Key length
214 * pbyKey - Pointer to key
218 * Return Value: TRUE if success otherwise FALSE
222 void *pDeviceHandler
,
223 PSKeyManagement pTable
,
226 unsigned long uKeyLength
,
232 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
236 unsigned int uKeyIdx
;
238 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enter KeybSetKey: %lX\n", dwKeyIndex
);
240 j
= (MAX_KEY_TABLE
-1);
241 for (i
=0;i
<(MAX_KEY_TABLE
-1);i
++) {
242 if ((pTable
->KeyTable
[i
].bInUse
== FALSE
) &&
243 (j
== (MAX_KEY_TABLE
-1))) {
247 if ((pTable
->KeyTable
[i
].bInUse
== TRUE
) &&
248 !compare_ether_addr(pTable
->KeyTable
[i
].abyBSSID
, pbyBSSID
)) {
249 // found table already exist
250 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
252 pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
253 pTable
->KeyTable
[i
].wKeyCtl
&= 0xFFF0; // clear pairwise key control filed
254 pTable
->KeyTable
[i
].wKeyCtl
|= byKeyDecMode
;
255 uKeyIdx
= 4; // use HW key entry 4 for pairwise key
258 if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
)
260 pKey
= &(pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
& 0x000000FF]);
261 if ((dwKeyIndex
& TRANSMIT_KEY
) != 0) {
262 // Group transmit key
263 pTable
->KeyTable
[i
].dwGTKeyIndex
= dwKeyIndex
;
264 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Group transmit key(R)[%lX]: %d\n", pTable
->KeyTable
[i
].dwGTKeyIndex
, i
);
266 pTable
->KeyTable
[i
].wKeyCtl
&= 0xFF0F; // clear group key control filed
267 pTable
->KeyTable
[i
].wKeyCtl
|= (byKeyDecMode
<< 4);
268 pTable
->KeyTable
[i
].wKeyCtl
|= 0x0040; // use group key for group address
269 uKeyIdx
= (dwKeyIndex
& 0x000000FF);
271 pTable
->KeyTable
[i
].wKeyCtl
|= 0x8000; // enable on-fly
273 pKey
->bKeyValid
= TRUE
;
274 pKey
->uKeyLength
= uKeyLength
;
275 pKey
->dwKeyIndex
= dwKeyIndex
;
276 pKey
->byCipherSuite
= byKeyDecMode
;
277 memcpy(pKey
->abyKey
, pbyKey
, uKeyLength
);
278 if (byKeyDecMode
== KEY_CTL_WEP
) {
279 if (uKeyLength
== WLAN_WEP40_KEYLEN
)
280 pKey
->abyKey
[15] &= 0x7F;
281 if (uKeyLength
== WLAN_WEP104_KEYLEN
)
282 pKey
->abyKey
[15] |= 0x80;
284 MACvSetKeyEntry(pDevice
, pTable
->KeyTable
[i
].wKeyCtl
, i
, uKeyIdx
, pbyBSSID
, (PDWORD
)pKey
->abyKey
);
286 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
288 memset(&(pKey
->KeyRSC
), 0, sizeof(QWORD
));
291 memcpy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
293 pKey
->dwTSC47_16
= 0;
296 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybSetKey(R): \n");
297 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->bKeyValid: %d\n ", pKey
->bKeyValid
);
298 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", pKey->uKeyLength);
299 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->abyKey: ");
300 for (ii
= 0; ii
< pKey
->uKeyLength
; ii
++) {
301 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pKey
->abyKey
[ii
]);
303 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
305 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwTSC47_16: %lx\n ", pKey
->dwTSC47_16
);
306 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->wTSC15_0: %x\n ", pKey
->wTSC15_0
);
307 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwKeyIndex: %lx\n ", pKey
->dwKeyIndex
);
312 if (j
< (MAX_KEY_TABLE
-1)) {
313 memcpy(pTable
->KeyTable
[j
].abyBSSID
, pbyBSSID
, ETH_ALEN
);
314 pTable
->KeyTable
[j
].bInUse
= TRUE
;
315 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
317 pKey
= &(pTable
->KeyTable
[j
].PairwiseKey
);
318 pTable
->KeyTable
[j
].wKeyCtl
&= 0xFFF0; // clear pairwise key control filed
319 pTable
->KeyTable
[j
].wKeyCtl
|= byKeyDecMode
;
320 uKeyIdx
= 4; // use HW key entry 4 for pairwise key
323 if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
)
325 pKey
= &(pTable
->KeyTable
[j
].GroupKey
[dwKeyIndex
& 0x000000FF]);
326 if ((dwKeyIndex
& TRANSMIT_KEY
) != 0) {
327 // Group transmit key
328 pTable
->KeyTable
[j
].dwGTKeyIndex
= dwKeyIndex
;
329 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Group transmit key(N)[%lX]: %d\n", pTable
->KeyTable
[j
].dwGTKeyIndex
, j
);
331 pTable
->KeyTable
[j
].wKeyCtl
&= 0xFF0F; // clear group key control filed
332 pTable
->KeyTable
[j
].wKeyCtl
|= (byKeyDecMode
<< 4);
333 pTable
->KeyTable
[j
].wKeyCtl
|= 0x0040; // use group key for group address
334 uKeyIdx
= (dwKeyIndex
& 0x000000FF);
336 pTable
->KeyTable
[j
].wKeyCtl
|= 0x8000; // enable on-fly
338 pKey
->bKeyValid
= TRUE
;
339 pKey
->uKeyLength
= uKeyLength
;
340 pKey
->dwKeyIndex
= dwKeyIndex
;
341 pKey
->byCipherSuite
= byKeyDecMode
;
342 memcpy(pKey
->abyKey
, pbyKey
, uKeyLength
);
343 if (byKeyDecMode
== KEY_CTL_WEP
) {
344 if (uKeyLength
== WLAN_WEP40_KEYLEN
)
345 pKey
->abyKey
[15] &= 0x7F;
346 if (uKeyLength
== WLAN_WEP104_KEYLEN
)
347 pKey
->abyKey
[15] |= 0x80;
349 MACvSetKeyEntry(pDevice
, pTable
->KeyTable
[j
].wKeyCtl
, j
, uKeyIdx
, pbyBSSID
, (PDWORD
)pKey
->abyKey
);
351 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
353 memset(&(pKey
->KeyRSC
), 0, sizeof(QWORD
));
356 memcpy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
358 pKey
->dwTSC47_16
= 0;
361 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybSetKey(N): \n");
362 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->bKeyValid: %d\n ", pKey
->bKeyValid
);
363 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->uKeyLength: %d\n ", (int)pKey
->uKeyLength
);
364 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->abyKey: ");
365 for (ii
= 0; ii
< pKey
->uKeyLength
; ii
++) {
366 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pKey
->abyKey
[ii
]);
368 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
370 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwTSC47_16: %lx\n ", pKey
->dwTSC47_16
);
371 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->wTSC15_0: %x\n ", pKey
->wTSC15_0
);
372 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwKeyIndex: %lx\n ", pKey
->dwKeyIndex
);
381 * Description: Remove Key from table
385 * pTable - Pointer to Key table
386 * pbyBSSID - BSSID of Key
387 * dwKeyIndex - Key Index (reference to NDIS DDK)
391 * Return Value: TRUE if success otherwise FALSE
395 void *pDeviceHandler
,
396 PSKeyManagement pTable
,
401 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
403 BOOL bReturnValue
= FALSE
;
405 if (is_broadcast_ether_addr(pbyBSSID
)) {
407 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
408 for (i
=0;i
<MAX_KEY_TABLE
;i
++) {
409 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= FALSE
;
413 else if ((dwKeyIndex
& 0x000000FF) < MAX_GROUP_KEY
) {
414 for (i
=0;i
<MAX_KEY_TABLE
;i
++) {
415 pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
& 0x000000FF].bKeyValid
= FALSE
;
416 if ((dwKeyIndex
& 0x7FFFFFFF) == (pTable
->KeyTable
[i
].dwGTKeyIndex
& 0x7FFFFFFF)) {
417 // remove Group transmit key
418 pTable
->KeyTable
[i
].dwGTKeyIndex
= 0;
424 bReturnValue
= FALSE
;
428 for (i
=0;i
<MAX_KEY_TABLE
;i
++) {
429 if ( (pTable
->KeyTable
[i
].bInUse
== TRUE
) &&
430 !compare_ether_addr(pTable
->KeyTable
[i
].abyBSSID
, pbyBSSID
)) {
432 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
433 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= FALSE
;
437 else if ((dwKeyIndex
& 0x000000FF) < MAX_GROUP_KEY
) {
438 pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
& 0x000000FF].bKeyValid
= FALSE
;
439 if ((dwKeyIndex
& 0x7FFFFFFF) == (pTable
->KeyTable
[i
].dwGTKeyIndex
& 0x7FFFFFFF)) {
440 // remove Group transmit key
441 pTable
->KeyTable
[i
].dwGTKeyIndex
= 0;
447 bReturnValue
= FALSE
;
450 } //pTable->KeyTable[i].bInUse == TRUE
455 s_vCheckKeyTableValid(pDevice
,pTable
);
463 * Description: Remove Key from table
467 * pTable - Pointer to Key table
468 * pbyBSSID - BSSID of Key
472 * Return Value: TRUE if success otherwise FALSE
475 BOOL
KeybRemoveAllKey(
476 void *pDeviceHandler
,
477 PSKeyManagement pTable
,
481 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
484 for (i
=0;i
<MAX_KEY_TABLE
;i
++) {
485 if ((pTable
->KeyTable
[i
].bInUse
== TRUE
) &&
486 !compare_ether_addr(pTable
->KeyTable
[i
].abyBSSID
, pbyBSSID
)) {
487 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= FALSE
;
488 for (u
= 0; u
< MAX_GROUP_KEY
; u
++)
489 pTable
->KeyTable
[i
].GroupKey
[u
].bKeyValid
= FALSE
;
491 pTable
->KeyTable
[i
].dwGTKeyIndex
= 0;
492 s_vCheckKeyTableValid(pDevice
, pTable
);
500 * Description: Remove WEP Key from table
504 * pTable - Pointer to Key table
508 * Return Value: TRUE if success otherwise FALSE
511 void KeyvRemoveWEPKey(
512 void *pDeviceHandler
,
513 PSKeyManagement pTable
,
517 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
519 if ((dwKeyIndex
& 0x000000FF) < MAX_GROUP_KEY
) {
520 if (pTable
->KeyTable
[MAX_KEY_TABLE
-1].bInUse
== TRUE
) {
521 if (pTable
->KeyTable
[MAX_KEY_TABLE
-1].GroupKey
[dwKeyIndex
& 0x000000FF].byCipherSuite
== KEY_CTL_WEP
) {
522 pTable
->KeyTable
[MAX_KEY_TABLE
-1].GroupKey
[dwKeyIndex
& 0x000000FF].bKeyValid
= FALSE
;
523 if ((dwKeyIndex
& 0x7FFFFFFF) == (pTable
->KeyTable
[MAX_KEY_TABLE
-1].dwGTKeyIndex
& 0x7FFFFFFF)) {
524 // remove Group transmit key
525 pTable
->KeyTable
[MAX_KEY_TABLE
-1].dwGTKeyIndex
= 0;
529 s_vCheckKeyTableValid(pDevice
, pTable
);
534 void KeyvRemoveAllWEPKey(void *pDeviceHandler
, PSKeyManagement pTable
)
536 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
539 for (i
= 0; i
< MAX_GROUP_KEY
; i
++)
540 KeyvRemoveWEPKey(pDevice
, pTable
, i
);
544 * Description: Get Transmit Key from table
548 * pTable - Pointer to Key table
549 * pbyBSSID - BSSID of Key
553 * Return Value: TRUE if found otherwise FALSE
556 BOOL
KeybGetTransmitKey(PSKeyManagement pTable
, PBYTE pbyBSSID
, DWORD dwKeyType
,
562 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
563 if ((pTable
->KeyTable
[i
].bInUse
== TRUE
) &&
564 !compare_ether_addr(pTable
->KeyTable
[i
].abyBSSID
, pbyBSSID
)) {
566 if (dwKeyType
== PAIRWISE_KEY
) {
568 if (pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
== TRUE
) {
569 *pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
571 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybGetTransmitKey:");
572 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PAIRWISE_KEY: KeyTable.abyBSSID: ");
573 for (ii
= 0; ii
< 6; ii
++) {
574 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%x ", pTable
->KeyTable
[i
].abyBSSID
[ii
]);
576 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
582 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PairwiseKey.bKeyValid == FALSE\n");
585 } // End of Type == PAIRWISE
587 if (pTable
->KeyTable
[i
].dwGTKeyIndex
== 0) {
588 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ERROR: dwGTKeyIndex == 0 !!!\n");
591 if (pTable
->KeyTable
[i
].GroupKey
[(pTable
->KeyTable
[i
].dwGTKeyIndex
&0x000000FF)].bKeyValid
== TRUE
) {
592 *pKey
= &(pTable
->KeyTable
[i
].GroupKey
[(pTable
->KeyTable
[i
].dwGTKeyIndex
&0x000000FF)]);
594 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybGetTransmitKey:");
595 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GROUP_KEY: KeyTable.abyBSSID\n");
596 for (ii
= 0; ii
< 6; ii
++) {
597 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%x ", pTable
->KeyTable
[i
].abyBSSID
[ii
]);
599 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
600 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dwGTKeyIndex: %lX\n", pTable
->KeyTable
[i
].dwGTKeyIndex
);
605 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GroupKey.bKeyValid == FALSE\n");
608 } // End of Type = GROUP
611 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ERROR: NO Match BSSID !!! ");
612 for (ii
= 0; ii
< 6; ii
++) {
613 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", *(pbyBSSID
+ii
));
615 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
621 * Description: Check Pairewise Key
625 * pTable - Pointer to Key table
629 * Return Value: TRUE if found otherwise FALSE
632 BOOL
KeybCheckPairewiseKey(PSKeyManagement pTable
, PSKeyItem
*pKey
)
637 for (i
=0;i
<MAX_KEY_TABLE
;i
++) {
638 if ((pTable
->KeyTable
[i
].bInUse
== TRUE
) &&
639 (pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
== TRUE
)) {
640 *pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
648 * Description: Set Key to table
652 * pTable - Pointer to Key table
653 * dwKeyIndex - Key index (reference to NDIS DDK)
654 * uKeyLength - Key length
656 * pbyKey - Pointer to key
660 * Return Value: TRUE if success otherwise FALSE
663 BOOL
KeybSetDefaultKey(
664 void *pDeviceHandler
,
665 PSKeyManagement pTable
,
667 unsigned long uKeyLength
,
673 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
676 unsigned int uKeyIdx
;
678 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enter KeybSetDefaultKey: %1x, %d\n",
679 (int) dwKeyIndex
, (int) uKeyLength
);
681 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) { // Pairwise key
683 } else if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
) {
687 pTable
->KeyTable
[MAX_KEY_TABLE
-1].bInUse
= TRUE
;
688 for (ii
= 0; ii
< ETH_ALEN
; ii
++)
689 pTable
->KeyTable
[MAX_KEY_TABLE
-1].abyBSSID
[ii
] = 0xFF;
692 pKey
= &(pTable
->KeyTable
[MAX_KEY_TABLE
-1].GroupKey
[dwKeyIndex
& 0x000000FF]);
693 if ((dwKeyIndex
& TRANSMIT_KEY
) != 0) {
694 // Group transmit key
695 pTable
->KeyTable
[MAX_KEY_TABLE
-1].dwGTKeyIndex
= dwKeyIndex
;
696 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);
699 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
&= 0x7F00; // clear all key control filed
700 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= (byKeyDecMode
<< 4);
701 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= (byKeyDecMode
);
702 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= 0x0044; // use group key for all address
703 uKeyIdx
= (dwKeyIndex
& 0x000000FF);
705 if ((uKeyLength
== WLAN_WEP232_KEYLEN
) &&
706 (byKeyDecMode
== KEY_CTL_WEP
)) {
707 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= 0x4000; // disable on-fly disable address match
708 pTable
->KeyTable
[MAX_KEY_TABLE
-1].bSoftWEP
= TRUE
;
710 if (pTable
->KeyTable
[MAX_KEY_TABLE
-1].bSoftWEP
== FALSE
)
711 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= 0xC000; // enable on-fly disable address match
714 pKey
->bKeyValid
= TRUE
;
715 pKey
->uKeyLength
= uKeyLength
;
716 pKey
->dwKeyIndex
= dwKeyIndex
;
717 pKey
->byCipherSuite
= byKeyDecMode
;
718 memcpy(pKey
->abyKey
, pbyKey
, uKeyLength
);
719 if (byKeyDecMode
== KEY_CTL_WEP
) {
720 if (uKeyLength
== WLAN_WEP40_KEYLEN
)
721 pKey
->abyKey
[15] &= 0x7F;
722 if (uKeyLength
== WLAN_WEP104_KEYLEN
)
723 pKey
->abyKey
[15] |= 0x80;
726 MACvSetKeyEntry(pDevice
, pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
, MAX_KEY_TABLE
-1, uKeyIdx
, pTable
->KeyTable
[MAX_KEY_TABLE
-1].abyBSSID
, (PDWORD
) pKey
->abyKey
);
728 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
730 memset(&(pKey
->KeyRSC
), 0, sizeof(QWORD
));
732 memcpy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
734 pKey
->dwTSC47_16
= 0;
738 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybSetKey(R): \n");
739 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->bKeyValid: %d\n", pKey
->bKeyValid
);
740 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->uKeyLength: %d\n", (int)pKey
->uKeyLength
);
741 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->abyKey: \n");
742 for (ii
= 0; ii
< pKey
->uKeyLength
; ii
++) {
743 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%x", pKey
->abyKey
[ii
]);
745 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
747 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwTSC47_16: %lx\n", pKey
->dwTSC47_16
);
748 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->wTSC15_0: %x\n", pKey
->wTSC15_0
);
749 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwKeyIndex: %lx\n", pKey
->dwKeyIndex
);
756 * Description: Set Key to table
760 * pTable - Pointer to Key table
761 * dwKeyIndex - Key index (reference to NDIS DDK)
762 * uKeyLength - Key length
764 * pbyKey - Pointer to key
768 * Return Value: TRUE if success otherwise FALSE
771 BOOL
KeybSetAllGroupKey(
772 void *pDeviceHandler
,
773 PSKeyManagement pTable
,
775 unsigned long uKeyLength
,
781 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
785 unsigned int uKeyIdx
;
787 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enter KeybSetAllGroupKey: %lX\n", dwKeyIndex
);
790 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) { // Pairwise key
792 } else if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
) {
796 for (i
=0; i
< MAX_KEY_TABLE
-1; i
++) {
797 if (pTable
->KeyTable
[i
].bInUse
== TRUE
) {
798 // found table already exist
800 pKey
= &(pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
& 0x000000FF]);
801 if ((dwKeyIndex
& TRANSMIT_KEY
) != 0) {
802 // Group transmit key
803 pTable
->KeyTable
[i
].dwGTKeyIndex
= dwKeyIndex
;
804 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Group transmit key(R)[%lX]: %d\n", pTable
->KeyTable
[i
].dwGTKeyIndex
, i
);
807 pTable
->KeyTable
[i
].wKeyCtl
&= 0xFF0F; // clear group key control filed
808 pTable
->KeyTable
[i
].wKeyCtl
|= (byKeyDecMode
<< 4);
809 pTable
->KeyTable
[i
].wKeyCtl
|= 0x0040; // use group key for group address
810 uKeyIdx
= (dwKeyIndex
& 0x000000FF);
812 pTable
->KeyTable
[i
].wKeyCtl
|= 0x8000; // enable on-fly
814 pKey
->bKeyValid
= TRUE
;
815 pKey
->uKeyLength
= uKeyLength
;
816 pKey
->dwKeyIndex
= dwKeyIndex
;
817 pKey
->byCipherSuite
= byKeyDecMode
;
818 memcpy(pKey
->abyKey
, pbyKey
, uKeyLength
);
819 if (byKeyDecMode
== KEY_CTL_WEP
) {
820 if (uKeyLength
== WLAN_WEP40_KEYLEN
)
821 pKey
->abyKey
[15] &= 0x7F;
822 if (uKeyLength
== WLAN_WEP104_KEYLEN
)
823 pKey
->abyKey
[15] |= 0x80;
826 MACvSetKeyEntry(pDevice
, pTable
->KeyTable
[i
].wKeyCtl
, i
, uKeyIdx
, pTable
->KeyTable
[i
].abyBSSID
, (PDWORD
) pKey
->abyKey
);
828 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
830 memset(&(pKey
->KeyRSC
), 0, sizeof(QWORD
));
833 memcpy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
835 pKey
->dwTSC47_16
= 0;
838 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybSetKey(R): \n");
839 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->bKeyValid: %d\n ", pKey
->bKeyValid
);
840 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->uKeyLength: %d\n ", (int)pKey
->uKeyLength
);
841 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->abyKey: ");
842 for (ii
= 0; ii
< pKey
->uKeyLength
; ii
++) {
843 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pKey
->abyKey
[ii
]);
845 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
847 //DBG_PRN_GRP12(("pKey->dwTSC47_16: %lX\n ", pKey->dwTSC47_16));
848 //DBG_PRN_GRP12(("pKey->wTSC15_0: %X\n ", pKey->wTSC15_0));
849 //DBG_PRN_GRP12(("pKey->dwKeyIndex: %lX\n ", pKey->dwKeyIndex));
851 } // (pTable->KeyTable[i].bInUse == TRUE)