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