-
Notifications
You must be signed in to change notification settings - Fork 52
/
ioctl_linux.c
12970 lines (10598 loc) · 331 KB
/
ioctl_linux.c
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
*
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*
*
******************************************************************************/
#define _IOCTL_LINUX_C_
#include <drv_conf.h>
#include <osdep_service.h>
#include <drv_types.h>
#include <wlan_bssdef.h>
#include <rtw_debug.h>
#include <wifi.h>
#include <rtw_mlme.h>
#include <rtw_mlme_ext.h>
#include <rtw_ioctl.h>
#include <rtw_ioctl_set.h>
#include <rtw_ioctl_query.h>
//#ifdef CONFIG_MP_INCLUDED
#include <rtw_mp_ioctl.h>
//#endif
#include <usb_ops.h>
#include <rtw_version.h>
#ifdef CONFIG_MP_INCLUDED
#include <rtw_mp.h>
#endif
#include <rtl8192d_hal.h>
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27))
#define iwe_stream_add_event(a, b, c, d, e) iwe_stream_add_event(b, c, d, e)
#define iwe_stream_add_point(a, b, c, d, e) iwe_stream_add_point(b, c, d, e)
#endif
#define RTL_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
#define SCAN_ITEM_SIZE 768
#define MAX_CUSTOM_LEN 64
#define RATE_COUNT 4
#ifdef CONFIG_GLOBAL_UI_PID
extern int ui_pid[3];
#endif
// combo scan
#define WEXT_CSCAN_AMOUNT 9
#define WEXT_CSCAN_BUF_LEN 360
#define WEXT_CSCAN_HEADER "CSCAN S\x01\x00\x00S\x00"
#define WEXT_CSCAN_HEADER_SIZE 12
#define WEXT_CSCAN_SSID_SECTION 'S'
#define WEXT_CSCAN_CHANNEL_SECTION 'C'
#define WEXT_CSCAN_NPROBE_SECTION 'N'
#define WEXT_CSCAN_ACTV_DWELL_SECTION 'A'
#define WEXT_CSCAN_PASV_DWELL_SECTION 'P'
#define WEXT_CSCAN_HOME_DWELL_SECTION 'H'
#define WEXT_CSCAN_TYPE_SECTION 'T'
extern u8 key_2char2num(u8 hch, u8 lch);
extern u8 str_2char2num(u8 hch, u8 lch);
extern u8 convert_ip_addr(u8 hch, u8 mch, u8 lch);
u32 rtw_rates[] = {1000000,2000000,5500000,11000000,
6000000,9000000,12000000,18000000,24000000,36000000,48000000,54000000};
static const char * const iw_operation_mode[] =
{
"Auto", "Ad-Hoc", "Managed", "Master", "Repeater", "Secondary", "Monitor"
};
static int hex2num_i(char c)
{
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
return -1;
}
static int hex2byte_i(const char *hex)
{
int a, b;
a = hex2num_i(*hex++);
if (a < 0)
return -1;
b = hex2num_i(*hex++);
if (b < 0)
return -1;
return (a << 4) | b;
}
/**
* hwaddr_aton - Convert ASCII string to MAC address
* @txt: MAC address as a string (e.g., "00:11:22:33:44:55")
* @addr: Buffer for the MAC address (ETH_ALEN = 6 bytes)
* Returns: 0 on success, -1 on failure (e.g., string not a MAC address)
*/
static int hwaddr_aton_i(const char *txt, u8 *addr)
{
int i;
for (i = 0; i < 6; i++) {
int a, b;
a = hex2num_i(*txt++);
if (a < 0)
return -1;
b = hex2num_i(*txt++);
if (b < 0)
return -1;
*addr++ = (a << 4) | b;
if (i < 5 && *txt++ != ':')
return -1;
}
return 0;
}
static void indicate_wx_custom_event(_adapter *padapter, char *msg)
{
#ifndef CONFIG_IOCTL_CFG80211
u8 *buff, *p;
union iwreq_data wrqu;
if ((u32)strlen(msg) > IW_CUSTOM_MAX) {
DBG_871X("%s strlen(msg):%u > IW_CUSTOM_MAX:%u\n", __FUNCTION__ ,(u32)strlen(msg), IW_CUSTOM_MAX);
return;
}
buff = kzalloc(IW_CUSTOM_MAX+1, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
if(!buff)
return;
memcpy(buff, msg, strlen(msg));
_rtw_memset(&wrqu,0,sizeof(wrqu));
wrqu.data.length = strlen(msg);
DBG_871X("%s %s\n", __FUNCTION__, buff);
wireless_send_event(padapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
rtw_mfree(buff, IW_CUSTOM_MAX+1);
#endif
}
static void request_wps_pbc_event(_adapter *padapter)
{
#ifndef CONFIG_IOCTL_CFG80211
u8 *buff, *p;
union iwreq_data wrqu;
buff = kzalloc(IW_CUSTOM_MAX, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
if(!buff)
return;
p=buff;
p+=sprintf(p, "WPS_PBC_START.request=TRUE");
_rtw_memset(&wrqu,0,sizeof(wrqu));
wrqu.data.length = p-buff;
wrqu.data.length = (wrqu.data.length<IW_CUSTOM_MAX) ? wrqu.data.length:IW_CUSTOM_MAX;
DBG_871X("%s\n", __FUNCTION__);
wireless_send_event(padapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
if(buff)
{
rtw_mfree(buff, IW_CUSTOM_MAX);
}
#endif
}
void indicate_wx_scan_complete_event(_adapter *padapter)
{
#ifndef CONFIG_IOCTL_CFG80211
union iwreq_data wrqu;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
_rtw_memset(&wrqu, 0, sizeof(union iwreq_data));
//DBG_871X("+rtw_indicate_wx_scan_complete_event\n");
wireless_send_event(padapter->pnetdev, SIOCGIWSCAN, &wrqu, NULL);
#endif
}
void rtw_indicate_wx_assoc_event(_adapter *padapter)
{
#ifndef CONFIG_IOCTL_CFG80211
union iwreq_data wrqu;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
_rtw_memset(&wrqu, 0, sizeof(union iwreq_data));
wrqu.ap_addr.sa_family = ARPHRD_ETHER;
memcpy(wrqu.ap_addr.sa_data, pmlmepriv->cur_network.network.MacAddress, ETH_ALEN);
//DBG_871X("+rtw_indicate_wx_assoc_event\n");
wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL);
#endif
}
void rtw_indicate_wx_disassoc_event(_adapter *padapter)
{
#ifndef CONFIG_IOCTL_CFG80211
union iwreq_data wrqu;
_rtw_memset(&wrqu, 0, sizeof(union iwreq_data));
wrqu.ap_addr.sa_family = ARPHRD_ETHER;
_rtw_memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
//DBG_871X("+rtw_indicate_wx_disassoc_event\n");
wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL);
#endif
}
/*
uint rtw_is_cckrates_included(u8 *rate)
{
u32 i = 0;
while(rate[i]!=0)
{
if ( (((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
(((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22) )
return _TRUE;
i++;
}
return _FALSE;
}
uint rtw_is_cckratesonly_included(u8 *rate)
{
u32 i = 0;
while(rate[i]!=0)
{
if ( (((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
(((rate[i]) & 0x7f) != 11) && (((rate[i]) & 0x7f) != 22) )
return _FALSE;
i++;
}
return _TRUE;
}
*/
static int search_p2p_wfd_ie(_adapter *padapter,
struct iw_request_info* info, struct wlan_network *pnetwork,
char *start, char *stop)
{
#ifdef CONFIG_P2P
struct wifidirect_info *pwdinfo = &padapter->wdinfo;
#ifdef CONFIG_WFD
if ( SCAN_RESULT_ALL == pwdinfo->wfd_info->scan_result_type )
{
}
else if ( ( SCAN_RESULT_P2P_ONLY == pwdinfo->wfd_info->scan_result_type ) ||
( SCAN_RESULT_WFD_TYPE == pwdinfo->wfd_info->scan_result_type ) )
#endif // CONFIG_WFD
{
if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
{
u32 blnGotP2PIE = _FALSE;
// User is doing the P2P device discovery
// The prefix of SSID should be "DIRECT-" and the IE should contains the P2P IE.
// If not, the driver should ignore this AP and go to the next AP.
// Verifying the SSID
if ( _rtw_memcmp( pnetwork->network.Ssid.Ssid, pwdinfo->p2p_wildcard_ssid, P2P_WILDCARD_SSID_LEN ) )
{
u32 p2pielen = 0;
// Verifying the P2P IE
if (rtw_get_p2p_ie_from_scan_queue(&pnetwork->network.IEs[0], pnetwork->network.IELength, NULL, &p2pielen, pnetwork->network.Reserved[0]))
{
blnGotP2PIE = _TRUE;
}
}
if ( blnGotP2PIE == _FALSE )
{
return _FALSE;
}
}
}
#ifdef CONFIG_WFD
if ( SCAN_RESULT_WFD_TYPE == pwdinfo->wfd_info->scan_result_type )
{
u32 blnGotWFD = _FALSE;
u8 wfd_ie[ 128 ] = { 0x00 };
uint wfd_ielen = 0;
if ( rtw_get_wfd_ie_from_scan_queue( &pnetwork->network.IEs[0], pnetwork->network.IELength, wfd_ie, &wfd_ielen, pnetwork->network.Reserved[0]) )
{
u8 wfd_devinfo[ 6 ] = { 0x00 };
uint wfd_devlen = 6;
if ( rtw_get_wfd_attr_content( wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, wfd_devinfo, &wfd_devlen) )
{
if ( pwdinfo->wfd_info->wfd_device_type == WFD_DEVINFO_PSINK )
{
// the first two bits will indicate the WFD device type
if ( ( wfd_devinfo[ 1 ] & 0x03 ) == WFD_DEVINFO_SOURCE )
{
// If this device is Miracast PSink device, the scan reuslt should just provide the Miracast source.
blnGotWFD = _TRUE;
}
}
else if ( pwdinfo->wfd_info->wfd_device_type == WFD_DEVINFO_SOURCE )
{
// the first two bits will indicate the WFD device type
if ( ( wfd_devinfo[ 1 ] & 0x03 ) == WFD_DEVINFO_PSINK )
{
// If this device is Miracast source device, the scan reuslt should just provide the Miracast PSink.
// Todo: How about the SSink?!
blnGotWFD = _TRUE;
}
}
}
}
if ( blnGotWFD == _FALSE )
{
return _FALSE;
}
}
#endif // CONFIG_WFD
#endif //CONFIG_P2P
return _TRUE;
}
static inline char *iwe_stream_mac_addr_proess(_adapter *padapter,
struct iw_request_info* info, struct wlan_network *pnetwork,
char *start, char *stop,struct iw_event *iwe)
{
/* AP MAC address */
iwe->cmd = SIOCGIWAP;
iwe->u.ap_addr.sa_family = ARPHRD_ETHER;
memcpy(iwe->u.ap_addr.sa_data, pnetwork->network.MacAddress, ETH_ALEN);
start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_ADDR_LEN);
return start;
}
static inline char * iwe_stream_essid_proess(_adapter *padapter,
struct iw_request_info* info, struct wlan_network *pnetwork,
char *start, char *stop,struct iw_event *iwe)
{
/* Add the ESSID */
iwe->cmd = SIOCGIWESSID;
iwe->u.data.flags = 1;
iwe->u.data.length = min((u16)pnetwork->network.Ssid.SsidLength, (u16)32);
start = iwe_stream_add_point(info, start, stop, iwe, pnetwork->network.Ssid.Ssid);
return start;
}
static inline char * iwe_stream_chan_process(_adapter *padapter,
struct iw_request_info* info, struct wlan_network *pnetwork,
char *start, char *stop,struct iw_event *iwe)
{
if(pnetwork->network.Configuration.DSConfig<1 /*|| pnetwork->network.Configuration.DSConfig>14*/)
pnetwork->network.Configuration.DSConfig = 1;
/* Add frequency/channel */
iwe->cmd = SIOCGIWFREQ;
iwe->u.freq.m = rtw_ch2freq(pnetwork->network.Configuration.DSConfig) * 100000;
iwe->u.freq.e = 1;
iwe->u.freq.i = pnetwork->network.Configuration.DSConfig;
start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_FREQ_LEN);
return start;
}
static inline char * iwe_stream_mode_process(_adapter *padapter,
struct iw_request_info* info, struct wlan_network *pnetwork,
char *start, char *stop,struct iw_event *iwe,u16 cap)
{
/* Add mode */
if(cap & (WLAN_CAPABILITY_IBSS |WLAN_CAPABILITY_BSS)){
iwe->cmd = SIOCGIWMODE;
if (cap & WLAN_CAPABILITY_BSS)
iwe->u.mode = IW_MODE_MASTER;
else
iwe->u.mode = IW_MODE_ADHOC;
start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_UINT_LEN);
}
return start;
}
static inline char * iwe_stream_encryption_process(_adapter *padapter,
struct iw_request_info* info, struct wlan_network *pnetwork,
char *start, char *stop,struct iw_event *iwe,u16 cap)
{
/* Add encryption capability */
iwe->cmd = SIOCGIWENCODE;
if (cap & WLAN_CAPABILITY_PRIVACY)
iwe->u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
else
iwe->u.data.flags = IW_ENCODE_DISABLED;
iwe->u.data.length = 0;
start = iwe_stream_add_point(info, start, stop, iwe, pnetwork->network.Ssid.Ssid);
return start;
}
static inline char * iwe_stream_protocol_process(_adapter *padapter,
struct iw_request_info* info, struct wlan_network *pnetwork,
char *start, char *stop,struct iw_event *iwe)
{
u16 ht_cap=_FALSE,vht_cap = _FALSE;
u32 ht_ielen = 0, vht_ielen = 0;
char *p;
u8 ie_offset = (pnetwork->network.Reserved[0] == 2? 0:12);// Probe Request
//parsing HT_CAP_IE
p = rtw_get_ie(&pnetwork->network.IEs[ie_offset], _HT_CAPABILITY_IE_, &ht_ielen, pnetwork->network.IELength-ie_offset);
if(p && ht_ielen>0)
ht_cap = _TRUE;
#ifdef CONFIG_80211AC_VHT
//parsing VHT_CAP_IE
p = rtw_get_ie(&pnetwork->network.IEs[ie_offset], EID_VHTCapability, &vht_ielen, pnetwork->network.IELength-ie_offset);
if(p && vht_ielen>0)
vht_cap = _TRUE;
#endif
/* Add the protocol name */
iwe->cmd = SIOCGIWNAME;
if ((rtw_is_cckratesonly_included((u8*)&pnetwork->network.SupportedRates)) == _TRUE)
{
if(ht_cap == _TRUE)
snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11bn");
else
snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11b");
}
else if ((rtw_is_cckrates_included((u8*)&pnetwork->network.SupportedRates)) == _TRUE)
{
if(ht_cap == _TRUE)
snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11bgn");
else
snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11bg");
}
else
{
if(pnetwork->network.Configuration.DSConfig > 14)
{
#ifdef CONFIG_80211AC_VHT
if(vht_cap == _TRUE){
snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11AC");
}
else
#endif
{
if(ht_cap == _TRUE)
snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11an");
else
snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11a");
}
}
else
{
if(ht_cap == _TRUE)
snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11gn");
else
snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11g");
}
}
start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_CHAR_LEN);
return start;
}
static inline char * iwe_stream_rate_process(_adapter *padapter,
struct iw_request_info* info, struct wlan_network *pnetwork,
char *start, char *stop,struct iw_event *iwe)
{
u32 ht_ielen = 0, vht_ielen = 0;
char *p;
u16 max_rate=0, rate, ht_cap=_FALSE, vht_cap = _FALSE;
u32 i = 0;
u8 bw_40MHz=0, short_GI=0, bw_160MHz=0, vht_highest_rate = 0;
u16 mcs_rate=0, vht_data_rate=0;
char custom[MAX_CUSTOM_LEN]={0};
u8 ie_offset = (pnetwork->network.Reserved[0] == 2? 0:12);// Probe Request
//parsing HT_CAP_IE
p = rtw_get_ie(&pnetwork->network.IEs[ie_offset], _HT_CAPABILITY_IE_, &ht_ielen, pnetwork->network.IELength-ie_offset);
if(p && ht_ielen>0)
{
struct rtw_ieee80211_ht_cap *pht_capie;
ht_cap = _TRUE;
pht_capie = (struct rtw_ieee80211_ht_cap *)(p+2);
memcpy(&mcs_rate , pht_capie->supp_mcs_set, 2);
bw_40MHz = (pht_capie->cap_info&IEEE80211_HT_CAP_SUP_WIDTH) ? 1:0;
short_GI = (pht_capie->cap_info&(IEEE80211_HT_CAP_SGI_20|IEEE80211_HT_CAP_SGI_40)) ? 1:0;
}
#ifdef CONFIG_80211AC_VHT
//parsing VHT_CAP_IE
p = rtw_get_ie(&pnetwork->network.IEs[ie_offset], EID_VHTCapability, &vht_ielen, pnetwork->network.IELength-ie_offset);
if(p && vht_ielen>0)
{
u8 mcs_map[2];
vht_cap = _TRUE;
bw_160MHz = GET_VHT_CAPABILITY_ELE_CHL_WIDTH(p+2);
if(bw_160MHz)
short_GI = GET_VHT_CAPABILITY_ELE_SHORT_GI160M(p+2);
else
short_GI = GET_VHT_CAPABILITY_ELE_SHORT_GI80M(p+2);
memcpy(mcs_map, GET_VHT_CAPABILITY_ELE_TX_MCS(p+2), 2);
vht_highest_rate = rtw_get_vht_highest_rate(mcs_map);
vht_data_rate = rtw_vht_mcs_to_data_rate(CHANNEL_WIDTH_80, short_GI, vht_highest_rate);
}
#endif
/*Add basic and extended rates */
p = custom;
p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Rates (Mb/s): ");
while(pnetwork->network.SupportedRates[i]!=0)
{
rate = pnetwork->network.SupportedRates[i]&0x7F;
if (rate > max_rate)
max_rate = rate;
p += snprintf(p, MAX_CUSTOM_LEN - (p - custom),
"%d%s ", rate >> 1, (rate & 1) ? ".5" : "");
i++;
}
#ifdef CONFIG_80211AC_VHT
if(vht_cap == _TRUE) {
max_rate = vht_data_rate;
}
else
#endif
if(ht_cap == _TRUE)
{
if(mcs_rate&0x8000)//MCS15
{
max_rate = (bw_40MHz) ? ((short_GI)?300:270):((short_GI)?144:130);
}
else if(mcs_rate&0x0080)//MCS7
{
max_rate = (bw_40MHz) ? ((short_GI)?150:135):((short_GI)?72:65);
}
else//default MCS7
{
//DBG_871X("wx_get_scan, mcs_rate_bitmap=0x%x\n", mcs_rate);
max_rate = (bw_40MHz) ? ((short_GI)?150:135):((short_GI)?72:65);
}
max_rate = max_rate*2;//Mbps/2;
}
iwe->cmd = SIOCGIWRATE;
iwe->u.bitrate.fixed = iwe->u.bitrate.disabled = 0;
iwe->u.bitrate.value = max_rate * 500000;
start =iwe_stream_add_event(info, start, stop, iwe, IW_EV_PARAM_LEN);
return start ;
}
static inline char * iwe_stream_wpa_wpa2_process(_adapter *padapter,
struct iw_request_info* info, struct wlan_network *pnetwork,
char *start, char *stop,struct iw_event *iwe)
{
int buf_size = MAX_WPA_IE_LEN*2;
//u8 pbuf[buf_size]={0};
u8 *pbuf = kzalloc(buf_size, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
u8 wpa_ie[255]={0},rsn_ie[255]={0};
u16 i, wpa_len=0,rsn_len=0;
u8 *p;
sint out_len=0;
if(pbuf){
p=pbuf;
//parsing WPA/WPA2 IE
if (pnetwork->network.Reserved[0] != 2) // Probe Request
{
out_len=rtw_get_sec_ie(pnetwork->network.IEs ,pnetwork->network.IELength,rsn_ie,&rsn_len,wpa_ie,&wpa_len);
RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("rtw_wx_get_scan: ssid=%s\n",pnetwork->network.Ssid.Ssid));
RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("rtw_wx_get_scan: wpa_len=%d rsn_len=%d\n",wpa_len,rsn_len));
if (wpa_len > 0){
_rtw_memset(pbuf, 0, buf_size);
p += sprintf(p, "wpa_ie=");
for (i = 0; i < wpa_len; i++) {
p += sprintf(p, "%02x", wpa_ie[i]);
}
if (wpa_len > 100) {
printk("-----------------Len %d----------------\n", wpa_len);
for (i = 0; i < wpa_len; i++) {
printk("%02x ", wpa_ie[i]);
}
printk("\n");
printk("-----------------Len %d----------------\n", wpa_len);
}
_rtw_memset(iwe, 0, sizeof(*iwe));
iwe->cmd = IWEVCUSTOM;
iwe->u.data.length = strlen(pbuf);
start = iwe_stream_add_point(info, start, stop, iwe,pbuf);
_rtw_memset(iwe, 0, sizeof(*iwe));
iwe->cmd =IWEVGENIE;
iwe->u.data.length = wpa_len;
start = iwe_stream_add_point(info, start, stop, iwe, wpa_ie);
}
if (rsn_len > 0){
_rtw_memset(pbuf, 0, buf_size);
p += sprintf(p, "rsn_ie=");
for (i = 0; i < rsn_len; i++) {
p += sprintf(p, "%02x", rsn_ie[i]);
}
_rtw_memset(iwe, 0, sizeof(*iwe));
iwe->cmd = IWEVCUSTOM;
iwe->u.data.length = strlen(pbuf);
start = iwe_stream_add_point(info, start, stop, iwe,pbuf);
_rtw_memset(iwe, 0, sizeof(*iwe));
iwe->cmd =IWEVGENIE;
iwe->u.data.length = rsn_len;
start = iwe_stream_add_point(info, start, stop, iwe, rsn_ie);
}
}
rtw_mfree(pbuf, buf_size);
}
return start;
}
static inline char * iwe_stream_wps_process(_adapter *padapter,
struct iw_request_info* info, struct wlan_network *pnetwork,
char *start, char *stop,struct iw_event *iwe)
{
//parsing WPS IE
uint cnt = 0,total_ielen;
u8 *wpsie_ptr=NULL;
uint wps_ielen = 0;
u8 ie_offset = (pnetwork->network.Reserved[0] == 2? 0:12);
u8 *ie_ptr = pnetwork->network.IEs + ie_offset;
total_ielen= pnetwork->network.IELength - ie_offset;
if (pnetwork->network.Reserved[0] == 2) // Probe Request
{
ie_ptr = pnetwork->network.IEs;
total_ielen = pnetwork->network.IELength;
}
else // Beacon or Probe Respones
{
ie_ptr = pnetwork->network.IEs + _FIXED_IE_LENGTH_;
total_ielen = pnetwork->network.IELength - _FIXED_IE_LENGTH_;
}
while(cnt < total_ielen)
{
if(rtw_is_wps_ie(&ie_ptr[cnt], &wps_ielen) && (wps_ielen>2))
{
wpsie_ptr = &ie_ptr[cnt];
iwe->cmd =IWEVGENIE;
iwe->u.data.length = (u16)wps_ielen;
start = iwe_stream_add_point(info, start, stop,iwe, wpsie_ptr);
}
cnt+=ie_ptr[cnt+1]+2; //goto next
}
return start;
}
static inline char * iwe_stream_wapi_process(_adapter *padapter,
struct iw_request_info* info, struct wlan_network *pnetwork,
char *start, char *stop,struct iw_event *iwe)
{
#ifdef CONFIG_WAPI_SUPPORT
char *p;
if (pnetwork->network.Reserved[0] != 2) // Probe Request
{
sint out_len_wapi=0;
/* here use static for stack size */
static u8 buf_wapi[MAX_WAPI_IE_LEN*2]={0};
static u8 wapi_ie[MAX_WAPI_IE_LEN]={0};
u16 wapi_len=0;
u16 i;
out_len_wapi=rtw_get_wapi_ie(pnetwork->network.IEs ,pnetwork->network.IELength,wapi_ie,&wapi_len);
RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("rtw_wx_get_scan: ssid=%s\n",pnetwork->network.Ssid.Ssid));
RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("rtw_wx_get_scan: wapi_len=%d \n",wapi_len));
DBG_871X("rtw_wx_get_scan: %s ",pnetwork->network.Ssid.Ssid);
DBG_871X("rtw_wx_get_scan: ssid = %d ",wapi_len);
if (wapi_len > 0)
{
p=buf_wapi;
//_rtw_memset(buf_wapi, 0, MAX_WAPI_IE_LEN*2);
p += sprintf(p, "wapi_ie=");
for (i = 0; i < wapi_len; i++) {
p += sprintf(p, "%02x", wapi_ie[i]);
}
_rtw_memset(iwe, 0, sizeof(*iwe));
iwe->cmd = IWEVCUSTOM;
iwe->u.data.length = strlen(buf_wapi);
start = iwe_stream_add_point(info, start, stop, iwe,buf_wapi);
_rtw_memset(iwe, 0, sizeof(*iwe));
iwe->cmd =IWEVGENIE;
iwe->u.data.length = wapi_len;
start = iwe_stream_add_point(info, start, stop, iwe, wapi_ie);
}
}
#endif//#ifdef CONFIG_WAPI_SUPPORT
return start;
}
static inline char * iwe_stream_rssi_process(_adapter *padapter,
struct iw_request_info* info, struct wlan_network *pnetwork,
char *start, char *stop,struct iw_event *iwe)
{
u8 ss, sq;
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
/* Add quality statistics */
iwe->cmd = IWEVQUAL;
iwe->u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED
#if defined(CONFIG_SIGNAL_DISPLAY_DBM) && defined(CONFIG_BACKGROUND_NOISE_MONITOR)
| IW_QUAL_NOISE_UPDATED
#else
| IW_QUAL_NOISE_INVALID
#endif
#ifdef CONFIG_SIGNAL_DISPLAY_DBM
| IW_QUAL_DBM
#endif
;
if ( check_fwstate(pmlmepriv, _FW_LINKED)== _TRUE &&
is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network, 0)){
ss = padapter->recvpriv.signal_strength;
sq = padapter->recvpriv.signal_qual;
} else {
ss = pnetwork->network.PhyInfo.SignalStrength;
sq = pnetwork->network.PhyInfo.SignalQuality;
}
#ifdef CONFIG_SIGNAL_DISPLAY_DBM
iwe->u.qual.level = (u8) translate_percentage_to_dbm(ss);//dbm
#else
#ifdef CONFIG_SKIP_SIGNAL_SCALE_MAPPING
{
/* Do signal scale mapping when using percentage as the unit of signal strength, since the scale mapping is skipped in odm */
HAL_DATA_TYPE *pHal = GET_HAL_DATA(padapter);
iwe->u.qual.level = (u8)odm_SignalScaleMapping(&pHal->odmpriv, ss);
}
#else
iwe->u.qual.level = (u8)ss;//%
#endif
#endif
iwe->u.qual.qual = (u8)sq; // signal quality
#ifdef CONFIG_PLATFORM_ROCKCHIPS
iwe->u.qual.noise = -100; // noise level suggest by zhf@rockchips
#else
#if defined(CONFIG_SIGNAL_DISPLAY_DBM) && defined(CONFIG_BACKGROUND_NOISE_MONITOR)
{
s16 tmp_noise=0;
rtw_hal_get_odm_var(padapter, HAL_ODM_NOISE_MONITOR,&(pnetwork->network.Configuration.DSConfig), &(tmp_noise));
iwe->u.qual.noise = tmp_noise;
}
#else
iwe->u.qual.noise = 0; // noise level
#endif
#endif //CONFIG_PLATFORM_ROCKCHIPS
//DBG_871X("iqual=%d, ilevel=%d, inoise=%d, iupdated=%d\n", iwe.u.qual.qual, iwe.u.qual.level , iwe.u.qual.noise, iwe.u.qual.updated);
start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_QUAL_LEN);
return start;
}
static inline char * iwe_stream_net_rsv_process(_adapter *padapter,
struct iw_request_info* info, struct wlan_network *pnetwork,
char *start, char *stop,struct iw_event *iwe)
{
u8 buf[32] = {0};
u8 * p,*pos;
int len;
p = buf;
pos = pnetwork->network.Reserved;
p += sprintf(p, "fm=%02X%02X", pos[1], pos[0]);
_rtw_memset(iwe, 0, sizeof(*iwe));
iwe->cmd = IWEVCUSTOM;
iwe->u.data.length = strlen(buf);
start = iwe_stream_add_point(info, start, stop,iwe, buf);
return start;
}
static char *translate_scan(_adapter *padapter,
struct iw_request_info* info, struct wlan_network *pnetwork,
char *start, char *stop)
{
struct iw_event iwe;
u16 cap = 0;
_rtw_memset(&iwe, 0, sizeof(iwe));
if(_FALSE == search_p2p_wfd_ie(padapter,info,pnetwork,start,stop))
return start;
start = iwe_stream_mac_addr_proess(padapter,info,pnetwork,start,stop,&iwe);
start = iwe_stream_essid_proess(padapter,info,pnetwork,start,stop,&iwe);
start = iwe_stream_protocol_process(padapter,info,pnetwork,start,stop,&iwe);
if (pnetwork->network.Reserved[0] == 2) // Probe Request
{
cap = 0;
}
else
{
memcpy((u8 *)&cap, rtw_get_capability_from_ie(pnetwork->network.IEs), 2);
cap = le16_to_cpu(cap);
}
start = iwe_stream_mode_process(padapter,info,pnetwork,start,stop,&iwe,cap);
start = iwe_stream_chan_process(padapter,info,pnetwork,start,stop,&iwe);
start = iwe_stream_encryption_process(padapter,info,pnetwork,start,stop,&iwe,cap);
start = iwe_stream_rate_process(padapter,info,pnetwork,start,stop,&iwe);
start = iwe_stream_wpa_wpa2_process(padapter,info,pnetwork,start,stop,&iwe);
start = iwe_stream_wps_process(padapter,info,pnetwork,start,stop,&iwe);
start = iwe_stream_wapi_process(padapter,info,pnetwork,start,stop,&iwe);
start = iwe_stream_rssi_process(padapter,info,pnetwork,start,stop,&iwe);
start = iwe_stream_net_rsv_process(padapter,info,pnetwork,start,stop,&iwe);
return start;
}
static int wpa_set_auth_algs(struct net_device *dev, u32 value)
{
_adapter *padapter = (_adapter *) rtw_netdev_priv(dev);
int ret = 0;
if ((value & AUTH_ALG_SHARED_KEY)&&(value & AUTH_ALG_OPEN_SYSTEM))
{
DBG_871X("wpa_set_auth_algs, AUTH_ALG_SHARED_KEY and AUTH_ALG_OPEN_SYSTEM [value:0x%x]\n",value);
padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeAutoSwitch;
padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
}
else if (value & AUTH_ALG_SHARED_KEY)
{
DBG_871X("wpa_set_auth_algs, AUTH_ALG_SHARED_KEY [value:0x%x]\n",value);
padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
#ifdef CONFIG_PLATFORM_MT53XX
padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeAutoSwitch;
padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
#else
padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeShared;
padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Shared;
#endif
}
else if(value & AUTH_ALG_OPEN_SYSTEM)
{
DBG_871X("wpa_set_auth_algs, AUTH_ALG_OPEN_SYSTEM\n");
//padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
if(padapter->securitypriv.ndisauthtype < Ndis802_11AuthModeWPAPSK)
{
#ifdef CONFIG_PLATFORM_MT53XX
padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeAutoSwitch;
padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
#else
padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
#endif
}
}
else if(value & AUTH_ALG_LEAP)
{
DBG_871X("wpa_set_auth_algs, AUTH_ALG_LEAP\n");
}
else
{
DBG_871X("wpa_set_auth_algs, error!\n");
ret = -EINVAL;
}
return ret;
}
static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len)
{
int ret = 0;
u32 wep_key_idx, wep_key_len,wep_total_len;
NDIS_802_11_WEP *pwep = NULL;
_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
struct security_priv *psecuritypriv = &padapter->securitypriv;
#ifdef CONFIG_P2P
struct wifidirect_info* pwdinfo = &padapter->wdinfo;
#endif //CONFIG_P2P
_func_enter_;
param->u.crypt.err = 0;
param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
if (param_len < (u32) ((u8 *) param->u.crypt.key - (u8 *) param) + param->u.crypt.key_len)
{
ret = -EINVAL;
goto exit;
}
if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
{
if (param->u.crypt.idx >= WEP_KEYS
#ifdef CONFIG_IEEE80211W
&& param->u.crypt.idx > BIP_MAX_KEYID
#endif //CONFIG_IEEE80211W
)
{
ret = -EINVAL;
goto exit;
}
}
else
{
{
ret = -EINVAL;
goto exit;
}
}
if (strcmp(param->u.crypt.alg, "WEP") == 0)
{
RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_err_,("wpa_set_encryption, crypt.alg = WEP\n"));
DBG_871X("wpa_set_encryption, crypt.alg = WEP\n");
padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
padapter->securitypriv.dot11PrivacyAlgrthm=_WEP40_;
padapter->securitypriv.dot118021XGrpPrivacy=_WEP40_;
wep_key_idx = param->u.crypt.idx;
wep_key_len = param->u.crypt.key_len;
RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_info_,("(1)wep_key_idx=%d\n", wep_key_idx));
DBG_871X("(1)wep_key_idx=%d\n", wep_key_idx);
if (wep_key_idx > WEP_KEYS)
return -EINVAL;
RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_info_,("(2)wep_key_idx=%d\n", wep_key_idx));
if (wep_key_len > 0)
{
wep_key_len = wep_key_len <= 5 ? 5 : 13;
wep_total_len = wep_key_len + FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial);
pwep = kzalloc(wep_total_len, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
if (!pwep){