Staging: vt665x: Remove umem.h Part 2
[deliverable/linux.git] / drivers / staging / vt6656 / key.c
CommitLineData
92b96797
FB
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
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.
9 *
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.
14 *
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.
18 *
19 *
20 * File: key.c
21 *
22 * Purpose: Implement functions for 802.11i Key management
23 *
24 * Author: Jerry Chen
25 *
26 * Date: May 29, 2003
27 *
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
34 *
35 * Revision History:
36 *
37 */
38
92b96797 39#include "tmacro.h"
92b96797 40#include "tbit.h"
92b96797 41#include "key.h"
92b96797 42#include "mac.h"
92b96797 43#include "rndis.h"
92b96797 44#include "control.h"
92b96797
FB
45
46/*--------------------- Static Definitions -------------------------*/
47
48/*--------------------- Static Classes ----------------------------*/
49
50/*--------------------- Static Variables --------------------------*/
51static int msglevel =MSG_LEVEL_INFO;
52//static int msglevel =MSG_LEVEL_DEBUG;
53/*--------------------- Static Functions --------------------------*/
54
55/*--------------------- Export Variables --------------------------*/
56
57/*--------------------- Static Definitions -------------------------*/
58
59/*--------------------- Static Classes ----------------------------*/
60
61/*--------------------- Static Variables --------------------------*/
62
63/*--------------------- Static Functions --------------------------*/
64static VOID
65s_vCheckKeyTableValid (PVOID pDeviceHandler, PSKeyManagement pTable)
66{
67 PSDevice pDevice = (PSDevice) pDeviceHandler;
68 int i;
69 WORD wLength = 0;
70 BYTE pbyData[MAX_KEY_TABLE];
71
72 for (i=0;i<MAX_KEY_TABLE;i++) {
73 if ((pTable->KeyTable[i].bInUse == TRUE) &&
74 (pTable->KeyTable[i].PairwiseKey.bKeyValid == FALSE) &&
75 (pTable->KeyTable[i].GroupKey[0].bKeyValid == FALSE) &&
76 (pTable->KeyTable[i].GroupKey[1].bKeyValid == FALSE) &&
77 (pTable->KeyTable[i].GroupKey[2].bKeyValid == FALSE) &&
78 (pTable->KeyTable[i].GroupKey[3].bKeyValid == FALSE)
79 ) {
80
81 pTable->KeyTable[i].bInUse = FALSE;
82 pTable->KeyTable[i].wKeyCtl = 0;
83 pTable->KeyTable[i].bSoftWEP = FALSE;
84 pbyData[wLength++] = (BYTE) i;
85 //MACvDisableKeyEntry(pDevice, i);
86 }
87 }
88 if ( wLength != 0 ) {
89 CONTROLnsRequestOut(pDevice,
90 MESSAGE_TYPE_CLRKEYENTRY,
91 0,
92 0,
93 wLength,
94 pbyData
95 );
96 }
97
98}
99
100
101/*--------------------- Export Functions --------------------------*/
102
103
104/*
105 * Description: Init Key management table
106 *
107 * Parameters:
108 * In:
109 * pTable - Pointer to Key table
110 * Out:
111 * none
112 *
113 * Return Value: none
114 *
115 */
116VOID KeyvInitTable(PVOID pDeviceHandler, PSKeyManagement pTable)
117{
118 PSDevice pDevice = (PSDevice) pDeviceHandler;
119 int i;
120 int jj;
121 BYTE pbyData[MAX_KEY_TABLE+1];
122
123 spin_lock_irq(&pDevice->lock);
124 for (i=0;i<MAX_KEY_TABLE;i++) {
125 pTable->KeyTable[i].bInUse = FALSE;
126 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE;
127 pTable->KeyTable[i].PairwiseKey.pvKeyTable = (PVOID)&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 = (PVOID) &(pTable->KeyTable[i]);
131 }
132 pTable->KeyTable[i].wKeyCtl = 0;
133 pTable->KeyTable[i].dwGTKeyIndex = 0;
134 pTable->KeyTable[i].bSoftWEP = FALSE;
135 pbyData[i] = (BYTE) i;
136 }
137 pbyData[i] = (BYTE) i;
138 CONTROLnsRequestOut(pDevice,
139 MESSAGE_TYPE_CLRKEYENTRY,
140 0,
141 0,
142 11,
143 pbyData
144 );
145
146 spin_unlock_irq(&pDevice->lock);
147
148 return;
149}
150
151
152/*
153 * Description: Get Key from table
154 *
155 * Parameters:
156 * In:
157 * pTable - Pointer to Key table
158 * pbyBSSID - BSSID of Key
159 * dwKeyIndex - Key Index (0xFFFFFFFF means pairwise key)
160 * Out:
161 * pKey - Key return
162 *
163 * Return Value: TRUE if found otherwise FALSE
164 *
165 */
166BOOL KeybGetKey (
167 IN PSKeyManagement pTable,
168 IN PBYTE pbyBSSID,
169 IN DWORD dwKeyIndex,
170 OUT PSKeyItem *pKey
171 )
172{
173 int i;
174
175 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetKey() \n");
176
177 *pKey = NULL;
178 for (i=0;i<MAX_KEY_TABLE;i++) {
179 if ((pTable->KeyTable[i].bInUse == TRUE) &&
180 IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) {
181 if (dwKeyIndex == 0xFFFFFFFF) {
182 if (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE) {
183 *pKey = &(pTable->KeyTable[i].PairwiseKey);
184 return (TRUE);
185 }
186 else {
187 return (FALSE);
188 }
189 } else if (dwKeyIndex < MAX_GROUP_KEY) {
190 if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid == TRUE) {
191 *pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex]);
192 return (TRUE);
193 }
194 else {
195 return (FALSE);
196 }
197 }
198 else {
199 return (FALSE);
200 }
201 }
202 }
203 return (FALSE);
204}
205
206
207/*
208 * Description: Set Key to table
209 *
210 * Parameters:
211 * In:
212 * pTable - Pointer to Key table
213 * pbyBSSID - BSSID of Key
214 * dwKeyIndex - Key index (reference to NDIS DDK)
215 * uKeyLength - Key length
216 * KeyRSC - Key RSC
217 * pbyKey - Pointer to key
218 * Out:
219 * none
220 *
221 * Return Value: TRUE if success otherwise FALSE
222 *
223 */
224BOOL KeybSetKey (
225 PVOID pDeviceHandler,
226 PSKeyManagement pTable,
227 PBYTE pbyBSSID,
228 DWORD dwKeyIndex,
229 ULONG uKeyLength,
230 PQWORD pKeyRSC,
231 PBYTE pbyKey,
232 BYTE byKeyDecMode
233 )
234{
235 PSDevice pDevice = (PSDevice) pDeviceHandler;
236 int i,j;
237 UINT ii;
238 PSKeyItem pKey;
239 UINT uKeyIdx;
240
241 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetKey: %lX\n", dwKeyIndex);
242
243 j = (MAX_KEY_TABLE-1);
244 for (i=0;i<(MAX_KEY_TABLE-1);i++) {
245 if ((pTable->KeyTable[i].bInUse == FALSE) &&
246 (j == (MAX_KEY_TABLE-1))) {
247 // found empty table
248 j = i;
249 }
250 if ((pTable->KeyTable[i].bInUse == TRUE) &&
251 IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) {
252 // found table already exist
253 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
254 // Pairwise key
255 pKey = &(pTable->KeyTable[i].PairwiseKey);
256 pTable->KeyTable[i].wKeyCtl &= 0xFFF0; // clear pairwise key control filed
257 pTable->KeyTable[i].wKeyCtl |= byKeyDecMode;
258 uKeyIdx = 4; // use HW key entry 4 for pairwise key
259 } else {
260 // Group key
261 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
262 return (FALSE);
263 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
264 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
265 // Group transmit key
266 pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
267 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i);
268 }
269 pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed
270 pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
271 pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address
272 uKeyIdx = (dwKeyIndex & 0x000000FF);
273 }
274 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly
275
276 pKey->bKeyValid = TRUE;
277 pKey->uKeyLength = uKeyLength;
278 pKey->dwKeyIndex = dwKeyIndex;
279 pKey->byCipherSuite = byKeyDecMode;
3e362598 280 memcpy(pKey->abyKey, pbyKey, uKeyLength);
92b96797
FB
281 if (byKeyDecMode == KEY_CTL_WEP) {
282 if (uKeyLength == WLAN_WEP40_KEYLEN)
283 pKey->abyKey[15] &= 0x7F;
284 if (uKeyLength == WLAN_WEP104_KEYLEN)
285 pKey->abyKey[15] |= 0x80;
286 }
287 MACvSetKeyEntry(pDevice, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey);
288
289 if ((dwKeyIndex & USE_KEYRSC) == 0) {
290 // RSC set by NIC
3e362598 291 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
92b96797
FB
292 }
293 else {
3e362598 294 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
92b96797
FB
295 }
296 pKey->dwTSC47_16 = 0;
297 pKey->wTSC15_0 = 0;
298
299 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
300 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
301 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", pKey->uKeyLength);
302 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
303 for (ii = 0; ii < pKey->uKeyLength; ii++) {
304 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
305 }
306 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
307
308 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16);
309 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
310 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex);
311
312 return (TRUE);
313 }
314 }
315 if (j < (MAX_KEY_TABLE-1)) {
3e362598 316 memcpy(pTable->KeyTable[j].abyBSSID,pbyBSSID,U_ETHER_ADDR_LEN);
92b96797
FB
317 pTable->KeyTable[j].bInUse = TRUE;
318 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
319 // Pairwise key
320 pKey = &(pTable->KeyTable[j].PairwiseKey);
321 pTable->KeyTable[j].wKeyCtl &= 0xFFF0; // clear pairwise key control filed
322 pTable->KeyTable[j].wKeyCtl |= byKeyDecMode;
323 uKeyIdx = 4; // use HW key entry 4 for pairwise key
324 } else {
325 // Group key
326 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
327 return (FALSE);
328 pKey = &(pTable->KeyTable[j].GroupKey[dwKeyIndex & 0x000000FF]);
329 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
330 // Group transmit key
331 pTable->KeyTable[j].dwGTKeyIndex = dwKeyIndex;
332 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(N)[%lX]: %d\n", pTable->KeyTable[j].dwGTKeyIndex, j);
333 }
334 pTable->KeyTable[j].wKeyCtl &= 0xFF0F; // clear group key control filed
335 pTable->KeyTable[j].wKeyCtl |= (byKeyDecMode << 4);
336 pTable->KeyTable[j].wKeyCtl |= 0x0040; // use group key for group address
337 uKeyIdx = (dwKeyIndex & 0x000000FF);
338 }
339 pTable->KeyTable[j].wKeyCtl |= 0x8000; // enable on-fly
340
341 pKey->bKeyValid = TRUE;
342 pKey->uKeyLength = uKeyLength;
343 pKey->dwKeyIndex = dwKeyIndex;
344 pKey->byCipherSuite = byKeyDecMode;
3e362598 345 memcpy(pKey->abyKey, pbyKey, uKeyLength);
92b96797
FB
346 if (byKeyDecMode == KEY_CTL_WEP) {
347 if (uKeyLength == WLAN_WEP40_KEYLEN)
348 pKey->abyKey[15] &= 0x7F;
349 if (uKeyLength == WLAN_WEP104_KEYLEN)
350 pKey->abyKey[15] |= 0x80;
351 }
352 MACvSetKeyEntry(pDevice, pTable->KeyTable[j].wKeyCtl, j, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey);
353
354 if ((dwKeyIndex & USE_KEYRSC) == 0) {
355 // RSC set by NIC
3e362598 356 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
92b96797
FB
357 }
358 else {
3e362598 359 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
92b96797
FB
360 }
361 pKey->dwTSC47_16 = 0;
362 pKey->wTSC15_0 = 0;
363
364 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(N): \n");
365 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
366 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
367 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
368 for (ii = 0; ii < pKey->uKeyLength; ii++) {
369 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
370 }
371 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
372
373 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16);
374 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
375 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex);
376
377 return (TRUE);
378 }
379 return (FALSE);
380}
381
382
383/*
384 * Description: Remove Key from table
385 *
386 * Parameters:
387 * In:
388 * pTable - Pointer to Key table
389 * pbyBSSID - BSSID of Key
390 * dwKeyIndex - Key Index (reference to NDIS DDK)
391 * Out:
392 * none
393 *
394 * Return Value: TRUE if success otherwise FALSE
395 *
396 */
397BOOL KeybRemoveKey (
398 PVOID pDeviceHandler,
399 PSKeyManagement pTable,
400 PBYTE pbyBSSID,
401 DWORD dwKeyIndex
402 )
403{
404 PSDevice pDevice = (PSDevice) pDeviceHandler;
405 int i;
406 BOOL bReturnValue = FALSE;
407
408 if (IS_BROADCAST_ADDRESS(pbyBSSID)) {
409 // dealte all key
410 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
411 for (i=0;i<MAX_KEY_TABLE;i++) {
412 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE;
413 }
414 bReturnValue = TRUE;
415 }
416 else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
417 for (i=0;i<MAX_KEY_TABLE;i++) {
418 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE;
419 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
420 // remove Group transmit key
421 pTable->KeyTable[i].dwGTKeyIndex = 0;
422 }
423 }
424 bReturnValue = TRUE;
425 }
426 else {
427 bReturnValue = FALSE;
428 }
429
430 } else {
431 for (i=0;i<MAX_KEY_TABLE;i++) {
432 if ( (pTable->KeyTable[i].bInUse == TRUE) &&
433 IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) {
434
435 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
436 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE;
437 bReturnValue = TRUE;
438 break;
439 }
440 else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
441 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE;
442 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
443 // remove Group transmit key
444 pTable->KeyTable[i].dwGTKeyIndex = 0;
445 }
446 bReturnValue = TRUE;
447 break;
448 }
449 else {
450 bReturnValue = FALSE;
451 break;
452 }
453 } //pTable->KeyTable[i].bInUse == TRUE
454 } //for
455 bReturnValue = TRUE;
456 }
457
458 s_vCheckKeyTableValid(pDevice,pTable);
459 return bReturnValue;
460
461
462}
463
464
465/*
466 * Description: Remove Key from table
467 *
468 * Parameters:
469 * In:
470 * pTable - Pointer to Key table
471 * pbyBSSID - BSSID of Key
472 * Out:
473 * none
474 *
475 * Return Value: TRUE if success otherwise FALSE
476 *
477 */
478BOOL KeybRemoveAllKey (
479 PVOID pDeviceHandler,
480 PSKeyManagement pTable,
481 PBYTE pbyBSSID
482 )
483{
484 PSDevice pDevice = (PSDevice) pDeviceHandler;
485 int i,u;
486
487 for (i=0;i<MAX_KEY_TABLE;i++) {
488 if ((pTable->KeyTable[i].bInUse == TRUE) &&
489 IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) {
490 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE;
491 for(u=0;u<MAX_GROUP_KEY;u++) {
492 pTable->KeyTable[i].GroupKey[u].bKeyValid = FALSE;
493 }
494 pTable->KeyTable[i].dwGTKeyIndex = 0;
495 s_vCheckKeyTableValid(pDevice, pTable);
496 return (TRUE);
497 }
498 }
499 return (FALSE);
500}
501
502/*
503 * Description: Remove WEP Key from table
504 *
505 * Parameters:
506 * In:
507 * pTable - Pointer to Key table
508 * Out:
509 * none
510 *
511 * Return Value: TRUE if success otherwise FALSE
512 *
513 */
514VOID KeyvRemoveWEPKey (
515 PVOID pDeviceHandler,
516 PSKeyManagement pTable,
517 DWORD dwKeyIndex
518 )
519{
520 PSDevice pDevice = (PSDevice) pDeviceHandler;
521
522 if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
523 if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == TRUE) {
524 if (pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].byCipherSuite == KEY_CTL_WEP) {
525 pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE;
526 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex & 0x7FFFFFFF)) {
527 // remove Group transmit key
528 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = 0;
529 }
530 }
531 }
532 s_vCheckKeyTableValid(pDevice, pTable);
533 }
534 return;
535}
536
537VOID KeyvRemoveAllWEPKey (
538 PVOID pDeviceHandler,
539 PSKeyManagement pTable
540 )
541{
542 PSDevice pDevice = (PSDevice) pDeviceHandler;
543
544 int i;
545
546 for(i=0;i<MAX_GROUP_KEY;i++) {
547 KeyvRemoveWEPKey(pDevice,pTable, i);
548 }
549
550}
551
552/*
553 * Description: Get Transmit Key from table
554 *
555 * Parameters:
556 * In:
557 * pTable - Pointer to Key table
558 * pbyBSSID - BSSID of Key
559 * Out:
560 * pKey - Key return
561 *
562 * Return Value: TRUE if found otherwise FALSE
563 *
564 */
565BOOL KeybGetTransmitKey (
566 IN PSKeyManagement pTable,
567 IN PBYTE pbyBSSID,
568 IN DWORD dwKeyType,
569 OUT PSKeyItem *pKey
570 )
571{
572 int i, ii;
573
574 *pKey = NULL;
575 for (i=0;i<MAX_KEY_TABLE;i++) {
576 if ((pTable->KeyTable[i].bInUse == TRUE) &&
577 IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) {
578
579 if (dwKeyType == PAIRWISE_KEY) {
580
581 if (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE) {
582 *pKey = &(pTable->KeyTable[i].PairwiseKey);
583
584 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:");
585 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PAIRWISE_KEY: KeyTable.abyBSSID: ");
586 for (ii = 0; ii < 6; ii++) {
587 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x ", pTable->KeyTable[i].abyBSSID[ii]);
588 }
589 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
590
591
592 return (TRUE);
593 }
594 else {
595 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PairwiseKey.bKeyValid == FALSE\n");
596 return (FALSE);
597 }
598 } // End of Type == PAIRWISE
599 else {
600 if (pTable->KeyTable[i].dwGTKeyIndex == 0) {
601 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: dwGTKeyIndex == 0 !!!\n");
602 return FALSE;
603 }
604 if (pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)].bKeyValid == TRUE) {
605 *pKey = &(pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)]);
606
607 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:");
608 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GROUP_KEY: KeyTable.abyBSSID\n");
609 for (ii = 0; ii < 6; ii++) {
610 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x ", pTable->KeyTable[i].abyBSSID[ii]);
611 }
612 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
613 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"dwGTKeyIndex: %lX\n", pTable->KeyTable[i].dwGTKeyIndex);
614
615 return (TRUE);
616 }
617 else {
618 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GroupKey.bKeyValid == FALSE\n");
619 return (FALSE);
620 }
621 } // End of Type = GROUP
622 } // BSSID match
623 }
624 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: NO Match BSSID !!! ");
625 for (ii = 0; ii < 6; ii++) {
626 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(pbyBSSID+ii));
627 }
628 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
629 return (FALSE);
630}
631
632
633/*
634 * Description: Check Pairewise Key
635 *
636 * Parameters:
637 * In:
638 * pTable - Pointer to Key table
639 * Out:
640 * none
641 *
642 * Return Value: TRUE if found otherwise FALSE
643 *
644 */
645BOOL KeybCheckPairewiseKey (
646 IN PSKeyManagement pTable,
647 OUT PSKeyItem *pKey
648 )
649{
650 int i;
651
652 *pKey = NULL;
653 for (i=0;i<MAX_KEY_TABLE;i++) {
654 if ((pTable->KeyTable[i].bInUse == TRUE) &&
655 (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE)) {
656 *pKey = &(pTable->KeyTable[i].PairwiseKey);
657 return (TRUE);
658 }
659 }
660 return (FALSE);
661}
662
663/*
664 * Description: Set Key to table
665 *
666 * Parameters:
667 * In:
668 * pTable - Pointer to Key table
669 * dwKeyIndex - Key index (reference to NDIS DDK)
670 * uKeyLength - Key length
671 * KeyRSC - Key RSC
672 * pbyKey - Pointer to key
673 * Out:
674 * none
675 *
676 * Return Value: TRUE if success otherwise FALSE
677 *
678 */
679BOOL KeybSetDefaultKey (
680 PVOID pDeviceHandler,
681 PSKeyManagement pTable,
682 DWORD dwKeyIndex,
683 ULONG uKeyLength,
684 PQWORD pKeyRSC,
685 PBYTE pbyKey,
686 BYTE byKeyDecMode
687 )
688{
689 PSDevice pDevice = (PSDevice) pDeviceHandler;
690 UINT ii;
691 PSKeyItem pKey;
692 UINT uKeyIdx;
693
694 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetDefaultKey: %1x, %d \n", (int)dwKeyIndex, (int)uKeyLength);
695
696
697 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key
698 return (FALSE);
699 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
700 return (FALSE);
701 }
702
703 pTable->KeyTable[MAX_KEY_TABLE-1].bInUse = TRUE;
704 for(ii=0;ii<U_ETHER_ADDR_LEN;ii++)
705 pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID[ii] = 0xFF;
706
707 // Group key
708 pKey = &(pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF]);
709 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
710 // Group transmit key
711 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = dwKeyIndex;
712 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);
713
714 }
715 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl &= 0x7F00; // clear all key control filed
716 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode << 4);
717 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode);
718 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x0044; // use group key for all address
719 uKeyIdx = (dwKeyIndex & 0x000000FF);
720
721 if ((uKeyLength == WLAN_WEP232_KEYLEN) &&
722 (byKeyDecMode == KEY_CTL_WEP)) {
723 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x4000; // disable on-fly disable address match
724 pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP = TRUE;
725 } else {
726 if (pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP == FALSE)
727 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0xC000; // enable on-fly disable address match
728 }
729
730 pKey->bKeyValid = TRUE;
731 pKey->uKeyLength = uKeyLength;
732 pKey->dwKeyIndex = dwKeyIndex;
733 pKey->byCipherSuite = byKeyDecMode;
3e362598 734 memcpy(pKey->abyKey, pbyKey, uKeyLength);
92b96797
FB
735 if (byKeyDecMode == KEY_CTL_WEP) {
736 if (uKeyLength == WLAN_WEP40_KEYLEN)
737 pKey->abyKey[15] &= 0x7F;
738 if (uKeyLength == WLAN_WEP104_KEYLEN)
739 pKey->abyKey[15] |= 0x80;
740 }
741
742 MACvSetKeyEntry(pDevice, pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl, MAX_KEY_TABLE-1, uKeyIdx, pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID, (PDWORD) pKey->abyKey);
743
744 if ((dwKeyIndex & USE_KEYRSC) == 0) {
745 // RSC set by NIC
3e362598 746 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
92b96797 747 } else {
3e362598 748 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
92b96797
FB
749 }
750 pKey->dwTSC47_16 = 0;
751 pKey->wTSC15_0 = 0;
752
753
754 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
755 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n", pKey->bKeyValid);
756 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n", (int)pKey->uKeyLength);
757 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: \n");
758 for (ii = 0; ii < pKey->uKeyLength; ii++) {
759 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x", pKey->abyKey[ii]);
760 }
761 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
762
763 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n", pKey->dwTSC47_16);
764 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n", pKey->wTSC15_0);
765 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n", pKey->dwKeyIndex);
766
767 return (TRUE);
768}
769
770
771/*
772 * Description: Set Key to table
773 *
774 * Parameters:
775 * In:
776 * pTable - Pointer to Key table
777 * dwKeyIndex - Key index (reference to NDIS DDK)
778 * uKeyLength - Key length
779 * KeyRSC - Key RSC
780 * pbyKey - Pointer to key
781 * Out:
782 * none
783 *
784 * Return Value: TRUE if success otherwise FALSE
785 *
786 */
787BOOL KeybSetAllGroupKey (
788 PVOID pDeviceHandler,
789 PSKeyManagement pTable,
790 DWORD dwKeyIndex,
791 ULONG uKeyLength,
792 PQWORD pKeyRSC,
793 PBYTE pbyKey,
794 BYTE byKeyDecMode
795 )
796{
797 PSDevice pDevice = (PSDevice) pDeviceHandler;
798 int i;
799 UINT ii;
800 PSKeyItem pKey;
801 UINT uKeyIdx;
802
803 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetAllGroupKey: %lX\n", dwKeyIndex);
804
805
806 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key
807 return (FALSE);
808 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
809 return (FALSE);
810 }
811
812 for (i=0; i < MAX_KEY_TABLE-1; i++) {
813 if (pTable->KeyTable[i].bInUse == TRUE) {
814 // found table already exist
815 // Group key
816 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
817 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
818 // Group transmit key
819 pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
820 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i);
821
822 }
823 pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed
824 pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
825 pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address
826 uKeyIdx = (dwKeyIndex & 0x000000FF);
827
828 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly
829
830 pKey->bKeyValid = TRUE;
831 pKey->uKeyLength = uKeyLength;
832 pKey->dwKeyIndex = dwKeyIndex;
833 pKey->byCipherSuite = byKeyDecMode;
3e362598 834 memcpy(pKey->abyKey, pbyKey, uKeyLength);
92b96797
FB
835 if (byKeyDecMode == KEY_CTL_WEP) {
836 if (uKeyLength == WLAN_WEP40_KEYLEN)
837 pKey->abyKey[15] &= 0x7F;
838 if (uKeyLength == WLAN_WEP104_KEYLEN)
839 pKey->abyKey[15] |= 0x80;
840 }
841
842 MACvSetKeyEntry(pDevice, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pTable->KeyTable[i].abyBSSID, (PDWORD) pKey->abyKey);
843
844 if ((dwKeyIndex & USE_KEYRSC) == 0) {
845 // RSC set by NIC
3e362598 846 memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
92b96797
FB
847 }
848 else {
3e362598 849 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
92b96797
FB
850 }
851 pKey->dwTSC47_16 = 0;
852 pKey->wTSC15_0 = 0;
853
854 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
855 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
856 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
857 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
858 for (ii = 0; ii < pKey->uKeyLength; ii++) {
859 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", pKey->abyKey[ii]);
860 }
861 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
862
863 //DBG_PRN_GRP12(("pKey->dwTSC47_16: %lX\n ", pKey->dwTSC47_16));
864 //DBG_PRN_GRP12(("pKey->wTSC15_0: %X\n ", pKey->wTSC15_0));
865 //DBG_PRN_GRP12(("pKey->dwKeyIndex: %lX\n ", pKey->dwKeyIndex));
866
867 } // (pTable->KeyTable[i].bInUse == TRUE)
868 }
869 return (TRUE);
870}
This page took 0.065231 seconds and 5 git commands to generate.