aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesper Juhl <jj@chaosbits.net>2012-01-16 15:28:23 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-02-09 12:20:06 -0500
commit4e1efd6e853977a134ff262230ccb4b69319d926 (patch)
treea6583ed1d33256f148114fadb8245ba74654f889
parent08afcf9c9f5b9372e26f3f29313f45528fafc15c (diff)
staging, vt6656/wpactl.c: A basic style cleanup
This patch cleans up the coding style in drivers/staging/vt6656/wpactl.c to closer match the generally accepted kernel CodingStyle. It is by no means a "make it perfect" patch, but it does get the file a fair bit closer to matching the accepted style (whomever was involved in the evolution of this file seriously need to configure their editors to maintain a consistent style - it was a mess). Besides pure style cleanups I also took the liberty of removing some pointless parens, some unneeded casts and removing some commented out code (it was obviously not used and git has it if it's ever needed in the future). Signed-off-by: Jesper Juhl <jj@chaosbits.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/vt6656/wpactl.c936
1 files changed, 418 insertions, 518 deletions
diff --git a/drivers/staging/vt6656/wpactl.c b/drivers/staging/vt6656/wpactl.c
index 2fa4f845a75..9d148686635 100644
--- a/drivers/staging/vt6656/wpactl.c
+++ b/drivers/staging/vt6656/wpactl.c
@@ -46,23 +46,18 @@
46 46
47#define VIAWGET_WPA_MAX_BUF_SIZE 1024 47#define VIAWGET_WPA_MAX_BUF_SIZE 1024
48 48
49
50
51static const int frequency_list[] = { 49static const int frequency_list[] = {
52 2412, 2417, 2422, 2427, 2432, 2437, 2442, 50 2412, 2417, 2422, 2427, 2432, 2437, 2442,
53 2447, 2452, 2457, 2462, 2467, 2472, 2484 51 2447, 2452, 2457, 2462, 2467, 2472, 2484
54}; 52};
53
55/*--------------------- Static Classes ----------------------------*/ 54/*--------------------- Static Classes ----------------------------*/
56 55
57/*--------------------- Static Variables --------------------------*/ 56/*--------------------- Static Variables --------------------------*/
58//static int msglevel =MSG_LEVEL_DEBUG; 57static int msglevel = MSG_LEVEL_INFO;
59static int msglevel =MSG_LEVEL_INFO;
60 58
61/*--------------------- Static Functions --------------------------*/ 59/*--------------------- Static Functions --------------------------*/
62 60
63
64
65
66/*--------------------- Export Variables --------------------------*/ 61/*--------------------- Export Variables --------------------------*/
67static void wpadev_setup(struct net_device *dev) 62static void wpadev_setup(struct net_device *dev)
68{ 63{
@@ -72,9 +67,9 @@ static void wpadev_setup(struct net_device *dev)
72 dev->addr_len = ETH_ALEN; 67 dev->addr_len = ETH_ALEN;
73 dev->tx_queue_len = 1000; 68 dev->tx_queue_len = 1000;
74 69
75 memset(dev->broadcast,0xFF, ETH_ALEN); 70 memset(dev->broadcast, 0xFF, ETH_ALEN);
76 71
77 dev->flags = IFF_BROADCAST|IFF_MULTICAST; 72 dev->flags = IFF_BROADCAST | IFF_MULTICAST;
78} 73}
79 74
80/* 75/*
@@ -90,45 +85,43 @@ static void wpadev_setup(struct net_device *dev)
90 * Return Value: 85 * Return Value:
91 * 86 *
92 */ 87 */
93
94static int wpa_init_wpadev(PSDevice pDevice) 88static int wpa_init_wpadev(PSDevice pDevice)
95{ 89{
96 PSDevice wpadev_priv; 90 PSDevice wpadev_priv;
97 struct net_device *dev = pDevice->dev; 91 struct net_device *dev = pDevice->dev;
98 int ret=0; 92 int ret = 0;
99 93
100 pDevice->wpadev = alloc_netdev(sizeof(PSDevice), "vntwpa", wpadev_setup); 94 pDevice->wpadev = alloc_netdev(sizeof(PSDevice), "vntwpa", wpadev_setup);
101 if (pDevice->wpadev == NULL) 95 if (pDevice->wpadev == NULL)
102 return -ENOMEM; 96 return -ENOMEM;
103 97
104 wpadev_priv = netdev_priv(pDevice->wpadev); 98 wpadev_priv = netdev_priv(pDevice->wpadev);
105 *wpadev_priv = *pDevice; 99 *wpadev_priv = *pDevice;
106 memcpy(pDevice->wpadev->dev_addr, dev->dev_addr, ETH_ALEN); 100 memcpy(pDevice->wpadev->dev_addr, dev->dev_addr, ETH_ALEN);
107 pDevice->wpadev->base_addr = dev->base_addr; 101 pDevice->wpadev->base_addr = dev->base_addr;
108 pDevice->wpadev->irq = dev->irq; 102 pDevice->wpadev->irq = dev->irq;
109 pDevice->wpadev->mem_start = dev->mem_start; 103 pDevice->wpadev->mem_start = dev->mem_start;
110 pDevice->wpadev->mem_end = dev->mem_end; 104 pDevice->wpadev->mem_end = dev->mem_end;
111 ret = register_netdev(pDevice->wpadev); 105 ret = register_netdev(pDevice->wpadev);
112 if (ret) { 106 if (ret) {
113 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdev(WPA) failed!\n", 107 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdev(WPA) failed!\n",
114 dev->name); 108 dev->name);
115 free_netdev(pDevice->wpadev); 109 free_netdev(pDevice->wpadev);
116 return -1; 110 return -1;
117 } 111 }
118 112
119 if (pDevice->skb == NULL) { 113 if (pDevice->skb == NULL) {
120 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz); 114 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
121 if (pDevice->skb == NULL) 115 if (pDevice->skb == NULL)
122 return -ENOMEM; 116 return -ENOMEM;
123 } 117 }
124 118
125 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdev %s for WPA management\n", 119 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdev %s for WPA management\n",
126 dev->name, pDevice->wpadev->name); 120 dev->name, pDevice->wpadev->name);
127 121
128 return 0; 122 return 0;
129} 123}
130 124
131
132/* 125/*
133 * Description: 126 * Description:
134 * unregister net_device (wpadev) 127 * unregister net_device (wpadev)
@@ -141,29 +134,24 @@ static int wpa_init_wpadev(PSDevice pDevice)
141 * Return Value: 134 * Return Value:
142 * 135 *
143 */ 136 */
144
145static int wpa_release_wpadev(PSDevice pDevice) 137static int wpa_release_wpadev(PSDevice pDevice)
146{ 138{
147 if (pDevice->skb) { 139 if (pDevice->skb) {
148 dev_kfree_skb(pDevice->skb); 140 dev_kfree_skb(pDevice->skb);
149 pDevice->skb = NULL; 141 pDevice->skb = NULL;
150 } 142 }
151 143
152 if (pDevice->wpadev) { 144 if (pDevice->wpadev) {
153 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n", 145 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n",
154 pDevice->dev->name, pDevice->wpadev->name); 146 pDevice->dev->name, pDevice->wpadev->name);
155 unregister_netdev(pDevice->wpadev); 147 unregister_netdev(pDevice->wpadev);
156 free_netdev(pDevice->wpadev); 148 free_netdev(pDevice->wpadev);
157 pDevice->wpadev = NULL; 149 pDevice->wpadev = NULL;
158 } 150 }
159 151
160 return 0; 152 return 0;
161} 153}
162 154
163
164
165
166
167/* 155/*
168 * Description: 156 * Description:
169 * Set enable/disable dev for wpa supplicant deamon 157 * Set enable/disable dev for wpa supplicant deamon
@@ -177,13 +165,11 @@ static int wpa_release_wpadev(PSDevice pDevice)
177 * Return Value: 165 * Return Value:
178 * 166 *
179 */ 167 */
180
181int wpa_set_wpadev(PSDevice pDevice, int val) 168int wpa_set_wpadev(PSDevice pDevice, int val)
182{ 169{
183 if (val) 170 if (val)
184 return wpa_init_wpadev(pDevice); 171 return wpa_init_wpadev(pDevice);
185 else 172 return wpa_release_wpadev(pDevice);
186 return wpa_release_wpadev(pDevice);
187} 173}
188 174
189/* 175/*
@@ -199,245 +185,217 @@ int wpa_set_wpadev(PSDevice pDevice, int val)
199 * Return Value: 185 * Return Value:
200 * 186 *
201 */ 187 */
202
203 int wpa_set_keys(PSDevice pDevice, void *ctx, BOOL fcpfkernel) 188 int wpa_set_keys(PSDevice pDevice, void *ctx, BOOL fcpfkernel)
204{ 189{
205 struct viawget_wpa_param *param=ctx; 190 struct viawget_wpa_param *param = ctx;
206 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 191 PSMgmtObject pMgmt = &pDevice->sMgmtObj;
207 DWORD dwKeyIndex = 0; 192 DWORD dwKeyIndex = 0;
208 BYTE abyKey[MAX_KEY_LEN]; 193 BYTE abyKey[MAX_KEY_LEN];
209 BYTE abySeq[MAX_KEY_LEN]; 194 BYTE abySeq[MAX_KEY_LEN];
210 QWORD KeyRSC; 195 QWORD KeyRSC;
211// NDIS_802_11_KEY_RSC KeyRSC; 196 BYTE byKeyDecMode = KEY_CTL_WEP;
212 BYTE byKeyDecMode = KEY_CTL_WEP;
213 int ret = 0; 197 int ret = 0;
214 int uu, ii; 198 int uu;
215 199 int ii;
216 200
217 if (param->u.wpa_key.alg_name > WPA_ALG_CCMP) 201 if (param->u.wpa_key.alg_name > WPA_ALG_CCMP)
218 return -EINVAL; 202 return -EINVAL;
219 203
220 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "param->u.wpa_key.alg_name = %d \n", param->u.wpa_key.alg_name); 204 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "param->u.wpa_key.alg_name = %d \n",
205 param->u.wpa_key.alg_name);
221 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) { 206 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
222 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; 207 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
223 pDevice->bEncryptionEnable = FALSE; 208 pDevice->bEncryptionEnable = FALSE;
224 pDevice->byKeyIndex = 0; 209 pDevice->byKeyIndex = 0;
225 pDevice->bTransmitKey = FALSE; 210 pDevice->bTransmitKey = FALSE;
226 for (uu=0; uu<MAX_KEY_TABLE; uu++) { 211 for (uu=0; uu<MAX_KEY_TABLE; uu++) {
227 MACvDisableKeyEntry(pDevice, uu); 212 MACvDisableKeyEntry(pDevice, uu);
228 } 213 }
229 return ret; 214 return ret;
230 } 215 }
231 216
232 if (param->u.wpa_key.key && param->u.wpa_key.key_len > sizeof(abyKey)) 217 if (param->u.wpa_key.key && param->u.wpa_key.key_len > sizeof(abyKey))
233 return -EINVAL; 218 return -EINVAL;
234 219
235 spin_unlock_irq(&pDevice->lock); 220 spin_unlock_irq(&pDevice->lock);
236 if(param->u.wpa_key.key && fcpfkernel) { 221 if (param->u.wpa_key.key && fcpfkernel) {
237 memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len); 222 memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len);
238 } 223 } else {
239 else { 224 if (param->u.wpa_key.key &&
240 if (param->u.wpa_key.key && 225 copy_from_user(&abyKey[0], param->u.wpa_key.key,
241 copy_from_user(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len)) { 226 param->u.wpa_key.key_len)) {
242 spin_lock_irq(&pDevice->lock); 227 spin_lock_irq(&pDevice->lock);
243 return -EINVAL; 228 return -EINVAL;
229 }
244 } 230 }
245 } 231 spin_lock_irq(&pDevice->lock);
246 spin_lock_irq(&pDevice->lock);
247 232
248 dwKeyIndex = (DWORD)(param->u.wpa_key.key_index); 233 dwKeyIndex = (DWORD)(param->u.wpa_key.key_index);
249 234
250 if (param->u.wpa_key.alg_name == WPA_ALG_WEP) { 235 if (param->u.wpa_key.alg_name == WPA_ALG_WEP) {
251 if (dwKeyIndex > 3) { 236 if (dwKeyIndex > 3) {
252 return -EINVAL; 237 return -EINVAL;
253 } 238 } else {
254 else { 239 if (param->u.wpa_key.set_tx) {
255 if (param->u.wpa_key.set_tx) { 240 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
256 pDevice->byKeyIndex = (BYTE)dwKeyIndex; 241 pDevice->bTransmitKey = TRUE;
257 pDevice->bTransmitKey = TRUE; 242 dwKeyIndex |= (1 << 31);
258 dwKeyIndex |= (1 << 31); 243 }
259 } 244 KeybSetDefaultKey( pDevice,
260 KeybSetDefaultKey( pDevice, 245 &(pDevice->sKey),
261 &(pDevice->sKey), 246 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
262 dwKeyIndex & ~(BIT30 | USE_KEYRSC), 247 param->u.wpa_key.key_len,
263 param->u.wpa_key.key_len, 248 NULL,
264 NULL, 249 abyKey,
265 abyKey, 250 KEY_CTL_WEP
266 KEY_CTL_WEP 251 );
267 ); 252
268 253 }
269 } 254 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
270 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; 255 pDevice->bEncryptionEnable = TRUE;
271 pDevice->bEncryptionEnable = TRUE; 256 return ret;
272 return ret;
273 } 257 }
274 258
275 259
276 if (param->u.wpa_key.seq && param->u.wpa_key.seq_len > sizeof(abySeq)) 260 if (param->u.wpa_key.seq && param->u.wpa_key.seq_len > sizeof(abySeq))
277 return -EINVAL; 261 return -EINVAL;
278 262
279 spin_unlock_irq(&pDevice->lock); 263 spin_unlock_irq(&pDevice->lock);
280 if(param->u.wpa_key.seq && fcpfkernel) { 264 if (param->u.wpa_key.seq && fcpfkernel) {
281 memcpy(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len); 265 memcpy(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len);
282 } 266 } else {
283 else { 267 if (param->u.wpa_key.seq &&
284 if (param->u.wpa_key.seq && 268 copy_from_user(&abySeq[0], param->u.wpa_key.seq,
285 copy_from_user(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len)) { 269 param->u.wpa_key.seq_len)) {
286 spin_lock_irq(&pDevice->lock); 270 spin_lock_irq(&pDevice->lock);
287 return -EINVAL; 271 return -EINVAL;
288 } 272 }
289 } 273 }
290 spin_lock_irq(&pDevice->lock); 274 spin_lock_irq(&pDevice->lock);
291 275
292 if (param->u.wpa_key.seq_len > 0) { 276 if (param->u.wpa_key.seq_len > 0) {
293 for (ii = 0 ; ii < param->u.wpa_key.seq_len ; ii++) { 277 for (ii = 0 ; ii < param->u.wpa_key.seq_len ; ii++) {
294 if (ii < 4) 278 if (ii < 4)
295 LODWORD(KeyRSC) |= (abySeq[ii] << (ii * 8)); 279 LODWORD(KeyRSC) |= (abySeq[ii] << (ii * 8));
296 else 280 else
297 HIDWORD(KeyRSC) |= (abySeq[ii] << ((ii-4) * 8)); 281 HIDWORD(KeyRSC) |= (abySeq[ii] << ((ii-4) * 8));
298 //KeyRSC |= (abySeq[ii] << (ii * 8));
299 } 282 }
300 dwKeyIndex |= 1 << 29; 283 dwKeyIndex |= 1 << 29;
301 } 284 }
302 285
303 if (param->u.wpa_key.key_index >= MAX_GROUP_KEY) { 286 if (param->u.wpa_key.key_index >= MAX_GROUP_KEY) {
304 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return dwKeyIndex > 3\n"); 287 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return dwKeyIndex > 3\n");
305 return -EINVAL; 288 return -EINVAL;
306 } 289 }
307 290
308 if (param->u.wpa_key.alg_name == WPA_ALG_TKIP) { 291 if (param->u.wpa_key.alg_name == WPA_ALG_TKIP) {
309 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; 292 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
310 } 293 }
311 294
312 if (param->u.wpa_key.alg_name == WPA_ALG_CCMP) { 295 if (param->u.wpa_key.alg_name == WPA_ALG_CCMP) {
313 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; 296 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
314 } 297 }
315 298
316 if (param->u.wpa_key.set_tx) 299 if (param->u.wpa_key.set_tx)
317 dwKeyIndex |= (1 << 31); 300 dwKeyIndex |= (1 << 31);
318 301
319 302
320 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) 303 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
321 byKeyDecMode = KEY_CTL_CCMP; 304 byKeyDecMode = KEY_CTL_CCMP;
322 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) 305 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
323 byKeyDecMode = KEY_CTL_TKIP; 306 byKeyDecMode = KEY_CTL_TKIP;
324 else 307 else
325 byKeyDecMode = KEY_CTL_WEP; 308 byKeyDecMode = KEY_CTL_WEP;
326 309
327 // Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled 310 // Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled
328 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) { 311 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
329 if (param->u.wpa_key.key_len == MAX_KEY_LEN) 312 if (param->u.wpa_key.key_len == MAX_KEY_LEN)
330 byKeyDecMode = KEY_CTL_TKIP; 313 byKeyDecMode = KEY_CTL_TKIP;
331 else if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN) 314 else if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
332 byKeyDecMode = KEY_CTL_WEP; 315 byKeyDecMode = KEY_CTL_WEP;
333 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN) 316 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
334 byKeyDecMode = KEY_CTL_WEP; 317 byKeyDecMode = KEY_CTL_WEP;
335 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) { 318 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
336 if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN) 319 if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
337 byKeyDecMode = KEY_CTL_WEP; 320 byKeyDecMode = KEY_CTL_WEP;
338 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN) 321 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
339 byKeyDecMode = KEY_CTL_WEP; 322 byKeyDecMode = KEY_CTL_WEP;
340 } 323 }
341
342 // Check TKIP key length
343 if ((byKeyDecMode == KEY_CTL_TKIP) &&
344 (param->u.wpa_key.key_len != MAX_KEY_LEN)) {
345 // TKIP Key must be 256 bits
346 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - TKIP Key must be 256 bits\n"));
347 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return- TKIP Key must be 256 bits!\n");
348 return -EINVAL;
349 }
350 // Check AES key length
351 if ((byKeyDecMode == KEY_CTL_CCMP) &&
352 (param->u.wpa_key.key_len != AES_KEY_LEN)) {
353 // AES Key must be 128 bits
354 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return - AES Key must be 128 bits\n");
355 return -EINVAL;
356 }
357 324
358 if (is_broadcast_ether_addr(&param->addr[0]) || (param->addr == NULL)) { 325 // Check TKIP key length
359 /* if broadcast, set the key as every key entry's group key */ 326 if ((byKeyDecMode == KEY_CTL_TKIP) &&
360 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Groupe Key Assign.\n"); 327 (param->u.wpa_key.key_len != MAX_KEY_LEN)) {
361 328 // TKIP Key must be 256 bits
362 if ((KeybSetAllGroupKey(pDevice, 329 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return- TKIP Key must be 256 bits!\n");
363 &(pDevice->sKey), 330 return -EINVAL;
364 dwKeyIndex,
365 param->u.wpa_key.key_len,
366 (PQWORD) &(KeyRSC),
367 (PBYTE)abyKey,
368 byKeyDecMode
369 ) == TRUE) &&
370 (KeybSetDefaultKey(pDevice,
371 &(pDevice->sKey),
372 dwKeyIndex,
373 param->u.wpa_key.key_len,
374 (PQWORD) &(KeyRSC),
375 (PBYTE)abyKey,
376 byKeyDecMode
377 ) == TRUE) ) {
378 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");
379
380 } else {
381 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -KeybSetDefaultKey Fail.0\n"));
382 return -EINVAL;
383 }
384
385 } else {
386 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Assign.\n");
387 // BSSID not 0xffffffffffff
388 // Pairwise Key can't be WEP
389 if (byKeyDecMode == KEY_CTL_WEP) {
390 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key can't be WEP\n");
391 return -EINVAL;
392 }
393
394 dwKeyIndex |= (1 << 30); // set pairwise key
395 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
396 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - WMAC_CONFIG_IBSS_STA\n"));
397 return -EINVAL;
398 }
399 if (KeybSetKey(pDevice,
400 &(pDevice->sKey),
401 &param->addr[0],
402 dwKeyIndex,
403 param->u.wpa_key.key_len,
404 (PQWORD) &(KeyRSC),
405 (PBYTE)abyKey,
406 byKeyDecMode
407 ) == TRUE) {
408 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");
409
410 } else {
411 // Key Table Full
412 if (!compare_ether_addr(&param->addr[0], pDevice->abyBSSID)) {
413 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
414 return -EINVAL;
415
416 } else {
417 // Save Key and configure just before associate/reassociate to BSSID
418 // we do not implement now
419 return -EINVAL;
420 }
421 }
422 } // BSSID not 0xffffffffffff
423 if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
424 pDevice->byKeyIndex = (BYTE)param->u.wpa_key.key_index;
425 pDevice->bTransmitKey = TRUE;
426 } 331 }
427 pDevice->bEncryptionEnable = TRUE; 332 // Check AES key length
333 if ((byKeyDecMode == KEY_CTL_CCMP) &&
334 (param->u.wpa_key.key_len != AES_KEY_LEN)) {
335 // AES Key must be 128 bits
336 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return - AES Key must be 128 bits\n");
337 return -EINVAL;
338 }
428 339
429/* 340 if (is_broadcast_ether_addr(&param->addr[0]) || (param->addr == NULL)) {
430 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n", 341 /* if broadcast, set the key as every key entry's group key */
431 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][0], 342 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Groupe Key Assign.\n");
432 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][1], 343
433 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][2], 344 if ((KeybSetAllGroupKey(pDevice, &(pDevice->sKey), dwKeyIndex,
434 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][3], 345 param->u.wpa_key.key_len,
435 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][4] 346 (PQWORD) &(KeyRSC),
436 ); 347 (PBYTE)abyKey,
437*/ 348 byKeyDecMode
349 ) == TRUE) &&
350 (KeybSetDefaultKey(pDevice,
351 &(pDevice->sKey),
352 dwKeyIndex,
353 param->u.wpa_key.key_len,
354 (PQWORD) &(KeyRSC),
355 (PBYTE)abyKey,
356 byKeyDecMode
357 ) == TRUE) ) {
358 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");
359 } else {
360 return -EINVAL;
361 }
362 } else {
363 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Assign.\n");
364 // BSSID not 0xffffffffffff
365 // Pairwise Key can't be WEP
366 if (byKeyDecMode == KEY_CTL_WEP) {
367 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key can't be WEP\n");
368 return -EINVAL;
369 }
370 dwKeyIndex |= (1 << 30); // set pairwise key
371 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
372 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - WMAC_CONFIG_IBSS_STA\n"));
373 return -EINVAL;
374 }
375 if (KeybSetKey(pDevice, &(pDevice->sKey), &param->addr[0],
376 dwKeyIndex, param->u.wpa_key.key_len,
377 (PQWORD) &(KeyRSC), (PBYTE)abyKey, byKeyDecMode
378 ) == TRUE) {
379 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");
380 } else {
381 // Key Table Full
382 if (!compare_ether_addr(&param->addr[0], pDevice->abyBSSID)) {
383 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
384 return -EINVAL;
385 } else {
386 // Save Key and configure just before associate/reassociate to BSSID
387 // we do not implement now
388 return -EINVAL;
389 }
390 }
391 } // BSSID not 0xffffffffffff
392 if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
393 pDevice->byKeyIndex = (BYTE)param->u.wpa_key.key_index;
394 pDevice->bTransmitKey = TRUE;
395 }
396 pDevice->bEncryptionEnable = TRUE;
438 397
439 return ret; 398 return ret;
440
441} 399}
442 400
443 401
@@ -454,23 +412,17 @@ int wpa_set_wpadev(PSDevice pDevice, int val)
454 * Return Value: 412 * Return Value:
455 * 413 *
456 */ 414 */
457 415static int wpa_set_wpa(PSDevice pDevice, struct viawget_wpa_param *param)
458static int wpa_set_wpa(PSDevice pDevice,
459 struct viawget_wpa_param *param)
460{ 416{
461 417 PSMgmtObject pMgmt = &pDevice->sMgmtObj;
462 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
463 int ret = 0; 418 int ret = 0;
464 419
465 pMgmt->eAuthenMode = WMAC_AUTH_OPEN; 420 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
466 pMgmt->bShareKeyAlgorithm = FALSE; 421 pMgmt->bShareKeyAlgorithm = FALSE;
467 422
468 return ret; 423 return ret;
469} 424}
470 425
471
472
473
474 /* 426 /*
475 * Description: 427 * Description:
476 * set disassociate 428 * set disassociate
@@ -484,25 +436,21 @@ static int wpa_set_wpa(PSDevice pDevice,
484 * Return Value: 436 * Return Value:
485 * 437 *
486 */ 438 */
487 439static int wpa_set_disassociate(PSDevice pDevice, struct viawget_wpa_param *param)
488static int wpa_set_disassociate(PSDevice pDevice,
489 struct viawget_wpa_param *param)
490{ 440{
491 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 441 PSMgmtObject pMgmt = &pDevice->sMgmtObj;
492 int ret = 0; 442 int ret = 0;
493 443
494 spin_lock_irq(&pDevice->lock); 444 spin_lock_irq(&pDevice->lock);
495 if (pDevice->bLinkPass) { 445 if (pDevice->bLinkPass) {
496 if (!memcmp(param->addr, pMgmt->abyCurrBSSID, 6)) 446 if (!memcmp(param->addr, pMgmt->abyCurrBSSID, 6))
497 bScheduleCommand((void *) pDevice, WLAN_CMD_DISASSOCIATE, NULL); 447 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
498 } 448 }
499 spin_unlock_irq(&pDevice->lock); 449 spin_unlock_irq(&pDevice->lock);
500 450
501 return ret; 451 return ret;
502} 452}
503 453
504
505
506/* 454/*
507 * Description: 455 * Description:
508 * enable scan process 456 * enable scan process
@@ -516,36 +464,30 @@ static int wpa_set_disassociate(PSDevice pDevice,
516 * Return Value: 464 * Return Value:
517 * 465 *
518 */ 466 */
519 467static int wpa_set_scan(PSDevice pDevice, struct viawget_wpa_param *param)
520static int wpa_set_scan(PSDevice pDevice,
521 struct viawget_wpa_param *param)
522{ 468{
523 int ret = 0; 469 int ret = 0;
524 470
525/**set ap_scan=1&&scan_ssid=1 under hidden ssid mode**/ 471/**set ap_scan=1&&scan_ssid=1 under hidden ssid mode**/
526 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 472 PSMgmtObject pMgmt = &pDevice->sMgmtObj;
527 PWLAN_IE_SSID pItemSSID; 473 PWLAN_IE_SSID pItemSSID;
528printk("wpa_set_scan-->desired [ssid=%s,ssid_len=%d]\n", 474 printk("wpa_set_scan-->desired [ssid=%s,ssid_len=%d]\n",
529 param->u.scan_req.ssid,param->u.scan_req.ssid_len); 475 param->u.scan_req.ssid,param->u.scan_req.ssid_len);
530// Set the SSID 476// Set the SSID
531memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); 477 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
532pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID; 478 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
533pItemSSID->byElementID = WLAN_EID_SSID; 479 pItemSSID->byElementID = WLAN_EID_SSID;
534memcpy(pItemSSID->abySSID, param->u.scan_req.ssid, param->u.scan_req.ssid_len); 480 memcpy(pItemSSID->abySSID, param->u.scan_req.ssid, param->u.scan_req.ssid_len);
535pItemSSID->len = param->u.scan_req.ssid_len; 481 pItemSSID->len = param->u.scan_req.ssid_len;
536
537 spin_lock_irq(&pDevice->lock);
538 BSSvClearBSSList((void *) pDevice, pDevice->bLinkPass);
539 /* bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL); */
540 bScheduleCommand((void *) pDevice,
541 WLAN_CMD_BSSID_SCAN,
542 pMgmt->abyDesireSSID);
543 spin_unlock_irq(&pDevice->lock);
544
545 return ret;
546}
547 482
483 spin_lock_irq(&pDevice->lock);
484 BSSvClearBSSList((void *) pDevice, pDevice->bLinkPass);
485 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN,
486 pMgmt->abyDesireSSID);
487 spin_unlock_irq(&pDevice->lock);
548 488
489 return ret;
490}
549 491
550/* 492/*
551 * Description: 493 * Description:
@@ -560,19 +502,15 @@ pItemSSID->len = param->u.scan_req.ssid_len;
560 * Return Value: 502 * Return Value:
561 * 503 *
562 */ 504 */
563 505static int wpa_get_bssid(PSDevice pDevice, struct viawget_wpa_param *param)
564static int wpa_get_bssid(PSDevice pDevice,
565 struct viawget_wpa_param *param)
566{ 506{
567 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 507 PSMgmtObject pMgmt = &pDevice->sMgmtObj;
568 int ret = 0; 508 int ret = 0;
569 memcpy(param->u.wpa_associate.bssid, pMgmt->abyCurrBSSID , 6); 509 memcpy(param->u.wpa_associate.bssid, pMgmt->abyCurrBSSID, 6);
570 510
571 return ret; 511 return ret;
572
573} 512}
574 513
575
576/* 514/*
577 * Description: 515 * Description:
578 * get bssid 516 * get bssid
@@ -586,24 +524,20 @@ static int wpa_get_bssid(PSDevice pDevice,
586 * Return Value: 524 * Return Value:
587 * 525 *
588 */ 526 */
589 527static int wpa_get_ssid(PSDevice pDevice, struct viawget_wpa_param *param)
590static int wpa_get_ssid(PSDevice pDevice,
591 struct viawget_wpa_param *param)
592{ 528{
593 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 529 PSMgmtObject pMgmt = &pDevice->sMgmtObj;
594 PWLAN_IE_SSID pItemSSID; 530 PWLAN_IE_SSID pItemSSID;
595 int ret = 0; 531 int ret = 0;
596 532
597 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID; 533 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
598 534
599 memcpy(param->u.wpa_associate.ssid, pItemSSID->abySSID , pItemSSID->len); 535 memcpy(param->u.wpa_associate.ssid, pItemSSID->abySSID, pItemSSID->len);
600 param->u.wpa_associate.ssid_len = pItemSSID->len; 536 param->u.wpa_associate.ssid_len = pItemSSID->len;
601 537
602 return ret; 538 return ret;
603} 539}
604 540
605
606
607/* 541/*
608 * Description: 542 * Description:
609 * get scan results 543 * get scan results
@@ -617,135 +551,114 @@ static int wpa_get_ssid(PSDevice pDevice,
617 * Return Value: 551 * Return Value:
618 * 552 *
619 */ 553 */
620 554static int wpa_get_scan(PSDevice pDevice, struct viawget_wpa_param *param)
621static int wpa_get_scan(PSDevice pDevice,
622 struct viawget_wpa_param *param)
623{ 555{
624 struct viawget_scan_result *scan_buf; 556 struct viawget_scan_result *scan_buf;
625 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 557 PSMgmtObject pMgmt = &pDevice->sMgmtObj;
626 PWLAN_IE_SSID pItemSSID; 558 PWLAN_IE_SSID pItemSSID;
627 PKnownBSS pBSS; 559 PKnownBSS pBSS;
628 PBYTE pBuf; 560 PBYTE pBuf;
629 int ret = 0; 561 int ret = 0;
630 u16 count = 0; 562 u16 count = 0;
631 u16 ii, jj; 563 u16 ii;
632 long ldBm;//James //add 564 u16 jj;
565 long ldBm; //James //add
633 566
634//******mike:bubble sort by stronger RSSI*****// 567//******mike:bubble sort by stronger RSSI*****//
568 PBYTE ptempBSS;
635 569
636 PBYTE ptempBSS; 570 ptempBSS = kmalloc(sizeof(KnownBSS), GFP_ATOMIC);
637
638 571
572 if (ptempBSS == NULL) {
573 printk("bubble sort kmalloc memory fail@@@\n");
574 ret = -ENOMEM;
575 return ret;
576 }
639 577
640 ptempBSS = kmalloc(sizeof(KnownBSS), (int)GFP_ATOMIC); 578 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
641 579 for (jj = 0; jj < MAX_BSS_NUM - ii - 1; jj++) {
642 if (ptempBSS == NULL) { 580 if ((pMgmt->sBSSList[jj].bActive != TRUE)
643 581 || ((pMgmt->sBSSList[jj].uRSSI > pMgmt->sBSSList[jj + 1].uRSSI)
644 printk("bubble sort kmalloc memory fail@@@\n"); 582 && (pMgmt->sBSSList[jj + 1].bActive != FALSE))) {
645 583 memcpy(ptempBSS,&pMgmt->sBSSList[jj], sizeof(KnownBSS));
646 ret = -ENOMEM; 584 memcpy(&pMgmt->sBSSList[jj], &pMgmt->sBSSList[jj + 1],
647 585 sizeof(KnownBSS));
648 return ret; 586 memcpy(&pMgmt->sBSSList[jj + 1], ptempBSS, sizeof(KnownBSS));
649 587 }
650 } 588 }
651 589 }
652 for (ii = 0; ii < MAX_BSS_NUM; ii++) { 590 kfree(ptempBSS);
653
654 for (jj = 0; jj < MAX_BSS_NUM - ii - 1; jj++) {
655
656 if ((pMgmt->sBSSList[jj].bActive != TRUE) ||
657
658 ((pMgmt->sBSSList[jj].uRSSI>pMgmt->sBSSList[jj+1].uRSSI) &&(pMgmt->sBSSList[jj+1].bActive!=FALSE))) {
659
660 memcpy(ptempBSS,&pMgmt->sBSSList[jj],sizeof(KnownBSS));
661
662 memcpy(&pMgmt->sBSSList[jj],&pMgmt->sBSSList[jj+1],sizeof(KnownBSS));
663
664 memcpy(&pMgmt->sBSSList[jj+1],ptempBSS,sizeof(KnownBSS));
665
666 }
667
668 }
669
670 }
671
672 kfree(ptempBSS);
673
674 // printk("bubble sort result:\n");
675 591
676 count = 0; 592 count = 0;
677 pBSS = &(pMgmt->sBSSList[0]); 593 pBSS = &(pMgmt->sBSSList[0]);
678 for (ii = 0; ii < MAX_BSS_NUM; ii++) { 594 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
679 pBSS = &(pMgmt->sBSSList[ii]); 595 pBSS = &(pMgmt->sBSSList[ii]);
680 if (!pBSS->bActive) 596 if (!pBSS->bActive)
681 continue; 597 continue;
682 count++; 598 count++;
683 } 599 }
684 600
685 pBuf = kcalloc(count, sizeof(struct viawget_scan_result), (int)GFP_ATOMIC); 601 pBuf = kcalloc(count, sizeof(struct viawget_scan_result), GFP_ATOMIC);
686 602
687 if (pBuf == NULL) { 603 if (pBuf == NULL) {
688 ret = -ENOMEM; 604 ret = -ENOMEM;
689 return ret; 605 return ret;
690 } 606 }
691 scan_buf = (struct viawget_scan_result *)pBuf; 607 scan_buf = (struct viawget_scan_result *)pBuf;
692 pBSS = &(pMgmt->sBSSList[0]); 608 pBSS = &(pMgmt->sBSSList[0]);
693 for (ii = 0, jj = 0; ii < MAX_BSS_NUM ; ii++) { 609 for (ii = 0, jj = 0; ii < MAX_BSS_NUM; ii++) {
694 pBSS = &(pMgmt->sBSSList[ii]); 610 pBSS = &(pMgmt->sBSSList[ii]);
695 if (pBSS->bActive) { 611 if (pBSS->bActive) {
696 if (jj >= count) 612 if (jj >= count)
697 break; 613 break;
698 memcpy(scan_buf->bssid, pBSS->abyBSSID, WLAN_BSSID_LEN); 614 memcpy(scan_buf->bssid, pBSS->abyBSSID, WLAN_BSSID_LEN);
699 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID; 615 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
700 memcpy(scan_buf->ssid, pItemSSID->abySSID, pItemSSID->len); 616 memcpy(scan_buf->ssid, pItemSSID->abySSID, pItemSSID->len);
701 scan_buf->ssid_len = pItemSSID->len; 617 scan_buf->ssid_len = pItemSSID->len;
702 scan_buf->freq = frequency_list[pBSS->uChannel-1]; 618 scan_buf->freq = frequency_list[pBSS->uChannel-1];
703 scan_buf->caps = pBSS->wCapInfo; //DavidWang for sharemode 619 scan_buf->caps = pBSS->wCapInfo; // DavidWang for sharemode
704 620
705 RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm); 621 RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
706 if(-ldBm<50){ 622 if (-ldBm < 50)
707 scan_buf->qual = 100; 623 scan_buf->qual = 100;
708 }else if(-ldBm > 90) { 624 else if (-ldBm > 90)
709 scan_buf->qual = 0; 625 scan_buf->qual = 0;
710 }else { 626 else
711 scan_buf->qual=(40-(-ldBm-50))*100/40; 627 scan_buf->qual=(40-(-ldBm-50))*100/40;
712 }
713 628
714 //James 629 //James
715 //scan_buf->caps = pBSS->wCapInfo; 630 //scan_buf->caps = pBSS->wCapInfo;
716 //scan_buf->qual = 631 //scan_buf->qual =
717 scan_buf->noise = 0; 632 scan_buf->noise = 0;
718 scan_buf->level = ldBm; 633 scan_buf->level = ldBm;
719 634
720 //scan_buf->maxrate = 635 //scan_buf->maxrate =
721 if (pBSS->wWPALen != 0) { 636 if (pBSS->wWPALen != 0) {
722 scan_buf->wpa_ie_len = pBSS->wWPALen; 637 scan_buf->wpa_ie_len = pBSS->wWPALen;
723 memcpy(scan_buf->wpa_ie, pBSS->byWPAIE, pBSS->wWPALen); 638 memcpy(scan_buf->wpa_ie, pBSS->byWPAIE, pBSS->wWPALen);
724 } 639 }
725 if (pBSS->wRSNLen != 0) { 640 if (pBSS->wRSNLen != 0) {
726 scan_buf->rsn_ie_len = pBSS->wRSNLen; 641 scan_buf->rsn_ie_len = pBSS->wRSNLen;
727 memcpy(scan_buf->rsn_ie, pBSS->byRSNIE, pBSS->wRSNLen); 642 memcpy(scan_buf->rsn_ie, pBSS->byRSNIE, pBSS->wRSNLen);
728 } 643 }
729 scan_buf = (struct viawget_scan_result *)((PBYTE)scan_buf + sizeof(struct viawget_scan_result)); 644 scan_buf = (struct viawget_scan_result *)((PBYTE)scan_buf + sizeof(struct viawget_scan_result));
730 jj ++; 645 jj ++;
731 } 646 }
732 } 647 }
733 648
734 if (jj < count) 649 if (jj < count)
735 count = jj; 650 count = jj;
736 651
737 if (copy_to_user(param->u.scan_results.buf, pBuf, sizeof(struct viawget_scan_result) * count)) { 652 if (copy_to_user(param->u.scan_results.buf, pBuf, sizeof(struct viawget_scan_result) * count))
738 ret = -EFAULT; 653 ret = -EFAULT;
739 } 654
740 param->u.scan_results.scan_count = count; 655 param->u.scan_results.scan_count = count;
741 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " param->u.scan_results.scan_count = %d\n", count) 656 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " param->u.scan_results.scan_count = %d\n", count);
742 657
743 kfree(pBuf); 658 kfree(pBuf);
744 return ret; 659 return ret;
745} 660}
746 661
747
748
749/* 662/*
750 * Description: 663 * Description:
751 * set associate with AP 664 * set associate with AP
@@ -759,25 +672,23 @@ static int wpa_get_scan(PSDevice pDevice,
759 * Return Value: 672 * Return Value:
760 * 673 *
761 */ 674 */
762 675static int wpa_set_associate(PSDevice pDevice, struct viawget_wpa_param *param)
763static int wpa_set_associate(PSDevice pDevice,
764 struct viawget_wpa_param *param)
765{ 676{
766 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 677 PSMgmtObject pMgmt = &pDevice->sMgmtObj;
767 PWLAN_IE_SSID pItemSSID; 678 PWLAN_IE_SSID pItemSSID;
768 BYTE abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 679 BYTE abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
769 BYTE abyWPAIE[64]; 680 BYTE abyWPAIE[64];
770 int ret = 0; 681 int ret = 0;
771 BOOL bwepEnabled=FALSE; 682 BOOL bwepEnabled=FALSE;
772 683
773 // set key type & algorithm 684 // set key type & algorithm
774 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise_suite = %d\n", param->u.wpa_associate.pairwise_suite); 685 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise_suite = %d\n", param->u.wpa_associate.pairwise_suite);
775 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "group_suite = %d\n", param->u.wpa_associate.group_suite); 686 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "group_suite = %d\n", param->u.wpa_associate.group_suite);
776 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key_mgmt_suite = %d\n", param->u.wpa_associate.key_mgmt_suite); 687 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key_mgmt_suite = %d\n", param->u.wpa_associate.key_mgmt_suite);
777 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "auth_alg = %d\n", param->u.wpa_associate.auth_alg); 688 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "auth_alg = %d\n", param->u.wpa_associate.auth_alg);
778 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "mode = %d\n", param->u.wpa_associate.mode); 689 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "mode = %d\n", param->u.wpa_associate.mode);
779 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len); 690 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len);
780 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming dBm = %d\n", param->u.wpa_associate.roam_dbm); //Davidwang 691 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming dBm = %d\n", param->u.wpa_associate.roam_dbm); // Davidwang
781 692
782 if (param->u.wpa_associate.wpa_ie) { 693 if (param->u.wpa_associate.wpa_ie) {
783 if (param->u.wpa_associate.wpa_ie_len > sizeof(abyWPAIE)) 694 if (param->u.wpa_associate.wpa_ie_len > sizeof(abyWPAIE))
@@ -789,25 +700,25 @@ static int wpa_set_associate(PSDevice pDevice,
789 } 700 }
790 701
791 if (param->u.wpa_associate.mode == 1) 702 if (param->u.wpa_associate.mode == 1)
792 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA; 703 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
793 else 704 else
794 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA; 705 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
795 706
796 // set bssid 707 // set bssid
797 if (memcmp(param->u.wpa_associate.bssid, &abyNullAddr[0], 6) != 0) 708 if (memcmp(param->u.wpa_associate.bssid, &abyNullAddr[0], 6) != 0)
798 memcpy(pMgmt->abyDesireBSSID, param->u.wpa_associate.bssid, 6); 709 memcpy(pMgmt->abyDesireBSSID, param->u.wpa_associate.bssid, 6);
799 // set ssid 710 // set ssid
800 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); 711 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
801 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID; 712 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
802 pItemSSID->byElementID = WLAN_EID_SSID; 713 pItemSSID->byElementID = WLAN_EID_SSID;
803 pItemSSID->len = param->u.wpa_associate.ssid_len; 714 pItemSSID->len = param->u.wpa_associate.ssid_len;
804 memcpy(pItemSSID->abySSID, param->u.wpa_associate.ssid, pItemSSID->len); 715 memcpy(pItemSSID->abySSID, param->u.wpa_associate.ssid, pItemSSID->len);
805 716
806 if (param->u.wpa_associate.wpa_ie_len == 0) { 717 if (param->u.wpa_associate.wpa_ie_len == 0) {
807 if (param->u.wpa_associate.auth_alg & AUTH_ALG_SHARED_KEY) 718 if (param->u.wpa_associate.auth_alg & AUTH_ALG_SHARED_KEY)
808 pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY; 719 pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
809 else 720 else
810 pMgmt->eAuthenMode = WMAC_AUTH_OPEN; 721 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
811 } else if (abyWPAIE[0] == RSN_INFO_ELEM) { 722 } else if (abyWPAIE[0] == RSN_INFO_ELEM) {
812 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK) 723 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
813 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK; 724 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
@@ -817,9 +728,9 @@ static int wpa_set_associate(PSDevice pDevice,
817 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_WPA_NONE) 728 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_WPA_NONE)
818 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE; 729 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
819 else if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK) 730 else if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
820 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK; 731 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
821 else 732 else
822 pMgmt->eAuthenMode = WMAC_AUTH_WPA; 733 pMgmt->eAuthenMode = WMAC_AUTH_WPA;
823 } 734 }
824 735
825 switch (param->u.wpa_associate.pairwise_suite) { 736 switch (param->u.wpa_associate.pairwise_suite) {
@@ -833,7 +744,6 @@ static int wpa_set_associate(PSDevice pDevice,
833 case CIPHER_WEP104: 744 case CIPHER_WEP104:
834 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; 745 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
835 bwepEnabled = TRUE; 746 bwepEnabled = TRUE;
836 // printk("****************wpa_set_associate:set CIPHER_WEP40_104\n");
837 break; 747 break;
838 case CIPHER_NONE: 748 case CIPHER_NONE:
839 if (param->u.wpa_associate.group_suite == CIPHER_CCMP) 749 if (param->u.wpa_associate.group_suite == CIPHER_CCMP)
@@ -845,70 +755,64 @@ static int wpa_set_associate(PSDevice pDevice,
845 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; 755 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
846 } 756 }
847 757
848 pMgmt->Roam_dbm = param->u.wpa_associate.roam_dbm; 758 pMgmt->Roam_dbm = param->u.wpa_associate.roam_dbm;
849 // if ((pMgmt->Roam_dbm > 40)&&(pMgmt->Roam_dbm<80)) 759 if (pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) { // @wep-sharekey
850 // pDevice->bEnableRoaming = TRUE; 760 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
851 761 pMgmt->bShareKeyAlgorithm = TRUE;
852 if (pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) { //@wep-sharekey 762 } else if (pMgmt->eAuthenMode == WMAC_AUTH_OPEN) {
853 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; 763 if(bwepEnabled==TRUE) { //@open-wep
854 pMgmt->bShareKeyAlgorithm = TRUE; 764 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
855 } 765 } else {
856 else if (pMgmt->eAuthenMode == WMAC_AUTH_OPEN) { 766 // @only open
857 if(bwepEnabled==TRUE) { //@open-wep 767 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
858 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
859 }
860 else { //@only open
861 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
862 } 768 }
863 } 769 }
864//mike save old encryption status 770 // mike save old encryption status
865 pDevice->eOldEncryptionStatus = pDevice->eEncryptionStatus; 771 pDevice->eOldEncryptionStatus = pDevice->eEncryptionStatus;
866 772
867 if (pDevice->eEncryptionStatus != Ndis802_11EncryptionDisabled) 773 if (pDevice->eEncryptionStatus != Ndis802_11EncryptionDisabled)
868 pDevice->bEncryptionEnable = TRUE; 774 pDevice->bEncryptionEnable = TRUE;
869 else 775 else
870 pDevice->bEncryptionEnable = FALSE; 776 pDevice->bEncryptionEnable = FALSE;
871
872 if ((pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) ||
873 ((pMgmt->eAuthenMode == WMAC_AUTH_OPEN) && (bwepEnabled==TRUE))) {
874 //mike re-comment:open-wep && sharekey-wep needn't do initial key!!
875
876 }
877 else
878 KeyvInitTable(pDevice,&pDevice->sKey);
879 777
880 spin_lock_irq(&pDevice->lock); 778 if ((pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) ||
881 pDevice->bLinkPass = FALSE; 779 ((pMgmt->eAuthenMode == WMAC_AUTH_OPEN) && (bwepEnabled==TRUE))) {
882 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); 780 // mike re-comment:open-wep && sharekey-wep needn't do initial key!!
883 memset(pMgmt->abyCurrBSSID, 0, 6); 781 } else {
884 pMgmt->eCurrState = WMAC_STATE_IDLE; 782 KeyvInitTable(pDevice,&pDevice->sKey);
885 netif_stop_queue(pDevice->dev); 783 }
886 784
887/*******search if ap_scan=2 ,which is associating request in hidden ssid mode ****/ 785 spin_lock_irq(&pDevice->lock);
888{ 786 pDevice->bLinkPass = FALSE;
889 PKnownBSS pCurr = NULL; 787 ControlvMaskByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PAPEDELAY, LEDSTS_STS, LEDSTS_SLOW);
890 pCurr = BSSpSearchBSSList(pDevice, 788 memset(pMgmt->abyCurrBSSID, 0, 6);
891 pMgmt->abyDesireBSSID, 789 pMgmt->eCurrState = WMAC_STATE_IDLE;
892 pMgmt->abyDesireSSID, 790 netif_stop_queue(pDevice->dev);
893 pDevice->eConfigPHYMode 791
894 ); 792/******* search if ap_scan=2, which is associating request in hidden ssid mode ****/
895 793 {
896 if (pCurr == NULL){ 794 PKnownBSS pCurr = NULL;
897 printk("wpa_set_associate---->hidden mode site survey before associate.......\n"); 795 pCurr = BSSpSearchBSSList(pDevice,
898 bScheduleCommand((void *) pDevice, 796 pMgmt->abyDesireBSSID,
899 WLAN_CMD_BSSID_SCAN, 797 pMgmt->abyDesireSSID,
900 pMgmt->abyDesireSSID); 798 pDevice->eConfigPHYMode
901 } 799 );
902} 800
801 if (pCurr == NULL){
802 printk("wpa_set_associate---->hidden mode site survey before associate.......\n");
803 bScheduleCommand((void *)pDevice,
804 WLAN_CMD_BSSID_SCAN,
805 pMgmt->abyDesireSSID);
806 }
807 }
903/****************************************************************/ 808/****************************************************************/
904 809
905 bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL); 810 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
906 spin_unlock_irq(&pDevice->lock); 811 spin_unlock_irq(&pDevice->lock);
907 812
908 return ret; 813 return ret;
909} 814}
910 815
911
912/* 816/*
913 * Description: 817 * Description:
914 * wpa_ioctl main function supported for wpa supplicant 818 * wpa_ioctl main function supported for wpa supplicant
@@ -922,7 +826,6 @@ static int wpa_set_associate(PSDevice pDevice,
922 * Return Value: 826 * Return Value:
923 * 827 *
924 */ 828 */
925
926int wpa_ioctl(PSDevice pDevice, struct iw_point *p) 829int wpa_ioctl(PSDevice pDevice, struct iw_point *p)
927{ 830{
928 struct viawget_wpa_param *param; 831 struct viawget_wpa_param *param;
@@ -930,10 +833,10 @@ int wpa_ioctl(PSDevice pDevice, struct iw_point *p)
930 int wpa_ioctl = 0; 833 int wpa_ioctl = 0;
931 834
932 if (p->length < sizeof(struct viawget_wpa_param) || 835 if (p->length < sizeof(struct viawget_wpa_param) ||
933 p->length > VIAWGET_WPA_MAX_BUF_SIZE || !p->pointer) 836 p->length > VIAWGET_WPA_MAX_BUF_SIZE || !p->pointer)
934 return -EINVAL; 837 return -EINVAL;
935 838
936 param = kmalloc((int)p->length, (int)GFP_KERNEL); 839 param = kmalloc((int)p->length, GFP_KERNEL);
937 if (param == NULL) 840 if (param == NULL)
938 return -ENOMEM; 841 return -ENOMEM;
939 842
@@ -944,63 +847,62 @@ int wpa_ioctl(PSDevice pDevice, struct iw_point *p)
944 847
945 switch (param->cmd) { 848 switch (param->cmd) {
946 case VIAWGET_SET_WPA: 849 case VIAWGET_SET_WPA:
947 ret = wpa_set_wpa(pDevice, param); 850 ret = wpa_set_wpa(pDevice, param);
948 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_WPA \n"); 851 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_WPA \n");
949 break; 852 break;
950 853
951 case VIAWGET_SET_KEY: 854 case VIAWGET_SET_KEY:
952 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_KEY \n"); 855 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_KEY \n");
953 spin_lock_irq(&pDevice->lock); 856 spin_lock_irq(&pDevice->lock);
954 ret = wpa_set_keys(pDevice, param, FALSE); 857 ret = wpa_set_keys(pDevice, param, FALSE);
955 spin_unlock_irq(&pDevice->lock); 858 spin_unlock_irq(&pDevice->lock);
956 break; 859 break;
957 860
958 case VIAWGET_SET_SCAN: 861 case VIAWGET_SET_SCAN:
959 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_SCAN \n"); 862 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_SCAN \n");
960 ret = wpa_set_scan(pDevice, param); 863 ret = wpa_set_scan(pDevice, param);
961 break; 864 break;
962 865
963 case VIAWGET_GET_SCAN: 866 case VIAWGET_GET_SCAN:
964 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SCAN\n"); 867 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SCAN\n");
965 ret = wpa_get_scan(pDevice, param); 868 ret = wpa_get_scan(pDevice, param);
966 wpa_ioctl = 1; 869 wpa_ioctl = 1;
967 break; 870 break;
968 871
969 case VIAWGET_GET_SSID: 872 case VIAWGET_GET_SSID:
970 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SSID \n"); 873 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SSID \n");
971 ret = wpa_get_ssid(pDevice, param); 874 ret = wpa_get_ssid(pDevice, param);
972 wpa_ioctl = 1; 875 wpa_ioctl = 1;
973 break; 876 break;
974 877
975 case VIAWGET_GET_BSSID: 878 case VIAWGET_GET_BSSID:
976 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_BSSID \n"); 879 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_BSSID \n");
977 ret = wpa_get_bssid(pDevice, param); 880 ret = wpa_get_bssid(pDevice, param);
978 wpa_ioctl = 1; 881 wpa_ioctl = 1;
979 break; 882 break;
980 883
981 case VIAWGET_SET_ASSOCIATE: 884 case VIAWGET_SET_ASSOCIATE:
982 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_ASSOCIATE \n"); 885 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_ASSOCIATE \n");
983 ret = wpa_set_associate(pDevice, param); 886 ret = wpa_set_associate(pDevice, param);
984 break; 887 break;
985 888
986 case VIAWGET_SET_DISASSOCIATE: 889 case VIAWGET_SET_DISASSOCIATE:
987 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DISASSOCIATE \n"); 890 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DISASSOCIATE \n");
988 ret = wpa_set_disassociate(pDevice, param); 891 ret = wpa_set_disassociate(pDevice, param);
989 break; 892 break;
990 893
991 case VIAWGET_SET_DROP_UNENCRYPT: 894 case VIAWGET_SET_DROP_UNENCRYPT:
992 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DROP_UNENCRYPT \n"); 895 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DROP_UNENCRYPT \n");
993 break; 896 break;
994 897
995 case VIAWGET_SET_DEAUTHENTICATE: 898 case VIAWGET_SET_DEAUTHENTICATE:
996 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DEAUTHENTICATE \n"); 899 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DEAUTHENTICATE \n");
997 break; 900 break;
998 901
999 default: 902 default:
1000 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ioctl: unknown cmd=%d\n", 903 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ioctl: unknown cmd=%d\n",
1001 param->cmd); 904 param->cmd);
1002 return -EOPNOTSUPP; 905 return -EOPNOTSUPP;
1003 break;
1004 } 906 }
1005 907
1006 if ((ret == 0) && wpa_ioctl) { 908 if ((ret == 0) && wpa_ioctl) {
@@ -1012,7 +914,5 @@ int wpa_ioctl(PSDevice pDevice, struct iw_point *p)
1012 914
1013out: 915out:
1014 kfree(param); 916 kfree(param);
1015
1016 return ret; 917 return ret;
1017} 918}
1018