net: wireless: rockchip_wlan: add rtl8723cs support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723cs / core / rtw_ioctl_set.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
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  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20 #define _RTW_IOCTL_SET_C_
21
22 #include <drv_types.h>
23 #include <hal_data.h>
24
25
26 extern void indicate_wx_scan_complete_event(_adapter *padapter);
27
28 #define IS_MAC_ADDRESS_BROADCAST(addr) \
29         (\
30          ((addr[0] == 0xff) && (addr[1] == 0xff) && \
31           (addr[2] == 0xff) && (addr[3] == 0xff) && \
32           (addr[4] == 0xff) && (addr[5] == 0xff)) ? _TRUE : _FALSE \
33         )
34
35 u8 rtw_validate_bssid(u8 *bssid)
36 {
37         u8 ret = _TRUE;
38
39         if (is_zero_mac_addr(bssid)
40             || is_broadcast_mac_addr(bssid)
41             || is_multicast_mac_addr(bssid)
42            )
43                 ret = _FALSE;
44
45         return ret;
46 }
47
48 u8 rtw_validate_ssid(NDIS_802_11_SSID *ssid)
49 {
50         u8       i;
51         u8      ret = _TRUE;
52
53
54         if (ssid->SsidLength > 32) {
55                 ret = _FALSE;
56                 goto exit;
57         }
58
59 #ifdef CONFIG_VALIDATE_SSID
60         for (i = 0; i < ssid->SsidLength; i++) {
61                 /* wifi, printable ascii code must be supported */
62                 if (!((ssid->Ssid[i] >= 0x20) && (ssid->Ssid[i] <= 0x7e))) {
63                         ret = _FALSE;
64                         break;
65                 }
66         }
67 #endif /* CONFIG_VALIDATE_SSID */
68
69 exit:
70
71
72         return ret;
73 }
74
75 u8 rtw_do_join(_adapter *padapter);
76 u8 rtw_do_join(_adapter *padapter)
77 {
78         _irqL   irqL;
79         _list   *plist, *phead;
80         u8 *pibss = NULL;
81         struct  mlme_priv       *pmlmepriv = &(padapter->mlmepriv);
82         _queue  *queue  = &(pmlmepriv->scanned_queue);
83         u8 ret = _SUCCESS;
84
85
86         _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
87         phead = get_list_head(queue);
88         plist = get_next(phead);
89
90
91         pmlmepriv->cur_network.join_res = -2;
92
93         set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
94
95         pmlmepriv->pscanned = plist;
96
97         pmlmepriv->to_join = _TRUE;
98
99         if (_rtw_queue_empty(queue) == _TRUE) {
100                 _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
101                 _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
102
103                 /* when set_ssid/set_bssid for rtw_do_join(), but scanning queue is empty */
104                 /* we try to issue sitesurvey firstly    */
105
106                 if (pmlmepriv->LinkDetectInfo.bBusyTraffic == _FALSE
107                     || rtw_to_roam(padapter) > 0
108                    ) {
109                         /* submit site_survey_cmd */
110                         ret = rtw_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid, 1, NULL, 0);
111                         if (_SUCCESS != ret) {
112                                 pmlmepriv->to_join = _FALSE;
113                         }
114                 } else {
115                         pmlmepriv->to_join = _FALSE;
116                         ret = _FAIL;
117                 }
118
119                 goto exit;
120         } else {
121                 int select_ret;
122                 _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
123                 select_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv);
124                 if (select_ret == _SUCCESS) {
125                         pmlmepriv->to_join = _FALSE;
126                         _set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT);
127                 } else {
128                         if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE) {
129                                 /* submit createbss_cmd to change to a ADHOC_MASTER */
130
131                                 /* pmlmepriv->lock has been acquired by caller... */
132                                 WLAN_BSSID_EX    *pdev_network = &(padapter->registrypriv.dev_network);
133
134                                 /*pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;*/
135                                 init_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
136
137                                 pibss = padapter->registrypriv.dev_network.MacAddress;
138
139                                 _rtw_memset(&pdev_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
140                                 _rtw_memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(NDIS_802_11_SSID));
141
142                                 rtw_update_registrypriv_dev_network(padapter);
143
144                                 rtw_generate_random_ibss(pibss);
145
146                                 if (rtw_create_ibss_cmd(padapter, 0) != _SUCCESS) {
147                                         ret =  _FALSE;
148                                         goto exit;
149                                 }
150
151                                 pmlmepriv->to_join = _FALSE;
152
153
154                         } else {
155                                 /* can't associate ; reset under-linking                         */
156                                 _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
157
158 #if 0
159                                 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)) {
160                                         if (_rtw_memcmp(pmlmepriv->cur_network.network.Ssid.Ssid, pmlmepriv->assoc_ssid.Ssid, pmlmepriv->assoc_ssid.SsidLength)) {
161                                                 /* for funk to do roaming */
162                                                 /* funk will reconnect, but funk will not sitesurvey before reconnect */
163                                                 if (pmlmepriv->sitesurveyctrl.traffic_busy == _FALSE)
164                                                         rtw_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid, 1, NULL, 0);
165                                         }
166
167                                 }
168 #endif
169
170                                 /* when set_ssid/set_bssid for rtw_do_join(), but there are no desired bss in scanning queue */
171                                 /* we try to issue sitesurvey firstly                    */
172                                 if (pmlmepriv->LinkDetectInfo.bBusyTraffic == _FALSE
173                                     || rtw_to_roam(padapter) > 0
174                                    ) {
175                                         /* RTW_INFO("rtw_do_join() when   no desired bss in scanning queue\n"); */
176                                         ret = rtw_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid, 1, NULL, 0);
177                                         if (_SUCCESS != ret) {
178                                                 pmlmepriv->to_join = _FALSE;
179                                         }
180                                 } else {
181                                         ret = _FAIL;
182                                         pmlmepriv->to_join = _FALSE;
183                                 }
184                         }
185
186                 }
187
188         }
189
190 exit:
191
192         return ret;
193 }
194
195 #ifdef PLATFORM_WINDOWS
196 u8 rtw_pnp_set_power_wakeup(_adapter *padapter)
197 {
198         u8 res = _SUCCESS;
199
200
201
202         res = rtw_setstandby_cmd(padapter, 0);
203
204
205
206         return res;
207 }
208
209 u8 rtw_pnp_set_power_sleep(_adapter *padapter)
210 {
211         u8 res = _SUCCESS;
212
213
214         /* DbgPrint("+rtw_pnp_set_power_sleep\n"); */
215
216         res = rtw_setstandby_cmd(padapter, 1);
217
218
219
220         return res;
221 }
222
223 u8 rtw_set_802_11_reload_defaults(_adapter *padapter, NDIS_802_11_RELOAD_DEFAULTS reloadDefaults)
224 {
225
226
227
228         /* SecClearAllKeys(Adapter); */
229         /* 8711 CAM was not for En/Decrypt only */
230         /* so, we can't clear all keys. */
231         /* should we disable WPAcfg (ox0088) bit 1-2, instead of clear all CAM */
232
233         /* TO DO... */
234
235
236         return _TRUE;
237 }
238
239 u8 set_802_11_test(_adapter *padapter, NDIS_802_11_TEST *test)
240 {
241         u8 ret = _TRUE;
242
243
244         switch (test->Type) {
245         case 1:
246                 NdisMIndicateStatus(padapter->hndis_adapter, NDIS_STATUS_MEDIA_SPECIFIC_INDICATION, (PVOID)&test->AuthenticationEvent, test->Length - 8);
247                 NdisMIndicateStatusComplete(padapter->hndis_adapter);
248                 break;
249
250         case 2:
251                 NdisMIndicateStatus(padapter->hndis_adapter, NDIS_STATUS_MEDIA_SPECIFIC_INDICATION, (PVOID)&test->RssiTrigger, sizeof(NDIS_802_11_RSSI));
252                 NdisMIndicateStatusComplete(padapter->hndis_adapter);
253                 break;
254
255         default:
256                 ret = _FALSE;
257                 break;
258         }
259
260
261         return ret;
262 }
263
264 u8      rtw_set_802_11_pmkid(_adapter   *padapter, NDIS_802_11_PMKID *pmkid)
265 {
266         u8      ret = _SUCCESS;
267
268         return ret;
269 }
270
271 #endif
272
273 u8 rtw_set_802_11_bssid(_adapter *padapter, u8 *bssid)
274 {
275         _irqL irqL;
276         u8 status = _SUCCESS;
277
278         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
279
280
281         RTW_PRINT("set bssid:%pM\n", bssid);
282
283         if ((bssid[0] == 0x00 && bssid[1] == 0x00 && bssid[2] == 0x00 && bssid[3] == 0x00 && bssid[4] == 0x00 && bssid[5] == 0x00) ||
284             (bssid[0] == 0xFF && bssid[1] == 0xFF && bssid[2] == 0xFF && bssid[3] == 0xFF && bssid[4] == 0xFF && bssid[5] == 0xFF)) {
285                 status = _FAIL;
286                 goto exit;
287         }
288
289         _enter_critical_bh(&pmlmepriv->lock, &irqL);
290
291
292         RTW_INFO("Set BSSID under fw_state=0x%08x\n", get_fwstate(pmlmepriv));
293         if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
294                 goto handle_tkip_countermeasure;
295         else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE)
296                 goto release_mlme_lock;
297
298         if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE) == _TRUE) {
299
300                 if (_rtw_memcmp(&pmlmepriv->cur_network.network.MacAddress, bssid, ETH_ALEN) == _TRUE) {
301                         if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _FALSE)
302                                 goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */
303                 } else {
304
305                         rtw_disassoc_cmd(padapter, 0, 0);
306
307                         if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
308                                 rtw_indicate_disconnect(padapter, 0, _FALSE);
309
310                         rtw_free_assoc_resources(padapter, 1);
311
312                         if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE)) {
313                                 _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
314                                 set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
315                         }
316                 }
317         }
318
319 handle_tkip_countermeasure:
320         if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) {
321                 status = _FAIL;
322                 goto release_mlme_lock;
323         }
324
325         _rtw_memset(&pmlmepriv->assoc_ssid, 0, sizeof(NDIS_802_11_SSID));
326         _rtw_memcpy(&pmlmepriv->assoc_bssid, bssid, ETH_ALEN);
327         pmlmepriv->assoc_by_bssid = _TRUE;
328
329         if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
330                 pmlmepriv->to_join = _TRUE;
331         else
332                 status = rtw_do_join(padapter);
333
334 release_mlme_lock:
335         _exit_critical_bh(&pmlmepriv->lock, &irqL);
336
337 exit:
338
339
340         return status;
341 }
342
343 u8 rtw_set_802_11_ssid(_adapter *padapter, NDIS_802_11_SSID *ssid)
344 {
345         _irqL irqL;
346         u8 status = _SUCCESS;
347         u32 cur_time = 0;
348
349         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
350         struct wlan_network *pnetwork = &pmlmepriv->cur_network;
351
352
353         RTW_PRINT("set ssid [%s] fw_state=0x%08x\n",
354                   ssid->Ssid, get_fwstate(pmlmepriv));
355
356         if (!rtw_is_hw_init_completed(padapter)) {
357                 status = _FAIL;
358                 goto exit;
359         }
360
361         _enter_critical_bh(&pmlmepriv->lock, &irqL);
362
363         RTW_INFO("Set SSID under fw_state=0x%08x\n", get_fwstate(pmlmepriv));
364         if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
365                 goto handle_tkip_countermeasure;
366         else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE)
367                 goto release_mlme_lock;
368
369         if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE) == _TRUE) {
370
371                 if ((pmlmepriv->assoc_ssid.SsidLength == ssid->SsidLength) &&
372                     (_rtw_memcmp(&pmlmepriv->assoc_ssid.Ssid, ssid->Ssid, ssid->SsidLength) == _TRUE)) {
373                         if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _FALSE)) {
374
375                                 if (rtw_is_same_ibss(padapter, pnetwork) == _FALSE) {
376                                         /* if in WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE, create bss or rejoin again */
377                                         rtw_disassoc_cmd(padapter, 0, 0);
378
379                                         if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
380                                                 rtw_indicate_disconnect(padapter, 0, _FALSE);
381
382                                         rtw_free_assoc_resources(padapter, 1);
383
384                                         if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) {
385                                                 _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
386                                                 set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
387                                         }
388                                 } else {
389                                         goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */
390                                 }
391                         }
392 #ifdef CONFIG_LPS
393                         else
394                                 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_JOINBSS, 1);
395 #endif
396                 } else {
397
398                         rtw_disassoc_cmd(padapter, 0, 0);
399
400                         if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
401                                 rtw_indicate_disconnect(padapter, 0, _FALSE);
402
403                         rtw_free_assoc_resources(padapter, 1);
404
405                         if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) {
406                                 _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
407                                 set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
408                         }
409                 }
410         }
411
412 handle_tkip_countermeasure:
413         if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) {
414                 status = _FAIL;
415                 goto release_mlme_lock;
416         }
417
418         if (rtw_validate_ssid(ssid) == _FALSE) {
419                 status = _FAIL;
420                 goto release_mlme_lock;
421         }
422
423         _rtw_memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(NDIS_802_11_SSID));
424         pmlmepriv->assoc_by_bssid = _FALSE;
425
426         if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
427                 pmlmepriv->to_join = _TRUE;
428         else
429                 status = rtw_do_join(padapter);
430
431 release_mlme_lock:
432         _exit_critical_bh(&pmlmepriv->lock, &irqL);
433
434 exit:
435
436
437         return status;
438
439 }
440
441 u8 rtw_set_802_11_connect(_adapter *padapter, u8 *bssid, NDIS_802_11_SSID *ssid)
442 {
443         _irqL irqL;
444         u8 status = _SUCCESS;
445         u32 cur_time = 0;
446         bool bssid_valid = _TRUE;
447         bool ssid_valid = _TRUE;
448         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
449
450
451         if (!ssid || rtw_validate_ssid(ssid) == _FALSE)
452                 ssid_valid = _FALSE;
453
454         if (!bssid || rtw_validate_bssid(bssid) == _FALSE)
455                 bssid_valid = _FALSE;
456
457         if (ssid_valid == _FALSE && bssid_valid == _FALSE) {
458                 RTW_INFO(FUNC_ADPT_FMT" ssid:%p, ssid_valid:%d, bssid:%p, bssid_valid:%d\n",
459                         FUNC_ADPT_ARG(padapter), ssid, ssid_valid, bssid, bssid_valid);
460                 status = _FAIL;
461                 goto exit;
462         }
463
464         if (!rtw_is_hw_init_completed(padapter)) {
465                 status = _FAIL;
466                 goto exit;
467         }
468
469         _enter_critical_bh(&pmlmepriv->lock, &irqL);
470
471         RTW_PRINT(FUNC_ADPT_FMT"  fw_state=0x%08x\n",
472                   FUNC_ADPT_ARG(padapter), get_fwstate(pmlmepriv));
473
474         if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
475                 goto handle_tkip_countermeasure;
476         else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE)
477                 goto release_mlme_lock;
478
479 handle_tkip_countermeasure:
480         if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) {
481                 status = _FAIL;
482                 goto release_mlme_lock;
483         }
484
485         if (ssid && ssid_valid)
486                 _rtw_memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(NDIS_802_11_SSID));
487         else
488                 _rtw_memset(&pmlmepriv->assoc_ssid, 0, sizeof(NDIS_802_11_SSID));
489
490         if (bssid && bssid_valid) {
491                 _rtw_memcpy(&pmlmepriv->assoc_bssid, bssid, ETH_ALEN);
492                 pmlmepriv->assoc_by_bssid = _TRUE;
493         } else
494                 pmlmepriv->assoc_by_bssid = _FALSE;
495
496         if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
497                 pmlmepriv->to_join = _TRUE;
498         else
499                 status = rtw_do_join(padapter);
500
501 release_mlme_lock:
502         _exit_critical_bh(&pmlmepriv->lock, &irqL);
503
504 exit:
505
506
507         return status;
508 }
509
510 u8 rtw_set_802_11_infrastructure_mode(_adapter *padapter,
511                               NDIS_802_11_NETWORK_INFRASTRUCTURE networktype)
512 {
513         _irqL irqL;
514         struct  mlme_priv       *pmlmepriv = &padapter->mlmepriv;
515         struct  wlan_network    *cur_network = &pmlmepriv->cur_network;
516         NDIS_802_11_NETWORK_INFRASTRUCTURE *pold_state = &(cur_network->network.InfrastructureMode);
517         u8 ap2sta_mode = _FALSE;
518
519
520
521         if (*pold_state != networktype) {
522                 /* RTW_INFO("change mode, old_mode=%d, new_mode=%d, fw_state=0x%x\n", *pold_state, networktype, get_fwstate(pmlmepriv)); */
523
524                 if (*pold_state == Ndis802_11APMode) {
525                         /* change to other mode from Ndis802_11APMode                    */
526                         cur_network->join_res = -1;
527                         ap2sta_mode = _TRUE;
528 #ifdef CONFIG_NATIVEAP_MLME
529                         stop_ap_mode(padapter);
530 #endif
531                 }
532
533                 _enter_critical_bh(&pmlmepriv->lock, &irqL);
534
535                 if ((check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) || (*pold_state == Ndis802_11IBSS))
536                         rtw_disassoc_cmd(padapter, 0, 0);
537
538                 if ((check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) ||
539                     (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE))
540                         rtw_free_assoc_resources(padapter, 1);
541
542                 if ((*pold_state == Ndis802_11Infrastructure) || (*pold_state == Ndis802_11IBSS)) {
543                         if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
544                                 rtw_indicate_disconnect(padapter, 0, _FALSE); /*will clr Linked_state; before this function, we must have checked whether issue dis-assoc_cmd or not*/
545                         }
546                 }
547
548                 *pold_state = networktype;
549
550                 _clr_fwstate_(pmlmepriv, ~WIFI_NULL_STATE);
551
552                 switch (networktype) {
553                 case Ndis802_11IBSS:
554                         set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
555                         break;
556
557                 case Ndis802_11Infrastructure:
558                         set_fwstate(pmlmepriv, WIFI_STATION_STATE);
559
560                         if (ap2sta_mode)
561                                 rtw_init_bcmc_stainfo(padapter);
562                         break;
563
564                 case Ndis802_11APMode:
565                         set_fwstate(pmlmepriv, WIFI_AP_STATE);
566 #ifdef CONFIG_NATIVEAP_MLME
567                         start_ap_mode(padapter);
568                         /* rtw_indicate_connect(padapter); */
569 #endif
570
571                         break;
572
573                 case Ndis802_11AutoUnknown:
574                 case Ndis802_11InfrastructureMax:
575                         break;
576                 case Ndis802_11Monitor:
577                         set_fwstate(pmlmepriv, WIFI_MONITOR_STATE);
578                         break;
579                 }
580
581                 /* SecClearAllKeys(adapter); */
582
583
584                 _exit_critical_bh(&pmlmepriv->lock, &irqL);
585         }
586
587
588         return _TRUE;
589 }
590
591
592 u8 rtw_set_802_11_disassociate(_adapter *padapter)
593 {
594         _irqL irqL;
595         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
596
597
598         _enter_critical_bh(&pmlmepriv->lock, &irqL);
599
600         if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
601
602                 rtw_disassoc_cmd(padapter, 0, 0);
603                 rtw_indicate_disconnect(padapter, 0, _FALSE);
604                 /* modify for CONFIG_IEEE80211W, none 11w can use it */
605                 rtw_free_assoc_resources_cmd(padapter);
606                 if (_FAIL == rtw_pwr_wakeup(padapter))
607                         RTW_INFO("%s(): rtw_pwr_wakeup fail !!!\n", __FUNCTION__);
608         }
609
610         _exit_critical_bh(&pmlmepriv->lock, &irqL);
611
612
613         return _TRUE;
614 }
615
616 #if 1
617 u8 rtw_set_802_11_bssid_list_scan(_adapter *padapter, NDIS_802_11_SSID *pssid, int ssid_max_num, struct rtw_ieee80211_channel *ch, int ch_num)
618 {
619         _irqL   irqL;
620         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
621         u8      res = _TRUE;
622
623         _enter_critical_bh(&pmlmepriv->lock, &irqL);
624         res = rtw_sitesurvey_cmd(padapter, pssid, ssid_max_num, ch, ch_num);
625         _exit_critical_bh(&pmlmepriv->lock, &irqL);
626
627         return res;
628 }
629
630 #else
631 u8 rtw_set_802_11_bssid_list_scan(_adapter *padapter, NDIS_802_11_SSID *pssid, int ssid_max_num, struct rtw_ieee80211_channel *ch, int ch_num)
632 {
633         _irqL   irqL;
634         struct  mlme_priv               *pmlmepriv = &padapter->mlmepriv;
635         u8      res = _TRUE;
636
637
638
639         if (padapter == NULL) {
640                 res = _FALSE;
641                 goto exit;
642         }
643         if (!rtw_is_hw_init_completed(padapter)) {
644                 res = _FALSE;
645                 goto exit;
646         }
647
648         if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING) == _TRUE) ||
649             (pmlmepriv->LinkDetectInfo.bBusyTraffic == _TRUE)) {
650                 /* Scan or linking is in progress, do nothing. */
651                 res = _TRUE;
652
653
654         } else {
655                 if (rtw_is_scan_deny(padapter)) {
656                         RTW_INFO(FUNC_ADPT_FMT": scan deny\n", FUNC_ADPT_ARG(padapter));
657                         indicate_wx_scan_complete_event(padapter);
658                         return _SUCCESS;
659                 }
660
661                 _enter_critical_bh(&pmlmepriv->lock, &irqL);
662
663                 res = rtw_sitesurvey_cmd(padapter, pssid, ssid_max_num, NULL, 0, ch, ch_num);
664
665                 _exit_critical_bh(&pmlmepriv->lock, &irqL);
666         }
667 exit:
668
669
670         return res;
671 }
672 #endif
673 u8 rtw_set_802_11_authentication_mode(_adapter *padapter, NDIS_802_11_AUTHENTICATION_MODE authmode)
674 {
675         struct security_priv *psecuritypriv = &padapter->securitypriv;
676         int res;
677         u8 ret;
678
679
680
681         psecuritypriv->ndisauthtype = authmode;
682
683
684         if (psecuritypriv->ndisauthtype > 3)
685                 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
686
687 #ifdef CONFIG_WAPI_SUPPORT
688         if (psecuritypriv->ndisauthtype == 6)
689                 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
690 #endif
691
692         res = rtw_set_auth(padapter, psecuritypriv);
693
694         if (res == _SUCCESS)
695                 ret = _TRUE;
696         else
697                 ret = _FALSE;
698
699
700         return ret;
701 }
702
703 u8 rtw_set_802_11_add_wep(_adapter *padapter, NDIS_802_11_WEP *wep)
704 {
705
706         u8              bdefaultkey;
707         u8              btransmitkey;
708         sint            keyid, res;
709         struct security_priv *psecuritypriv = &(padapter->securitypriv);
710         u8              ret = _SUCCESS;
711
712
713         bdefaultkey = (wep->KeyIndex & 0x40000000) > 0 ? _FALSE : _TRUE; /* for ??? */
714         btransmitkey = (wep->KeyIndex & 0x80000000) > 0 ? _TRUE  : _FALSE;      /* for ??? */
715         keyid = wep->KeyIndex & 0x3fffffff;
716
717         if (keyid >= 4) {
718                 ret = _FALSE;
719                 goto exit;
720         }
721
722         switch (wep->KeyLength) {
723         case 5:
724                 psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
725                 break;
726         case 13:
727                 psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
728                 break;
729         default:
730                 psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
731                 break;
732         }
733
734
735         _rtw_memcpy(&(psecuritypriv->dot11DefKey[keyid].skey[0]), &(wep->KeyMaterial), wep->KeyLength);
736
737         psecuritypriv->dot11DefKeylen[keyid] = wep->KeyLength;
738
739         psecuritypriv->dot11PrivacyKeyIndex = keyid;
740
741
742         res = rtw_set_key(padapter, psecuritypriv, keyid, 1, _TRUE);
743
744         if (res == _FAIL)
745                 ret = _FALSE;
746 exit:
747
748
749         return ret;
750
751 }
752
753 u8 rtw_set_802_11_remove_wep(_adapter *padapter, u32 keyindex)
754 {
755
756         u8 ret = _SUCCESS;
757
758
759         if (keyindex >= 0x80000000 || padapter == NULL) {
760
761                 ret = _FALSE;
762                 goto exit;
763
764         } else {
765                 int res;
766                 struct security_priv *psecuritypriv = &(padapter->securitypriv);
767                 if (keyindex < 4) {
768
769                         _rtw_memset(&psecuritypriv->dot11DefKey[keyindex], 0, 16);
770
771                         res = rtw_set_key(padapter, psecuritypriv, keyindex, 0, _TRUE);
772
773                         psecuritypriv->dot11DefKeylen[keyindex] = 0;
774
775                         if (res == _FAIL)
776                                 ret = _FAIL;
777
778                 } else
779                         ret = _FAIL;
780
781         }
782
783 exit:
784
785
786         return ret;
787
788 }
789
790 u8 rtw_set_802_11_add_key(_adapter *padapter, NDIS_802_11_KEY *key)
791 {
792
793         uint    encryptionalgo;
794         u8 *pbssid;
795         struct sta_info *stainfo;
796         u8      bgroup = _FALSE;
797         u8      bgrouptkey = _FALSE;/* can be remove later */
798         u8      ret = _SUCCESS;
799
800
801         if (((key->KeyIndex & 0x80000000) == 0) && ((key->KeyIndex & 0x40000000) > 0)) {
802
803                 /* It is invalid to clear bit 31 and set bit 30. If the miniport driver encounters this combination, */
804                 /* it must fail the request and return NDIS_STATUS_INVALID_DATA. */
805                 ret = _FAIL;
806                 goto exit;
807         }
808
809         if (key->KeyIndex & 0x40000000) {
810                 /* Pairwise key */
811
812
813                 pbssid = get_bssid(&padapter->mlmepriv);
814                 stainfo = rtw_get_stainfo(&padapter->stapriv, pbssid);
815
816                 if ((stainfo != NULL) && (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)) {
817                         encryptionalgo = stainfo->dot118021XPrivacy;
818                 } else {
819                         encryptionalgo = padapter->securitypriv.dot11PrivacyAlgrthm;
820                 }
821
822
823
824
825                 if (key->KeyIndex & 0x000000FF) {
826                         /* The key index is specified in the lower 8 bits by values of zero to 255. */
827                         /* The key index should be set to zero for a Pairwise key, and the driver should fail with */
828                         /* NDIS_STATUS_INVALID_DATA if the lower 8 bits is not zero */
829                         ret = _FAIL;
830                         goto exit;
831                 }
832
833                 /* check BSSID */
834                 if (IS_MAC_ADDRESS_BROADCAST(key->BSSID) == _TRUE) {
835
836                         ret = _FALSE;
837                         goto exit;
838                 }
839
840                 /* Check key length for TKIP. */
841                 /* if(encryptionAlgorithm == RT_ENC_TKIP_ENCRYPTION && key->KeyLength != 32) */
842                 if ((encryptionalgo == _TKIP_) && (key->KeyLength != 32)) {
843                         ret = _FAIL;
844                         goto exit;
845
846                 }
847
848                 /* Check key length for AES. */
849                 if ((encryptionalgo == _AES_) && (key->KeyLength != 16)) {
850                         /* For our supplicant, EAPPkt9x.vxd, cannot differentiate TKIP and AES case. */
851                         if (key->KeyLength == 32)
852                                 key->KeyLength = 16;
853                         else {
854                                 ret = _FAIL;
855                                 goto exit;
856                         }
857                 }
858
859                 /* Check key length for WEP. For NDTEST, 2005.01.27, by rcnjko. -> modify checking condition*/
860                 if (((encryptionalgo == _WEP40_) && (key->KeyLength != 5)) || ((encryptionalgo == _WEP104_) && (key->KeyLength != 13))) {
861                         ret = _FAIL;
862                         goto exit;
863                 }
864
865                 bgroup = _FALSE;
866
867                 /* Check the pairwise key. Added by Annie, 2005-07-06. */
868
869         } else {
870                 /* Group key - KeyIndex(BIT30==0) */
871
872
873                 /* when add wep key through add key and didn't assigned encryption type before */
874                 if ((padapter->securitypriv.ndisauthtype <= 3) && (padapter->securitypriv.dot118021XGrpPrivacy == 0)) {
875
876                         switch (key->KeyLength) {
877                         case 5:
878                                 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
879                                 break;
880                         case 13:
881                                 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
882                                 break;
883                         default:
884                                 padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
885                                 break;
886                         }
887
888                         encryptionalgo = padapter->securitypriv.dot11PrivacyAlgrthm;
889
890
891                 } else {
892                         encryptionalgo = padapter->securitypriv.dot118021XGrpPrivacy;
893
894                 }
895
896                 if ((check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE) == _TRUE) && (IS_MAC_ADDRESS_BROADCAST(key->BSSID) == _FALSE)) {
897                         ret = _FAIL;
898                         goto exit;
899                 }
900
901                 /* Check key length for TKIP */
902                 if ((encryptionalgo == _TKIP_) && (key->KeyLength != 32)) {
903
904                         ret = _FAIL;
905                         goto exit;
906
907                 } else if (encryptionalgo == _AES_ && (key->KeyLength != 16 && key->KeyLength != 32)) {
908
909                         /* Check key length for AES */
910                         /* For NDTEST, we allow keylen=32 in this case. 2005.01.27, by rcnjko. */
911                         ret = _FAIL;
912                         goto exit;
913                 }
914
915                 /* Change the key length for EAPPkt9x.vxd. Added by Annie, 2005-11-03. */
916                 if ((encryptionalgo ==  _AES_) && (key->KeyLength == 32)) {
917                         key->KeyLength = 16;
918                 }
919
920                 if (key->KeyIndex & 0x8000000) /* error ??? 0x8000_0000 */
921                         bgrouptkey = _TRUE;
922
923                 if ((check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE) == _TRUE) && (check_fwstate(&padapter->mlmepriv, _FW_LINKED) == _TRUE))
924                         bgrouptkey = _TRUE;
925
926                 bgroup = _TRUE;
927
928
929         }
930
931         /* If WEP encryption algorithm, just call rtw_set_802_11_add_wep(). */
932         if ((padapter->securitypriv.dot11AuthAlgrthm != dot11AuthAlgrthm_8021X) && (encryptionalgo == _WEP40_  || encryptionalgo == _WEP104_)) {
933                 u8 ret;
934                 u32 keyindex;
935                 u32 len = FIELD_OFFSET(NDIS_802_11_KEY, KeyMaterial) + key->KeyLength;
936                 NDIS_802_11_WEP *wep = &padapter->securitypriv.ndiswep;
937
938
939                 wep->Length = len;
940                 keyindex = key->KeyIndex & 0x7fffffff;
941                 wep->KeyIndex = keyindex ;
942                 wep->KeyLength = key->KeyLength;
943
944
945                 _rtw_memcpy(wep->KeyMaterial, key->KeyMaterial, key->KeyLength);
946                 _rtw_memcpy(&(padapter->securitypriv.dot11DefKey[keyindex].skey[0]), key->KeyMaterial, key->KeyLength);
947
948                 padapter->securitypriv.dot11DefKeylen[keyindex] = key->KeyLength;
949                 padapter->securitypriv.dot11PrivacyKeyIndex = keyindex;
950
951                 ret = rtw_set_802_11_add_wep(padapter, wep);
952
953                 goto exit;
954
955         }
956
957         if (key->KeyIndex & 0x20000000) {
958                 /* SetRSC */
959                 if (bgroup == _TRUE) {
960                         NDIS_802_11_KEY_RSC keysrc = key->KeyRSC & 0x00FFFFFFFFFFFFULL;
961                         _rtw_memcpy(&padapter->securitypriv.dot11Grprxpn, &keysrc, 8);
962                 } else {
963                         NDIS_802_11_KEY_RSC keysrc = key->KeyRSC & 0x00FFFFFFFFFFFFULL;
964                         _rtw_memcpy(&padapter->securitypriv.dot11Grptxpn, &keysrc, 8);
965                 }
966
967         }
968
969         /* Indicate this key idx is used for TX */
970         /* Save the key in KeyMaterial */
971         if (bgroup == _TRUE) { /* Group transmit key */
972                 int res;
973
974                 if (bgrouptkey == _TRUE)
975                         padapter->securitypriv.dot118021XGrpKeyid = (u8)key->KeyIndex;
976
977                 if ((key->KeyIndex & 0x3) == 0) {
978                         ret = _FAIL;
979                         goto exit;
980                 }
981
982                 _rtw_memset(&padapter->securitypriv.dot118021XGrpKey[(u8)((key->KeyIndex) & 0x03)], 0, 16);
983                 _rtw_memset(&padapter->securitypriv.dot118021XGrptxmickey[(u8)((key->KeyIndex) & 0x03)], 0, 16);
984                 _rtw_memset(&padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)], 0, 16);
985
986                 if ((key->KeyIndex & 0x10000000)) {
987                         _rtw_memcpy(&padapter->securitypriv.dot118021XGrptxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 16, 8);
988                         _rtw_memcpy(&padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 24, 8);
989
990
991                 } else {
992                         _rtw_memcpy(&padapter->securitypriv.dot118021XGrptxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 24, 8);
993                         _rtw_memcpy(&padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 16, 8);
994
995
996                 }
997
998                 /* set group key by index */
999                 _rtw_memcpy(&padapter->securitypriv.dot118021XGrpKey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial, key->KeyLength);
1000
1001                 key->KeyIndex = key->KeyIndex & 0x03;
1002
1003                 padapter->securitypriv.binstallGrpkey = _TRUE;
1004
1005                 padapter->securitypriv.bcheck_grpkey = _FALSE;
1006
1007
1008                 res = rtw_set_key(padapter, &padapter->securitypriv, key->KeyIndex, 1, _TRUE);
1009
1010                 if (res == _FAIL)
1011                         ret = _FAIL;
1012
1013                 goto exit;
1014
1015         } else { /* Pairwise Key */
1016                 u8 res;
1017
1018                 pbssid = get_bssid(&padapter->mlmepriv);
1019                 stainfo = rtw_get_stainfo(&padapter->stapriv , pbssid);
1020
1021                 if (stainfo != NULL) {
1022                         _rtw_memset(&stainfo->dot118021x_UncstKey, 0, 16); /* clear keybuffer */
1023
1024                         _rtw_memcpy(&stainfo->dot118021x_UncstKey, key->KeyMaterial, 16);
1025
1026                         if (encryptionalgo == _TKIP_) {
1027                                 padapter->securitypriv.busetkipkey = _FALSE;
1028
1029                                 /* _set_timer(&padapter->securitypriv.tkip_timer, 50); */
1030
1031
1032                                 /* if TKIP, save the Receive/Transmit MIC key in KeyMaterial[128-255] */
1033                                 if ((key->KeyIndex & 0x10000000)) {
1034                                         _rtw_memcpy(&stainfo->dot11tkiptxmickey, key->KeyMaterial + 16, 8);
1035                                         _rtw_memcpy(&stainfo->dot11tkiprxmickey, key->KeyMaterial + 24, 8);
1036
1037                                 } else {
1038                                         _rtw_memcpy(&stainfo->dot11tkiptxmickey, key->KeyMaterial + 24, 8);
1039                                         _rtw_memcpy(&stainfo->dot11tkiprxmickey, key->KeyMaterial + 16, 8);
1040
1041                                 }
1042
1043                         } else if (encryptionalgo == _AES_) {
1044
1045                         }
1046
1047
1048                         /* Set key to CAM through H2C command */
1049 #if 0
1050                         if (bgrouptkey) { /* never go to here */
1051                                 res = rtw_setstakey_cmd(padapter, stainfo, GROUP_KEY, _TRUE);
1052                         } else {
1053                                 res = rtw_setstakey_cmd(padapter, stainfo, UNICAST_KEY, _TRUE);
1054                         }
1055 #else
1056
1057                         res = rtw_setstakey_cmd(padapter, stainfo, UNICAST_KEY, _TRUE);
1058 #endif
1059
1060                         if (res == _FALSE)
1061                                 ret = _FAIL;
1062
1063                 }
1064
1065         }
1066
1067 exit:
1068
1069
1070         return ret;
1071 }
1072
1073 u8 rtw_set_802_11_remove_key(_adapter   *padapter, NDIS_802_11_REMOVE_KEY *key)
1074 {
1075
1076         uint                            encryptionalgo;
1077         u8 *pbssid;
1078         struct sta_info *stainfo;
1079         u8      bgroup = (key->KeyIndex & 0x4000000) > 0 ? _FALSE : _TRUE;
1080         u8      keyIndex = (u8)key->KeyIndex & 0x03;
1081         u8      ret = _SUCCESS;
1082
1083
1084         if ((key->KeyIndex & 0xbffffffc) > 0) {
1085                 ret = _FAIL;
1086                 goto exit;
1087         }
1088
1089         if (bgroup == _TRUE) {
1090                 encryptionalgo = padapter->securitypriv.dot118021XGrpPrivacy;
1091                 /* clear group key by index */
1092                 /* NdisZeroMemory(Adapter->MgntInfo.SecurityInfo.KeyBuf[keyIndex], MAX_WEP_KEY_LEN); */
1093                 /* Adapter->MgntInfo.SecurityInfo.KeyLen[keyIndex] = 0; */
1094
1095                 _rtw_memset(&padapter->securitypriv.dot118021XGrpKey[keyIndex], 0, 16);
1096
1097                 /* ! \todo Send a H2C Command to Firmware for removing this Key in CAM Entry. */
1098
1099         } else {
1100
1101                 pbssid = get_bssid(&padapter->mlmepriv);
1102                 stainfo = rtw_get_stainfo(&padapter->stapriv , pbssid);
1103                 if (stainfo != NULL) {
1104                         encryptionalgo = stainfo->dot118021XPrivacy;
1105
1106                         /* clear key by BSSID */
1107                         _rtw_memset(&stainfo->dot118021x_UncstKey, 0, 16);
1108
1109                         /* ! \todo Send a H2C Command to Firmware for disable this Key in CAM Entry. */
1110
1111                 } else {
1112                         ret = _FAIL;
1113                         goto exit;
1114                 }
1115         }
1116
1117 exit:
1118
1119
1120         return _TRUE;
1121
1122 }
1123
1124 /*
1125 * rtw_get_cur_max_rate -
1126 * @adapter: pointer to _adapter structure
1127 *
1128 * Return 0 or 100Kbps
1129 */
1130 u16 rtw_get_cur_max_rate(_adapter *adapter)
1131 {
1132         int     i = 0;
1133         u16     rate = 0, max_rate = 0;
1134         struct mlme_priv        *pmlmepriv = &adapter->mlmepriv;
1135         WLAN_BSSID_EX   *pcur_bss = &pmlmepriv->cur_network.network;
1136         struct sta_info *psta = NULL;
1137         u8      short_GI = 0;
1138 #ifdef CONFIG_80211N_HT
1139         u8      rf_type = 0;
1140 #endif
1141
1142 #ifdef CONFIG_MP_INCLUDED
1143         if (adapter->registrypriv.mp_mode == 1) {
1144                 if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE)
1145                         return 0;
1146         }
1147 #endif
1148
1149         if ((check_fwstate(pmlmepriv, _FW_LINKED) != _TRUE)
1150             && (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) != _TRUE))
1151                 return 0;
1152
1153         psta = rtw_get_stainfo(&adapter->stapriv, get_bssid(pmlmepriv));
1154         if (psta == NULL)
1155                 return 0;
1156
1157         short_GI = query_ra_short_GI(psta, psta->bw_mode);
1158
1159 #ifdef CONFIG_80211N_HT
1160         if (is_supported_ht(psta->wireless_mode)) {
1161                 rtw_hal_get_hwreg(adapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
1162                 max_rate = rtw_mcs_rate(rf_type
1163                         , (psta->bw_mode == CHANNEL_WIDTH_40) ? 1 : 0
1164                         , short_GI
1165                         , psta->htpriv.ht_cap.supp_mcs_set
1166                 );
1167         }
1168 #ifdef CONFIG_80211AC_VHT
1169         else if (is_supported_vht(psta->wireless_mode))
1170                 max_rate = ((rtw_vht_mcs_to_data_rate(psta->bw_mode, short_GI, pmlmepriv->vhtpriv.vht_highest_rate) + 1) >> 1) * 10;
1171 #endif /* CONFIG_80211AC_VHT */
1172         else
1173 #endif /* CONFIG_80211N_HT */
1174         {
1175                 while ((pcur_bss->SupportedRates[i] != 0) && (pcur_bss->SupportedRates[i] != 0xFF)) {
1176                         rate = pcur_bss->SupportedRates[i] & 0x7F;
1177                         if (rate > max_rate)
1178                                 max_rate = rate;
1179                         i++;
1180                 }
1181
1182                 max_rate = max_rate * 10 / 2;
1183         }
1184
1185         return max_rate;
1186 }
1187
1188 /*
1189 * rtw_set_scan_mode -
1190 * @adapter: pointer to _adapter structure
1191 * @scan_mode:
1192 *
1193 * Return _SUCCESS or _FAIL
1194 */
1195 int rtw_set_scan_mode(_adapter *adapter, RT_SCAN_TYPE scan_mode)
1196 {
1197         if (scan_mode != SCAN_ACTIVE && scan_mode != SCAN_PASSIVE)
1198                 return _FAIL;
1199
1200         adapter->mlmepriv.scan_mode = scan_mode;
1201
1202         return _SUCCESS;
1203 }
1204
1205 /*
1206 * rtw_set_channel_plan -
1207 * @adapter: pointer to _adapter structure
1208 * @channel_plan:
1209 *
1210 * Return _SUCCESS or _FAIL
1211 */
1212 int rtw_set_channel_plan(_adapter *adapter, u8 channel_plan)
1213 {
1214         struct registry_priv *pregistrypriv = &adapter->registrypriv;
1215         struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1216
1217         /* handle by cmd_thread to sync with scan operation */
1218         return rtw_set_chplan_cmd(adapter, RTW_CMDF_WAIT_ACK, channel_plan, 1);
1219 }
1220
1221 /*
1222 * rtw_set_country -
1223 * @adapter: pointer to _adapter structure
1224 * @country_code: string of country code
1225 *
1226 * Return _SUCCESS or _FAIL
1227 */
1228 int rtw_set_country(_adapter *adapter, const char *country_code)
1229 {
1230 #ifdef CONFIG_RTW_IOCTL_SET_COUNTRY
1231         return rtw_set_country_cmd(adapter, RTW_CMDF_WAIT_ACK, country_code, 1);
1232 #else
1233         return _FAIL;
1234 #endif
1235 }
1236
1237 /*
1238 * rtw_set_band -
1239 * @adapter: pointer to _adapter structure
1240 * @band: band to set
1241 *
1242 * Return _SUCCESS or _FAIL
1243 */
1244 int rtw_set_band(_adapter *adapter, u8 band)
1245 {
1246         if (rtw_band_valid(band)) {
1247                 RTW_INFO(FUNC_ADPT_FMT" band:%d\n", FUNC_ADPT_ARG(adapter), band);
1248                 adapter->setband = band;
1249                 return _SUCCESS;
1250         }
1251
1252         RTW_PRINT(FUNC_ADPT_FMT" band:%d fail\n", FUNC_ADPT_ARG(adapter), band);
1253         return _FAIL;
1254 }