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