e4fdb6fc6eab14858f443ddbaf96125c1d930014
[deliverable/linux.git] / drivers / staging / vt6656 / iwctl.c
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: iwctl.c
20 *
21 * Purpose: wireless ext & ioctl functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: July 5, 2006
26 *
27 * Functions:
28 *
29 * Revision History:
30 *
31 */
32
33
34 #if !defined(__DEVICE_H__)
35 #include "device.h"
36 #endif
37 #if !defined(__IOCTL_H__)
38 #include "ioctl.h"
39 #endif
40 #if !defined(__IOCMD_H__)
41 #include "iocmd.h"
42 #endif
43 #if !defined(__MAC_H__)
44 #include "mac.h"
45 #endif
46 #if !defined(__CARD_H__)
47 #include "card.h"
48 #endif
49 #if !defined(__HOSTAP_H__)
50 #include "hostap.h"
51 #endif
52 #if !defined(__UMEM_H__)
53 #include "umem.h"
54 #endif
55 #if !defined(__POWER_H__)
56 #include "power.h"
57 #endif
58 #if !defined(__RF_H__)
59 #include "rf.h"
60 #endif
61
62 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
63 #if !defined(__IOWPA_H__)
64 #include "iowpa.h"
65 #endif
66 #if !defined(__WPACTL_H__)
67 #include "wpactl.h"
68 #endif
69 #endif
70
71 #include <net/iw_handler.h>
72
73
74 /*--------------------- Static Definitions -------------------------*/
75
76 //2008-0409-07, <Add> by Einsn Liu
77 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
78 #define SUPPORTED_WIRELESS_EXT 18
79 #else
80 #define SUPPORTED_WIRELESS_EXT 17
81 #endif
82
83 static const long frequency_list[] = {
84 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
85 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
86 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
87 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
88 5700, 5745, 5765, 5785, 5805, 5825
89 };
90
91
92 /*--------------------- Static Classes ----------------------------*/
93
94
95 //static int msglevel =MSG_LEVEL_DEBUG;
96 static int msglevel =MSG_LEVEL_INFO;
97
98
99 /*--------------------- Static Variables --------------------------*/
100 /*--------------------- Static Functions --------------------------*/
101
102 /*--------------------- Export Variables --------------------------*/
103
104 struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
105 {
106 PSDevice pDevice = netdev_priv(dev);
107 long ldBm;
108
109 pDevice->wstats.status = pDevice->eOPMode;
110 #ifdef Calcu_LinkQual
111 #if 0
112 if(pDevice->byBBType == BB_TYPE_11B) {
113 if(pDevice->byCurrSQ > 120)
114 pDevice->scStatistic.LinkQuality = 100;
115 else
116 pDevice->scStatistic.LinkQuality = pDevice->byCurrSQ*100/120;
117 }
118 else if(pDevice->byBBType == BB_TYPE_11G) {
119 if(pDevice->byCurrSQ < 20)
120 pDevice->scStatistic.LinkQuality = 100;
121 else if(pDevice->byCurrSQ >96)
122 pDevice->scStatistic.LinkQuality = 0;
123 else
124 pDevice->scStatistic.LinkQuality = (96-pDevice->byCurrSQ)*100/76;
125 }
126 if(pDevice->bLinkPass !=TRUE)
127 pDevice->scStatistic.LinkQuality = 0;
128 #endif
129 if(pDevice->scStatistic.LinkQuality > 100)
130 pDevice->scStatistic.LinkQuality = 100;
131 pDevice->wstats.qual.qual =(BYTE) pDevice->scStatistic.LinkQuality;
132 #else
133 pDevice->wstats.qual.qual = pDevice->byCurrSQ;
134 #endif
135 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
136 pDevice->wstats.qual.level = ldBm;
137 //pDevice->wstats.qual.level = 0x100 - pDevice->uCurrRSSI;
138 pDevice->wstats.qual.noise = 0;
139 pDevice->wstats.qual.updated = 1;
140 pDevice->wstats.discard.nwid = 0;
141 pDevice->wstats.discard.code = 0;
142 pDevice->wstats.discard.fragment = 0;
143 pDevice->wstats.discard.retries = pDevice->scStatistic.dwTsrErr;
144 pDevice->wstats.discard.misc = 0;
145 pDevice->wstats.miss.beacon = 0;
146
147 return &pDevice->wstats;
148 }
149
150
151
152 /*------------------------------------------------------------------*/
153
154
155 static int iwctl_commit(struct net_device *dev,
156 struct iw_request_info *info,
157 void *wrq,
158 char *extra)
159 {
160 //2008-0409-02, <Mark> by Einsn Liu
161 /*
162 #ifdef Safe_Close
163 PSDevice pDevice = (PSDevice)netdev_priv(dev);
164 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
165 return -EINVAL;
166 #endif
167 */
168 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWCOMMIT \n");
169
170 return 0;
171
172 }
173
174 /*
175 * Wireless Handler : get protocol name
176 */
177
178 int iwctl_giwname(struct net_device *dev,
179 struct iw_request_info *info,
180 char *wrq,
181 char *extra)
182 {
183 strcpy(wrq, "802.11-a/b/g");
184 return 0;
185 }
186
187 int iwctl_giwnwid(struct net_device *dev,
188 struct iw_request_info *info,
189 struct iw_param *wrq,
190 char *extra)
191 {
192 //wrq->value = 0x100;
193 //wrq->disabled = 0;
194 //wrq->fixed = 1;
195 //return 0;
196 return -EOPNOTSUPP;
197 }
198 /*
199 * Wireless Handler : set scan
200 */
201
202 int iwctl_siwscan(struct net_device *dev,
203 struct iw_request_info *info,
204 struct iw_point *wrq,
205 char *extra)
206 {
207 PSDevice pDevice = (PSDevice)netdev_priv(dev);
208 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
209 struct iw_scan_req *req = (struct iw_scan_req *)extra;
210 BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
211 PWLAN_IE_SSID pItemSSID=NULL;
212
213 //2008-0920-01<Add>by MikeLiu
214 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
215 return -EINVAL;
216
217 PRINT_K(" SIOCSIWSCAN \n");
218
219 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
220 // In scanning..
221 PRINT_K("SIOCSIWSCAN(overlap??)-->In scanning...\n");
222 return -EAGAIN;
223 }
224
225 if(pDevice->byReAssocCount > 0) { //reject scan when re-associating!
226 //send scan event to wpa_Supplicant
227 union iwreq_data wrqu;
228 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
229 memset(&wrqu, 0, sizeof(wrqu));
230 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
231 return 0;
232 }
233
234 spin_lock_irq(&pDevice->lock);
235
236 #ifdef update_BssList
237 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
238 #endif
239
240 //mike add: active scan OR passive scan OR desire_ssid scan
241 if(wrq->length == sizeof(struct iw_scan_req)) {
242 if (wrq->flags & IW_SCAN_THIS_ESSID) { //desire_ssid scan
243 memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
244 pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
245 pItemSSID->byElementID = WLAN_EID_SSID;
246 memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
247 if (pItemSSID->abySSID[req->essid_len - 1] == '\0') {
248 if(req->essid_len>0)
249 pItemSSID->len = req->essid_len - 1;
250 }
251 else
252 pItemSSID->len = req->essid_len;
253 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
254 PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n",((PWLAN_IE_SSID)abyScanSSID)->abySSID,
255 ((PWLAN_IE_SSID)abyScanSSID)->len);
256 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
257 spin_unlock_irq(&pDevice->lock);
258
259 return 0;
260 }
261 else if(req->scan_type == IW_SCAN_TYPE_PASSIVE) { //passive scan
262 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
263 }
264 }
265 else { //active scan
266 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
267 }
268
269 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
270 //printk("SIOCSIWSCAN:WLAN_CMD_BSSID_SCAN\n");
271 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
272 spin_unlock_irq(&pDevice->lock);
273
274 return 0;
275 }
276
277
278 /*
279 * Wireless Handler : get scan results
280 */
281
282 int iwctl_giwscan(struct net_device *dev,
283 struct iw_request_info *info,
284 struct iw_point *wrq,
285 char *extra)
286 {
287 int ii, jj, kk;
288 PSDevice pDevice = (PSDevice)netdev_priv(dev);
289 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
290 PKnownBSS pBSS;
291 PWLAN_IE_SSID pItemSSID;
292 PWLAN_IE_SUPP_RATES pSuppRates, pExtSuppRates;
293 char *current_ev = extra;
294 char *end_buf = extra + IW_SCAN_MAX_DATA;
295 char *current_val = NULL;
296 struct iw_event iwe;
297 long ldBm;
298 char buf[MAX_WPA_IE_LEN * 2 + 30];
299
300 //2008-0409-02, <Mark> by Einsn Liu
301 /*
302 #ifdef Safe_Close
303 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
304 return -EINVAL;
305 #endif
306 */
307 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSCAN \n");
308
309 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
310 // In scanning..
311 return -EAGAIN;
312 }
313 pBSS = &(pMgmt->sBSSList[0]);
314 for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) {
315 if (current_ev >= end_buf)
316 break;
317 pBSS = &(pMgmt->sBSSList[jj]);
318 if (pBSS->bActive) {
319 //ADD mac address
320 memset(&iwe, 0, sizeof(iwe));
321 iwe.cmd = SIOCGIWAP;
322 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
323 memcpy(iwe.u.ap_addr.sa_data, pBSS->abyBSSID, WLAN_BSSID_LEN);
324 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
325 //ADD ssid
326 memset(&iwe, 0, sizeof(iwe));
327 iwe.cmd = SIOCGIWESSID;
328 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
329 iwe.u.data.length = pItemSSID->len;
330 iwe.u.data.flags = 1;
331 current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID);
332 //ADD mode
333 memset(&iwe, 0, sizeof(iwe));
334 iwe.cmd = SIOCGIWMODE;
335 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo)) {
336 iwe.u.mode = IW_MODE_INFRA;
337 }
338 else {
339 iwe.u.mode = IW_MODE_ADHOC;
340 }
341 iwe.len = IW_EV_UINT_LEN;
342 current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
343 //ADD frequency
344 pSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abySuppRates;
345 pExtSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abyExtSuppRates;
346 memset(&iwe, 0, sizeof(iwe));
347 iwe.cmd = SIOCGIWFREQ;
348 iwe.u.freq.m = pBSS->uChannel;
349 iwe.u.freq.e = 0;
350 iwe.u.freq.i = 0;
351 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
352 //2008-0409-04, <Add> by Einsn Liu
353 {
354 int f = (int)pBSS->uChannel - 1;
355 if(f < 0)f = 0;
356 iwe.u.freq.m = frequency_list[f] * 100000;
357 iwe.u.freq.e = 1;
358 }
359 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
360 //ADD quality
361 memset(&iwe, 0, sizeof(iwe));
362 iwe.cmd = IWEVQUAL;
363 RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
364 iwe.u.qual.level = ldBm;
365 iwe.u.qual.noise = 0;
366 //2008-0409-01, <Add> by Einsn Liu
367 if(-ldBm<50){
368 iwe.u.qual.qual = 100;
369 }else if(-ldBm > 90) {
370 iwe.u.qual.qual = 0;
371 }else {
372 iwe.u.qual.qual=(40-(-ldBm-50))*100/40;
373 }
374 iwe.u.qual.updated=7;
375
376 //2008-0409-01, <Mark> by Einsn Liu
377 /*
378 //2008-0220-03, <Modify> by Einsn Liu
379 if(pDevice->bLinkPass== TRUE && IS_ETH_ADDRESS_EQUAL(pBSS->abyBSSID, pMgmt->abyCurrBSSID)){
380 #ifdef Calcu_LinkQual
381 #if 0
382 if(pDevice->byBBType == BB_TYPE_11B) {
383 if(pDevice->byCurrSQ > 120)
384 pDevice->scStatistic.LinkQuality = 100;
385 else
386 pDevice->scStatistic.LinkQuality = pDevice->byCurrSQ*100/120;
387 }
388 else if(pDevice->byBBType == BB_TYPE_11G) {
389 if(pDevice->byCurrSQ < 20)
390 pDevice->scStatistic.LinkQuality = 100;
391 else if(pDevice->byCurrSQ >96)
392 pDevice->scStatistic.LinkQuality = 0;
393 else
394 pDevice->scStatistic.LinkQuality = (96-pDevice->byCurrSQ)*100/76;
395 }
396 if(pDevice->bLinkPass !=TRUE)
397 pDevice->scStatistic.LinkQuality = 0;
398 #endif
399 if(pDevice->scStatistic.LinkQuality > 100)
400 pDevice->scStatistic.LinkQuality = 100;
401 iwe.u.qual.qual =(BYTE) pDevice->scStatistic.LinkQuality;
402 #else
403 iwe.u.qual.qual = pDevice->byCurrSQ;
404 #endif
405 }else {
406 iwe.u.qual.qual = 0;
407 }
408 */
409 current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
410 //ADD encryption
411 memset(&iwe, 0, sizeof(iwe));
412 iwe.cmd = SIOCGIWENCODE;
413 iwe.u.data.length = 0;
414 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo)) {
415 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
416 }else {
417 iwe.u.data.flags = IW_ENCODE_DISABLED;
418 }
419 current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID);
420
421 memset(&iwe, 0, sizeof(iwe));
422 iwe.cmd = SIOCGIWRATE;
423 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
424 current_val = current_ev + IW_EV_LCP_LEN;
425
426 for (kk = 0 ; kk < 12 ; kk++) {
427 if (pSuppRates->abyRates[kk] == 0)
428 break;
429 // Bit rate given in 500 kb/s units (+ 0x80)
430 iwe.u.bitrate.value = ((pSuppRates->abyRates[kk] & 0x7f) * 500000);
431 current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
432 }
433 for (kk = 0 ; kk < 8 ; kk++) {
434 if (pExtSuppRates->abyRates[kk] == 0)
435 break;
436 // Bit rate given in 500 kb/s units (+ 0x80)
437 iwe.u.bitrate.value = ((pExtSuppRates->abyRates[kk] & 0x7f) * 500000);
438 current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
439 }
440
441 if((current_val - current_ev) > IW_EV_LCP_LEN)
442 current_ev = current_val;
443
444 memset(&iwe, 0, sizeof(iwe));
445 iwe.cmd = IWEVCUSTOM;
446 sprintf(buf, "bcn_int=%d", pBSS->wBeaconInterval);
447 iwe.u.data.length = strlen(buf);
448 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, buf);
449
450 if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) {
451 memset(&iwe, 0, sizeof(iwe));
452 iwe.cmd = IWEVGENIE;
453 iwe.u.data.length = pBSS->wWPALen;
454 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byWPAIE);
455 }
456
457 if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) {
458 memset(&iwe, 0, sizeof(iwe));
459 iwe.cmd = IWEVGENIE;
460 iwe.u.data.length = pBSS->wRSNLen;
461 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byRSNIE);
462 }
463
464 }
465 }// for
466
467 wrq->length = current_ev - extra;
468 return 0;
469
470 }
471
472
473 /*
474 * Wireless Handler : set frequence or channel
475 */
476
477 int iwctl_siwfreq(struct net_device *dev,
478 struct iw_request_info *info,
479 struct iw_freq *wrq,
480 char *extra)
481 {
482 PSDevice pDevice = (PSDevice)netdev_priv(dev);
483 int rc = 0;
484
485 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFREQ \n");
486
487 // If setting by frequency, convert to a channel
488 if((wrq->e == 1) &&
489 (wrq->m >= (int) 2.412e8) &&
490 (wrq->m <= (int) 2.487e8)) {
491 int f = wrq->m / 100000;
492 int c = 0;
493 while((c < 14) && (f != frequency_list[c]))
494 c++;
495 wrq->e = 0;
496 wrq->m = c + 1;
497 }
498 // Setting by channel number
499 if((wrq->m > 14) || (wrq->e > 0))
500 rc = -EOPNOTSUPP;
501 else {
502 int channel = wrq->m;
503 if((channel < 1) || (channel > 14)) {
504 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: New channel value of %d is invalid!\n", dev->name, wrq->m);
505 rc = -EINVAL;
506 } else {
507 // Yes ! We can set it !!!
508 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set to channel = %d\n", channel);
509 pDevice->uChannel = channel;
510 }
511 }
512
513 return rc;
514 }
515
516 /*
517 * Wireless Handler : get frequence or channel
518 */
519
520 int iwctl_giwfreq(struct net_device *dev,
521 struct iw_request_info *info,
522 struct iw_freq *wrq,
523 char *extra)
524 {
525 PSDevice pDevice = (PSDevice)netdev_priv(dev);
526 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
527
528 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ \n");
529
530 #ifdef WEXT_USECHANNELS
531 wrq->m = (int)pMgmt->uCurrChannel;
532 wrq->e = 0;
533 #else
534 {
535 int f = (int)pMgmt->uCurrChannel - 1;
536 if(f < 0)
537 f = 0;
538 wrq->m = frequency_list[f] * 100000;
539 wrq->e = 1;
540 }
541 #endif
542
543 return 0;
544 }
545
546 /*
547 * Wireless Handler : set operation mode
548 */
549
550 int iwctl_siwmode(struct net_device *dev,
551 struct iw_request_info *info,
552 __u32 *wmode,
553 char *extra)
554 {
555 PSDevice pDevice = (PSDevice)netdev_priv(dev);
556 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
557 int rc = 0;
558
559 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE \n");
560
561 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP && pDevice->bEnableHostapd) {
562 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Can't set operation mode, hostapd is running \n");
563 return rc;
564 }
565
566 switch(*wmode) {
567
568 case IW_MODE_ADHOC:
569 if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
570 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
571 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
572 pDevice->bCommit = TRUE;
573 }
574 }
575 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc \n");
576 break;
577 case IW_MODE_AUTO:
578 case IW_MODE_INFRA:
579 if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
580 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
581 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
582 pDevice->bCommit = TRUE;
583 }
584 }
585 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure \n");
586 break;
587 case IW_MODE_MASTER:
588
589 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
590 rc = -EOPNOTSUPP;
591 break;
592
593 if (pMgmt->eConfigMode != WMAC_CONFIG_AP) {
594 pMgmt->eConfigMode = WMAC_CONFIG_AP;
595 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
596 pDevice->bCommit = TRUE;
597 }
598 }
599 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point \n");
600 break;
601
602 case IW_MODE_REPEAT:
603 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
604 rc = -EOPNOTSUPP;
605 break;
606 default:
607 rc = -EINVAL;
608 }
609
610 return rc;
611 }
612
613 /*
614 * Wireless Handler : get operation mode
615 */
616
617 int iwctl_giwmode(struct net_device *dev,
618 struct iw_request_info *info,
619 __u32 *wmode,
620 char *extra)
621 {
622 PSDevice pDevice = (PSDevice)netdev_priv(dev);
623 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
624
625
626 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE \n");
627 // If not managed, assume it's ad-hoc
628 switch (pMgmt->eConfigMode) {
629 case WMAC_CONFIG_ESS_STA:
630 *wmode = IW_MODE_INFRA;
631 break;
632 case WMAC_CONFIG_IBSS_STA:
633 *wmode = IW_MODE_ADHOC;
634 break;
635 case WMAC_CONFIG_AUTO:
636 *wmode = IW_MODE_INFRA;
637 break;
638 case WMAC_CONFIG_AP:
639 *wmode = IW_MODE_MASTER;
640 break;
641 default:
642 *wmode = IW_MODE_ADHOC;
643 }
644
645 return 0;
646 }
647
648
649 /*
650 * Wireless Handler : get capability range
651 */
652
653 int iwctl_giwrange(struct net_device *dev,
654 struct iw_request_info *info,
655 struct iw_point *wrq,
656 char *extra)
657 {
658 struct iw_range *range = (struct iw_range *) extra;
659 int i,k;
660 BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
661 //2008-0409-02, <Mark> by Einsn Liu
662 /*
663 #ifdef Safe_Close
664 PSDevice pDevice = (PSDevice)netdev_priv(dev);
665 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
666 return -EINVAL;
667 #endif
668 */
669
670 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRANGE \n");
671 if (wrq->pointer) {
672 wrq->length = sizeof(struct iw_range);
673 memset(range, 0, sizeof(struct iw_range));
674 range->min_nwid = 0x0000;
675 range->max_nwid = 0x0000;
676 range->num_channels = 14;
677 // Should be based on cap_rid.country to give only
678 // what the current card support
679 k = 0;
680 for(i = 0; i < 14; i++) {
681 range->freq[k].i = i + 1; // List index
682 range->freq[k].m = frequency_list[i] * 100000;
683 range->freq[k++].e = 1; // Values in table in MHz -> * 10^5 * 10
684 }
685 range->num_frequency = k;
686 // Hum... Should put the right values there
687 #ifdef Calcu_LinkQual
688 range->max_qual.qual = 100;
689 #else
690 range->max_qual.qual = 255;
691 #endif
692 range->max_qual.level = 0;
693 range->max_qual.noise = 0;
694 range->sensitivity = 255;
695
696 for(i = 0 ; i < 13 ; i++) {
697 range->bitrate[i] = abySupportedRates[i] * 500000;
698 if(range->bitrate[i] == 0)
699 break;
700 }
701 range->num_bitrates = i;
702
703 // Set an indication of the max TCP throughput
704 // in bit/s that we can expect using this interface.
705 // May be use for QoS stuff... Jean II
706 if(i > 2)
707 range->throughput = 5 * 1000 * 1000;
708 else
709 range->throughput = 1.5 * 1000 * 1000;
710
711 range->min_rts = 0;
712 range->max_rts = 2312;
713 range->min_frag = 256;
714 range->max_frag = 2312;
715
716
717 // the encoding capabilities
718 range->num_encoding_sizes = 3;
719 // 64(40) bits WEP
720 range->encoding_size[0] = 5;
721 // 128(104) bits WEP
722 range->encoding_size[1] = 13;
723 // 256 bits for WPA-PSK
724 range->encoding_size[2] = 32;
725 // 4 keys are allowed
726 range->max_encoding_tokens = 4;
727
728 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
729 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
730
731 range->min_pmp = 0;
732 range->max_pmp = 1000000;// 1 secs
733 range->min_pmt = 0;
734 range->max_pmt = 1000000;// 1 secs
735 range->pmp_flags = IW_POWER_PERIOD;
736 range->pmt_flags = IW_POWER_TIMEOUT;
737 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
738
739 // Transmit Power - values are in mW
740
741 range->txpower[0] = 100;
742 range->num_txpower = 1;
743 range->txpower_capa = IW_TXPOW_MWATT;
744 range->we_version_source = SUPPORTED_WIRELESS_EXT;
745 range->we_version_compiled = WIRELESS_EXT;
746 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
747 range->retry_flags = IW_RETRY_LIMIT;
748 range->r_time_flags = IW_RETRY_LIFETIME;
749 range->min_retry = 1;
750 range->max_retry = 65535;
751 range->min_r_time = 1024;
752 range->max_r_time = 65535 * 1024;
753 // Experimental measurements - boundary 11/5.5 Mb/s
754 // Note : with or without the (local->rssi), results
755 // are somewhat different. - Jean II
756 range->avg_qual.qual = 6;
757 range->avg_qual.level = 176; // -80 dBm
758 range->avg_qual.noise = 0;
759 }
760
761
762 return 0;
763 }
764
765
766 /*
767 * Wireless Handler : set ap mac address
768 */
769
770 int iwctl_siwap(struct net_device *dev,
771 struct iw_request_info *info,
772 struct sockaddr *wrq,
773 char *extra)
774 {
775 PSDevice pDevice = (PSDevice)netdev_priv(dev);
776 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
777 int rc = 0;
778 BYTE ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};
779
780 PRINT_K(" SIOCSIWAP \n");
781
782 if (wrq->sa_family != ARPHRD_ETHER)
783 rc = -EINVAL;
784 else {
785 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
786 memcpy(pMgmt->abyDesireBSSID, wrq->sa_data, 6);
787
788 //mike :add
789 if ((IS_BROADCAST_ADDRESS(pMgmt->abyDesireBSSID)) ||
790 (memcmp(pMgmt->abyDesireBSSID, ZeroBSSID, 6) == 0)){
791 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
792 return rc;
793 }
794 //mike add: if desired AP is hidden ssid(there are two same BSSID in list),
795 // then ignore,because you don't known which one to be connect with??
796 {
797 UINT ii , uSameBssidNum=0;
798 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
799 if (pMgmt->sBSSList[ii].bActive &&
800 IS_ETH_ADDRESS_EQUAL(pMgmt->sBSSList[ii].abyBSSID,pMgmt->abyDesireBSSID)) {
801 uSameBssidNum++;
802 }
803 }
804 if(uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
805 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
806 return rc;
807 }
808 }
809
810 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
811 pDevice->bCommit = TRUE;
812 }
813 }
814 return rc;
815 }
816
817 /*
818 * Wireless Handler : get ap mac address
819 */
820
821 int iwctl_giwap(struct net_device *dev,
822 struct iw_request_info *info,
823 struct sockaddr *wrq,
824 char *extra)
825 {
826 PSDevice pDevice = (PSDevice)netdev_priv(dev);
827 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
828
829
830 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP \n");
831
832 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
833
834 //20080123-02,<Modify> by Einsn Liu
835 if ((pDevice->bLinkPass == FALSE) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP))
836 // if ((pDevice->bLinkPass == FALSE) && (pMgmt->eCurrMode == WMAC_MODE_ESS_STA))
837 memset(wrq->sa_data, 0, 6);
838
839 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
840 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
841 }
842
843 wrq->sa_family = ARPHRD_ETHER;
844
845 return 0;
846
847 }
848
849
850 /*
851 * Wireless Handler : get ap list
852 */
853
854 int iwctl_giwaplist(struct net_device *dev,
855 struct iw_request_info *info,
856 struct iw_point *wrq,
857 char *extra)
858 {
859 int ii,jj, rc = 0;
860 struct sockaddr sock[IW_MAX_AP];
861 struct iw_quality qual[IW_MAX_AP];
862 PSDevice pDevice = (PSDevice)netdev_priv(dev);
863 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
864
865
866 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST \n");
867 // Only super-user can see AP list
868
869 if (!capable(CAP_NET_ADMIN)) {
870 rc = -EPERM;
871 return rc;
872 }
873
874 if (wrq->pointer) {
875
876 PKnownBSS pBSS = &(pMgmt->sBSSList[0]);
877
878 for (ii = 0, jj= 0; ii < MAX_BSS_NUM; ii++) {
879 pBSS = &(pMgmt->sBSSList[ii]);
880 if (!pBSS->bActive)
881 continue;
882 if ( jj >= IW_MAX_AP)
883 break;
884 memcpy(sock[jj].sa_data, pBSS->abyBSSID, 6);
885 sock[jj].sa_family = ARPHRD_ETHER;
886 qual[jj].level = pBSS->uRSSI;
887 qual[jj].qual = qual[jj].noise = 0;
888 qual[jj].updated = 2;
889 jj++;
890 }
891
892 wrq->flags = 1; // Should be define'd
893 wrq->length = jj;
894 memcpy(extra, sock, sizeof(struct sockaddr)*jj);
895 memcpy(extra + sizeof(struct sockaddr)*jj, qual, sizeof(struct iw_quality)*jj);
896 }
897
898 return rc;
899 }
900
901
902 /*
903 * Wireless Handler : set essid
904 */
905
906 int iwctl_siwessid(struct net_device *dev,
907 struct iw_request_info *info,
908 struct iw_point *wrq,
909 char *extra)
910 {
911 PSDevice pDevice = (PSDevice)netdev_priv(dev);
912 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
913 PWLAN_IE_SSID pItemSSID;
914
915 //2008-0920-01<Add>by MikeLiu
916 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
917 return -EINVAL;
918
919 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID :\n");
920
921 pDevice->fWPA_Authened = FALSE;
922 // Check if we asked for `any'
923 if(wrq->flags == 0) {
924 // Just send an empty SSID list
925 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
926 memset(pMgmt->abyDesireBSSID, 0xFF,6);
927 PRINT_K("set essid to 'any' \n");
928 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
929 //Unknown desired AP,so here need not associate??
930 return 0;
931 #endif
932 } else {
933 // Set the SSID
934 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
935 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
936 pItemSSID->byElementID = WLAN_EID_SSID;
937
938 memcpy(pItemSSID->abySSID, extra, wrq->length);
939 if (pItemSSID->abySSID[wrq->length - 1] == '\0') {
940 if(wrq->length>0)
941 pItemSSID->len = wrq->length - 1;
942 }
943 else
944 pItemSSID->len = wrq->length;
945 PRINT_K("set essid to %s \n",pItemSSID->abySSID);
946
947 //mike:need clear desiredBSSID
948 if(pItemSSID->len==0) {
949 memset(pMgmt->abyDesireBSSID, 0xFF,6);
950 return 0;
951 }
952
953 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
954 //Wext wil order another command of siwap to link with desired AP,
955 //so here need not associate??
956 if(pDevice->bWPASuppWextEnabled == TRUE) {
957 /*******search if in hidden ssid mode ****/
958 {
959 PKnownBSS pCurr = NULL;
960 BYTE abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
961 UINT ii , uSameBssidNum=0;
962
963 memset(abyTmpDesireSSID,0,sizeof(abyTmpDesireSSID));
964 memcpy(abyTmpDesireSSID,pMgmt->abyDesireSSID,sizeof(abyTmpDesireSSID));
965 pCurr = BSSpSearchBSSList(pDevice,
966 NULL,
967 abyTmpDesireSSID,
968 pDevice->eConfigPHYMode
969 );
970
971 if (pCurr == NULL){
972 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
973 vResetCommandTimer((HANDLE) pDevice);
974 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
975 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
976 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
977 }
978 else { //mike:to find out if that desired SSID is a hidden-ssid AP ,
979 // by means of judging if there are two same BSSID exist in list ?
980 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
981 if (pMgmt->sBSSList[ii].bActive &&
982 IS_ETH_ADDRESS_EQUAL(pMgmt->sBSSList[ii].abyBSSID, pCurr->abyBSSID)) {
983 uSameBssidNum++;
984 }
985 }
986 if(uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
987 PRINT_K("SIOCSIWESSID:hidden ssid directly associate.......\n");
988 vResetCommandTimer((HANDLE) pDevice);
989 pMgmt->eScanType = WMAC_SCAN_PASSIVE; //this scan type,you'll submit scan result!
990 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
991 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
992 }
993 }
994 }
995 return 0;
996 }
997 #endif
998
999 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s \n", pItemSSID->abySSID);
1000 }
1001
1002 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1003 pDevice->bCommit = TRUE;
1004 }
1005
1006
1007 return 0;
1008 }
1009
1010
1011 /*
1012 * Wireless Handler : get essid
1013 */
1014
1015 int iwctl_giwessid(struct net_device *dev,
1016 struct iw_request_info *info,
1017 struct iw_point *wrq,
1018 char *extra)
1019 {
1020
1021 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1022 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1023 PWLAN_IE_SSID pItemSSID;
1024
1025 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID \n");
1026
1027 // Note : if wrq->u.data.flags != 0, we should
1028 // get the relevant SSID from the SSID list...
1029
1030 // Get the current SSID
1031 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
1032 //pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
1033 memcpy(extra, pItemSSID->abySSID , pItemSSID->len);
1034 extra[pItemSSID->len] = '\0';
1035 //2008-0409-03, <Add> by Einsn Liu
1036 wrq->length = pItemSSID->len;
1037 wrq->flags = 1; // active
1038
1039
1040 return 0;
1041 }
1042
1043 /*
1044 * Wireless Handler : set data rate
1045 */
1046
1047 int iwctl_siwrate(struct net_device *dev,
1048 struct iw_request_info *info,
1049 struct iw_param *wrq,
1050 char *extra)
1051 {
1052 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1053 int rc = 0;
1054 u8 brate = 0;
1055 int i;
1056 BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
1057
1058
1059 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE \n");
1060 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1061 rc = -EINVAL;
1062 return rc;
1063 }
1064
1065 // First : get a valid bit rate value
1066
1067 // Which type of value
1068 if((wrq->value < 13) &&
1069 (wrq->value >= 0)) {
1070 // Setting by rate index
1071 // Find value in the magic rate table
1072 brate = wrq->value;
1073 } else {
1074 // Setting by frequency value
1075 u8 normvalue = (u8) (wrq->value/500000);
1076
1077 // Check if rate is valid
1078 for(i = 0 ; i < 13 ; i++) {
1079 if(normvalue == abySupportedRates[i]) {
1080 brate = i;
1081 break;
1082 }
1083 }
1084 }
1085 // -1 designed the max rate (mostly auto mode)
1086 if(wrq->value == -1) {
1087 // Get the highest available rate
1088 for(i = 0 ; i < 13 ; i++) {
1089 if(abySupportedRates[i] == 0)
1090 break;
1091 }
1092 if(i != 0)
1093 brate = i - 1;
1094
1095 }
1096 // Check that it is valid
1097 // brate is index of abySupportedRates[]
1098 if(brate > 13 ) {
1099 rc = -EINVAL;
1100 return rc;
1101 }
1102
1103 // Now, check if we want a fixed or auto value
1104 if(wrq->fixed != 0) {
1105 // Fixed mode
1106 // One rate, fixed
1107 pDevice->bFixRate = TRUE;
1108 if ((pDevice->byBBType == BB_TYPE_11B)&& (brate > 3)) {
1109 pDevice->uConnectionRate = 3;
1110 }
1111 else {
1112 pDevice->uConnectionRate = brate;
1113 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate);
1114 }
1115
1116 }
1117 else {
1118 pDevice->bFixRate = FALSE;
1119 pDevice->uConnectionRate = 13;
1120 }
1121
1122 return rc;
1123 }
1124
1125 /*
1126 * Wireless Handler : get data rate
1127 */
1128
1129 int iwctl_giwrate(struct net_device *dev,
1130 struct iw_request_info *info,
1131 struct iw_param *wrq,
1132 char *extra)
1133 {
1134 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1135 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1136
1137 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE \n");
1138 {
1139 BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
1140 int brate = 0;
1141 if (pDevice->uConnectionRate < 13) {
1142 brate = abySupportedRates[pDevice->uConnectionRate];
1143 }else {
1144 if (pDevice->byBBType == BB_TYPE_11B)
1145 brate = 0x16;
1146 if (pDevice->byBBType == BB_TYPE_11G)
1147 brate = 0x6C;
1148 if (pDevice->byBBType == BB_TYPE_11A)
1149 brate = 0x6C;
1150 }
1151
1152 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1153 if (pDevice->byBBType == BB_TYPE_11B)
1154 brate = 0x16;
1155 if (pDevice->byBBType == BB_TYPE_11G)
1156 brate = 0x6C;
1157 if (pDevice->byBBType == BB_TYPE_11A)
1158 brate = 0x6C;
1159 }
1160 if (pDevice->uConnectionRate == 13)
1161 brate = abySupportedRates[pDevice->wCurrentRate];
1162 wrq->value = brate * 500000;
1163 // If more than one rate, set auto
1164 if (pDevice->bFixRate == TRUE)
1165 wrq->fixed = TRUE;
1166 }
1167
1168
1169 return 0;
1170 }
1171
1172
1173
1174 /*
1175 * Wireless Handler : set rts threshold
1176 */
1177
1178 int iwctl_siwrts(struct net_device *dev,
1179 struct iw_request_info *info,
1180 struct iw_param *wrq,
1181 char *extra)
1182 {
1183 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1184 int rc = 0;
1185
1186 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRTS \n");
1187
1188 {
1189 int rthr = wrq->value;
1190 if(wrq->disabled)
1191 rthr = 2312;
1192 if((rthr < 0) || (rthr > 2312)) {
1193 rc = -EINVAL;
1194 }else {
1195 pDevice->wRTSThreshold = rthr;
1196 }
1197 }
1198
1199 return 0;
1200 }
1201
1202 /*
1203 * Wireless Handler : get rts
1204 */
1205
1206 int iwctl_giwrts(struct net_device *dev,
1207 struct iw_request_info *info,
1208 struct iw_param *wrq,
1209 char *extra)
1210 {
1211 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1212
1213 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS \n");
1214 wrq->value = pDevice->wRTSThreshold;
1215 wrq->disabled = (wrq->value >= 2312);
1216 wrq->fixed = 1;
1217
1218 return 0;
1219 }
1220
1221 /*
1222 * Wireless Handler : set fragment threshold
1223 */
1224
1225 int iwctl_siwfrag(struct net_device *dev,
1226 struct iw_request_info *info,
1227 struct iw_param *wrq,
1228 char *extra)
1229 {
1230 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1231 int rc = 0;
1232 int fthr = wrq->value;
1233
1234
1235 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG \n");
1236
1237
1238 if (wrq->disabled)
1239 fthr = 2312;
1240 if((fthr < 256) || (fthr > 2312)) {
1241 rc = -EINVAL;
1242 }else {
1243 fthr &= ~0x1; // Get an even value
1244 pDevice->wFragmentationThreshold = (u16)fthr;
1245 }
1246
1247 return rc;
1248 }
1249
1250 /*
1251 * Wireless Handler : get fragment threshold
1252 */
1253
1254 int iwctl_giwfrag(struct net_device *dev,
1255 struct iw_request_info *info,
1256 struct iw_param *wrq,
1257 char *extra)
1258 {
1259 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1260
1261 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG \n");
1262 wrq->value = pDevice->wFragmentationThreshold;
1263 wrq->disabled = (wrq->value >= 2312);
1264 wrq->fixed = 1;
1265
1266 return 0;
1267 }
1268
1269
1270
1271 /*
1272 * Wireless Handler : set retry threshold
1273 */
1274 int iwctl_siwretry(struct net_device *dev,
1275 struct iw_request_info *info,
1276 struct iw_param *wrq,
1277 char *extra)
1278 {
1279 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1280 int rc = 0;
1281
1282
1283 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRETRY \n");
1284
1285 if (wrq->disabled) {
1286 rc = -EINVAL;
1287 return rc;
1288 }
1289
1290 if (wrq->flags & IW_RETRY_LIMIT) {
1291 if(wrq->flags & IW_RETRY_MAX)
1292 pDevice->byLongRetryLimit = wrq->value;
1293 else if (wrq->flags & IW_RETRY_MIN)
1294 pDevice->byShortRetryLimit = wrq->value;
1295 else {
1296 // No modifier : set both
1297 pDevice->byShortRetryLimit = wrq->value;
1298 pDevice->byLongRetryLimit = wrq->value;
1299 }
1300 }
1301 if (wrq->flags & IW_RETRY_LIFETIME) {
1302 pDevice->wMaxTransmitMSDULifetime = wrq->value;
1303 }
1304
1305
1306 return rc;
1307 }
1308
1309 /*
1310 * Wireless Handler : get retry threshold
1311 */
1312 int iwctl_giwretry(struct net_device *dev,
1313 struct iw_request_info *info,
1314 struct iw_param *wrq,
1315 char *extra)
1316 {
1317 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1318 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY \n");
1319 wrq->disabled = 0; // Can't be disabled
1320
1321 // Note : by default, display the min retry number
1322 if((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1323 wrq->flags = IW_RETRY_LIFETIME;
1324 wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; //ms
1325 } else if((wrq->flags & IW_RETRY_MAX)) {
1326 wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1327 wrq->value = (int)pDevice->byLongRetryLimit;
1328 } else {
1329 wrq->flags = IW_RETRY_LIMIT;
1330 wrq->value = (int)pDevice->byShortRetryLimit;
1331 if((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
1332 wrq->flags |= IW_RETRY_MIN;
1333 }
1334
1335
1336 return 0;
1337 }
1338
1339
1340 /*
1341 * Wireless Handler : set encode mode
1342 */
1343 int iwctl_siwencode(struct net_device *dev,
1344 struct iw_request_info *info,
1345 struct iw_point *wrq,
1346 char *extra)
1347 {
1348 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1349 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1350 DWORD dwKeyIndex = (DWORD)(wrq->flags & IW_ENCODE_INDEX);
1351 int ii,uu, rc = 0;
1352 int index = (wrq->flags & IW_ENCODE_INDEX);
1353
1354
1355 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
1356
1357 // Check the size of the key
1358 if (wrq->length > WLAN_WEP232_KEYLEN) {
1359 rc = -EINVAL;
1360 return rc;
1361 }
1362
1363 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1364 rc = -EINVAL;
1365 return rc;
1366 }
1367
1368 if (dwKeyIndex > 0)
1369 dwKeyIndex--;
1370
1371 // Send the key to the card
1372 if (wrq->length > 0) {
1373
1374 if (wrq->length == WLAN_WEP232_KEYLEN) {
1375 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1376 }
1377 else if (wrq->length == WLAN_WEP104_KEYLEN) {
1378 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1379 }
1380 else if (wrq->length == WLAN_WEP40_KEYLEN) {
1381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1382 }
1383 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1384 memcpy(pDevice->abyKey, extra, wrq->length);
1385
1386 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1387 for (ii = 0; ii < wrq->length; ii++) {
1388 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1389 }
1390
1391 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1392 spin_lock_irq(&pDevice->lock);
1393 KeybSetDefaultKey( pDevice,
1394 &(pDevice->sKey),
1395 dwKeyIndex | (1 << 31),
1396 wrq->length,
1397 NULL,
1398 pDevice->abyKey,
1399 KEY_CTL_WEP
1400 );
1401 spin_unlock_irq(&pDevice->lock);
1402 }
1403 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
1404 pDevice->uKeyLength = wrq->length;
1405 pDevice->bTransmitKey = TRUE;
1406 pDevice->bEncryptionEnable = TRUE;
1407 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1408
1409 // Do we want to just set the transmit key index ?
1410 if ( index < 4 ) {
1411 pDevice->byKeyIndex = index;
1412 }
1413 else if(!wrq->flags & IW_ENCODE_MODE) {
1414 rc = -EINVAL;
1415 return rc;
1416 }
1417 }
1418 // Read the flags
1419 if(wrq->flags & IW_ENCODE_DISABLED){
1420
1421 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1422 pMgmt->bShareKeyAlgorithm = FALSE;
1423 pDevice->bEncryptionEnable = FALSE;
1424 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1425 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1426 spin_lock_irq(&pDevice->lock);
1427 for(uu=0;uu<MAX_KEY_TABLE;uu++)
1428 MACvDisableKeyEntry(pDevice,uu);
1429 spin_unlock_irq(&pDevice->lock);
1430 }
1431 }
1432 if(wrq->flags & IW_ENCODE_RESTRICTED) {
1433 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n");
1434 pMgmt->bShareKeyAlgorithm = TRUE;
1435 }
1436 if(wrq->flags & IW_ENCODE_OPEN) {
1437 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n");
1438 pMgmt->bShareKeyAlgorithm = FALSE;
1439 }
1440
1441 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1442 memset(pMgmt->abyDesireBSSID, 0xFF,6);
1443 #endif
1444
1445 return rc;
1446 }
1447
1448 /*
1449 * Wireless Handler : get encode mode
1450 */
1451 //2008-0409-06, <Mark> by Einsn Liu
1452 /*
1453 int iwctl_giwencode(struct net_device *dev,
1454 struct iw_request_info *info,
1455 struct iw_point *wrq,
1456 char *extra)
1457 {
1458 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1459 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1460 int rc = 0;
1461 char abyKey[WLAN_WEP232_KEYLEN];
1462 UINT index = (UINT)(wrq->flags & IW_ENCODE_INDEX);
1463 PSKeyItem pKey = NULL;
1464
1465 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1466
1467
1468 memset(abyKey, 0, sizeof(abyKey));
1469 // Check encryption mode
1470 wrq->flags = IW_ENCODE_NOKEY;
1471 // Is WEP enabled ???
1472 if (pDevice->bEncryptionEnable)
1473 wrq->flags |= IW_ENCODE_ENABLED;
1474 else
1475 wrq->flags |= IW_ENCODE_DISABLED;
1476
1477 if (pMgmt->bShareKeyAlgorithm)
1478 wrq->flags |= IW_ENCODE_RESTRICTED;
1479 else
1480 wrq->flags |= IW_ENCODE_OPEN;
1481
1482 if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index , &pKey)){
1483 wrq->length = pKey->uKeyLength;
1484 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1485 }
1486 else {
1487 rc = -EINVAL;
1488 return rc;
1489 }
1490 wrq->flags |= index;
1491 // Copy the key to the user buffer
1492 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1493 return 0;
1494 }
1495 */
1496
1497 //2008-0409-06, <Add> by Einsn Liu
1498
1499 int iwctl_giwencode(struct net_device *dev,
1500 struct iw_request_info *info,
1501 struct iw_point *wrq,
1502 char *extra)
1503 {
1504 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1505 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1506 char abyKey[WLAN_WEP232_KEYLEN];
1507
1508 UINT index = (UINT)(wrq->flags & IW_ENCODE_INDEX);
1509 PSKeyItem pKey = NULL;
1510
1511 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1512
1513 if (index > WLAN_WEP_NKEYS) {
1514 return -EINVAL;
1515 }
1516 if(index<1){//get default key
1517 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1518 index=pDevice->byKeyIndex;
1519 } else
1520 index=0;
1521 }else
1522 index--;
1523
1524 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
1525 // Check encryption mode
1526 wrq->flags = IW_ENCODE_NOKEY;
1527 // Is WEP enabled ???
1528 if (pDevice->bEncryptionEnable)
1529 wrq->flags |= IW_ENCODE_ENABLED;
1530 else
1531 wrq->flags |= IW_ENCODE_DISABLED;
1532
1533 if (pMgmt->bShareKeyAlgorithm)
1534 wrq->flags |= IW_ENCODE_RESTRICTED;
1535 else
1536 wrq->flags |= IW_ENCODE_OPEN;
1537 wrq->length=0;
1538
1539 if((index==0)&&(pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled||
1540 pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)){//get wpa pairwise key
1541 if (KeybGetKey(&(pDevice->sKey),pMgmt->abyCurrBSSID, 0xffffffff, &pKey)){
1542 wrq->length = pKey->uKeyLength;
1543 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1544 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1545 }
1546 }else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index , &pKey)){
1547 wrq->length = pKey->uKeyLength;
1548 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1549 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1550 }
1551
1552 wrq->flags |= index+1;
1553
1554 return 0;
1555 }
1556
1557
1558 /*
1559 * Wireless Handler : set power mode
1560 */
1561 int iwctl_siwpower(struct net_device *dev,
1562 struct iw_request_info *info,
1563 struct iw_param *wrq,
1564 char *extra)
1565 {
1566 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1567 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1568 int rc = 0;
1569
1570 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER \n");
1571
1572 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1573 rc = -EINVAL;
1574 return rc;
1575 }
1576
1577 if (wrq->disabled) {
1578 pDevice->ePSMode = WMAC_POWER_CAM;
1579 PSvDisablePowerSaving(pDevice);
1580 return rc;
1581 }
1582 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1583 pDevice->ePSMode = WMAC_POWER_FAST;
1584 PSvEnablePowerSaving((HANDLE)pDevice, pMgmt->wListenInterval);
1585
1586 } else if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
1587 pDevice->ePSMode = WMAC_POWER_FAST;
1588 PSvEnablePowerSaving((HANDLE)pDevice, pMgmt->wListenInterval);
1589 }
1590 switch (wrq->flags & IW_POWER_MODE) {
1591 case IW_POWER_UNICAST_R:
1592 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_UNICAST_R \n");
1593 rc = -EINVAL;
1594 break;
1595 case IW_POWER_ALL_R:
1596 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ALL_R \n");
1597 rc = -EINVAL;
1598 case IW_POWER_ON:
1599 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ON \n");
1600 break;
1601 default:
1602 rc = -EINVAL;
1603 }
1604
1605 return rc;
1606 }
1607
1608 /*
1609 * Wireless Handler : get power mode
1610 */
1611 int iwctl_giwpower(struct net_device *dev,
1612 struct iw_request_info *info,
1613 struct iw_param *wrq,
1614 char *extra)
1615 {
1616 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1617 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1618 int mode = pDevice->ePSMode;
1619
1620
1621 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPOWER \n");
1622
1623
1624 if ((wrq->disabled = (mode == WMAC_POWER_CAM)))
1625 return 0;
1626
1627 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1628 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1629 wrq->flags = IW_POWER_TIMEOUT;
1630 } else {
1631 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1632 wrq->flags = IW_POWER_PERIOD;
1633 }
1634 wrq->flags |= IW_POWER_ALL_R;
1635
1636 return 0;
1637 }
1638
1639
1640 /*
1641 * Wireless Handler : get Sensitivity
1642 */
1643 int iwctl_giwsens(struct net_device *dev,
1644 struct iw_request_info *info,
1645 struct iw_param *wrq,
1646 char *extra)
1647 {
1648 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1649 long ldBm;
1650
1651 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS \n");
1652 if (pDevice->bLinkPass == TRUE) {
1653 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
1654 wrq->value = ldBm;
1655 }
1656 else {
1657 wrq->value = 0;
1658 };
1659 wrq->disabled = (wrq->value == 0);
1660 wrq->fixed = 1;
1661
1662
1663 return 0;
1664 }
1665
1666 //2008-0409-07, <Add> by Einsn Liu
1667 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1668
1669 int iwctl_siwauth(struct net_device *dev,
1670 struct iw_request_info *info,
1671 struct iw_param *wrq,
1672 char *extra)
1673 {
1674 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1675 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1676 int ret=0;
1677 static int wpa_version=0; //must be static to save the last value,einsn liu
1678 static int pairwise=0;
1679
1680 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
1681 switch (wrq->flags & IW_AUTH_INDEX) {
1682 case IW_AUTH_WPA_VERSION:
1683 wpa_version = wrq->value;
1684 if(wrq->value == IW_AUTH_WPA_VERSION_DISABLED) {
1685 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1686 //pDevice->bWPADEVUp = FALSE;
1687 }
1688 else if(wrq->value == IW_AUTH_WPA_VERSION_WPA) {
1689 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1690 }
1691 else {
1692 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1693 }
1694 //pDevice->bWPASuppWextEnabled =TRUE;
1695 break;
1696 case IW_AUTH_CIPHER_PAIRWISE:
1697 pairwise = wrq->value;
1698 PRINT_K("iwctl_siwauth:set pairwise=%d\n",pairwise);
1699 if(pairwise == IW_AUTH_CIPHER_CCMP){
1700 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1701 }else if(pairwise == IW_AUTH_CIPHER_TKIP){
1702 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1703 }else if(pairwise == IW_AUTH_CIPHER_WEP40||pairwise == IW_AUTH_CIPHER_WEP104){
1704 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1705 }else if(pairwise == IW_AUTH_CIPHER_NONE){
1706 //do nothing,einsn liu
1707 }else pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1708
1709 break;
1710 case IW_AUTH_CIPHER_GROUP:
1711 PRINT_K("iwctl_siwauth:set GROUP=%d\n",wrq->value);
1712 if(wpa_version == IW_AUTH_WPA_VERSION_DISABLED)
1713 break;
1714 if(pairwise == IW_AUTH_CIPHER_NONE){
1715 if(wrq->value == IW_AUTH_CIPHER_CCMP){
1716 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1717 }else {
1718 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1719 }
1720 }
1721 break;
1722 case IW_AUTH_KEY_MGMT:
1723 PRINT_K("iwctl_siwauth(wpa_version=%d):set KEY_MGMT=%d\n",wpa_version,wrq->value);
1724 if(wpa_version == IW_AUTH_WPA_VERSION_WPA2){
1725 if(wrq->value == IW_AUTH_KEY_MGMT_PSK)
1726 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
1727 else pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
1728 }else if(wpa_version == IW_AUTH_WPA_VERSION_WPA){
1729 if(wrq->value == 0){
1730 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
1731 }else if(wrq->value == IW_AUTH_KEY_MGMT_PSK)
1732 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
1733 else pMgmt->eAuthenMode = WMAC_AUTH_WPA;
1734 }
1735
1736 break;
1737 case IW_AUTH_TKIP_COUNTERMEASURES:
1738 break; /* FIXME */
1739 case IW_AUTH_DROP_UNENCRYPTED:
1740 break;
1741 case IW_AUTH_80211_AUTH_ALG:
1742 PRINT_K("iwctl_siwauth:set AUTH_ALG=%d\n",wrq->value);
1743 if(wrq->value==IW_AUTH_ALG_OPEN_SYSTEM){
1744 pMgmt->bShareKeyAlgorithm=FALSE;
1745 }else if(wrq->value==IW_AUTH_ALG_SHARED_KEY){
1746 pMgmt->bShareKeyAlgorithm=TRUE;
1747 }
1748 break;
1749 case IW_AUTH_WPA_ENABLED:
1750 //pDevice->bWPADEVUp = !! wrq->value;
1751 //if(pDevice->bWPADEVUp==TRUE)
1752 // printk("iwctl_siwauth:set WPADEV to enable sucessful*******\n");
1753 //else
1754 // printk("iwctl_siwauth:set WPADEV to enable fail?????\n");
1755 break;
1756 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1757 break;
1758 case IW_AUTH_ROAMING_CONTROL:
1759 ret = -EOPNOTSUPP;
1760 break;
1761 case IW_AUTH_PRIVACY_INVOKED:
1762 pDevice->bEncryptionEnable = !!wrq->value;
1763 if(pDevice->bEncryptionEnable == FALSE){
1764 wpa_version = 0;
1765 pairwise = 0;
1766 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1767 pMgmt->bShareKeyAlgorithm = FALSE;
1768 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
1769 //pDevice->bWPADEVUp = FALSE;
1770 PRINT_K("iwctl_siwauth:set WPADEV to disaable at 2?????\n");
1771 }
1772
1773 break;
1774 default:
1775 ret = -EOPNOTSUPP;
1776 break;
1777 }
1778 /*
1779 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_version = %d\n",wpa_version);
1780 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise = %d\n",pairwise);
1781 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->eEncryptionStatus = %d\n",pDevice->eEncryptionStatus);
1782 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->eAuthenMode = %d\n",pMgmt->eAuthenMode);
1783 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->bShareKeyAlgorithm = %s\n",pMgmt->bShareKeyAlgorithm?"TRUE":"FALSE");
1784 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bEncryptionEnable = %s\n",pDevice->bEncryptionEnable?"TRUE":"FALSE");
1785 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bWPADEVUp = %s\n",pDevice->bWPADEVUp?"TRUE":"FALSE");
1786 */
1787 return ret;
1788 }
1789
1790
1791 int iwctl_giwauth(struct net_device *dev,
1792 struct iw_request_info *info,
1793 struct iw_param *wrq,
1794 char *extra)
1795 {
1796 return -EOPNOTSUPP;
1797 }
1798
1799
1800
1801 int iwctl_siwgenie(struct net_device *dev,
1802 struct iw_request_info *info,
1803 struct iw_point *wrq,
1804 char *extra)
1805 {
1806 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1807 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1808 int ret=0;
1809
1810 if(wrq->length){
1811 if ((wrq->length < 2) || (extra[1]+2 != wrq->length)) {
1812 ret = -EINVAL;
1813 goto out;
1814 }
1815 if(wrq->length > MAX_WPA_IE_LEN){
1816 ret = -ENOMEM;
1817 goto out;
1818 }
1819 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1820 if(copy_from_user(pMgmt->abyWPAIE, extra, wrq->length)){
1821 ret = -EFAULT;
1822 goto out;
1823 }
1824 pMgmt->wWPAIELen = wrq->length;
1825 }else {
1826 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1827 pMgmt->wWPAIELen = 0;
1828 }
1829
1830 out://not completely ...not necessary in wpa_supplicant 0.5.8
1831 return 0;
1832 }
1833
1834 int iwctl_giwgenie(struct net_device *dev,
1835 struct iw_request_info *info,
1836 struct iw_point *wrq,
1837 char *extra)
1838 {
1839 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1840 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1841 int ret=0;
1842 int space = wrq->length;
1843
1844 wrq->length = 0;
1845 if(pMgmt->wWPAIELen > 0){
1846 wrq->length = pMgmt->wWPAIELen;
1847 if(pMgmt->wWPAIELen <= space){
1848 if(copy_to_user(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen)){
1849 ret = -EFAULT;
1850 }
1851 }else
1852 ret = -E2BIG;
1853 }
1854
1855 return ret;
1856 }
1857
1858
1859 int iwctl_siwencodeext(struct net_device *dev,
1860 struct iw_request_info *info,
1861 struct iw_point *wrq,
1862 char *extra)
1863 {
1864 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1865 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1866 struct iw_encode_ext *ext = (struct iw_encode_ext*)extra;
1867 struct viawget_wpa_param *param=NULL;
1868 //original member
1869 wpa_alg alg_name;
1870 u8 addr[6];
1871 int key_idx, set_tx=0;
1872 u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
1873 u8 key[64];
1874 size_t seq_len=0,key_len=0;
1875 //
1876 // int ii;
1877 u8 *buf;
1878 size_t blen;
1879 u8 key_array[64];
1880 int ret=0;
1881
1882 PRINT_K("SIOCSIWENCODEEXT...... \n");
1883
1884 blen = sizeof(*param);
1885 buf = kmalloc((int)blen, (int)GFP_KERNEL);
1886 if (buf == NULL)
1887 return -ENOMEM;
1888 memset(buf, 0, blen);
1889 param = (struct viawget_wpa_param *) buf;
1890
1891 //recover alg_name
1892 switch (ext->alg) {
1893 case IW_ENCODE_ALG_NONE:
1894 alg_name = WPA_ALG_NONE;
1895 break;
1896 case IW_ENCODE_ALG_WEP:
1897 alg_name = WPA_ALG_WEP;
1898 break;
1899 case IW_ENCODE_ALG_TKIP:
1900 alg_name = WPA_ALG_TKIP;
1901 break;
1902 case IW_ENCODE_ALG_CCMP:
1903 alg_name = WPA_ALG_CCMP;
1904 break;
1905 default:
1906 PRINT_K("Unknown alg = %d\n",ext->alg);
1907 ret= -ENOMEM;
1908 goto error;
1909 }
1910 //recover addr
1911 memcpy(addr, ext->addr.sa_data, ETH_ALEN);
1912 //recover key_idx
1913 key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1;
1914 //recover set_tx
1915 if(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1916 set_tx = 1;
1917 //recover seq,seq_len
1918 if(ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1919 seq_len=IW_ENCODE_SEQ_MAX_SIZE;
1920 memcpy(seq, ext->rx_seq, seq_len);
1921 }
1922 //recover key,key_len
1923 if(ext->key_len) {
1924 key_len=ext->key_len;
1925 memcpy(key, &ext->key[0], key_len);
1926 }
1927
1928 memset(key_array, 0, 64);
1929 if ( key_len > 0) {
1930 memcpy(key_array, key, key_len);
1931 if (key_len == 32) {
1932 // notice ! the oder
1933 memcpy(&key_array[16], &key[24], 8);
1934 memcpy(&key_array[24], &key[16], 8);
1935 }
1936 }
1937
1938 /**************Translate iw_encode_ext to viawget_wpa_param****************/
1939 memcpy(param->addr, addr, ETH_ALEN);
1940 param->u.wpa_key.alg_name = (int)alg_name;
1941 param->u.wpa_key.set_tx = set_tx;
1942 param->u.wpa_key.key_index = key_idx;
1943 param->u.wpa_key.key_len = key_len;
1944 param->u.wpa_key.key = (u8 *)key_array;
1945 param->u.wpa_key.seq = (u8 *)seq;
1946 param->u.wpa_key.seq_len = seq_len;
1947
1948 #if 0
1949 printk("param->u.wpa_key.alg_name =%d\n",param->u.wpa_key.alg_name);
1950 printk("param->addr=%02x:%02x:%02x:%02x:%02x:%02x\n",
1951 param->addr[0],param->addr[1],param->addr[2],
1952 param->addr[3],param->addr[4],param->addr[5]);
1953 printk("param->u.wpa_key.set_tx =%d\n",param->u.wpa_key.set_tx);
1954 printk("param->u.wpa_key.key_index =%d\n",param->u.wpa_key.key_index);
1955 printk("param->u.wpa_key.key_len =%d\n",param->u.wpa_key.key_len);
1956 printk("param->u.wpa_key.key =");
1957 for(ii=0;ii<param->u.wpa_key.key_len;ii++)
1958 printk("%02x:",param->u.wpa_key.key[ii]);
1959 printk("\n");
1960 printk("param->u.wpa_key.seq_len =%d\n",param->u.wpa_key.seq_len);
1961 printk("param->u.wpa_key.seq =");
1962 for(ii=0;ii<param->u.wpa_key.seq_len;ii++)
1963 printk("%02x:",param->u.wpa_key.seq[ii]);
1964 printk("\n");
1965
1966 printk("...........\n");
1967 #endif
1968 //****set if current action is Network Manager count??
1969 //****this method is so foolish,but there is no other way???
1970 if(param->u.wpa_key.alg_name == WPA_ALG_NONE) {
1971 if(param->u.wpa_key.key_index ==0) {
1972 pDevice->bwextstep0 = TRUE;
1973 }
1974 if((pDevice->bwextstep0 = TRUE)&&(param->u.wpa_key.key_index ==1)) {
1975 pDevice->bwextstep0 = FALSE;
1976 pDevice->bwextstep1 = TRUE;
1977 }
1978 if((pDevice->bwextstep1 = TRUE)&&(param->u.wpa_key.key_index ==2)) {
1979 pDevice->bwextstep1 = FALSE;
1980 pDevice->bwextstep2 = TRUE;
1981 }
1982 if((pDevice->bwextstep2 = TRUE)&&(param->u.wpa_key.key_index ==3)) {
1983 pDevice->bwextstep2 = FALSE;
1984 pDevice->bwextstep3 = TRUE;
1985 }
1986 }
1987 if(pDevice->bwextstep3 == TRUE) {
1988 PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
1989 pDevice->bwextstep0 = FALSE;
1990 pDevice->bwextstep1 = FALSE;
1991 pDevice->bwextstep2 = FALSE;
1992 pDevice->bwextstep3 = FALSE;
1993 pDevice->bWPASuppWextEnabled = TRUE;
1994 memset(pMgmt->abyDesireBSSID, 0xFF,6);
1995 KeyvInitTable(pDevice,&pDevice->sKey);
1996 }
1997 //******
1998
1999 spin_lock_irq(&pDevice->lock);
2000 ret = wpa_set_keys(pDevice, param, TRUE);
2001 spin_unlock_irq(&pDevice->lock);
2002
2003 error:
2004 kfree(param);
2005 return ret;
2006 }
2007
2008
2009
2010 int iwctl_giwencodeext(struct net_device *dev,
2011 struct iw_request_info *info,
2012 struct iw_point *wrq,
2013 char *extra)
2014 {
2015 return -EOPNOTSUPP;;
2016 }
2017
2018 int iwctl_siwmlme(struct net_device *dev,
2019 struct iw_request_info * info,
2020 struct iw_point *wrq,
2021 char *extra)
2022 {
2023 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2024 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2025 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2026 //u16 reason = cpu_to_le16(mlme->reason_code);
2027 int ret = 0;
2028
2029 if(memcmp(pMgmt->abyCurrBSSID, mlme->addr.sa_data, ETH_ALEN)){
2030 ret = -EINVAL;
2031 return ret;
2032 }
2033 switch(mlme->cmd){
2034 case IW_MLME_DEAUTH:
2035 //this command seems to be not complete,please test it --einsnliu
2036 //printk("iwctl_siwmlme--->send DEAUTH\n");
2037 //bScheduleCommand((HANDLE) pDevice, WLAN_CMD_DEAUTH, (PBYTE)&reason);
2038 //break;
2039 case IW_MLME_DISASSOC:
2040 if(pDevice->bLinkPass == TRUE){
2041 PRINT_K("iwctl_siwmlme--->send DISASSOCIATE\n");
2042 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
2043 }
2044 break;
2045 default:
2046 ret = -EOPNOTSUPP;
2047 }
2048
2049 return ret;
2050
2051 }
2052
2053 #endif
2054 //End Add --//2008-0409-07, <Add> by Einsn Liu
2055
2056
2057
2058 /*------------------------------------------------------------------*/
2059 /*
2060 * Structures to export the Wireless Handlers
2061 */
2062
2063
2064 /*
2065 static const iw_handler iwctl_handler[] =
2066 {
2067 (iw_handler) iwctl_commit, // SIOCSIWCOMMIT
2068 (iw_handler) iwctl_giwname, // SIOCGIWNAME
2069 (iw_handler) NULL, // SIOCSIWNWID
2070 (iw_handler) NULL, // SIOCGIWNWID
2071 (iw_handler) iwctl_siwfreq, // SIOCSIWFREQ
2072 (iw_handler) iwctl_giwfreq, // SIOCGIWFREQ
2073 (iw_handler) iwctl_siwmode, // SIOCSIWMODE
2074 (iw_handler) iwctl_giwmode, // SIOCGIWMODE
2075 (iw_handler) NULL, // SIOCSIWSENS
2076 (iw_handler) iwctl_giwsens, // SIOCGIWSENS
2077 (iw_handler) NULL, // SIOCSIWRANGE
2078 (iw_handler) iwctl_giwrange, // SIOCGIWRANGE
2079 (iw_handler) NULL, // SIOCSIWPRIV
2080 (iw_handler) NULL, // SIOCGIWPRIV
2081 (iw_handler) NULL, // SIOCSIWSTATS
2082 (iw_handler) NULL, // SIOCGIWSTATS
2083 (iw_handler) NULL, // SIOCSIWSPY
2084 (iw_handler) NULL, // SIOCGIWSPY
2085 (iw_handler) NULL, // -- hole --
2086 (iw_handler) NULL, // -- hole --
2087 (iw_handler) iwctl_siwap, // SIOCSIWAP
2088 (iw_handler) iwctl_giwap, // SIOCGIWAP
2089 (iw_handler) NULL, // -- hole -- 0x16
2090 (iw_handler) iwctl_giwaplist, // SIOCGIWAPLIST
2091 (iw_handler) iwctl_siwscan, // SIOCSIWSCAN
2092 (iw_handler) iwctl_giwscan, // SIOCGIWSCAN
2093 (iw_handler) iwctl_siwessid, // SIOCSIWESSID
2094 (iw_handler) iwctl_giwessid, // SIOCGIWESSID
2095 (iw_handler) NULL, // SIOCSIWNICKN
2096 (iw_handler) NULL, // SIOCGIWNICKN
2097 (iw_handler) NULL, // -- hole --
2098 (iw_handler) NULL, // -- hole --
2099 (iw_handler) iwctl_siwrate, // SIOCSIWRATE 0x20
2100 (iw_handler) iwctl_giwrate, // SIOCGIWRATE
2101 (iw_handler) iwctl_siwrts, // SIOCSIWRTS
2102 (iw_handler) iwctl_giwrts, // SIOCGIWRTS
2103 (iw_handler) iwctl_siwfrag, // SIOCSIWFRAG
2104 (iw_handler) iwctl_giwfrag, // SIOCGIWFRAG
2105 (iw_handler) NULL, // SIOCSIWTXPOW
2106 (iw_handler) NULL, // SIOCGIWTXPOW
2107 (iw_handler) iwctl_siwretry, // SIOCSIWRETRY
2108 (iw_handler) iwctl_giwretry, // SIOCGIWRETRY
2109 (iw_handler) iwctl_siwencode, // SIOCSIWENCODE
2110 (iw_handler) iwctl_giwencode, // SIOCGIWENCODE
2111 (iw_handler) iwctl_siwpower, // SIOCSIWPOWER
2112 (iw_handler) iwctl_giwpower, // SIOCGIWPOWER
2113 (iw_handler) NULL, // -- hole --
2114 (iw_handler) NULL, // -- hole --
2115 (iw_handler) iwctl_siwgenie, // SIOCSIWGENIE
2116 (iw_handler) iwctl_giwgenie, // SIOCGIWGENIE
2117 (iw_handler) iwctl_siwauth, // SIOCSIWAUTH
2118 (iw_handler) iwctl_giwauth, // SIOCGIWAUTH
2119 (iw_handler) iwctl_siwencodeext, // SIOCSIWENCODEEXT
2120 (iw_handler) iwctl_giwencodeext, // SIOCGIWENCODEEXT
2121 (iw_handler) NULL, // SIOCSIWPMKSA
2122 (iw_handler) NULL, // -- hole --
2123
2124 };
2125 */
2126
2127 static const iw_handler iwctl_handler[] =
2128 {
2129 (iw_handler) iwctl_commit, // SIOCSIWCOMMIT
2130 (iw_handler) NULL, // SIOCGIWNAME
2131 (iw_handler) NULL, // SIOCSIWNWID
2132 (iw_handler) NULL, // SIOCGIWNWID
2133 (iw_handler) NULL, // SIOCSIWFREQ
2134 (iw_handler) NULL, // SIOCGIWFREQ
2135 (iw_handler) NULL, // SIOCSIWMODE
2136 (iw_handler) NULL, // SIOCGIWMODE
2137 (iw_handler) NULL, // SIOCSIWSENS
2138 (iw_handler) NULL, // SIOCGIWSENS
2139 (iw_handler) NULL, // SIOCSIWRANGE
2140 (iw_handler) iwctl_giwrange, // SIOCGIWRANGE
2141 (iw_handler) NULL, // SIOCSIWPRIV
2142 (iw_handler) NULL, // SIOCGIWPRIV
2143 (iw_handler) NULL, // SIOCSIWSTATS
2144 (iw_handler) NULL, // SIOCGIWSTATS
2145 (iw_handler) NULL, // SIOCSIWSPY
2146 (iw_handler) NULL, // SIOCGIWSPY
2147 (iw_handler) NULL, // -- hole --
2148 (iw_handler) NULL, // -- hole --
2149 (iw_handler) NULL, // SIOCSIWAP
2150 (iw_handler) NULL, // SIOCGIWAP
2151 (iw_handler) NULL, // -- hole -- 0x16
2152 (iw_handler) NULL, // SIOCGIWAPLIST
2153 (iw_handler) iwctl_siwscan, // SIOCSIWSCAN
2154 (iw_handler) iwctl_giwscan, // SIOCGIWSCAN
2155 (iw_handler) NULL, // SIOCSIWESSID
2156 (iw_handler) NULL, // SIOCGIWESSID
2157 (iw_handler) NULL, // SIOCSIWNICKN
2158 (iw_handler) NULL, // SIOCGIWNICKN
2159 (iw_handler) NULL, // -- hole --
2160 (iw_handler) NULL, // -- hole --
2161 (iw_handler) NULL, // SIOCSIWRATE 0x20
2162 (iw_handler) NULL, // SIOCGIWRATE
2163 (iw_handler) NULL, // SIOCSIWRTS
2164 (iw_handler) NULL, // SIOCGIWRTS
2165 (iw_handler) NULL, // SIOCSIWFRAG
2166 (iw_handler) NULL, // SIOCGIWFRAG
2167 (iw_handler) NULL, // SIOCSIWTXPOW
2168 (iw_handler) NULL, // SIOCGIWTXPOW
2169 (iw_handler) NULL, // SIOCSIWRETRY
2170 (iw_handler) NULL, // SIOCGIWRETRY
2171 (iw_handler) NULL, // SIOCSIWENCODE
2172 (iw_handler) NULL, // SIOCGIWENCODE
2173 (iw_handler) NULL, // SIOCSIWPOWER
2174 (iw_handler) NULL, // SIOCGIWPOWER
2175 (iw_handler) NULL, // -- hole --
2176 (iw_handler) NULL, // -- hole --
2177 (iw_handler) NULL, // SIOCSIWGENIE
2178 (iw_handler) NULL, // SIOCGIWGENIE
2179 (iw_handler) NULL, // SIOCSIWAUTH
2180 (iw_handler) NULL, // SIOCGIWAUTH
2181 (iw_handler) NULL, // SIOCSIWENCODEEXT
2182 (iw_handler) NULL, // SIOCGIWENCODEEXT
2183 (iw_handler) NULL, // SIOCSIWPMKSA
2184 (iw_handler) NULL, // -- hole --
2185 };
2186
2187
2188 static const iw_handler iwctl_private_handler[] =
2189 {
2190 NULL, // SIOCIWFIRSTPRIV
2191 };
2192
2193
2194 struct iw_priv_args iwctl_private_args[] = {
2195 { IOCTL_CMD_SET,
2196 IW_PRIV_TYPE_CHAR | 1024, 0,
2197 "set"},
2198 };
2199
2200
2201
2202 const struct iw_handler_def iwctl_handler_def =
2203 {
2204 .get_wireless_stats = &iwctl_get_wireless_stats,
2205 .num_standard = sizeof(iwctl_handler)/sizeof(iw_handler),
2206 // .num_private = sizeof(iwctl_private_handler)/sizeof(iw_handler),
2207 // .num_private_args = sizeof(iwctl_private_args)/sizeof(struct iw_priv_args),
2208 .num_private = 0,
2209 .num_private_args = 0,
2210 .standard = (iw_handler *) iwctl_handler,
2211 // .private = (iw_handler *) iwctl_private_handler,
2212 // .private_args = (struct iw_priv_args *)iwctl_private_args,
2213 .private = NULL,
2214 .private_args = NULL,
2215 };
This page took 0.090771 seconds and 4 git commands to generate.