forked from ivanovborislav/rtl8812au
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtw_mlme.c
5984 lines (4874 loc) · 176 KB
/
rtw_mlme.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 - 2019 Realtek Corporation.
*
* 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.
*
*****************************************************************************/
#define _RTW_MLME_C_
#include <hal_data.h>
#ifdef CONFIG_PLATFORM_CMAP_INTFS
#include "../os_dep/linux/custom_multiap_intfs/custom_multiap_intfs.h"
#endif
extern void indicate_wx_scan_complete_event(_adapter *padapter);
extern u8 rtw_do_join(_adapter *padapter);
void rtw_init_mlme_timer(_adapter *padapter)
{
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
rtw_init_timer(&(pmlmepriv->assoc_timer), padapter, rtw_join_timeout_handler, padapter);
rtw_init_timer(&(pmlmepriv->scan_to_timer), padapter, rtw_scan_timeout_handler, padapter);
#ifdef CONFIG_SET_SCAN_DENY_TIMER
rtw_init_timer(&(pmlmepriv->set_scan_deny_timer), padapter, rtw_set_scan_deny_timer_hdl, padapter);
#endif
#ifdef RTK_DMP_PLATFORM
_init_workitem(&(pmlmepriv->Linkup_workitem), Linkup_workitem_callback, padapter);
_init_workitem(&(pmlmepriv->Linkdown_workitem), Linkdown_workitem_callback, padapter);
#endif
}
sint _rtw_init_mlme_priv(_adapter *padapter)
{
sint i;
u8 *pbuf;
struct wlan_network *pnetwork;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
sint res = _SUCCESS;
#ifdef CONFIG_RTW_MULTI_AP
struct unassoc_sta_info *unassoc_sta;
#endif
/* We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc(). */
/* _rtw_memset((u8 *)pmlmepriv, 0, sizeof(struct mlme_priv)); */
/*qos_priv*/
/*pmlmepriv->qospriv.qos_option = pregistrypriv->wmm_enable;*/
/*ht_priv*/
#ifdef CONFIG_80211N_HT
pmlmepriv->htpriv.ampdu_enable = _FALSE;/*set to disabled*/
#endif
pmlmepriv->nic_hdl = (u8 *)padapter;
pmlmepriv->pscanned = NULL;
init_fwstate(pmlmepriv, WIFI_STATION_STATE);
pmlmepriv->cur_network.network.InfrastructureMode = Ndis802_11AutoUnknown;
pmlmepriv->scan_mode = SCAN_ACTIVE; /* 1: active, 0: pasive. Maybe someday we should rename this varable to "active_mode" (Jeff) */
_rtw_spinlock_init(&(pmlmepriv->lock));
_rtw_init_queue(&(pmlmepriv->free_bss_pool));
_rtw_init_queue(&(pmlmepriv->scanned_queue));
set_scanned_network_val(pmlmepriv, 0);
_rtw_memset(&pmlmepriv->assoc_ssid, 0, sizeof(NDIS_802_11_SSID));
if (padapter->registrypriv.max_bss_cnt != 0)
pmlmepriv->max_bss_cnt = padapter->registrypriv.max_bss_cnt;
else if (rfctl->max_chan_nums <= MAX_CHANNEL_NUM_2G)
pmlmepriv->max_bss_cnt = MAX_BSS_CNT;
else
pmlmepriv->max_bss_cnt = MAX_BSS_CNT + MAX_BSS_CNT;
pbuf = rtw_zvmalloc(pmlmepriv->max_bss_cnt * (sizeof(struct wlan_network)));
if (pbuf == NULL) {
res = _FAIL;
goto exit;
}
pmlmepriv->free_bss_buf = pbuf;
pnetwork = (struct wlan_network *)pbuf;
for (i = 0; i < pmlmepriv->max_bss_cnt; i++) {
_rtw_init_listhead(&(pnetwork->list));
rtw_list_insert_tail(&(pnetwork->list), &(pmlmepriv->free_bss_pool.queue));
pnetwork++;
}
#ifdef CONFIG_RTW_MULTI_AP
if (is_primary_adapter(padapter)) {
_rtw_init_queue(&(pmlmepriv->free_unassoc_sta_queue));
_rtw_init_queue(&(pmlmepriv->unassoc_sta_queue));
for (i = 0; i < UNASOC_STA_SRC_NUM; i++)
pmlmepriv->unassoc_sta_mode_of_stype[i] = padapter->registrypriv.unassoc_sta_mode_of_stype[i];
if (padapter->registrypriv.max_unassoc_sta_cnt != 0)
pmlmepriv->max_unassoc_sta_cnt = padapter->registrypriv.max_unassoc_sta_cnt;
else if (rfctl->max_chan_nums <= MAX_CHANNEL_NUM_2G)
pmlmepriv->max_unassoc_sta_cnt = MAX_UNASSOC_STA_CNT;
else
pmlmepriv->max_unassoc_sta_cnt = MAX_UNASSOC_STA_CNT * 2;
pbuf = rtw_zvmalloc(pmlmepriv->max_unassoc_sta_cnt * (sizeof(struct unassoc_sta_info)));
if (pbuf == NULL) {
res = _FAIL;
goto exit;
}
pmlmepriv->free_unassoc_sta_buf = pbuf;
unassoc_sta = (struct unassoc_sta_info *) pbuf;
for (i = 0; i < pmlmepriv->max_unassoc_sta_cnt; i++) {
_rtw_init_listhead(&(unassoc_sta->list));
rtw_list_insert_tail(&(unassoc_sta->list), &(pmlmepriv->free_unassoc_sta_queue.queue));
unassoc_sta++;
}
}
#ifdef CONFIG_PLATFORM_CMAP_INTFS
rtw_init_timer(&pmlmepriv->cmap_unassoc_sta_timer, padapter, cmap_unassoc_sta_report_info_timer, padapter);
#endif
#endif
/* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
rtw_clear_scan_deny(padapter);
#ifdef CONFIG_ARP_KEEP_ALIVE
pmlmepriv->bGetGateway = 0;
pmlmepriv->GetGatewayTryCnt = 0;
#endif
#ifdef CONFIG_LAYER2_ROAMING
#define RTW_ROAM_SCAN_RESULT_EXP_MS (5*1000)
#define RTW_ROAM_RSSI_DIFF_TH 10
#define RTW_ROAM_SCAN_INTERVAL (5) /* 5*(2 second)*/
#define RTW_ROAM_RSSI_THRESHOLD 70
#define RTW_ROAM_DICONNECT_DELAY 20
_rtw_spinlock_init(&pmlmepriv->clnt_auth_lock);
pmlmepriv->roam_flags = CONFIG_ROAMING_FLAG;
pmlmepriv->roam_scanr_exp_ms = RTW_ROAM_SCAN_RESULT_EXP_MS;
pmlmepriv->roam_rssi_diff_th = RTW_ROAM_RSSI_DIFF_TH;
pmlmepriv->roam_scan_int = RTW_ROAM_SCAN_INTERVAL;
pmlmepriv->roam_rssi_threshold = RTW_ROAM_RSSI_THRESHOLD;
pmlmepriv->need_to_roam = _FALSE;
pmlmepriv->last_roaming = rtw_get_current_time();
#endif /* CONFIG_LAYER2_ROAMING */
#ifdef CONFIG_RTW_80211R
rtw_ft_info_init(&pmlmepriv->ft_roam);
#endif
#ifdef CONFIG_LAYER2_ROAMING
#if defined(CONFIG_RTW_WNM) || defined(CONFIG_RTW_80211K)
rtw_roam_nb_info_init(padapter);
pmlmepriv->ch_cnt = 0;
#endif
#endif
pmlmepriv->defs_lmt_sta = 2;
pmlmepriv->defs_lmt_time = 5;
rtw_init_mlme_timer(padapter);
exit:
return res;
}
void rtw_mfree_mlme_priv_lock(struct mlme_priv *pmlmepriv);
void rtw_mfree_mlme_priv_lock(struct mlme_priv *pmlmepriv)
{
_rtw_spinlock_free(&pmlmepriv->lock);
#ifdef CONFIG_LAYER2_ROAMING
_rtw_spinlock_free(&pmlmepriv->clnt_auth_lock);
#endif
_rtw_spinlock_free(&(pmlmepriv->free_bss_pool.lock));
_rtw_spinlock_free(&(pmlmepriv->scanned_queue.lock));
#ifdef CONFIG_RTW_MULTI_AP
if (is_primary_adapter(mlme_to_adapter(pmlmepriv))) {
_rtw_spinlock_free(&(pmlmepriv->unassoc_sta_queue.lock));
_rtw_spinlock_free(&(pmlmepriv->free_unassoc_sta_queue.lock));
}
#endif
}
void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv)
{
rtw_buf_free(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len);
rtw_buf_free(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len);
#if defined(CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
rtw_buf_free(&pmlmepriv->wps_beacon_ie, &pmlmepriv->wps_beacon_ie_len);
rtw_buf_free(&pmlmepriv->wps_probe_req_ie, &pmlmepriv->wps_probe_req_ie_len);
rtw_buf_free(&pmlmepriv->wps_probe_resp_ie, &pmlmepriv->wps_probe_resp_ie_len);
rtw_buf_free(&pmlmepriv->wps_assoc_resp_ie, &pmlmepriv->wps_assoc_resp_ie_len);
rtw_buf_free(&pmlmepriv->p2p_beacon_ie, &pmlmepriv->p2p_beacon_ie_len);
rtw_buf_free(&pmlmepriv->p2p_probe_req_ie, &pmlmepriv->p2p_probe_req_ie_len);
rtw_buf_free(&pmlmepriv->p2p_probe_resp_ie, &pmlmepriv->p2p_probe_resp_ie_len);
rtw_buf_free(&pmlmepriv->p2p_go_probe_resp_ie, &pmlmepriv->p2p_go_probe_resp_ie_len);
rtw_buf_free(&pmlmepriv->p2p_assoc_req_ie, &pmlmepriv->p2p_assoc_req_ie_len);
rtw_buf_free(&pmlmepriv->p2p_assoc_resp_ie, &pmlmepriv->p2p_assoc_resp_ie_len);
#endif
#if defined(CONFIG_WFD) && defined(CONFIG_IOCTL_CFG80211)
rtw_buf_free(&pmlmepriv->wfd_beacon_ie, &pmlmepriv->wfd_beacon_ie_len);
rtw_buf_free(&pmlmepriv->wfd_probe_req_ie, &pmlmepriv->wfd_probe_req_ie_len);
rtw_buf_free(&pmlmepriv->wfd_probe_resp_ie, &pmlmepriv->wfd_probe_resp_ie_len);
rtw_buf_free(&pmlmepriv->wfd_go_probe_resp_ie, &pmlmepriv->wfd_go_probe_resp_ie_len);
rtw_buf_free(&pmlmepriv->wfd_assoc_req_ie, &pmlmepriv->wfd_assoc_req_ie_len);
rtw_buf_free(&pmlmepriv->wfd_assoc_resp_ie, &pmlmepriv->wfd_assoc_resp_ie_len);
#endif
#ifdef CONFIG_RTW_80211R
rtw_buf_free(&pmlmepriv->auth_rsp, &pmlmepriv->auth_rsp_len);
#endif
#ifdef CONFIG_RTW_MBO
rtw_buf_free(&pmlmepriv->pcell_data_cap_ie, &pmlmepriv->cell_data_cap_len);
#endif
}
#if defined(CONFIG_WFD) && defined(CONFIG_IOCTL_CFG80211)
int rtw_mlme_update_wfd_ie_data(struct mlme_priv *mlme, u8 type, u8 *ie, u32 ie_len)
{
_adapter *adapter = mlme_to_adapter(mlme);
struct wifi_display_info *wfd_info = &adapter->wfd_info;
u8 clear = 0;
u8 **t_ie = NULL;
u32 *t_ie_len = NULL;
int ret = _FAIL;
if (!hal_chk_wl_func(adapter, WL_FUNC_MIRACAST))
goto success;
if (wfd_info->wfd_enable == _TRUE)
goto success; /* WFD IE is build by self */
if (!ie && !ie_len)
clear = 1;
else if (!ie || !ie_len) {
RTW_PRINT(FUNC_ADPT_FMT" type:%u, ie:%p, ie_len:%u"
, FUNC_ADPT_ARG(adapter), type, ie, ie_len);
rtw_warn_on(1);
goto exit;
}
switch (type) {
case MLME_BEACON_IE:
t_ie = &mlme->wfd_beacon_ie;
t_ie_len = &mlme->wfd_beacon_ie_len;
break;
case MLME_PROBE_REQ_IE:
t_ie = &mlme->wfd_probe_req_ie;
t_ie_len = &mlme->wfd_probe_req_ie_len;
break;
case MLME_PROBE_RESP_IE:
t_ie = &mlme->wfd_probe_resp_ie;
t_ie_len = &mlme->wfd_probe_resp_ie_len;
break;
case MLME_GO_PROBE_RESP_IE:
t_ie = &mlme->wfd_go_probe_resp_ie;
t_ie_len = &mlme->wfd_go_probe_resp_ie_len;
break;
case MLME_ASSOC_REQ_IE:
t_ie = &mlme->wfd_assoc_req_ie;
t_ie_len = &mlme->wfd_assoc_req_ie_len;
break;
case MLME_ASSOC_RESP_IE:
t_ie = &mlme->wfd_assoc_resp_ie;
t_ie_len = &mlme->wfd_assoc_resp_ie_len;
break;
default:
RTW_PRINT(FUNC_ADPT_FMT" unsupported type:%u"
, FUNC_ADPT_ARG(adapter), type);
rtw_warn_on(1);
goto exit;
}
if (*t_ie) {
u32 free_len = *t_ie_len;
*t_ie_len = 0;
rtw_mfree(*t_ie, free_len);
*t_ie = NULL;
}
if (!clear) {
*t_ie = rtw_malloc(ie_len);
if (*t_ie == NULL) {
RTW_ERR(FUNC_ADPT_FMT" type:%u, rtw_malloc() fail\n"
, FUNC_ADPT_ARG(adapter), type);
goto exit;
}
_rtw_memcpy(*t_ie, ie, ie_len);
*t_ie_len = ie_len;
}
if (*t_ie && *t_ie_len) {
u8 *attr_content;
u32 attr_contentlen = 0;
attr_content = rtw_get_wfd_attr_content(*t_ie, *t_ie_len, WFD_ATTR_DEVICE_INFO, NULL, &attr_contentlen);
if (attr_content && attr_contentlen) {
if (RTW_GET_BE16(attr_content + 2) != wfd_info->rtsp_ctrlport) {
wfd_info->rtsp_ctrlport = RTW_GET_BE16(attr_content + 2);
RTW_INFO(FUNC_ADPT_FMT" type:%u, RTSP CTRL port = %u\n"
, FUNC_ADPT_ARG(adapter), type, wfd_info->rtsp_ctrlport);
}
}
}
success:
ret = _SUCCESS;
exit:
return ret;
}
#endif /* defined(CONFIG_WFD) && defined(CONFIG_IOCTL_CFG80211) */
void _rtw_free_mlme_priv(struct mlme_priv *pmlmepriv)
{
_adapter *adapter = mlme_to_adapter(pmlmepriv);
if (NULL == pmlmepriv) {
rtw_warn_on(1);
goto exit;
}
rtw_free_mlme_priv_ie_data(pmlmepriv);
if (pmlmepriv) {
rtw_mfree_mlme_priv_lock(pmlmepriv);
if (pmlmepriv->free_bss_buf)
rtw_vmfree(pmlmepriv->free_bss_buf, pmlmepriv->max_bss_cnt * sizeof(struct wlan_network));
#ifdef CONFIG_RTW_MULTI_AP
if (is_primary_adapter(adapter)) {
if (pmlmepriv->free_unassoc_sta_buf)
rtw_vmfree(pmlmepriv->free_unassoc_sta_buf, pmlmepriv->max_unassoc_sta_cnt * sizeof(struct unassoc_sta_info));
}
#ifdef CONFIG_PLATFORM_CMAP_INTFS
_cancel_timer_ex(&pmlmepriv->cmap_unassoc_sta_timer);
#endif
#endif
}
exit:
return;
}
sint _rtw_enqueue_network(_queue *queue, struct wlan_network *pnetwork)
{
_irqL irqL;
if (pnetwork == NULL)
goto exit;
_enter_critical_bh(&queue->lock, &irqL);
rtw_list_insert_tail(&pnetwork->list, &queue->queue);
_exit_critical_bh(&queue->lock, &irqL);
exit:
return _SUCCESS;
}
/*
struct wlan_network *_rtw_dequeue_network(_queue *queue)
{
_irqL irqL;
struct wlan_network *pnetwork;
_enter_critical_bh(&queue->lock, &irqL);
if (_rtw_queue_empty(queue) == _TRUE)
pnetwork = NULL;
else
{
pnetwork = LIST_CONTAINOR(get_next(&queue->queue), struct wlan_network, list);
rtw_list_delete(&(pnetwork->list));
}
_exit_critical_bh(&queue->lock, &irqL);
return pnetwork;
}
*/
struct wlan_network *_rtw_alloc_network(struct mlme_priv *pmlmepriv) /* (_queue *free_queue) */
{
_irqL irqL;
struct wlan_network *pnetwork;
_queue *free_queue = &pmlmepriv->free_bss_pool;
_list *plist = NULL;
_enter_critical_bh(&free_queue->lock, &irqL);
if (_rtw_queue_empty(free_queue) == _TRUE) {
pnetwork = NULL;
goto exit;
}
plist = get_next(&(free_queue->queue));
pnetwork = LIST_CONTAINOR(plist , struct wlan_network, list);
rtw_list_delete(&pnetwork->list);
pnetwork->network_type = 0;
pnetwork->fixed = _FALSE;
pnetwork->last_scanned = rtw_get_current_time();
pnetwork->last_non_hidden_ssid_ap = pnetwork->last_scanned;
#if defined(CONFIG_RTW_MESH) && CONFIG_RTW_MESH_ACNODE_PREVENT
pnetwork->acnode_stime = 0;
pnetwork->acnode_notify_etime = 0;
#endif
pnetwork->aid = 0;
pnetwork->join_res = 0;
pmlmepriv->num_of_scanned++;
exit:
_exit_critical_bh(&free_queue->lock, &irqL);
return pnetwork;
}
void _rtw_free_network(struct mlme_priv *pmlmepriv , struct wlan_network *pnetwork, u8 isfreeall)
{
u32 delta_time;
u32 lifetime = SCANQUEUE_LIFETIME;
_irqL irqL;
_queue *free_queue = &(pmlmepriv->free_bss_pool);
if (pnetwork == NULL)
goto exit;
if (pnetwork->fixed == _TRUE)
goto exit;
if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) ||
(check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE))
lifetime = 1;
if (!isfreeall) {
delta_time = (u32) rtw_get_passing_time_ms(pnetwork->last_scanned);
if (delta_time < lifetime) /* unit:msec */
goto exit;
}
_enter_critical_bh(&free_queue->lock, &irqL);
rtw_list_delete(&(pnetwork->list));
rtw_list_insert_tail(&(pnetwork->list), &(free_queue->queue));
pmlmepriv->num_of_scanned--;
/* RTW_INFO("_rtw_free_network:SSID=%s\n", pnetwork->network.Ssid.Ssid); */
_exit_critical_bh(&free_queue->lock, &irqL);
exit:
return;
}
void _rtw_free_network_nolock(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork)
{
_queue *free_queue = &(pmlmepriv->free_bss_pool);
if (pnetwork == NULL)
goto exit;
if (pnetwork->fixed == _TRUE)
goto exit;
/* _enter_critical(&free_queue->lock, &irqL); */
rtw_list_delete(&(pnetwork->list));
rtw_list_insert_tail(&(pnetwork->list), get_list_head(free_queue));
pmlmepriv->num_of_scanned--;
/* _exit_critical(&free_queue->lock, &irqL); */
exit:
return;
}
void _rtw_free_network_queue(_adapter *padapter, u8 isfreeall)
{
_irqL irqL;
_list *phead, *plist;
struct wlan_network *pnetwork;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
_queue *scanned_queue = &pmlmepriv->scanned_queue;
_enter_critical_bh(&scanned_queue->lock, &irqL);
phead = get_list_head(scanned_queue);
plist = get_next(phead);
while (rtw_end_of_queue_search(phead, plist) == _FALSE) {
pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
plist = get_next(plist);
_rtw_free_network(pmlmepriv, pnetwork, isfreeall);
}
_exit_critical_bh(&scanned_queue->lock, &irqL);
}
sint rtw_if_up(_adapter *padapter)
{
sint res;
if (RTW_CANNOT_RUN(padapter) ||
(check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == _FALSE)) {
res = _FALSE;
} else
res = _TRUE;
return res;
}
void rtw_generate_random_ibss(u8 *pibss)
{
*((u32 *)(&pibss[2])) = rtw_random32();
pibss[0] = 0x02; /* in ad-hoc mode local bit must set to 1 */
pibss[1] = 0x11;
pibss[2] = 0x87;
}
u8 *rtw_get_capability_from_ie(u8 *ie)
{
return ie + 8 + 2;
}
u16 rtw_get_capability(WLAN_BSSID_EX *bss)
{
u16 val;
_rtw_memcpy((u8 *)&val, rtw_get_capability_from_ie(bss->IEs), 2);
return le16_to_cpu(val);
}
u8 *rtw_get_timestampe_from_ie(u8 *ie)
{
return ie + 0;
}
u8 *rtw_get_beacon_interval_from_ie(u8 *ie)
{
return ie + 8;
}
int rtw_init_mlme_priv(_adapter *padapter) /* (struct mlme_priv *pmlmepriv) */
{
int res;
res = _rtw_init_mlme_priv(padapter);/* (pmlmepriv); */
return res;
}
void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv)
{
_rtw_free_mlme_priv(pmlmepriv);
}
int rtw_enqueue_network(_queue *queue, struct wlan_network *pnetwork);
int rtw_enqueue_network(_queue *queue, struct wlan_network *pnetwork)
{
int res;
res = _rtw_enqueue_network(queue, pnetwork);
return res;
}
/*
static struct wlan_network *rtw_dequeue_network(_queue *queue)
{
struct wlan_network *pnetwork;
pnetwork = _rtw_dequeue_network(queue);
return pnetwork;
}
*/
struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv);
struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv) /* (_queue *free_queue) */
{
struct wlan_network *pnetwork;
pnetwork = _rtw_alloc_network(pmlmepriv);
return pnetwork;
}
void rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 is_freeall);
void rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 is_freeall)/* (struct wlan_network *pnetwork, _queue *free_queue) */
{
_rtw_free_network(pmlmepriv, pnetwork, is_freeall);
}
void rtw_free_network_nolock(_adapter *padapter, struct wlan_network *pnetwork);
void rtw_free_network_nolock(_adapter *padapter, struct wlan_network *pnetwork)
{
_rtw_free_network_nolock(&(padapter->mlmepriv), pnetwork);
#ifdef CONFIG_IOCTL_CFG80211
rtw_cfg80211_unlink_bss(padapter, pnetwork);
#endif /* CONFIG_IOCTL_CFG80211 */
}
void rtw_free_network_queue(_adapter *dev, u8 isfreeall)
{
_rtw_free_network_queue(dev, isfreeall);
}
struct wlan_network *_rtw_find_network(_queue *scanned_queue, const u8 *addr)
{
_list *phead, *plist;
struct wlan_network *pnetwork = NULL;
u8 zero_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
if (_rtw_memcmp(zero_addr, addr, ETH_ALEN)) {
pnetwork = NULL;
goto exit;
}
phead = get_list_head(scanned_queue);
plist = get_next(phead);
while (plist != phead) {
pnetwork = LIST_CONTAINOR(plist, struct wlan_network , list);
if (_rtw_memcmp(addr, pnetwork->network.MacAddress, ETH_ALEN) == _TRUE)
break;
plist = get_next(plist);
}
if (plist == phead)
pnetwork = NULL;
exit:
return pnetwork;
}
struct wlan_network *rtw_find_network(_queue *scanned_queue, const u8 *addr)
{
struct wlan_network *pnetwork;
_irqL irqL;
_enter_critical_bh(&scanned_queue->lock, &irqL);
pnetwork = _rtw_find_network(scanned_queue, addr);
_exit_critical_bh(&scanned_queue->lock, &irqL);
return pnetwork;
}
int rtw_is_same_ibss(_adapter *adapter, struct wlan_network *pnetwork)
{
int ret = _TRUE;
struct security_priv *psecuritypriv = &adapter->securitypriv;
if ((psecuritypriv->dot11PrivacyAlgrthm != _NO_PRIVACY_) &&
(pnetwork->network.Privacy == 0))
ret = _FALSE;
else if ((psecuritypriv->dot11PrivacyAlgrthm == _NO_PRIVACY_) &&
(pnetwork->network.Privacy == 1))
ret = _FALSE;
else
ret = _TRUE;
return ret;
}
inline int is_same_ess(WLAN_BSSID_EX *a, WLAN_BSSID_EX *b)
{
return (a->Ssid.SsidLength == b->Ssid.SsidLength)
&& _rtw_memcmp(a->Ssid.Ssid, b->Ssid.Ssid, a->Ssid.SsidLength) == _TRUE;
}
int is_same_network(WLAN_BSSID_EX *src, WLAN_BSSID_EX *dst, u8 feature)
{
u16 s_cap, d_cap;
if (rtw_bug_check(dst, src, &s_cap, &d_cap) == _FALSE)
return _FALSE;
_rtw_memcpy((u8 *)&s_cap, rtw_get_capability_from_ie(src->IEs), 2);
_rtw_memcpy((u8 *)&d_cap, rtw_get_capability_from_ie(dst->IEs), 2);
s_cap = le16_to_cpu(s_cap);
d_cap = le16_to_cpu(d_cap);
#ifdef CONFIG_P2P
if ((feature == 1) && /* 1: P2P supported */
(_rtw_memcmp(src->MacAddress, dst->MacAddress, ETH_ALEN) == _TRUE)
)
return _TRUE;
#endif
/* Wi-Fi driver doesn't consider the situation of BCN and ProbRsp sent from the same hidden AP,
* it considers these two packets are sent from different AP.
* Therefore, the scan queue may store two scan results of the same hidden AP, likes below.
*
* index bssid ch RSSI SdBm Noise age flag ssid
* 1 00:e0:4c:55:50:01 153 -73 -73 0 7044 [WPS][ESS] RTK5G
* 3 00:e0:4c:55:50:01 153 -73 -73 0 7044 [WPS][ESS]
*
* Original rules will compare Ssid, SsidLength, MacAddress, s_cap, d_cap at the same time.
* Wi-Fi driver will assume that the BCN and ProbRsp sent from the same hidden AP are the same network
* after we add an additional rule to compare SsidLength and Ssid.
* It means the scan queue will not store two scan results of the same hidden AP, it only store ProbRsp.
* For customer request.
*/
if (((_rtw_memcmp(src->MacAddress, dst->MacAddress, ETH_ALEN)) == _TRUE) &&
((s_cap & WLAN_CAPABILITY_IBSS) == (d_cap & WLAN_CAPABILITY_IBSS)) &&
((s_cap & WLAN_CAPABILITY_BSS) == (d_cap & WLAN_CAPABILITY_BSS))) {
if ((src->Ssid.SsidLength == dst->Ssid.SsidLength) &&
(((_rtw_memcmp(src->Ssid.Ssid, dst->Ssid.Ssid, src->Ssid.SsidLength)) == _TRUE) || //Case of normal AP
(is_all_null(src->Ssid.Ssid, src->Ssid.SsidLength) == _TRUE || is_all_null(dst->Ssid.Ssid, dst->Ssid.SsidLength) == _TRUE))) //Case of hidden AP
return _TRUE;
else if ((src->Ssid.SsidLength == 0 || dst->Ssid.SsidLength == 0)) //Case of hidden AP
return _TRUE;
else
return _FALSE;
} else {
return _FALSE;
}
}
struct wlan_network *_rtw_find_same_network(_queue *scanned_queue, struct wlan_network *network)
{
_list *phead, *plist;
struct wlan_network *found = NULL;
phead = get_list_head(scanned_queue);
plist = get_next(phead);
while (plist != phead) {
found = LIST_CONTAINOR(plist, struct wlan_network , list);
if (is_same_network(&network->network, &found->network, 0))
break;
plist = get_next(plist);
}
if (plist == phead)
found = NULL;
return found;
}
struct wlan_network *rtw_find_same_network(_queue *scanned_queue, struct wlan_network *network)
{
_irqL irqL;
struct wlan_network *found = NULL;
if (scanned_queue == NULL || network == NULL)
goto exit;
_enter_critical_bh(&scanned_queue->lock, &irqL);
found = _rtw_find_same_network(scanned_queue, network);
_exit_critical_bh(&scanned_queue->lock, &irqL);
exit:
return found;
}
struct wlan_network *rtw_get_oldest_wlan_network(_queue *scanned_queue)
{
_list *plist, *phead;
struct wlan_network *pwlan = NULL;
struct wlan_network *oldest = NULL;
phead = get_list_head(scanned_queue);
plist = get_next(phead);
while (1) {
if (rtw_end_of_queue_search(phead, plist) == _TRUE)
break;
pwlan = LIST_CONTAINOR(plist, struct wlan_network, list);
if (pwlan->fixed != _TRUE) {
if (oldest == NULL || rtw_time_after(oldest->last_scanned, pwlan->last_scanned))
oldest = pwlan;
}
plist = get_next(plist);
}
return oldest;
}
void update_network(WLAN_BSSID_EX *dst, WLAN_BSSID_EX *src,
_adapter *padapter, bool update_ie)
{
#if defined(DBG_RX_SIGNAL_DISPLAY_SSID_MONITORED) && 1
u8 ss_ori = dst->PhyInfo.SignalStrength;
u8 sq_ori = dst->PhyInfo.SignalQuality;
u8 ss_smp = src->PhyInfo.SignalStrength;
long rssi_smp = src->Rssi;
#endif
long rssi_ori = dst->Rssi;
u8 sq_smp = src->PhyInfo.SignalQuality;
u8 ss_final;
u8 sq_final;
long rssi_final;
#ifdef CONFIG_ANTENNA_DIVERSITY
rtw_hal_antdiv_rssi_compared(padapter, dst, src); /* this will update src.Rssi, need consider again */
#endif
#if defined(DBG_RX_SIGNAL_DISPLAY_SSID_MONITORED) && 1
if (strcmp(dst->Ssid.Ssid, DBG_RX_SIGNAL_DISPLAY_SSID_MONITORED) == 0) {
RTW_INFO(FUNC_ADPT_FMT" %s("MAC_FMT", ch%u) ss_ori:%3u, sq_ori:%3u, rssi_ori:%3ld, ss_smp:%3u, sq_smp:%3u, rssi_smp:%3ld\n"
, FUNC_ADPT_ARG(padapter)
, src->Ssid.Ssid, MAC_ARG(src->MacAddress), src->Configuration.DSConfig
, ss_ori, sq_ori, rssi_ori
, ss_smp, sq_smp, rssi_smp
);
}
#endif
/* The rule below is 1/5 for sample value, 4/5 for history value */
if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) && is_same_network(&(padapter->mlmepriv.cur_network.network), src, 0)) {
/* Take the recvpriv's value for the connected AP*/
ss_final = padapter->recvpriv.signal_strength;
sq_final = padapter->recvpriv.signal_qual;
/* the rssi value here is undecorated, and will be used for antenna diversity */
if (sq_smp != 101) /* from the right channel */
rssi_final = (src->Rssi + dst->Rssi * 4) / 5;
else
rssi_final = rssi_ori;
} else {
if (sq_smp != 101) { /* from the right channel */
ss_final = ((u32)(src->PhyInfo.SignalStrength) + (u32)(dst->PhyInfo.SignalStrength) * 4) / 5;
sq_final = ((u32)(src->PhyInfo.SignalQuality) + (u32)(dst->PhyInfo.SignalQuality) * 4) / 5;
rssi_final = (src->Rssi + dst->Rssi * 4) / 5;
} else {
/* bss info not receving from the right channel, use the original RX signal infos */
ss_final = dst->PhyInfo.SignalStrength;
sq_final = dst->PhyInfo.SignalQuality;
rssi_final = dst->Rssi;
}
}
if (update_ie) {
dst->Reserved[0] = src->Reserved[0];
dst->Reserved[1] = src->Reserved[1];
_rtw_memcpy((u8 *)dst, (u8 *)src, get_WLAN_BSSID_EX_sz(src));
}
#ifdef CONFIG_LAYER2_ROAMING
dst->tsf = src->tsf;
#endif
dst->PhyInfo.SignalStrength = ss_final;
dst->PhyInfo.SignalQuality = sq_final;
dst->Rssi = rssi_final;
#if defined(DBG_RX_SIGNAL_DISPLAY_SSID_MONITORED) && 1
if (strcmp(dst->Ssid.Ssid, DBG_RX_SIGNAL_DISPLAY_SSID_MONITORED) == 0) {
RTW_INFO(FUNC_ADPT_FMT" %s("MAC_FMT"), SignalStrength:%u, SignalQuality:%u, RawRSSI:%ld\n"
, FUNC_ADPT_ARG(padapter)
, dst->Ssid.Ssid, MAC_ARG(dst->MacAddress), dst->PhyInfo.SignalStrength, dst->PhyInfo.SignalQuality, dst->Rssi);
}
#endif
#if 0 /* old codes, may be useful one day...
* RTW_INFO("update_network: rssi=0x%lx dst->Rssi=%d ,dst->Rssi=0x%lx , src->Rssi=0x%lx",(dst->Rssi+src->Rssi)/2,dst->Rssi,dst->Rssi,src->Rssi); */
if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) && is_same_network(&(padapter->mlmepriv.cur_network.network), src)) {
/* RTW_INFO("b:ssid=%s update_network: src->rssi=0x%d padapter->recvpriv.ui_rssi=%d\n",src->Ssid.Ssid,src->Rssi,padapter->recvpriv.signal); */
if (padapter->recvpriv.signal_qual_data.total_num++ >= PHY_LINKQUALITY_SLID_WIN_MAX) {
padapter->recvpriv.signal_qual_data.total_num = PHY_LINKQUALITY_SLID_WIN_MAX;
last_evm = padapter->recvpriv.signal_qual_data.elements[padapter->recvpriv.signal_qual_data.index];
padapter->recvpriv.signal_qual_data.total_val -= last_evm;
}
padapter->recvpriv.signal_qual_data.total_val += query_rx_pwr_percentage(src->Rssi);
padapter->recvpriv.signal_qual_data.elements[padapter->recvpriv.signal_qual_data.index++] = query_rx_pwr_percentage(src->Rssi);
if (padapter->recvpriv.signal_qual_data.index >= PHY_LINKQUALITY_SLID_WIN_MAX)
padapter->recvpriv.signal_qual_data.index = 0;
/* RTW_INFO("Total SQ=%d pattrib->signal_qual= %d\n", padapter->recvpriv.signal_qual_data.total_val, src->Rssi); */
/* <1> Showed on UI for user,in percentage. */
tmpVal = padapter->recvpriv.signal_qual_data.total_val / padapter->recvpriv.signal_qual_data.total_num;
padapter->recvpriv.signal = (u8)tmpVal; /* Link quality */
src->Rssi = translate_percentage_to_dbm(padapter->recvpriv.signal) ;
} else {
/* RTW_INFO("ELSE:ssid=%s update_network: src->rssi=0x%d dst->rssi=%d\n",src->Ssid.Ssid,src->Rssi,dst->Rssi); */
src->Rssi = (src->Rssi + dst->Rssi) / 2; /* dBM */
}
/* RTW_INFO("a:update_network: src->rssi=0x%d padapter->recvpriv.ui_rssi=%d\n",src->Rssi,padapter->recvpriv.signal); */
#endif
}
static void update_current_network(_adapter *adapter, WLAN_BSSID_EX *pnetwork)
{
struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
rtw_bug_check(&(pmlmepriv->cur_network.network),
&(pmlmepriv->cur_network.network),
&(pmlmepriv->cur_network.network),
&(pmlmepriv->cur_network.network));
if ((check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE) && (is_same_network(&(pmlmepriv->cur_network.network), pnetwork, 0))) {
/* if(pmlmepriv->cur_network.network.IELength<= pnetwork->IELength) */
{
update_network(&(pmlmepriv->cur_network.network), pnetwork, adapter, _TRUE);
rtw_update_protection(adapter, (pmlmepriv->cur_network.network.IEs) + sizeof(NDIS_802_11_FIXED_IEs),
pmlmepriv->cur_network.network.IELength);
}
}
}
/*
Caller must hold pmlmepriv->lock first.
*/
bool rtw_update_scanned_network(_adapter *adapter, WLAN_BSSID_EX *target)
{
_irqL irqL;
_list *plist, *phead;
u32 bssid_ex_sz;
struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
#ifdef CONFIG_P2P
struct wifidirect_info *pwdinfo = &(adapter->wdinfo);
#endif /* CONFIG_P2P */
_queue *queue = &(pmlmepriv->scanned_queue);
struct wlan_network *pnetwork = NULL;
struct wlan_network *choice = NULL;
int target_find = 0;
u8 feature = 0;
bool update_ie = _FALSE;