jbd: Fix a race between checkpointing code and journal_get_write_access()
[linux/fpc-iii.git] / drivers / staging / vt6655 / key.c
blob168ebd3be944af5b3938eeb3ab52bd9e865abfbe
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
20 * File: key.c
22 * Purpose: Implement functions for 802.11i Key management
24 * Author: Jerry Chen
26 * Date: May 29, 2003
28 * Functions:
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
35 * Revision History:
40 #if !defined(__TMACRO_H__)
41 #include "tmacro.h"
42 #endif
43 #if !defined(__TBIT_H__)
44 #include "tbit.h"
45 #endif
46 #if !defined(__KEY_H__)
47 #include "key.h"
48 #endif
49 #if !defined(__UMEM_H__)
50 #include "umem.h"
51 #endif
52 #if !defined(__MAC_H__)
53 #include "mac.h"
54 #endif
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 --------------------------*/
75 static VOID
76 s_vCheckKeyTableValid (PSKeyManagement pTable, DWORD_PTR dwIoBase)
78 int i;
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)
87 ) {
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
103 * Parameters:
104 * In:
105 * pTable - Pointer to Key table
106 * Out:
107 * none
109 * Return Value: none
112 VOID KeyvInitTable (PSKeyManagement pTable, DWORD_PTR dwIoBase)
114 int i;
115 int jj;
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
136 * Parameters:
137 * In:
138 * pTable - Pointer to Key table
139 * pbyBSSID - BSSID of Key
140 * dwKeyIndex - Key Index (0xFFFFFFFF means pairwise key)
141 * Out:
142 * pKey - Key return
144 * Return Value: TRUE if found otherwise FALSE
147 BOOL KeybGetKey (
148 IN PSKeyManagement pTable,
149 IN PBYTE pbyBSSID,
150 IN DWORD dwKeyIndex,
151 OUT PSKeyItem *pKey
154 int i;
156 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetKey() \n");
158 *pKey = NULL;
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);
165 return (TRUE);
167 else {
168 return (FALSE);
170 } else if (dwKeyIndex < MAX_GROUP_KEY) {
171 if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid == TRUE) {
172 *pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex]);
173 return (TRUE);
175 else {
176 return (FALSE);
179 else {
180 return (FALSE);
184 return (FALSE);
189 * Description: Set Key to table
191 * Parameters:
192 * In:
193 * pTable - Pointer to Key table
194 * pbyBSSID - BSSID of Key
195 * dwKeyIndex - Key index (reference to NDIS DDK)
196 * uKeyLength - Key length
197 * KeyRSC - Key RSC
198 * pbyKey - Pointer to key
199 * Out:
200 * none
202 * Return Value: TRUE if success otherwise FALSE
205 BOOL KeybSetKey (
206 PSKeyManagement pTable,
207 PBYTE pbyBSSID,
208 DWORD dwKeyIndex,
209 ULONG uKeyLength,
210 PQWORD pKeyRSC,
211 PBYTE pbyKey,
212 BYTE byKeyDecMode,
213 DWORD_PTR dwIoBase,
214 BYTE byLocalID
217 int i,j;
218 UINT ii;
219 PSKeyItem pKey;
220 UINT uKeyIdx;
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))) {
228 // found empty table
229 j = i;
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) {
235 // Pairwise key
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
240 } else {
241 // Group key
242 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
243 return (FALSE);
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) {
271 // RSC set by NIC
272 ZERO_MEMORY(&(pKey->KeyRSC), sizeof(QWORD));
274 else {
275 MEMvCopy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
277 pKey->dwTSC47_16 = 0;
278 pKey->wTSC15_0 = 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);
293 return (TRUE);
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) {
300 // Pairwise key
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
305 } else {
306 // Group key
307 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
308 return (FALSE);
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) {
336 // RSC set by NIC
337 ZERO_MEMORY(&(pKey->KeyRSC), sizeof(QWORD));
339 else {
340 MEMvCopy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
342 pKey->dwTSC47_16 = 0;
343 pKey->wTSC15_0 = 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);
358 return (TRUE);
360 return (FALSE);
365 * Description: Remove Key from table
367 * Parameters:
368 * In:
369 * pTable - Pointer to Key table
370 * pbyBSSID - BSSID of Key
371 * dwKeyIndex - Key Index (reference to NDIS DDK)
372 * Out:
373 * none
375 * Return Value: TRUE if success otherwise FALSE
378 BOOL KeybRemoveKey (
379 PSKeyManagement pTable,
380 PBYTE pbyBSSID,
381 DWORD dwKeyIndex,
382 DWORD_PTR dwIoBase
385 int i;
387 if (IS_BROADCAST_ADDRESS(pbyBSSID)) {
388 // dealte all key
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);
394 return TRUE;
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);
405 return TRUE;
407 else {
408 return FALSE;
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);
418 return (TRUE);
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);
427 return (TRUE);
429 else {
430 return (FALSE);
434 return (FALSE);
439 * Description: Remove Key from table
441 * Parameters:
442 * In:
443 * pTable - Pointer to Key table
444 * pbyBSSID - BSSID of Key
445 * Out:
446 * none
448 * Return Value: TRUE if success otherwise FALSE
451 BOOL KeybRemoveAllKey (
452 PSKeyManagement pTable,
453 PBYTE pbyBSSID,
454 DWORD_PTR dwIoBase
457 int i,u;
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);
468 return (TRUE);
471 return (FALSE);
475 * Description: Remove WEP Key from table
477 * Parameters:
478 * In:
479 * pTable - Pointer to Key table
480 * Out:
481 * none
483 * Return Value: TRUE if success otherwise FALSE
486 VOID KeyvRemoveWEPKey (
487 PSKeyManagement pTable,
488 DWORD dwKeyIndex,
489 DWORD_PTR dwIoBase
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);
505 return;
508 VOID KeyvRemoveAllWEPKey (
509 PSKeyManagement pTable,
510 DWORD_PTR dwIoBase
513 int i;
515 for(i=0;i<MAX_GROUP_KEY;i++) {
516 KeyvRemoveWEPKey(pTable, i, dwIoBase);
521 * Description: Get Transmit Key from table
523 * Parameters:
524 * In:
525 * pTable - Pointer to Key table
526 * pbyBSSID - BSSID of Key
527 * Out:
528 * pKey - Key return
530 * Return Value: TRUE if found otherwise FALSE
533 BOOL KeybGetTransmitKey (
534 IN PSKeyManagement pTable,
535 IN PBYTE pbyBSSID,
536 IN DWORD dwKeyType,
537 OUT PSKeyItem *pKey
540 int i, ii;
542 *pKey = NULL;
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");
560 return (TRUE);
562 else {
563 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PairwiseKey.bKeyValid == FALSE\n");
564 return (FALSE);
566 } // End of Type == PAIRWISE
567 else {
568 if (pTable->KeyTable[i].dwGTKeyIndex == 0) {
569 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: dwGTKeyIndex == 0 !!!\n");
570 return FALSE;
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);
583 return (TRUE);
585 else {
586 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GroupKey.bKeyValid == FALSE\n");
587 return (FALSE);
589 } // End of Type = GROUP
590 } // BSSID match
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");
597 return (FALSE);
602 * Description: Check Pairewise Key
604 * Parameters:
605 * In:
606 * pTable - Pointer to Key table
607 * Out:
608 * none
610 * Return Value: TRUE if found otherwise FALSE
613 BOOL KeybCheckPairewiseKey (
614 IN PSKeyManagement pTable,
615 OUT PSKeyItem *pKey
618 int i;
620 *pKey = NULL;
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);
625 return (TRUE);
628 return (FALSE);
632 * Description: Set Key to table
634 * Parameters:
635 * In:
636 * pTable - Pointer to Key table
637 * dwKeyIndex - Key index (reference to NDIS DDK)
638 * uKeyLength - Key length
639 * KeyRSC - Key RSC
640 * pbyKey - Pointer to key
641 * Out:
642 * none
644 * Return Value: TRUE if success otherwise FALSE
647 BOOL KeybSetDefaultKey (
648 PSKeyManagement pTable,
649 DWORD dwKeyIndex,
650 ULONG uKeyLength,
651 PQWORD pKeyRSC,
652 PBYTE pbyKey,
653 BYTE byKeyDecMode,
654 DWORD_PTR dwIoBase,
655 BYTE byLocalID
658 UINT ii;
659 PSKeyItem pKey;
660 UINT uKeyIdx;
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
666 return (FALSE);
667 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
668 return (FALSE);
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;
675 // Group key
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;
693 } else {
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) {
712 // RSC set by NIC
713 ZERO_MEMORY(&(pKey->KeyRSC), sizeof(QWORD));
714 } else {
715 MEMvCopy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
717 pKey->dwTSC47_16 = 0;
718 pKey->wTSC15_0 = 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);
734 return (TRUE);
739 * Description: Set Key to table
741 * Parameters:
742 * In:
743 * pTable - Pointer to Key table
744 * dwKeyIndex - Key index (reference to NDIS DDK)
745 * uKeyLength - Key length
746 * KeyRSC - Key RSC
747 * pbyKey - Pointer to key
748 * Out:
749 * none
751 * Return Value: TRUE if success otherwise FALSE
754 BOOL KeybSetAllGroupKey (
755 PSKeyManagement pTable,
756 DWORD dwKeyIndex,
757 ULONG uKeyLength,
758 PQWORD pKeyRSC,
759 PBYTE pbyKey,
760 BYTE byKeyDecMode,
761 DWORD_PTR dwIoBase,
762 BYTE byLocalID
765 int i;
766 UINT ii;
767 PSKeyItem pKey;
768 UINT uKeyIdx;
770 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetAllGroupKey: %lX\n", dwKeyIndex);
773 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key
774 return (FALSE);
775 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
776 return (FALSE);
779 for (i=0; i < MAX_KEY_TABLE-1; i++) {
780 if (pTable->KeyTable[i].bInUse == TRUE) {
781 // found table already exist
782 // Group key
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) {
811 // RSC set by NIC
812 ZERO_MEMORY(&(pKey->KeyRSC), sizeof(QWORD));
814 else {
815 MEMvCopy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
817 pKey->dwTSC47_16 = 0;
818 pKey->wTSC15_0 = 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)
835 return (TRUE);