-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcfg80211drv.c
1229 lines (980 loc) · 28.6 KB
/
cfg80211drv.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
/*
*************************************************************************
* Ralink Tech Inc.
* 5F., No.36, Taiyuan St., Jhubei City,
* Hsinchu County 302,
* Taiwan, R.O.C.
*
* (c) Copyright 2002-2010, Ralink Technology, Inc.
*
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
*************************************************************************/
#ifdef RT_CFG80211_SUPPORT
#include "rt_config.h"
#define RT_CFG80211_DEBUG /* debug use */
#define CFG80211CB (pAd->pCfg80211_CB)
#ifdef RT_CFG80211_DEBUG
#define CFG80211DBG(__Flg, __pMsg) DBGPRINT(__Flg, __pMsg)
#else
#define CFG80211DBG(__Flg, __pMsg)
#endif /* RT_CFG80211_DEBUG */
INT CFG80211DRV_IoctlHandle(
IN VOID *pAdSrc,
IN RTMP_IOCTL_INPUT_STRUCT *wrq,
IN INT cmd,
IN USHORT subcmd,
IN VOID *pData,
IN ULONG Data)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdSrc;
switch(cmd)
{
case CMD_RTPRIV_IOCTL_80211_START:
case CMD_RTPRIV_IOCTL_80211_END:
/* nothing to do */
break;
case CMD_RTPRIV_IOCTL_80211_CB_GET:
*(VOID **)pData = (VOID *)(pAd->pCfg80211_CB);
break;
case CMD_RTPRIV_IOCTL_80211_CB_SET:
pAd->pCfg80211_CB = pData;
break;
case CMD_RTPRIV_IOCTL_80211_CHAN_SET:
if (CFG80211DRV_OpsSetChannel(pAd, pData) != TRUE)
return NDIS_STATUS_FAILURE;
break;
case CMD_RTPRIV_IOCTL_80211_VIF_CHG:
if (CFG80211DRV_OpsChgVirtualInf(pAd, pData, Data) != TRUE)
return NDIS_STATUS_FAILURE;
break;
case CMD_RTPRIV_IOCTL_80211_SCAN:
CFG80211DRV_OpsScan(pAd);
break;
case CMD_RTPRIV_IOCTL_80211_IBSS_JOIN:
CFG80211DRV_OpsJoinIbss(pAd, pData);
break;
case CMD_RTPRIV_IOCTL_80211_STA_LEAVE:
CFG80211DRV_OpsLeave(pAd);
break;
case CMD_RTPRIV_IOCTL_80211_STA_GET:
if (CFG80211DRV_StaGet(pAd, pData) != TRUE)
return NDIS_STATUS_FAILURE;
break;
case CMD_RTPRIV_IOCTL_80211_KEY_ADD:
CFG80211DRV_KeyAdd(pAd, pData);
break;
case CMD_RTPRIV_IOCTL_80211_KEY_DEFAULT_SET:
#ifdef CONFIG_STA_SUPPORT
pAd->StaCfg.DefaultKeyId = Data; /* base 0 */
#endif /* CONFIG_STA_SUPPORT */
break;
case CMD_RTPRIV_IOCTL_80211_CONNECT_TO:
CFG80211DRV_Connect(pAd, pData);
break;
#ifdef RFKILL_HW_SUPPORT
case CMD_RTPRIV_IOCTL_80211_RFKILL:
{
UINT32 data = 0;
BOOLEAN active;
/* Read GPIO pin2 as Hardware controlled radio state */
RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &data);
active = !!(data & 0x04);
if (!active)
{
RTMPSetLED(pAd, LED_RADIO_OFF);
*(UINT8 *)pData = 0;
}
else
*(UINT8 *)pData = 1;
}
break;
#endif /* RFKILL_HW_SUPPORT */
case CMD_RTPRIV_IOCTL_80211_REG_NOTIFY_TO:
CFG80211DRV_RegNotify(pAd, pData);
break;
case CMD_RTPRIV_IOCTL_80211_UNREGISTER:
CFG80211_UnRegister(pAd, pData);
break;
case CMD_RTPRIV_IOCTL_80211_BANDINFO_GET:
{
CFG80211_BAND *pBandInfo = (CFG80211_BAND *)pData;
CFG80211_BANDINFO_FILL(pAd, pBandInfo);
}
break;
case CMD_RTPRIV_IOCTL_80211_SURVEY_GET:
CFG80211DRV_SurveyGet(pAd, pData);
break;
#ifdef RT_P2P_SPECIFIC_WIRELESS_EVENT
case CMD_RTPRIV_IOCTL_80211_SEND_WIRELESS_EVENT:
CFG80211_SendWirelessEvent(pAd, pData);
break;
#endif /* RT_P2P_SPECIFIC_WIRELESS_EVENT */
default:
return NDIS_STATUS_FAILURE;
}
return NDIS_STATUS_SUCCESS;
}
BOOLEAN CFG80211DRV_OpsSetChannel(
VOID *pAdOrg,
VOID *pData)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
CMD_RTPRIV_IOCTL_80211_CHAN *pChan;
UINT8 ChanId;
UINT8 IfType;
UINT8 ChannelType;
STRING ChStr[5] = { 0 };
#ifdef DOT11_N_SUPPORT
UCHAR BW_Old;
BOOLEAN FlgIsChanged;
#endif /* DOT11_N_SUPPORT */
/* init */
pChan = (CMD_RTPRIV_IOCTL_80211_CHAN *)pData;
ChanId = pChan->ChanId;
IfType = pChan->IfType;
ChannelType = pChan->ChanType;
#ifdef DOT11_N_SUPPORT
if (IfType != RT_CMD_80211_IFTYPE_MONITOR)
{
/* get channel BW */
FlgIsChanged = FALSE;
BW_Old = pAd->CommonCfg.RegTransmitSetting.field.BW;
/* set to new channel BW */
if (ChannelType == RT_CMD_80211_CHANTYPE_HT20)
{
pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
FlgIsChanged = TRUE;
}
else if ((ChannelType == RT_CMD_80211_CHANTYPE_HT40MINUS) ||
(ChannelType == RT_CMD_80211_CHANTYPE_HT40PLUS))
{
/* not support NL80211_CHAN_HT40MINUS or NL80211_CHAN_HT40PLUS */
/* i.e. primary channel = 36, secondary channel must be 40 */
pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40;
FlgIsChanged = TRUE;
} /* End of if */
CFG80211DBG(RT_DEBUG_ERROR, ("80211> New BW = %d\n",
pAd->CommonCfg.RegTransmitSetting.field.BW));
/* change HT/non-HT mode (do NOT change wireless mode here) */
if (((ChannelType == RT_CMD_80211_CHANTYPE_NOHT) &&
(pAd->CommonCfg.HT_Disable == 0)) ||
((ChannelType != RT_CMD_80211_CHANTYPE_NOHT) &&
(pAd->CommonCfg.HT_Disable == 1)))
{
if (ChannelType == RT_CMD_80211_CHANTYPE_NOHT)
pAd->CommonCfg.HT_Disable = 1;
else
pAd->CommonCfg.HT_Disable = 0;
/* End of if */
FlgIsChanged = TRUE;
CFG80211DBG(RT_DEBUG_ERROR, ("80211> HT Disable = %d\n",
pAd->CommonCfg.HT_Disable));
} /* End of if */
}
else
{
/* for monitor mode */
FlgIsChanged = TRUE;
pAd->CommonCfg.HT_Disable = 0;
pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40;
} /* End of if */
if (FlgIsChanged == TRUE)
SetCommonHT(pAd);
/* End of if */
#endif /* DOT11_N_SUPPORT */
/* switch to the channel */
sprintf(ChStr, "%d", ChanId);
if (Set_Channel_Proc(pAd, ChStr) == FALSE)
{
CFG80211DBG(RT_DEBUG_ERROR, ("80211> Change channel fail!\n"));
} /* End of if */
#ifdef CONFIG_STA_SUPPORT
#ifdef DOT11_N_SUPPORT
if ((IfType == RT_CMD_80211_IFTYPE_STATION) && (FlgIsChanged == TRUE))
{
/*
1. Station mode;
2. New BW settings is 20MHz but current BW is not 20MHz;
3. New BW settings is 40MHz but current BW is 20MHz;
Re-connect to the AP due to BW 20/40 or HT/non-HT change.
*/
Set_SSID_Proc(pAd, (PSTRING)pAd->CommonCfg.Ssid);
} /* End of if */
#endif /* DOT11_N_SUPPORT */
if (IfType == RT_CMD_80211_IFTYPE_ADHOC)
{
/* update IBSS beacon */
MlmeUpdateTxRates(pAd, FALSE, 0);
MakeIbssBeacon(pAd);
AsicEnableIbssSync(pAd);
Set_SSID_Proc(pAd, (PSTRING)pAd->CommonCfg.Ssid);
} /* End of if */
if (IfType == RT_CMD_80211_IFTYPE_MONITOR)
{
/* reset monitor mode in the new channel */
Set_NetworkType_Proc(pAd, "Monitor");
RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, pChan->MonFilterFlag);
} /* End of if */
#endif /* CONFIG_STA_SUPPORT */
return TRUE;
}
BOOLEAN CFG80211DRV_OpsChgVirtualInf(
VOID *pAdOrg,
VOID *pFlgFilter,
UINT8 IfType)
{
#ifdef CONFIG_STA_SUPPORT
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
UINT32 FlgFilter = *(UINT32 *)pFlgFilter;
/* change type */
if (IfType == RT_CMD_80211_IFTYPE_ADHOC)
Set_NetworkType_Proc(pAd, "Adhoc");
else if (IfType == RT_CMD_80211_IFTYPE_STATION)
Set_NetworkType_Proc(pAd, "Infra");
else if (IfType == RT_CMD_80211_IFTYPE_MONITOR)
{
/* set packet filter */
Set_NetworkType_Proc(pAd, "Monitor");
if (FlgFilter != 0)
{
UINT32 Filter;
RTMP_IO_READ32(pAd, RX_FILTR_CFG, &Filter);
if ((FlgFilter & RT_CMD_80211_FILTER_FCSFAIL) == \
RT_CMD_80211_FILTER_FCSFAIL)
{
Filter = Filter & (~0x01);
}
else
Filter = Filter | 0x01;
/* End of if */
if ((FlgFilter & RT_CMD_80211_FILTER_PLCPFAIL) == \
RT_CMD_80211_FILTER_PLCPFAIL)
{
Filter = Filter & (~0x02);
}
else
Filter = Filter | 0x02;
/* End of if */
if ((FlgFilter & RT_CMD_80211_FILTER_CONTROL) == \
RT_CMD_80211_FILTER_CONTROL)
{
Filter = Filter & (~0xFF00);
}
else
Filter = Filter | 0xFF00;
/* End of if */
if ((FlgFilter & RT_CMD_80211_FILTER_OTHER_BSS) == \
RT_CMD_80211_FILTER_OTHER_BSS)
{
Filter = Filter & (~0x08);
}
else
Filter = Filter | 0x08;
/* End of if */
RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, Filter);
*(UINT32 *)pFlgFilter = Filter;
} /* End of if */
return TRUE; /* not need to set SSID */
} /* End of if */
pAd->StaCfg.bAutoReconnect = TRUE;
CFG80211DBG(RT_DEBUG_ERROR, ("80211> SSID = %s\n", pAd->CommonCfg.Ssid));
Set_SSID_Proc(pAd, (PSTRING)pAd->CommonCfg.Ssid);
#endif /* CONFIG_STA_SUPPORT */
return TRUE;
}
BOOLEAN CFG80211DRV_OpsScan(
VOID *pAdOrg)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
if (pAd->FlgCfg80211Scanning == TRUE)
return FALSE; /* scanning */
/* End of if */
/* do scan */
pAd->FlgCfg80211Scanning = TRUE;
return TRUE;
}
BOOLEAN CFG80211DRV_OpsJoinIbss(
VOID *pAdOrg,
VOID *pData)
{
#ifdef CONFIG_STA_SUPPORT
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
CMD_RTPRIV_IOCTL_80211_IBSS *pIbssInfo;
pIbssInfo = (CMD_RTPRIV_IOCTL_80211_IBSS *)pData;
pAd->StaCfg.bAutoReconnect = TRUE;
pAd->CommonCfg.BeaconPeriod = pIbssInfo->BeaconInterval;
Set_SSID_Proc(pAd, (PSTRING)pIbssInfo->pSsid);
#endif /* CONFIG_STA_SUPPORT */
return TRUE;
}
BOOLEAN CFG80211DRV_OpsLeave(
VOID *pAdOrg)
{
#ifdef CONFIG_STA_SUPPORT
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
pAd->StaCfg.bAutoReconnect = FALSE;
pAd->FlgCfg80211Connecting = FALSE;
LinkDown(pAd, FALSE);
#endif /* CONFIG_STA_SUPPORT */
return TRUE;
}
BOOLEAN CFG80211DRV_StaGet(
VOID *pAdOrg,
VOID *pData)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
CMD_RTPRIV_IOCTL_80211_STA *pIbssInfo;
pIbssInfo = (CMD_RTPRIV_IOCTL_80211_STA *)pData;
#ifdef CONFIG_STA_SUPPORT
{
HTTRANSMIT_SETTING PhyInfo;
ULONG DataRate = 0;
UINT32 RSSI;
/* fill tx rate */
if ((!WMODE_CAP_N(pAd->CommonCfg.PhyMode)) ||
(pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
{
PhyInfo.word = pAd->StaCfg.HTPhyMode.word;
}
else
PhyInfo.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
/* End of if */
getRate(PhyInfo, &DataRate);
if ((PhyInfo.field.MODE == MODE_HTMIX) ||
(PhyInfo.field.MODE == MODE_HTGREENFIELD))
{
if (PhyInfo.field.BW)
pIbssInfo->TxRateFlags |= RT_CMD_80211_TXRATE_BW_40;
/* End of if */
if (PhyInfo.field.ShortGI)
pIbssInfo->TxRateFlags |= RT_CMD_80211_TXRATE_SHORT_GI;
/* End of if */
pIbssInfo->TxRateMCS = PhyInfo.field.MCS;
}
else
{
pIbssInfo->TxRateFlags = RT_CMD_80211_TXRATE_LEGACY;
pIbssInfo->TxRateMCS = DataRate*10; /* unit: 100kbps */
} /* End of if */
/* fill signal */
RSSI = (pAd->StaCfg.RssiSample.AvgRssi0 +
pAd->StaCfg.RssiSample.AvgRssi1 +
pAd->StaCfg.RssiSample.AvgRssi2) / 3;
pIbssInfo->Signal = RSSI;
}
#endif /* CONFIG_STA_SUPPORT */
return TRUE;
}
BOOLEAN CFG80211DRV_KeyAdd(
VOID *pAdOrg,
VOID *pData)
{
#ifdef CONFIG_STA_SUPPORT
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
CMD_RTPRIV_IOCTL_80211_KEY *pKeyInfo;
pKeyInfo = (CMD_RTPRIV_IOCTL_80211_KEY *)pData;
if (pKeyInfo->KeyType == RT_CMD_80211_KEY_WEP)
{
switch(pKeyInfo->KeyId)
{
case 1:
default:
Set_Key1_Proc(pAd, (PSTRING)pKeyInfo->KeyBuf);
break;
case 2:
Set_Key2_Proc(pAd, (PSTRING)pKeyInfo->KeyBuf);
break;
case 3:
Set_Key3_Proc(pAd, (PSTRING)pKeyInfo->KeyBuf);
break;
case 4:
Set_Key4_Proc(pAd, (PSTRING)pKeyInfo->KeyBuf);
break;
} /* End of switch */
}
else
Set_WPAPSK_Proc(pAd, (PSTRING)pKeyInfo->KeyBuf);
#endif /* CONFIG_STA_SUPPORT */
return TRUE;
}
BOOLEAN CFG80211DRV_Connect(
VOID *pAdOrg,
VOID *pData)
{
#ifdef CONFIG_STA_SUPPORT
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
CMD_RTPRIV_IOCTL_80211_CONNECT *pConnInfo;
UCHAR SSID[NDIS_802_11_LENGTH_SSID];
UINT32 SSIDLen;
pConnInfo = (CMD_RTPRIV_IOCTL_80211_CONNECT *)pData;
/* change to infrastructure mode if we are in ADHOC mode */
Set_NetworkType_Proc(pAd, "Infra");
/* set authentication mode */
if (pConnInfo->WpaVer == 2)
{
if (pConnInfo->FlgIs8021x == TRUE)
Set_AuthMode_Proc(pAd, "WPA2");
else
Set_AuthMode_Proc(pAd, "WPA2PSK");
/* End of if */
}
else if (pConnInfo->WpaVer == 1)
{
if (pConnInfo->FlgIs8021x == TRUE)
Set_AuthMode_Proc(pAd, "WPA");
else
Set_AuthMode_Proc(pAd, "WPAPSK");
/* End of if */
}
else if (pConnInfo->FlgIsAuthOpen == FALSE)
Set_AuthMode_Proc(pAd, "SHARED");
else
Set_AuthMode_Proc(pAd, "OPEN");
/* End of if */
CFG80211DBG(RT_DEBUG_ERROR,
("80211> AuthMode = %d\n", pAd->StaCfg.AuthMode));
/* set encryption mode */
if (pConnInfo->PairwiseEncrypType & RT_CMD_80211_CONN_ENCRYPT_CCMP)
Set_EncrypType_Proc(pAd, "AES");
else if (pConnInfo->PairwiseEncrypType & RT_CMD_80211_CONN_ENCRYPT_TKIP)
Set_EncrypType_Proc(pAd, "TKIP");
else if (pConnInfo->PairwiseEncrypType & RT_CMD_80211_CONN_ENCRYPT_WEP)
{
Set_EncrypType_Proc(pAd, "WEP");
}
else if (pConnInfo->GroupwiseEncrypType & RT_CMD_80211_CONN_ENCRYPT_CCMP)
Set_EncrypType_Proc(pAd, "AES");
else if (pConnInfo->GroupwiseEncrypType & RT_CMD_80211_CONN_ENCRYPT_TKIP)
Set_EncrypType_Proc(pAd, "TKIP");
else
Set_EncrypType_Proc(pAd, "NONE");
/* End of if */
CFG80211DBG(RT_DEBUG_ERROR,
("80211> EncrypType = %d\n", pAd->StaCfg.WepStatus));
/* set channel: STATION will auto-scan */
/* set WEP key */
if (pConnInfo->pKey &&
((pConnInfo->GroupwiseEncrypType | pConnInfo->PairwiseEncrypType) &
RT_CMD_80211_CONN_ENCRYPT_WEP))
{
UCHAR KeyBuf[50];
/* reset AuthMode and EncrypType */
Set_AuthMode_Proc(pAd, "SHARED");
Set_EncrypType_Proc(pAd, "WEP");
/* reset key */
#ifdef RT_CFG80211_DEBUG
hex_dump("KeyBuf=", (UINT8 *)pConnInfo->pKey, pConnInfo->KeyLen);
#endif /* RT_CFG80211_DEBUG */
pAd->StaCfg.DefaultKeyId = pConnInfo->KeyIdx; /* base 0 */
if (pConnInfo->KeyLen >= sizeof(KeyBuf))
return FALSE;
/* End of if */
memcpy(KeyBuf, pConnInfo->pKey, pConnInfo->KeyLen);
KeyBuf[pConnInfo->KeyLen] = 0x00;
CFG80211DBG(RT_DEBUG_ERROR,
("80211> pAd->StaCfg.DefaultKeyId = %d\n",
pAd->StaCfg.DefaultKeyId));
switch(pConnInfo->KeyIdx)
{
case 1:
default:
Set_Key1_Proc(pAd, (PSTRING)KeyBuf);
break;
case 2:
Set_Key2_Proc(pAd, (PSTRING)KeyBuf);
break;
case 3:
Set_Key3_Proc(pAd, (PSTRING)KeyBuf);
break;
case 4:
Set_Key4_Proc(pAd, (PSTRING)KeyBuf);
break;
} /* End of switch */
} /* End of if */
/* TODO: We need to provide a command to set BSSID to associate a AP */
/* re-set SSID */
pAd->StaCfg.bAutoReconnect = TRUE;
pAd->FlgCfg80211Connecting = TRUE;
SSIDLen = pConnInfo->SsidLen;
if (SSIDLen > NDIS_802_11_LENGTH_SSID)
SSIDLen = NDIS_802_11_LENGTH_SSID;
/* End of if */
memset(&SSID, 0, sizeof(SSID));
memcpy(SSID, pConnInfo->pSsid, SSIDLen);
Set_SSID_Proc(pAd, (PSTRING)SSID);
CFG80211DBG(RT_DEBUG_ERROR, ("80211> SSID = %s\n", SSID));
#endif /* CONFIG_STA_SUPPORT */
return TRUE;
}
VOID CFG80211DRV_RegNotify(
VOID *pAdOrg,
VOID *pData)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
CMD_RTPRIV_IOCTL_80211_REG_NOTIFY *pRegInfo;
pRegInfo = (CMD_RTPRIV_IOCTL_80211_REG_NOTIFY *)pData;
/* keep Alpha2 and we can re-call the function when interface is up */
pAd->Cfg80211_Alpha2[0] = pRegInfo->Alpha2[0];
pAd->Cfg80211_Alpha2[1] = pRegInfo->Alpha2[1];
/* apply the new regulatory rule */
if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP))
{
/* interface is up */
CFG80211_RegRuleApply(pAd, pRegInfo->pWiphy, (UCHAR *)pRegInfo->Alpha2);
}
else
{
CFG80211DBG(RT_DEBUG_ERROR, ("crda> interface is down!\n"));
} /* End of if */
}
VOID CFG80211DRV_SurveyGet(
VOID *pAdOrg,
VOID *pData)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
CMD_RTPRIV_IOCTL_80211_SURVEY *pSurveyInfo;
pSurveyInfo = (CMD_RTPRIV_IOCTL_80211_SURVEY *)pData;
pSurveyInfo->pCfg80211 = pAd->pCfg80211_CB;
#ifdef AP_QLOAD_SUPPORT
pSurveyInfo->ChannelTimeBusy = pAd->QloadLatestChannelBusyTimePri;
pSurveyInfo->ChannelTimeExtBusy = pAd->QloadLatestChannelBusyTimeSec;
#endif /* AP_QLOAD_SUPPORT */
}
VOID CFG80211_UnRegister(
IN VOID *pAdOrg,
IN VOID *pNetDev)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
/* sanity check */
if (pAd->pCfg80211_CB == NULL)
return;
/* End of if */
CFG80211OS_UnRegister(pAd->pCfg80211_CB, pNetDev);
pAd->pCfg80211_CB = NULL;
pAd->CommonCfg.HT_Disable = 0;
}
/*
========================================================================
Routine Description:
Parse and handle country region in beacon from associated AP.
Arguments:
pAdCB - WLAN control block pointer
pVIE - Beacon elements
LenVIE - Total length of Beacon elements
Return Value:
NONE
Note:
========================================================================
*/
VOID CFG80211_BeaconCountryRegionParse(
IN VOID *pAdCB,
IN NDIS_802_11_VARIABLE_IEs *pVIE,
IN UINT16 LenVIE)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdCB;
UCHAR *pElement = (UCHAR *)pVIE;
UINT32 LenEmt;
while(LenVIE > 0)
{
pVIE = (NDIS_802_11_VARIABLE_IEs *)pElement;
if (pVIE->ElementID == IE_COUNTRY)
{
/* send command to do regulation hint only when associated */
RTEnqueueInternalCmd(pAd, CMDTHREAD_REG_HINT_11D,
pVIE->data, pVIE->Length);
break;
} /* End of if */
LenEmt = pVIE->Length + 2;
if (LenVIE <= LenEmt)
break; /* length is not enough */
/* End of if */
pElement += LenEmt;
LenVIE -= LenEmt;
} /* End of while */
} /* End of CFG80211_BeaconCountryRegionParse */
/*
========================================================================
Routine Description:
Hint to the wireless core a regulatory domain from driver.
Arguments:
pAd - WLAN control block pointer
pCountryIe - pointer to the country IE
CountryIeLen - length of the country IE
Return Value:
NONE
Note:
Must call the function in kernel thread.
========================================================================
*/
VOID CFG80211_RegHint(
IN VOID *pAdCB,
IN UCHAR *pCountryIe,
IN ULONG CountryIeLen)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdCB;
CFG80211OS_RegHint(CFG80211CB, pCountryIe, CountryIeLen);
} /* End of CFG80211_RegHint */
/*
========================================================================
Routine Description:
Hint to the wireless core a regulatory domain from country element.
Arguments:
pAdCB - WLAN control block pointer
pCountryIe - pointer to the country IE
CountryIeLen - length of the country IE
Return Value:
NONE
Note:
Must call the function in kernel thread.
========================================================================
*/
VOID CFG80211_RegHint11D(
IN VOID *pAdCB,
IN UCHAR *pCountryIe,
IN ULONG CountryIeLen)
{
/* no regulatory_hint_11d() in 2.6.32 */
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdCB;
CFG80211OS_RegHint11D(CFG80211CB, pCountryIe, CountryIeLen);
} /* End of CFG80211_RegHint11D */
/*
========================================================================
Routine Description:
Apply new regulatory rule.
Arguments:
pAdCB - WLAN control block pointer
pWiphy - Wireless hardware description
pAlpha2 - Regulation domain (2B)
Return Value:
NONE
Note:
Can only be called when interface is up.
For general mac80211 device, it will be set to new power by Ops->config()
In rt2x00/, the settings is done in rt2x00lib_config().
========================================================================
*/
VOID CFG80211_RegRuleApply(
IN VOID *pAdCB,
IN VOID *pWiphy,
IN UCHAR *pAlpha2)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdCB;
VOID *pBand24G, *pBand5G;
UINT32 IdBand, IdChan, IdPwr;
UINT32 ChanNum, ChanId, Power, RecId, DfsType;
BOOLEAN FlgIsRadar;
ULONG IrqFlags;
#ifdef DFS_SUPPORT
RADAR_DETECT_STRUCT *pRadarDetect;
#endif /* DFS_SUPPORT */
CFG80211DBG(RT_DEBUG_ERROR, ("crda> CFG80211_RegRuleApply ==>\n"));
/* init */
pBand24G = NULL;
pBand5G = NULL;
if (pAd == NULL)
return;
RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags);
/* zero first */
NdisZeroMemory(pAd->ChannelList,
MAX_NUM_OF_CHANNELS * sizeof(CHANNEL_TX_POWER));
/* 2.4GHZ & 5GHz */
RecId = 0;
#ifdef DFS_SUPPORT
pRadarDetect = &pAd->CommonCfg.RadarDetect;
#endif /* DFS_SUPPORT */
/* find the DfsType */
DfsType = CE;
pBand24G = NULL;
pBand5G = NULL;
if (CFG80211OS_BandInfoGet(CFG80211CB, pWiphy, &pBand24G, &pBand5G) == FALSE)
return;
#ifdef AUTO_CH_SELECT_ENHANCE
#ifdef EXT_BUILD_CHANNEL_LIST
if ((pAlpha2[0] != '0') && (pAlpha2[1] != '0'))
{
UINT32 IdReg;
if (pBand5G != NULL)
{
for(IdReg=0; ; IdReg++)
{
if (ChRegion[IdReg].CountReg[0] == 0x00)
break;
/* End of if */
if ((pAlpha2[0] == ChRegion[IdReg].CountReg[0]) &&
(pAlpha2[1] == ChRegion[IdReg].CountReg[1]))
{
if (pAd->CommonCfg.DfsType != MAX_RD_REGION)
DfsType = pAd->CommonCfg.DfsType;
else
DfsType = ChRegion[IdReg].DfsType;
CFG80211DBG(RT_DEBUG_ERROR,
("crda> find region %c%c, DFS Type %d\n",
pAlpha2[0], pAlpha2[1], DfsType));
break;
} /* End of if */
} /* End of for */
} /* End of if */
} /* End of if */
#endif /* EXT_BUILD_CHANNEL_LIST */
#endif /* AUTO_CH_SELECT_ENHANCE */
for(IdBand=0; IdBand<2; IdBand++)
{
if (((IdBand == 0) && (pBand24G == NULL)) ||
((IdBand == 1) && (pBand5G == NULL)))
{
continue;
} /* End of if */
if (IdBand == 0)
{
CFG80211DBG(RT_DEBUG_ERROR, ("crda> reset chan/power for 2.4GHz\n"));
}
else
{
CFG80211DBG(RT_DEBUG_ERROR, ("crda> reset chan/power for 5GHz\n"));
} /* End of if */
ChanNum = CFG80211OS_ChanNumGet(CFG80211CB, pWiphy, IdBand);
for(IdChan=0; IdChan<ChanNum; IdChan++)
{
if (CFG80211OS_ChanInfoGet(CFG80211CB, pWiphy, IdBand, IdChan,
&ChanId, &Power, &FlgIsRadar) == FALSE)
{
/* the channel is not allowed in the regulatory domain */
/* get next channel information */
continue;
}
if (!WMODE_CAP_2G(pAd->CommonCfg.PhyMode))
{
/* 5G-only mode */
if (ChanId <= CFG80211_NUM_OF_CHAN_2GHZ)
continue;
}
if (!WMODE_CAP_5G(pAd->CommonCfg.PhyMode))
{
/* 2.4G-only mode */
if (ChanId > CFG80211_NUM_OF_CHAN_2GHZ)
continue;
}
for(IdPwr=0; IdPwr<MAX_NUM_OF_CHANNELS; IdPwr++)
{
if (ChanId == pAd->TxPower[IdPwr].Channel)
{
/* init the channel info. */
NdisMoveMemory(&pAd->ChannelList[RecId],
&pAd->TxPower[IdPwr],
sizeof(CHANNEL_TX_POWER));
/* keep channel number */
pAd->ChannelList[RecId].Channel = ChanId;
/* keep maximum tranmission power */
pAd->ChannelList[RecId].MaxTxPwr = Power;
/* keep DFS flag */
if (FlgIsRadar == TRUE)
pAd->ChannelList[RecId].DfsReq = TRUE;
else
pAd->ChannelList[RecId].DfsReq = FALSE;
/* End of if */
/* keep DFS type */
pAd->ChannelList[RecId].RegulatoryDomain = DfsType;
/* re-set DFS info. */
pAd->CommonCfg.RDDurRegion = DfsType;
CFG80211DBG(RT_DEBUG_ERROR,
("Chan %03d:\tpower %d dBm, "
"DFS %d, DFS Type %d\n",
ChanId, Power,
((FlgIsRadar == TRUE)?1:0),
DfsType));
/* change to record next channel info. */
RecId ++;