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