1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/string.h>
17#include "rtl_core.h"
18#include "rtl_wx.h"
19
20#define RATE_COUNT 12
21static u32 rtl8192_rates[] = {
22 1000000, 2000000, 5500000, 11000000, 6000000, 9000000, 12000000,
23 18000000, 24000000, 36000000, 48000000, 54000000
24};
25
26#ifndef ENETDOWN
27#define ENETDOWN 1
28#endif
29
30static int _rtl92e_wx_get_freq(struct net_device *dev,
31 struct iw_request_info *a,
32 union iwreq_data *wrqu, char *b)
33{
34 struct r8192_priv *priv = rtllib_priv(dev);
35
36 return rtllib_wx_get_freq(priv->rtllib, a, wrqu, b);
37}
38
39static int _rtl92e_wx_get_mode(struct net_device *dev,
40 struct iw_request_info *a,
41 union iwreq_data *wrqu, char *b)
42{
43 struct r8192_priv *priv = rtllib_priv(dev);
44
45 return rtllib_wx_get_mode(priv->rtllib, a, wrqu, b);
46}
47
48static int _rtl92e_wx_get_rate(struct net_device *dev,
49 struct iw_request_info *info,
50 union iwreq_data *wrqu, char *extra)
51{
52 struct r8192_priv *priv = rtllib_priv(dev);
53
54 return rtllib_wx_get_rate(priv->rtllib, info, wrqu, extra);
55}
56
57static int _rtl92e_wx_set_rate(struct net_device *dev,
58 struct iw_request_info *info,
59 union iwreq_data *wrqu, char *extra)
60{
61 int ret;
62 struct r8192_priv *priv = rtllib_priv(dev);
63
64 if (priv->bHwRadioOff)
65 return 0;
66
67 mutex_lock(&priv->wx_mutex);
68
69 ret = rtllib_wx_set_rate(priv->rtllib, info, wrqu, extra);
70
71 mutex_unlock(&priv->wx_mutex);
72
73 return ret;
74}
75
76static int _rtl92e_wx_set_rts(struct net_device *dev,
77 struct iw_request_info *info,
78 union iwreq_data *wrqu, char *extra)
79{
80 int ret;
81 struct r8192_priv *priv = rtllib_priv(dev);
82
83 if (priv->bHwRadioOff)
84 return 0;
85
86 mutex_lock(&priv->wx_mutex);
87
88 ret = rtllib_wx_set_rts(priv->rtllib, info, wrqu, extra);
89
90 mutex_unlock(&priv->wx_mutex);
91
92 return ret;
93}
94
95static int _rtl92e_wx_get_rts(struct net_device *dev,
96 struct iw_request_info *info,
97 union iwreq_data *wrqu, char *extra)
98{
99 struct r8192_priv *priv = rtllib_priv(dev);
100
101 return rtllib_wx_get_rts(priv->rtllib, info, wrqu, extra);
102}
103
104static int _rtl92e_wx_set_power(struct net_device *dev,
105 struct iw_request_info *info,
106 union iwreq_data *wrqu, char *extra)
107{
108 int ret;
109 struct r8192_priv *priv = rtllib_priv(dev);
110
111 if (priv->bHwRadioOff) {
112 netdev_warn(dev, "%s(): Can't set Power: Radio is Off.\n",
113 __func__);
114 return 0;
115 }
116 mutex_lock(&priv->wx_mutex);
117
118 ret = rtllib_wx_set_power(priv->rtllib, info, wrqu, extra);
119
120 mutex_unlock(&priv->wx_mutex);
121
122 return ret;
123}
124
125static int _rtl92e_wx_get_power(struct net_device *dev,
126 struct iw_request_info *info,
127 union iwreq_data *wrqu, char *extra)
128{
129 struct r8192_priv *priv = rtllib_priv(dev);
130
131 return rtllib_wx_get_power(priv->rtllib, info, wrqu, extra);
132}
133
134static int _rtl92e_wx_set_rawtx(struct net_device *dev,
135 struct iw_request_info *info,
136 union iwreq_data *wrqu, char *extra)
137{
138 struct r8192_priv *priv = rtllib_priv(dev);
139 int ret;
140
141 if (priv->bHwRadioOff)
142 return 0;
143
144 mutex_lock(&priv->wx_mutex);
145
146 ret = rtllib_wx_set_rawtx(priv->rtllib, info, wrqu, extra);
147
148 mutex_unlock(&priv->wx_mutex);
149
150 return ret;
151}
152
153static int _rtl92e_wx_force_reset(struct net_device *dev,
154 struct iw_request_info *info,
155 union iwreq_data *wrqu, char *extra)
156{
157 struct r8192_priv *priv = rtllib_priv(dev);
158
159 mutex_lock(&priv->wx_mutex);
160
161 RT_TRACE(COMP_DBG, "%s(): force reset ! extra is %d\n",
162 __func__, *extra);
163 priv->force_reset = *extra;
164 mutex_unlock(&priv->wx_mutex);
165 return 0;
166}
167
168static int _rtl92e_wx_adapter_power_status(struct net_device *dev,
169 struct iw_request_info *info,
170 union iwreq_data *wrqu, char *extra)
171{
172 struct r8192_priv *priv = rtllib_priv(dev);
173 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
174 (&priv->rtllib->PowerSaveControl);
175 struct rtllib_device *ieee = priv->rtllib;
176
177 mutex_lock(&priv->wx_mutex);
178
179 RT_TRACE(COMP_POWER, "%s(): %s\n", __func__, (*extra == 6) ?
180 "DC power" : "AC power");
181 if (*extra || priv->force_lps) {
182 priv->ps_force = false;
183 pPSC->bLeisurePs = true;
184 } else {
185 if (priv->rtllib->state == RTLLIB_LINKED)
186 rtl92e_leisure_ps_leave(dev);
187
188 priv->ps_force = true;
189 pPSC->bLeisurePs = false;
190 ieee->ps = *extra;
191 }
192
193 mutex_unlock(&priv->wx_mutex);
194
195 return 0;
196}
197
198static int _rtl92e_wx_set_lps_awake_interval(struct net_device *dev,
199 struct iw_request_info *info,
200 union iwreq_data *wrqu,
201 char *extra)
202{
203 struct r8192_priv *priv = rtllib_priv(dev);
204 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
205 (&priv->rtllib->PowerSaveControl);
206
207 mutex_lock(&priv->wx_mutex);
208
209 netdev_info(dev, "%s(): set lps awake interval ! extra is %d\n",
210 __func__, *extra);
211
212 pPSC->RegMaxLPSAwakeIntvl = *extra;
213 mutex_unlock(&priv->wx_mutex);
214 return 0;
215}
216
217static int _rtl92e_wx_set_force_lps(struct net_device *dev,
218 struct iw_request_info *info,
219 union iwreq_data *wrqu, char *extra)
220{
221 struct r8192_priv *priv = rtllib_priv(dev);
222
223 mutex_lock(&priv->wx_mutex);
224
225 netdev_info(dev,
226 "%s(): force LPS ! extra is %d (1 is open 0 is close)\n",
227 __func__, *extra);
228 priv->force_lps = *extra;
229 mutex_unlock(&priv->wx_mutex);
230 return 0;
231}
232
233static int _rtl92e_wx_set_debug(struct net_device *dev,
234 struct iw_request_info *info,
235 union iwreq_data *wrqu, char *extra)
236{
237 struct r8192_priv *priv = rtllib_priv(dev);
238 u8 c = *extra;
239
240 if (priv->bHwRadioOff)
241 return 0;
242
243 netdev_info(dev, "=====>%s(), *extra:%x, debugflag:%x\n", __func__,
244 *extra, rt_global_debug_component);
245 if (c > 0)
246 rt_global_debug_component |= (1 << c);
247 else
248 rt_global_debug_component &= BIT31;
249 return 0;
250}
251
252static int _rtl92e_wx_set_mode(struct net_device *dev,
253 struct iw_request_info *a,
254 union iwreq_data *wrqu, char *b)
255{
256 struct r8192_priv *priv = rtllib_priv(dev);
257 struct rtllib_device *ieee = netdev_priv_rsl(dev);
258
259 enum rt_rf_power_state rtState;
260 int ret;
261
262 if (priv->bHwRadioOff)
263 return 0;
264 rtState = priv->rtllib->eRFPowerState;
265 mutex_lock(&priv->wx_mutex);
266 if (wrqu->mode == IW_MODE_ADHOC || wrqu->mode == IW_MODE_MONITOR ||
267 ieee->bNetPromiscuousMode) {
268 if (priv->rtllib->PowerSaveControl.bInactivePs) {
269 if (rtState == eRfOff) {
270 if (priv->rtllib->RfOffReason >
271 RF_CHANGE_BY_IPS) {
272 netdev_warn(dev, "%s(): RF is OFF.\n",
273 __func__);
274 mutex_unlock(&priv->wx_mutex);
275 return -1;
276 }
277 netdev_info(dev,
278 "=========>%s(): rtl92e_ips_leave\n",
279 __func__);
280 mutex_lock(&priv->rtllib->ips_mutex);
281 rtl92e_ips_leave(dev);
282 mutex_unlock(&priv->rtllib->ips_mutex);
283 }
284 }
285 }
286 ret = rtllib_wx_set_mode(priv->rtllib, a, wrqu, b);
287
288 mutex_unlock(&priv->wx_mutex);
289 return ret;
290}
291
292struct iw_range_with_scan_capa {
293
294 __u32 throughput;
295
296
297
298
299
300
301
302
303 __u32 min_nwid;
304 __u32 max_nwid;
305
306
307 __u16 old_num_channels;
308 __u8 old_num_frequency;
309
310
311 __u8 scan_capa;
312};
313
314static int _rtl92e_wx_get_range(struct net_device *dev,
315 struct iw_request_info *info,
316 union iwreq_data *wrqu, char *extra)
317{
318 struct iw_range *range = (struct iw_range *)extra;
319 struct r8192_priv *priv = rtllib_priv(dev);
320 u16 val;
321 int i;
322
323 wrqu->data.length = sizeof(*range);
324 memset(range, 0, sizeof(*range));
325
326
327 range->throughput = 130 * 1000 * 1000;
328
329 if (priv->rf_set_sens != NULL)
330
331 range->sensitivity = priv->max_sens;
332
333 range->max_qual.qual = 100;
334 range->max_qual.level = 0;
335 range->max_qual.noise = 0;
336 range->max_qual.updated = 7;
337
338 range->avg_qual.qual = 70;
339 range->avg_qual.level = 0;
340 range->avg_qual.noise = 0;
341 range->avg_qual.updated = 7;
342
343 range->num_bitrates = min(RATE_COUNT, IW_MAX_BITRATES);
344
345 for (i = 0; i < range->num_bitrates; i++)
346 range->bitrate[i] = rtl8192_rates[i];
347
348 range->max_rts = DEFAULT_RTS_THRESHOLD;
349 range->min_frag = MIN_FRAG_THRESHOLD;
350 range->max_frag = MAX_FRAG_THRESHOLD;
351
352 range->min_pmp = 0;
353 range->max_pmp = 5000000;
354 range->min_pmt = 0;
355 range->max_pmt = 65535 * 1000;
356 range->pmp_flags = IW_POWER_PERIOD;
357 range->pmt_flags = IW_POWER_TIMEOUT;
358 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
359 range->we_version_compiled = WIRELESS_EXT;
360 range->we_version_source = 18;
361
362 for (i = 0, val = 0; i < 14; i++) {
363 if ((priv->rtllib->active_channel_map)[i + 1]) {
364 range->freq[val].i = i + 1;
365 range->freq[val].m = rtllib_wlan_frequencies[i] *
366 100000;
367 range->freq[val].e = 1;
368 val++;
369 }
370
371 if (val == IW_MAX_FREQUENCIES)
372 break;
373 }
374 range->num_frequency = val;
375 range->num_channels = val;
376 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
377 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
378 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE;
379
380
381
382 return 0;
383}
384
385static int _rtl92e_wx_set_scan(struct net_device *dev,
386 struct iw_request_info *a,
387 union iwreq_data *wrqu, char *b)
388{
389 struct r8192_priv *priv = rtllib_priv(dev);
390 struct rtllib_device *ieee = priv->rtllib;
391 enum rt_rf_power_state rtState;
392 int ret;
393
394 if (!(ieee->softmac_features & IEEE_SOFTMAC_SCAN)) {
395 if ((ieee->state >= RTLLIB_ASSOCIATING) &&
396 (ieee->state <= RTLLIB_ASSOCIATING_AUTHENTICATED))
397 return 0;
398 if ((priv->rtllib->state == RTLLIB_LINKED) &&
399 (priv->rtllib->CntAfterLink < 2))
400 return 0;
401 }
402
403 if (priv->bHwRadioOff) {
404 netdev_info(dev, "================>%s(): hwradio off\n",
405 __func__);
406 return 0;
407 }
408 rtState = priv->rtllib->eRFPowerState;
409 if (!priv->up)
410 return -ENETDOWN;
411 if (priv->rtllib->LinkDetectInfo.bBusyTraffic == true)
412 return -EAGAIN;
413
414 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
415 struct iw_scan_req *req = (struct iw_scan_req *)b;
416
417 if (req->essid_len) {
418 ieee->current_network.ssid_len = req->essid_len;
419 memcpy(ieee->current_network.ssid, req->essid,
420 req->essid_len);
421 }
422 }
423
424 mutex_lock(&priv->wx_mutex);
425
426 priv->rtllib->FirstIe_InScan = true;
427
428 if (priv->rtllib->state != RTLLIB_LINKED) {
429 if (priv->rtllib->PowerSaveControl.bInactivePs) {
430 if (rtState == eRfOff) {
431 if (priv->rtllib->RfOffReason >
432 RF_CHANGE_BY_IPS) {
433 netdev_warn(dev, "%s(): RF is OFF.\n",
434 __func__);
435 mutex_unlock(&priv->wx_mutex);
436 return -1;
437 }
438 RT_TRACE(COMP_PS,
439 "=========>%s(): rtl92e_ips_leave\n",
440 __func__);
441 mutex_lock(&priv->rtllib->ips_mutex);
442 rtl92e_ips_leave(dev);
443 mutex_unlock(&priv->rtllib->ips_mutex);
444 }
445 }
446 rtllib_stop_scan(priv->rtllib);
447 if (priv->rtllib->LedControlHandler)
448 priv->rtllib->LedControlHandler(dev,
449 LED_CTL_SITE_SURVEY);
450
451 if (priv->rtllib->eRFPowerState != eRfOff) {
452 priv->rtllib->actscanning = true;
453
454 if (ieee->ScanOperationBackupHandler)
455 ieee->ScanOperationBackupHandler(ieee->dev,
456 SCAN_OPT_BACKUP);
457
458 rtllib_start_scan_syncro(priv->rtllib, 0);
459
460 if (ieee->ScanOperationBackupHandler)
461 ieee->ScanOperationBackupHandler(ieee->dev,
462 SCAN_OPT_RESTORE);
463 }
464 ret = 0;
465 } else {
466 priv->rtllib->actscanning = true;
467 ret = rtllib_wx_set_scan(priv->rtllib, a, wrqu, b);
468 }
469
470 mutex_unlock(&priv->wx_mutex);
471 return ret;
472}
473
474static int _rtl92e_wx_get_scan(struct net_device *dev,
475 struct iw_request_info *a,
476 union iwreq_data *wrqu, char *b)
477{
478 int ret;
479 struct r8192_priv *priv = rtllib_priv(dev);
480
481 if (!priv->up)
482 return -ENETDOWN;
483
484 if (priv->bHwRadioOff)
485 return 0;
486
487 mutex_lock(&priv->wx_mutex);
488
489 ret = rtllib_wx_get_scan(priv->rtllib, a, wrqu, b);
490
491 mutex_unlock(&priv->wx_mutex);
492
493 return ret;
494}
495
496static int _rtl92e_wx_set_essid(struct net_device *dev,
497 struct iw_request_info *a,
498 union iwreq_data *wrqu, char *b)
499{
500 struct r8192_priv *priv = rtllib_priv(dev);
501 int ret;
502
503 if (priv->bHwRadioOff) {
504 netdev_info(dev,
505 "=========>%s():hw radio off,or Rf state is eRfOff, return\n",
506 __func__);
507 return 0;
508 }
509 mutex_lock(&priv->wx_mutex);
510 ret = rtllib_wx_set_essid(priv->rtllib, a, wrqu, b);
511
512 mutex_unlock(&priv->wx_mutex);
513
514 return ret;
515}
516
517static int _rtl92e_wx_get_essid(struct net_device *dev,
518 struct iw_request_info *a,
519 union iwreq_data *wrqu, char *b)
520{
521 int ret;
522 struct r8192_priv *priv = rtllib_priv(dev);
523
524 mutex_lock(&priv->wx_mutex);
525
526 ret = rtllib_wx_get_essid(priv->rtllib, a, wrqu, b);
527
528 mutex_unlock(&priv->wx_mutex);
529
530 return ret;
531}
532
533static int _rtl92e_wx_set_nick(struct net_device *dev,
534 struct iw_request_info *info,
535 union iwreq_data *wrqu, char *extra)
536{
537 struct r8192_priv *priv = rtllib_priv(dev);
538
539 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
540 return -E2BIG;
541 mutex_lock(&priv->wx_mutex);
542 wrqu->data.length = min_t(size_t, wrqu->data.length,
543 sizeof(priv->nick));
544 memset(priv->nick, 0, sizeof(priv->nick));
545 memcpy(priv->nick, extra, wrqu->data.length);
546 mutex_unlock(&priv->wx_mutex);
547 return 0;
548}
549
550static int _rtl92e_wx_get_nick(struct net_device *dev,
551 struct iw_request_info *info,
552 union iwreq_data *wrqu, char *extra)
553{
554 struct r8192_priv *priv = rtllib_priv(dev);
555
556 mutex_lock(&priv->wx_mutex);
557 wrqu->data.length = strlen(priv->nick);
558 memcpy(extra, priv->nick, wrqu->data.length);
559 wrqu->data.flags = 1;
560 mutex_unlock(&priv->wx_mutex);
561 return 0;
562}
563
564static int _rtl92e_wx_set_freq(struct net_device *dev,
565 struct iw_request_info *a,
566 union iwreq_data *wrqu, char *b)
567{
568 int ret;
569 struct r8192_priv *priv = rtllib_priv(dev);
570
571 if (priv->bHwRadioOff)
572 return 0;
573
574 mutex_lock(&priv->wx_mutex);
575
576 ret = rtllib_wx_set_freq(priv->rtllib, a, wrqu, b);
577
578 mutex_unlock(&priv->wx_mutex);
579 return ret;
580}
581
582static int _rtl92e_wx_get_name(struct net_device *dev,
583 struct iw_request_info *info,
584 union iwreq_data *wrqu, char *extra)
585{
586 struct r8192_priv *priv = rtllib_priv(dev);
587
588 return rtllib_wx_get_name(priv->rtllib, info, wrqu, extra);
589}
590
591static int _rtl92e_wx_set_frag(struct net_device *dev,
592 struct iw_request_info *info,
593 union iwreq_data *wrqu, char *extra)
594{
595 struct r8192_priv *priv = rtllib_priv(dev);
596
597 if (priv->bHwRadioOff)
598 return 0;
599
600 if (wrqu->frag.disabled)
601 priv->rtllib->fts = DEFAULT_FRAG_THRESHOLD;
602 else {
603 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
604 wrqu->frag.value > MAX_FRAG_THRESHOLD)
605 return -EINVAL;
606
607 priv->rtllib->fts = wrqu->frag.value & ~0x1;
608 }
609
610 return 0;
611}
612
613static int _rtl92e_wx_get_frag(struct net_device *dev,
614 struct iw_request_info *info,
615 union iwreq_data *wrqu, char *extra)
616{
617 struct r8192_priv *priv = rtllib_priv(dev);
618
619 wrqu->frag.value = priv->rtllib->fts;
620 wrqu->frag.fixed = 0;
621 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FRAG_THRESHOLD);
622
623 return 0;
624}
625
626static int _rtl92e_wx_set_wap(struct net_device *dev,
627 struct iw_request_info *info,
628 union iwreq_data *awrq, char *extra)
629{
630 int ret;
631 struct r8192_priv *priv = rtllib_priv(dev);
632
633 if (priv->bHwRadioOff)
634 return 0;
635
636 mutex_lock(&priv->wx_mutex);
637
638 ret = rtllib_wx_set_wap(priv->rtllib, info, awrq, extra);
639
640 mutex_unlock(&priv->wx_mutex);
641
642 return ret;
643}
644
645static int _rtl92e_wx_get_wap(struct net_device *dev,
646 struct iw_request_info *info,
647 union iwreq_data *wrqu, char *extra)
648{
649 struct r8192_priv *priv = rtllib_priv(dev);
650
651 return rtllib_wx_get_wap(priv->rtllib, info, wrqu, extra);
652}
653
654static int _rtl92e_wx_get_enc(struct net_device *dev,
655 struct iw_request_info *info,
656 union iwreq_data *wrqu, char *key)
657{
658 struct r8192_priv *priv = rtllib_priv(dev);
659
660 return rtllib_wx_get_encode(priv->rtllib, info, wrqu, key);
661}
662
663static int _rtl92e_wx_set_enc(struct net_device *dev,
664 struct iw_request_info *info,
665 union iwreq_data *wrqu, char *key)
666{
667 struct r8192_priv *priv = rtllib_priv(dev);
668 int ret;
669
670 struct rtllib_device *ieee = priv->rtllib;
671 u32 hwkey[4] = {0, 0, 0, 0};
672 u8 mask = 0xff;
673 u32 key_idx = 0;
674 u8 zero_addr[4][6] = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
675 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
676 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
677 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03} };
678 int i;
679
680 if (priv->bHwRadioOff)
681 return 0;
682
683 if (!priv->up)
684 return -ENETDOWN;
685
686 priv->rtllib->wx_set_enc = 1;
687 mutex_lock(&priv->rtllib->ips_mutex);
688 rtl92e_ips_leave(dev);
689 mutex_unlock(&priv->rtllib->ips_mutex);
690 mutex_lock(&priv->wx_mutex);
691
692 RT_TRACE(COMP_SEC, "Setting SW wep key");
693 ret = rtllib_wx_set_encode(priv->rtllib, info, wrqu, key);
694 mutex_unlock(&priv->wx_mutex);
695
696 if (wrqu->encoding.flags & IW_ENCODE_DISABLED) {
697 ieee->pairwise_key_type = ieee->group_key_type = KEY_TYPE_NA;
698 rtl92e_cam_reset(dev);
699 memset(priv->rtllib->swcamtable, 0,
700 sizeof(struct sw_cam_table) * 32);
701 goto end_hw_sec;
702 }
703 if (wrqu->encoding.length != 0) {
704 for (i = 0; i < 4; i++) {
705 hwkey[i] |= key[4 * i + 0] & mask;
706 if (i == 1 && (4 * i + 1) == wrqu->encoding.length)
707 mask = 0x00;
708 if (i == 3 && (4 * i + 1) == wrqu->encoding.length)
709 mask = 0x00;
710 hwkey[i] |= (key[4 * i + 1] & mask) << 8;
711 hwkey[i] |= (key[4 * i + 2] & mask) << 16;
712 hwkey[i] |= (key[4 * i + 3] & mask) << 24;
713 }
714
715 switch (wrqu->encoding.flags & IW_ENCODE_INDEX) {
716 case 0:
717 key_idx = ieee->crypt_info.tx_keyidx;
718 break;
719 case 1:
720 key_idx = 0;
721 break;
722 case 2:
723 key_idx = 1;
724 break;
725 case 3:
726 key_idx = 2;
727 break;
728 case 4:
729 key_idx = 3;
730 break;
731 default:
732 break;
733 }
734 if (wrqu->encoding.length == 0x5) {
735 ieee->pairwise_key_type = KEY_TYPE_WEP40;
736 rtl92e_enable_hw_security_config(dev);
737 }
738
739 else if (wrqu->encoding.length == 0xd) {
740 ieee->pairwise_key_type = KEY_TYPE_WEP104;
741 rtl92e_enable_hw_security_config(dev);
742 rtl92e_set_key(dev, key_idx, key_idx, KEY_TYPE_WEP104,
743 zero_addr[key_idx], 0, hwkey);
744 rtl92e_set_swcam(dev, key_idx, key_idx, KEY_TYPE_WEP104,
745 zero_addr[key_idx], 0, hwkey, 0);
746 } else {
747 netdev_info(dev,
748 "wrong type in WEP, not WEP40 and WEP104\n");
749 }
750 }
751
752end_hw_sec:
753 priv->rtllib->wx_set_enc = 0;
754 return ret;
755}
756
757static int _rtl92e_wx_set_scan_type(struct net_device *dev,
758 struct iw_request_info *aa,
759 union iwreq_data *wrqu, char *p)
760{
761 struct r8192_priv *priv = rtllib_priv(dev);
762 int *parms = (int *)p;
763 int mode = parms[0];
764
765 if (priv->bHwRadioOff)
766 return 0;
767
768 priv->rtllib->active_scan = mode;
769
770 return 1;
771}
772
773#define R8192_MAX_RETRY 255
774static int _rtl92e_wx_set_retry(struct net_device *dev,
775 struct iw_request_info *info,
776 union iwreq_data *wrqu, char *extra)
777{
778 struct r8192_priv *priv = rtllib_priv(dev);
779 int err = 0;
780
781 if (priv->bHwRadioOff)
782 return 0;
783
784 mutex_lock(&priv->wx_mutex);
785
786 if (wrqu->retry.flags & IW_RETRY_LIFETIME ||
787 wrqu->retry.disabled) {
788 err = -EINVAL;
789 goto exit;
790 }
791 if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) {
792 err = -EINVAL;
793 goto exit;
794 }
795
796 if (wrqu->retry.value > R8192_MAX_RETRY) {
797 err = -EINVAL;
798 goto exit;
799 }
800 if (wrqu->retry.flags & IW_RETRY_MAX)
801 priv->retry_rts = wrqu->retry.value;
802 else
803 priv->retry_data = wrqu->retry.value;
804
805 rtl92e_commit(dev);
806exit:
807 mutex_unlock(&priv->wx_mutex);
808
809 return err;
810}
811
812static int _rtl92e_wx_get_retry(struct net_device *dev,
813 struct iw_request_info *info,
814 union iwreq_data *wrqu, char *extra)
815{
816 struct r8192_priv *priv = rtllib_priv(dev);
817
818 wrqu->retry.disabled = 0;
819
820 if ((wrqu->retry.flags & IW_RETRY_TYPE) ==
821 IW_RETRY_LIFETIME)
822 return -EINVAL;
823
824 if (wrqu->retry.flags & IW_RETRY_MAX) {
825 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
826 wrqu->retry.value = priv->retry_rts;
827 } else {
828 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
829 wrqu->retry.value = priv->retry_data;
830 }
831 return 0;
832}
833
834static int _rtl92e_wx_get_sens(struct net_device *dev,
835 struct iw_request_info *info,
836 union iwreq_data *wrqu, char *extra)
837{
838 struct r8192_priv *priv = rtllib_priv(dev);
839
840 if (priv->rf_set_sens == NULL)
841 return -1;
842 wrqu->sens.value = priv->sens;
843 return 0;
844}
845
846static int _rtl92e_wx_set_sens(struct net_device *dev,
847 struct iw_request_info *info,
848 union iwreq_data *wrqu, char *extra)
849{
850 struct r8192_priv *priv = rtllib_priv(dev);
851
852 short err = 0;
853
854 if (priv->bHwRadioOff)
855 return 0;
856
857 mutex_lock(&priv->wx_mutex);
858 if (priv->rf_set_sens == NULL) {
859 err = -1;
860 goto exit;
861 }
862 if (priv->rf_set_sens(dev, wrqu->sens.value) == 0)
863 priv->sens = wrqu->sens.value;
864 else
865 err = -EINVAL;
866
867exit:
868 mutex_unlock(&priv->wx_mutex);
869
870 return err;
871}
872
873static int _rtl92e_wx_set_encode_ext(struct net_device *dev,
874 struct iw_request_info *info,
875 union iwreq_data *wrqu, char *extra)
876{
877 int ret = 0;
878 struct r8192_priv *priv = rtllib_priv(dev);
879 struct rtllib_device *ieee = priv->rtllib;
880
881 if (priv->bHwRadioOff)
882 return 0;
883
884 mutex_lock(&priv->wx_mutex);
885
886 priv->rtllib->wx_set_enc = 1;
887 mutex_lock(&priv->rtllib->ips_mutex);
888 rtl92e_ips_leave(dev);
889 mutex_unlock(&priv->rtllib->ips_mutex);
890
891 ret = rtllib_wx_set_encode_ext(ieee, info, wrqu, extra);
892 {
893 const u8 broadcast_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
894 const u8 zero[ETH_ALEN] = {0};
895 u32 key[4] = {0};
896 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
897 struct iw_point *encoding = &wrqu->encoding;
898 u8 idx = 0, alg = 0, group = 0;
899
900 if ((encoding->flags & IW_ENCODE_DISABLED) ||
901 ext->alg == IW_ENCODE_ALG_NONE) {
902 ieee->pairwise_key_type = ieee->group_key_type
903 = KEY_TYPE_NA;
904 rtl92e_cam_reset(dev);
905 memset(priv->rtllib->swcamtable, 0,
906 sizeof(struct sw_cam_table) * 32);
907 goto end_hw_sec;
908 }
909 alg = (ext->alg == IW_ENCODE_ALG_CCMP) ? KEY_TYPE_CCMP :
910 ext->alg;
911 idx = encoding->flags & IW_ENCODE_INDEX;
912 if (idx)
913 idx--;
914 group = ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY;
915
916 if ((!group) || (ieee->iw_mode == IW_MODE_ADHOC) ||
917 (alg == KEY_TYPE_WEP40)) {
918 if ((ext->key_len == 13) && (alg == KEY_TYPE_WEP40))
919 alg = KEY_TYPE_WEP104;
920 ieee->pairwise_key_type = alg;
921 rtl92e_enable_hw_security_config(dev);
922 }
923 memcpy((u8 *)key, ext->key, 16);
924
925 if ((alg & KEY_TYPE_WEP40) && (ieee->auth_mode != 2)) {
926 if (ext->key_len == 13)
927 ieee->pairwise_key_type = alg = KEY_TYPE_WEP104;
928 rtl92e_set_key(dev, idx, idx, alg, zero, 0, key);
929 rtl92e_set_swcam(dev, idx, idx, alg, zero, 0, key, 0);
930 } else if (group) {
931 ieee->group_key_type = alg;
932 rtl92e_set_key(dev, idx, idx, alg, broadcast_addr, 0,
933 key);
934 rtl92e_set_swcam(dev, idx, idx, alg, broadcast_addr, 0,
935 key, 0);
936 } else {
937 if ((ieee->pairwise_key_type == KEY_TYPE_CCMP) &&
938 ieee->pHTInfo->bCurrentHTSupport)
939 rtl92e_writeb(dev, 0x173, 1);
940 rtl92e_set_key(dev, 4, idx, alg,
941 (u8 *)ieee->ap_mac_addr, 0, key);
942 rtl92e_set_swcam(dev, 4, idx, alg,
943 (u8 *)ieee->ap_mac_addr, 0, key, 0);
944 }
945 }
946
947end_hw_sec:
948 priv->rtllib->wx_set_enc = 0;
949 mutex_unlock(&priv->wx_mutex);
950 return ret;
951}
952
953static int _rtl92e_wx_set_auth(struct net_device *dev,
954 struct iw_request_info *info,
955 union iwreq_data *data, char *extra)
956{
957 int ret = 0;
958
959 struct r8192_priv *priv = rtllib_priv(dev);
960
961 if (priv->bHwRadioOff)
962 return 0;
963
964 mutex_lock(&priv->wx_mutex);
965 ret = rtllib_wx_set_auth(priv->rtllib, info, &data->param, extra);
966 mutex_unlock(&priv->wx_mutex);
967 return ret;
968}
969
970static int _rtl92e_wx_set_mlme(struct net_device *dev,
971 struct iw_request_info *info,
972 union iwreq_data *wrqu, char *extra)
973{
974 int ret = 0;
975
976 struct r8192_priv *priv = rtllib_priv(dev);
977
978 if (priv->bHwRadioOff)
979 return 0;
980
981 mutex_lock(&priv->wx_mutex);
982 ret = rtllib_wx_set_mlme(priv->rtllib, info, wrqu, extra);
983 mutex_unlock(&priv->wx_mutex);
984 return ret;
985}
986
987static int _rtl92e_wx_set_gen_ie(struct net_device *dev,
988 struct iw_request_info *info,
989 union iwreq_data *data, char *extra)
990{
991 int ret = 0;
992
993 struct r8192_priv *priv = rtllib_priv(dev);
994
995 if (priv->bHwRadioOff)
996 return 0;
997
998 mutex_lock(&priv->wx_mutex);
999 ret = rtllib_wx_set_gen_ie(priv->rtllib, extra, data->data.length);
1000 mutex_unlock(&priv->wx_mutex);
1001 return ret;
1002}
1003
1004static int _rtl92e_wx_get_gen_ie(struct net_device *dev,
1005 struct iw_request_info *info,
1006 union iwreq_data *data, char *extra)
1007{
1008 int ret = 0;
1009 struct r8192_priv *priv = rtllib_priv(dev);
1010 struct rtllib_device *ieee = priv->rtllib;
1011
1012 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
1013 data->data.length = 0;
1014 return 0;
1015 }
1016
1017 if (data->data.length < ieee->wpa_ie_len)
1018 return -E2BIG;
1019
1020 data->data.length = ieee->wpa_ie_len;
1021 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
1022 return ret;
1023}
1024
1025#define OID_RT_INTEL_PROMISCUOUS_MODE 0xFF0101F6
1026
1027static int _rtl92e_wx_set_promisc_mode(struct net_device *dev,
1028 struct iw_request_info *info,
1029 union iwreq_data *wrqu, char *extra)
1030{
1031 struct r8192_priv *priv = rtllib_priv(dev);
1032 struct rtllib_device *ieee = priv->rtllib;
1033
1034 u32 info_buf[3];
1035
1036 u32 oid;
1037 u32 bPromiscuousOn;
1038 u32 bFilterSourceStationFrame;
1039
1040 if (copy_from_user(info_buf, wrqu->data.pointer, sizeof(info_buf)))
1041 return -EFAULT;
1042
1043 oid = info_buf[0];
1044 bPromiscuousOn = info_buf[1];
1045 bFilterSourceStationFrame = info_buf[2];
1046
1047 if (oid == OID_RT_INTEL_PROMISCUOUS_MODE) {
1048 ieee->IntelPromiscuousModeInfo.bPromiscuousOn =
1049 (bPromiscuousOn) ? (true) : (false);
1050 ieee->IntelPromiscuousModeInfo.bFilterSourceStationFrame =
1051 (bFilterSourceStationFrame) ? (true) : (false);
1052 (bPromiscuousOn) ?
1053 (rtllib_EnableIntelPromiscuousMode(dev, false)) :
1054 (rtllib_DisableIntelPromiscuousMode(dev, false));
1055
1056 netdev_info(dev,
1057 "=======>%s(), on = %d, filter src sta = %d\n",
1058 __func__, bPromiscuousOn,
1059 bFilterSourceStationFrame);
1060 } else {
1061 return -1;
1062 }
1063
1064 return 0;
1065}
1066
1067static int _rtl92e_wx_get_promisc_mode(struct net_device *dev,
1068 struct iw_request_info *info,
1069 union iwreq_data *wrqu, char *extra)
1070{
1071 struct r8192_priv *priv = rtllib_priv(dev);
1072 struct rtllib_device *ieee = priv->rtllib;
1073
1074 mutex_lock(&priv->wx_mutex);
1075
1076 snprintf(extra, 45, "PromiscuousMode:%d, FilterSrcSTAFrame:%d",
1077 ieee->IntelPromiscuousModeInfo.bPromiscuousOn,
1078 ieee->IntelPromiscuousModeInfo.bFilterSourceStationFrame);
1079 wrqu->data.length = strlen(extra) + 1;
1080
1081 mutex_unlock(&priv->wx_mutex);
1082
1083 return 0;
1084}
1085
1086#define IW_IOCTL(x) ((x) - SIOCSIWCOMMIT)
1087static iw_handler r8192_wx_handlers[] = {
1088 [IW_IOCTL(SIOCGIWNAME)] = _rtl92e_wx_get_name,
1089 [IW_IOCTL(SIOCSIWFREQ)] = _rtl92e_wx_set_freq,
1090 [IW_IOCTL(SIOCGIWFREQ)] = _rtl92e_wx_get_freq,
1091 [IW_IOCTL(SIOCSIWMODE)] = _rtl92e_wx_set_mode,
1092 [IW_IOCTL(SIOCGIWMODE)] = _rtl92e_wx_get_mode,
1093 [IW_IOCTL(SIOCSIWSENS)] = _rtl92e_wx_set_sens,
1094 [IW_IOCTL(SIOCGIWSENS)] = _rtl92e_wx_get_sens,
1095 [IW_IOCTL(SIOCGIWRANGE)] = _rtl92e_wx_get_range,
1096 [IW_IOCTL(SIOCSIWAP)] = _rtl92e_wx_set_wap,
1097 [IW_IOCTL(SIOCGIWAP)] = _rtl92e_wx_get_wap,
1098 [IW_IOCTL(SIOCSIWSCAN)] = _rtl92e_wx_set_scan,
1099 [IW_IOCTL(SIOCGIWSCAN)] = _rtl92e_wx_get_scan,
1100 [IW_IOCTL(SIOCSIWESSID)] = _rtl92e_wx_set_essid,
1101 [IW_IOCTL(SIOCGIWESSID)] = _rtl92e_wx_get_essid,
1102 [IW_IOCTL(SIOCSIWNICKN)] = _rtl92e_wx_set_nick,
1103 [IW_IOCTL(SIOCGIWNICKN)] = _rtl92e_wx_get_nick,
1104 [IW_IOCTL(SIOCSIWRATE)] = _rtl92e_wx_set_rate,
1105 [IW_IOCTL(SIOCGIWRATE)] = _rtl92e_wx_get_rate,
1106 [IW_IOCTL(SIOCSIWRTS)] = _rtl92e_wx_set_rts,
1107 [IW_IOCTL(SIOCGIWRTS)] = _rtl92e_wx_get_rts,
1108 [IW_IOCTL(SIOCSIWFRAG)] = _rtl92e_wx_set_frag,
1109 [IW_IOCTL(SIOCGIWFRAG)] = _rtl92e_wx_get_frag,
1110 [IW_IOCTL(SIOCSIWRETRY)] = _rtl92e_wx_set_retry,
1111 [IW_IOCTL(SIOCGIWRETRY)] = _rtl92e_wx_get_retry,
1112 [IW_IOCTL(SIOCSIWENCODE)] = _rtl92e_wx_set_enc,
1113 [IW_IOCTL(SIOCGIWENCODE)] = _rtl92e_wx_get_enc,
1114 [IW_IOCTL(SIOCSIWPOWER)] = _rtl92e_wx_set_power,
1115 [IW_IOCTL(SIOCGIWPOWER)] = _rtl92e_wx_get_power,
1116 [IW_IOCTL(SIOCSIWGENIE)] = _rtl92e_wx_set_gen_ie,
1117 [IW_IOCTL(SIOCGIWGENIE)] = _rtl92e_wx_get_gen_ie,
1118 [IW_IOCTL(SIOCSIWMLME)] = _rtl92e_wx_set_mlme,
1119 [IW_IOCTL(SIOCSIWAUTH)] = _rtl92e_wx_set_auth,
1120 [IW_IOCTL(SIOCSIWENCODEEXT)] = _rtl92e_wx_set_encode_ext,
1121};
1122
1123
1124
1125
1126
1127static const struct iw_priv_args r8192_private_args[] = {
1128 {
1129 SIOCIWFIRSTPRIV + 0x0,
1130 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_debugflag"
1131 }, {
1132 SIOCIWFIRSTPRIV + 0x1,
1133 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "activescan"
1134 }, {
1135 SIOCIWFIRSTPRIV + 0x2,
1136 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "rawtx"
1137 }, {
1138 SIOCIWFIRSTPRIV + 0x3,
1139 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "forcereset"
1140 }, {
1141 SIOCIWFIRSTPRIV + 0x6,
1142 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE,
1143 "set_power"
1144 }, {
1145 SIOCIWFIRSTPRIV + 0xa,
1146 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE,
1147 "lps_interv"
1148 }, {
1149 SIOCIWFIRSTPRIV + 0xb,
1150 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE,
1151 "lps_force"
1152 }, {
1153 SIOCIWFIRSTPRIV + 0x16,
1154 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 3, 0, "setpromisc"
1155 }, {
1156 SIOCIWFIRSTPRIV + 0x17,
1157 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 45, "getpromisc"
1158 }
1159
1160};
1161
1162static iw_handler r8192_private_handler[] = {
1163 (iw_handler)_rtl92e_wx_set_debug,
1164 (iw_handler)_rtl92e_wx_set_scan_type,
1165 (iw_handler)_rtl92e_wx_set_rawtx,
1166 (iw_handler)_rtl92e_wx_force_reset,
1167 (iw_handler)NULL,
1168 (iw_handler)NULL,
1169 (iw_handler)_rtl92e_wx_adapter_power_status,
1170 (iw_handler)NULL,
1171 (iw_handler)NULL,
1172 (iw_handler)NULL,
1173 (iw_handler)_rtl92e_wx_set_lps_awake_interval,
1174 (iw_handler)_rtl92e_wx_set_force_lps,
1175 (iw_handler)NULL,
1176 (iw_handler)NULL,
1177 (iw_handler)NULL,
1178 (iw_handler)NULL,
1179 (iw_handler)NULL,
1180 (iw_handler)NULL,
1181 (iw_handler)NULL,
1182 (iw_handler)NULL,
1183 (iw_handler)NULL,
1184 (iw_handler)NULL,
1185 (iw_handler)_rtl92e_wx_set_promisc_mode,
1186 (iw_handler)_rtl92e_wx_get_promisc_mode,
1187};
1188
1189static struct iw_statistics *_rtl92e_get_wireless_stats(struct net_device *dev)
1190{
1191 struct r8192_priv *priv = rtllib_priv(dev);
1192 struct rtllib_device *ieee = priv->rtllib;
1193 struct iw_statistics *wstats = &priv->wstats;
1194 int tmp_level = 0;
1195 int tmp_qual = 0;
1196 int tmp_noise = 0;
1197
1198 if (ieee->state < RTLLIB_LINKED) {
1199 wstats->qual.qual = 10;
1200 wstats->qual.level = 0;
1201 wstats->qual.noise = 0x100 - 100;
1202 wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1203 return wstats;
1204 }
1205
1206 tmp_level = (&ieee->current_network)->stats.rssi;
1207 tmp_qual = (&ieee->current_network)->stats.signal;
1208 tmp_noise = (&ieee->current_network)->stats.noise;
1209
1210 wstats->qual.level = tmp_level;
1211 wstats->qual.qual = tmp_qual;
1212 wstats->qual.noise = tmp_noise;
1213 wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1214 return wstats;
1215}
1216
1217const struct iw_handler_def r8192_wx_handlers_def = {
1218 .standard = r8192_wx_handlers,
1219 .num_standard = ARRAY_SIZE(r8192_wx_handlers),
1220 .private = r8192_private_handler,
1221 .num_private = ARRAY_SIZE(r8192_private_handler),
1222 .num_private_args = sizeof(r8192_private_args) /
1223 sizeof(struct iw_priv_args),
1224 .get_wireless_stats = _rtl92e_get_wireless_stats,
1225 .private_args = (struct iw_priv_args *)r8192_private_args,
1226};
1227