rtl8192eu-linux-driver/core/rtw_ioctl_set.c

931 lines
23 KiB
C
Raw Normal View History

/******************************************************************************
*
2019-11-09 10:12:08 +00:00
* Copyright(c) 2007 - 2017 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.
*
2019-11-09 10:12:08 +00:00
*****************************************************************************/
#define _RTW_IOCTL_SET_C_
#include <drv_types.h>
2017-05-11 18:47:23 +00:00
#include <hal_data.h>
extern void indicate_wx_scan_complete_event(_adapter *padapter);
#define IS_MAC_ADDRESS_BROADCAST(addr) \
2019-11-09 10:12:08 +00:00
(\
((addr[0] == 0xff) && (addr[1] == 0xff) && \
(addr[2] == 0xff) && (addr[3] == 0xff) && \
(addr[4] == 0xff) && (addr[5] == 0xff)) ? _TRUE : _FALSE \
)
u8 rtw_validate_bssid(u8 *bssid)
{
u8 ret = _TRUE;
if (is_zero_mac_addr(bssid)
2019-11-09 10:12:08 +00:00
|| is_broadcast_mac_addr(bssid)
|| is_multicast_mac_addr(bssid)
)
ret = _FALSE;
return ret;
}
u8 rtw_validate_ssid(NDIS_802_11_SSID *ssid)
{
2019-11-09 10:12:08 +00:00
#ifdef CONFIG_VALIDATE_SSID
u8 i;
2019-11-09 10:12:08 +00:00
#endif
u8 ret = _TRUE;
if (ssid->SsidLength > 32) {
2019-11-09 10:12:08 +00:00
ret = _FALSE;
goto exit;
}
#ifdef CONFIG_VALIDATE_SSID
2019-11-09 10:12:08 +00:00
for (i = 0; i < ssid->SsidLength; i++) {
/* wifi, printable ascii code must be supported */
if (!((ssid->Ssid[i] >= 0x20) && (ssid->Ssid[i] <= 0x7e))) {
ret = _FALSE;
break;
}
}
#endif /* CONFIG_VALIDATE_SSID */
2019-11-09 10:12:08 +00:00
exit:
return ret;
}
2019-11-09 10:12:08 +00:00
u8 rtw_do_join(_adapter *padapter);
u8 rtw_do_join(_adapter *padapter)
{
_irqL irqL;
_list *plist, *phead;
2019-11-09 10:12:08 +00:00
u8 *pibss = NULL;
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2019-11-09 10:12:08 +00:00
struct sitesurvey_parm parm;
_queue *queue = &(pmlmepriv->scanned_queue);
2019-11-09 10:12:08 +00:00
u8 ret = _SUCCESS;
_enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
phead = get_list_head(queue);
plist = get_next(phead);
pmlmepriv->cur_network.join_res = -2;
2019-11-09 10:12:08 +00:00
set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
pmlmepriv->pscanned = plist;
pmlmepriv->to_join = _TRUE;
2019-11-09 10:12:08 +00:00
rtw_init_sitesurvey_parm(padapter, &parm);
_rtw_memcpy(&parm.ssid[0], &pmlmepriv->assoc_ssid, sizeof(NDIS_802_11_SSID));
parm.ssid_num = 1;
if (_rtw_queue_empty(queue) == _TRUE) {
_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
_clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
2019-11-09 10:12:08 +00:00
/* when set_ssid/set_bssid for rtw_do_join(), but scanning queue is empty */
/* we try to issue sitesurvey firstly */
if (pmlmepriv->LinkDetectInfo.bBusyTraffic == _FALSE
|| rtw_to_roam(padapter) > 0
) {
u8 ssc_chk = rtw_sitesurvey_condition_check(padapter, _FALSE);
if ((ssc_chk == SS_ALLOW) || (ssc_chk == SS_DENY_BUSY_TRAFFIC) ){
/* submit site_survey_cmd */
ret = rtw_sitesurvey_cmd(padapter, &parm);
if (_SUCCESS != ret)
pmlmepriv->to_join = _FALSE;
} else {
/*if (ssc_chk == SS_DENY_BUDDY_UNDER_SURVEY)*/
pmlmepriv->to_join = _FALSE;
2019-11-09 10:12:08 +00:00
ret = _FAIL;
}
2019-11-09 10:12:08 +00:00
} else {
pmlmepriv->to_join = _FALSE;
ret = _FAIL;
}
2019-11-09 10:12:08 +00:00
goto exit;
2019-11-09 10:12:08 +00:00
} else {
int select_ret;
_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
2019-11-09 10:12:08 +00:00
select_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv);
if (select_ret == _SUCCESS) {
pmlmepriv->to_join = _FALSE;
_set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT);
2019-11-09 10:12:08 +00:00
} else {
if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE) {
/* submit createbss_cmd to change to a ADHOC_MASTER */
2019-11-09 10:12:08 +00:00
/* pmlmepriv->lock has been acquired by caller... */
WLAN_BSSID_EX *pdev_network = &(padapter->registrypriv.dev_network);
2019-11-09 10:12:08 +00:00
/*pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;*/
init_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
pibss = padapter->registrypriv.dev_network.MacAddress;
_rtw_memset(&pdev_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
_rtw_memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(NDIS_802_11_SSID));
2019-11-09 10:12:08 +00:00
rtw_update_registrypriv_dev_network(padapter);
rtw_generate_random_ibss(pibss);
2019-11-09 10:12:08 +00:00
2017-05-11 18:47:23 +00:00
if (rtw_create_ibss_cmd(padapter, 0) != _SUCCESS) {
ret = _FALSE;
goto exit;
}
2019-11-09 10:12:08 +00:00
pmlmepriv->to_join = _FALSE;
2019-11-09 10:12:08 +00:00
} else {
/* can't associate ; reset under-linking */
_clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
2019-11-09 10:12:08 +00:00
/* when set_ssid/set_bssid for rtw_do_join(), but there are no desired bss in scanning queue */
/* we try to issue sitesurvey firstly */
if (pmlmepriv->LinkDetectInfo.bBusyTraffic == _FALSE
|| rtw_to_roam(padapter) > 0
) {
u8 ssc_chk = rtw_sitesurvey_condition_check(padapter, _FALSE);
if ((ssc_chk == SS_ALLOW) || (ssc_chk == SS_DENY_BUSY_TRAFFIC)){
/* RTW_INFO(("rtw_do_join() when no desired bss in scanning queue\n"); */
ret = rtw_sitesurvey_cmd(padapter, &parm);
if (_SUCCESS != ret)
pmlmepriv->to_join = _FALSE;
} else {
/*if (ssc_chk == SS_DENY_BUDDY_UNDER_SURVEY) {
} else {*/
ret = _FAIL;
pmlmepriv->to_join = _FALSE;
}
2019-11-09 10:12:08 +00:00
} else {
ret = _FAIL;
pmlmepriv->to_join = _FALSE;
}
}
}
}
2019-11-09 10:12:08 +00:00
exit:
2019-11-09 10:12:08 +00:00
return ret;
}
#ifdef PLATFORM_WINDOWS
2019-11-09 10:12:08 +00:00
u8 rtw_pnp_set_power_wakeup(_adapter *padapter)
{
2019-11-09 10:12:08 +00:00
u8 res = _SUCCESS;
res = rtw_setstandby_cmd(padapter, 0);
2019-11-09 10:12:08 +00:00
return res;
}
2019-11-09 10:12:08 +00:00
u8 rtw_pnp_set_power_sleep(_adapter *padapter)
{
2019-11-09 10:12:08 +00:00
u8 res = _SUCCESS;
2019-11-09 10:12:08 +00:00
/* DbgPrint("+rtw_pnp_set_power_sleep\n"); */
res = rtw_setstandby_cmd(padapter, 1);
return res;
}
2019-11-09 10:12:08 +00:00
u8 rtw_set_802_11_reload_defaults(_adapter *padapter, NDIS_802_11_RELOAD_DEFAULTS reloadDefaults)
{
2019-11-09 10:12:08 +00:00
/* SecClearAllKeys(Adapter); */
/* 8711 CAM was not for En/Decrypt only */
/* so, we can't clear all keys. */
/* should we disable WPAcfg (ox0088) bit 1-2, instead of clear all CAM */
/* TO DO... */
return _TRUE;
}
2019-11-09 10:12:08 +00:00
u8 set_802_11_test(_adapter *padapter, NDIS_802_11_TEST *test)
{
2019-11-09 10:12:08 +00:00
u8 ret = _TRUE;
2019-11-09 10:12:08 +00:00
switch (test->Type) {
case 1:
NdisMIndicateStatus(padapter->hndis_adapter, NDIS_STATUS_MEDIA_SPECIFIC_INDICATION, (PVOID)&test->AuthenticationEvent, test->Length - 8);
NdisMIndicateStatusComplete(padapter->hndis_adapter);
break;
2019-11-09 10:12:08 +00:00
case 2:
NdisMIndicateStatus(padapter->hndis_adapter, NDIS_STATUS_MEDIA_SPECIFIC_INDICATION, (PVOID)&test->RssiTrigger, sizeof(NDIS_802_11_RSSI));
NdisMIndicateStatusComplete(padapter->hndis_adapter);
break;
default:
ret = _FALSE;
break;
}
2019-11-09 10:12:08 +00:00
return ret;
}
2019-11-09 10:12:08 +00:00
u8 rtw_set_802_11_pmkid(_adapter *padapter, NDIS_802_11_PMKID *pmkid)
{
2019-11-09 10:12:08 +00:00
u8 ret = _SUCCESS;
return ret;
}
#endif
2019-11-09 10:12:08 +00:00
u8 rtw_set_802_11_bssid(_adapter *padapter, u8 *bssid)
{
_irqL irqL;
u8 status = _SUCCESS;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2019-11-09 10:12:08 +00:00
RTW_PRINT("set bssid:%pM\n", bssid);
if ((bssid[0] == 0x00 && bssid[1] == 0x00 && bssid[2] == 0x00 && bssid[3] == 0x00 && bssid[4] == 0x00 && bssid[5] == 0x00) ||
(bssid[0] == 0xFF && bssid[1] == 0xFF && bssid[2] == 0xFF && bssid[3] == 0xFF && bssid[4] == 0xFF && bssid[5] == 0xFF)) {
status = _FAIL;
goto exit;
}
2019-11-09 10:12:08 +00:00
_enter_critical_bh(&pmlmepriv->lock, &irqL);
2019-11-09 10:12:08 +00:00
RTW_INFO("Set BSSID under fw_state=0x%08x\n", get_fwstate(pmlmepriv));
if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
goto handle_tkip_countermeasure;
2019-11-09 10:12:08 +00:00
else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE)
goto release_mlme_lock;
2019-11-09 10:12:08 +00:00
if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE) == _TRUE) {
2019-11-09 10:12:08 +00:00
if (_rtw_memcmp(&pmlmepriv->cur_network.network.MacAddress, bssid, ETH_ALEN) == _TRUE) {
if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _FALSE)
2019-11-09 10:12:08 +00:00
goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */
} else {
2019-11-09 10:12:08 +00:00
rtw_disassoc_cmd(padapter, 0, 0);
if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
2017-05-11 18:47:23 +00:00
rtw_indicate_disconnect(padapter, 0, _FALSE);
2019-11-09 10:12:08 +00:00
rtw_free_assoc_resources_cmd(padapter, _TRUE, 0);
if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE)) {
_clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
2019-11-09 10:12:08 +00:00
}
}
}
handle_tkip_countermeasure:
if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) {
status = _FAIL;
goto release_mlme_lock;
}
_rtw_memset(&pmlmepriv->assoc_ssid, 0, sizeof(NDIS_802_11_SSID));
_rtw_memcpy(&pmlmepriv->assoc_bssid, bssid, ETH_ALEN);
2019-11-09 10:12:08 +00:00
pmlmepriv->assoc_by_bssid = _TRUE;
2019-11-09 10:12:08 +00:00
if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
pmlmepriv->to_join = _TRUE;
else
status = rtw_do_join(padapter);
release_mlme_lock:
_exit_critical_bh(&pmlmepriv->lock, &irqL);
2019-11-09 10:12:08 +00:00
exit:
2019-11-09 10:12:08 +00:00
return status;
}
2019-11-09 10:12:08 +00:00
u8 rtw_set_802_11_ssid(_adapter *padapter, NDIS_802_11_SSID *ssid)
{
_irqL irqL;
u8 status = _SUCCESS;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
struct wlan_network *pnetwork = &pmlmepriv->cur_network;
2019-11-09 10:12:08 +00:00
RTW_PRINT("set ssid [%s] fw_state=0x%08x\n",
ssid->Ssid, get_fwstate(pmlmepriv));
2017-05-11 18:47:23 +00:00
if (!rtw_is_hw_init_completed(padapter)) {
status = _FAIL;
goto exit;
}
2019-11-09 10:12:08 +00:00
_enter_critical_bh(&pmlmepriv->lock, &irqL);
2019-11-09 10:12:08 +00:00
RTW_INFO("Set SSID under fw_state=0x%08x\n", get_fwstate(pmlmepriv));
if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
goto handle_tkip_countermeasure;
2019-11-09 10:12:08 +00:00
else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE)
goto release_mlme_lock;
2019-11-09 10:12:08 +00:00
if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE) == _TRUE) {
if ((pmlmepriv->assoc_ssid.SsidLength == ssid->SsidLength) &&
2019-11-09 10:12:08 +00:00
(_rtw_memcmp(&pmlmepriv->assoc_ssid.Ssid, ssid->Ssid, ssid->SsidLength) == _TRUE)) {
if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _FALSE)) {
if (rtw_is_same_ibss(padapter, pnetwork) == _FALSE) {
/* if in WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE, create bss or rejoin again */
rtw_disassoc_cmd(padapter, 0, 0);
if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
2017-05-11 18:47:23 +00:00
rtw_indicate_disconnect(padapter, 0, _FALSE);
2019-11-09 10:12:08 +00:00
rtw_free_assoc_resources_cmd(padapter, _TRUE, 0);
if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) {
_clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
}
2019-11-09 10:12:08 +00:00
} else {
goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */
}
}
#ifdef CONFIG_LPS
2019-11-09 10:12:08 +00:00
else
rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_JOINBSS, 0);
#endif
2019-11-09 10:12:08 +00:00
} else {
2019-11-09 10:12:08 +00:00
rtw_disassoc_cmd(padapter, 0, 0);
if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
2017-05-11 18:47:23 +00:00
rtw_indicate_disconnect(padapter, 0, _FALSE);
2019-11-09 10:12:08 +00:00
rtw_free_assoc_resources_cmd(padapter, _TRUE, 0);
if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) {
_clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
}
2019-11-09 10:12:08 +00:00
}
}
handle_tkip_countermeasure:
if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) {
status = _FAIL;
goto release_mlme_lock;
}
if (rtw_validate_ssid(ssid) == _FALSE) {
status = _FAIL;
goto release_mlme_lock;
}
_rtw_memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(NDIS_802_11_SSID));
2019-11-09 10:12:08 +00:00
pmlmepriv->assoc_by_bssid = _FALSE;
2019-11-09 10:12:08 +00:00
if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
pmlmepriv->to_join = _TRUE;
else
status = rtw_do_join(padapter);
release_mlme_lock:
_exit_critical_bh(&pmlmepriv->lock, &irqL);
exit:
2019-11-09 10:12:08 +00:00
return status;
2019-11-09 10:12:08 +00:00
}
2019-11-09 10:12:08 +00:00
u8 rtw_set_802_11_connect(_adapter *padapter, u8 *bssid, NDIS_802_11_SSID *ssid)
{
_irqL irqL;
u8 status = _SUCCESS;
bool bssid_valid = _TRUE;
bool ssid_valid = _TRUE;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
if (!ssid || rtw_validate_ssid(ssid) == _FALSE)
ssid_valid = _FALSE;
if (!bssid || rtw_validate_bssid(bssid) == _FALSE)
bssid_valid = _FALSE;
if (ssid_valid == _FALSE && bssid_valid == _FALSE) {
2019-11-09 10:12:08 +00:00
RTW_INFO(FUNC_ADPT_FMT" ssid:%p, ssid_valid:%d, bssid:%p, bssid_valid:%d\n",
FUNC_ADPT_ARG(padapter), ssid, ssid_valid, bssid, bssid_valid);
status = _FAIL;
goto exit;
}
2017-05-11 18:47:23 +00:00
if (!rtw_is_hw_init_completed(padapter)) {
status = _FAIL;
goto exit;
}
_enter_critical_bh(&pmlmepriv->lock, &irqL);
2019-11-09 10:12:08 +00:00
RTW_PRINT(FUNC_ADPT_FMT" fw_state=0x%08x\n",
FUNC_ADPT_ARG(padapter), get_fwstate(pmlmepriv));
2019-11-09 10:12:08 +00:00
if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
goto handle_tkip_countermeasure;
2019-11-09 10:12:08 +00:00
else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE)
goto release_mlme_lock;
handle_tkip_countermeasure:
if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) {
status = _FAIL;
goto release_mlme_lock;
}
if (ssid && ssid_valid)
_rtw_memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(NDIS_802_11_SSID));
else
_rtw_memset(&pmlmepriv->assoc_ssid, 0, sizeof(NDIS_802_11_SSID));
if (bssid && bssid_valid) {
_rtw_memcpy(&pmlmepriv->assoc_bssid, bssid, ETH_ALEN);
pmlmepriv->assoc_by_bssid = _TRUE;
2019-11-09 10:12:08 +00:00
} else
pmlmepriv->assoc_by_bssid = _FALSE;
2019-11-09 10:12:08 +00:00
if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE)
pmlmepriv->to_join = _TRUE;
else
status = rtw_do_join(padapter);
release_mlme_lock:
_exit_critical_bh(&pmlmepriv->lock, &irqL);
exit:
2019-11-09 10:12:08 +00:00
return status;
}
2019-11-09 10:12:08 +00:00
u8 rtw_set_802_11_infrastructure_mode(_adapter *padapter,
NDIS_802_11_NETWORK_INFRASTRUCTURE networktype, u8 flags)
{
_irqL irqL;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
struct wlan_network *cur_network = &pmlmepriv->cur_network;
2019-11-09 10:12:08 +00:00
NDIS_802_11_NETWORK_INFRASTRUCTURE *pold_state = &(cur_network->network.InfrastructureMode);
u8 ap2sta_mode = _FALSE;
u8 ret = _TRUE;
u8 is_linked = _FALSE, is_adhoc_master = _FALSE;
if (*pold_state != networktype) {
/* RTW_INFO("change mode, old_mode=%d, new_mode=%d, fw_state=0x%x\n", *pold_state, networktype, get_fwstate(pmlmepriv)); */
2019-11-09 10:12:08 +00:00
if (*pold_state == Ndis802_11APMode
|| *pold_state == Ndis802_11_mesh
) {
/* change to other mode from Ndis802_11APMode/Ndis802_11_mesh */
cur_network->join_res = -1;
2019-11-09 10:12:08 +00:00
ap2sta_mode = _TRUE;
#ifdef CONFIG_NATIVEAP_MLME
stop_ap_mode(padapter);
#endif
}
_enter_critical_bh(&pmlmepriv->lock, &irqL);
2019-11-09 10:12:08 +00:00
is_linked = check_fwstate(pmlmepriv, _FW_LINKED);
is_adhoc_master = check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
/* flags = 0, means enqueue cmd and no wait */
if (flags != 0)
_exit_critical_bh(&pmlmepriv->lock, &irqL);
if ((is_linked == _TRUE) || (*pold_state == Ndis802_11IBSS))
rtw_disassoc_cmd(padapter, 0, flags);
if ((is_linked == _TRUE) ||
(is_adhoc_master == _TRUE))
rtw_free_assoc_resources_cmd(padapter, _TRUE, flags);
if ((*pold_state == Ndis802_11Infrastructure) || (*pold_state == Ndis802_11IBSS)) {
if (is_linked == _TRUE) {
2017-05-11 18:47:23 +00:00
rtw_indicate_disconnect(padapter, 0, _FALSE); /*will clr Linked_state; before this function, we must have checked whether issue dis-assoc_cmd or not*/
}
2019-11-09 10:12:08 +00:00
}
/* flags = 0, means enqueue cmd and no wait */
if (flags != 0)
_enter_critical_bh(&pmlmepriv->lock, &irqL);
*pold_state = networktype;
_clr_fwstate_(pmlmepriv, ~WIFI_NULL_STATE);
2019-11-09 10:12:08 +00:00
switch (networktype) {
case Ndis802_11IBSS:
set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
break;
case Ndis802_11Infrastructure:
set_fwstate(pmlmepriv, WIFI_STATION_STATE);
if (ap2sta_mode)
rtw_init_bcmc_stainfo(padapter);
break;
case Ndis802_11APMode:
set_fwstate(pmlmepriv, WIFI_AP_STATE);
#ifdef CONFIG_NATIVEAP_MLME
2019-11-09 10:12:08 +00:00
start_ap_mode(padapter);
/* rtw_indicate_connect(padapter); */
#endif
break;
#ifdef CONFIG_RTW_MESH
case Ndis802_11_mesh:
set_fwstate(pmlmepriv, WIFI_MESH_STATE);
start_ap_mode(padapter);
break;
#endif
case Ndis802_11AutoUnknown:
case Ndis802_11InfrastructureMax:
break;
case Ndis802_11Monitor:
set_fwstate(pmlmepriv, WIFI_MONITOR_STATE);
break;
default:
ret = _FALSE;
rtw_warn_on(1);
}
2019-11-09 10:12:08 +00:00
/* SecClearAllKeys(adapter); */
_exit_critical_bh(&pmlmepriv->lock, &irqL);
}
2019-11-09 10:12:08 +00:00
return ret;
}
u8 rtw_set_802_11_disassociate(_adapter *padapter)
{
_irqL irqL;
2019-11-09 10:12:08 +00:00
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
_enter_critical_bh(&pmlmepriv->lock, &irqL);
2019-11-09 10:12:08 +00:00
if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
2019-11-09 10:12:08 +00:00
rtw_disassoc_cmd(padapter, 0, 0);
2017-05-11 18:47:23 +00:00
rtw_indicate_disconnect(padapter, 0, _FALSE);
2019-11-09 10:12:08 +00:00
/* modify for CONFIG_IEEE80211W, none 11w can use it */
rtw_free_assoc_resources_cmd(padapter, _TRUE, 0);
if (_FAIL == rtw_pwr_wakeup(padapter))
2019-11-09 10:12:08 +00:00
RTW_INFO("%s(): rtw_pwr_wakeup fail !!!\n", __FUNCTION__);
}
_exit_critical_bh(&pmlmepriv->lock, &irqL);
2019-11-09 10:12:08 +00:00
return _TRUE;
}
#if 1
u8 rtw_set_802_11_bssid_list_scan(_adapter *padapter, struct sitesurvey_parm *pparm)
{
_irqL irqL;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
u8 res = _TRUE;
_enter_critical_bh(&pmlmepriv->lock, &irqL);
res = rtw_sitesurvey_cmd(padapter, pparm);
_exit_critical_bh(&pmlmepriv->lock, &irqL);
return res;
}
2019-11-09 10:12:08 +00:00
#else
u8 rtw_set_802_11_bssid_list_scan(_adapter *padapter, struct sitesurvey_parm *pparm)
{
_irqL irqL;
2019-11-09 10:12:08 +00:00
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
u8 res = _TRUE;
if (padapter == NULL) {
2019-11-09 10:12:08 +00:00
res = _FALSE;
goto exit;
}
2017-05-11 18:47:23 +00:00
if (!rtw_is_hw_init_completed(padapter)) {
res = _FALSE;
goto exit;
}
2019-11-09 10:12:08 +00:00
if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING) == _TRUE) ||
(pmlmepriv->LinkDetectInfo.bBusyTraffic == _TRUE)) {
/* Scan or linking is in progress, do nothing. */
res = _TRUE;
2019-11-09 10:12:08 +00:00
} else {
if (rtw_is_scan_deny(padapter)) {
2019-11-09 10:12:08 +00:00
RTW_INFO(FUNC_ADPT_FMT": scan deny\n", FUNC_ADPT_ARG(padapter));
indicate_wx_scan_complete_event(padapter);
return _SUCCESS;
}
2019-11-09 10:12:08 +00:00
_enter_critical_bh(&pmlmepriv->lock, &irqL);
res = rtw_sitesurvey_cmd(padapter, pparm);
_exit_critical_bh(&pmlmepriv->lock, &irqL);
}
exit:
2019-11-09 10:12:08 +00:00
return res;
}
#endif
u8 rtw_set_802_11_authentication_mode(_adapter *padapter, NDIS_802_11_AUTHENTICATION_MODE authmode)
{
struct security_priv *psecuritypriv = &padapter->securitypriv;
int res;
u8 ret;
2019-11-09 10:12:08 +00:00
psecuritypriv->ndisauthtype = authmode;
2019-11-09 10:12:08 +00:00
if (psecuritypriv->ndisauthtype > 3)
psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
2019-11-09 10:12:08 +00:00
#ifdef CONFIG_WAPI_SUPPORT
if (psecuritypriv->ndisauthtype == 6)
psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
#endif
2019-11-09 10:12:08 +00:00
res = rtw_set_auth(padapter, psecuritypriv);
2019-11-09 10:12:08 +00:00
if (res == _SUCCESS)
ret = _TRUE;
else
ret = _FALSE;
return ret;
}
2019-11-09 10:12:08 +00:00
u8 rtw_set_802_11_add_wep(_adapter *padapter, NDIS_802_11_WEP *wep)
{
2019-11-09 10:12:08 +00:00
u8 bdefaultkey;
u8 btransmitkey;
sint keyid, res;
struct security_priv *psecuritypriv = &(padapter->securitypriv);
u8 ret = _SUCCESS;
2019-11-09 10:12:08 +00:00
bdefaultkey = (wep->KeyIndex & 0x40000000) > 0 ? _FALSE : _TRUE; /* for ??? */
btransmitkey = (wep->KeyIndex & 0x80000000) > 0 ? _TRUE : _FALSE; /* for ??? */
keyid = wep->KeyIndex & 0x3fffffff;
2019-11-09 10:12:08 +00:00
if (keyid >= 4) {
ret = _FALSE;
goto exit;
}
2019-11-09 10:12:08 +00:00
switch (wep->KeyLength) {
case 5:
psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
break;
case 13:
psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
break;
default:
psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
break;
}
2019-11-09 10:12:08 +00:00
_rtw_memcpy(&(psecuritypriv->dot11DefKey[keyid].skey[0]), &(wep->KeyMaterial), wep->KeyLength);
2019-11-09 10:12:08 +00:00
psecuritypriv->dot11DefKeylen[keyid] = wep->KeyLength;
2019-11-09 10:12:08 +00:00
psecuritypriv->dot11PrivacyKeyIndex = keyid;
2019-11-09 10:12:08 +00:00
res = rtw_set_key(padapter, psecuritypriv, keyid, 1, _TRUE);
2019-11-09 10:12:08 +00:00
if (res == _FAIL)
ret = _FALSE;
exit:
2019-11-09 10:12:08 +00:00
return ret;
}
/*
2019-11-09 10:12:08 +00:00
* rtw_get_cur_max_rate -
* @adapter: pointer to _adapter structure
2019-11-09 10:12:08 +00:00
*
* Return 0 or 100Kbps
*/
u16 rtw_get_cur_max_rate(_adapter *adapter)
{
2019-11-09 10:12:08 +00:00
int j;
int i = 0;
u16 rate = 0, max_rate = 0;
struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
WLAN_BSSID_EX *pcur_bss = &pmlmepriv->cur_network.network;
2019-11-09 10:12:08 +00:00
int sta_bssrate_len = 0;
unsigned char sta_bssrate[NumRates];
struct sta_info *psta = NULL;
2019-11-09 10:12:08 +00:00
u8 short_GI = 0;
#ifdef CONFIG_80211N_HT
u8 rf_type = 0;
#endif
#ifdef CONFIG_MP_INCLUDED
2019-11-09 10:12:08 +00:00
if (adapter->registrypriv.mp_mode == 1) {
if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE)
return 0;
}
#endif
2019-11-09 10:12:08 +00:00
if ((check_fwstate(pmlmepriv, _FW_LINKED) != _TRUE)
&& (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) != _TRUE))
return 0;
psta = rtw_get_stainfo(&adapter->stapriv, get_bssid(pmlmepriv));
if (psta == NULL)
return 0;
2019-11-09 10:12:08 +00:00
short_GI = query_ra_short_GI(psta, rtw_get_tx_bw_mode(adapter, psta));
#ifdef CONFIG_80211N_HT
2019-11-09 10:12:08 +00:00
if (is_supported_ht(psta->wireless_mode)) {
rtw_hal_get_hwreg(adapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
2019-11-09 10:12:08 +00:00
max_rate = rtw_mcs_rate(rf_type
, (psta->cmn.bw_mode == CHANNEL_WIDTH_40) ? 1 : 0
, short_GI
, psta->htpriv.ht_cap.supp_mcs_set
);
}
#ifdef CONFIG_80211AC_VHT
2019-11-09 10:12:08 +00:00
else if (is_supported_vht(psta->wireless_mode))
max_rate = ((rtw_vht_mcs_to_data_rate(psta->cmn.bw_mode, short_GI, pmlmepriv->vhtpriv.vht_highest_rate) + 1) >> 1) * 10;
#endif /* CONFIG_80211AC_VHT */
else
#endif /* CONFIG_80211N_HT */
{
2019-11-09 10:12:08 +00:00
/*station mode show :station && ap support rate; softap :show ap support rate*/
if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)
get_rate_set(adapter, sta_bssrate, &sta_bssrate_len);/*get sta rate and length*/
while ((pcur_bss->SupportedRates[i] != 0) && (pcur_bss->SupportedRates[i] != 0xFF)) {
rate = pcur_bss->SupportedRates[i] & 0x7F;/*AP support rates*/
/*RTW_INFO("%s rate=%02X \n", __func__, rate);*/
/*check STA support rate or not */
if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE) {
for (j = 0; j < sta_bssrate_len; j++) {
/* Avoid the proprietary data rate (22Mbps) of Handlink WSG-4000 AP */
if ((rate | IEEE80211_BASIC_RATE_MASK)
== (sta_bssrate[j] | IEEE80211_BASIC_RATE_MASK)) {
if (rate > max_rate) {
max_rate = rate;
}
break;
}
}
} else {
if (rate > max_rate)
max_rate = rate;
}
i++;
}
2019-11-09 10:12:08 +00:00
max_rate = max_rate * 10 / 2;
}
return max_rate;
}
/*
2019-11-09 10:12:08 +00:00
* rtw_set_scan_mode -
* @adapter: pointer to _adapter structure
2019-11-09 10:12:08 +00:00
* @scan_mode:
*
* Return _SUCCESS or _FAIL
*/
int rtw_set_scan_mode(_adapter *adapter, RT_SCAN_TYPE scan_mode)
{
2019-11-09 10:12:08 +00:00
if (scan_mode != SCAN_ACTIVE && scan_mode != SCAN_PASSIVE)
return _FAIL;
2019-11-09 10:12:08 +00:00
adapter->mlmepriv.scan_mode = scan_mode;
return _SUCCESS;
}
/*
2019-11-09 10:12:08 +00:00
* rtw_set_channel_plan -
* @adapter: pointer to _adapter structure
2019-11-09 10:12:08 +00:00
* @channel_plan:
*
* Return _SUCCESS or _FAIL
*/
int rtw_set_channel_plan(_adapter *adapter, u8 channel_plan)
{
2019-11-09 10:12:08 +00:00
/* handle by cmd_thread to sync with scan operation */
2017-05-11 18:47:23 +00:00
return rtw_set_chplan_cmd(adapter, RTW_CMDF_WAIT_ACK, channel_plan, 1);
}
/*
2019-11-09 10:12:08 +00:00
* rtw_set_country -
* @adapter: pointer to _adapter structure
* @country_code: string of country code
2019-11-09 10:12:08 +00:00
*
* Return _SUCCESS or _FAIL
*/
int rtw_set_country(_adapter *adapter, const char *country_code)
{
2017-05-11 18:47:23 +00:00
#ifdef CONFIG_RTW_IOCTL_SET_COUNTRY
return rtw_set_country_cmd(adapter, RTW_CMDF_WAIT_ACK, country_code, 1);
#else
2019-11-09 10:12:08 +00:00
RTW_INFO("%s(): not applied\n", __func__);
return _SUCCESS;
2017-05-11 18:47:23 +00:00
#endif
}
/*
2019-11-09 10:12:08 +00:00
* rtw_set_band -
* @adapter: pointer to _adapter structure
* @band: band to set
2019-11-09 10:12:08 +00:00
*
* Return _SUCCESS or _FAIL
*/
2017-05-11 18:47:23 +00:00
int rtw_set_band(_adapter *adapter, u8 band)
{
if (rtw_band_valid(band)) {
2019-11-09 10:12:08 +00:00
RTW_INFO(FUNC_ADPT_FMT" band:%d\n", FUNC_ADPT_ARG(adapter), band);
adapter->setband = band;
return _SUCCESS;
}
2019-11-09 10:12:08 +00:00
RTW_PRINT(FUNC_ADPT_FMT" band:%d fail\n", FUNC_ADPT_ARG(adapter), band);
return _FAIL;
}