Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nu11secur1ty
GitHub Repository: nu11secur1ty/Kali-Linux
Path: blob/master/ALFA-W1F1/RTL8814AU/core/rtw_ioctl_set.c
1307 views
1
/******************************************************************************
2
*
3
* Copyright(c) 2007 - 2017 Realtek Corporation.
4
*
5
* This program is free software; you can redistribute it and/or modify it
6
* under the terms of version 2 of the GNU General Public License as
7
* published by the Free Software Foundation.
8
*
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
* more details.
13
*
14
*****************************************************************************/
15
#define _RTW_IOCTL_SET_C_
16
17
#include <drv_types.h>
18
#include <hal_data.h>
19
20
21
extern void indicate_wx_scan_complete_event(_adapter *padapter);
22
23
#define IS_MAC_ADDRESS_BROADCAST(addr) \
24
(\
25
((addr[0] == 0xff) && (addr[1] == 0xff) && \
26
(addr[2] == 0xff) && (addr[3] == 0xff) && \
27
(addr[4] == 0xff) && (addr[5] == 0xff)) ? _TRUE : _FALSE \
28
)
29
30
u8 rtw_validate_bssid(u8 *bssid)
31
{
32
u8 ret = _TRUE;
33
34
if (is_zero_mac_addr(bssid)
35
|| is_broadcast_mac_addr(bssid)
36
|| is_multicast_mac_addr(bssid)
37
)
38
ret = _FALSE;
39
40
return ret;
41
}
42
43
u8 rtw_validate_ssid(NDIS_802_11_SSID *ssid)
44
{
45
#ifdef CONFIG_VALIDATE_SSID
46
u8 i;
47
#endif
48
u8 ret = _TRUE;
49
50
51
if (ssid->SsidLength > 32) {
52
ret = _FALSE;
53
goto exit;
54
}
55
56
#ifdef CONFIG_VALIDATE_SSID
57
for (i = 0; i < ssid->SsidLength; i++) {
58
/* wifi, printable ascii code must be supported */
59
if (!((ssid->Ssid[i] >= 0x20) && (ssid->Ssid[i] <= 0x7e))) {
60
ret = _FALSE;
61
break;
62
}
63
}
64
#endif /* CONFIG_VALIDATE_SSID */
65
66
exit:
67
68
69
return ret;
70
}
71
72
u8 rtw_do_join(_adapter *padapter);
73
u8 rtw_do_join(_adapter *padapter)
74
{
75
_irqL irqL;
76
_list *plist, *phead;
77
u8 *pibss = NULL;
78
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
79
struct sitesurvey_parm parm;
80
_queue *queue = &(pmlmepriv->scanned_queue);
81
u8 ret = _SUCCESS;
82
83
84
_enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
85
phead = get_list_head(queue);
86
plist = get_next(phead);
87
88
89
pmlmepriv->cur_network.join_res = -2;
90
91
set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
92
93
pmlmepriv->pscanned = plist;
94
95
pmlmepriv->to_join = _TRUE;
96
97
rtw_init_sitesurvey_parm(padapter, &parm);
98
_rtw_memcpy(&parm.ssid[0], &pmlmepriv->assoc_ssid, sizeof(NDIS_802_11_SSID));
99
parm.ssid_num = 1;
100
101
if (_rtw_queue_empty(queue) == _TRUE) {
102
_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
103
_clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
104
105
/* when set_ssid/set_bssid for rtw_do_join(), but scanning queue is empty */
106
/* we try to issue sitesurvey firstly */
107
108
if (pmlmepriv->LinkDetectInfo.bBusyTraffic == _FALSE
109
|| rtw_to_roam(padapter) > 0
110
) {
111
u8 ssc_chk = rtw_sitesurvey_condition_check(padapter, _FALSE);
112
113
if ((ssc_chk == SS_ALLOW) || (ssc_chk == SS_DENY_BUSY_TRAFFIC) ){
114
/* submit site_survey_cmd */
115
ret = rtw_sitesurvey_cmd(padapter, &parm);
116
if (_SUCCESS != ret)
117
pmlmepriv->to_join = _FALSE;
118
} else {
119
/*if (ssc_chk == SS_DENY_BUDDY_UNDER_SURVEY)*/
120
pmlmepriv->to_join = _FALSE;
121
ret = _FAIL;
122
}
123
} else {
124
pmlmepriv->to_join = _FALSE;
125
ret = _FAIL;
126
}
127
128
goto exit;
129
} else {
130
int select_ret;
131
_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
132
select_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv);
133
if (select_ret == _SUCCESS) {
134
pmlmepriv->to_join = _FALSE;
135
_set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT);
136
} else {
137
if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE) {
138
/* submit createbss_cmd to change to a ADHOC_MASTER */
139
140
/* pmlmepriv->lock has been acquired by caller... */
141
WLAN_BSSID_EX *pdev_network = &(padapter->registrypriv.dev_network);
142
143
/*pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;*/
144
init_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
145
146
pibss = padapter->registrypriv.dev_network.MacAddress;
147
148
_rtw_memset(&pdev_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
149
_rtw_memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(NDIS_802_11_SSID));
150
151
rtw_update_registrypriv_dev_network(padapter);
152
153
rtw_generate_random_ibss(pibss);
154
155
if (rtw_create_ibss_cmd(padapter, 0) != _SUCCESS) {
156
ret = _FALSE;
157
goto exit;
158
}
159
160
pmlmepriv->to_join = _FALSE;
161
162
163
} else {
164
/* can't associate ; reset under-linking */
165
_clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
166
167
/* when set_ssid/set_bssid for rtw_do_join(), but there are no desired bss in scanning queue */
168
/* we try to issue sitesurvey firstly */
169
if (pmlmepriv->LinkDetectInfo.bBusyTraffic == _FALSE
170
|| rtw_to_roam(padapter) > 0
171
) {
172
u8 ssc_chk = rtw_sitesurvey_condition_check(padapter, _FALSE);
173
174
if ((ssc_chk == SS_ALLOW) || (ssc_chk == SS_DENY_BUSY_TRAFFIC)){
175
/* RTW_INFO(("rtw_do_join() when no desired bss in scanning queue\n"); */
176
ret = rtw_sitesurvey_cmd(padapter, &parm);
177
if (_SUCCESS != ret)
178
pmlmepriv->to_join = _FALSE;
179
} else {
180
/*if (ssc_chk == SS_DENY_BUDDY_UNDER_SURVEY) {
181
} else {*/
182
ret = _FAIL;
183
pmlmepriv->to_join = _FALSE;
184
}
185
} else {
186
ret = _FAIL;
187
pmlmepriv->to_join = _FALSE;
188
}
189
}
190
191
}
192
193
}
194
195
exit:
196
197
return ret;
198
}
199
200
u8 rtw_set_802_11_bssid(_adapter *padapter, u8 *bssid)
201
{
202
_irqL irqL;
203
u8 status = _SUCCESS;
204
205
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
206
207
208
RTW_PRINT("set bssid:%pM\n", bssid);
209
210
if ((bssid[0] == 0x00 && bssid[1] == 0x00 && bssid[2] == 0x00 && bssid[3] == 0x00 && bssid[4] == 0x00 && bssid[5] == 0x00) ||
211
(bssid[0] == 0xFF && bssid[1] == 0xFF && bssid[2] == 0xFF && bssid[3] == 0xFF && bssid[4] == 0xFF && bssid[5] == 0xFF)) {
212
status = _FAIL;
213
goto exit;
214
}
215
216
_enter_critical_bh(&pmlmepriv->lock, &irqL);
217
218
219
RTW_INFO("Set BSSID under fw_state=0x%08x\n", get_fwstate(pmlmepriv));
220
if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
221
goto handle_tkip_countermeasure;
222
else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE)
223
goto release_mlme_lock;
224
225
if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE) == _TRUE) {
226
227
if (_rtw_memcmp(&pmlmepriv->cur_network.network.MacAddress, bssid, ETH_ALEN) == _TRUE) {
228
if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _FALSE)
229
goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */
230
} else {
231
232
rtw_disassoc_cmd(padapter, 0, 0);
233
234
if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
235
rtw_indicate_disconnect(padapter, 0, _FALSE);
236
237
rtw_free_assoc_resources_cmd(padapter, _TRUE, 0);
238
239
if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE)) {
240
_clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
241
set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
242
}
243
}
244
}
245
246
handle_tkip_countermeasure:
247
if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) {
248
status = _FAIL;
249
goto release_mlme_lock;
250
}
251
252
_rtw_memset(&pmlmepriv->assoc_ssid, 0, sizeof(NDIS_802_11_SSID));
253
_rtw_memcpy(&pmlmepriv->assoc_bssid, bssid, ETH_ALEN);
254
pmlmepriv->assoc_by_bssid = _TRUE;
255
256
if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
257
pmlmepriv->to_join = _TRUE;
258
else
259
status = rtw_do_join(padapter);
260
261
release_mlme_lock:
262
_exit_critical_bh(&pmlmepriv->lock, &irqL);
263
264
exit:
265
266
267
return status;
268
}
269
270
u8 rtw_set_802_11_ssid(_adapter *padapter, NDIS_802_11_SSID *ssid)
271
{
272
_irqL irqL;
273
u8 status = _SUCCESS;
274
275
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
276
struct wlan_network *pnetwork = &pmlmepriv->cur_network;
277
278
279
RTW_PRINT("set ssid [%s] fw_state=0x%08x\n",
280
ssid->Ssid, get_fwstate(pmlmepriv));
281
282
if (!rtw_is_hw_init_completed(padapter)) {
283
status = _FAIL;
284
goto exit;
285
}
286
287
_enter_critical_bh(&pmlmepriv->lock, &irqL);
288
289
RTW_INFO("Set SSID under fw_state=0x%08x\n", get_fwstate(pmlmepriv));
290
if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
291
goto handle_tkip_countermeasure;
292
else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE)
293
goto release_mlme_lock;
294
295
if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE) == _TRUE) {
296
297
if ((pmlmepriv->assoc_ssid.SsidLength == ssid->SsidLength) &&
298
(_rtw_memcmp(&pmlmepriv->assoc_ssid.Ssid, ssid->Ssid, ssid->SsidLength) == _TRUE)) {
299
if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _FALSE)) {
300
301
if (rtw_is_same_ibss(padapter, pnetwork) == _FALSE) {
302
/* if in WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE, create bss or rejoin again */
303
rtw_disassoc_cmd(padapter, 0, 0);
304
305
if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
306
rtw_indicate_disconnect(padapter, 0, _FALSE);
307
308
rtw_free_assoc_resources_cmd(padapter, _TRUE, 0);
309
310
if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) {
311
_clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
312
set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
313
}
314
} else {
315
goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */
316
}
317
}
318
#ifdef CONFIG_LPS
319
else
320
rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_JOINBSS, 0);
321
#endif
322
} else {
323
324
rtw_disassoc_cmd(padapter, 0, 0);
325
326
if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
327
rtw_indicate_disconnect(padapter, 0, _FALSE);
328
329
rtw_free_assoc_resources_cmd(padapter, _TRUE, 0);
330
331
if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) {
332
_clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
333
set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
334
}
335
}
336
}
337
338
handle_tkip_countermeasure:
339
if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) {
340
status = _FAIL;
341
goto release_mlme_lock;
342
}
343
344
if (rtw_validate_ssid(ssid) == _FALSE) {
345
status = _FAIL;
346
goto release_mlme_lock;
347
}
348
349
_rtw_memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(NDIS_802_11_SSID));
350
pmlmepriv->assoc_by_bssid = _FALSE;
351
352
if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
353
pmlmepriv->to_join = _TRUE;
354
else
355
status = rtw_do_join(padapter);
356
357
release_mlme_lock:
358
_exit_critical_bh(&pmlmepriv->lock, &irqL);
359
360
exit:
361
362
363
return status;
364
365
}
366
367
u8 rtw_set_802_11_connect(_adapter *padapter, u8 *bssid, NDIS_802_11_SSID *ssid)
368
{
369
_irqL irqL;
370
u8 status = _SUCCESS;
371
bool bssid_valid = _TRUE;
372
bool ssid_valid = _TRUE;
373
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
374
375
376
if (!ssid || rtw_validate_ssid(ssid) == _FALSE)
377
ssid_valid = _FALSE;
378
379
if (!bssid || rtw_validate_bssid(bssid) == _FALSE)
380
bssid_valid = _FALSE;
381
382
if (ssid_valid == _FALSE && bssid_valid == _FALSE) {
383
RTW_INFO(FUNC_ADPT_FMT" ssid:%p, ssid_valid:%d, bssid:%p, bssid_valid:%d\n",
384
FUNC_ADPT_ARG(padapter), ssid, ssid_valid, bssid, bssid_valid);
385
status = _FAIL;
386
goto exit;
387
}
388
389
if (!rtw_is_hw_init_completed(padapter)) {
390
status = _FAIL;
391
goto exit;
392
}
393
394
_enter_critical_bh(&pmlmepriv->lock, &irqL);
395
396
RTW_PRINT(FUNC_ADPT_FMT" fw_state=0x%08x\n",
397
FUNC_ADPT_ARG(padapter), get_fwstate(pmlmepriv));
398
399
if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
400
goto handle_tkip_countermeasure;
401
else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE)
402
goto release_mlme_lock;
403
404
handle_tkip_countermeasure:
405
if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) {
406
status = _FAIL;
407
goto release_mlme_lock;
408
}
409
410
if (ssid && ssid_valid)
411
_rtw_memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(NDIS_802_11_SSID));
412
else
413
_rtw_memset(&pmlmepriv->assoc_ssid, 0, sizeof(NDIS_802_11_SSID));
414
415
if (bssid && bssid_valid) {
416
_rtw_memcpy(&pmlmepriv->assoc_bssid, bssid, ETH_ALEN);
417
pmlmepriv->assoc_by_bssid = _TRUE;
418
} else
419
pmlmepriv->assoc_by_bssid = _FALSE;
420
421
if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
422
pmlmepriv->to_join = _TRUE;
423
else
424
status = rtw_do_join(padapter);
425
426
release_mlme_lock:
427
_exit_critical_bh(&pmlmepriv->lock, &irqL);
428
429
exit:
430
return status;
431
}
432
433
u8 rtw_set_802_11_infrastructure_mode(_adapter *padapter,
434
NDIS_802_11_NETWORK_INFRASTRUCTURE networktype, u8 flags)
435
{
436
_irqL irqL;
437
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
438
struct wlan_network *cur_network = &pmlmepriv->cur_network;
439
NDIS_802_11_NETWORK_INFRASTRUCTURE *pold_state = &(cur_network->network.InfrastructureMode);
440
u8 ap2sta_mode = _FALSE;
441
u8 ret = _TRUE;
442
u8 is_linked = _FALSE, is_adhoc_master = _FALSE;
443
444
if (*pold_state != networktype) {
445
/* RTW_INFO("change mode, old_mode=%d, new_mode=%d, fw_state=0x%x\n", *pold_state, networktype, get_fwstate(pmlmepriv)); */
446
447
if (*pold_state == Ndis802_11APMode
448
|| *pold_state == Ndis802_11_mesh
449
) {
450
/* change to other mode from Ndis802_11APMode/Ndis802_11_mesh */
451
cur_network->join_res = -1;
452
ap2sta_mode = _TRUE;
453
#ifdef CONFIG_NATIVEAP_MLME
454
stop_ap_mode(padapter);
455
#endif
456
}
457
458
_enter_critical_bh(&pmlmepriv->lock, &irqL);
459
is_linked = check_fwstate(pmlmepriv, _FW_LINKED);
460
is_adhoc_master = check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
461
462
/* flags = 0, means enqueue cmd and no wait */
463
if (flags != 0)
464
_exit_critical_bh(&pmlmepriv->lock, &irqL);
465
466
if ((is_linked == _TRUE) || (*pold_state == Ndis802_11IBSS))
467
rtw_disassoc_cmd(padapter, 0, flags);
468
469
if ((is_linked == _TRUE) ||
470
(is_adhoc_master == _TRUE))
471
rtw_free_assoc_resources_cmd(padapter, _TRUE, flags);
472
473
if ((*pold_state == Ndis802_11Infrastructure) || (*pold_state == Ndis802_11IBSS)) {
474
if (is_linked == _TRUE) {
475
rtw_indicate_disconnect(padapter, 0, _FALSE); /*will clr Linked_state; before this function, we must have checked whether issue dis-assoc_cmd or not*/
476
}
477
}
478
479
/* flags = 0, means enqueue cmd and no wait */
480
if (flags != 0)
481
_enter_critical_bh(&pmlmepriv->lock, &irqL);
482
483
*pold_state = networktype;
484
485
_clr_fwstate_(pmlmepriv, ~WIFI_NULL_STATE);
486
487
switch (networktype) {
488
case Ndis802_11IBSS:
489
set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
490
break;
491
492
case Ndis802_11Infrastructure:
493
set_fwstate(pmlmepriv, WIFI_STATION_STATE);
494
495
if (ap2sta_mode)
496
rtw_init_bcmc_stainfo(padapter);
497
break;
498
499
case Ndis802_11APMode:
500
set_fwstate(pmlmepriv, WIFI_AP_STATE);
501
#ifdef CONFIG_NATIVEAP_MLME
502
start_ap_mode(padapter);
503
/* rtw_indicate_connect(padapter); */
504
#endif
505
506
break;
507
508
#ifdef CONFIG_RTW_MESH
509
case Ndis802_11_mesh:
510
set_fwstate(pmlmepriv, WIFI_MESH_STATE);
511
start_ap_mode(padapter);
512
break;
513
#endif
514
515
case Ndis802_11AutoUnknown:
516
case Ndis802_11InfrastructureMax:
517
break;
518
case Ndis802_11Monitor:
519
set_fwstate(pmlmepriv, WIFI_MONITOR_STATE);
520
break;
521
default:
522
ret = _FALSE;
523
rtw_warn_on(1);
524
}
525
526
/* SecClearAllKeys(adapter); */
527
528
529
_exit_critical_bh(&pmlmepriv->lock, &irqL);
530
}
531
532
return ret;
533
}
534
535
536
u8 rtw_set_802_11_disassociate(_adapter *padapter)
537
{
538
_irqL irqL;
539
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
540
541
542
_enter_critical_bh(&pmlmepriv->lock, &irqL);
543
544
if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
545
546
rtw_disassoc_cmd(padapter, 0, 0);
547
rtw_indicate_disconnect(padapter, 0, _FALSE);
548
/* modify for CONFIG_IEEE80211W, none 11w can use it */
549
rtw_free_assoc_resources_cmd(padapter, _TRUE, 0);
550
if (_FAIL == rtw_pwr_wakeup(padapter))
551
RTW_INFO("%s(): rtw_pwr_wakeup fail !!!\n", __FUNCTION__);
552
}
553
554
_exit_critical_bh(&pmlmepriv->lock, &irqL);
555
556
557
return _TRUE;
558
}
559
560
#if 1
561
u8 rtw_set_802_11_bssid_list_scan(_adapter *padapter, struct sitesurvey_parm *pparm)
562
{
563
_irqL irqL;
564
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
565
u8 res = _TRUE;
566
567
_enter_critical_bh(&pmlmepriv->lock, &irqL);
568
res = rtw_sitesurvey_cmd(padapter, pparm);
569
_exit_critical_bh(&pmlmepriv->lock, &irqL);
570
571
return res;
572
}
573
574
#else
575
u8 rtw_set_802_11_bssid_list_scan(_adapter *padapter, struct sitesurvey_parm *pparm)
576
{
577
_irqL irqL;
578
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
579
u8 res = _TRUE;
580
581
582
583
if (padapter == NULL) {
584
res = _FALSE;
585
goto exit;
586
}
587
if (!rtw_is_hw_init_completed(padapter)) {
588
res = _FALSE;
589
goto exit;
590
}
591
592
if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING) == _TRUE) ||
593
(pmlmepriv->LinkDetectInfo.bBusyTraffic == _TRUE)) {
594
/* Scan or linking is in progress, do nothing. */
595
res = _TRUE;
596
597
598
} else {
599
if (rtw_is_scan_deny(padapter)) {
600
RTW_INFO(FUNC_ADPT_FMT": scan deny\n", FUNC_ADPT_ARG(padapter));
601
indicate_wx_scan_complete_event(padapter);
602
return _SUCCESS;
603
}
604
605
_enter_critical_bh(&pmlmepriv->lock, &irqL);
606
607
res = rtw_sitesurvey_cmd(padapter, pparm);
608
609
_exit_critical_bh(&pmlmepriv->lock, &irqL);
610
}
611
exit:
612
613
614
return res;
615
}
616
#endif
617
u8 rtw_set_802_11_authentication_mode(_adapter *padapter, NDIS_802_11_AUTHENTICATION_MODE authmode)
618
{
619
struct security_priv *psecuritypriv = &padapter->securitypriv;
620
int res;
621
u8 ret;
622
623
624
625
psecuritypriv->ndisauthtype = authmode;
626
627
628
if (psecuritypriv->ndisauthtype > 3)
629
psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
630
631
#ifdef CONFIG_WAPI_SUPPORT
632
if (psecuritypriv->ndisauthtype == 6)
633
psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
634
#endif
635
636
res = rtw_set_auth(padapter, psecuritypriv);
637
638
if (res == _SUCCESS)
639
ret = _TRUE;
640
else
641
ret = _FALSE;
642
643
644
return ret;
645
}
646
647
u8 rtw_set_802_11_add_wep(_adapter *padapter, NDIS_802_11_WEP *wep)
648
{
649
650
u8 bdefaultkey;
651
u8 btransmitkey;
652
sint keyid, res;
653
struct security_priv *psecuritypriv = &(padapter->securitypriv);
654
u8 ret = _SUCCESS;
655
656
657
bdefaultkey = (wep->KeyIndex & 0x40000000) > 0 ? _FALSE : _TRUE; /* for ??? */
658
btransmitkey = (wep->KeyIndex & 0x80000000) > 0 ? _TRUE : _FALSE; /* for ??? */
659
keyid = wep->KeyIndex & 0x3fffffff;
660
661
if (keyid >= 4) {
662
ret = _FALSE;
663
goto exit;
664
}
665
666
switch (wep->KeyLength) {
667
case 5:
668
psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
669
break;
670
case 13:
671
psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
672
break;
673
default:
674
psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
675
break;
676
}
677
678
679
_rtw_memcpy(&(psecuritypriv->dot11DefKey[keyid].skey[0]), &(wep->KeyMaterial), wep->KeyLength);
680
681
psecuritypriv->dot11DefKeylen[keyid] = wep->KeyLength;
682
683
psecuritypriv->dot11PrivacyKeyIndex = keyid;
684
685
686
res = rtw_set_key(padapter, psecuritypriv, keyid, 1, _TRUE);
687
688
if (res == _FAIL)
689
ret = _FALSE;
690
exit:
691
692
693
return ret;
694
695
}
696
697
/*
698
* rtw_get_cur_max_rate -
699
* @adapter: pointer to _adapter structure
700
*
701
* Return 0 or 100Kbps
702
*/
703
u16 rtw_get_cur_max_rate(_adapter *adapter)
704
{
705
int j;
706
int i = 0;
707
u16 rate = 0, max_rate = 0;
708
struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
709
WLAN_BSSID_EX *pcur_bss = &pmlmepriv->cur_network.network;
710
int sta_bssrate_len = 0;
711
unsigned char sta_bssrate[NumRates];
712
struct sta_info *psta = NULL;
713
u8 short_GI = 0;
714
715
#ifdef CONFIG_MP_INCLUDED
716
if (adapter->registrypriv.mp_mode == 1) {
717
if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE)
718
return 0;
719
}
720
#endif
721
722
if ((check_fwstate(pmlmepriv, _FW_LINKED) != _TRUE)
723
&& (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) != _TRUE))
724
return 0;
725
726
psta = rtw_get_stainfo(&adapter->stapriv, get_bssid(pmlmepriv));
727
if (psta == NULL)
728
return 0;
729
730
short_GI = query_ra_short_GI(psta, rtw_get_tx_bw_mode(adapter, psta));
731
732
#ifdef CONFIG_80211N_HT
733
if (is_supported_ht(psta->wireless_mode)) {
734
max_rate = rtw_ht_mcs_rate((psta->cmn.bw_mode == CHANNEL_WIDTH_40) ? 1 : 0
735
, short_GI
736
, psta->htpriv.ht_cap.supp_mcs_set
737
);
738
}
739
#ifdef CONFIG_80211AC_VHT
740
else if (is_supported_vht(psta->wireless_mode))
741
max_rate = ((rtw_vht_mcs_to_data_rate(psta->cmn.bw_mode, short_GI, pmlmepriv->vhtpriv.vht_highest_rate) + 1) >> 1) * 10;
742
#endif /* CONFIG_80211AC_VHT */
743
else
744
#endif /* CONFIG_80211N_HT */
745
{
746
/*station mode show :station && ap support rate; softap :show ap support rate*/
747
if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)
748
get_rate_set(adapter, sta_bssrate, &sta_bssrate_len);/*get sta rate and length*/
749
750
751
while ((pcur_bss->SupportedRates[i] != 0) && (pcur_bss->SupportedRates[i] != 0xFF)) {
752
rate = pcur_bss->SupportedRates[i] & 0x7F;/*AP support rates*/
753
/*RTW_INFO("%s rate=%02X \n", __func__, rate);*/
754
755
/*check STA support rate or not */
756
if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE) {
757
for (j = 0; j < sta_bssrate_len; j++) {
758
/* Avoid the proprietary data rate (22Mbps) of Handlink WSG-4000 AP */
759
if ((rate | IEEE80211_BASIC_RATE_MASK)
760
== (sta_bssrate[j] | IEEE80211_BASIC_RATE_MASK)) {
761
if (rate > max_rate) {
762
max_rate = rate;
763
}
764
break;
765
}
766
}
767
} else {
768
769
if (rate > max_rate)
770
max_rate = rate;
771
772
}
773
i++;
774
}
775
776
max_rate = max_rate * 10 / 2;
777
}
778
return max_rate;
779
}
780
781
/*
782
* rtw_set_scan_mode -
783
* @adapter: pointer to _adapter structure
784
* @scan_mode:
785
*
786
* Return _SUCCESS or _FAIL
787
*/
788
int rtw_set_scan_mode(_adapter *adapter, RT_SCAN_TYPE scan_mode)
789
{
790
if (scan_mode != SCAN_ACTIVE && scan_mode != SCAN_PASSIVE)
791
return _FAIL;
792
793
adapter->mlmepriv.scan_mode = scan_mode;
794
795
return _SUCCESS;
796
}
797
798
/*
799
* rtw_set_channel_plan -
800
* @adapter: pointer to _adapter structure
801
* @channel_plan:
802
*
803
* Return _SUCCESS or _FAIL
804
*/
805
int rtw_set_channel_plan(_adapter *adapter, u8 channel_plan)
806
{
807
/* handle by cmd_thread to sync with scan operation */
808
return rtw_set_chplan_cmd(adapter, RTW_CMDF_WAIT_ACK, channel_plan, 1);
809
}
810
811
/*
812
* rtw_set_country -
813
* @adapter: pointer to _adapter structure
814
* @country_code: string of country code
815
*
816
* Return _SUCCESS or _FAIL
817
*/
818
int rtw_set_country(_adapter *adapter, const char *country_code)
819
{
820
#ifdef CONFIG_RTW_IOCTL_SET_COUNTRY
821
return rtw_set_country_cmd(adapter, RTW_CMDF_WAIT_ACK, country_code, 1);
822
#else
823
RTW_INFO("%s(): not applied\n", __func__);
824
return _SUCCESS;
825
#endif
826
}
827
828
/*
829
* rtw_set_band -
830
* @adapter: pointer to _adapter structure
831
* @band: band to set
832
*
833
* Return _SUCCESS or _FAIL
834
*/
835
int rtw_set_band(_adapter *adapter, u8 band)
836
{
837
if (rtw_band_valid(band)) {
838
RTW_INFO(FUNC_ADPT_FMT" band:%d\n", FUNC_ADPT_ARG(adapter), band);
839
adapter->setband = band;
840
return _SUCCESS;
841
}
842
843
RTW_PRINT(FUNC_ADPT_FMT" band:%d fail\n", FUNC_ADPT_ARG(adapter), band);
844
return _FAIL;
845
}
846
847