Commit | Line | Data |
---|---|---|
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 --------------------------*/ | |
48 | static 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 | 61 | static void |
5449c685 FB |
62 | s_vCheckKeyTableValid (PSKeyManagement pTable, DWORD_PTR dwIoBase) |
63 | { | |
64 | int i; | |
65 | ||
66 | for (i=0;i<MAX_KEY_TABLE;i++) { | |
67 | if ((pTable->KeyTable[i].bInUse == TRUE) && | |
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) | |
73 | ) { | |
612822f5 | 74 | |
5449c685 FB |
75 | pTable->KeyTable[i].bInUse = FALSE; |
76 | pTable->KeyTable[i].wKeyCtl = 0; | |
77 | pTable->KeyTable[i].bSoftWEP = FALSE; | |
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 | */ | |
6b35b7b3 | 99 | void KeyvInitTable (PSKeyManagement pTable, DWORD_PTR dwIoBase) |
5449c685 FB |
100 | { |
101 | int i; | |
102 | int jj; | |
103 | ||
104 | for (i=0;i<MAX_KEY_TABLE;i++) { | |
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 FB |
108 | for (jj=0; jj < MAX_GROUP_KEY; jj++) { |
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; | |
114 | pTable->KeyTable[i].bSoftWEP = FALSE; | |
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 | * | |
131 | * Return Value: TRUE if found otherwise FALSE | |
132 | * | |
133 | */ | |
134 | BOOL KeybGetKey ( | |
3a215e0f CC |
135 | PSKeyManagement pTable, |
136 | PBYTE pbyBSSID, | |
137 | DWORD 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++) { | |
147 | if ((pTable->KeyTable[i].bInUse == TRUE) && | |
148 | IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) { | |
149 | if (dwKeyIndex == 0xFFFFFFFF) { | |
150 | if (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE) { | |
151 | *pKey = &(pTable->KeyTable[i].PairwiseKey); | |
152 | return (TRUE); | |
153 | } | |
154 | else { | |
155 | return (FALSE); | |
156 | } | |
157 | } else if (dwKeyIndex < MAX_GROUP_KEY) { | |
158 | if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid == TRUE) { | |
159 | *pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex]); | |
160 | return (TRUE); | |
161 | } | |
162 | else { | |
163 | return (FALSE); | |
164 | } | |
165 | } | |
166 | else { | |
167 | return (FALSE); | |
168 | } | |
169 | } | |
170 | } | |
171 | return (FALSE); | |
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 | * | |
189 | * Return Value: TRUE if success otherwise FALSE | |
190 | * | |
191 | */ | |
192 | BOOL KeybSetKey ( | |
193 | PSKeyManagement pTable, | |
194 | PBYTE pbyBSSID, | |
195 | DWORD dwKeyIndex, | |
196 | ULONG uKeyLength, | |
197 | PQWORD pKeyRSC, | |
198 | PBYTE pbyKey, | |
199 | BYTE byKeyDecMode, | |
200 | DWORD_PTR dwIoBase, | |
201 | BYTE byLocalID | |
202 | ) | |
203 | { | |
204 | int i,j; | |
205 | UINT ii; | |
206 | PSKeyItem pKey; | |
207 | UINT uKeyIdx; | |
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++) { | |
213 | if ((pTable->KeyTable[i].bInUse == FALSE) && | |
214 | (j == (MAX_KEY_TABLE-1))) { | |
215 | // found empty table | |
216 | j = i; | |
217 | } | |
218 | if ((pTable->KeyTable[i].bInUse == TRUE) && | |
219 | IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) { | |
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) | |
230 | return (FALSE); | |
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 | ||
244 | pKey->bKeyValid = TRUE; | |
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 | } | |
255 | MACvSetKeyEntry(dwIoBase, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey, byLocalID); | |
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 FB |
279 | |
280 | return (TRUE); | |
281 | } | |
282 | } | |
283 | if (j < (MAX_KEY_TABLE-1)) { | |
078b078f | 284 | memcpy(pTable->KeyTable[j].abyBSSID,pbyBSSID,ETH_ALEN); |
5449c685 FB |
285 | pTable->KeyTable[j].bInUse = TRUE; |
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) | |
295 | return (FALSE); | |
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 | ||
309 | pKey->bKeyValid = TRUE; | |
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 | } | |
320 | MACvSetKeyEntry(dwIoBase, pTable->KeyTable[j].wKeyCtl, j, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey, byLocalID); | |
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 FB |
344 | |
345 | return (TRUE); | |
346 | } | |
347 | return (FALSE); | |
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 | * | |
362 | * Return Value: TRUE if success otherwise FALSE | |
363 | * | |
364 | */ | |
365 | BOOL KeybRemoveKey ( | |
366 | PSKeyManagement pTable, | |
367 | PBYTE pbyBSSID, | |
368 | DWORD dwKeyIndex, | |
369 | DWORD_PTR dwIoBase | |
370 | ) | |
371 | { | |
372 | int i; | |
373 | ||
ca9e12ac | 374 | if (is_broadcast_ether_addr(pbyBSSID)) { |
5449c685 FB |
375 | // dealte all key |
376 | if ((dwKeyIndex & PAIRWISE_KEY) != 0) { | |
377 | for (i=0;i<MAX_KEY_TABLE;i++) { | |
378 | pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE; | |
379 | } | |
380 | s_vCheckKeyTableValid(pTable, dwIoBase); | |
381 | return TRUE; | |
382 | } | |
383 | else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { | |
384 | for (i=0;i<MAX_KEY_TABLE;i++) { | |
385 | pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE; | |
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); | |
392 | return TRUE; | |
393 | } | |
394 | else { | |
395 | return FALSE; | |
396 | } | |
397 | } | |
398 | ||
399 | for (i=0;i<MAX_KEY_TABLE;i++) { | |
400 | if ((pTable->KeyTable[i].bInUse == TRUE) && | |
401 | IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) { | |
402 | if ((dwKeyIndex & PAIRWISE_KEY) != 0) { | |
403 | pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE; | |
404 | s_vCheckKeyTableValid(pTable, dwIoBase); | |
405 | return (TRUE); | |
406 | } | |
407 | else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { | |
408 | pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE; | |
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); | |
414 | return (TRUE); | |
415 | } | |
416 | else { | |
417 | return (FALSE); | |
418 | } | |
419 | } | |
420 | } | |
421 | return (FALSE); | |
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 | * | |
435 | * Return Value: TRUE if success otherwise FALSE | |
436 | * | |
437 | */ | |
438 | BOOL KeybRemoveAllKey ( | |
439 | PSKeyManagement pTable, | |
440 | PBYTE pbyBSSID, | |
441 | DWORD_PTR dwIoBase | |
442 | ) | |
443 | { | |
444 | int i,u; | |
445 | ||
446 | for (i=0;i<MAX_KEY_TABLE;i++) { | |
447 | if ((pTable->KeyTable[i].bInUse == TRUE) && | |
448 | IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) { | |
449 | pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE; | |
450 | for(u=0;u<MAX_GROUP_KEY;u++) { | |
451 | pTable->KeyTable[i].GroupKey[u].bKeyValid = FALSE; | |
452 | } | |
453 | pTable->KeyTable[i].dwGTKeyIndex = 0; | |
454 | s_vCheckKeyTableValid(pTable, dwIoBase); | |
455 | return (TRUE); | |
456 | } | |
457 | } | |
458 | return (FALSE); | |
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 | * | |
470 | * Return Value: TRUE if success otherwise FALSE | |
471 | * | |
472 | */ | |
6b35b7b3 | 473 | void KeyvRemoveWEPKey ( |
5449c685 FB |
474 | PSKeyManagement pTable, |
475 | DWORD dwKeyIndex, | |
476 | DWORD_PTR dwIoBase | |
477 | ) | |
478 | { | |
479 | ||
480 | if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { | |
481 | if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == TRUE) { | |
482 | if (pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].byCipherSuite == KEY_CTL_WEP) { | |
483 | pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE; | |
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 | 495 | void KeyvRemoveAllWEPKey ( |
5449c685 FB |
496 | PSKeyManagement pTable, |
497 | DWORD_PTR dwIoBase | |
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 | * | |
517 | * Return Value: TRUE if found otherwise FALSE | |
518 | * | |
519 | */ | |
520 | BOOL KeybGetTransmitKey ( | |
3a215e0f CC |
521 | PSKeyManagement pTable, |
522 | PBYTE pbyBSSID, | |
523 | DWORD 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++) { | |
531 | if ((pTable->KeyTable[i].bInUse == TRUE) && | |
532 | IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) { | |
533 | ||
534 | if (dwKeyType == PAIRWISE_KEY) { | |
535 | ||
536 | if (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE) { | |
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 | ||
547 | return (TRUE); | |
548 | } | |
549 | else { | |
7e809a9b | 550 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PairwiseKey.bKeyValid == FALSE\n"); |
5449c685 FB |
551 | return (FALSE); |
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"); |
5449c685 FB |
557 | return FALSE; |
558 | } | |
559 | if (pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)].bKeyValid == TRUE) { | |
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 FB |
569 | |
570 | return (TRUE); | |
571 | } | |
572 | else { | |
7e809a9b | 573 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GroupKey.bKeyValid == FALSE\n"); |
5449c685 FB |
574 | return (FALSE); |
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"); |
5449c685 FB |
584 | return (FALSE); |
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 | * | |
597 | * Return Value: TRUE if found otherwise FALSE | |
598 | * | |
599 | */ | |
600 | BOOL 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++) { | |
609 | if ((pTable->KeyTable[i].bInUse == TRUE) && | |
610 | (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE)) { | |
611 | *pKey = &(pTable->KeyTable[i].PairwiseKey); | |
612 | return (TRUE); | |
613 | } | |
614 | } | |
615 | return (FALSE); | |
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 | * | |
631 | * Return Value: TRUE if success otherwise FALSE | |
632 | * | |
633 | */ | |
634 | BOOL KeybSetDefaultKey ( | |
635 | PSKeyManagement pTable, | |
636 | DWORD dwKeyIndex, | |
637 | ULONG uKeyLength, | |
638 | PQWORD pKeyRSC, | |
639 | PBYTE pbyKey, | |
640 | BYTE byKeyDecMode, | |
641 | DWORD_PTR dwIoBase, | |
642 | BYTE byLocalID | |
643 | ) | |
644 | { | |
645 | UINT ii; | |
646 | PSKeyItem pKey; | |
647 | UINT uKeyIdx; | |
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 | |
653 | return (FALSE); | |
654 | } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) { | |
655 | return (FALSE); | |
656 | } | |
657 | ||
658 | pTable->KeyTable[MAX_KEY_TABLE-1].bInUse = TRUE; | |
078b078f | 659 | for(ii=0;ii<ETH_ALEN;ii++) |
5449c685 FB |
660 | pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID[ii] = 0xFF; |
661 | ||
662 | // Group key | |
663 | pKey = &(pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF]); | |
664 | if ((dwKeyIndex & TRANSMIT_KEY) != 0) { | |
665 | // Group transmit key | |
666 | pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = dwKeyIndex; | |
7e809a9b | 667 | 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 |
668 | |
669 | } | |
670 | pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl &= 0x7F00; // clear all key control filed | |
671 | pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode << 4); | |
672 | pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode); | |
673 | pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x0044; // use group key for all address | |
674 | uKeyIdx = (dwKeyIndex & 0x000000FF); | |
675 | ||
676 | if ((uKeyLength == WLAN_WEP232_KEYLEN) && | |
677 | (byKeyDecMode == KEY_CTL_WEP)) { | |
678 | pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x4000; // disable on-fly disable address match | |
679 | pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP = TRUE; | |
680 | } else { | |
681 | if (pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP == FALSE) | |
682 | pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0xC000; // enable on-fly disable address match | |
683 | } | |
684 | ||
685 | pKey->bKeyValid = TRUE; | |
686 | pKey->uKeyLength = uKeyLength; | |
687 | pKey->dwKeyIndex = dwKeyIndex; | |
688 | pKey->byCipherSuite = byKeyDecMode; | |
51b6d9c2 | 689 | memcpy(pKey->abyKey, pbyKey, uKeyLength); |
5449c685 FB |
690 | if (byKeyDecMode == KEY_CTL_WEP) { |
691 | if (uKeyLength == WLAN_WEP40_KEYLEN) | |
692 | pKey->abyKey[15] &= 0x7F; | |
693 | if (uKeyLength == WLAN_WEP104_KEYLEN) | |
694 | pKey->abyKey[15] |= 0x80; | |
695 | } | |
696 | MACvSetKeyEntry(dwIoBase, pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl, MAX_KEY_TABLE-1, uKeyIdx, pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID, (PDWORD)pKey->abyKey, byLocalID); | |
697 | ||
698 | if ((dwKeyIndex & USE_KEYRSC) == 0) { | |
699 | // RSC set by NIC | |
51b6d9c2 | 700 | memset(&(pKey->KeyRSC), 0, sizeof(QWORD)); |
5449c685 | 701 | } else { |
51b6d9c2 | 702 | memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD)); |
5449c685 FB |
703 | } |
704 | pKey->dwTSC47_16 = 0; | |
705 | pKey->wTSC15_0 = 0; | |
706 | ||
707 | ||
7e809a9b JL |
708 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n"); |
709 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n", pKey->bKeyValid); | |
710 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n", (int)pKey->uKeyLength); | |
711 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: \n"); | |
5449c685 | 712 | for (ii = 0; ii < pKey->uKeyLength; ii++) { |
7e809a9b | 713 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x", pKey->abyKey[ii]); |
5449c685 | 714 | } |
7e809a9b | 715 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n"); |
5449c685 | 716 | |
7e809a9b JL |
717 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n", pKey->dwTSC47_16); |
718 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n", pKey->wTSC15_0); | |
719 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n", pKey->dwKeyIndex); | |
5449c685 FB |
720 | |
721 | return (TRUE); | |
722 | } | |
723 | ||
724 | ||
725 | /* | |
726 | * Description: Set Key to table | |
727 | * | |
728 | * Parameters: | |
729 | * In: | |
730 | * pTable - Pointer to Key table | |
731 | * dwKeyIndex - Key index (reference to NDIS DDK) | |
732 | * uKeyLength - Key length | |
733 | * KeyRSC - Key RSC | |
734 | * pbyKey - Pointer to key | |
735 | * Out: | |
736 | * none | |
737 | * | |
738 | * Return Value: TRUE if success otherwise FALSE | |
739 | * | |
740 | */ | |
741 | BOOL KeybSetAllGroupKey ( | |
742 | PSKeyManagement pTable, | |
743 | DWORD dwKeyIndex, | |
744 | ULONG uKeyLength, | |
745 | PQWORD pKeyRSC, | |
746 | PBYTE pbyKey, | |
747 | BYTE byKeyDecMode, | |
748 | DWORD_PTR dwIoBase, | |
749 | BYTE byLocalID | |
750 | ) | |
751 | { | |
752 | int i; | |
753 | UINT ii; | |
754 | PSKeyItem pKey; | |
755 | UINT uKeyIdx; | |
756 | ||
7e809a9b | 757 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetAllGroupKey: %lX\n", dwKeyIndex); |
5449c685 FB |
758 | |
759 | ||
760 | if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key | |
761 | return (FALSE); | |
762 | } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) { | |
763 | return (FALSE); | |
764 | } | |
765 | ||
766 | for (i=0; i < MAX_KEY_TABLE-1; i++) { | |
767 | if (pTable->KeyTable[i].bInUse == TRUE) { | |
768 | // found table already exist | |
769 | // Group key | |
770 | pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]); | |
771 | if ((dwKeyIndex & TRANSMIT_KEY) != 0) { | |
772 | // Group transmit key | |
773 | pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex; | |
7e809a9b | 774 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i); |
5449c685 FB |
775 | |
776 | } | |
777 | pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed | |
778 | pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4); | |
779 | pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address | |
780 | uKeyIdx = (dwKeyIndex & 0x000000FF); | |
781 | ||
782 | pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly | |
783 | ||
784 | pKey->bKeyValid = TRUE; | |
785 | pKey->uKeyLength = uKeyLength; | |
786 | pKey->dwKeyIndex = dwKeyIndex; | |
787 | pKey->byCipherSuite = byKeyDecMode; | |
51b6d9c2 | 788 | memcpy(pKey->abyKey, pbyKey, uKeyLength); |
5449c685 FB |
789 | if (byKeyDecMode == KEY_CTL_WEP) { |
790 | if (uKeyLength == WLAN_WEP40_KEYLEN) | |
791 | pKey->abyKey[15] &= 0x7F; | |
792 | if (uKeyLength == WLAN_WEP104_KEYLEN) | |
793 | pKey->abyKey[15] |= 0x80; | |
794 | } | |
795 | MACvSetKeyEntry(dwIoBase, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pTable->KeyTable[i].abyBSSID, (PDWORD)pKey->abyKey, byLocalID); | |
796 | ||
797 | if ((dwKeyIndex & USE_KEYRSC) == 0) { | |
798 | // RSC set by NIC | |
51b6d9c2 | 799 | memset(&(pKey->KeyRSC), 0, sizeof(QWORD)); |
5449c685 FB |
800 | } |
801 | else { | |
51b6d9c2 | 802 | memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD)); |
5449c685 FB |
803 | } |
804 | pKey->dwTSC47_16 = 0; | |
805 | pKey->wTSC15_0 = 0; | |
806 | ||
7e809a9b JL |
807 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n"); |
808 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid); | |
809 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength); | |
810 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: "); | |
5449c685 | 811 | for (ii = 0; ii < pKey->uKeyLength; ii++) { |
7e809a9b | 812 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", pKey->abyKey[ii]); |
5449c685 | 813 | } |
7e809a9b | 814 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n"); |
5449c685 FB |
815 | |
816 | //DBG_PRN_GRP12(("pKey->dwTSC47_16: %lX\n ", pKey->dwTSC47_16)); | |
817 | //DBG_PRN_GRP12(("pKey->wTSC15_0: %X\n ", pKey->wTSC15_0)); | |
818 | //DBG_PRN_GRP12(("pKey->dwKeyIndex: %lX\n ", pKey->dwKeyIndex)); | |
819 | ||
820 | } // (pTable->KeyTable[i].bInUse == TRUE) | |
821 | } | |
822 | return (TRUE); | |
823 | } |