blob: ee83704e440139d2c0d713512ef3e864584eec20 [file] [log] [blame]
Forest Bond5449c682009-04-25 10:30:44 -04001/*
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 *
Jim Lieb612822f2009-08-12 14:54:03 -070019 *
Forest Bond5449c682009-04-25 10:30:44 -040020 * File: wpactl.c
21 *
22 * Purpose: handle wpa supplicant ioctl input/out functions
23 *
24 * Author: Lyndon Chen
25 *
26 * Date: Oct. 20, 2003
27 *
28 * Functions:
29 *
30 * Revision History:
31 *
32 */
33
Forest Bond5449c682009-04-25 10:30:44 -040034#include "wpactl.h"
Forest Bond5449c682009-04-25 10:30:44 -040035#include "key.h"
Forest Bond5449c682009-04-25 10:30:44 -040036#include "mac.h"
Forest Bond5449c682009-04-25 10:30:44 -040037#include "device.h"
Forest Bond5449c682009-04-25 10:30:44 -040038#include "wmgr.h"
Forest Bond5449c682009-04-25 10:30:44 -040039#include "iocmd.h"
Forest Bond5449c682009-04-25 10:30:44 -040040#include "iowpa.h"
Forest Bond5449c682009-04-25 10:30:44 -040041#include "rf.h"
Forest Bond5449c682009-04-25 10:30:44 -040042
43/*--------------------- Static Definitions -------------------------*/
44
45#define VIAWGET_WPA_MAX_BUF_SIZE 1024
46
Forest Bond5449c682009-04-25 10:30:44 -040047static const int frequency_list[] = {
48 2412, 2417, 2422, 2427, 2432, 2437, 2442,
49 2447, 2452, 2457, 2462, 2467, 2472, 2484
50};
51/*--------------------- Static Classes ----------------------------*/
52
53/*--------------------- Static Variables --------------------------*/
54//static int msglevel =MSG_LEVEL_DEBUG;
Joe Perchesf9cf92b2013-03-18 10:45:14 -070055static int msglevel = MSG_LEVEL_INFO;
Forest Bond5449c682009-04-25 10:30:44 -040056
57/*--------------------- Static Functions --------------------------*/
58
Forest Bond5449c682009-04-25 10:30:44 -040059/*--------------------- Export Variables --------------------------*/
Forest Bond5449c682009-04-25 10:30:44 -040060static void wpadev_setup(struct net_device *dev)
61{
62 dev->type = ARPHRD_IEEE80211;
63 dev->hard_header_len = ETH_HLEN;
64 dev->mtu = 2048;
65 dev->addr_len = ETH_ALEN;
66 dev->tx_queue_len = 1000;
67
Joe Perchesf9cf92b2013-03-18 10:45:14 -070068 memset(dev->broadcast, 0xFF, ETH_ALEN);
Forest Bond5449c682009-04-25 10:30:44 -040069
70 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
71}
72
Forest Bond5449c682009-04-25 10:30:44 -040073/*
74 * Description:
Justin P. Mattock789d1ae2012-08-20 08:43:13 -070075 * register netdev for wpa supplicant daemon
Forest Bond5449c682009-04-25 10:30:44 -040076 *
77 * Parameters:
78 * In:
79 * pDevice -
80 * enable -
81 * Out:
82 *
83 * Return Value:
84 *
85 */
86
87static int wpa_init_wpadev(PSDevice pDevice)
88{
Joe Perchesf9cf92b2013-03-18 10:45:14 -070089 PSDevice wpadev_priv;
Forest Bond5449c682009-04-25 10:30:44 -040090 struct net_device *dev = pDevice->dev;
Joe Perchesf9cf92b2013-03-18 10:45:14 -070091 int ret = 0;
Forest Bond5449c682009-04-25 10:30:44 -040092
Forest Bondc9d03522009-06-01 20:00:14 -040093 pDevice->wpadev = alloc_netdev(sizeof(PSDevice), "vntwpa", wpadev_setup);
Forest Bond5449c682009-04-25 10:30:44 -040094 if (pDevice->wpadev == NULL)
95 return -ENOMEM;
96
Joe Perchesf9cf92b2013-03-18 10:45:14 -070097 wpadev_priv = netdev_priv(pDevice->wpadev);
98 *wpadev_priv = *pDevice;
Bjørn Mork314cb112013-08-30 18:08:52 +020099 eth_hw_addr_inherit(pDevice->wpadev, dev);
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700100 pDevice->wpadev->base_addr = dev->base_addr;
Forest Bond5449c682009-04-25 10:30:44 -0400101 pDevice->wpadev->irq = dev->irq;
102 pDevice->wpadev->mem_start = dev->mem_start;
103 pDevice->wpadev->mem_end = dev->mem_end;
104 ret = register_netdev(pDevice->wpadev);
105 if (ret) {
Jim Lieb7e809a92009-07-30 10:27:21 -0700106 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdev(WPA) failed!\n",
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700107 dev->name);
Forest Bond5449c682009-04-25 10:30:44 -0400108 free_netdev(pDevice->wpadev);
109 return -1;
110 }
111
112 if (pDevice->skb == NULL) {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700113 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
114 if (pDevice->skb == NULL)
115 return -ENOMEM;
116 }
Forest Bond5449c682009-04-25 10:30:44 -0400117
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700118 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdev %s for WPA management\n",
119 dev->name, pDevice->wpadev->name);
Forest Bond5449c682009-04-25 10:30:44 -0400120
121 return 0;
122}
123
Forest Bond5449c682009-04-25 10:30:44 -0400124/*
125 * Description:
126 * unregister net_device (wpadev)
127 *
128 * Parameters:
129 * In:
130 * pDevice -
131 * Out:
132 *
133 * Return Value:
134 *
135 */
136
137static int wpa_release_wpadev(PSDevice pDevice)
138{
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700139 if (pDevice->skb) {
140 dev_kfree_skb(pDevice->skb);
141 pDevice->skb = NULL;
142 }
Forest Bond5449c682009-04-25 10:30:44 -0400143
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700144 if (pDevice->wpadev) {
145 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n",
146 pDevice->dev->name, pDevice->wpadev->name);
147 unregister_netdev(pDevice->wpadev);
148 free_netdev(pDevice->wpadev);
149 pDevice->wpadev = NULL;
150 }
Forest Bond5449c682009-04-25 10:30:44 -0400151
152 return 0;
153}
154
Forest Bond5449c682009-04-25 10:30:44 -0400155/*
156 * Description:
Justin P. Mattock789d1ae2012-08-20 08:43:13 -0700157 * Set enable/disable dev for wpa supplicant daemon
Forest Bond5449c682009-04-25 10:30:44 -0400158 *
159 * Parameters:
160 * In:
161 * pDevice -
162 * val -
163 * Out:
164 *
165 * Return Value:
166 *
167 */
168
169int wpa_set_wpadev(PSDevice pDevice, int val)
170{
Forest Bond5449c682009-04-25 10:30:44 -0400171 if (val)
172 return wpa_init_wpadev(pDevice);
173 else
174 return wpa_release_wpadev(pDevice);
175}
176
Forest Bond5449c682009-04-25 10:30:44 -0400177/*
178 * Description:
179 * Set WPA algorithm & keys
180 *
181 * Parameters:
182 * In:
183 * pDevice -
184 * param -
185 * Out:
186 *
187 * Return Value:
188 *
189 */
190
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700191int wpa_set_keys(PSDevice pDevice, void *ctx, bool fcpfkernel)
Forest Bond5449c682009-04-25 10:30:44 -0400192{
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700193 struct viawget_wpa_param *param = ctx;
194 PSMgmtObject pMgmt = pDevice->pMgmt;
195 unsigned long dwKeyIndex = 0;
196 unsigned char abyKey[MAX_KEY_LEN];
197 unsigned char abySeq[MAX_KEY_LEN];
198 QWORD KeyRSC;
Forest Bond5449c682009-04-25 10:30:44 -0400199// NDIS_802_11_KEY_RSC KeyRSC;
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700200 unsigned char byKeyDecMode = KEY_CTL_WEP;
Forest Bond5449c682009-04-25 10:30:44 -0400201 int ret = 0;
202 int uu, ii;
203
Dan Carpenter6b7200f2011-10-18 09:27:25 +0300204 if (param->u.wpa_key.alg_name > WPA_ALG_CCMP ||
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700205 param->u.wpa_key.key_len >= MAX_KEY_LEN ||
206 param->u.wpa_key.seq_len >= MAX_KEY_LEN)
Forest Bond5449c682009-04-25 10:30:44 -0400207 return -EINVAL;
208
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700209 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "param->u.wpa_key.alg_name = %d \n", param->u.wpa_key.alg_name);
Forest Bond5449c682009-04-25 10:30:44 -0400210 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700211 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
212 pDevice->bEncryptionEnable = false;
213 pDevice->byKeyIndex = 0;
214 pDevice->bTransmitKey = false;
215 KeyvRemoveAllWEPKey(&(pDevice->sKey), pDevice->PortOffset);
216 for (uu = 0; uu < MAX_KEY_TABLE; uu++) {
217 MACvDisableKeyEntry(pDevice->PortOffset, uu);
218 }
219 return ret;
Forest Bond5449c682009-04-25 10:30:44 -0400220 }
221
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700222 //spin_unlock_irq(&pDevice->lock);
223 if (param->u.wpa_key.key && fcpfkernel) {
224 memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len);
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700225 } else {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700226 spin_unlock_irq(&pDevice->lock);
227 if (param->u.wpa_key.key &&
228 copy_from_user(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len)) {
229 spin_lock_irq(&pDevice->lock);
230 return -EINVAL;
231 }
232 spin_lock_irq(&pDevice->lock);
233 }
234
235 dwKeyIndex = (unsigned long)(param->u.wpa_key.key_index);
236
237 if (param->u.wpa_key.alg_name == WPA_ALG_WEP) {
238 if (dwKeyIndex > 3) {
239 return -EINVAL;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700240 } else {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700241 if (param->u.wpa_key.set_tx) {
242 pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
243 pDevice->bTransmitKey = true;
244 dwKeyIndex |= (1 << 31);
245 }
246 KeybSetDefaultKey(&(pDevice->sKey),
247 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
248 param->u.wpa_key.key_len,
249 NULL,
250 abyKey,
251 KEY_CTL_WEP,
252 pDevice->PortOffset,
253 pDevice->byLocalID);
254
255 }
256 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
257 pDevice->bEncryptionEnable = true;
258 return ret;
259 }
260
261 //spin_unlock_irq(&pDevice->lock);
262 if (param->u.wpa_key.seq && fcpfkernel) {
263 memcpy(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len);
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700264 } else {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700265 spin_unlock_irq(&pDevice->lock);
266 if (param->u.wpa_key.seq &&
267 copy_from_user(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len)) {
268 spin_lock_irq(&pDevice->lock);
269 return -EINVAL;
270 }
271 spin_lock_irq(&pDevice->lock);
272 }
Forest Bond5449c682009-04-25 10:30:44 -0400273
274 if (param->u.wpa_key.seq_len > 0) {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700275 for (ii = 0; ii < param->u.wpa_key.seq_len; ii++) {
276 if (ii < 4)
277 LODWORD(KeyRSC) |= (abySeq[ii] << (ii * 8));
278 else
279 HIDWORD(KeyRSC) |= (abySeq[ii] << ((ii-4) * 8));
280 //KeyRSC |= (abySeq[ii] << (ii * 8));
Forest Bond5449c682009-04-25 10:30:44 -0400281 }
282 dwKeyIndex |= 1 << 29;
283 }
284
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700285 if (param->u.wpa_key.key_index >= MAX_GROUP_KEY) {
286 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return dwKeyIndex > 3\n");
287 return -EINVAL;
288 }
Forest Bond5449c682009-04-25 10:30:44 -0400289
290 if (param->u.wpa_key.alg_name == WPA_ALG_TKIP) {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700291 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
292 }
Forest Bond5449c682009-04-25 10:30:44 -0400293
294 if (param->u.wpa_key.alg_name == WPA_ALG_CCMP) {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700295 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
296 }
Forest Bond5449c682009-04-25 10:30:44 -0400297
298 if (param->u.wpa_key.set_tx)
299 dwKeyIndex |= (1 << 31);
300
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700301 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
302 byKeyDecMode = KEY_CTL_CCMP;
303 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
304 byKeyDecMode = KEY_CTL_TKIP;
305 else
306 byKeyDecMode = KEY_CTL_WEP;
Forest Bond5449c682009-04-25 10:30:44 -0400307
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700308 // Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled
309 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
310 if (param->u.wpa_key.key_len == MAX_KEY_LEN)
311 byKeyDecMode = KEY_CTL_TKIP;
312 else if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
313 byKeyDecMode = KEY_CTL_WEP;
314 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
315 byKeyDecMode = KEY_CTL_WEP;
316 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
317 if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
318 byKeyDecMode = KEY_CTL_WEP;
319 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
320 byKeyDecMode = KEY_CTL_WEP;
321 }
Forest Bond5449c682009-04-25 10:30:44 -0400322
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700323 // Check TKIP key length
324 if ((byKeyDecMode == KEY_CTL_TKIP) &&
325 (param->u.wpa_key.key_len != MAX_KEY_LEN)) {
326 // TKIP Key must be 256 bits
327 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - TKIP Key must be 256 bits\n"));
328 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return- TKIP Key must be 256 bits!\n");
329 return -EINVAL;
330 }
331 // Check AES key length
332 if ((byKeyDecMode == KEY_CTL_CCMP) &&
333 (param->u.wpa_key.key_len != AES_KEY_LEN)) {
334 // AES Key must be 128 bits
335 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - AES Key must be 128 bits\n"));
336 return -EINVAL;
337 }
Forest Bond5449c682009-04-25 10:30:44 -0400338
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700339 // spin_lock_irq(&pDevice->lock);
340 if (is_broadcast_ether_addr(&param->addr[0]) || (param->addr == NULL)) {
341 // If is_broadcast_ether_addr, set the key as every key entry's group key.
342 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Groupe Key Assign.\n");
Forest Bond5449c682009-04-25 10:30:44 -0400343
Teodora Baluta1208f142013-11-10 17:12:42 +0200344 if (KeybSetAllGroupKey(&(pDevice->sKey),
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700345 dwKeyIndex,
346 param->u.wpa_key.key_len,
347 (PQWORD) &(KeyRSC),
348 (unsigned char *)abyKey,
349 byKeyDecMode,
350 pDevice->PortOffset,
Teodora Baluta1208f142013-11-10 17:12:42 +0200351 pDevice->byLocalID) &&
352 KeybSetDefaultKey(&(pDevice->sKey),
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700353 dwKeyIndex,
354 param->u.wpa_key.key_len,
355 (PQWORD) &(KeyRSC),
356 (unsigned char *)abyKey,
357 byKeyDecMode,
358 pDevice->PortOffset,
Teodora Baluta1208f142013-11-10 17:12:42 +0200359 pDevice->byLocalID)) {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700360 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");
Forest Bond5449c682009-04-25 10:30:44 -0400361
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700362 } else {
363 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -KeybSetDefaultKey Fail.0\n"));
364 // spin_unlock_irq(&pDevice->lock);
365 return -EINVAL;
366 }
Forest Bond5449c682009-04-25 10:30:44 -0400367
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700368 } else {
369 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Assign.\n");
370 // BSSID not 0xffffffffffff
371 // Pairwise Key can't be WEP
372 if (byKeyDecMode == KEY_CTL_WEP) {
373 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key can't be WEP\n");
374 //spin_unlock_irq(&pDevice->lock);
375 return -EINVAL;
376 }
Forest Bond5449c682009-04-25 10:30:44 -0400377
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700378 dwKeyIndex |= (1 << 30); // set pairwise key
379 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
380 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - WMAC_CONFIG_IBSS_STA\n"));
381 //spin_unlock_irq(&pDevice->lock);
382 return -EINVAL;
383 }
384 if (KeybSetKey(&(pDevice->sKey),
385 &param->addr[0],
386 dwKeyIndex,
387 param->u.wpa_key.key_len,
388 (PQWORD) &(KeyRSC),
389 (unsigned char *)abyKey,
390 byKeyDecMode,
391 pDevice->PortOffset,
Teodora Baluta1208f142013-11-10 17:12:42 +0200392 pDevice->byLocalID)) {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700393 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");
Forest Bond5449c682009-04-25 10:30:44 -0400394
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700395 } else {
396 // Key Table Full
Joe Perches83294192013-09-01 12:15:47 -0700397 if (ether_addr_equal(param->addr, pDevice->abyBSSID)) {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700398 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
399 //spin_unlock_irq(&pDevice->lock);
400 return -EINVAL;
Forest Bond5449c682009-04-25 10:30:44 -0400401
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700402 } else {
403 // Save Key and configure just before associate/reassociate to BSSID
404 // we do not implement now
405 //spin_unlock_irq(&pDevice->lock);
406 return -EINVAL;
407 }
408 }
409 } // BSSID not 0xffffffffffff
410 if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
411 pDevice->byKeyIndex = (unsigned char)param->u.wpa_key.key_index;
412 pDevice->bTransmitKey = true;
413 }
414 pDevice->bEncryptionEnable = true;
415 //spin_unlock_irq(&pDevice->lock);
Forest Bond5449c682009-04-25 10:30:44 -0400416
417/*
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700418 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
419 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][0],
420 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][1],
421 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][2],
422 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][3],
423 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][4]
424);
Forest Bond5449c682009-04-25 10:30:44 -0400425*/
426
427 return ret;
Forest Bond5449c682009-04-25 10:30:44 -0400428}
429
Forest Bond5449c682009-04-25 10:30:44 -0400430/*
431 * Description:
432 * enable wpa auth & mode
433 *
434 * Parameters:
435 * In:
436 * pDevice -
437 * param -
438 * Out:
439 *
440 * Return Value:
441 *
442 */
443
444static int wpa_set_wpa(PSDevice pDevice,
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700445 struct viawget_wpa_param *param)
Forest Bond5449c682009-04-25 10:30:44 -0400446{
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700447 PSMgmtObject pMgmt = pDevice->pMgmt;
Forest Bond5449c682009-04-25 10:30:44 -0400448 int ret = 0;
449
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700450 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
451 pMgmt->bShareKeyAlgorithm = false;
Forest Bond5449c682009-04-25 10:30:44 -0400452
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700453 return ret;
Forest Bond5449c682009-04-25 10:30:44 -0400454}
455
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700456/*
Forest Bond5449c682009-04-25 10:30:44 -0400457 * Description:
458 * set disassociate
459 *
460 * Parameters:
461 * In:
462 * pDevice -
463 * param -
464 * Out:
465 *
466 * Return Value:
467 *
468 */
469
470static int wpa_set_disassociate(PSDevice pDevice,
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700471 struct viawget_wpa_param *param)
Forest Bond5449c682009-04-25 10:30:44 -0400472{
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700473 PSMgmtObject pMgmt = pDevice->pMgmt;
Forest Bond5449c682009-04-25 10:30:44 -0400474 int ret = 0;
475
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700476 spin_lock_irq(&pDevice->lock);
477 if (pDevice->bLinkPass) {
478 if (!memcmp(param->addr, pMgmt->abyCurrBSSID, 6))
479 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
480 }
481 spin_unlock_irq(&pDevice->lock);
Forest Bond5449c682009-04-25 10:30:44 -0400482
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700483 return ret;
Forest Bond5449c682009-04-25 10:30:44 -0400484}
485
Forest Bond5449c682009-04-25 10:30:44 -0400486/*
487 * Description:
488 * enable scan process
489 *
490 * Parameters:
491 * In:
492 * pDevice -
493 * param -
494 * Out:
495 *
496 * Return Value:
497 *
498 */
499
500static int wpa_set_scan(PSDevice pDevice,
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700501 struct viawget_wpa_param *param)
Forest Bond5449c682009-04-25 10:30:44 -0400502{
503 int ret = 0;
504
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700505 spin_lock_irq(&pDevice->lock);
506 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
507 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
508 spin_unlock_irq(&pDevice->lock);
Forest Bond5449c682009-04-25 10:30:44 -0400509
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700510 return ret;
Forest Bond5449c682009-04-25 10:30:44 -0400511}
512
Forest Bond5449c682009-04-25 10:30:44 -0400513/*
514 * Description:
515 * get bssid
516 *
517 * Parameters:
518 * In:
519 * pDevice -
520 * param -
521 * Out:
522 *
523 * Return Value:
524 *
525 */
526
527static int wpa_get_bssid(PSDevice pDevice,
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700528 struct viawget_wpa_param *param)
Forest Bond5449c682009-04-25 10:30:44 -0400529{
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700530 PSMgmtObject pMgmt = pDevice->pMgmt;
Forest Bond5449c682009-04-25 10:30:44 -0400531 int ret = 0;
532
533 memcpy(param->u.wpa_associate.bssid, pMgmt->abyCurrBSSID , 6);
534
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700535 return ret;
Forest Bond5449c682009-04-25 10:30:44 -0400536}
537
Forest Bond5449c682009-04-25 10:30:44 -0400538/*
539 * Description:
540 * get bssid
541 *
542 * Parameters:
543 * In:
544 * pDevice -
545 * param -
546 * Out:
547 *
548 * Return Value:
549 *
550 */
551
552static int wpa_get_ssid(PSDevice pDevice,
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700553 struct viawget_wpa_param *param)
Forest Bond5449c682009-04-25 10:30:44 -0400554{
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700555 PSMgmtObject pMgmt = pDevice->pMgmt;
Forest Bond5449c682009-04-25 10:30:44 -0400556 PWLAN_IE_SSID pItemSSID;
557 int ret = 0;
558
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700559 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
Forest Bond5449c682009-04-25 10:30:44 -0400560
561 memcpy(param->u.wpa_associate.ssid, pItemSSID->abySSID , pItemSSID->len);
562 param->u.wpa_associate.ssid_len = pItemSSID->len;
563
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700564 return ret;
Forest Bond5449c682009-04-25 10:30:44 -0400565}
566
Forest Bond5449c682009-04-25 10:30:44 -0400567/*
568 * Description:
569 * get scan results
570 *
571 * Parameters:
572 * In:
573 * pDevice -
574 * param -
575 * Out:
576 *
577 * Return Value:
578 *
579 */
580
581static int wpa_get_scan(PSDevice pDevice,
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700582 struct viawget_wpa_param *param)
Forest Bond5449c682009-04-25 10:30:44 -0400583{
584 struct viawget_scan_result *scan_buf;
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700585 PSMgmtObject pMgmt = pDevice->pMgmt;
586 PWLAN_IE_SSID pItemSSID;
587 PKnownBSS pBSS;
Charles Clément2989e962010-06-05 15:13:47 -0700588 unsigned char *pBuf;
Forest Bond5449c682009-04-25 10:30:44 -0400589 int ret = 0;
590 u16 count = 0;
591 u16 ii, jj;
592#if 1
593
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700594 unsigned char *ptempBSS;
Forest Bond5449c682009-04-25 10:30:44 -0400595
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700596 ptempBSS = kmalloc(sizeof(KnownBSS), (int)GFP_ATOMIC);
Forest Bond5449c682009-04-25 10:30:44 -0400597
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700598 if (ptempBSS == NULL) {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700599 printk("bubble sort kmalloc memory fail@@@\n");
Forest Bond5449c682009-04-25 10:30:44 -0400600
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700601 ret = -ENOMEM;
Forest Bond5449c682009-04-25 10:30:44 -0400602
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700603 return ret;
Forest Bond5449c682009-04-25 10:30:44 -0400604
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700605 }
Forest Bond5449c682009-04-25 10:30:44 -0400606
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700607 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700608 for (jj = 0; jj < MAX_BSS_NUM - ii - 1; jj++) {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700609 if ((pMgmt->sBSSList[jj].bActive != true) ||
Forest Bond5449c682009-04-25 10:30:44 -0400610
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700611 ((pMgmt->sBSSList[jj].uRSSI > pMgmt->sBSSList[jj + 1].uRSSI) && (pMgmt->sBSSList[jj + 1].bActive != false))) {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700612 memcpy(ptempBSS, &pMgmt->sBSSList[jj], sizeof(KnownBSS));
Forest Bond5449c682009-04-25 10:30:44 -0400613
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700614 memcpy(&pMgmt->sBSSList[jj], &pMgmt->sBSSList[jj + 1], sizeof(KnownBSS));
Forest Bond5449c682009-04-25 10:30:44 -0400615
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700616 memcpy(&pMgmt->sBSSList[jj + 1], ptempBSS, sizeof(KnownBSS));
Forest Bond5449c682009-04-25 10:30:44 -0400617
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700618 }
Forest Bond5449c682009-04-25 10:30:44 -0400619
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700620 }
Forest Bond5449c682009-04-25 10:30:44 -0400621
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700622 }
Forest Bond5449c682009-04-25 10:30:44 -0400623
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700624 kfree(ptempBSS);
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700625#endif
Forest Bond5449c682009-04-25 10:30:44 -0400626
627//******mike:bubble sort by stronger RSSI*****//
628
Forest Bond5449c682009-04-25 10:30:44 -0400629 count = 0;
630 pBSS = &(pMgmt->sBSSList[0]);
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700631 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
632 pBSS = &(pMgmt->sBSSList[ii]);
633 if (!pBSS->bActive)
634 continue;
635 count++;
636 }
Forest Bond5449c682009-04-25 10:30:44 -0400637
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700638 pBuf = kcalloc(count, sizeof(struct viawget_scan_result), (int)GFP_ATOMIC);
Forest Bond5449c682009-04-25 10:30:44 -0400639
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700640 if (pBuf == NULL) {
641 ret = -ENOMEM;
642 return ret;
643 }
644 scan_buf = (struct viawget_scan_result *)pBuf;
Forest Bond5449c682009-04-25 10:30:44 -0400645 pBSS = &(pMgmt->sBSSList[0]);
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700646 for (ii = 0, jj = 0; ii < MAX_BSS_NUM; ii++) {
647 pBSS = &(pMgmt->sBSSList[ii]);
648 if (pBSS->bActive) {
649 if (jj >= count)
650 break;
651 memcpy(scan_buf->bssid, pBSS->abyBSSID, WLAN_BSSID_LEN);
652 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
653 memcpy(scan_buf->ssid, pItemSSID->abySSID, pItemSSID->len);
654 scan_buf->ssid_len = pItemSSID->len;
655 scan_buf->freq = frequency_list[pBSS->uChannel-1];
656 scan_buf->caps = pBSS->wCapInfo;
657 //scan_buf->caps = pBSS->wCapInfo;
658 //scan_buf->qual =
659 //scan_buf->noise =
660 //scan_buf->level =
661 //scan_buf->maxrate =
662 if (pBSS->wWPALen != 0) {
663 scan_buf->wpa_ie_len = pBSS->wWPALen;
664 memcpy(scan_buf->wpa_ie, pBSS->byWPAIE, pBSS->wWPALen);
665 }
666 if (pBSS->wRSNLen != 0) {
667 scan_buf->rsn_ie_len = pBSS->wRSNLen;
668 memcpy(scan_buf->rsn_ie, pBSS->byRSNIE, pBSS->wRSNLen);
669 }
670 scan_buf = (struct viawget_scan_result *)((unsigned char *)scan_buf + sizeof(struct viawget_scan_result));
671 jj++;
672 }
673 }
Forest Bond5449c682009-04-25 10:30:44 -0400674
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700675 if (jj < count)
676 count = jj;
Forest Bond5449c682009-04-25 10:30:44 -0400677
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700678 if (copy_to_user(param->u.scan_results.buf, pBuf, sizeof(struct viawget_scan_result) * count)) {
Forest Bond5449c682009-04-25 10:30:44 -0400679 ret = -EFAULT;
Joe Perches9fc86022011-04-10 14:31:32 -0700680 }
Forest Bond5449c682009-04-25 10:30:44 -0400681 param->u.scan_results.scan_count = count;
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700682 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " param->u.scan_results.scan_count = %d\n", count)
Forest Bond5449c682009-04-25 10:30:44 -0400683
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700684 kfree(pBuf);
685 return ret;
Forest Bond5449c682009-04-25 10:30:44 -0400686}
687
Forest Bond5449c682009-04-25 10:30:44 -0400688/*
689 * Description:
690 * set associate with AP
691 *
692 * Parameters:
693 * In:
694 * pDevice -
695 * param -
696 * Out:
697 *
698 * Return Value:
699 *
700 */
701
702static int wpa_set_associate(PSDevice pDevice,
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700703 struct viawget_wpa_param *param)
Forest Bond5449c682009-04-25 10:30:44 -0400704{
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700705 PSMgmtObject pMgmt = pDevice->pMgmt;
706 PWLAN_IE_SSID pItemSSID;
707 unsigned char abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
708 unsigned char abyWPAIE[64];
709 int ret = 0;
710 bool bWepEnabled = false;
Forest Bond5449c682009-04-25 10:30:44 -0400711
712 // set key type & algorithm
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700713 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise_suite = %d\n", param->u.wpa_associate.pairwise_suite);
714 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "group_suite = %d\n", param->u.wpa_associate.group_suite);
715 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key_mgmt_suite = %d\n", param->u.wpa_associate.key_mgmt_suite);
716 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "auth_alg = %d\n", param->u.wpa_associate.auth_alg);
717 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "mode = %d\n", param->u.wpa_associate.mode);
718 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len);
Forest Bond5449c682009-04-25 10:30:44 -0400719
Dan Carpenterdd173ab2010-09-06 14:32:30 +0200720 if (param->u.wpa_associate.wpa_ie_len) {
721 if (!param->u.wpa_associate.wpa_ie)
722 return -EINVAL;
723 if (param->u.wpa_associate.wpa_ie_len > sizeof(abyWPAIE))
724 return -EINVAL;
725 if (copy_from_user(&abyWPAIE[0], param->u.wpa_associate.wpa_ie, param->u.wpa_associate.wpa_ie_len))
726 return -EFAULT;
727 }
Forest Bond5449c682009-04-25 10:30:44 -0400728
729 if (param->u.wpa_associate.mode == 1)
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700730 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
Forest Bond5449c682009-04-25 10:30:44 -0400731 else
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700732 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
733 // set ssid
Forest Bond5449c682009-04-25 10:30:44 -0400734 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700735 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
736 pItemSSID->byElementID = WLAN_EID_SSID;
Forest Bond5449c682009-04-25 10:30:44 -0400737 pItemSSID->len = param->u.wpa_associate.ssid_len;
738 memcpy(pItemSSID->abySSID, param->u.wpa_associate.ssid, pItemSSID->len);
739 // set bssid
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700740 if (memcmp(param->u.wpa_associate.bssid, &abyNullAddr[0], 6) != 0)
741 memcpy(pMgmt->abyDesireBSSID, param->u.wpa_associate.bssid, 6);
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700742 else {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700743 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pItemSSID->abySSID);
744 }
Forest Bond5449c682009-04-25 10:30:44 -0400745
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700746 if (param->u.wpa_associate.wpa_ie_len == 0) {
747 if (param->u.wpa_associate.auth_alg & AUTH_ALG_SHARED_KEY)
748 pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
749 else
750 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
Forest Bond5449c682009-04-25 10:30:44 -0400751 } else if (abyWPAIE[0] == RSN_INFO_ELEM) {
752 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
753 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
754 else
755 pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
756 } else {
757 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_WPA_NONE)
758 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
759 else if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700760 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
Forest Bond5449c682009-04-25 10:30:44 -0400761 else
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700762 pMgmt->eAuthenMode = WMAC_AUTH_WPA;
Forest Bond5449c682009-04-25 10:30:44 -0400763 }
764
765 switch (param->u.wpa_associate.pairwise_suite) {
766 case CIPHER_CCMP:
767 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
768 break;
769 case CIPHER_TKIP:
770 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
771 break;
772 case CIPHER_WEP40:
773 case CIPHER_WEP104:
774 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700775 bWepEnabled = true;
Forest Bond5449c682009-04-25 10:30:44 -0400776 break;
777 case CIPHER_NONE:
778 if (param->u.wpa_associate.group_suite == CIPHER_CCMP)
779 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
780 else
781 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
782 break;
783 default:
784 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
Joe Perches95cd17c2011-04-10 14:31:35 -0700785 }
Forest Bond5449c682009-04-25 10:30:44 -0400786
787//DavidWang add for WPA_supplicant support open/share mode
788
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700789 if (pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) {
790 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
791 //pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
792 pMgmt->bShareKeyAlgorithm = true;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700793 } else if (pMgmt->eAuthenMode == WMAC_AUTH_OPEN) {
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700794 if (!bWepEnabled) pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
795 else pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
796 //pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
797 //pMgmt->bShareKeyAlgorithm = false; //20080717-06,<Modify> by chester//Fix Open mode, WEP encryption
798 }
Forest Bond5449c682009-04-25 10:30:44 -0400799//mike save old encryption status
800 pDevice->eOldEncryptionStatus = pDevice->eEncryptionStatus;
801
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700802 if (pDevice->eEncryptionStatus != Ndis802_11EncryptionDisabled)
803 pDevice->bEncryptionEnable = true;
804 else
805 pDevice->bEncryptionEnable = false;
806 if (!((pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) ||
Teodora Baluta1208f142013-11-10 17:12:42 +0200807 ((pMgmt->eAuthenMode == WMAC_AUTH_OPEN) && bWepEnabled))) //DavidWang //20080717-06,<Modify> by chester//Not to initial WEP
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700808 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
809 spin_lock_irq(&pDevice->lock);
810 pDevice->bLinkPass = false;
811 memset(pMgmt->abyCurrBSSID, 0, 6);
812 pMgmt->eCurrState = WMAC_STATE_IDLE;
813 netif_stop_queue(pDevice->dev);
Forest Bond5449c682009-04-25 10:30:44 -0400814 //20080701-02,<Add> by Mike Liu
815/*******search if ap_scan=2 ,which is associating request in hidden ssid mode ****/
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700816 {
817 PKnownBSS pCurr = NULL;
818 pCurr = BSSpSearchBSSList(pDevice,
819 pMgmt->abyDesireBSSID,
820 pMgmt->abyDesireSSID,
821 pMgmt->eConfigPHYMode
822);
Forest Bond5449c682009-04-25 10:30:44 -0400823
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700824 if (pCurr == NULL) {
825 printk("wpa_set_associate---->hidden mode site survey before associate.......\n");
826 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
827 }
828 }
Forest Bond5449c682009-04-25 10:30:44 -0400829/****************************************************************/
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700830 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
831 spin_unlock_irq(&pDevice->lock);
Forest Bond5449c682009-04-25 10:30:44 -0400832
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700833 return ret;
Forest Bond5449c682009-04-25 10:30:44 -0400834}
835
Forest Bond5449c682009-04-25 10:30:44 -0400836/*
837 * Description:
838 * wpa_ioctl main function supported for wpa supplicant
839 *
840 * Parameters:
841 * In:
842 * pDevice -
843 * iw_point -
844 * Out:
845 *
846 * Return Value:
847 *
848 */
849
850int wpa_ioctl(PSDevice pDevice, struct iw_point *p)
851{
852 struct viawget_wpa_param *param;
853 int ret = 0;
854 int wpa_ioctl = 0;
855
856 if (p->length < sizeof(struct viawget_wpa_param) ||
857 p->length > VIAWGET_WPA_MAX_BUF_SIZE || !p->pointer)
858 return -EINVAL;
859
Julia Lawall32414872010-05-11 20:26:57 +0200860 param = kmalloc((int)p->length, (int)GFP_KERNEL);
Forest Bond5449c682009-04-25 10:30:44 -0400861 if (param == NULL)
862 return -ENOMEM;
863
864 if (copy_from_user(param, p->pointer, p->length)) {
865 ret = -EFAULT;
866 goto out;
867 }
868
869 switch (param->cmd) {
870 case VIAWGET_SET_WPA:
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700871 ret = wpa_set_wpa(pDevice, param);
872 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_WPA \n");
Forest Bond5449c682009-04-25 10:30:44 -0400873 break;
874
875 case VIAWGET_SET_KEY:
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700876 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_KEY \n");
877 spin_lock_irq(&pDevice->lock);
878 ret = wpa_set_keys(pDevice, param, false);
879 spin_unlock_irq(&pDevice->lock);
Forest Bond5449c682009-04-25 10:30:44 -0400880 break;
881
882 case VIAWGET_SET_SCAN:
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700883 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_SCAN \n");
884 ret = wpa_set_scan(pDevice, param);
Forest Bond5449c682009-04-25 10:30:44 -0400885 break;
886
887 case VIAWGET_GET_SCAN:
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700888 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SCAN\n");
889 ret = wpa_get_scan(pDevice, param);
Forest Bond5449c682009-04-25 10:30:44 -0400890 wpa_ioctl = 1;
891 break;
892
893 case VIAWGET_GET_SSID:
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700894 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SSID \n");
895 ret = wpa_get_ssid(pDevice, param);
Forest Bond5449c682009-04-25 10:30:44 -0400896 wpa_ioctl = 1;
897 break;
898
899 case VIAWGET_GET_BSSID:
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700900 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_BSSID \n");
901 ret = wpa_get_bssid(pDevice, param);
Forest Bond5449c682009-04-25 10:30:44 -0400902 wpa_ioctl = 1;
903 break;
904
905 case VIAWGET_SET_ASSOCIATE:
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700906 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_ASSOCIATE \n");
907 ret = wpa_set_associate(pDevice, param);
Forest Bond5449c682009-04-25 10:30:44 -0400908 break;
909
910 case VIAWGET_SET_DISASSOCIATE:
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700911 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DISASSOCIATE \n");
912 ret = wpa_set_disassociate(pDevice, param);
Forest Bond5449c682009-04-25 10:30:44 -0400913 break;
914
915 case VIAWGET_SET_DROP_UNENCRYPT:
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700916 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DROP_UNENCRYPT \n");
Forest Bond5449c682009-04-25 10:30:44 -0400917 break;
918
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700919 case VIAWGET_SET_DEAUTHENTICATE:
920 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DEAUTHENTICATE \n");
Forest Bond5449c682009-04-25 10:30:44 -0400921 break;
922
923 default:
Joe Perchesf9cf92b2013-03-18 10:45:14 -0700924 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ioctl: unknown cmd=%d\n",
925 param->cmd);
Forest Bond5449c682009-04-25 10:30:44 -0400926 return -EOPNOTSUPP;
927 break;
928 }
929
930 if ((ret == 0) && wpa_ioctl) {
931 if (copy_to_user(p->pointer, param, p->length)) {
932 ret = -EFAULT;
933 goto out;
934 }
935 }
936
937out:
Ilia Mirkin6403bb72011-03-13 00:29:14 -0500938 kfree(param);
Forest Bond5449c682009-04-25 10:30:44 -0400939
940 return ret;
941}