Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[linux/fpc-iii.git] / drivers / staging / vt6655 / key.c
blobeab3b41f9e3c77b1c7d41fa18a29c56d8a17d901
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:
39 #include "tmacro.h"
40 #include "key.h"
41 #include "mac.h"
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 --------------------------*/
61 static void
62 s_vCheckKeyTableValid(PSKeyManagement pTable, unsigned long dwIoBase)
64 int i;
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
86 * Parameters:
87 * In:
88 * pTable - Pointer to Key table
89 * Out:
90 * none
92 * Return Value: none
95 void KeyvInitTable(PSKeyManagement pTable, unsigned long dwIoBase)
97 int i;
98 int jj;
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
118 * Parameters:
119 * In:
120 * pTable - Pointer to Key table
121 * pbyBSSID - BSSID of Key
122 * dwKeyIndex - Key Index (0xFFFFFFFF means pairwise key)
123 * Out:
124 * pKey - Key return
126 * Return Value: true if found otherwise false
129 bool KeybGetKey(
130 PSKeyManagement pTable,
131 unsigned char *pbyBSSID,
132 unsigned long dwKeyIndex,
133 PSKeyItem *pKey
136 int i;
138 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybGetKey() \n");
140 *pKey = NULL;
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);
147 return true;
148 } else {
149 return false;
151 } else if (dwKeyIndex < MAX_GROUP_KEY) {
152 if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid) {
153 *pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex]);
154 return true;
155 } else {
156 return false;
158 } else {
159 return false;
163 return false;
167 * Description: Set Key to table
169 * Parameters:
170 * In:
171 * pTable - Pointer to Key table
172 * pbyBSSID - BSSID of Key
173 * dwKeyIndex - Key index (reference to NDIS DDK)
174 * uKeyLength - Key length
175 * KeyRSC - Key RSC
176 * pbyKey - Pointer to key
177 * Out:
178 * none
180 * Return Value: true if success otherwise false
183 bool KeybSetKey(
184 PSKeyManagement pTable,
185 unsigned char *pbyBSSID,
186 unsigned long dwKeyIndex,
187 unsigned long uKeyLength,
188 PQWORD pKeyRSC,
189 unsigned char *pbyKey,
190 unsigned char byKeyDecMode,
191 unsigned long dwIoBase,
192 unsigned char byLocalID
195 int i, j;
196 unsigned int ii;
197 PSKeyItem pKey;
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))) {
205 // found empty table
206 j = i;
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) {
212 // Pairwise key
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
217 } else {
218 // Group key
219 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
220 return false;
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) {
248 // RSC set by NIC
249 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
250 } else {
251 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
253 pKey->dwTSC47_16 = 0;
254 pKey->wTSC15_0 = 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);
269 return true;
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) {
276 // Pairwise key
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
281 } else {
282 // Group key
283 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
284 return false;
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) {
312 // RSC set by NIC
313 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
314 } else {
315 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
317 pKey->dwTSC47_16 = 0;
318 pKey->wTSC15_0 = 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);
333 return true;
335 return false;
339 * Description: Remove Key from table
341 * Parameters:
342 * In:
343 * pTable - Pointer to Key table
344 * pbyBSSID - BSSID of Key
345 * dwKeyIndex - Key Index (reference to NDIS DDK)
346 * Out:
347 * none
349 * Return Value: true if success otherwise false
352 bool KeybRemoveKey(
353 PSKeyManagement pTable,
354 unsigned char *pbyBSSID,
355 unsigned long dwKeyIndex,
356 unsigned long dwIoBase
359 int i;
361 if (is_broadcast_ether_addr(pbyBSSID)) {
362 // delete all keys
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);
368 return true;
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);
378 return true;
379 } else {
380 return false;
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);
390 return true;
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);
398 return true;
399 } else {
400 return false;
404 return false;
408 * Description: Remove Key from table
410 * Parameters:
411 * In:
412 * pTable - Pointer to Key table
413 * pbyBSSID - BSSID of Key
414 * Out:
415 * none
417 * Return Value: true if success otherwise false
420 bool KeybRemoveAllKey(
421 PSKeyManagement pTable,
422 unsigned char *pbyBSSID,
423 unsigned long dwIoBase
426 int i, u;
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);
437 return true;
440 return false;
444 * Description: Remove WEP Key from table
446 * Parameters:
447 * In:
448 * pTable - Pointer to Key table
449 * Out:
450 * none
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);
473 return;
476 void KeyvRemoveAllWEPKey(
477 PSKeyManagement pTable,
478 unsigned long dwIoBase
481 int i;
483 for (i = 0; i < MAX_GROUP_KEY; i++) {
484 KeyvRemoveWEPKey(pTable, i, dwIoBase);
489 * Description: Get Transmit Key from table
491 * Parameters:
492 * In:
493 * pTable - Pointer to Key table
494 * pbyBSSID - BSSID of Key
495 * Out:
496 * pKey - Key return
498 * Return Value: true if found otherwise false
501 bool KeybGetTransmitKey(
502 PSKeyManagement pTable,
503 unsigned char *pbyBSSID,
504 unsigned long dwKeyType,
505 PSKeyItem *pKey
508 int i, ii;
510 *pKey = NULL;
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");
525 return true;
526 } else {
527 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PairwiseKey.bKeyValid == false\n");
528 return false;
530 } // End of Type == PAIRWISE
531 else {
532 if (pTable->KeyTable[i].dwGTKeyIndex == 0) {
533 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ERROR: dwGTKeyIndex == 0 !!!\n");
534 return false;
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);
547 return true;
548 } else {
549 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GroupKey.bKeyValid == false\n");
550 return false;
552 } // End of Type = GROUP
553 } // BSSID match
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");
560 return false;
564 * Description: Check Pairewise Key
566 * Parameters:
567 * In:
568 * pTable - Pointer to Key table
569 * Out:
570 * none
572 * Return Value: true if found otherwise false
575 bool KeybCheckPairewiseKey(
576 PSKeyManagement pTable,
577 PSKeyItem *pKey
580 int i;
582 *pKey = NULL;
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);
587 return true;
590 return false;
594 * Description: Set Key to table
596 * Parameters:
597 * In:
598 * pTable - Pointer to Key table
599 * dwKeyIndex - Key index (reference to NDIS DDK)
600 * uKeyLength - Key length
601 * KeyRSC - Key RSC
602 * pbyKey - Pointer to key
603 * Out:
604 * none
606 * Return Value: true if success otherwise false
609 bool KeybSetDefaultKey(
610 PSKeyManagement pTable,
611 unsigned long dwKeyIndex,
612 unsigned long uKeyLength,
613 PQWORD pKeyRSC,
614 unsigned char *pbyKey,
615 unsigned char byKeyDecMode,
616 unsigned long dwIoBase,
617 unsigned char byLocalID
620 unsigned int ii;
621 PSKeyItem pKey;
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
627 return false;
628 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
629 return false;
632 if (uKeyLength > MAX_KEY_LEN)
633 return false;
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;
639 // Group key
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;
657 } else {
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) {
676 // RSC set by NIC
677 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
678 } else {
679 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
681 pKey->dwTSC47_16 = 0;
682 pKey->wTSC15_0 = 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);
697 return true;
701 * Description: Set Key to table
703 * Parameters:
704 * In:
705 * pTable - Pointer to Key table
706 * dwKeyIndex - Key index (reference to NDIS DDK)
707 * uKeyLength - Key length
708 * KeyRSC - Key RSC
709 * pbyKey - Pointer to key
710 * Out:
711 * none
713 * Return Value: true if success otherwise false
716 bool KeybSetAllGroupKey(
717 PSKeyManagement pTable,
718 unsigned long dwKeyIndex,
719 unsigned long uKeyLength,
720 PQWORD pKeyRSC,
721 unsigned char *pbyKey,
722 unsigned char byKeyDecMode,
723 unsigned long dwIoBase,
724 unsigned char byLocalID
727 int i;
728 unsigned int ii;
729 PSKeyItem pKey;
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
735 return false;
736 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
737 return false;
740 for (i = 0; i < MAX_KEY_TABLE - 1; i++) {
741 if (pTable->KeyTable[i].bInUse) {
742 // found table already exist
743 // Group key
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) {
772 // RSC set by NIC
773 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
774 } else {
775 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
777 pKey->dwTSC47_16 = 0;
778 pKey->wTSC15_0 = 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)
795 return true;