Commit | Line | Data |
---|---|---|
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 | * File: hostap.c | |
20 | * | |
21 | * Purpose: handle hostap deamon ioctl input/out functions | |
22 | * | |
23 | * Author: Lyndon Chen | |
24 | * | |
25 | * Date: Oct. 20, 2003 | |
26 | * | |
27 | * Functions: | |
28 | * | |
29 | * Revision History: | |
30 | * | |
31 | */ | |
32 | ||
92b96797 | 33 | #include "hostap.h" |
92b96797 | 34 | #include "iocmd.h" |
92b96797 | 35 | #include "mac.h" |
92b96797 | 36 | #include "card.h" |
92b96797 | 37 | #include "baseband.h" |
92b96797 | 38 | #include "wpactl.h" |
92b96797 | 39 | #include "key.h" |
92b96797 | 40 | #include "mac.h" |
92b96797 | 41 | #include "datarate.h" |
92b96797 FB |
42 | |
43 | #define VIAWGET_HOSTAPD_MAX_BUF_SIZE 1024 | |
44 | #define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT0 | |
45 | #define HOSTAP_CRYPT_FLAG_PERMANENT BIT1 | |
46 | #define HOSTAP_CRYPT_ERR_UNKNOWN_ALG 2 | |
47 | #define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3 | |
48 | #define HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED 4 | |
49 | #define HOSTAP_CRYPT_ERR_KEY_SET_FAILED 5 | |
50 | #define HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED 6 | |
51 | #define HOSTAP_CRYPT_ERR_CARD_CONF_FAILED 7 | |
52 | ||
53 | ||
54 | /*--------------------- Static Definitions -------------------------*/ | |
55 | ||
56 | /*--------------------- Static Classes ----------------------------*/ | |
57 | ||
58 | /*--------------------- Static Variables --------------------------*/ | |
59 | //static int msglevel =MSG_LEVEL_DEBUG; | |
60 | static int msglevel =MSG_LEVEL_INFO; | |
61 | ||
62 | /*--------------------- Static Functions --------------------------*/ | |
63 | ||
64 | ||
65 | ||
66 | ||
67 | /*--------------------- Export Variables --------------------------*/ | |
68 | ||
69 | ||
70 | /* | |
71 | * Description: | |
72 | * register net_device (AP) for hostap deamon | |
73 | * | |
74 | * Parameters: | |
75 | * In: | |
76 | * pDevice - | |
77 | * rtnl_locked - | |
78 | * Out: | |
79 | * | |
80 | * Return Value: | |
81 | * | |
82 | */ | |
83 | ||
84 | static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked) | |
85 | { | |
1e28efa3 | 86 | PSDevice apdev_priv; |
92b96797 FB |
87 | struct net_device *dev = pDevice->dev; |
88 | int ret; | |
d899d403 JL |
89 | const struct net_device_ops apdev_netdev_ops = { |
90 | .ndo_start_xmit = pDevice->tx_80211, | |
91 | }; | |
92b96797 FB |
92 | |
93 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name); | |
94 | ||
95 | pDevice->apdev = (struct net_device *)kmalloc(sizeof(struct net_device), GFP_KERNEL); | |
77f58b13 | 96 | if (pDevice->apdev == NULL) |
92b96797 FB |
97 | return -ENOMEM; |
98 | memset(pDevice->apdev, 0, sizeof(struct net_device)); | |
99 | ||
1e28efa3 FB |
100 | apdev_priv = netdev_priv(pDevice->apdev); |
101 | *apdev_priv = *pDevice; | |
92b96797 | 102 | memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN); |
dd8db704 | 103 | |
dd8db704 FB |
104 | pDevice->apdev->netdev_ops = &apdev_netdev_ops; |
105 | ||
92b96797 FB |
106 | pDevice->apdev->type = ARPHRD_IEEE80211; |
107 | ||
108 | pDevice->apdev->base_addr = dev->base_addr; | |
109 | pDevice->apdev->irq = dev->irq; | |
110 | pDevice->apdev->mem_start = dev->mem_start; | |
111 | pDevice->apdev->mem_end = dev->mem_end; | |
112 | sprintf(pDevice->apdev->name, "%sap", dev->name); | |
113 | if (rtnl_locked) | |
114 | ret = register_netdevice(pDevice->apdev); | |
115 | else | |
116 | ret = register_netdev(pDevice->apdev); | |
117 | if (ret) { | |
118 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdevice(AP) failed!\n", | |
119 | dev->name); | |
120 | return -1; | |
121 | } | |
122 | ||
123 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdevice %s for AP management\n", | |
124 | dev->name, pDevice->apdev->name); | |
125 | ||
126 | KeyvInitTable(pDevice,&pDevice->sKey); | |
127 | ||
128 | return 0; | |
129 | } | |
130 | ||
131 | /* | |
132 | * Description: | |
133 | * unregister net_device(AP) | |
134 | * | |
135 | * Parameters: | |
136 | * In: | |
137 | * pDevice - | |
138 | * rtnl_locked - | |
139 | * Out: | |
140 | * | |
141 | * Return Value: | |
142 | * | |
143 | */ | |
144 | ||
145 | static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked) | |
146 | { | |
147 | ||
148 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name); | |
149 | ||
150 | if (pDevice->apdev && pDevice->apdev->name && pDevice->apdev->name[0]) { | |
151 | if (rtnl_locked) | |
152 | unregister_netdevice(pDevice->apdev); | |
153 | else | |
154 | unregister_netdev(pDevice->apdev); | |
155 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n", | |
156 | pDevice->dev->name, pDevice->apdev->name); | |
157 | } | |
158 | kfree(pDevice->apdev); | |
159 | pDevice->apdev = NULL; | |
160 | pDevice->bEnable8021x = FALSE; | |
161 | pDevice->bEnableHostWEP = FALSE; | |
162 | pDevice->bEncryptionEnable = FALSE; | |
163 | ||
164 | return 0; | |
165 | } | |
166 | ||
167 | ||
168 | /* | |
169 | * Description: | |
170 | * Set enable/disable hostapd mode | |
171 | * | |
172 | * Parameters: | |
173 | * In: | |
174 | * pDevice - | |
175 | * rtnl_locked - | |
176 | * Out: | |
177 | * | |
178 | * Return Value: | |
179 | * | |
180 | */ | |
181 | ||
182 | int hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked) | |
183 | { | |
184 | if (val < 0 || val > 1) | |
185 | return -EINVAL; | |
186 | ||
187 | if (pDevice->bEnableHostapd == val) | |
188 | return 0; | |
189 | ||
190 | pDevice->bEnableHostapd = val; | |
191 | ||
192 | if (val) | |
193 | return hostap_enable_hostapd(pDevice, rtnl_locked); | |
194 | else | |
195 | return hostap_disable_hostapd(pDevice, rtnl_locked); | |
196 | } | |
197 | ||
198 | ||
199 | /* | |
200 | * Description: | |
201 | * remove station function supported for hostap deamon | |
202 | * | |
203 | * Parameters: | |
204 | * In: | |
205 | * pDevice - | |
206 | * param - | |
207 | * Out: | |
208 | * | |
209 | * Return Value: | |
210 | * | |
211 | */ | |
212 | static int hostap_remove_sta(PSDevice pDevice, | |
213 | struct viawget_hostapd_param *param) | |
214 | { | |
215 | UINT uNodeIndex; | |
216 | ||
217 | ||
218 | if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) { | |
219 | BSSvRemoveOneNode(pDevice, uNodeIndex); | |
220 | } | |
221 | else { | |
222 | return -ENOENT; | |
223 | } | |
224 | return 0; | |
225 | } | |
226 | ||
227 | /* | |
228 | * Description: | |
229 | * add a station from hostap deamon | |
230 | * | |
231 | * Parameters: | |
232 | * In: | |
233 | * pDevice - | |
234 | * param - | |
235 | * Out: | |
236 | * | |
237 | * Return Value: | |
238 | * | |
239 | */ | |
240 | static int hostap_add_sta(PSDevice pDevice, | |
241 | struct viawget_hostapd_param *param) | |
242 | { | |
243 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); | |
244 | UINT uNodeIndex; | |
245 | ||
246 | ||
247 | if (!BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) { | |
248 | BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex); | |
249 | } | |
250 | memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, param->sta_addr, WLAN_ADDR_LEN); | |
251 | pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC; | |
252 | pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = param->u.add_sta.capability; | |
253 | // TODO listenInterval | |
254 | // pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = 1; | |
255 | pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = FALSE; | |
256 | pMgmt->sNodeDBTable[uNodeIndex].bySuppRate = param->u.add_sta.tx_supp_rates; | |
257 | ||
258 | // set max tx rate | |
259 | pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate = | |
260 | pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate; | |
261 | // set max basic rate | |
262 | pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate = RATE_2M; | |
263 | // Todo: check sta preamble, if ap can't support, set status code | |
264 | pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = | |
265 | WLAN_GET_CAP_INFO_SHORTPREAMBLE(pMgmt->sNodeDBTable[uNodeIndex].wCapInfo); | |
266 | ||
267 | pMgmt->sNodeDBTable[uNodeIndex].wAID = (WORD)param->u.add_sta.aid; | |
268 | ||
269 | pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer = jiffies; | |
270 | ||
271 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Add STA AID= %d \n", pMgmt->sNodeDBTable[uNodeIndex].wAID); | |
272 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n", | |
273 | param->sta_addr[0], | |
274 | param->sta_addr[1], | |
275 | param->sta_addr[2], | |
276 | param->sta_addr[3], | |
277 | param->sta_addr[4], | |
278 | param->sta_addr[5] | |
279 | ) ; | |
280 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Max Support rate = %d \n", | |
281 | pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate); | |
282 | ||
283 | return 0; | |
284 | } | |
285 | ||
286 | /* | |
287 | * Description: | |
288 | * get station info | |
289 | * | |
290 | * Parameters: | |
291 | * In: | |
292 | * pDevice - | |
293 | * param - | |
294 | * Out: | |
295 | * | |
296 | * Return Value: | |
297 | * | |
298 | */ | |
299 | ||
300 | static int hostap_get_info_sta(PSDevice pDevice, | |
301 | struct viawget_hostapd_param *param) | |
302 | { | |
303 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); | |
304 | UINT uNodeIndex; | |
305 | ||
306 | if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) { | |
307 | param->u.get_info_sta.inactive_sec = | |
308 | (jiffies - pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer) / HZ; | |
309 | ||
310 | //param->u.get_info_sta.txexc = pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts; | |
311 | } | |
312 | else { | |
313 | return -ENOENT; | |
314 | } | |
315 | ||
316 | return 0; | |
317 | } | |
318 | ||
319 | /* | |
320 | * Description: | |
321 | * reset txexec | |
322 | * | |
323 | * Parameters: | |
324 | * In: | |
325 | * pDevice - | |
326 | * param - | |
327 | * Out: | |
328 | * TURE, FALSE | |
329 | * | |
330 | * Return Value: | |
331 | * | |
332 | */ | |
333 | /* | |
334 | static int hostap_reset_txexc_sta(PSDevice pDevice, | |
335 | struct viawget_hostapd_param *param) | |
336 | { | |
337 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); | |
338 | UINT uNodeIndex; | |
339 | ||
340 | if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) { | |
341 | pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts = 0; | |
342 | } | |
343 | else { | |
344 | return -ENOENT; | |
345 | } | |
346 | ||
347 | return 0; | |
348 | } | |
349 | */ | |
350 | ||
351 | /* | |
352 | * Description: | |
353 | * set station flag | |
354 | * | |
355 | * Parameters: | |
356 | * In: | |
357 | * pDevice - | |
358 | * param - | |
359 | * Out: | |
360 | * | |
361 | * Return Value: | |
362 | * | |
363 | */ | |
364 | static int hostap_set_flags_sta(PSDevice pDevice, | |
365 | struct viawget_hostapd_param *param) | |
366 | { | |
367 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); | |
368 | UINT uNodeIndex; | |
369 | ||
370 | if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) { | |
371 | pMgmt->sNodeDBTable[uNodeIndex].dwFlags |= param->u.set_flags_sta.flags_or; | |
372 | pMgmt->sNodeDBTable[uNodeIndex].dwFlags &= param->u.set_flags_sta.flags_and; | |
373 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " dwFlags = %x \n", | |
374 | (UINT)pMgmt->sNodeDBTable[uNodeIndex].dwFlags); | |
375 | } | |
376 | else { | |
377 | return -ENOENT; | |
378 | } | |
379 | ||
380 | return 0; | |
381 | } | |
382 | ||
383 | ||
384 | ||
385 | /* | |
386 | * Description: | |
387 | * set generic element (wpa ie) | |
388 | * | |
389 | * Parameters: | |
390 | * In: | |
391 | * pDevice - | |
392 | * param - | |
393 | * Out: | |
394 | * | |
395 | * Return Value: | |
396 | * | |
397 | */ | |
398 | static int hostap_set_generic_element(PSDevice pDevice, | |
399 | struct viawget_hostapd_param *param) | |
400 | { | |
401 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); | |
402 | ||
403 | ||
404 | ||
405 | memcpy( pMgmt->abyWPAIE, | |
406 | param->u.generic_elem.data, | |
407 | param->u.generic_elem.len | |
408 | ); | |
409 | ||
410 | pMgmt->wWPAIELen = param->u.generic_elem.len; | |
411 | ||
412 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pMgmt->wWPAIELen = %d\n", pMgmt->wWPAIELen); | |
413 | ||
414 | // disable wpa | |
415 | if (pMgmt->wWPAIELen == 0) { | |
416 | pMgmt->eAuthenMode = WMAC_AUTH_OPEN; | |
417 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " No WPAIE, Disable WPA \n"); | |
418 | } else { | |
419 | // enable wpa | |
420 | if ((pMgmt->abyWPAIE[0] == WLAN_EID_RSN_WPA) || | |
421 | (pMgmt->abyWPAIE[0] == WLAN_EID_RSN)) { | |
422 | pMgmt->eAuthenMode = WMAC_AUTH_WPANONE; | |
423 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set WPAIE enable WPA\n"); | |
424 | } else | |
425 | return -EINVAL; | |
426 | } | |
427 | ||
428 | return 0; | |
429 | } | |
430 | ||
431 | /* | |
432 | * Description: | |
433 | * flush station nodes table. | |
434 | * | |
435 | * Parameters: | |
436 | * In: | |
437 | * pDevice - | |
438 | * Out: | |
439 | * | |
440 | * Return Value: | |
441 | * | |
442 | */ | |
443 | ||
444 | static void hostap_flush_sta(PSDevice pDevice) | |
445 | { | |
446 | // reserved node index =0 for multicast node. | |
447 | BSSvClearNodeDBTable(pDevice, 1); | |
448 | pDevice->uAssocCount = 0; | |
449 | ||
450 | return; | |
451 | } | |
452 | ||
453 | /* | |
454 | * Description: | |
455 | * set each stations encryption key | |
456 | * | |
457 | * Parameters: | |
458 | * In: | |
459 | * pDevice - | |
460 | * param - | |
461 | * Out: | |
462 | * | |
463 | * Return Value: | |
464 | * | |
465 | */ | |
466 | static int hostap_set_encryption(PSDevice pDevice, | |
467 | struct viawget_hostapd_param *param, | |
468 | int param_len) | |
469 | { | |
470 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); | |
471 | DWORD dwKeyIndex = 0; | |
472 | BYTE abyKey[MAX_KEY_LEN]; | |
473 | BYTE abySeq[MAX_KEY_LEN]; | |
474 | NDIS_802_11_KEY_RSC KeyRSC; | |
475 | BYTE byKeyDecMode = KEY_CTL_WEP; | |
476 | int ret = 0; | |
477 | int iNodeIndex = -1; | |
478 | int ii; | |
479 | BOOL bKeyTableFull = FALSE; | |
480 | WORD wKeyCtl = 0; | |
481 | ||
482 | ||
483 | param->u.crypt.err = 0; | |
484 | /* | |
485 | if (param_len != | |
486 | (int) ((char *) param->u.crypt.key - (char *) param) + | |
487 | param->u.crypt.key_len) | |
488 | return -EINVAL; | |
489 | */ | |
490 | ||
491 | if (param->u.crypt.alg > WPA_ALG_CCMP) | |
492 | return -EINVAL; | |
493 | ||
494 | ||
495 | if ((param->u.crypt.idx > 3) || (param->u.crypt.key_len > MAX_KEY_LEN)) { | |
496 | param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED; | |
497 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_KEY_SET_FAILED\n"); | |
498 | return -EINVAL; | |
499 | } | |
500 | ||
501 | if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff && | |
502 | param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && | |
503 | param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) { | |
504 | if (param->u.crypt.idx >= MAX_GROUP_KEY) | |
505 | return -EINVAL; | |
506 | iNodeIndex = 0; | |
507 | ||
508 | } else { | |
509 | if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == FALSE) { | |
510 | param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR; | |
511 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n"); | |
512 | return -EINVAL; | |
513 | } | |
514 | } | |
515 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: sta_index %d \n", iNodeIndex); | |
516 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: alg %d \n", param->u.crypt.alg); | |
517 | ||
518 | if (param->u.crypt.alg == WPA_ALG_NONE) { | |
519 | ||
520 | if (pMgmt->sNodeDBTable[iNodeIndex].bOnFly == TRUE) { | |
521 | if (KeybRemoveKey( pDevice, | |
522 | &(pDevice->sKey), | |
523 | param->sta_addr, | |
524 | pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex | |
525 | ) == FALSE) { | |
526 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybRemoveKey fail \n"); | |
527 | } | |
528 | pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE; | |
529 | } | |
530 | pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = 0; | |
531 | pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = 0; | |
532 | pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = 0; | |
533 | pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = 0; | |
534 | pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0; | |
535 | pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0; | |
536 | pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = 0; | |
537 | memset(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0], | |
538 | 0, | |
539 | MAX_KEY_LEN | |
540 | ); | |
541 | ||
542 | return ret; | |
543 | } | |
544 | ||
545 | memcpy(abyKey, param->u.crypt.key, param->u.crypt.key_len); | |
546 | // copy to node key tbl | |
547 | pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = param->u.crypt.idx; | |
548 | pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = param->u.crypt.key_len; | |
549 | memcpy(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0], | |
550 | param->u.crypt.key, | |
551 | param->u.crypt.key_len | |
552 | ); | |
553 | ||
554 | dwKeyIndex = (DWORD)(param->u.crypt.idx); | |
555 | if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) { | |
556 | pDevice->byKeyIndex = (BYTE)dwKeyIndex; | |
557 | pDevice->bTransmitKey = TRUE; | |
558 | dwKeyIndex |= (1 << 31); | |
559 | } | |
560 | ||
561 | if (param->u.crypt.alg == WPA_ALG_WEP) { | |
562 | ||
563 | if ((pDevice->bEnable8021x == FALSE) || (iNodeIndex == 0)) { | |
564 | KeybSetDefaultKey( pDevice, | |
565 | &(pDevice->sKey), | |
566 | dwKeyIndex & ~(BIT30 | USE_KEYRSC), | |
567 | param->u.crypt.key_len, | |
568 | NULL, | |
569 | abyKey, | |
570 | KEY_CTL_WEP | |
571 | ); | |
572 | ||
573 | } else { | |
574 | // 8021x enable, individual key | |
575 | dwKeyIndex |= (1 << 30); // set pairwise key | |
576 | if (KeybSetKey(pDevice, | |
577 | &(pDevice->sKey), | |
578 | ¶m->sta_addr[0], | |
579 | dwKeyIndex & ~(USE_KEYRSC), | |
580 | param->u.crypt.key_len, | |
581 | (PQWORD) &(KeyRSC), | |
582 | (PBYTE)abyKey, | |
583 | KEY_CTL_WEP | |
584 | ) == TRUE) { | |
585 | ||
586 | ||
587 | pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE; | |
588 | ||
589 | } else { | |
590 | // Key Table Full | |
591 | pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE; | |
592 | bKeyTableFull = TRUE; | |
593 | } | |
594 | } | |
595 | pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; | |
596 | pDevice->bEncryptionEnable = TRUE; | |
597 | pMgmt->byCSSPK = KEY_CTL_WEP; | |
598 | pMgmt->byCSSGK = KEY_CTL_WEP; | |
599 | pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = KEY_CTL_WEP; | |
600 | pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex; | |
601 | return ret; | |
602 | } | |
603 | ||
604 | if (param->u.crypt.seq) { | |
605 | memcpy(&abySeq, param->u.crypt.seq, 8); | |
606 | for (ii = 0 ; ii < 8 ; ii++) { | |
607 | KeyRSC |= (abySeq[ii] << (ii * 8)); | |
608 | } | |
609 | dwKeyIndex |= 1 << 29; | |
610 | pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = KeyRSC; | |
611 | } | |
612 | ||
613 | if (param->u.crypt.alg == WPA_ALG_TKIP) { | |
614 | if (param->u.crypt.key_len != MAX_KEY_LEN) | |
615 | return -EINVAL; | |
616 | pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; | |
617 | byKeyDecMode = KEY_CTL_TKIP; | |
618 | pMgmt->byCSSPK = KEY_CTL_TKIP; | |
619 | pMgmt->byCSSGK = KEY_CTL_TKIP; | |
620 | } | |
621 | ||
622 | if (param->u.crypt.alg == WPA_ALG_CCMP) { | |
623 | if ((param->u.crypt.key_len != AES_KEY_LEN) || | |
624 | (pDevice->byLocalID <= REV_ID_VT3253_A1)) | |
625 | return -EINVAL; | |
626 | pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; | |
627 | byKeyDecMode = KEY_CTL_CCMP; | |
628 | pMgmt->byCSSPK = KEY_CTL_CCMP; | |
629 | pMgmt->byCSSGK = KEY_CTL_CCMP; | |
630 | } | |
631 | ||
632 | ||
633 | if (iNodeIndex == 0) { | |
634 | KeybSetDefaultKey( pDevice, | |
635 | &(pDevice->sKey), | |
636 | dwKeyIndex, | |
637 | param->u.crypt.key_len, | |
638 | (PQWORD) &(KeyRSC), | |
639 | abyKey, | |
640 | byKeyDecMode | |
641 | ); | |
642 | pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE; | |
643 | ||
644 | } else { | |
645 | dwKeyIndex |= (1 << 30); // set pairwise key | |
646 | if (KeybSetKey(pDevice, | |
647 | &(pDevice->sKey), | |
648 | ¶m->sta_addr[0], | |
649 | dwKeyIndex, | |
650 | param->u.crypt.key_len, | |
651 | (PQWORD) &(KeyRSC), | |
652 | (PBYTE)abyKey, | |
653 | byKeyDecMode | |
654 | ) == TRUE) { | |
655 | ||
656 | pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE; | |
657 | ||
658 | } else { | |
659 | // Key Table Full | |
660 | pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE; | |
661 | bKeyTableFull = TRUE; | |
662 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Key Table Full\n"); | |
663 | } | |
664 | ||
665 | } | |
666 | ||
667 | if (bKeyTableFull == TRUE) { | |
668 | wKeyCtl &= 0x7F00; // clear all key control filed | |
669 | wKeyCtl |= (byKeyDecMode << 4); | |
670 | wKeyCtl |= (byKeyDecMode); | |
671 | wKeyCtl |= 0x0044; // use group key for all address | |
672 | wKeyCtl |= 0x4000; // disable KeyTable[MAX_KEY_TABLE-1] on-fly to genernate rx int | |
673 | // Todo.. xxxxxx | |
674 | //MACvSetDefaultKeyCtl(pDevice->PortOffset, wKeyCtl, MAX_KEY_TABLE-1, pDevice->byLocalID); | |
675 | } | |
676 | ||
677 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set key sta_index= %d \n", iNodeIndex); | |
678 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " tx_index=%d len=%d \n", param->u.crypt.idx, | |
679 | param->u.crypt.key_len ); | |
680 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n", | |
681 | pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0], | |
682 | pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[1], | |
683 | pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[2], | |
684 | pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[3], | |
685 | pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[4] | |
686 | ); | |
687 | ||
688 | // set wep key | |
689 | pDevice->bEncryptionEnable = TRUE; | |
690 | pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = byKeyDecMode; | |
691 | pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex; | |
692 | pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0; | |
693 | pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0; | |
694 | ||
695 | return ret; | |
696 | } | |
697 | ||
698 | ||
699 | ||
700 | /* | |
701 | * Description: | |
702 | * get each stations encryption key | |
703 | * | |
704 | * Parameters: | |
705 | * In: | |
706 | * pDevice - | |
707 | * param - | |
708 | * Out: | |
709 | * | |
710 | * Return Value: | |
711 | * | |
712 | */ | |
713 | static int hostap_get_encryption(PSDevice pDevice, | |
714 | struct viawget_hostapd_param *param, | |
715 | int param_len) | |
716 | { | |
717 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); | |
718 | int ret = 0; | |
719 | int ii; | |
720 | int iNodeIndex =0; | |
721 | ||
722 | ||
723 | param->u.crypt.err = 0; | |
724 | ||
725 | if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff && | |
726 | param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && | |
727 | param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) { | |
728 | iNodeIndex = 0; | |
729 | } else { | |
730 | if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == FALSE) { | |
731 | param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR; | |
732 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n"); | |
733 | return -EINVAL; | |
734 | } | |
735 | } | |
736 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: %d\n", iNodeIndex); | |
737 | memset(param->u.crypt.seq, 0, 8); | |
738 | for (ii = 0 ; ii < 8 ; ii++) { | |
739 | param->u.crypt.seq[ii] = (BYTE)pMgmt->sNodeDBTable[iNodeIndex].KeyRSC >> (ii * 8); | |
740 | } | |
741 | ||
742 | return ret; | |
743 | } | |
744 | ||
745 | ||
746 | /* | |
747 | * Description: | |
748 | * hostap_ioctl main function supported for hostap deamon. | |
749 | * | |
750 | * Parameters: | |
751 | * In: | |
752 | * pDevice - | |
753 | * iw_point - | |
754 | * Out: | |
755 | * | |
756 | * Return Value: | |
757 | * | |
758 | */ | |
759 | ||
760 | int hostap_ioctl(PSDevice pDevice, struct iw_point *p) | |
761 | { | |
762 | struct viawget_hostapd_param *param; | |
763 | int ret = 0; | |
764 | int ap_ioctl = 0; | |
765 | ||
766 | if (p->length < sizeof(struct viawget_hostapd_param) || | |
767 | p->length > VIAWGET_HOSTAPD_MAX_BUF_SIZE || !p->pointer) | |
768 | return -EINVAL; | |
769 | ||
770 | param = (struct viawget_hostapd_param *) kmalloc((int)p->length, (int)GFP_KERNEL); | |
771 | if (param == NULL) | |
772 | return -ENOMEM; | |
773 | ||
774 | if (copy_from_user(param, p->pointer, p->length)) { | |
775 | ret = -EFAULT; | |
776 | goto out; | |
777 | } | |
778 | ||
779 | switch (param->cmd) { | |
780 | case VIAWGET_HOSTAPD_SET_ENCRYPTION: | |
781 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ENCRYPTION \n"); | |
782 | spin_lock_irq(&pDevice->lock); | |
783 | ret = hostap_set_encryption(pDevice, param, p->length); | |
784 | spin_unlock_irq(&pDevice->lock); | |
785 | break; | |
786 | case VIAWGET_HOSTAPD_GET_ENCRYPTION: | |
787 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_ENCRYPTION \n"); | |
788 | spin_lock_irq(&pDevice->lock); | |
789 | ret = hostap_get_encryption(pDevice, param, p->length); | |
790 | spin_unlock_irq(&pDevice->lock); | |
791 | break; | |
792 | case VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR: | |
793 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR \n"); | |
794 | return -EOPNOTSUPP; | |
795 | break; | |
796 | case VIAWGET_HOSTAPD_FLUSH: | |
797 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_FLUSH \n"); | |
798 | spin_lock_irq(&pDevice->lock); | |
799 | hostap_flush_sta(pDevice); | |
800 | spin_unlock_irq(&pDevice->lock); | |
801 | break; | |
802 | case VIAWGET_HOSTAPD_ADD_STA: | |
803 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_ADD_STA \n"); | |
804 | spin_lock_irq(&pDevice->lock); | |
805 | ret = hostap_add_sta(pDevice, param); | |
806 | spin_unlock_irq(&pDevice->lock); | |
807 | break; | |
808 | case VIAWGET_HOSTAPD_REMOVE_STA: | |
809 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_REMOVE_STA \n"); | |
810 | spin_lock_irq(&pDevice->lock); | |
811 | ret = hostap_remove_sta(pDevice, param); | |
812 | spin_unlock_irq(&pDevice->lock); | |
813 | break; | |
814 | case VIAWGET_HOSTAPD_GET_INFO_STA: | |
815 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_INFO_STA \n"); | |
816 | ret = hostap_get_info_sta(pDevice, param); | |
817 | ap_ioctl = 1; | |
818 | break; | |
819 | /* | |
820 | case VIAWGET_HOSTAPD_RESET_TXEXC_STA: | |
821 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_RESET_TXEXC_STA \n"); | |
822 | ret = hostap_reset_txexc_sta(pDevice, param); | |
823 | break; | |
824 | */ | |
825 | case VIAWGET_HOSTAPD_SET_FLAGS_STA: | |
826 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_FLAGS_STA \n"); | |
827 | ret = hostap_set_flags_sta(pDevice, param); | |
828 | break; | |
829 | ||
830 | case VIAWGET_HOSTAPD_MLME: | |
831 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_MLME \n"); | |
832 | return -EOPNOTSUPP; | |
833 | ||
834 | case VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT: | |
835 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT \n"); | |
836 | ret = hostap_set_generic_element(pDevice, param); | |
837 | break; | |
838 | ||
839 | case VIAWGET_HOSTAPD_SCAN_REQ: | |
840 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SCAN_REQ \n"); | |
841 | return -EOPNOTSUPP; | |
842 | ||
843 | case VIAWGET_HOSTAPD_STA_CLEAR_STATS: | |
844 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_STA_CLEAR_STATS \n"); | |
845 | return -EOPNOTSUPP; | |
846 | ||
847 | default: | |
848 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_ioctl: unknown cmd=%d\n", | |
849 | (int)param->cmd); | |
850 | return -EOPNOTSUPP; | |
851 | break; | |
852 | } | |
853 | ||
854 | ||
855 | if ((ret == 0) && ap_ioctl) { | |
856 | if (copy_to_user(p->pointer, param, p->length)) { | |
857 | ret = -EFAULT; | |
858 | goto out; | |
859 | } | |
860 | } | |
861 | ||
862 | out: | |
863 | if (param != NULL) | |
864 | kfree(param); | |
865 | ||
866 | return ret; | |
867 | } | |
868 |