]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/staging/vt6655/key.c
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * Purpose: Implement functions for 802.11i Key management
29 * KeyvInitTable - Init Key management table
30 * KeybGetKey - Get Key from table
31 * KeybSetKey - Set Key to table
32 * KeybRemoveKey - Remove Key from table
33 * KeybGetTransmitKey - Get Transmit Key from table
43 /*--------------------- Static Definitions -------------------------*/
45 /*--------------------- Static Classes ----------------------------*/
47 /*--------------------- Static Variables --------------------------*/
48 static int msglevel
= MSG_LEVEL_INFO
;
49 /*--------------------- Static Functions --------------------------*/
51 /*--------------------- Export Variables --------------------------*/
53 /*--------------------- Static Definitions -------------------------*/
55 /*--------------------- Static Classes ----------------------------*/
57 /*--------------------- Static Variables --------------------------*/
59 /*--------------------- Static Functions --------------------------*/
61 s_vCheckKeyTableValid(PSKeyManagement pTable
, unsigned long dwIoBase
)
65 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
66 if (pTable
->KeyTable
[i
].bInUse
&&
67 !pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
&&
68 !pTable
->KeyTable
[i
].GroupKey
[0].bKeyValid
&&
69 !pTable
->KeyTable
[i
].GroupKey
[1].bKeyValid
&&
70 !pTable
->KeyTable
[i
].GroupKey
[2].bKeyValid
&&
71 !pTable
->KeyTable
[i
].GroupKey
[3].bKeyValid
) {
72 pTable
->KeyTable
[i
].bInUse
= false;
73 pTable
->KeyTable
[i
].wKeyCtl
= 0;
74 pTable
->KeyTable
[i
].bSoftWEP
= false;
75 MACvDisableKeyEntry(dwIoBase
, i
);
80 /*--------------------- Export Functions --------------------------*/
83 * Description: Init Key management table
87 * pTable - Pointer to Key table
94 void KeyvInitTable(PSKeyManagement pTable
, unsigned long dwIoBase
)
99 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
100 pTable
->KeyTable
[i
].bInUse
= false;
101 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= false;
102 pTable
->KeyTable
[i
].PairwiseKey
.pvKeyTable
= (void *)&pTable
->KeyTable
[i
];
103 for (jj
= 0; jj
< MAX_GROUP_KEY
; jj
++) {
104 pTable
->KeyTable
[i
].GroupKey
[jj
].bKeyValid
= false;
105 pTable
->KeyTable
[i
].GroupKey
[jj
].pvKeyTable
= (void *)&pTable
->KeyTable
[i
];
107 pTable
->KeyTable
[i
].wKeyCtl
= 0;
108 pTable
->KeyTable
[i
].dwGTKeyIndex
= 0;
109 pTable
->KeyTable
[i
].bSoftWEP
= false;
110 MACvDisableKeyEntry(dwIoBase
, i
);
115 * Description: Get Key from table
119 * pTable - Pointer to Key table
120 * pbyBSSID - BSSID of Key
121 * dwKeyIndex - Key Index (0xFFFFFFFF means pairwise key)
125 * Return Value: true if found otherwise false
129 PSKeyManagement pTable
,
130 unsigned char *pbyBSSID
,
131 unsigned long dwKeyIndex
,
137 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybGetKey() \n");
140 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
141 if (pTable
->KeyTable
[i
].bInUse
&&
142 ether_addr_equal(pTable
->KeyTable
[i
].abyBSSID
, pbyBSSID
)) {
143 if (dwKeyIndex
== 0xFFFFFFFF) {
144 if (pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
) {
145 *pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
150 } else if (dwKeyIndex
< MAX_GROUP_KEY
) {
151 if (pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
].bKeyValid
) {
152 *pKey
= &(pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
]);
166 * Description: Set Key to table
170 * pTable - Pointer to Key table
171 * pbyBSSID - BSSID of Key
172 * dwKeyIndex - Key index (reference to NDIS DDK)
173 * uKeyLength - Key length
175 * pbyKey - Pointer to key
179 * Return Value: true if success otherwise false
183 PSKeyManagement pTable
,
184 unsigned char *pbyBSSID
,
185 unsigned long dwKeyIndex
,
186 unsigned long uKeyLength
,
188 unsigned char *pbyKey
,
189 unsigned char byKeyDecMode
,
190 unsigned long dwIoBase
,
191 unsigned char byLocalID
197 unsigned int uKeyIdx
;
199 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enter KeybSetKey: %lX\n", dwKeyIndex
);
201 j
= (MAX_KEY_TABLE
-1);
202 for (i
= 0; i
< (MAX_KEY_TABLE
- 1); i
++) {
203 if (!pTable
->KeyTable
[i
].bInUse
&& (j
== (MAX_KEY_TABLE
-1))) {
207 if (pTable
->KeyTable
[i
].bInUse
&&
208 ether_addr_equal(pTable
->KeyTable
[i
].abyBSSID
, pbyBSSID
)) {
209 // found table already exist
210 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
212 pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
213 pTable
->KeyTable
[i
].wKeyCtl
&= 0xFFF0; // clear pairwise key control filed
214 pTable
->KeyTable
[i
].wKeyCtl
|= byKeyDecMode
;
215 uKeyIdx
= 4; // use HW key entry 4 for pairwise key
218 if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
)
220 pKey
= &(pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
& 0x000000FF]);
221 if ((dwKeyIndex
& TRANSMIT_KEY
) != 0) {
222 // Group transmit key
223 pTable
->KeyTable
[i
].dwGTKeyIndex
= dwKeyIndex
;
224 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Group transmit key(R)[%lX]: %d\n", pTable
->KeyTable
[i
].dwGTKeyIndex
, i
);
226 pTable
->KeyTable
[i
].wKeyCtl
&= 0xFF0F; // clear group key control filed
227 pTable
->KeyTable
[i
].wKeyCtl
|= (byKeyDecMode
<< 4);
228 pTable
->KeyTable
[i
].wKeyCtl
|= 0x0040; // use group key for group address
229 uKeyIdx
= (dwKeyIndex
& 0x000000FF);
231 pTable
->KeyTable
[i
].wKeyCtl
|= 0x8000; // enable on-fly
233 pKey
->bKeyValid
= true;
234 pKey
->uKeyLength
= uKeyLength
;
235 pKey
->dwKeyIndex
= dwKeyIndex
;
236 pKey
->byCipherSuite
= byKeyDecMode
;
237 memcpy(pKey
->abyKey
, pbyKey
, uKeyLength
);
238 if (byKeyDecMode
== KEY_CTL_WEP
) {
239 if (uKeyLength
== WLAN_WEP40_KEYLEN
)
240 pKey
->abyKey
[15] &= 0x7F;
241 if (uKeyLength
== WLAN_WEP104_KEYLEN
)
242 pKey
->abyKey
[15] |= 0x80;
244 MACvSetKeyEntry(dwIoBase
, pTable
->KeyTable
[i
].wKeyCtl
, i
, uKeyIdx
, pbyBSSID
, (u32
*)pKey
->abyKey
, byLocalID
);
246 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
248 memset(&(pKey
->KeyRSC
), 0, sizeof(QWORD
));
250 memcpy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
252 pKey
->dwTSC47_16
= 0;
255 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybSetKey(R): \n");
256 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->bKeyValid: %d\n ", pKey
->bKeyValid
);
257 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->abyKey: ");
258 for (ii
= 0; ii
< pKey
->uKeyLength
; ii
++) {
259 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pKey
->abyKey
[ii
]);
261 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
263 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwTSC47_16: %lx\n ", pKey
->dwTSC47_16
);
264 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->wTSC15_0: %x\n ", pKey
->wTSC15_0
);
265 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwKeyIndex: %lx\n ", pKey
->dwKeyIndex
);
270 if (j
< (MAX_KEY_TABLE
-1)) {
271 memcpy(pTable
->KeyTable
[j
].abyBSSID
, pbyBSSID
, ETH_ALEN
);
272 pTable
->KeyTable
[j
].bInUse
= true;
273 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
275 pKey
= &(pTable
->KeyTable
[j
].PairwiseKey
);
276 pTable
->KeyTable
[j
].wKeyCtl
&= 0xFFF0; // clear pairwise key control filed
277 pTable
->KeyTable
[j
].wKeyCtl
|= byKeyDecMode
;
278 uKeyIdx
= 4; // use HW key entry 4 for pairwise key
281 if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
)
283 pKey
= &(pTable
->KeyTable
[j
].GroupKey
[dwKeyIndex
& 0x000000FF]);
284 if ((dwKeyIndex
& TRANSMIT_KEY
) != 0) {
285 // Group transmit key
286 pTable
->KeyTable
[j
].dwGTKeyIndex
= dwKeyIndex
;
287 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Group transmit key(N)[%lX]: %d\n", pTable
->KeyTable
[j
].dwGTKeyIndex
, j
);
289 pTable
->KeyTable
[j
].wKeyCtl
&= 0xFF0F; // clear group key control filed
290 pTable
->KeyTable
[j
].wKeyCtl
|= (byKeyDecMode
<< 4);
291 pTable
->KeyTable
[j
].wKeyCtl
|= 0x0040; // use group key for group address
292 uKeyIdx
= (dwKeyIndex
& 0x000000FF);
294 pTable
->KeyTable
[j
].wKeyCtl
|= 0x8000; // enable on-fly
296 pKey
->bKeyValid
= true;
297 pKey
->uKeyLength
= uKeyLength
;
298 pKey
->dwKeyIndex
= dwKeyIndex
;
299 pKey
->byCipherSuite
= byKeyDecMode
;
300 memcpy(pKey
->abyKey
, pbyKey
, uKeyLength
);
301 if (byKeyDecMode
== KEY_CTL_WEP
) {
302 if (uKeyLength
== WLAN_WEP40_KEYLEN
)
303 pKey
->abyKey
[15] &= 0x7F;
304 if (uKeyLength
== WLAN_WEP104_KEYLEN
)
305 pKey
->abyKey
[15] |= 0x80;
307 MACvSetKeyEntry(dwIoBase
, pTable
->KeyTable
[j
].wKeyCtl
, j
, uKeyIdx
, pbyBSSID
, (u32
*)pKey
->abyKey
, byLocalID
);
309 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
311 memset(&(pKey
->KeyRSC
), 0, sizeof(QWORD
));
313 memcpy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
315 pKey
->dwTSC47_16
= 0;
318 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybSetKey(N): \n");
319 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->bKeyValid: %d\n ", pKey
->bKeyValid
);
320 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->uKeyLength: %d\n ", (int)pKey
->uKeyLength
);
321 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->abyKey: ");
322 for (ii
= 0; ii
< pKey
->uKeyLength
; ii
++) {
323 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pKey
->abyKey
[ii
]);
325 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
327 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwTSC47_16: %lx\n ", pKey
->dwTSC47_16
);
328 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->wTSC15_0: %x\n ", pKey
->wTSC15_0
);
329 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwKeyIndex: %lx\n ", pKey
->dwKeyIndex
);
337 * Description: Remove Key from table
341 * pTable - Pointer to Key table
342 * pbyBSSID - BSSID of Key
343 * dwKeyIndex - Key Index (reference to NDIS DDK)
347 * Return Value: true if success otherwise false
351 PSKeyManagement pTable
,
352 unsigned char *pbyBSSID
,
353 unsigned long dwKeyIndex
,
354 unsigned long dwIoBase
359 if (is_broadcast_ether_addr(pbyBSSID
)) {
361 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
362 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
363 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= false;
365 s_vCheckKeyTableValid(pTable
, dwIoBase
);
367 } else if ((dwKeyIndex
& 0x000000FF) < MAX_GROUP_KEY
) {
368 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
369 pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
& 0x000000FF].bKeyValid
= false;
370 if ((dwKeyIndex
& 0x7FFFFFFF) == (pTable
->KeyTable
[i
].dwGTKeyIndex
& 0x7FFFFFFF)) {
371 // remove Group transmit key
372 pTable
->KeyTable
[i
].dwGTKeyIndex
= 0;
375 s_vCheckKeyTableValid(pTable
, dwIoBase
);
382 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
383 if (pTable
->KeyTable
[i
].bInUse
&&
384 ether_addr_equal(pTable
->KeyTable
[i
].abyBSSID
, pbyBSSID
)) {
385 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) {
386 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= false;
387 s_vCheckKeyTableValid(pTable
, dwIoBase
);
389 } else if ((dwKeyIndex
& 0x000000FF) < MAX_GROUP_KEY
) {
390 pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
& 0x000000FF].bKeyValid
= false;
391 if ((dwKeyIndex
& 0x7FFFFFFF) == (pTable
->KeyTable
[i
].dwGTKeyIndex
& 0x7FFFFFFF)) {
392 // remove Group transmit key
393 pTable
->KeyTable
[i
].dwGTKeyIndex
= 0;
395 s_vCheckKeyTableValid(pTable
, dwIoBase
);
406 * Description: Remove Key from table
410 * pTable - Pointer to Key table
411 * pbyBSSID - BSSID of Key
415 * Return Value: true if success otherwise false
418 bool KeybRemoveAllKey(
419 PSKeyManagement pTable
,
420 unsigned char *pbyBSSID
,
421 unsigned long dwIoBase
426 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
427 if (pTable
->KeyTable
[i
].bInUse
&&
428 ether_addr_equal(pTable
->KeyTable
[i
].abyBSSID
, pbyBSSID
)) {
429 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
= false;
430 for (u
= 0; u
< MAX_GROUP_KEY
; u
++) {
431 pTable
->KeyTable
[i
].GroupKey
[u
].bKeyValid
= false;
433 pTable
->KeyTable
[i
].dwGTKeyIndex
= 0;
434 s_vCheckKeyTableValid(pTable
, dwIoBase
);
442 * Description: Remove WEP Key from table
446 * pTable - Pointer to Key table
450 * Return Value: true if success otherwise false
453 void KeyvRemoveWEPKey(
454 PSKeyManagement pTable
,
455 unsigned long dwKeyIndex
,
456 unsigned long dwIoBase
459 if ((dwKeyIndex
& 0x000000FF) < MAX_GROUP_KEY
) {
460 if (pTable
->KeyTable
[MAX_KEY_TABLE
-1].bInUse
) {
461 if (pTable
->KeyTable
[MAX_KEY_TABLE
-1].GroupKey
[dwKeyIndex
& 0x000000FF].byCipherSuite
== KEY_CTL_WEP
) {
462 pTable
->KeyTable
[MAX_KEY_TABLE
-1].GroupKey
[dwKeyIndex
& 0x000000FF].bKeyValid
= false;
463 if ((dwKeyIndex
& 0x7FFFFFFF) == (pTable
->KeyTable
[MAX_KEY_TABLE
-1].dwGTKeyIndex
& 0x7FFFFFFF)) {
464 // remove Group transmit key
465 pTable
->KeyTable
[MAX_KEY_TABLE
-1].dwGTKeyIndex
= 0;
469 s_vCheckKeyTableValid(pTable
, dwIoBase
);
474 void KeyvRemoveAllWEPKey(
475 PSKeyManagement pTable
,
476 unsigned long dwIoBase
481 for (i
= 0; i
< MAX_GROUP_KEY
; i
++) {
482 KeyvRemoveWEPKey(pTable
, i
, dwIoBase
);
487 * Description: Get Transmit Key from table
491 * pTable - Pointer to Key table
492 * pbyBSSID - BSSID of Key
496 * Return Value: true if found otherwise false
499 bool KeybGetTransmitKey(
500 PSKeyManagement pTable
,
501 unsigned char *pbyBSSID
,
502 unsigned long dwKeyType
,
509 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
510 if (pTable
->KeyTable
[i
].bInUse
&&
511 ether_addr_equal(pTable
->KeyTable
[i
].abyBSSID
, pbyBSSID
)) {
512 if (dwKeyType
== PAIRWISE_KEY
) {
513 if (pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
) {
514 *pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
516 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybGetTransmitKey:");
517 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PAIRWISE_KEY: KeyTable.abyBSSID: ");
518 for (ii
= 0; ii
< 6; ii
++) {
519 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%x ", pTable
->KeyTable
[i
].abyBSSID
[ii
]);
521 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
525 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PairwiseKey.bKeyValid == false\n");
528 } // End of Type == PAIRWISE
530 if (pTable
->KeyTable
[i
].dwGTKeyIndex
== 0) {
531 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ERROR: dwGTKeyIndex == 0 !!!\n");
534 if (pTable
->KeyTable
[i
].GroupKey
[(pTable
->KeyTable
[i
].dwGTKeyIndex
&0x000000FF)].bKeyValid
) {
535 *pKey
= &(pTable
->KeyTable
[i
].GroupKey
[(pTable
->KeyTable
[i
].dwGTKeyIndex
&0x000000FF)]);
537 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybGetTransmitKey:");
538 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GROUP_KEY: KeyTable.abyBSSID\n");
539 for (ii
= 0; ii
< 6; ii
++) {
540 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%x ", pTable
->KeyTable
[i
].abyBSSID
[ii
]);
542 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
543 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dwGTKeyIndex: %lX\n", pTable
->KeyTable
[i
].dwGTKeyIndex
);
547 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GroupKey.bKeyValid == false\n");
550 } // End of Type = GROUP
553 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ERROR: NO Match BSSID !!! ");
554 for (ii
= 0; ii
< 6; ii
++) {
555 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", *(pbyBSSID
+ii
));
557 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
562 * Description: Check Pairewise Key
566 * pTable - Pointer to Key table
570 * Return Value: true if found otherwise false
573 bool KeybCheckPairewiseKey(
574 PSKeyManagement pTable
,
581 for (i
= 0; i
< MAX_KEY_TABLE
; i
++) {
582 if (pTable
->KeyTable
[i
].bInUse
&&
583 pTable
->KeyTable
[i
].PairwiseKey
.bKeyValid
) {
584 *pKey
= &(pTable
->KeyTable
[i
].PairwiseKey
);
592 * Description: Set Key to table
596 * pTable - Pointer to Key table
597 * dwKeyIndex - Key index (reference to NDIS DDK)
598 * uKeyLength - Key length
600 * pbyKey - Pointer to key
604 * Return Value: true if success otherwise false
607 bool KeybSetDefaultKey(
608 PSKeyManagement pTable
,
609 unsigned long dwKeyIndex
,
610 unsigned long uKeyLength
,
612 unsigned char *pbyKey
,
613 unsigned char byKeyDecMode
,
614 unsigned long dwIoBase
,
615 unsigned char byLocalID
620 unsigned int uKeyIdx
;
622 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enter KeybSetDefaultKey: %1x, %d \n", (int)dwKeyIndex
, (int)uKeyLength
);
624 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) { // Pairwise key
626 } else if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
) {
630 if (uKeyLength
> MAX_KEY_LEN
)
633 pTable
->KeyTable
[MAX_KEY_TABLE
- 1].bInUse
= true;
634 for (ii
= 0; ii
< ETH_ALEN
; ii
++)
635 pTable
->KeyTable
[MAX_KEY_TABLE
- 1].abyBSSID
[ii
] = 0xFF;
638 pKey
= &(pTable
->KeyTable
[MAX_KEY_TABLE
- 1].GroupKey
[dwKeyIndex
& 0x000000FF]);
639 if ((dwKeyIndex
& TRANSMIT_KEY
) != 0) {
640 // Group transmit key
641 pTable
->KeyTable
[MAX_KEY_TABLE
-1].dwGTKeyIndex
= dwKeyIndex
;
642 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);
645 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
&= 0x7F00; // clear all key control filed
646 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= (byKeyDecMode
<< 4);
647 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= (byKeyDecMode
);
648 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= 0x0044; // use group key for all address
649 uKeyIdx
= (dwKeyIndex
& 0x000000FF);
651 if ((uKeyLength
== WLAN_WEP232_KEYLEN
) &&
652 (byKeyDecMode
== KEY_CTL_WEP
)) {
653 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= 0x4000; // disable on-fly disable address match
654 pTable
->KeyTable
[MAX_KEY_TABLE
-1].bSoftWEP
= true;
656 if (!pTable
->KeyTable
[MAX_KEY_TABLE
-1].bSoftWEP
)
657 pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
|= 0xC000; // enable on-fly disable address match
660 pKey
->bKeyValid
= true;
661 pKey
->uKeyLength
= uKeyLength
;
662 pKey
->dwKeyIndex
= dwKeyIndex
;
663 pKey
->byCipherSuite
= byKeyDecMode
;
664 memcpy(pKey
->abyKey
, pbyKey
, uKeyLength
);
665 if (byKeyDecMode
== KEY_CTL_WEP
) {
666 if (uKeyLength
== WLAN_WEP40_KEYLEN
)
667 pKey
->abyKey
[15] &= 0x7F;
668 if (uKeyLength
== WLAN_WEP104_KEYLEN
)
669 pKey
->abyKey
[15] |= 0x80;
671 MACvSetKeyEntry(dwIoBase
, pTable
->KeyTable
[MAX_KEY_TABLE
-1].wKeyCtl
, MAX_KEY_TABLE
-1, uKeyIdx
, pTable
->KeyTable
[MAX_KEY_TABLE
-1].abyBSSID
, (u32
*)pKey
->abyKey
, byLocalID
);
673 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
675 memset(&(pKey
->KeyRSC
), 0, sizeof(QWORD
));
677 memcpy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
679 pKey
->dwTSC47_16
= 0;
682 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybSetKey(R): \n");
683 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->bKeyValid: %d\n", pKey
->bKeyValid
);
684 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->uKeyLength: %d\n", (int)pKey
->uKeyLength
);
685 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->abyKey: \n");
686 for (ii
= 0; ii
< pKey
->uKeyLength
; ii
++) {
687 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%x", pKey
->abyKey
[ii
]);
689 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
691 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwTSC47_16: %lx\n", pKey
->dwTSC47_16
);
692 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->wTSC15_0: %x\n", pKey
->wTSC15_0
);
693 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->dwKeyIndex: %lx\n", pKey
->dwKeyIndex
);
699 * Description: Set Key to table
703 * pTable - Pointer to Key table
704 * dwKeyIndex - Key index (reference to NDIS DDK)
705 * uKeyLength - Key length
707 * pbyKey - Pointer to key
711 * Return Value: true if success otherwise false
714 bool KeybSetAllGroupKey(
715 PSKeyManagement pTable
,
716 unsigned long dwKeyIndex
,
717 unsigned long uKeyLength
,
719 unsigned char *pbyKey
,
720 unsigned char byKeyDecMode
,
721 unsigned long dwIoBase
,
722 unsigned char byLocalID
728 unsigned int uKeyIdx
;
730 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enter KeybSetAllGroupKey: %lX\n", dwKeyIndex
);
732 if ((dwKeyIndex
& PAIRWISE_KEY
) != 0) { // Pairwise key
734 } else if ((dwKeyIndex
& 0x000000FF) >= MAX_GROUP_KEY
) {
738 for (i
= 0; i
< MAX_KEY_TABLE
- 1; i
++) {
739 if (pTable
->KeyTable
[i
].bInUse
) {
740 // found table already exist
742 pKey
= &(pTable
->KeyTable
[i
].GroupKey
[dwKeyIndex
& 0x000000FF]);
743 if ((dwKeyIndex
& TRANSMIT_KEY
) != 0) {
744 // Group transmit key
745 pTable
->KeyTable
[i
].dwGTKeyIndex
= dwKeyIndex
;
746 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Group transmit key(R)[%lX]: %d\n", pTable
->KeyTable
[i
].dwGTKeyIndex
, i
);
749 pTable
->KeyTable
[i
].wKeyCtl
&= 0xFF0F; // clear group key control filed
750 pTable
->KeyTable
[i
].wKeyCtl
|= (byKeyDecMode
<< 4);
751 pTable
->KeyTable
[i
].wKeyCtl
|= 0x0040; // use group key for group address
752 uKeyIdx
= (dwKeyIndex
& 0x000000FF);
754 pTable
->KeyTable
[i
].wKeyCtl
|= 0x8000; // enable on-fly
756 pKey
->bKeyValid
= true;
757 pKey
->uKeyLength
= uKeyLength
;
758 pKey
->dwKeyIndex
= dwKeyIndex
;
759 pKey
->byCipherSuite
= byKeyDecMode
;
760 memcpy(pKey
->abyKey
, pbyKey
, uKeyLength
);
761 if (byKeyDecMode
== KEY_CTL_WEP
) {
762 if (uKeyLength
== WLAN_WEP40_KEYLEN
)
763 pKey
->abyKey
[15] &= 0x7F;
764 if (uKeyLength
== WLAN_WEP104_KEYLEN
)
765 pKey
->abyKey
[15] |= 0x80;
767 MACvSetKeyEntry(dwIoBase
, pTable
->KeyTable
[i
].wKeyCtl
, i
, uKeyIdx
, pTable
->KeyTable
[i
].abyBSSID
, (u32
*)pKey
->abyKey
, byLocalID
);
769 if ((dwKeyIndex
& USE_KEYRSC
) == 0) {
771 memset(&(pKey
->KeyRSC
), 0, sizeof(QWORD
));
773 memcpy(&(pKey
->KeyRSC
), pKeyRSC
, sizeof(QWORD
));
775 pKey
->dwTSC47_16
= 0;
778 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KeybSetKey(R): \n");
779 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->bKeyValid: %d\n ", pKey
->bKeyValid
);
780 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->uKeyLength: %d\n ", (int)pKey
->uKeyLength
);
781 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey->abyKey: ");
782 for (ii
= 0; ii
< pKey
->uKeyLength
; ii
++) {
783 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pKey
->abyKey
[ii
]);
785 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\n");
787 } // (pTable->KeyTable[i].bInUse == true)