lkml.org 
[lkml]   [2021]   [Jul]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/7] staging: rtl8188eu: introduce new core dir for RTL8188eu driver
Date
This patchset is split in order to keep the file sizes down. This core
directory is part of the newer/better driver from GitHub modified by
Larry Finger. Import this as the basis for all future work going
forward.

Suggested-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Phillip Potter <phil@philpotter.co.uk>
---
drivers/staging/rtl8188eu/core/rtw_ap.c | 3778 ++++
.../staging/rtl8188eu/core/rtw_beamforming.c | 3071 ++++
drivers/staging/rtl8188eu/core/rtw_br_ext.c | 1529 ++
drivers/staging/rtl8188eu/core/rtw_btcoex.c | 1632 ++
.../rtl8188eu/core/rtw_btcoex_wifionly.c | 26 +
drivers/staging/rtl8188eu/core/rtw_cmd.c | 4433 +++++
drivers/staging/rtl8188eu/core/rtw_debug.c | 4800 +++++
drivers/staging/rtl8188eu/core/rtw_efuse.c | 1523 ++
.../staging/rtl8188eu/core/rtw_ieee80211.c | 2673 +++
drivers/staging/rtl8188eu/core/rtw_io.c | 473 +
.../staging/rtl8188eu/core/rtw_ioctl_query.c | 6 +
.../staging/rtl8188eu/core/rtw_ioctl_set.c | 1035 ++
drivers/staging/rtl8188eu/core/rtw_iol.c | 355 +
drivers/staging/rtl8188eu/core/rtw_led.c | 1705 ++
drivers/staging/rtl8188eu/core/rtw_mi.c | 1198 ++
drivers/staging/rtl8188eu/core/rtw_mlme.c | 4401 +++++
drivers/staging/rtl8188eu/core/rtw_mlme_ext.c | 15277 ++++++++++++++++
drivers/staging/rtl8188eu/core/rtw_mp.c | 2620 +++
drivers/staging/rtl8188eu/core/rtw_odm.c | 430 +
drivers/staging/rtl8188eu/core/rtw_p2p.c | 5351 ++++++
drivers/staging/rtl8188eu/core/rtw_pwrctrl.c | 2480 +++
drivers/staging/rtl8188eu/core/rtw_recv.c | 4191 +++++
drivers/staging/rtl8188eu/core/rtw_rf.c | 1077 ++
drivers/staging/rtl8188eu/core/rtw_security.c | 3127 ++++
drivers/staging/rtl8188eu/core/rtw_sreset.c | 291 +
drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 1096 ++
drivers/staging/rtl8188eu/core/rtw_tdls.c | 3092 ++++
.../staging/rtl8188eu/core/rtw_wlan_util.c | 4140 +++++
drivers/staging/rtl8188eu/core/rtw_xmit.c | 5070 +++++
29 files changed, 80880 insertions(+)
create mode 100644 drivers/staging/rtl8188eu/core/rtw_ap.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_beamforming.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_br_ext.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_btcoex.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_btcoex_wifionly.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_cmd.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_debug.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_efuse.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_ieee80211.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_io.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_ioctl_query.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_iol.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_led.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_mi.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_mlme.c
create mode 100755 drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_mp.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_odm.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_p2p.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
create mode 100755 drivers/staging/rtl8188eu/core/rtw_recv.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_rf.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_security.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_sreset.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_tdls.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_wlan_util.c
create mode 100644 drivers/staging/rtl8188eu/core/rtw_xmit.c

diff --git a/drivers/staging/rtl8188eu/core/rtw_ap.c b/drivers/staging/rtl8188eu/core/rtw_ap.c
new file mode 100644
index 000000000000..f75dcd0e6d16
--- /dev/null
+++ b/drivers/staging/rtl8188eu/core/rtw_ap.c
@@ -0,0 +1,3778 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved. */
+
+#define _RTW_AP_C_
+
+#include <drv_types.h>
+#include <hal_data.h>
+
+#ifdef CONFIG_AP_MODE
+
+extern unsigned char RTW_WPA_OUI[];
+extern unsigned char WMM_OUI[];
+extern unsigned char WPS_OUI[];
+extern unsigned char P2P_OUI[];
+extern unsigned char WFD_OUI[];
+
+void init_mlme_ap_info(_adapter *padapter)
+{
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+
+ spin_lock_init(&pmlmepriv->bcn_update_lock);
+
+ /* pmlmeext->bstart_bss = false; */
+
+}
+
+void free_mlme_ap_info(_adapter *padapter)
+{
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+
+ stop_ap_mode(padapter);
+}
+
+static void update_BCNTIM(_adapter *padapter)
+{
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ WLAN_BSSID_EX *pnetwork_mlmeext = &(pmlmeinfo->network);
+ unsigned char *pie = pnetwork_mlmeext->IEs;
+ u8 *p, *dst_ie, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
+ __le16 tim_bitmap_le;
+ uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
+
+ tim_bitmap_le = cpu_to_le16(pstapriv->tim_bitmap);
+
+ p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, _TIM_IE_, &tim_ielen, pnetwork_mlmeext->IELength - _FIXED_IE_LENGTH_);
+ if (p != NULL && tim_ielen > 0) {
+ tim_ielen += 2;
+
+ premainder_ie = p + tim_ielen;
+
+ tim_ie_offset = (sint)(p - pie);
+
+ remainder_ielen = pnetwork_mlmeext->IELength - tim_ie_offset - tim_ielen;
+
+ /*append TIM IE from dst_ie offset*/
+ dst_ie = p;
+ } else {
+ tim_ielen = 0;
+
+ /*calculate head_len*/
+ offset = _FIXED_IE_LENGTH_;
+
+ /* get ssid_ie len */
+ p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SSID_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
+ if (p != NULL)
+ offset += tmp_len + 2;
+
+ /*get supported rates len*/
+ p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
+ if (p != NULL)
+ offset += tmp_len + 2;
+
+ /*DS Parameter Set IE, len=3*/
+ offset += 3;
+
+ premainder_ie = pie + offset;
+
+ remainder_ielen = pnetwork_mlmeext->IELength - offset - tim_ielen;
+
+ /*append TIM IE from offset*/
+ dst_ie = pie + offset;
+
+ }
+
+ if (remainder_ielen > 0) {
+ pbackup_remainder_ie = rtw_malloc(remainder_ielen);
+ if (pbackup_remainder_ie && premainder_ie)
+ memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
+ }
+
+ *dst_ie++ = _TIM_IE_;
+
+ if ((pstapriv->tim_bitmap & 0xff00) && (pstapriv->tim_bitmap & 0x00fe))
+ tim_ielen = 5;
+ else
+ tim_ielen = 4;
+
+ *dst_ie++ = tim_ielen;
+
+ *dst_ie++ = 0;/*DTIM count*/
+ *dst_ie++ = 1;/*DTIM period*/
+
+ if (pstapriv->tim_bitmap & BIT(0))/*for bc/mc frames*/
+ *dst_ie++ = BIT(0);/*bitmap ctrl */
+ else
+ *dst_ie++ = 0;
+ if (tim_ielen == 4) {
+ u8 pvb = 0;
+
+ if (pstapriv->tim_bitmap & 0xff00)
+ pvb = le16_to_cpu(tim_bitmap_le) >> 8;
+ else
+ pvb = le16_to_cpu(tim_bitmap_le);
+ *dst_ie++ = pvb;
+ } else if (tim_ielen == 5) {
+ memcpy(dst_ie, &tim_bitmap_le, 2);
+ dst_ie += 2;
+ }
+
+ /*copy remainder IE*/
+ if (pbackup_remainder_ie) {
+ memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
+
+ rtw_mfree(pbackup_remainder_ie, remainder_ielen);
+ }
+
+ offset = (uint)(dst_ie - pie);
+ pnetwork_mlmeext->IELength = offset + remainder_ielen;
+}
+
+void rtw_add_bcn_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index, u8 *data, u8 len)
+{
+ PNDIS_802_11_VARIABLE_IEs pIE;
+ u8 bmatch = false;
+ u8 *pie = pnetwork->IEs;
+ u8 *p = NULL, *dst_ie = NULL, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
+ u32 i, offset, ielen, ie_offset, remainder_ielen = 0;
+
+ for (i = sizeof(NDIS_802_11_FIXED_IEs); i < pnetwork->IELength;) {
+ pIE = (PNDIS_802_11_VARIABLE_IEs)(pnetwork->IEs + i);
+
+ if (pIE->ElementID > index)
+ break;
+ else if (pIE->ElementID == index) { /* already exist the same IE */
+ p = (u8 *)pIE;
+ ielen = pIE->Length;
+ bmatch = true;
+ break;
+ }
+
+ p = (u8 *)pIE;
+ ielen = pIE->Length;
+ i += (pIE->Length + 2);
+ }
+
+ if (p != NULL && ielen > 0) {
+ ielen += 2;
+
+ premainder_ie = p + ielen;
+
+ ie_offset = (sint)(p - pie);
+
+ remainder_ielen = pnetwork->IELength - ie_offset - ielen;
+
+ if (bmatch)
+ dst_ie = p;
+ else
+ dst_ie = (p + ielen);
+ }
+
+ if (dst_ie == NULL)
+ return;
+
+ if (remainder_ielen > 0) {
+ pbackup_remainder_ie = rtw_malloc(remainder_ielen);
+ if (pbackup_remainder_ie && premainder_ie)
+ memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
+ }
+
+ *dst_ie++ = index;
+ *dst_ie++ = len;
+
+ memcpy(dst_ie, data, len);
+ dst_ie += len;
+
+ /* copy remainder IE */
+ if (pbackup_remainder_ie) {
+ memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
+
+ rtw_mfree(pbackup_remainder_ie, remainder_ielen);
+ }
+
+ offset = (uint)(dst_ie - pie);
+ pnetwork->IELength = offset + remainder_ielen;
+}
+
+void rtw_remove_bcn_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index)
+{
+ u8 *p, *dst_ie = NULL, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
+ uint offset, ielen, ie_offset, remainder_ielen = 0;
+ u8 *pie = pnetwork->IEs;
+
+ p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, index, &ielen, pnetwork->IELength - _FIXED_IE_LENGTH_);
+ if (p != NULL && ielen > 0) {
+ ielen += 2;
+
+ premainder_ie = p + ielen;
+
+ ie_offset = (sint)(p - pie);
+
+ remainder_ielen = pnetwork->IELength - ie_offset - ielen;
+
+ dst_ie = p;
+ } else
+ return;
+
+ if (remainder_ielen > 0) {
+ pbackup_remainder_ie = rtw_malloc(remainder_ielen);
+ if (pbackup_remainder_ie && premainder_ie)
+ memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
+ }
+
+ /* copy remainder IE */
+ if (pbackup_remainder_ie) {
+ memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
+
+ rtw_mfree(pbackup_remainder_ie, remainder_ielen);
+ }
+
+ offset = (uint)(dst_ie - pie);
+ pnetwork->IELength = offset + remainder_ielen;
+}
+
+
+u8 chk_sta_is_alive(struct sta_info *psta);
+u8 chk_sta_is_alive(struct sta_info *psta)
+{
+ u8 ret = false;
+#ifdef DBG_EXPIRATION_CHK
+ RTW_INFO("sta:"MAC_FMT", rssi:%d, rx:"STA_PKTS_FMT", expire_to:%u, %s%ssq_len:%u\n"
+ , MAC_ARG(psta->hwaddr)
+ , psta->rssi_stat.undecorated_smoothed_pwdb
+ /* , STA_RX_PKTS_ARG(psta) */
+ , STA_RX_PKTS_DIFF_ARG(psta)
+ , psta->expire_to
+ , psta->state & WIFI_SLEEP_STATE ? "PS, " : ""
+ , psta->state & WIFI_STA_ALIVE_CHK_STATE ? "SAC, " : ""
+ , psta->sleepq_len
+ );
+#endif
+
+ /* if(sta_last_rx_pkts(psta) == sta_rx_pkts(psta)) */
+ if ((psta->sta_stats.last_rx_data_pkts + psta->sta_stats.last_rx_ctrl_pkts) == (psta->sta_stats.rx_data_pkts + psta->sta_stats.rx_ctrl_pkts)) {
+ } else
+ ret = true;
+
+ sta_update_last_rx_pkts(psta);
+
+ return ret;
+}
+
+void expire_timeout_chk(_adapter *padapter)
+{
+ unsigned long irqL;
+ _list *phead, *plist;
+ u8 updated = false;
+ struct sta_info *psta = NULL;
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ u8 chk_alive_num = 0;
+ char chk_alive_list[NUM_STA];
+ int i;
+
+
+#ifdef CONFIG_MCC_MODE
+ /* then driver may check fail due to not recv client's frame under sitesurvey,
+ * don't expire timeout chk under MCC under sitesurvey */
+
+ if (!rtw_hal_mcc_link_status_chk(padapter, __func__))
+ return;
+#endif
+
+ _enter_critical_bh(&pstapriv->auth_list_lock, &irqL);
+
+ phead = &pstapriv->auth_list;
+ plist = get_next(phead);
+
+ /* check auth_queue */
+#ifdef DBG_EXPIRATION_CHK
+ if (!rtw_end_of_queue_search(phead, plist)) {
+ RTW_INFO(FUNC_NDEV_FMT" auth_list, cnt:%u\n"
+ , FUNC_NDEV_ARG(padapter->pnetdev), pstapriv->auth_list_cnt);
+ }
+#endif
+ while ((!rtw_end_of_queue_search(phead, plist))) {
+ psta = LIST_CONTAINOR(plist, struct sta_info, auth_list);
+
+ plist = get_next(plist);
+
+
+#ifdef CONFIG_ATMEL_RC_PATCH
+ if (!memcmp((void *)(pstapriv->atmel_rc_pattern), (void *)(psta->hwaddr), ETH_ALEN))
+ continue;
+ if (psta->flag_atmel_rc)
+ continue;
+#endif
+ if (psta->expire_to > 0) {
+ psta->expire_to--;
+ if (psta->expire_to == 0) {
+ list_del_init(&psta->auth_list);
+ pstapriv->auth_list_cnt--;
+
+ RTW_INFO("auth expire %02X%02X%02X%02X%02X%02X\n",
+ psta->hwaddr[0], psta->hwaddr[1], psta->hwaddr[2], psta->hwaddr[3], psta->hwaddr[4], psta->hwaddr[5]);
+
+ _exit_critical_bh(&pstapriv->auth_list_lock, &irqL);
+
+ /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
+ rtw_free_stainfo(padapter, psta);
+ /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
+
+ _enter_critical_bh(&pstapriv->auth_list_lock, &irqL);
+ }
+ }
+
+ }
+
+ _exit_critical_bh(&pstapriv->auth_list_lock, &irqL);
+ psta = NULL;
+
+
+ _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+
+ phead = &pstapriv->asoc_list;
+ plist = get_next(phead);
+
+ /* check asoc_queue */
+#ifdef DBG_EXPIRATION_CHK
+ if (!rtw_end_of_queue_search(phead, plist)) {
+ RTW_INFO(FUNC_NDEV_FMT" asoc_list, cnt:%u\n"
+ , FUNC_NDEV_ARG(padapter->pnetdev), pstapriv->asoc_list_cnt);
+ }
+#endif
+ while ((!rtw_end_of_queue_search(phead, plist))) {
+ psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
+ plist = get_next(plist);
+#ifdef CONFIG_ATMEL_RC_PATCH
+ RTW_INFO("%s:%d psta=%p, %02x,%02x||%02x,%02x \n\n", __func__, __LINE__,
+ psta, pstapriv->atmel_rc_pattern[0], pstapriv->atmel_rc_pattern[5], psta->hwaddr[0], psta->hwaddr[5]);
+ if (!memcmp((void *)pstapriv->atmel_rc_pattern, (void *)(psta->hwaddr), ETH_ALEN))
+ continue;
+ if (psta->flag_atmel_rc)
+ continue;
+ RTW_INFO("%s: debug line:%d\n", __func__, __LINE__);
+#endif
+#ifdef CONFIG_AUTO_AP_MODE
+ if (psta->isrc)
+ continue;
+#endif
+ if (chk_sta_is_alive(psta) || !psta->expire_to) {
+ psta->expire_to = pstapriv->expire_to;
+ psta->keep_alive_trycnt = 0;
+#ifdef CONFIG_TX_MCAST2UNI
+ psta->under_exist_checking = 0;
+#endif /* CONFIG_TX_MCAST2UNI */
+ } else
+ psta->expire_to--;
+
+#ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
+#ifdef CONFIG_TX_MCAST2UNI
+ if ((psta->flags & WLAN_STA_HT) && (psta->htpriv.agg_enable_bitmap || psta->under_exist_checking)) {
+ /* check sta by delba(addba) for 11n STA */
+ /* ToDo: use CCX report to check for all STAs */
+ /* RTW_INFO("asoc check by DELBA/ADDBA! (pstapriv->expire_to=%d s)(psta->expire_to=%d s), [%02x, %d]\n", pstapriv->expire_to*2, psta->expire_to*2, psta->htpriv.agg_enable_bitmap, psta->under_exist_checking); */
+
+ if (psta->expire_to <= (pstapriv->expire_to - 50)) {
+ RTW_INFO("asoc expire by DELBA/ADDBA! (%d s)\n", (pstapriv->expire_to - psta->expire_to) * 2);
+ psta->under_exist_checking = 0;
+ psta->expire_to = 0;
+ } else if (psta->expire_to <= (pstapriv->expire_to - 3) && (psta->under_exist_checking == 0)) {
+ RTW_INFO("asoc check by DELBA/ADDBA! (%d s)\n", (pstapriv->expire_to - psta->expire_to) * 2);
+ psta->under_exist_checking = 1;
+ /* tear down TX AMPDU */
+ send_delba(padapter, 1, psta->hwaddr);/* */ /* originator */
+ psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
+ psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
+ }
+ }
+#endif /* CONFIG_TX_MCAST2UNI */
+#endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
+
+ if (psta->expire_to <= 0) {
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+
+ if (padapter->registrypriv.wifi_spec == 1) {
+ psta->expire_to = pstapriv->expire_to;
+ continue;
+ }
+
+#ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
+
+#define KEEP_ALIVE_TRYCNT (3)
+
+ if (psta->keep_alive_trycnt > 0 && psta->keep_alive_trycnt <= KEEP_ALIVE_TRYCNT) {
+ if (psta->state & WIFI_STA_ALIVE_CHK_STATE)
+ psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
+ else
+ psta->keep_alive_trycnt = 0;
+
+ } else if ((psta->keep_alive_trycnt > KEEP_ALIVE_TRYCNT) && !(psta->state & WIFI_STA_ALIVE_CHK_STATE))
+ psta->keep_alive_trycnt = 0;
+ if ((psta->htpriv.ht_option ) && (psta->htpriv.ampdu_enable == true)) {
+ uint priority = 1; /* test using BK */
+ u8 issued = 0;
+
+ /* issued = (psta->htpriv.agg_enable_bitmap>>priority)&0x1; */
+ issued |= (psta->htpriv.candidate_tid_bitmap >> priority) & 0x1;
+
+ if (0 == issued) {
+ if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
+ psta->htpriv.candidate_tid_bitmap |= BIT((u8)priority);
+
+ if (psta->state & WIFI_SLEEP_STATE)
+ psta->expire_to = 2; /* 2x2=4 sec */
+ else
+ psta->expire_to = 1; /* 2 sec */
+
+ psta->state |= WIFI_STA_ALIVE_CHK_STATE;
+
+ /* add_ba_hdl(padapter, (u8*)paddbareq_parm); */
+
+ RTW_INFO("issue addba_req to check if sta alive, keep_alive_trycnt=%d\n", psta->keep_alive_trycnt);
+
+ issue_addba_req(padapter, psta->hwaddr, (u8)priority);
+
+ _set_timer(&psta->addba_retry_timer, ADDBA_TO);
+
+ psta->keep_alive_trycnt++;
+
+ continue;
+ }
+ }
+ }
+ if (psta->keep_alive_trycnt > 0 && psta->state & WIFI_STA_ALIVE_CHK_STATE) {
+ psta->keep_alive_trycnt = 0;
+ psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
+ RTW_INFO("change to another methods to check alive if staion is at ps mode\n");
+ }
+
+#endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
+ if (psta->state & WIFI_SLEEP_STATE) {
+ if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
+ /* to check if alive by another methods if staion is at ps mode. */
+ psta->expire_to = pstapriv->expire_to;
+ psta->state |= WIFI_STA_ALIVE_CHK_STATE;
+
+ /* RTW_INFO("alive chk, sta:" MAC_FMT " is at ps mode!\n", MAC_ARG(psta->hwaddr)); */
+
+ /* to update bcn with tim_bitmap for this station */
+ pstapriv->tim_bitmap |= BIT(psta->aid);
+ update_beacon(padapter, _TIM_IE_, NULL, true);
+
+ if (!pmlmeext->active_keep_alive_check)
+ continue;
+ }
+ }
+#ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
+ if (pmlmeext->active_keep_alive_check) {
+ int stainfo_offset;
+
+ stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
+ if (stainfo_offset_valid(stainfo_offset))
+ chk_alive_list[chk_alive_num++] = stainfo_offset;
+
+ continue;
+ }
+#endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
+ list_del_init(&psta->asoc_list);
+ pstapriv->asoc_list_cnt--;
+ RTW_INFO("asoc expire "MAC_FMT", state=0x%x\n", MAC_ARG(psta->hwaddr), psta->state);
+ updated = ap_free_sta(padapter, psta, false, WLAN_REASON_DEAUTH_LEAVING, true);
+ } else {
+ /* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
+ if (psta->sleepq_len > (NR_XMITFRAME / pstapriv->asoc_list_cnt)
+ && padapter->xmitpriv.free_xmitframe_cnt < ((NR_XMITFRAME / pstapriv->asoc_list_cnt) / 2)
+ ) {
+ RTW_INFO("%s sta:"MAC_FMT", sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n", __func__
+ , MAC_ARG(psta->hwaddr)
+ , psta->sleepq_len, padapter->xmitpriv.free_xmitframe_cnt, pstapriv->asoc_list_cnt);
+ wakeup_sta_to_xmit(padapter, psta);
+ }
+ }
+ }
+
+ _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+
+#ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
+ if (chk_alive_num) {
+
+ u8 backup_ch = 0, backup_bw, backup_offset;
+ u8 union_ch = 0, union_bw, union_offset;
+ u8 switch_channel = true;
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+
+ if (!rtw_mi_get_ch_setting_union(padapter, &union_ch, &union_bw, &union_offset)
+ || pmlmeext->cur_channel != union_ch)
+ goto bypass_active_keep_alive;
+
+#ifdef CONFIG_MCC_MODE
+ if (MCC_EN(padapter)) {
+ /* driver doesn't switch channel under MCC */
+ if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC))
+ switch_channel = false;
+ }
+#endif
+ /* switch to correct channel of current network before issue keep-alive frames */
+ if (switch_channel && rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) {
+ backup_ch = rtw_get_oper_ch(padapter);
+ backup_bw = rtw_get_oper_bw(padapter);
+ backup_offset = rtw_get_oper_choffset(padapter);
+ set_channel_bwmode(padapter, union_ch, union_offset, union_bw);
+ }
+
+ /* issue null data to check sta alive*/
+ for (i = 0; i < chk_alive_num; i++) {
+ int ret = _FAIL;
+
+ psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
+#ifdef CONFIG_ATMEL_RC_PATCH
+ if (!memcmp(pstapriv->atmel_rc_pattern, psta->hwaddr, ETH_ALEN))
+ continue;
+ if (psta->flag_atmel_rc)
+ continue;
+#endif
+ if (!(psta->state & _FW_LINKED))
+ continue;
+
+ if (psta->state & WIFI_SLEEP_STATE)
+ ret = issue_nulldata(padapter, psta->hwaddr, 0, 1, 50);
+ else
+ ret = issue_nulldata(padapter, psta->hwaddr, 0, 3, 50);
+
+ psta->keep_alive_trycnt++;
+ if (ret == _SUCCESS) {
+ RTW_INFO("asoc check, sta(" MAC_FMT ") is alive\n", MAC_ARG(psta->hwaddr));
+ psta->expire_to = pstapriv->expire_to;
+ psta->keep_alive_trycnt = 0;
+ continue;
+ } else if (psta->keep_alive_trycnt <= 3) {
+ RTW_INFO("ack check for asoc expire, keep_alive_trycnt=%d\n", psta->keep_alive_trycnt);
+ psta->expire_to = 1;
+ continue;
+ }
+
+ psta->keep_alive_trycnt = 0;
+ RTW_INFO("asoc expire "MAC_FMT", state=0x%x\n", MAC_ARG(psta->hwaddr), psta->state);
+ _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+ if (!list_empty(&psta->asoc_list)) {
+ list_del_init(&psta->asoc_list);
+ pstapriv->asoc_list_cnt--;
+ updated = ap_free_sta(padapter, psta, false, WLAN_REASON_DEAUTH_LEAVING, true);
+ }
+ _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+
+ }
+
+ /* back to the original operation channel */
+ if (switch_channel && backup_ch > 0)
+ set_channel_bwmode(padapter, backup_ch, backup_offset, backup_bw);
+
+bypass_active_keep_alive:
+ ;
+ }
+#endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
+
+ associated_clients_update(padapter, updated, STA_INFO_UPDATE_ALL);
+}
+
+void add_RATid(_adapter *padapter, struct sta_info *psta, u8 rssi_level, u8 is_update_bw)
+{
+ int i;
+ u8 rf_type;
+ unsigned char sta_band = 0;
+ u64 tx_ra_bitmap = 0;
+ struct ht_priv *psta_ht = NULL;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ WLAN_BSSID_EX *pcur_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
+
+ if (psta)
+ psta_ht = &psta->htpriv;
+ else
+ return;
+
+ if (!(psta->state & _FW_LINKED))
+ return;
+
+ rtw_hal_update_sta_rate_mask(padapter, psta);
+ tx_ra_bitmap = psta->ra_mask;
+
+ if (pcur_network->Configuration.DSConfig > 14) {
+ if (tx_ra_bitmap & 0xffff000)
+ sta_band |= WIRELESS_11_5N ;
+
+ if (tx_ra_bitmap & 0xff0)
+ sta_band |= WIRELESS_11A;
+ } else {
+ /* 5G band */
+ if (tx_ra_bitmap & 0xffff000)
+ sta_band |= WIRELESS_11_24N;
+
+ if (tx_ra_bitmap & 0xff0)
+ sta_band |= WIRELESS_11G;
+
+ if (tx_ra_bitmap & 0x0f)
+ sta_band |= WIRELESS_11B;
+ }
+
+ psta->wireless_mode = sta_band;
+ psta->raid = rtw_hal_networktype_to_raid(padapter, psta);
+
+ if (psta->aid < NUM_STA) {
+ RTW_INFO("%s=> mac_id:%d , raid:%d, tx_ra_bitmap:0x%016llx, networkType:0x%02x\n",
+ __func__, psta->mac_id, psta->raid, tx_ra_bitmap, psta->wireless_mode);
+
+ rtw_update_ramask(padapter, psta, psta->mac_id, rssi_level, is_update_bw);
+ } else
+ RTW_INFO("station aid %d exceed the max number\n", psta->aid);
+
+}
+
+void update_bmc_sta(_adapter *padapter)
+{
+ unsigned long irqL;
+ unsigned char network_type;
+ int supportRateNum = 0;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ WLAN_BSSID_EX *pcur_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
+ struct sta_info *psta = rtw_get_bcmc_stainfo(padapter);
+
+ if (psta) {
+ psta->aid = 0;/* default set to 0 */
+ psta->qos_option = 0;
+ psta->htpriv.ht_option = false;
+
+ psta->ieee8021x_blocked = 0;
+
+ memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
+
+ /* psta->dot118021XPrivacy = _NO_PRIVACY_; */ /* !!! remove it, because it has been set before this. */
+
+ /* prepare for add_RATid */
+ supportRateNum = rtw_get_rateset_len((u8 *)&pcur_network->SupportedRates);
+ network_type = rtw_check_network_type((u8 *)&pcur_network->SupportedRates, supportRateNum, pcur_network->Configuration.DSConfig);
+ if (IsSupportedTxCCK(network_type))
+ network_type = WIRELESS_11B;
+ else if (network_type == WIRELESS_INVALID) { /* error handling */
+ if (pcur_network->Configuration.DSConfig > 14)
+ network_type = WIRELESS_11A;
+ else
+ network_type = WIRELESS_11B;
+ }
+ update_sta_basic_rate(psta, network_type);
+ psta->wireless_mode = network_type;
+
+ rtw_hal_update_sta_rate_mask(padapter, psta);
+
+ psta->raid = rtw_hal_networktype_to_raid(padapter, psta);
+
+ _enter_critical_bh(&psta->lock, &irqL);
+ psta->state = _FW_LINKED;
+ _exit_critical_bh(&psta->lock, &irqL);
+
+ rtw_sta_media_status_rpt(padapter, psta, 1);
+ rtw_hal_update_ra_mask(psta, psta->rssi_level, true);
+ } else
+ RTW_INFO("add_RATid_bmc_sta error!\n");
+
+}
+
+/* notes:
+ * AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode */
+void update_sta_info_apmode(_adapter *padapter, struct sta_info *psta)
+{
+ unsigned long irqL;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct security_priv *psecuritypriv = &padapter->securitypriv;
+ struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
+ struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
+ struct ht_priv *phtpriv_sta = &psta->htpriv;
+ u8 cur_ldpc_cap = 0, cur_stbc_cap = 0, cur_beamform_cap = 0;
+ /* set intf_tag to if1 */
+ /* psta->intf_tag = 0; */
+
+ RTW_INFO("%s\n", __func__);
+
+ /*alloc macid when call rtw_alloc_stainfo(),release macid when call rtw_free_stainfo()*/
+
+ /* ap mode */
+ rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, true);
+
+ if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)
+ psta->ieee8021x_blocked = true;
+ else
+ psta->ieee8021x_blocked = false;
+
+
+ /* update sta's cap */
+
+ /* ERP */
+ VCS_update(padapter, psta);
+ /* HT related cap */
+ if (phtpriv_sta->ht_option) {
+ /* check if sta supports rx ampdu */
+ phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
+
+ phtpriv_sta->rx_ampdu_min_spacing = (phtpriv_sta->ht_cap.ampdu_params_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
+
+ /* bwmode */
+ if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH))
+ psta->bw_mode = CHANNEL_WIDTH_40;
+ else
+ psta->bw_mode = CHANNEL_WIDTH_20;
+
+ if (psta->ht_40mhz_intolerant)
+ psta->bw_mode = CHANNEL_WIDTH_20;
+
+ if (pmlmeext->cur_bwmode < psta->bw_mode)
+ psta->bw_mode = pmlmeext->cur_bwmode;
+
+ phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
+
+
+ /* check if sta support s Short GI 20M */
+ if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20))
+ phtpriv_sta->sgi_20m = true;
+
+ /* check if sta support s Short GI 40M */
+ if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_40)) {
+ if (psta->bw_mode == CHANNEL_WIDTH_40) /* according to psta->bw_mode */
+ phtpriv_sta->sgi_40m = true;
+ else
+ phtpriv_sta->sgi_40m = false;
+ }
+
+ psta->qos_option = true;
+
+ /* B0 Config LDPC Coding Capability */
+ if (TEST_FLAG(phtpriv_ap->ldpc_cap, LDPC_HT_ENABLE_TX) &&
+ GET_HT_CAP_ELE_LDPC_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
+ SET_FLAG(cur_ldpc_cap, (LDPC_HT_ENABLE_TX | LDPC_HT_CAP_TX));
+ RTW_INFO("Enable HT Tx LDPC for STA(%d)\n", psta->aid);
+ }
+
+ /* B7 B8 B9 Config STBC setting */
+ if (TEST_FLAG(phtpriv_ap->stbc_cap, STBC_HT_ENABLE_TX) &&
+ GET_HT_CAP_ELE_RX_STBC((u8 *)(&phtpriv_sta->ht_cap))) {
+ SET_FLAG(cur_stbc_cap, (STBC_HT_ENABLE_TX | STBC_HT_CAP_TX));
+ RTW_INFO("Enable HT Tx STBC for STA(%d)\n", psta->aid);
+ }
+
+#ifdef CONFIG_BEAMFORMING
+ /*Config Tx beamforming setting*/
+ if (TEST_FLAG(phtpriv_ap->beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE) &&
+ GET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
+ SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE);
+ /*Shift to BEAMFORMING_HT_BEAMFORMEE_CHNL_EST_CAP*/
+ SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS((u8 *)(&phtpriv_sta->ht_cap)) << 6);
+ }
+
+ if (TEST_FLAG(phtpriv_ap->beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE) &&
+ GET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
+ SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE);
+ /*Shift to BEAMFORMING_HT_BEAMFORMER_STEER_NUM*/
+ SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS((u8 *)(&phtpriv_sta->ht_cap)) << 4);
+ }
+ if (cur_beamform_cap)
+ RTW_INFO("Client STA(%d) HT Beamforming Cap = 0x%02X\n", psta->aid, cur_beamform_cap);
+#endif /*CONFIG_BEAMFORMING*/
+ } else {
+ phtpriv_sta->ampdu_enable = false;
+
+ phtpriv_sta->sgi_20m = false;
+ phtpriv_sta->sgi_40m = false;
+ psta->bw_mode = CHANNEL_WIDTH_20;
+ phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
+ }
+
+ phtpriv_sta->ldpc_cap = cur_ldpc_cap;
+ phtpriv_sta->stbc_cap = cur_stbc_cap;
+ phtpriv_sta->beamform_cap = cur_beamform_cap;
+
+ /* Rx AMPDU */
+ send_delba(padapter, 0, psta->hwaddr);/* recipient */
+
+ /* TX AMPDU */
+ send_delba(padapter, 1, psta->hwaddr);/* */ /* originator */
+ phtpriv_sta->agg_enable_bitmap = 0x0;/* reset */
+ phtpriv_sta->candidate_tid_bitmap = 0x0;/* reset */
+
+ update_ldpc_stbc_cap(psta);
+
+ /* todo: init other variables */
+
+ memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
+
+ _enter_critical_bh(&psta->lock, &irqL);
+ psta->state |= _FW_LINKED;
+ _exit_critical_bh(&psta->lock, &irqL);
+
+
+}
+
+static void update_ap_info(_adapter *padapter, struct sta_info *psta)
+{
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
+ struct security_priv *psecuritypriv = &padapter->securitypriv;
+ struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
+ struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
+
+ psta->wireless_mode = pmlmeext->cur_wireless_mode;
+
+ psta->bssratelen = rtw_get_rateset_len(pnetwork->SupportedRates);
+ memcpy(psta->bssrateset, pnetwork->SupportedRates, psta->bssratelen);
+
+ /* HT related cap */
+ if (phtpriv_ap->ht_option) {
+ /* check if sta supports rx ampdu */
+ /* phtpriv_ap->ampdu_enable = phtpriv_ap->ampdu_enable; */
+
+ /* check if sta support s Short GI 20M */
+ if ((phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20))
+ phtpriv_ap->sgi_20m = true;
+ /* check if sta support s Short GI 40M */
+ if ((phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_40))
+ phtpriv_ap->sgi_40m = true;
+
+ psta->qos_option = true;
+ } else {
+ phtpriv_ap->ampdu_enable = false;
+
+ phtpriv_ap->sgi_20m = false;
+ phtpriv_ap->sgi_40m = false;
+ }
+
+ psta->bw_mode = pmlmeext->cur_bwmode;
+ phtpriv_ap->ch_offset = pmlmeext->cur_ch_offset;
+
+ phtpriv_ap->agg_enable_bitmap = 0x0;/* reset */
+ phtpriv_ap->candidate_tid_bitmap = 0x0;/* reset */
+
+ memcpy(&psta->htpriv, &pmlmepriv->htpriv, sizeof(struct ht_priv));
+
+ psta->state |= WIFI_AP_STATE; /* Aries, add,fix bug of flush_cam_entry at STOP AP mode , 0724 */
+}
+
+static void rtw_set_hw_wmm_param(_adapter *padapter)
+{
+ u8 ACI, ACM, AIFS, ECWMin, ECWMax, aSifsTime;
+ u8 acm_mask;
+ u16 TXOP;
+ u32 acParm, i;
+ u32 edca[4], inx[4];
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+
+ acm_mask = 0;
+
+ if (is_supported_5g(pmlmeext->cur_wireless_mode) ||
+ (pmlmeext->cur_wireless_mode & WIRELESS_11_24N))
+ aSifsTime = 16;
+ else
+ aSifsTime = 10;
+
+ if (pmlmeinfo->WMM_enable == 0) {
+ padapter->mlmepriv.acm_mask = 0;
+
+ AIFS = aSifsTime + (2 * pmlmeinfo->slotTime);
+
+ if (pmlmeext->cur_wireless_mode & (WIRELESS_11G | WIRELESS_11A)) {
+ ECWMin = 4;
+ ECWMax = 10;
+ } else if (pmlmeext->cur_wireless_mode & WIRELESS_11B) {
+ ECWMin = 5;
+ ECWMax = 10;
+ } else {
+ ECWMin = 4;
+ ECWMax = 10;
+ }
+
+ TXOP = 0;
+ acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
+ rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
+ rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
+ rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
+
+ ECWMin = 2;
+ ECWMax = 3;
+ TXOP = 0x2f;
+ acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
+ rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
+
+ } else {
+ edca[0] = edca[1] = edca[2] = edca[3] = 0;
+
+ /*TODO:*/
+ acm_mask = 0;
+ padapter->mlmepriv.acm_mask = acm_mask;
+ AIFS = (7 * pmlmeinfo->slotTime) + aSifsTime;
+ ECWMin = 4;
+ ECWMax = 10;
+ TXOP = 0;
+ acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
+ rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
+ edca[XMIT_BK_QUEUE] = acParm;
+ RTW_INFO("WMM(BK): %x\n", acParm);
+
+ /* BE */
+ AIFS = (3 * pmlmeinfo->slotTime) + aSifsTime;
+ ECWMin = 4;
+ ECWMax = 6;
+ TXOP = 0;
+ acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
+ rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
+ edca[XMIT_BE_QUEUE] = acParm;
+ RTW_INFO("WMM(BE): %x\n", acParm);
+
+ /* VI */
+ AIFS = (1 * pmlmeinfo->slotTime) + aSifsTime;
+ ECWMin = 3;
+ ECWMax = 4;
+ TXOP = 94;
+ acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
+ rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
+ edca[XMIT_VI_QUEUE] = acParm;
+ RTW_INFO("WMM(VI): %x\n", acParm);
+
+ /* VO */
+ AIFS = (1 * pmlmeinfo->slotTime) + aSifsTime;
+ ECWMin = 2;
+ ECWMax = 3;
+ TXOP = 47;
+ acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
+ rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
+ edca[XMIT_VO_QUEUE] = acParm;
+ RTW_INFO("WMM(VO): %x\n", acParm);
+
+
+ if (padapter->registrypriv.acm_method == 1)
+ rtw_hal_set_hwreg(padapter, HW_VAR_ACM_CTRL, (u8 *)(&acm_mask));
+ else
+ padapter->mlmepriv.acm_mask = acm_mask;
+
+ inx[0] = 0;
+ inx[1] = 1;
+ inx[2] = 2;
+ inx[3] = 3;
+
+ if (pregpriv->wifi_spec == 1) {
+ u32 j, tmp, change_inx = false;
+
+ /* entry indx: 0->vo, 1->vi, 2->be, 3->bk. */
+ for (i = 0 ; i < 4 ; i++) {
+ for (j = i + 1 ; j < 4 ; j++) {
+ /* compare CW and AIFS */
+ if ((edca[j] & 0xFFFF) < (edca[i] & 0xFFFF))
+ change_inx = true;
+ else if ((edca[j] & 0xFFFF) == (edca[i] & 0xFFFF)) {
+ /* compare TXOP */
+ if ((edca[j] >> 16) > (edca[i] >> 16))
+ change_inx = true;
+ }
+
+ if (change_inx) {
+ tmp = edca[i];
+ edca[i] = edca[j];
+ edca[j] = tmp;
+
+ tmp = inx[i];
+ inx[i] = inx[j];
+ inx[j] = tmp;
+
+ change_inx = false;
+ }
+ }
+ }
+ }
+
+ for (i = 0 ; i < 4 ; i++) {
+ pxmitpriv->wmm_para_seq[i] = inx[i];
+ RTW_INFO("wmm_para_seq(%d): %d\n", i, pxmitpriv->wmm_para_seq[i]);
+ }
+
+ }
+
+}
+
+static void update_hw_ht_param(_adapter *padapter)
+{
+ unsigned char max_AMPDU_len;
+ unsigned char min_MPDU_spacing;
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+
+ RTW_INFO("%s\n", __func__);
+
+
+ /* handle A-MPDU parameter field */
+ /*
+ AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
+ AMPDU_para [4:2]:Min MPDU Start Spacing
+ */
+ max_AMPDU_len = pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x03;
+
+ min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) >> 2;
+
+ rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, (u8 *)(&min_MPDU_spacing));
+
+ rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len));
+
+ /* Config SM Power Save setting */
+ pmlmeinfo->SM_PS = (le16_to_cpu(pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info) & 0x0C) >> 2;
+ if (pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC)
+ RTW_INFO("%s(): WLAN_HT_CAP_SM_PS_STATIC\n", __func__);
+}
+
+static void rtw_ap_check_scan(_adapter *padapter)
+{
+ unsigned long irqL;
+ _list *plist, *phead;
+ u32 delta_time, lifetime;
+ struct wlan_network *pnetwork = NULL;
+ WLAN_BSSID_EX *pbss = NULL;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ _queue *queue = &(pmlmepriv->scanned_queue);
+ u8 do_scan = false;
+ u8 reason = RTW_AUTO_SCAN_REASON_UNSPECIFIED;
+
+ lifetime = SCANQUEUE_LIFETIME; /* 20 sec */
+
+ _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
+ phead = get_list_head(queue);
+ if (rtw_end_of_queue_search(phead, get_next(phead)) )
+ if (padapter->registrypriv.wifi_spec) {
+ do_scan = true;
+ reason |= RTW_AUTO_SCAN_REASON_2040_BSS;
+ }
+ _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
+
+#ifdef CONFIG_AUTO_CHNL_SEL_NHM
+ if (padapter->registrypriv.acs_auto_scan) {
+ do_scan = true;
+ reason |= RTW_AUTO_SCAN_REASON_ACS;
+ rtw_acs_start(padapter, true);
+ }
+#endif
+
+ if (do_scan) {
+ RTW_INFO("%s : drv scans by itself and wait_completed\n", __func__);
+ rtw_drv_scan_by_self(padapter, reason);
+ rtw_scan_wait_completed(padapter);
+ }
+
+#ifdef CONFIG_AUTO_CHNL_SEL_NHM
+ if (padapter->registrypriv.acs_auto_scan)
+ rtw_acs_start(padapter, false);
+#endif
+ _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
+
+ phead = get_list_head(queue);
+ plist = get_next(phead);
+
+ while (1) {
+
+ if (rtw_end_of_queue_search(phead, plist) )
+ break;
+
+ pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
+
+ if (rtw_ch_set_search_ch(padapter->mlmeextpriv.channel_set, pnetwork->network.Configuration.DSConfig) >= 0
+ && rtw_mlme_band_check(padapter, pnetwork->network.Configuration.DSConfig)
+ && rtw_validate_ssid(&(pnetwork->network.Ssid))) {
+ delta_time = (u32) rtw_get_passing_time_ms(pnetwork->last_scanned);
+
+ if (delta_time < lifetime) {
+
+ uint ie_len = 0;
+ u8 *pbuf = NULL;
+ u8 *ie = NULL;
+
+ pbss = &pnetwork->network;
+ ie = pbss->IEs;
+
+ /*check if HT CAP INFO IE exists or not*/
+ pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pbss->IELength - _BEACON_IE_OFFSET_));
+ if (pbuf == NULL) {
+ /* HT CAP INFO IE don't exist, it is b/g mode bss.*/
+
+ if (false == ATOMIC_READ(&pmlmepriv->olbc))
+ ATOMIC_SET(&pmlmepriv->olbc, true);
+
+ if (false == ATOMIC_READ(&pmlmepriv->olbc_ht))
+ ATOMIC_SET(&pmlmepriv->olbc_ht, true);
+
+ if (padapter->registrypriv.wifi_spec)
+ RTW_INFO("%s: %s is a/b/g ap\n", __func__, pnetwork->network.Ssid.Ssid);
+ }
+ }
+ }
+
+ plist = get_next(plist);
+
+ }
+
+ _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
+
+ pmlmepriv->num_sta_no_ht = 0; /* reset to 0 after ap do scanning*/
+
+}
+
+void rtw_start_bss_hdl_after_chbw_decided(_adapter *adapter)
+{
+ WLAN_BSSID_EX *pnetwork = &(adapter->mlmepriv.cur_network.network);
+ struct sta_info *sta = NULL;
+
+ /* update cur_wireless_mode */
+ update_wireless_mode(adapter);
+
+ /* update RRSR and RTS_INIT_RATE register after set channel and bandwidth */
+ UpdateBrateTbl(adapter, pnetwork->SupportedRates);
+ rtw_hal_set_hwreg(adapter, HW_VAR_BASIC_RATE, pnetwork->SupportedRates);
+
+ /* update capability after cur_wireless_mode updated */
+ update_capinfo(adapter, rtw_get_capability(pnetwork));
+
+ /* update bc/mc sta_info */
+ update_bmc_sta(adapter);
+
+ /* update AP's sta info */
+ sta = rtw_get_stainfo(&adapter->stapriv, pnetwork->MacAddress);
+ if (!sta) {
+ RTW_INFO(FUNC_ADPT_FMT" !sta for macaddr="MAC_FMT"\n", FUNC_ADPT_ARG(adapter), MAC_ARG(pnetwork->MacAddress));
+ rtw_warn_on(1);
+ return;
+ }
+
+ update_ap_info(adapter, sta);
+}
+
+void start_bss_network(_adapter *padapter, struct createbss_parm *parm)
+{
+#define DUMP_ADAPTERS_STATUS 0
+
+ u8 val8;
+ u16 bcn_interval;
+ u32 acparm;
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct security_priv *psecuritypriv = &(padapter->securitypriv);
+ WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network; /* used as input */
+ struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ WLAN_BSSID_EX *pnetwork_mlmeext = &(pmlmeinfo->network);
+ struct dvobj_priv *pdvobj = padapter->dvobj;
+ s16 req_ch = -1, req_bw = -1, req_offset = -1;
+ bool ch_setting_changed = false;
+ u8 ch_to_set = 0, bw_to_set, offset_to_set;
+ u8 doiqk = false;
+ /* use for check ch bw offset can be allowed or not */
+ u8 chbw_allow = true;
+
+ if (parm->req_ch != 0) {
+ /* bypass other setting, go checking ch, bw, offset */
+ req_ch = parm->req_ch;
+ req_bw = parm->req_bw;
+ req_offset = parm->req_offset;
+ goto chbw_decision;
+ } else {
+ /* inform this request comes from upper layer */
+ req_ch = 0;
+ }
+
+ bcn_interval = (u16)pnetwork->Configuration.BeaconPeriod;
+
+ /* check if there is wps ie, */
+ /* if there is wpsie in beacon, the hostapd will update beacon twice when stating hostapd, */
+ /* and at first time the security ie ( RSN/WPA IE) will not include in beacon. */
+ if (NULL == rtw_get_wps_ie(pnetwork->IEs + _FIXED_IE_LENGTH_, pnetwork->IELength - _FIXED_IE_LENGTH_, NULL, NULL))
+ pmlmeext->bstart_bss = true;
+
+ /* todo: update wmm, ht cap */
+ /* pmlmeinfo->WMM_enable; */
+ /* pmlmeinfo->HT_enable; */
+ if (pmlmepriv->qospriv.qos_option)
+ pmlmeinfo->WMM_enable = true;
+ if (pmlmepriv->htpriv.ht_option) {
+ pmlmeinfo->WMM_enable = true;
+ pmlmeinfo->HT_enable = true;
+ /* pmlmeinfo->HT_info_enable = true; */
+ /* pmlmeinfo->HT_caps_enable = true; */
+
+ update_hw_ht_param(padapter);
+ }
+ if (pmlmepriv->cur_network.join_res != true) { /* setting only at first time */
+ /* WEP Key will be set before this function, do not clear CAM. */
+ if ((psecuritypriv->dot11PrivacyAlgrthm != _WEP40_) && (psecuritypriv->dot11PrivacyAlgrthm != _WEP104_))
+ flush_all_cam_entry(padapter); /* clear CAM */
+ }
+
+ /* set MSR to AP_Mode */
+ Set_MSR(padapter, _HW_STATE_AP_);
+
+ /* Set BSSID REG */
+ rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pnetwork->MacAddress);
+
+ /* Set EDCA param reg */
+#ifdef CONFIG_CONCURRENT_MODE
+ acparm = 0x005ea42b;
+#else
+ acparm = 0x002F3217; /* VO */
+#endif
+ rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acparm));
+ acparm = 0x005E4317; /* VI */
+ rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acparm));
+ /* acparm = 0x00105320; */ /* BE */
+ acparm = 0x005ea42b;
+ rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acparm));
+ acparm = 0x0000A444; /* BK */
+ rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acparm));
+
+ /* Set Security */
+ val8 = (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) ? 0xcc : 0xcf;
+ rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
+
+ /* Beacon Control related register */
+ rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&bcn_interval));
+
+chbw_decision:
+ ch_setting_changed = rtw_ap_chbw_decision(padapter, req_ch, req_bw, req_offset
+ , &ch_to_set, &bw_to_set, &offset_to_set, &chbw_allow);
+
+ /* let pnetwork_mlmeext == pnetwork_mlme. */
+ memcpy(pnetwork_mlmeext, pnetwork, pnetwork->Length);
+
+ rtw_start_bss_hdl_after_chbw_decided(padapter);
+
+#if defined(CONFIG_DFS_MASTER)
+ rtw_dfs_master_status_apply(padapter, MLME_AP_STARTED);
+#endif
+
+#ifdef CONFIG_MCC_MODE
+ if (MCC_EN(padapter)) {
+ /*
+ * due to check under rtw_ap_chbw_decision
+ * if under MCC mode, means req channel setting is the same as current channel setting
+ * if not under MCC mode, mean req channel setting is not the same as current channel setting
+ */
+ if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC)) {
+ RTW_INFO(FUNC_ADPT_FMT": req channel setting is the same as current channel setting, go to update BCN\n"
+ , FUNC_ADPT_ARG(padapter));
+
+ goto update_beacon;
+
+ }
+ }
+
+ /* issue null data to AP for all interface connecting to AP before switch channel setting for softap */
+ rtw_hal_mcc_issue_null_data(padapter, chbw_allow, 1);
+#endif /* CONFIG_MCC_MODE */
+
+ doiqk = true;
+ rtw_hal_set_hwreg(padapter , HW_VAR_DO_IQK , &doiqk);
+
+ if (ch_to_set != 0) {
+ set_channel_bwmode(padapter, ch_to_set, offset_to_set, bw_to_set);
+ rtw_mi_update_union_chan_inf(padapter, ch_to_set, offset_to_set, bw_to_set);
+ }
+
+ doiqk = false;
+ rtw_hal_set_hwreg(padapter , HW_VAR_DO_IQK , &doiqk);
+
+#ifdef CONFIG_MCC_MODE
+ /* after set_channel_bwmode for backup IQK */
+ rtw_hal_set_mcc_setting_start_bss_network(padapter, chbw_allow);
+#endif
+
+ if (DUMP_ADAPTERS_STATUS) {
+ RTW_INFO(FUNC_ADPT_FMT" done\n", FUNC_ADPT_ARG(padapter));
+ dump_adapters_status(RTW_DBGDUMP , adapter_to_dvobj(padapter));
+ }
+
+update_beacon:
+ /* update beacon content only if bstart_bss is true */
+ if (pmlmeext->bstart_bss) {
+
+ unsigned long irqL;
+
+ if ((ATOMIC_READ(&pmlmepriv->olbc) ) || (ATOMIC_READ(&pmlmepriv->olbc_ht) == true)) {
+ /* AP is not starting a 40 MHz BSS in presence of an 802.11g BSS. */
+
+ pmlmepriv->ht_op_mode &= (~HT_INFO_OPERATION_MODE_OP_MODE_MASK);
+ pmlmepriv->ht_op_mode |= OP_MODE_MAY_BE_LEGACY_STAS;
+ update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, false);
+ }
+
+ update_beacon(padapter, _TIM_IE_, NULL, false);
+
+#ifdef CONFIG_SWTIMER_BASED_TXBCN
+ _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
+ if (list_empty(&padapter->list)) {
+ list_add_tail(&padapter->list, get_list_head(&pdvobj->ap_if_q));
+ pdvobj->nr_ap_if++;
+ pdvobj->inter_bcn_space = DEFAULT_BCN_INTERVAL / pdvobj->nr_ap_if;
+ }
+ _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
+
+ rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pdvobj->inter_bcn_space));
+
+#endif /*CONFIG_SWTIMER_BASED_TXBCN*/
+
+ }
+
+ rtw_scan_wait_completed(padapter);
+
+ /* send beacon */
+ if ((0 == rtw_mi_check_fwstate(padapter, _FW_UNDER_SURVEY))
+ && (0 == rtw_mi_check_fwstate(padapter, WIFI_OP_CH_SWITCHING))
+ ) {
+
+ /*update_beacon(padapter, _TIM_IE_, NULL, true);*/
+
+#if !defined(CONFIG_INTERRUPT_BASED_TXBCN)
+#ifdef CONFIG_SWTIMER_BASED_TXBCN
+ if (pdvobj->nr_ap_if == 1) {
+ RTW_INFO("start SW BCN TIMER!\n");
+ _set_timer(&pdvobj->txbcn_timer, bcn_interval);
+ }
+#else
+ /* other case will tx beacon when bcn interrupt coming in. */
+ if (send_beacon(padapter) == _FAIL)
+ RTW_INFO("issue_beacon, fail!\n");
+#endif
+#endif /* !defined(CONFIG_INTERRUPT_BASED_TXBCN) */
+ }
+
+ /*Set EDCA param reg after update cur_wireless_mode & update_capinfo*/
+ if (pregpriv->wifi_spec == 1)
+ rtw_set_hw_wmm_param(padapter);
+
+ /*pmlmeext->bstart_bss = true;*/
+}
+
+int rtw_check_beacon_data(_adapter *padapter, u8 *pbuf, int len)
+{
+ int ret = _SUCCESS;
+ u8 *p;
+ u8 *pHT_caps_ie = NULL;
+ u8 *pHT_info_ie = NULL;
+ u16 cap, ht_cap = false;
+ uint ie_len = 0;
+ int group_cipher, pairwise_cipher;
+ u8 channel, network_type, supportRate[NDIS_802_11_LENGTH_RATES_EX];
+ int supportRateNum = 0;
+ u8 OUI1[] = {0x00, 0x50, 0xf2, 0x01};
+ u8 wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
+ u8 WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
+ struct registry_priv *pregistrypriv = &padapter->registrypriv;
+ struct security_priv *psecuritypriv = &padapter->securitypriv;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ WLAN_BSSID_EX *pbss_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ u8 *ie = pbss_network->IEs;
+ u8 vht_cap = false;
+ struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ u8 rf_num = 0;
+
+ /* SSID */
+ /* Supported rates */
+ /* DS Params */
+ /* WLAN_EID_COUNTRY */
+ /* ERP Information element */
+ /* Extended supported rates */
+ /* WPA/WPA2 */
+ /* Wi-Fi Wireless Multimedia Extensions */
+ /* ht_capab, ht_oper */
+ /* WPS IE */
+
+ RTW_INFO("%s, len=%d\n", __func__, len);
+
+ if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true)
+ return _FAIL;
+
+
+ if (len > MAX_IE_SZ)
+ return _FAIL;
+
+ pbss_network->IELength = len;
+
+ memset(ie, 0, MAX_IE_SZ);
+
+ memcpy(ie, pbuf, pbss_network->IELength);
+
+
+ if (pbss_network->InfrastructureMode != Ndis802_11APMode)
+ return _FAIL;
+
+
+ rtw_ap_check_scan(padapter);
+
+
+ pbss_network->Rssi = 0;
+
+ memcpy(pbss_network->MacAddress, adapter_mac_addr(padapter), ETH_ALEN);
+
+ /* beacon interval */
+ p = rtw_get_beacon_interval_from_ie(ie);/* ie + 8; */ /* 8: TimeStamp, 2: Beacon Interval 2:Capability */
+ /* pbss_network->Configuration.BeaconPeriod = le16_to_cpu(*(unsigned short*)p); */
+ pbss_network->Configuration.BeaconPeriod = RTW_GET_LE16(p);
+
+ /* capability */
+ /* cap = *(unsigned short *)rtw_get_capability_from_ie(ie); */
+ /* cap = le16_to_cpu(cap); */
+ cap = RTW_GET_LE16(ie);
+
+ /* SSID */
+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SSID_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
+ if (p && ie_len > 0) {
+ memset(&pbss_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
+ memcpy(pbss_network->Ssid.Ssid, (p + 2), ie_len);
+ pbss_network->Ssid.SsidLength = ie_len;
+#ifdef CONFIG_P2P
+ memcpy(padapter->wdinfo.p2p_group_ssid, pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength);
+ padapter->wdinfo.p2p_group_ssid_len = pbss_network->Ssid.SsidLength;
+#endif
+ }
+
+ /* chnnel */
+ channel = 0;
+ pbss_network->Configuration.Length = 0;
+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _DSSET_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
+ if (p && ie_len > 0)
+ channel = *(p + 2);
+
+ pbss_network->Configuration.DSConfig = channel;
+
+
+ memset(supportRate, 0, NDIS_802_11_LENGTH_RATES_EX);
+ /* get supported rates */
+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
+ if (p != NULL) {
+ memcpy(supportRate, p + 2, ie_len);
+ supportRateNum = ie_len;
+ }
+
+ /* get ext_supported rates */
+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_SUPPORTEDRATES_IE_, &ie_len, pbss_network->IELength - _BEACON_IE_OFFSET_);
+ if (p != NULL) {
+ memcpy(supportRate + supportRateNum, p + 2, ie_len);
+ supportRateNum += ie_len;
+
+ }
+
+ network_type = rtw_check_network_type(supportRate, supportRateNum, channel);
+
+ rtw_set_supported_rate(pbss_network->SupportedRates, network_type);
+
+
+ /* parsing ERP_IE */
+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
+ if (p && ie_len > 0)
+ ERP_IE_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)p);
+
+ /* update privacy/security */
+ if (cap & BIT(4))
+ pbss_network->Privacy = 1;
+ else
+ pbss_network->Privacy = 0;
+
+ psecuritypriv->wpa_psk = 0;
+
+ /* wpa2 */
+ group_cipher = 0;
+ pairwise_cipher = 0;
+ psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_;
+ psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_;
+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _RSN_IE_2_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
+ if (p && ie_len > 0) {
+ if (rtw_parse_wpa2_ie(p, ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
+ psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
+
+ psecuritypriv->dot8021xalg = 1;/* psk, todo:802.1x */
+ psecuritypriv->wpa_psk |= BIT(1);
+
+ psecuritypriv->wpa2_group_cipher = group_cipher;
+ psecuritypriv->wpa2_pairwise_cipher = pairwise_cipher;
+ }
+ }
+
+ /* wpa */
+ ie_len = 0;
+ group_cipher = 0;
+ pairwise_cipher = 0;
+ psecuritypriv->wpa_group_cipher = _NO_PRIVACY_;
+ psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_;
+ for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) {
+ p = rtw_get_ie(p, _SSN_IE_1_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
+ if ((p) && (!memcmp(p + 2, OUI1, 4))) {
+ if (rtw_parse_wpa_ie(p, ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
+ psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
+
+ psecuritypriv->dot8021xalg = 1;/* psk, todo:802.1x */
+
+ psecuritypriv->wpa_psk |= BIT(0);
+
+ psecuritypriv->wpa_group_cipher = group_cipher;
+ psecuritypriv->wpa_pairwise_cipher = pairwise_cipher;
+ }
+ break;
+ }
+
+ if ((p == NULL) || (ie_len == 0))
+ break;
+ }
+
+ /* wmm */
+ ie_len = 0;
+ pmlmepriv->qospriv.qos_option = 0;
+ if (pregistrypriv->wmm_enable) {
+ for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) {
+ p = rtw_get_ie(p, _VENDOR_SPECIFIC_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
+ if ((p) && !memcmp(p + 2, WMM_PARA_IE, 6)) {
+ pmlmepriv->qospriv.qos_option = 1;
+
+ *(p + 8) |= BIT(7); /* QoS Info, support U-APSD */
+
+ /* disable all ACM bits since the WMM admission control is not supported */
+ *(p + 10) &= ~BIT(4); /* BE */
+ *(p + 14) &= ~BIT(4); /* BK */
+ *(p + 18) &= ~BIT(4); /* VI */
+ *(p + 22) &= ~BIT(4); /* VO */
+
+ break;
+ }
+
+ if ((p == NULL) || (ie_len == 0))
+ break;
+ }
+ }
+ /* parsing HT_CAP_IE */
+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
+ if (p && ie_len > 0) {
+ u8 rf_type = 0;
+ HT_CAP_AMPDU_FACTOR max_rx_ampdu_factor = MAX_AMPDU_FACTOR_64K;
+ struct rtw_ieee80211_ht_cap *pht_cap = (struct rtw_ieee80211_ht_cap *)(p + 2);
+
+ if (0) {
+ RTW_INFO(FUNC_ADPT_FMT" HT_CAP_IE from upper layer:\n", FUNC_ADPT_ARG(padapter));
+ dump_ht_cap_ie_content(RTW_DBGDUMP, p + 2, ie_len);
+ }
+
+ pHT_caps_ie = p;
+
+ ht_cap = true;
+ network_type |= WIRELESS_11_24N;
+
+ rtw_ht_use_default_setting(padapter);
+
+ /* Update HT Capabilities Info field */
+ if (!pmlmepriv->htpriv.sgi_20m)
+ pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_SGI_20));
+
+ if (!pmlmepriv->htpriv.sgi_40m)
+ pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_SGI_40));
+
+ if (!TEST_FLAG(pmlmepriv->htpriv.ldpc_cap, LDPC_HT_ENABLE_RX))
+ pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_LDPC_CODING));
+
+ if (!TEST_FLAG(pmlmepriv->htpriv.stbc_cap, STBC_HT_ENABLE_TX))
+ pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_TX_STBC));
+
+ if (!TEST_FLAG(pmlmepriv->htpriv.stbc_cap, STBC_HT_ENABLE_RX))
+ pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_RX_STBC_3R));
+
+ /* Update A-MPDU Parameters field */
+ pht_cap->ampdu_params_info &= ~(IEEE80211_HT_CAP_AMPDU_FACTOR | IEEE80211_HT_CAP_AMPDU_DENSITY);
+
+ if ((psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_CCMP) ||
+ (psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_CCMP))
+ pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & (0x07 << 2));
+ else
+ pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & 0x00);
+
+ rtw_hal_get_def_var(padapter, HW_VAR_MAX_RX_AMPDU_FACTOR, &max_rx_ampdu_factor);
+ pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_FACTOR & max_rx_ampdu_factor); /* set Max Rx AMPDU size to 64K */
+
+ memcpy(&(pmlmeinfo->HT_caps), pht_cap, sizeof(struct HT_caps_element));
+
+ /* Update Supported MCS Set field */
+ {
+ struct hal_spec_t *hal_spec = GET_HAL_SPEC(padapter);
+ u8 rx_nss = 0;
+ int i;
+
+ rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
+ rx_nss = rtw_min(rf_type_to_rf_rx_cnt(rf_type), hal_spec->rx_nss_num);
+
+ /* RX MCS Bitmask */
+ switch (rx_nss) {
+ case 1:
+ set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_1R);
+ break;
+ case 2:
+ set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_2R);
+ break;
+ case 3:
+ set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_3R);
+ break;
+ case 4:
+ set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_4R);
+ break;
+ default:
+ RTW_WARN("rf_type:%d or rx_nss:%u is not expected\n", rf_type, hal_spec->rx_nss_num);
+ }
+ for (i = 0; i < 10; i++)
+ *(HT_CAP_ELE_RX_MCS_MAP(pht_cap) + i) &= padapter->mlmeextpriv.default_supported_mcs_set[i];
+ }
+
+#ifdef CONFIG_BEAMFORMING
+ /* Use registry value to enable HT Beamforming. */
+ /* ToDo: use configure file to set these capability. */
+ pht_cap->tx_BF_cap_info = 0;
+
+ /* HT Beamformer */
+ if (TEST_FLAG(pmlmepriv->htpriv.beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE)) {
+ /* Transmit NDP Capable */
+ SET_HT_CAP_TXBF_TRANSMIT_NDP_CAP(pht_cap, 1);
+ /* Explicit Compressed Steering Capable */
+ SET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP(pht_cap, 1);
+ /* Compressed Steering Number Antennas */
+ SET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pht_cap, 1);
+ rtw_hal_get_def_var(padapter, HAL_DEF_BEAMFORMER_CAP, (u8 *)&rf_num);
+ SET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS(pht_cap, rf_num);
+ }
+
+ /* HT Beamformee */
+ if (TEST_FLAG(pmlmepriv->htpriv.beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE)) {
+ /* Receive NDP Capable */
+ SET_HT_CAP_TXBF_RECEIVE_NDP_CAP(pht_cap, 1);
+ /* Explicit Compressed Beamforming Feedback Capable */
+ SET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP(pht_cap, 2);
+ rtw_hal_get_def_var(padapter, HAL_DEF_BEAMFORMEE_CAP, (u8 *)&rf_num);
+ SET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pht_cap, rf_num);
+ }
+#endif /* CONFIG_BEAMFORMING */
+
+ memcpy(&pmlmepriv->htpriv.ht_cap, p + 2, ie_len);
+
+ if (0) {
+ RTW_INFO(FUNC_ADPT_FMT" HT_CAP_IE driver masked:\n", FUNC_ADPT_ARG(padapter));
+ dump_ht_cap_ie_content(RTW_DBGDUMP, p + 2, ie_len);
+ }
+ }
+
+ /* parsing HT_INFO_IE */
+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
+ if (p && ie_len > 0)
+ pHT_info_ie = p;
+ switch (network_type) {
+ case WIRELESS_11B:
+ pbss_network->NetworkTypeInUse = Ndis802_11DS;
+ break;
+ case WIRELESS_11G:
+ case WIRELESS_11BG:
+ case WIRELESS_11G_24N:
+ case WIRELESS_11BG_24N:
+ pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
+ break;
+ case WIRELESS_11A:
+ pbss_network->NetworkTypeInUse = Ndis802_11OFDM5;
+ break;
+ default:
+ pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
+ break;
+ }
+
+ pmlmepriv->cur_network.network_type = network_type;
+
+ pmlmepriv->htpriv.ht_option = false;
+
+ if ((psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_TKIP) ||
+ (psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_TKIP)) {
+ /* todo: */
+ /* ht_cap = false; */
+ }
+
+ /* ht_cap */
+ if (pregistrypriv->ht_enable && ht_cap ) {
+ pmlmepriv->htpriv.ht_option = true;
+ pmlmepriv->qospriv.qos_option = 1;
+
+ pmlmepriv->htpriv.ampdu_enable = pregistrypriv->ampdu_enable ? true : false;
+
+ HT_caps_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)pHT_caps_ie);
+
+ HT_info_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)pHT_info_ie);
+ }
+ if(pbss_network->Configuration.DSConfig <= 14 && padapter->registrypriv.wifi_spec == 1) {
+ uint len = 0;
+
+ SET_EXT_CAPABILITY_ELE_BSS_COEXIST(pmlmepriv->ext_capab_ie_data, 1);
+ pmlmepriv->ext_capab_ie_len = 10;
+ rtw_set_ie(pbss_network->IEs + pbss_network->IELength, EID_EXTCapability, 8, pmlmepriv->ext_capab_ie_data, &len);
+ pbss_network->IELength += pmlmepriv->ext_capab_ie_len;
+ }
+
+ pbss_network->Length = get_WLAN_BSSID_EX_sz((WLAN_BSSID_EX *)pbss_network);
+
+ rtw_ies_get_chbw(pbss_network->IEs + _BEACON_IE_OFFSET_, pbss_network->IELength - _BEACON_IE_OFFSET_
+ , &pmlmepriv->ori_ch, &pmlmepriv->ori_bw, &pmlmepriv->ori_offset);
+ rtw_warn_on(pmlmepriv->ori_ch == 0);
+
+ {
+ /* alloc sta_info for ap itself */
+
+ struct sta_info *sta;
+
+ sta = rtw_get_stainfo(&padapter->stapriv, pbss_network->MacAddress);
+ if (!sta) {
+ sta = rtw_alloc_stainfo(&padapter->stapriv, pbss_network->MacAddress);
+ if (sta == NULL)
+ return _FAIL;
+ }
+ }
+
+ rtw_startbss_cmd(padapter, RTW_CMDF_WAIT_ACK);
+ {
+ int sk_band = RTW_GET_SCAN_BAND_SKIP(padapter);
+
+ if (sk_band)
+ RTW_CLR_SCAN_BAND_SKIP(padapter, sk_band);
+ }
+
+ rtw_indicate_connect(padapter);
+
+ pmlmepriv->cur_network.join_res = true;/* for check if already set beacon */
+
+ /* update bc/mc sta_info */
+ /* update_bmc_sta(padapter); */
+
+ return ret;
+
+}
+
+#if CONFIG_RTW_MACADDR_ACL
+static void rtw_macaddr_acl_init(_adapter *adapter)
+{
+ struct sta_priv *stapriv = &adapter->stapriv;
+ struct wlan_acl_pool *acl = &stapriv->acl_list;
+ _queue *acl_node_q = &acl->acl_node_q;
+ int i;
+ unsigned long irqL;
+
+ _enter_critical_bh(&(acl_node_q->lock), &irqL);
+ INIT_LIST_HEAD(&(acl_node_q->queue));
+ acl->num = 0;
+ acl->mode = RTW_ACL_MODE_DISABLED;
+ for (i = 0; i < NUM_ACL; i++) {
+ INIT_LIST_HEAD(&acl->aclnode[i].list);
+ acl->aclnode[i].valid = false;
+ }
+ _exit_critical_bh(&(acl_node_q->lock), &irqL);
+}
+
+static void rtw_macaddr_acl_deinit(_adapter *adapter)
+{
+ struct sta_priv *stapriv = &adapter->stapriv;
+ struct wlan_acl_pool *acl = &stapriv->acl_list;
+ _queue *acl_node_q = &acl->acl_node_q;
+ unsigned long irqL;
+ _list *head, *list;
+ struct rtw_wlan_acl_node *acl_node;
+
+ _enter_critical_bh(&(acl_node_q->lock), &irqL);
+ head = get_list_head(acl_node_q);
+ list = get_next(head);
+ while (!rtw_end_of_queue_search(head, list)) {
+ acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
+ list = get_next(list);
+
+ if (acl_node->valid ) {
+ acl_node->valid = false;
+ list_del_init(&acl_node->list);
+ acl->num--;
+ }
+ }
+ _exit_critical_bh(&(acl_node_q->lock), &irqL);
+
+ rtw_warn_on(acl->num);
+ acl->mode = RTW_ACL_MODE_DISABLED;
+}
+
+void rtw_set_macaddr_acl(_adapter *adapter, int mode)
+{
+ struct sta_priv *stapriv = &adapter->stapriv;
+ struct wlan_acl_pool *acl = &stapriv->acl_list;
+
+ RTW_INFO(FUNC_ADPT_FMT" mode=%d\n", FUNC_ADPT_ARG(adapter), mode);
+
+ acl->mode = mode;
+
+ if (mode == RTW_ACL_MODE_DISABLED)
+ rtw_macaddr_acl_deinit(adapter);
+}
+
+int rtw_acl_add_sta(_adapter *adapter, const u8 *addr)
+{
+ unsigned long irqL;
+ _list *list, *head;
+ u8 existed = 0;
+ int i = -1, ret = 0;
+ struct rtw_wlan_acl_node *acl_node;
+ struct sta_priv *stapriv = &adapter->stapriv;
+ struct wlan_acl_pool *acl = &stapriv->acl_list;
+ _queue *acl_node_q = &acl->acl_node_q;
+
+ _enter_critical_bh(&(acl_node_q->lock), &irqL);
+
+ head = get_list_head(acl_node_q);
+ list = get_next(head);
+
+ /* search for existed entry */
+ while (rtw_end_of_queue_search(head, list) == false) {
+ acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
+ list = get_next(list);
+
+ if (!memcmp(acl_node->addr, addr, ETH_ALEN)) {
+ if (acl_node->valid ) {
+ existed = 1;
+ break;
+ }
+ }
+ }
+ if (existed)
+ goto release_lock;
+
+ if (acl->num >= NUM_ACL)
+ goto release_lock;
+
+ /* find empty one and use */
+ for (i = 0; i < NUM_ACL; i++) {
+
+ acl_node = &acl->aclnode[i];
+ if (acl_node->valid == false) {
+
+ INIT_LIST_HEAD(&acl_node->list);
+ memcpy(acl_node->addr, addr, ETH_ALEN);
+ acl_node->valid = true;
+
+ list_add_tail(&acl_node->list, get_list_head(acl_node_q));
+ acl->num++;
+ break;
+ }
+ }
+
+release_lock:
+ _exit_critical_bh(&(acl_node_q->lock), &irqL);
+
+ if (!existed && (i < 0 || i >= NUM_ACL))
+ ret = -1;
+
+ RTW_INFO(FUNC_ADPT_FMT" "MAC_FMT" %s (acl_num=%d)\n"
+ , FUNC_ADPT_ARG(adapter), MAC_ARG(addr)
+ , (existed ? "existed" : ((i < 0 || i >= NUM_ACL) ? "no room" : "added"))
+ , acl->num);
+
+ return ret;
+}
+
+int rtw_acl_remove_sta(_adapter *adapter, const u8 *addr)
+{
+ unsigned long irqL;
+ _list *list, *head;
+ int ret = 0;
+ struct rtw_wlan_acl_node *acl_node;
+ struct sta_priv *stapriv = &adapter->stapriv;
+ struct wlan_acl_pool *acl = &stapriv->acl_list;
+ _queue *acl_node_q = &acl->acl_node_q;
+ u8 is_baddr = is_broadcast_mac_addr(addr);
+ u8 match = 0;
+
+ _enter_critical_bh(&(acl_node_q->lock), &irqL);
+
+ head = get_list_head(acl_node_q);
+ list = get_next(head);
+
+ while (rtw_end_of_queue_search(head, list) == false) {
+ acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
+ list = get_next(list);
+
+ if (is_baddr || !memcmp(acl_node->addr, addr, ETH_ALEN)) {
+ if (acl_node->valid ) {
+ acl_node->valid = false;
+ list_del_init(&acl_node->list);
+ acl->num--;
+ match = 1;
+ }
+ }
+ }
+
+ _exit_critical_bh(&(acl_node_q->lock), &irqL);
+
+ RTW_INFO(FUNC_ADPT_FMT" "MAC_FMT" %s (acl_num=%d)\n"
+ , FUNC_ADPT_ARG(adapter), MAC_ARG(addr)
+ , is_baddr ? "clear all" : (match ? "match" : "no found")
+ , acl->num);
+
+ return ret;
+}
+#endif /* CONFIG_RTW_MACADDR_ACL */
+
+u8 rtw_ap_set_pairwise_key(_adapter *padapter, struct sta_info *psta)
+{
+ struct cmd_obj *ph2c;
+ struct set_stakey_parm *psetstakey_para;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (ph2c == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ psetstakey_para = (struct set_stakey_parm *)rtw_zmalloc(sizeof(struct set_stakey_parm));
+ if (psetstakey_para == NULL) {
+ rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
+
+
+ psetstakey_para->algorithm = (u8)psta->dot118021XPrivacy;
+
+ memcpy(psetstakey_para->addr, psta->hwaddr, ETH_ALEN);
+
+ memcpy(psetstakey_para->key, &psta->dot118021x_UncstKey, 16);
+
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+
+ return res;
+
+}
+
+static int rtw_ap_set_key(_adapter *padapter, u8 *key, u8 alg, int keyid, u8 set_tx)
+{
+ u8 keylen;
+ struct cmd_obj *pcmd;
+ struct setkey_parm *psetkeyparm;
+ struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
+ int res = _SUCCESS;
+
+ /* RTW_INFO("%s\n", __func__); */
+
+ pcmd = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (pcmd == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+ psetkeyparm = (struct setkey_parm *)rtw_zmalloc(sizeof(struct setkey_parm));
+ if (psetkeyparm == NULL) {
+ rtw_mfree((unsigned char *)pcmd, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ memset(psetkeyparm, 0, sizeof(struct setkey_parm));
+
+ psetkeyparm->keyid = (u8)keyid;
+ if (is_wep_enc(alg))
+ padapter->securitypriv.key_mask |= BIT(psetkeyparm->keyid);
+
+ psetkeyparm->algorithm = alg;
+
+ psetkeyparm->set_tx = set_tx;
+
+ switch (alg) {
+ case _WEP40_:
+ keylen = 5;
+ break;
+ case _WEP104_:
+ keylen = 13;
+ break;
+ case _TKIP_:
+ case _TKIP_WTMIC_:
+ case _AES_:
+ default:
+ keylen = 16;
+ }
+
+ memcpy(&(psetkeyparm->key[0]), key, keylen);
+
+ pcmd->cmdcode = _SetKey_CMD_;
+ pcmd->parmbuf = (u8 *)psetkeyparm;
+ pcmd->cmdsz = (sizeof(struct setkey_parm));
+ pcmd->rsp = NULL;
+ pcmd->rspsz = 0;
+
+
+ INIT_LIST_HEAD(&pcmd->list);
+
+ res = rtw_enqueue_cmd(pcmdpriv, pcmd);
+
+exit:
+
+ return res;
+}
+
+int rtw_ap_set_group_key(_adapter *padapter, u8 *key, u8 alg, int keyid)
+{
+ RTW_INFO("%s\n", __func__);
+
+ return rtw_ap_set_key(padapter, key, alg, keyid, 1);
+}
+
+int rtw_ap_set_wep_key(_adapter *padapter, u8 *key, u8 keylen, int keyid, u8 set_tx)
+{
+ u8 alg;
+
+ switch (keylen) {
+ case 5:
+ alg = _WEP40_;
+ break;
+ case 13:
+ alg = _WEP104_;
+ break;
+ default:
+ alg = _NO_PRIVACY_;
+ }
+
+ RTW_INFO("%s\n", __func__);
+
+ return rtw_ap_set_key(padapter, key, alg, keyid, set_tx);
+}
+
+static u8 rtw_ap_bmc_frames_hdl(_adapter *padapter)
+{
+#define HIQ_XMIT_COUNTS (6)
+ unsigned long irqL;
+ struct sta_info *psta_bmc;
+ _list *xmitframe_plist, *xmitframe_phead;
+ struct xmit_frame *pxmitframe = NULL;
+ struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ bool update_tim = false;
+
+
+ if (padapter->registrypriv.wifi_spec != 1)
+ return H2C_SUCCESS;
+
+
+ psta_bmc = rtw_get_bcmc_stainfo(padapter);
+ if (!psta_bmc)
+ return H2C_SUCCESS;
+
+
+ _enter_critical_bh(&pxmitpriv->lock, &irqL);
+
+ if ((pstapriv->tim_bitmap & BIT(0)) && (psta_bmc->sleepq_len > 0)) {
+ int tx_counts = 0;
+
+ _update_beacon(padapter, _TIM_IE_, NULL, false, "update TIM with TIB=1");
+
+ RTW_INFO("sleepq_len of bmc_sta = %d\n", psta_bmc->sleepq_len);
+
+ xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
+ xmitframe_plist = get_next(xmitframe_phead);
+
+ while ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == false) {
+ pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
+
+ xmitframe_plist = get_next(xmitframe_plist);
+
+ list_del_init(&pxmitframe->list);
+
+ psta_bmc->sleepq_len--;
+ tx_counts++;
+
+ if (psta_bmc->sleepq_len > 0)
+ pxmitframe->attrib.mdata = 1;
+ else
+ pxmitframe->attrib.mdata = 0;
+
+ if (tx_counts == HIQ_XMIT_COUNTS)
+ pxmitframe->attrib.mdata = 0;
+
+ pxmitframe->attrib.triggered = 1;
+
+ if (xmitframe_hiq_filter(pxmitframe) )
+ pxmitframe->attrib.qsel = QSLT_HIGH;/*HIQ*/
+
+ rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
+
+ if (tx_counts == HIQ_XMIT_COUNTS)
+ break;
+
+ }
+
+ } else {
+ if (psta_bmc->sleepq_len == 0) {
+
+ /*RTW_INFO("sleepq_len of bmc_sta = %d\n", psta_bmc->sleepq_len);*/
+
+ if (pstapriv->tim_bitmap & BIT(0))
+ update_tim = true;
+
+ pstapriv->tim_bitmap &= ~BIT(0);
+ pstapriv->sta_dz_bitmap &= ~BIT(0);
+
+ if (update_tim ) {
+ RTW_INFO("clear TIB\n");
+ _update_beacon(padapter, _TIM_IE_, NULL, true, "bmc sleepq and HIQ empty");
+ }
+ }
+ }
+
+ _exit_critical_bh(&pxmitpriv->lock, &irqL);
+
+ return H2C_SUCCESS;
+}
+
+#ifdef CONFIG_NATIVEAP_MLME
+
+static void associated_stainfo_update(_adapter *padapter, struct sta_info *psta, u32 sta_info_type)
+{
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+
+ RTW_INFO("%s: "MAC_FMT", updated_type=0x%x\n", __func__, MAC_ARG(psta->hwaddr), sta_info_type);
+
+ if (sta_info_type & STA_INFO_UPDATE_BW) {
+
+ if ((psta->flags & WLAN_STA_HT) && !psta->ht_20mhz_set) {
+ if (pmlmepriv->sw_to_20mhz) {
+ psta->bw_mode = CHANNEL_WIDTH_20;
+ /*psta->htpriv.ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;*/
+ psta->htpriv.sgi_40m = false;
+ } else {
+ /*TODO: Switch back to 40MHZ?80MHZ*/
+ }
+ }
+ }
+
+ /*
+ if (sta_info_type & STA_INFO_UPDATE_RATE) {
+
+ }
+ */
+
+ if (sta_info_type & STA_INFO_UPDATE_PROTECTION_MODE)
+ VCS_update(padapter, psta);
+
+ /*
+ if (sta_info_type & STA_INFO_UPDATE_CAP) {
+
+ }
+
+ if (sta_info_type & STA_INFO_UPDATE_HT_CAP) {
+
+ }
+
+ if (sta_info_type & STA_INFO_UPDATE_VHT_CAP) {
+
+ }
+ */
+
+}
+
+static void update_bcn_ext_capab_ie(_adapter *padapter)
+{
+ sint ie_len = 0;
+ unsigned char *pbuf;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
+ u8 *ie = pnetwork->IEs;
+ u8 null_extcap_data[8] = {0};
+
+ pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_CAP_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
+ if (pbuf && ie_len > 0)
+ rtw_remove_bcn_ie(padapter, pnetwork, _EXT_CAP_IE_);
+
+ if ((pmlmepriv->ext_capab_ie_len > 0) &&
+ (!memcmp(pmlmepriv->ext_capab_ie_data, null_extcap_data, sizeof(null_extcap_data)) == false))
+ rtw_add_bcn_ie(padapter, pnetwork, _EXT_CAP_IE_, pmlmepriv->ext_capab_ie_data, pmlmepriv->ext_capab_ie_len);
+
+}
+
+static void update_bcn_fixed_ie(_adapter *padapter)
+{
+ RTW_INFO("%s\n", __func__);
+
+}
+
+static void update_bcn_erpinfo_ie(_adapter *padapter)
+{
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
+ unsigned char *p, *ie = pnetwork->IEs;
+ u32 len = 0;
+
+ RTW_INFO("%s, ERP_enable=%d\n", __func__, pmlmeinfo->ERP_enable);
+
+ if (!pmlmeinfo->ERP_enable)
+ return;
+
+ /* parsing ERP_IE */
+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
+ if (p && len > 0) {
+ PNDIS_802_11_VARIABLE_IEs pIE = (PNDIS_802_11_VARIABLE_IEs)p;
+
+ if (pmlmepriv->num_sta_non_erp == 1)
+ pIE->data[0] |= RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION;
+ else
+ pIE->data[0] &= ~(RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION);
+
+ if (pmlmepriv->num_sta_no_short_preamble > 0)
+ pIE->data[0] |= RTW_ERP_INFO_BARKER_PREAMBLE_MODE;
+ else
+ pIE->data[0] &= ~(RTW_ERP_INFO_BARKER_PREAMBLE_MODE);
+
+ ERP_IE_handler(padapter, pIE);
+ }
+
+}
+
+static void update_bcn_htcap_ie(_adapter *padapter)
+{
+ RTW_INFO("%s\n", __func__);
+
+}
+
+static void update_bcn_htinfo_ie(_adapter *padapter)
+{
+ /*
+ u8 beacon_updated = false;
+ u32 sta_info_update_type = STA_INFO_UPDATE_NONE;
+ */
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
+ unsigned char *p, *ie = pnetwork->IEs;
+ u32 len = 0;
+
+ if (pmlmepriv->htpriv.ht_option == false)
+ return;
+
+ if (pmlmeinfo->HT_info_enable != 1)
+ return;
+
+
+ RTW_INFO("%s current operation mode=0x%X\n",
+ __func__, pmlmepriv->ht_op_mode);
+
+ RTW_INFO("num_sta_40mhz_intolerant(%d), 20mhz_width_req(%d), intolerant_ch_rpt(%d), olbc(%d)\n",
+ pmlmepriv->num_sta_40mhz_intolerant, pmlmepriv->ht_20mhz_width_req, pmlmepriv->ht_intolerant_ch_reported, ATOMIC_READ(&pmlmepriv->olbc));
+
+ /*parsing HT_INFO_IE, currently only update ht_op_mode - pht_info->infos[1] & pht_info->infos[2] for wifi logo test*/
+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
+ if (p && len > 0) {
+ struct HT_info_element *pht_info = NULL;
+
+ pht_info = (struct HT_info_element *)(p + 2);
+
+ /* for STA Channel Width/Secondary Channel Offset*/
+ if ((pmlmepriv->sw_to_20mhz == 0) && (pmlmeext->cur_channel <= 14)) {
+ if ((pmlmepriv->num_sta_40mhz_intolerant > 0) || (pmlmepriv->ht_20mhz_width_req )
+ || (pmlmepriv->ht_intolerant_ch_reported ) || (ATOMIC_READ(&pmlmepriv->olbc) == true)) {
+ SET_HT_OP_ELE_2ND_CHL_OFFSET(pht_info, 0);
+ SET_HT_OP_ELE_STA_CHL_WIDTH(pht_info, 0);
+
+ pmlmepriv->sw_to_20mhz = 1;
+ /*
+ sta_info_update_type |= STA_INFO_UPDATE_BW;
+ beacon_updated = true;
+ */
+
+ RTW_INFO("%s:switching to 20Mhz\n", __func__);
+
+ /*TODO : cur_bwmode/cur_ch_offset switches to 20Mhz*/
+ }
+ } else {
+
+ if ((pmlmepriv->num_sta_40mhz_intolerant == 0) && (pmlmepriv->ht_20mhz_width_req == false)
+ && (pmlmepriv->ht_intolerant_ch_reported == false) && (ATOMIC_READ(&pmlmepriv->olbc) == false)) {
+
+ if (pmlmeext->cur_bwmode >= CHANNEL_WIDTH_40) {
+
+ SET_HT_OP_ELE_STA_CHL_WIDTH(pht_info, 1);
+
+ SET_HT_OP_ELE_2ND_CHL_OFFSET(pht_info,
+ (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER) ?
+ HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE : HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW);
+
+ pmlmepriv->sw_to_20mhz = 0;
+ /*
+ sta_info_update_type |= STA_INFO_UPDATE_BW;
+ beacon_updated = true;
+ */
+
+ RTW_INFO("%s:switching back to 40Mhz\n", __func__);
+ }
+ }
+ }
+
+ /* to update ht_op_mode*/
+ *(__le16 *)(pht_info->infos + 1) = cpu_to_le16(pmlmepriv->ht_op_mode);
+
+ }
+
+ /*associated_clients_update(padapter, beacon_updated, sta_info_update_type);*/
+
+}
+
+static void update_bcn_rsn_ie(_adapter *padapter)
+{
+ RTW_INFO("%s\n", __func__);
+
+}
+
+static void update_bcn_wpa_ie(_adapter *padapter)
+{
+ RTW_INFO("%s\n", __func__);
+
+}
+
+static void update_bcn_wmm_ie(_adapter *padapter)
+{
+ RTW_INFO("%s\n", __func__);
+
+}
+
+static void update_bcn_wps_ie(_adapter *padapter)
+{
+ u8 *pwps_ie = NULL, *pwps_ie_src, *premainder_ie, *pbackup_remainder_ie = NULL;
+ uint wps_ielen = 0, wps_offset, remainder_ielen;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
+ unsigned char *ie = pnetwork->IEs;
+ u32 ielen = pnetwork->IELength;
+
+
+ RTW_INFO("%s\n", __func__);
+
+ pwps_ie = rtw_get_wps_ie(ie + _FIXED_IE_LENGTH_, ielen - _FIXED_IE_LENGTH_, NULL, &wps_ielen);
+
+ if (pwps_ie == NULL || wps_ielen == 0)
+ return;
+
+ pwps_ie_src = pmlmepriv->wps_beacon_ie;
+ if (pwps_ie_src == NULL)
+ return;
+
+ wps_offset = (uint)(pwps_ie - ie);
+
+ premainder_ie = pwps_ie + wps_ielen;
+
+ remainder_ielen = ielen - wps_offset - wps_ielen;
+
+ if (remainder_ielen > 0) {
+ pbackup_remainder_ie = rtw_malloc(remainder_ielen);
+ if (pbackup_remainder_ie)
+ memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
+ }
+
+ wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */
+ if ((wps_offset + wps_ielen + 2 + remainder_ielen) <= MAX_IE_SZ) {
+ memcpy(pwps_ie, pwps_ie_src, wps_ielen + 2);
+ pwps_ie += (wps_ielen + 2);
+
+ if (pbackup_remainder_ie)
+ memcpy(pwps_ie, pbackup_remainder_ie, remainder_ielen);
+
+ /* update IELength */
+ pnetwork->IELength = wps_offset + (wps_ielen + 2) + remainder_ielen;
+ }
+
+ if (pbackup_remainder_ie)
+ rtw_mfree(pbackup_remainder_ie, remainder_ielen);
+
+ /* deal with the case without set_tx_beacon_cmd() in update_beacon() */
+#if defined(CONFIG_INTERRUPT_BASED_TXBCN)
+ if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) {
+ u8 sr = 0;
+ rtw_get_wps_attr_content(pwps_ie_src, wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL);
+
+ if (sr) {
+ set_fwstate(pmlmepriv, WIFI_UNDER_WPS);
+ RTW_INFO("%s, set WIFI_UNDER_WPS\n", __func__);
+ } else {
+ clr_fwstate(pmlmepriv, WIFI_UNDER_WPS);
+ RTW_INFO("%s, clr WIFI_UNDER_WPS\n", __func__);
+ }
+ }
+#endif
+}
+
+static void update_bcn_p2p_ie(_adapter *padapter)
+{
+
+}
+
+static void update_bcn_vendor_spec_ie(_adapter *padapter, u8 *oui)
+{
+ RTW_INFO("%s\n", __func__);
+
+ if (!memcmp(RTW_WPA_OUI, oui, 4))
+ update_bcn_wpa_ie(padapter);
+ else if (!memcmp(WMM_OUI, oui, 4))
+ update_bcn_wmm_ie(padapter);
+ else if (!memcmp(WPS_OUI, oui, 4))
+ update_bcn_wps_ie(padapter);
+ else if (!memcmp(P2P_OUI, oui, 4))
+ update_bcn_p2p_ie(padapter);
+ else
+ RTW_INFO("unknown OUI type!\n");
+
+
+}
+
+void _update_beacon(_adapter *padapter, u8 ie_id, u8 *oui, u8 tx, const char *tag)
+{
+ unsigned long irqL;
+ struct mlme_priv *pmlmepriv;
+ struct mlme_ext_priv *pmlmeext;
+ /* struct mlme_ext_info *pmlmeinfo; */
+
+ /* RTW_INFO("%s\n", __func__); */
+
+ if (!padapter)
+ return;
+
+ pmlmepriv = &(padapter->mlmepriv);
+ pmlmeext = &(padapter->mlmeextpriv);
+ /* pmlmeinfo = &(pmlmeext->mlmext_info); */
+
+ if (false == pmlmeext->bstart_bss)
+ return;
+
+ _enter_critical_bh(&pmlmepriv->bcn_update_lock, &irqL);
+
+ switch (ie_id) {
+ case 0xFF:
+
+ update_bcn_fixed_ie(padapter);/* 8: TimeStamp, 2: Beacon Interval 2:Capability */
+
+ break;
+
+ case _TIM_IE_:
+
+ update_BCNTIM(padapter);
+
+ break;
+
+ case _ERPINFO_IE_:
+
+ update_bcn_erpinfo_ie(padapter);
+
+ break;
+
+ case _HT_CAPABILITY_IE_:
+
+ update_bcn_htcap_ie(padapter);
+
+ break;
+
+ case _RSN_IE_2_:
+
+ update_bcn_rsn_ie(padapter);
+
+ break;
+
+ case _HT_ADD_INFO_IE_:
+
+ update_bcn_htinfo_ie(padapter);
+
+ break;
+
+ case _EXT_CAP_IE_:
+
+ update_bcn_ext_capab_ie(padapter);
+
+ break;
+
+ case _VENDOR_SPECIFIC_IE_:
+
+ update_bcn_vendor_spec_ie(padapter, oui);
+
+ break;
+
+ default:
+ break;
+ }
+
+ pmlmepriv->update_bcn = true;
+
+ _exit_critical_bh(&pmlmepriv->bcn_update_lock, &irqL);
+
+#ifndef CONFIG_INTERRUPT_BASED_TXBCN
+ if (tx) {
+ /* send_beacon(padapter); */ /* send_beacon must execute on TSR level */
+ if (0)
+ RTW_INFO(FUNC_ADPT_FMT" ie_id:%u - %s\n", FUNC_ADPT_ARG(padapter), ie_id, tag);
+ set_tx_beacon_cmd(padapter);
+ }
+#endif /* !CONFIG_INTERRUPT_BASED_TXBCN */
+}
+
+void rtw_process_public_act_bsscoex(_adapter *padapter, u8 *pframe, uint frame_len)
+{
+ struct sta_info *psta;
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ u8 beacon_updated = false;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
+ uint frame_body_len = frame_len - sizeof(struct rtw_ieee80211_hdr_3addr);
+ u8 category, action;
+
+ psta = rtw_get_stainfo(pstapriv, get_addr2_ptr(pframe));
+ if (psta == NULL)
+ return;
+
+
+ category = frame_body[0];
+ action = frame_body[1];
+
+ if (frame_body_len > 0) {
+ if ((frame_body[2] == EID_BSSCoexistence) && (frame_body[3] > 0)) {
+ u8 ie_data = frame_body[4];
+
+ if (ie_data & RTW_WLAN_20_40_BSS_COEX_40MHZ_INTOL) {
+ if (psta->ht_40mhz_intolerant == 0) {
+ psta->ht_40mhz_intolerant = 1;
+ pmlmepriv->num_sta_40mhz_intolerant++;
+ beacon_updated = true;
+ }
+ } else if (ie_data & RTW_WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ) {
+ if (pmlmepriv->ht_20mhz_width_req == false) {
+ pmlmepriv->ht_20mhz_width_req = true;
+ beacon_updated = true;
+ }
+ } else
+ beacon_updated = false;
+ }
+ }
+
+ if (frame_body_len > 8) {
+ /* if EID_BSSIntolerantChlReport ie exists */
+ if ((frame_body[5] == EID_BSSIntolerantChlReport) && (frame_body[6] > 0)) {
+ /*todo:*/
+ if (pmlmepriv->ht_intolerant_ch_reported == false) {
+ pmlmepriv->ht_intolerant_ch_reported = true;
+ beacon_updated = true;
+ }
+ }
+ }
+
+ if (beacon_updated) {
+
+ update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, true);
+
+ associated_stainfo_update(padapter, psta, STA_INFO_UPDATE_BW);
+ }
+
+
+
+}
+
+void rtw_process_ht_action_smps(_adapter *padapter, u8 *ta, u8 ctrl_field)
+{
+ u8 e_field, m_field;
+ struct sta_info *psta;
+ struct sta_priv *pstapriv = &padapter->stapriv;
+
+ psta = rtw_get_stainfo(pstapriv, ta);
+ if (psta == NULL)
+ return;
+
+ e_field = (ctrl_field & BIT(0)) ? 1 : 0;
+ m_field = (ctrl_field & BIT(1)) ? 1 : 0;
+
+ if (e_field) {
+
+ /* enable */
+ /* 0:static SMPS, 1:dynamic SMPS, 3:SMPS disabled, 2:reserved*/
+
+ if (m_field) /*mode*/
+ psta->htpriv.smps_cap = 1;
+ else
+ psta->htpriv.smps_cap = 0;
+ } else {
+ /*disable*/
+ psta->htpriv.smps_cap = 3;
+ }
+
+ rtw_dm_ra_mask_wk_cmd(padapter, (u8 *)psta);
+
+}
+
+/*
+op_mode
+Set to 0 (HT pure) under the followign conditions
+ - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
+ - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
+Set to 1 (HT non-member protection) if there may be non-HT STAs
+ in both the primary and the secondary channel
+Set to 2 if only HT STAs are associated in BSS,
+ however and at least one 20 MHz HT STA is associated
+Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
+ (currently non-GF HT station is considered as non-HT STA also)
+*/
+int rtw_ht_operation_update(_adapter *padapter)
+{
+ u16 cur_op_mode, new_op_mode;
+ int op_mode_changes = 0;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
+
+ if (pmlmepriv->htpriv.ht_option == false)
+ return 0;
+
+ /*if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
+ return 0;*/
+
+ RTW_INFO("%s current operation mode=0x%X\n",
+ __func__, pmlmepriv->ht_op_mode);
+
+ if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
+ && pmlmepriv->num_sta_ht_no_gf) {
+ pmlmepriv->ht_op_mode |=
+ HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
+ op_mode_changes++;
+ } else if ((pmlmepriv->ht_op_mode &
+ HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
+ pmlmepriv->num_sta_ht_no_gf == 0) {
+ pmlmepriv->ht_op_mode &=
+ ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
+ op_mode_changes++;
+ }
+
+ if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
+ (pmlmepriv->num_sta_no_ht || ATOMIC_READ(&pmlmepriv->olbc_ht))) {
+ pmlmepriv->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
+ op_mode_changes++;
+ } else if ((pmlmepriv->ht_op_mode &
+ HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
+ (pmlmepriv->num_sta_no_ht == 0 && !ATOMIC_READ(&pmlmepriv->olbc_ht))) {
+ pmlmepriv->ht_op_mode &=
+ ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
+ op_mode_changes++;
+ }
+
+ /* Note: currently we switch to the MIXED op mode if HT non-greenfield
+ * station is associated. Probably it's a theoretical case, since
+ * it looks like all known HT STAs support greenfield.
+ */
+ new_op_mode = 0;
+ if (pmlmepriv->num_sta_no_ht /*||
+ (pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)*/)
+ new_op_mode = OP_MODE_MIXED;
+ else if ((phtpriv_ap->ht_cap.cap_info & cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH))
+ && pmlmepriv->num_sta_ht_20mhz)
+ new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
+ else if (ATOMIC_READ(&pmlmepriv->olbc_ht))
+ new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
+ else
+ new_op_mode = OP_MODE_PURE;
+
+ cur_op_mode = pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
+ if (cur_op_mode != new_op_mode) {
+ pmlmepriv->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
+ pmlmepriv->ht_op_mode |= new_op_mode;
+ op_mode_changes++;
+ }
+
+ RTW_INFO("%s new operation mode=0x%X changes=%d\n",
+ __func__, pmlmepriv->ht_op_mode, op_mode_changes);
+
+ return op_mode_changes;
+
+}
+
+void associated_clients_update(_adapter *padapter, u8 updated, u32 sta_info_type)
+{
+ /* update associcated stations cap. */
+ if (updated ) {
+ unsigned long irqL;
+ _list *phead, *plist;
+ struct sta_info *psta = NULL;
+ struct sta_priv *pstapriv = &padapter->stapriv;
+
+ _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+
+ phead = &pstapriv->asoc_list;
+ plist = get_next(phead);
+
+ /* check asoc_queue */
+ while ((rtw_end_of_queue_search(phead, plist)) == false) {
+ psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
+
+ plist = get_next(plist);
+
+ associated_stainfo_update(padapter, psta, sta_info_type);
+ }
+
+ _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+
+ }
+
+}
+
+/* called > TSR LEVEL for USB or SDIO Interface*/
+void bss_cap_update_on_sta_join(_adapter *padapter, struct sta_info *psta)
+{
+ u8 beacon_updated = false;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
+
+ if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) {
+ if (!psta->no_short_preamble_set) {
+ psta->no_short_preamble_set = 1;
+
+ pmlmepriv->num_sta_no_short_preamble++;
+
+ if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
+ (pmlmepriv->num_sta_no_short_preamble == 1)) {
+ beacon_updated = true;
+ update_beacon(padapter, 0xFF, NULL, true);
+ }
+
+ }
+ } else {
+ if (psta->no_short_preamble_set) {
+ psta->no_short_preamble_set = 0;
+
+ pmlmepriv->num_sta_no_short_preamble--;
+
+ if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
+ (pmlmepriv->num_sta_no_short_preamble == 0)) {
+ beacon_updated = true;
+ update_beacon(padapter, 0xFF, NULL, true);
+ }
+
+ }
+ }
+
+ if (psta->flags & WLAN_STA_NONERP) {
+ if (!psta->nonerp_set) {
+ psta->nonerp_set = 1;
+
+ pmlmepriv->num_sta_non_erp++;
+
+ if (pmlmepriv->num_sta_non_erp == 1) {
+ beacon_updated = true;
+ update_beacon(padapter, _ERPINFO_IE_, NULL, true);
+ }
+ }
+
+ } else {
+ if (psta->nonerp_set) {
+ psta->nonerp_set = 0;
+
+ pmlmepriv->num_sta_non_erp--;
+
+ if (pmlmepriv->num_sta_non_erp == 0) {
+ beacon_updated = true;
+ update_beacon(padapter, _ERPINFO_IE_, NULL, true);
+ }
+ }
+
+ }
+ if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT)) {
+ if (!psta->no_short_slot_time_set) {
+ psta->no_short_slot_time_set = 1;
+
+ pmlmepriv->num_sta_no_short_slot_time++;
+
+ if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
+ (pmlmepriv->num_sta_no_short_slot_time == 1)) {
+ beacon_updated = true;
+ update_beacon(padapter, 0xFF, NULL, true);
+ }
+
+ }
+ } else {
+ if (psta->no_short_slot_time_set) {
+ psta->no_short_slot_time_set = 0;
+
+ pmlmepriv->num_sta_no_short_slot_time--;
+
+ if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
+ (pmlmepriv->num_sta_no_short_slot_time == 0)) {
+ beacon_updated = true;
+ update_beacon(padapter, 0xFF, NULL, true);
+ }
+ }
+ }
+
+ if (psta->flags & WLAN_STA_HT) {
+ u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info);
+
+ RTW_INFO("HT: STA " MAC_FMT " HT Capabilities "
+ "Info: 0x%04x\n", MAC_ARG(psta->hwaddr), ht_capab);
+
+ if (psta->no_ht_set) {
+ psta->no_ht_set = 0;
+ pmlmepriv->num_sta_no_ht--;
+ }
+
+ if ((ht_capab & IEEE80211_HT_CAP_GRN_FLD) == 0) {
+ if (!psta->no_ht_gf_set) {
+ psta->no_ht_gf_set = 1;
+ pmlmepriv->num_sta_ht_no_gf++;
+ }
+ RTW_INFO("%s STA " MAC_FMT " - no "
+ "greenfield, num of non-gf stations %d\n",
+ __func__, MAC_ARG(psta->hwaddr),
+ pmlmepriv->num_sta_ht_no_gf);
+ }
+
+ if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH) == 0) {
+ if (!psta->ht_20mhz_set) {
+ psta->ht_20mhz_set = 1;
+ pmlmepriv->num_sta_ht_20mhz++;
+ }
+ RTW_INFO("%s STA " MAC_FMT " - 20 MHz HT, "
+ "num of 20MHz HT STAs %d\n",
+ __func__, MAC_ARG(psta->hwaddr),
+ pmlmepriv->num_sta_ht_20mhz);
+ }
+
+ } else {
+ if (!psta->no_ht_set) {
+ psta->no_ht_set = 1;
+ pmlmepriv->num_sta_no_ht++;
+ }
+ if (pmlmepriv->htpriv.ht_option ) {
+ RTW_INFO("%s STA " MAC_FMT
+ " - no HT, num of non-HT stations %d\n",
+ __func__, MAC_ARG(psta->hwaddr),
+ pmlmepriv->num_sta_no_ht);
+ }
+ }
+
+ if (rtw_ht_operation_update(padapter) > 0) {
+ update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, false);
+ update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, true);
+ /*beacon_updated = true;*/
+ }
+
+ /* update associcated stations cap. */
+ associated_clients_update(padapter, beacon_updated, STA_INFO_UPDATE_ALL);
+
+ RTW_INFO("%s, updated=%d\n", __func__, beacon_updated);
+
+}
+
+u8 bss_cap_update_on_sta_leave(_adapter *padapter, struct sta_info *psta)
+{
+ u8 beacon_updated = false;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
+
+ if (!psta)
+ return beacon_updated;
+
+ if (psta->no_short_preamble_set) {
+ psta->no_short_preamble_set = 0;
+ pmlmepriv->num_sta_no_short_preamble--;
+ if (pmlmeext->cur_wireless_mode > WIRELESS_11B
+ && pmlmepriv->num_sta_no_short_preamble == 0) {
+ beacon_updated = true;
+ update_beacon(padapter, 0xFF, NULL, true);
+ }
+ }
+
+ if (psta->nonerp_set) {
+ psta->nonerp_set = 0;
+ pmlmepriv->num_sta_non_erp--;
+ if (pmlmepriv->num_sta_non_erp == 0) {
+ beacon_updated = true;
+ update_beacon(padapter, _ERPINFO_IE_, NULL, true);
+ }
+ }
+
+ if (psta->no_short_slot_time_set) {
+ psta->no_short_slot_time_set = 0;
+ pmlmepriv->num_sta_no_short_slot_time--;
+ if (pmlmeext->cur_wireless_mode > WIRELESS_11B
+ && pmlmepriv->num_sta_no_short_slot_time == 0) {
+ beacon_updated = true;
+ update_beacon(padapter, 0xFF, NULL, true);
+ }
+ }
+
+ if (psta->no_ht_gf_set) {
+ psta->no_ht_gf_set = 0;
+ pmlmepriv->num_sta_ht_no_gf--;
+ }
+
+ if (psta->no_ht_set) {
+ psta->no_ht_set = 0;
+ pmlmepriv->num_sta_no_ht--;
+ }
+
+ if (psta->ht_20mhz_set) {
+ psta->ht_20mhz_set = 0;
+ pmlmepriv->num_sta_ht_20mhz--;
+ }
+
+ if (rtw_ht_operation_update(padapter) > 0) {
+ update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, false);
+ update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, true);
+ }
+
+ RTW_INFO("%s, updated=%d\n", __func__, beacon_updated);
+
+ return beacon_updated;
+}
+
+u8 ap_free_sta(_adapter *padapter, struct sta_info *psta, bool active, u16 reason, bool enqueue)
+{
+ unsigned long irqL;
+ u8 beacon_updated = false;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
+ struct sta_priv *pstapriv = &padapter->stapriv;
+
+ if (!psta)
+ return beacon_updated;
+
+ if (active ) {
+ /* tear down Rx AMPDU */
+ send_delba(padapter, 0, psta->hwaddr);/* recipient */
+
+ /* tear down TX AMPDU */
+ send_delba(padapter, 1, psta->hwaddr);/* */ /* originator */
+
+ issue_deauth(padapter, psta->hwaddr, reason);
+ }
+
+#ifdef CONFIG_BEAMFORMING
+ beamforming_wk_cmd(padapter, BEAMFORMING_CTRL_LEAVE, psta->hwaddr, ETH_ALEN, 1);
+#endif
+
+ psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
+ psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
+
+ /* clear cam entry / key */
+ rtw_clearstakey_cmd(padapter, psta, enqueue);
+
+
+ _enter_critical_bh(&psta->lock, &irqL);
+ psta->state &= ~_FW_LINKED;
+ _exit_critical_bh(&psta->lock, &irqL);
+
+#ifdef CONFIG_IOCTL_CFG80211
+ if (1) {
+#ifdef COMPAT_KERNEL_RELEASE
+ rtw_cfg80211_indicate_sta_disassoc(padapter, psta->hwaddr, reason);
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
+ rtw_cfg80211_indicate_sta_disassoc(padapter, psta->hwaddr, reason);
+#else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER) */
+ /* will call rtw_cfg80211_indicate_sta_disassoc() in cmd_thread for old API context */
+#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER) */
+ } else
+#endif /* CONFIG_IOCTL_CFG80211 */
+ {
+ rtw_indicate_sta_disassoc_event(padapter, psta);
+ }
+
+ report_del_sta_event(padapter, psta->hwaddr, reason, enqueue, false);
+
+ beacon_updated = bss_cap_update_on_sta_leave(padapter, psta);
+
+ /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
+ rtw_free_stainfo(padapter, psta);
+ /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
+
+
+ return beacon_updated;
+
+}
+
+int rtw_ap_inform_ch_switch(_adapter *padapter, u8 new_ch, u8 ch_offset)
+{
+ unsigned long irqL;
+ _list *phead, *plist;
+ int ret = 0;
+ struct sta_info *psta = NULL;
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+
+ if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
+ return ret;
+
+ RTW_INFO(FUNC_NDEV_FMT" with ch:%u, offset:%u\n",
+ FUNC_NDEV_ARG(padapter->pnetdev), new_ch, ch_offset);
+
+ _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+ phead = &pstapriv->asoc_list;
+ plist = get_next(phead);
+
+ /* for each sta in asoc_queue */
+ while ((rtw_end_of_queue_search(phead, plist)) == false) {
+ psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
+ plist = get_next(plist);
+
+ issue_action_spct_ch_switch(padapter, psta->hwaddr, new_ch, ch_offset);
+ psta->expire_to = ((pstapriv->expire_to * 2) > 5) ? 5 : (pstapriv->expire_to * 2);
+ }
+ _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+
+ issue_action_spct_ch_switch(padapter, bc_addr, new_ch, ch_offset);
+
+ return ret;
+}
+
+int rtw_sta_flush(_adapter *padapter, bool enqueue)
+{
+ unsigned long irqL;
+ _list *phead, *plist;
+ int ret = 0;
+ struct sta_info *psta = NULL;
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+ u8 flush_num = 0;
+ char flush_list[NUM_STA];
+ int i;
+
+ if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
+ return ret;
+
+ RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
+
+ /* pick sta from sta asoc_queue */
+ _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+ phead = &pstapriv->asoc_list;
+ plist = get_next(phead);
+ while ((rtw_end_of_queue_search(phead, plist)) == false) {
+ int stainfo_offset;
+
+ psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
+ plist = get_next(plist);
+
+ list_del_init(&psta->asoc_list);
+ pstapriv->asoc_list_cnt--;
+
+ stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
+ if (stainfo_offset_valid(stainfo_offset))
+ flush_list[flush_num++] = stainfo_offset;
+ else
+ rtw_warn_on(1);
+ }
+ _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+
+ /* call ap_free_sta() for each sta picked */
+ for (i = 0; i < flush_num; i++) {
+ psta = rtw_get_stainfo_by_offset(pstapriv, flush_list[i]);
+ ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING, enqueue);
+ }
+
+ issue_deauth(padapter, bc_addr, WLAN_REASON_DEAUTH_LEAVING);
+
+ associated_clients_update(padapter, true, STA_INFO_UPDATE_ALL);
+
+ return ret;
+}
+
+/* called > TSR LEVEL for USB or SDIO Interface*/
+void sta_info_update(_adapter *padapter, struct sta_info *psta)
+{
+ int flags = psta->flags;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+
+
+ /* update wmm cap. */
+ if (WLAN_STA_WME & flags)
+ psta->qos_option = 1;
+ else
+ psta->qos_option = 0;
+
+ if (pmlmepriv->qospriv.qos_option == 0)
+ psta->qos_option = 0;
+
+ /* update 802.11n ht cap. */
+ if (WLAN_STA_HT & flags) {
+ psta->htpriv.ht_option = true;
+ psta->qos_option = 1;
+
+ psta->htpriv.smps_cap = (le16_to_cpu(psta->htpriv.ht_cap.cap_info) &
+ IEEE80211_HT_CAP_SM_PS) >> 2;
+ } else
+ psta->htpriv.ht_option = false;
+
+ if (pmlmepriv->htpriv.ht_option == false)
+ psta->htpriv.ht_option = false;
+ update_sta_info_apmode(padapter, psta);
+}
+
+/* called >= TSR LEVEL for USB or SDIO Interface*/
+void ap_sta_info_defer_update(_adapter *padapter, struct sta_info *psta)
+{
+ if (psta->state & _FW_LINKED)
+ rtw_hal_update_ra_mask(psta, psta->rssi_level, true); /* DM_RATR_STA_INIT */
+}
+/* restore hw setting from sw data structures */
+void rtw_ap_restore_network(_adapter *padapter)
+{
+ struct mlme_priv *mlmepriv = &padapter->mlmepriv;
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ struct sta_info *psta;
+ struct security_priv *psecuritypriv = &(padapter->securitypriv);
+ unsigned long irqL;
+ _list *phead, *plist;
+ u8 chk_alive_num = 0;
+ char chk_alive_list[NUM_STA];
+ int i;
+
+ rtw_setopmode_cmd(padapter, Ndis802_11APMode, false);
+
+ set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
+
+ rtw_startbss_cmd(padapter, RTW_CMDF_DIRECTLY);
+
+ if ((padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_) ||
+ (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)) {
+ /* restore group key, WEP keys is restored in ips_leave() */
+ rtw_set_key(padapter, psecuritypriv, psecuritypriv->dot118021XGrpKeyid, 0, false);
+ }
+
+ _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+
+ phead = &pstapriv->asoc_list;
+ plist = get_next(phead);
+
+ while ((rtw_end_of_queue_search(phead, plist)) == false) {
+ int stainfo_offset;
+
+ psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
+ plist = get_next(plist);
+
+ stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
+ if (stainfo_offset_valid(stainfo_offset))
+ chk_alive_list[chk_alive_num++] = stainfo_offset;
+ }
+
+ _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+
+ for (i = 0; i < chk_alive_num; i++) {
+ psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
+
+ if (psta == NULL)
+ RTW_INFO(FUNC_ADPT_FMT" sta_info is null\n", FUNC_ADPT_ARG(padapter));
+ else if (psta->state & _FW_LINKED) {
+ rtw_sta_media_status_rpt(padapter, psta, 1);
+ Update_RA_Entry(padapter, psta);
+ /* pairwise key */
+ /* per sta pairwise key and settings */
+ if ((padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_) ||
+ (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_))
+ rtw_setstakey_cmd(padapter, psta, UNICAST_KEY, false);
+ }
+ }
+
+}
+
+void start_ap_mode(_adapter *padapter)
+{
+ int i;
+ struct sta_info *psta = NULL;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ struct security_priv *psecuritypriv = &padapter->securitypriv;
+
+ pmlmepriv->update_bcn = false;
+
+ /*init_mlme_ap_info(padapter);*/
+
+ pmlmeext->bstart_bss = false;
+
+ pmlmepriv->num_sta_non_erp = 0;
+
+ pmlmepriv->num_sta_no_short_slot_time = 0;
+
+ pmlmepriv->num_sta_no_short_preamble = 0;
+
+ pmlmepriv->num_sta_ht_no_gf = 0;
+ pmlmepriv->num_sta_no_ht = 0;
+ pmlmeinfo->HT_info_enable = 0;
+ pmlmeinfo->HT_caps_enable = 0;
+ pmlmeinfo->HT_enable = 0;
+
+ pmlmepriv->num_sta_ht_20mhz = 0;
+ pmlmepriv->num_sta_40mhz_intolerant = 0;
+ ATOMIC_SET(&pmlmepriv->olbc, false);
+ ATOMIC_SET(&pmlmepriv->olbc_ht, false);
+
+ pmlmepriv->ht_20mhz_width_req = false;
+ pmlmepriv->ht_intolerant_ch_reported = false;
+ pmlmepriv->ht_op_mode = 0;
+ pmlmepriv->sw_to_20mhz = 0;
+
+ memset(pmlmepriv->ext_capab_ie_data, 0, sizeof(pmlmepriv->ext_capab_ie_data));
+ pmlmepriv->ext_capab_ie_len = 0;
+
+#ifdef CONFIG_CONCURRENT_MODE
+ psecuritypriv->dot118021x_bmc_cam_id = INVALID_SEC_MAC_CAM_ID;
+#endif
+
+ for (i = 0 ; i < NUM_STA ; i++)
+ pstapriv->sta_aid[i] = NULL;
+
+#if CONFIG_RTW_MACADDR_ACL
+ rtw_macaddr_acl_init(padapter);
+#endif
+
+ psta = rtw_get_bcmc_stainfo(padapter);
+ /*_enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);*/
+ if (psta)
+ rtw_free_stainfo(padapter, psta);
+ /*_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);*/
+
+ rtw_init_bcmc_stainfo(padapter);
+
+ if (rtw_mi_get_ap_num(padapter))
+ RTW_SET_SCAN_BAND_SKIP(padapter, BAND_5G);
+
+}
+
+void stop_ap_mode(_adapter *padapter)
+{
+ unsigned long irqL;
+ struct sta_info *psta = NULL;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct dvobj_priv *pdvobj = padapter->dvobj;
+
+ RTW_INFO("%s -"ADPT_FMT"\n", __func__, ADPT_ARG(padapter));
+
+ pmlmepriv->update_bcn = false;
+ padapter->netif_up = false;
+
+ /* reset and init security priv , this can refine with rtw_reset_securitypriv */
+ memset((unsigned char *)&padapter->securitypriv, 0, sizeof(struct security_priv));
+ padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
+ padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
+
+#ifdef CONFIG_DFS_MASTER
+ rtw_dfs_master_status_apply(padapter, MLME_AP_STOPPED);
+#endif
+
+ /* free scan queue */
+ rtw_free_network_queue(padapter, true);
+
+#if CONFIG_RTW_MACADDR_ACL
+ rtw_macaddr_acl_deinit(padapter);
+#endif
+
+ rtw_sta_flush(padapter, true);
+
+ /* free_assoc_sta_resources */
+ rtw_free_all_stainfo(padapter);
+
+ psta = rtw_get_bcmc_stainfo(padapter);
+ /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
+ rtw_free_stainfo(padapter, psta);
+ /*_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);*/
+
+ rtw_free_mlme_priv_ie_data(pmlmepriv);
+
+#ifdef CONFIG_SWTIMER_BASED_TXBCN
+ if (pmlmeext->bstart_bss ) {
+ _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
+ pdvobj->nr_ap_if--;
+ if (pdvobj->nr_ap_if > 0)
+ pdvobj->inter_bcn_space = DEFAULT_BCN_INTERVAL / pdvobj->nr_ap_if;
+ else
+ pdvobj->inter_bcn_space = DEFAULT_BCN_INTERVAL;
+
+ list_del_init(&padapter->list);
+ _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
+
+ rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pdvobj->inter_bcn_space));
+
+ if (pdvobj->nr_ap_if == 0)
+ _cancel_timer_ex(&pdvobj->txbcn_timer);
+ }
+#endif
+
+ pmlmeext->bstart_bss = false;
+
+#ifdef CONFIG_BT_COEXIST
+ rtw_btcoex_MediaStatusNotify(padapter, 0); /* disconnect */
+#endif
+
+}
+
+#endif /* CONFIG_NATIVEAP_MLME */
+
+void rtw_ap_update_bss_chbw(_adapter *adapter, WLAN_BSSID_EX *bss, u8 ch, u8 bw, u8 offset)
+{
+#define UPDATE_VHT_CAP 1
+#define UPDATE_HT_CAP 1
+
+ struct ht_priv *htpriv = &adapter->mlmepriv.htpriv;
+ u8 *ht_cap_ie, *ht_op_ie;
+ int ht_cap_ielen, ht_op_ielen;
+
+ ht_cap_ie = rtw_get_ie((bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)), EID_HTCapability, &ht_cap_ielen, (bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
+ ht_op_ie = rtw_get_ie((bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)), EID_HTInfo, &ht_op_ielen, (bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
+
+ /* update ht cap ie */
+ if (ht_cap_ie && ht_cap_ielen) {
+ #if UPDATE_HT_CAP
+ if (bw >= CHANNEL_WIDTH_40)
+ SET_HT_CAP_ELE_CHL_WIDTH(ht_cap_ie + 2, 1);
+ else
+ SET_HT_CAP_ELE_CHL_WIDTH(ht_cap_ie + 2, 0);
+
+ if (bw >= CHANNEL_WIDTH_40 && htpriv->sgi_40m)
+ SET_HT_CAP_ELE_SHORT_GI40M(ht_cap_ie + 2, 1);
+ else
+ SET_HT_CAP_ELE_SHORT_GI40M(ht_cap_ie + 2, 0);
+
+ if (htpriv->sgi_20m)
+ SET_HT_CAP_ELE_SHORT_GI20M(ht_cap_ie + 2, 1);
+ else
+ SET_HT_CAP_ELE_SHORT_GI20M(ht_cap_ie + 2, 0);
+ #endif
+ }
+
+ /* update ht op ie */
+ if (ht_op_ie && ht_op_ielen) {
+ SET_HT_OP_ELE_PRI_CHL(ht_op_ie + 2, ch);
+ switch (offset) {
+ case HAL_PRIME_CHNL_OFFSET_LOWER:
+ SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, SCA);
+ break;
+ case HAL_PRIME_CHNL_OFFSET_UPPER:
+ SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, SCB);
+ break;
+ case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
+ default:
+ SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, SCN);
+ break;
+ }
+
+ if (bw >= CHANNEL_WIDTH_40)
+ SET_HT_OP_ELE_STA_CHL_WIDTH(ht_op_ie + 2, 1);
+ else
+ SET_HT_OP_ELE_STA_CHL_WIDTH(ht_op_ie + 2, 0);
+ }
+
+ {
+ u8 *p;
+ int ie_len;
+ u8 old_ch = bss->Configuration.DSConfig;
+ bool change_band = false;
+
+ if ((ch <= 14 && old_ch >= 36) || (ch >= 36 && old_ch <= 14))
+ change_band = true;
+
+ /* update channel in IE */
+ p = rtw_get_ie((bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _DSSET_IE_, &ie_len, (bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
+ if (p && ie_len > 0)
+ *(p + 2) = ch;
+
+ bss->Configuration.DSConfig = ch;
+
+ /* band is changed, update ERP, support rate, ext support rate IE */
+ if (change_band )
+ change_band_update_ie(adapter, bss, ch);
+ }
+
+}
+
+bool rtw_ap_chbw_decision(_adapter *adapter, s16 req_ch, s8 req_bw, s8 req_offset
+ , u8 *ch, u8 *bw, u8 *offset, u8 *chbw_allow)
+{
+ u8 cur_ie_ch, cur_ie_bw, cur_ie_offset;
+ u8 dec_ch, dec_bw, dec_offset;
+ u8 u_ch = 0, u_offset, u_bw;
+ bool changed = false;
+ struct mlme_ext_priv *mlmeext = &(adapter->mlmeextpriv);
+ WLAN_BSSID_EX *network = &(adapter->mlmepriv.cur_network.network);
+ struct mi_state mstate;
+ bool set_u_ch = false, set_dec_ch = false;
+
+ rtw_ies_get_chbw(network->IEs + sizeof(NDIS_802_11_FIXED_IEs)
+ , network->IELength - sizeof(NDIS_802_11_FIXED_IEs)
+ , &cur_ie_ch, &cur_ie_bw, &cur_ie_offset);
+
+#ifdef CONFIG_MCC_MODE
+ if (MCC_EN(adapter)) {
+ if (rtw_hal_check_mcc_status(adapter, MCC_STATUS_DOING_MCC)) {
+ /* check channel settings are the same */
+ if (cur_ie_ch == mlmeext->cur_channel
+ && cur_ie_bw == mlmeext->cur_bwmode
+ && cur_ie_offset == mlmeext->cur_ch_offset) {
+
+
+ RTW_INFO(FUNC_ADPT_FMT"req ch settings are the same as current ch setting, go to exit\n"
+ , FUNC_ADPT_ARG(adapter));
+
+ *chbw_allow = false;
+ goto exit;
+ } else {
+ RTW_INFO(FUNC_ADPT_FMT"request channel settings are not the same as current channel setting(%d,%d,%d,%d,%d,%d), restart MCC\n"
+ , FUNC_ADPT_ARG(adapter)
+ , cur_ie_ch, cur_ie_bw, cur_ie_bw
+ , mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
+
+ rtw_hal_set_mcc_setting_disconnect(adapter);
+ }
+ }
+ }
+#endif /* CONFIG_MCC_MODE */
+
+ /* use chbw of cur_ie updated with specifying req as temporary decision */
+ dec_ch = (req_ch <= 0) ? cur_ie_ch : req_ch;
+ dec_bw = (req_bw < 0) ? cur_ie_bw : req_bw;
+ dec_offset = (req_offset < 0) ? cur_ie_offset : req_offset;
+
+ rtw_mi_status_no_self(adapter, &mstate);
+ RTW_INFO(FUNC_ADPT_FMT" ld_sta_num:%u, lg_sta_num%u, ap_num:%u\n"
+ , FUNC_ADPT_ARG(adapter), MSTATE_STA_LD_NUM(&mstate), MSTATE_STA_LG_NUM(&mstate), MSTATE_AP_NUM(&mstate));
+
+ if (MSTATE_STA_LD_NUM(&mstate) || MSTATE_AP_NUM(&mstate)) {
+ /* has linked STA or AP mode, follow */
+
+ rtw_warn_on(!rtw_mi_get_ch_setting_union_no_self(adapter, &u_ch, &u_bw, &u_offset));
+
+ RTW_INFO(FUNC_ADPT_FMT" union no self: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), u_ch, u_bw, u_offset);
+ RTW_INFO(FUNC_ADPT_FMT" req: %d,%d,%d\n", FUNC_ADPT_ARG(adapter), req_ch, req_bw, req_offset);
+
+ rtw_adjust_chbw(adapter, u_ch, &dec_bw, &dec_offset);
+#ifdef CONFIG_MCC_MODE
+ if (MCC_EN(adapter)) {
+ if (!rtw_is_chbw_grouped(u_ch, u_bw, u_offset, dec_ch, dec_bw, dec_offset)) {
+ mlmeext->cur_channel = *ch = dec_ch;
+ mlmeext->cur_bwmode = *bw = dec_bw;
+ mlmeext->cur_ch_offset = *offset = dec_offset;
+ /* channel bw offset can not be allowed, need MCC */
+ *chbw_allow = false;
+ RTW_INFO(FUNC_ADPT_FMT" enable mcc: %u,%u,%u\n", FUNC_ADPT_ARG(adapter)
+ , *ch, *bw, *offset);
+ goto exit;
+ } else
+ /* channel bw offset can be allowed, not need MCC */
+ *chbw_allow = true;
+ }
+#endif /* CONFIG_MCC_MODE */
+ rtw_sync_chbw(&dec_ch, &dec_bw, &dec_offset
+ , &u_ch, &u_bw, &u_offset);
+
+ rtw_ap_update_bss_chbw(adapter, &(adapter->mlmepriv.cur_network.network)
+ , dec_ch, dec_bw, dec_offset);
+
+ set_u_ch = true;
+ } else if (MSTATE_STA_LG_NUM(&mstate)) {
+ /* has linking STA */
+
+ rtw_warn_on(!rtw_mi_get_ch_setting_union_no_self(adapter, &u_ch, &u_bw, &u_offset));
+
+ RTW_INFO(FUNC_ADPT_FMT" union no self: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), u_ch, u_bw, u_offset);
+ RTW_INFO(FUNC_ADPT_FMT" req: %d,%d,%d\n", FUNC_ADPT_ARG(adapter), req_ch, req_bw, req_offset);
+
+ rtw_adjust_chbw(adapter, dec_ch, &dec_bw, &dec_offset);
+
+ if (rtw_is_chbw_grouped(u_ch, u_bw, u_offset, dec_ch, dec_bw, dec_offset)) {
+
+ rtw_sync_chbw(&dec_ch, &dec_bw, &dec_offset
+ , &u_ch, &u_bw, &u_offset);
+
+ rtw_ap_update_bss_chbw(adapter, &(adapter->mlmepriv.cur_network.network)
+ , dec_ch, dec_bw, dec_offset);
+
+ set_u_ch = true;
+
+ /* channel bw offset can be allowed, not need MCC */
+ *chbw_allow = true;
+ } else {
+#ifdef CONFIG_MCC_MODE
+ if (MCC_EN(adapter)) {
+ mlmeext->cur_channel = *ch = dec_ch;
+ mlmeext->cur_bwmode = *bw = dec_bw;
+ mlmeext->cur_ch_offset = *offset = dec_offset;
+
+ /* channel bw offset can not be allowed, need MCC */
+ *chbw_allow = false;
+ RTW_INFO(FUNC_ADPT_FMT" enable mcc: %u,%u,%u\n", FUNC_ADPT_ARG(adapter)
+ , *ch, *bw, *offset);
+ goto exit;
+ }
+#endif /* CONFIG_MCC_MODE */
+ /* set this for possible ch change when join down*/
+ set_fwstate(&adapter->mlmepriv, WIFI_OP_CH_SWITCHING);
+ }
+ } else {
+ /* single AP mode */
+
+ RTW_INFO(FUNC_ADPT_FMT" req: %d,%d,%d\n", FUNC_ADPT_ARG(adapter), req_ch, req_bw, req_offset);
+
+ /* check temporary decision first */
+ rtw_adjust_chbw(adapter, dec_ch, &dec_bw, &dec_offset);
+ if (!rtw_get_offset_by_chbw(dec_ch, dec_bw, &dec_offset)) {
+ if (req_ch == -1 || req_bw == -1)
+ goto choose_chbw;
+ RTW_WARN(FUNC_ADPT_FMT" req: %u,%u has no valid offset\n", FUNC_ADPT_ARG(adapter), dec_ch, dec_bw);
+ *chbw_allow = false;
+ goto exit;
+ }
+
+ if (!rtw_chset_is_chbw_valid(mlmeext->channel_set, dec_ch, dec_bw, dec_offset)) {
+ if (req_ch == -1 || req_bw == -1)
+ goto choose_chbw;
+ RTW_WARN(FUNC_ADPT_FMT" req: %u,%u,%u doesn't fit in chplan\n", FUNC_ADPT_ARG(adapter), dec_ch, dec_bw, dec_offset);
+ *chbw_allow = false;
+ goto exit;
+ }
+
+ if (rtw_odm_dfs_domain_unknown(adapter) && rtw_is_dfs_ch(dec_ch, dec_bw, dec_offset)) {
+ if (req_ch >= 0)
+ RTW_WARN(FUNC_ADPT_FMT" DFS channel %u,%u,%u can't be used\n", FUNC_ADPT_ARG(adapter), dec_ch, dec_bw, dec_offset);
+ if (req_ch > 0) {
+ /* specific channel and not from IE => don't change channel setting */
+ *chbw_allow = false;
+ goto exit;
+ }
+ goto choose_chbw;
+ }
+
+ if (rtw_chset_is_ch_non_ocp(mlmeext->channel_set, dec_ch, dec_bw, dec_offset) == false)
+ goto update_bss_chbw;
+
+choose_chbw:
+ if (req_bw < 0)
+ req_bw = cur_ie_bw;
+
+#if defined(CONFIG_DFS_MASTER)
+ if (!rtw_odm_dfs_domain_unknown(adapter)) {
+ /* choose 5G DFS channel for debug */
+ if (adapter_to_rfctl(adapter)->dbg_dfs_master_choose_dfs_ch_first
+ && rtw_choose_shortest_waiting_ch(adapter, req_bw, &dec_ch, &dec_bw, &dec_offset, RTW_CHF_2G | RTW_CHF_NON_DFS) )
+ RTW_INFO(FUNC_ADPT_FMT" choose 5G DFS channel for debug\n", FUNC_ADPT_ARG(adapter));
+ else if (adapter_to_rfctl(adapter)->dfs_ch_sel_d_flags
+ && rtw_choose_shortest_waiting_ch(adapter, req_bw, &dec_ch, &dec_bw, &dec_offset, adapter_to_rfctl(adapter)->dfs_ch_sel_d_flags) )
+ RTW_INFO(FUNC_ADPT_FMT" choose with dfs_ch_sel_d_flags:0x%02x for debug\n", FUNC_ADPT_ARG(adapter), adapter_to_rfctl(adapter)->dfs_ch_sel_d_flags);
+ else if (rtw_choose_shortest_waiting_ch(adapter, req_bw, &dec_ch, &dec_bw, &dec_offset, 0) == false) {
+ RTW_WARN(FUNC_ADPT_FMT" no available channel\n", FUNC_ADPT_ARG(adapter));
+ *chbw_allow = false;
+ goto exit;
+ }
+ } else
+#endif /* defined(CONFIG_DFS_MASTER) */
+ if (rtw_choose_shortest_waiting_ch(adapter, req_bw, &dec_ch, &dec_bw, &dec_offset, RTW_CHF_DFS) == false) {
+ RTW_WARN(FUNC_ADPT_FMT" no available channel\n", FUNC_ADPT_ARG(adapter));
+ *chbw_allow = false;
+ goto exit;
+ }
+
+update_bss_chbw:
+ rtw_ap_update_bss_chbw(adapter, &(adapter->mlmepriv.cur_network.network)
+ , dec_ch, dec_bw, dec_offset);
+
+ /* channel bw offset can be allowed for single AP, not need MCC */
+ *chbw_allow = true;
+ set_dec_ch = true;
+ }
+
+ if (rtw_mi_check_fwstate(adapter, _FW_UNDER_SURVEY)) {
+ /* scanning, leave ch setting to scan state machine */
+ set_u_ch = set_dec_ch = false;
+ }
+
+ if (mlmeext->cur_channel != dec_ch
+ || mlmeext->cur_bwmode != dec_bw
+ || mlmeext->cur_ch_offset != dec_offset)
+ changed = true;
+
+ if (changed && rtw_linked_check(adapter) == true) {
+#ifdef CONFIG_SPCT_CH_SWITCH
+ if (1)
+ rtw_ap_inform_ch_switch(adapter, dec_ch, dec_offset);
+ else
+#endif
+ rtw_sta_flush(adapter, false);
+ }
+
+ mlmeext->cur_channel = dec_ch;
+ mlmeext->cur_bwmode = dec_bw;
+ mlmeext->cur_ch_offset = dec_offset;
+
+ if (u_ch != 0)
+ RTW_INFO(FUNC_ADPT_FMT" union: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), u_ch, u_bw, u_offset);
+
+ RTW_INFO(FUNC_ADPT_FMT" dec: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), dec_ch, dec_bw, dec_offset);
+
+ if (set_u_ch ) {
+ *ch = u_ch;
+ *bw = u_bw;
+ *offset = u_offset;
+ } else if (set_dec_ch ) {
+ *ch = dec_ch;
+ *bw = dec_bw;
+ *offset = dec_offset;
+ }
+exit:
+ return changed;
+}
+
+/*#define DBG_SWTIMER_BASED_TXBCN*/
+
+#ifdef CONFIG_SWTIMER_BASED_TXBCN
+void tx_beacon_handler(struct dvobj_priv *pdvobj)
+{
+#define BEACON_EARLY_TIME 20 /* unit:TU*/
+ unsigned long irqL;
+ _list *plist, *phead;
+ u32 timestamp[2];
+ u32 bcn_interval_us; /* unit : usec */
+ u64 time;
+ u32 cur_tick, time_offset; /* unit : usec */
+ u32 inter_bcn_space_us; /* unit : usec */
+ int nr_vap, idx, bcn_idx;
+ int i;
+ u8 val8, late = 0;
+ _adapter *padapter = NULL;
+
+ i = 0;
+
+ /* get first ap mode interface */
+ _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
+ if (list_empty(&pdvobj->ap_if_q.queue) || (pdvobj->nr_ap_if == 0)) {
+ RTW_INFO("[%s] ERROR: ap_if_q is empty!or nr_ap = %d\n", __func__, pdvobj->nr_ap_if);
+ _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
+ return;
+ } else
+ padapter = LIST_CONTAINOR(get_next(&(pdvobj->ap_if_q.queue)), struct _ADAPTER, list);
+ _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
+
+ if (NULL == padapter) {
+ RTW_INFO("[%s] ERROR: no any ap interface!\n", __func__);
+ return;
+ }
+
+
+ bcn_interval_us = DEFAULT_BCN_INTERVAL * NET80211_TU_TO_US;
+ if (0 == bcn_interval_us) {
+ RTW_INFO("[%s] ERROR: beacon interval = 0\n", __func__);
+ return;
+ }
+
+ /* read TSF */
+ timestamp[1] = rtw_read32(padapter, 0x560 + 4);
+ timestamp[0] = rtw_read32(padapter, 0x560);
+ while (timestamp[1]) {
+ time = (0xFFFFFFFF % bcn_interval_us + 1) * timestamp[1] + timestamp[0];
+ timestamp[0] = (u32)time;
+ timestamp[1] = (u32)(time >> 32);
+ }
+ cur_tick = timestamp[0] % bcn_interval_us;
+
+
+ _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
+
+ nr_vap = (pdvobj->nr_ap_if - 1);
+ if (nr_vap > 0) {
+ inter_bcn_space_us = pdvobj->inter_bcn_space * NET80211_TU_TO_US; /* beacon_interval / (nr_vap+1); */
+ idx = cur_tick / inter_bcn_space_us;
+ if (idx < nr_vap) /* if (idx < (nr_vap+1))*/
+ bcn_idx = idx + 1; /* bcn_idx = (idx + 1) % (nr_vap+1);*/
+ else
+ bcn_idx = 0;
+
+ /* to get padapter based on bcn_idx */
+ padapter = NULL;
+ phead = get_list_head(&pdvobj->ap_if_q);
+ plist = get_next(phead);
+ while ((!rtw_end_of_queue_search(phead, plist))) {
+ padapter = LIST_CONTAINOR(plist, struct _ADAPTER, list);
+
+ plist = get_next(plist);
+
+ if (i == bcn_idx)
+ break;
+
+ i++;
+ }
+ if ((NULL == padapter) || (i > pdvobj->nr_ap_if)) {
+ RTW_INFO("[%s] ERROR: nr_ap_if = %d, padapter=%p, bcn_idx=%d, index=%d\n",
+ __func__, pdvobj->nr_ap_if, padapter, bcn_idx, i);
+ _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
+ return;
+ }
+#ifdef DBG_SWTIMER_BASED_TXBCN
+ RTW_INFO("BCN_IDX=%d, cur_tick=%d, padapter=%p\n", bcn_idx, cur_tick, padapter);
+#endif
+ if (((idx + 2 == nr_vap + 1) && (idx < nr_vap + 1)) || (0 == bcn_idx)) {
+ time_offset = bcn_interval_us - cur_tick - BEACON_EARLY_TIME * NET80211_TU_TO_US;
+ if ((s32)time_offset < 0)
+ time_offset += inter_bcn_space_us;
+
+ } else {
+ time_offset = (idx + 2) * inter_bcn_space_us - cur_tick - BEACON_EARLY_TIME * NET80211_TU_TO_US;
+ if (time_offset > (inter_bcn_space_us + (inter_bcn_space_us >> 1))) {
+ time_offset -= inter_bcn_space_us;
+ late = 1;
+ }
+ }
+ } else
+ /*#endif*/ { /* MBSSID */
+ time_offset = 2 * bcn_interval_us - cur_tick - BEACON_EARLY_TIME * NET80211_TU_TO_US;
+ if (time_offset > (bcn_interval_us + (bcn_interval_us >> 1))) {
+ time_offset -= bcn_interval_us;
+ late = 1;
+ }
+ }
+ _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
+
+#ifdef DBG_SWTIMER_BASED_TXBCN
+ RTW_INFO("set sw bcn timer %d us\n", time_offset);
+#endif
+ _set_timer(&pdvobj->txbcn_timer, time_offset / NET80211_TU_TO_US);
+
+ if (padapter) {
+#ifdef DBG_SWTIMER_BASED_TXBCN
+ RTW_INFO("padapter=%p, PORT=%d\n", padapter, padapter->hw_port);
+#endif
+ /*update_beacon(padapter, _TIM_IE_, NULL, false);*/
+ issue_beacon(padapter, 0);
+ }
+}
+
+void tx_beacon_timer_handler(struct dvobj_priv *pdvobj)
+{
+ _adapter *padapter = pdvobj->padapters[0];
+
+ if (padapter)
+ set_tx_beacon_cmd(padapter);
+}
+#endif
+
+#endif /* CONFIG_AP_MODE */
diff --git a/drivers/staging/rtl8188eu/core/rtw_beamforming.c b/drivers/staging/rtl8188eu/core/rtw_beamforming.c
new file mode 100644
index 000000000000..2ec9ba408fc4
--- /dev/null
+++ b/drivers/staging/rtl8188eu/core/rtw_beamforming.c
@@ -0,0 +1,3071 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved. */
+
+#define _RTW_BEAMFORMING_C_
+
+#include <drv_types.h>
+#include <hal_data.h>
+
+#ifdef CONFIG_BEAMFORMING
+
+#ifdef RTW_BEAMFORMING_VERSION_2
+
+struct ndpa_sta_info {
+ u16 aid:12;
+ u16 feedback_type:1;
+ u16 nc_index:3;
+};
+
+static void _get_txvector_parameter(PADAPTER adapter, struct sta_info *sta, u8 *g_id, u16 *p_aid)
+{
+ struct mlme_priv *mlme;
+ u16 aid;
+ u8 *bssid;
+ u16 val16;
+ u8 i;
+
+
+ mlme = &adapter->mlmepriv;
+
+ if (check_fwstate(mlme, WIFI_AP_STATE)) {
+ /*
+ * Sent by an AP and addressed to a STA associated with that AP
+ * or sent by a DLS or TDLS STA in a direct path to
+ * a DLS or TDLS peer STA
+ */
+
+ aid = sta->aid;
+ bssid = adapter_mac_addr(adapter);
+ RTW_INFO("%s: AID=0x%x BSSID=" MAC_FMT "\n",
+ __func__, sta->aid, MAC_ARG(bssid));
+
+ /* AID[0:8] */
+ aid &= 0x1FF;
+ /* BSSID[44:47] xor BSSID[40:43] */
+ val16 = ((bssid[5] & 0xF0) >> 4) ^ (bssid[5] & 0xF);
+ /* (dec(AID[0:8]) + dec(BSSID)*2^5) mod 2^9 */
+ *p_aid = (aid + (val16 << 5)) & 0x1FF;
+ *g_id = 63;
+ } else if ((check_fwstate(mlme, WIFI_ADHOC_STATE) == true)
+ || (check_fwstate(mlme, WIFI_ADHOC_MASTER_STATE) == true)) {
+ /*
+ * Otherwise, includes
+ * 1. Sent to an IBSS STA
+ * 2. Sent by an AP to a non associated STA
+ * 3. Sent to a STA for which it is not known
+ * which condition is applicable
+ */
+ *p_aid = 0;
+ *g_id = 63;
+ } else {
+ /* Addressed to AP */
+ bssid = sta->hwaddr;
+ RTW_INFO("%s: BSSID=" MAC_FMT "\n", __func__, MAC_ARG(bssid));
+
+ /* BSSID[39:47] */
+ *p_aid = (bssid[5] << 1) | (bssid[4] >> 7);
+ *g_id = 0;
+ }
+
+ RTW_INFO("%s: GROUP_ID=0x%02x PARTIAL_AID=0x%04x\n",
+ __func__, *g_id, *p_aid);
+}
+
+/*
+ * Parameters
+ * adapter struct _adapter*
+ * sta struct sta_info*
+ * sta_bf_cap beamforming capabe of sta
+ * sounding_dim Number of Sounding Dimensions
+ * comp_steering Compressed Steering Number of Beamformer Antennas Supported
+ */
+static void _get_sta_beamform_cap(PADAPTER adapter, struct sta_info *sta,
+ u8 *sta_bf_cap, u8 *sounding_dim, u8 *comp_steering)
+{
+ struct beamforming_info *info;
+ struct ht_priv *ht;
+ u16 bf_cap;
+
+
+ *sta_bf_cap = 0;
+ *sounding_dim = 0;
+ *comp_steering = 0;
+
+ info = GET_BEAMFORM_INFO(adapter);
+ ht = &adapter->mlmepriv.htpriv;
+
+ if (is_supported_ht(sta->wireless_mode) == true) {
+ /* HT */
+ bf_cap = ht->beamform_cap;
+
+ if (TEST_FLAG(bf_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE)) {
+ info->beamforming_cap |= BEAMFORMEE_CAP_HT_EXPLICIT;
+ *sta_bf_cap |= BEAMFORMER_CAP_HT_EXPLICIT;
+ *sounding_dim = (bf_cap & BEAMFORMING_HT_BEAMFORMEE_CHNL_EST_CAP) >> 6;
+ }
+ if (TEST_FLAG(bf_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE)) {
+ info->beamforming_cap |= BEAMFORMER_CAP_HT_EXPLICIT;
+ *sta_bf_cap |= BEAMFORMEE_CAP_HT_EXPLICIT;
+ *comp_steering = (bf_cap & BEAMFORMING_HT_BEAMFORMER_STEER_NUM) >> 4;
+ }
+ }
+}
+
+static u8 _send_ht_ndpa_packet(PADAPTER adapter, u8 *ra, CHANNEL_WIDTH bw)
+{
+ /* General */
+ struct xmit_priv *pxmitpriv;
+ struct mlme_ext_priv *pmlmeext;
+ struct mlme_ext_info *pmlmeinfo;
+ struct xmit_frame *pmgntframe;
+ /* Beamforming */
+ struct beamforming_info *info;
+ struct beamformee_entry *bfee;
+ struct ndpa_sta_info sta_info;
+ u8 ActionHdr[4] = {ACT_CAT_VENDOR, 0x00, 0xE0, 0x4C};
+ /* MISC */
+ struct pkt_attrib *attrib;
+ struct rtw_ieee80211_hdr *pwlanhdr;
+ enum MGN_RATE txrate;
+ u8 *pframe;
+ u16 duration = 0;
+ u8 aSifsTime = 0;
+
+
+ RTW_INFO("+%s: Send to " MAC_FMT "\n", __func__, MAC_ARG(ra));
+
+ pxmitpriv = &adapter->xmitpriv;
+ pmlmeext = &adapter->mlmeextpriv;
+ pmlmeinfo = &pmlmeext->mlmext_info;
+ bfee = rtw_bf_bfee_get_entry_by_addr(adapter, ra);
+ if (!bfee) {
+ RTW_ERR("%s: Cann't find beamformee entry!\n", __func__);
+ return false;
+ }
+
+ pmgntframe = alloc_mgtxmitframe(pxmitpriv);
+ if (!pmgntframe) {
+ RTW_ERR("%s: alloc mgnt frame fail!\n", __func__);
+ return false;
+ }
+
+ txrate = beamforming_get_htndp_tx_rate(GET_PDM_ODM(adapter), bfee->comp_steering_num_of_bfer);
+
+ /* update attribute */
+ attrib = &pmgntframe->attrib;
+ update_mgntframe_attrib(adapter, attrib);
+ /*attrib->type = WIFI_MGT_TYPE;*/ /* set in update_mgntframe_attrib() */
+ attrib->subtype = WIFI_ACTION_NOACK;
+ attrib->bwmode = bw;
+ /*attrib->qsel = QSLT_MGNT;*/ /* set in update_mgntframe_attrib() */
+ attrib->order = 1;
+ attrib->rate = (u8)txrate;
+ attrib->bf_pkt_type = 0;
+
+ memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
+ pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
+ pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
+
+ /* Frame control */
+ pwlanhdr->frame_ctl = 0;
+ set_frame_sub_type(pframe, attrib->subtype);
+ set_order_bit(pframe);
+
+ /* Duration */
+ if (pmlmeext->cur_wireless_mode == WIRELESS_11B)
+ aSifsTime = 10;
+ else
+ aSifsTime = 16;
+ duration = 2 * aSifsTime + 40;
+ if (bw == CHANNEL_WIDTH_40)
+ duration += 87;
+ else
+ duration += 180;
+ set_duration(pframe, duration);
+
+ /* DA */
+ memcpy(pwlanhdr->addr1, ra, ETH_ALEN);
+ /* SA */
+ memcpy(pwlanhdr->addr2, adapter_mac_addr(adapter), ETH_ALEN);
+ /* BSSID */
+ memcpy(pwlanhdr->addr3, get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
+
+ /* HT control field */
+ SET_HT_CTRL_CSI_STEERING(pframe + 24, 3);
+ SET_HT_CTRL_NDP_ANNOUNCEMENT(pframe + 24, 1);
+
+ /*
+ * Frame Body
+ * Category field: vender-specific value, 0x7F
+ * OUI: 0x00E04C
+ */
+ memcpy(pframe + 28, ActionHdr, 4);
+
+ attrib->pktlen = 32;
+ attrib->last_txcmdsz = attrib->pktlen;
+
+ dump_mgntframe(adapter, pmgntframe);
+
+ return true;
+}
+
+static u8 _send_vht_ndpa_packet(PADAPTER adapter, u8 *ra, u16 aid, CHANNEL_WIDTH bw)
+{
+ /* General */
+ struct xmit_priv *pxmitpriv;
+ struct mlme_ext_priv *pmlmeext;
+ struct xmit_frame *pmgntframe;
+ /* Beamforming */
+ struct beamforming_info *info;
+ struct beamformee_entry *bfee;
+ struct ndpa_sta_info sta_info;
+ /* MISC */
+ struct pkt_attrib *attrib;
+ struct rtw_ieee80211_hdr *pwlanhdr;
+ u8 *pframe;
+ enum MGN_RATE txrate;
+ u16 duration = 0;
+ u8 sequence = 0, aSifsTime = 0;
+
+
+ RTW_INFO("+%s: Send to " MAC_FMT "\n", __func__, MAC_ARG(ra));
+
+ pxmitpriv = &adapter->xmitpriv;
+ pmlmeext = &adapter->mlmeextpriv;
+ info = GET_BEAMFORM_INFO(adapter);
+ bfee = rtw_bf_bfee_get_entry_by_addr(adapter, ra);
+ if (!bfee) {
+ RTW_ERR("%s: Cann't find beamformee entry!\n", __func__);
+ return false;
+ }
+
+ pmgntframe = alloc_mgtxmitframe(pxmitpriv);
+ if (!pmgntframe) {
+ RTW_ERR("%s: alloc mgnt frame fail!\n", __func__);
+ return false;
+ }
+
+ txrate = beamforming_get_vht_ndp_tx_rate(GET_PDM_ODM(adapter), bfee->comp_steering_num_of_bfer);
+
+ /* update attribute */
+ attrib = &pmgntframe->attrib;
+ update_mgntframe_attrib(adapter, attrib);
+ /*pattrib->type = WIFI_MGT_TYPE;*/ /* set in update_mgntframe_attrib() */
+ attrib->subtype = WIFI_NDPA;
+ attrib->bwmode = bw;
+ /*attrib->qsel = QSLT_MGNT;*/ /* set in update_mgntframe_attrib() */
+ attrib->rate = (u8)txrate;
+ attrib->bf_pkt_type = 0;
+
+ memset(pmgntframe->buf_addr, 0, TXDESC_OFFSET + WLANHDR_OFFSET);
+ pframe = pmgntframe->buf_addr + TXDESC_OFFSET;
+ pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
+
+ /* Frame control */
+ pwlanhdr->frame_ctl = 0;
+ set_frame_sub_type(pframe, attrib->subtype);
+
+ /* Duration */
+ if (is_supported_5g(pmlmeext->cur_wireless_mode) || is_supported_ht(pmlmeext->cur_wireless_mode))
+ aSifsTime = 16;
+ else
+ aSifsTime = 10;
+ duration = 2 * aSifsTime + 44;
+ if (bw == CHANNEL_WIDTH_80)
+ duration += 40;
+ else if (bw == CHANNEL_WIDTH_40)
+ duration += 87;
+ else
+ duration += 180;
+ set_duration(pframe, duration);
+
+ /* RA */
+ memcpy(pwlanhdr->addr1, ra, ETH_ALEN);
+
+ /* TA */
+ memcpy(pwlanhdr->addr2, adapter_mac_addr(adapter), ETH_ALEN);
+
+ /* Sounding Sequence, bit0~1 is reserved */
+ sequence = info->sounding_sequence << 2;
+ if (info->sounding_sequence >= 0x3f)
+ info->sounding_sequence = 0;
+ else
+ info->sounding_sequence++;
+ memcpy(pframe + 16, &sequence, 1);
+
+ /* STA Info */
+ /*
+ * "AID12" Equal to 0 if the STA is an AP, mesh STA or
+ * STA that is a member of an IBSS
+ */
+ if (check_fwstate(&adapter->mlmepriv, WIFI_AP_STATE) == false)
+ aid = 0;
+ sta_info.aid = aid;
+ /* "Feedback Type" set to 0 for SU */
+ sta_info.feedback_type = 0;
+ /* "Nc Index" reserved if the Feedback Type field indicates SU */
+ sta_info.nc_index = 0;
+ memcpy(pframe + 17, (u8 *)&sta_info, 2);
+
+ attrib->pktlen = 19;
+ attrib->last_txcmdsz = attrib->pktlen;
+
+ dump_mgntframe(adapter, pmgntframe);
+
+ return true;
+}
+
+static u8 _send_vht_mu_ndpa_packet(PADAPTER adapter, CHANNEL_WIDTH bw)
+{
+ /* General */
+ struct xmit_priv *pxmitpriv;
+ struct mlme_ext_priv *pmlmeext;
+ struct xmit_frame *pmgntframe;
+ /* Beamforming */
+ struct beamforming_info *info;
+ struct sounding_info *sounding;
+ struct beamformee_entry *bfee;
+ struct ndpa_sta_info sta_info;
+ /* MISC */
+ struct pkt_attrib *attrib;
+ struct rtw_ieee80211_hdr *pwlanhdr;
+ enum MGN_RATE txrate;
+ u8 *pframe;
+ u8 *ra = NULL;
+ u16 duration = 0;
+ u8 sequence = 0, aSifsTime = 0;
+ u8 i;
+
+
+ RTW_INFO("+%s\n", __func__);
+
+ pxmitpriv = &adapter->xmitpriv;
+ pmlmeext = &adapter->mlmeextpriv;
+ info = GET_BEAMFORM_INFO(adapter);
+ sounding = &info->sounding_info;
+
+ txrate = MGN_VHT2SS_MCS0;
+
+ /*
+ * Fill the first MU BFee entry (STA1) MAC addr to destination address then
+ * HW will change A1 to broadcast addr.
+ * 2015.05.28. Suggested by SD1 Chunchu.
+ */
+ bfee = &info->bfee_entry[sounding->mu_sounding_list[0]];
+ ra = bfee->mac_addr;
+
+ pmgntframe = alloc_mgtxmitframe(pxmitpriv);
+ if (!pmgntframe) {
+ RTW_ERR("%s: alloc mgnt frame fail!\n", __func__);
+ return false;
+ }
+
+ /* update attribute */
+ attrib = &pmgntframe->attrib;
+ update_mgntframe_attrib(adapter, attrib);
+ /*attrib->type = WIFI_MGT_TYPE;*/ /* set in update_mgntframe_attrib() */
+ attrib->subtype = WIFI_NDPA;
+ attrib->bwmode = bw;
+ /*attrib->qsel = QSLT_MGNT;*/ /* set in update_mgntframe_attrib() */
+ attrib->rate = (u8)txrate;
+ /* Set TxBFPktType of Tx desc to unicast type if there is only one MU STA for HW design */
+ if (info->sounding_info.candidate_mu_bfee_cnt > 1)
+ attrib->bf_pkt_type = 1;
+ else
+ attrib->bf_pkt_type = 0;
+
+ memset(pmgntframe->buf_addr, 0, TXDESC_OFFSET + WLANHDR_OFFSET);
+ pframe = pmgntframe->buf_addr + TXDESC_OFFSET;
+ pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
+
+ /* Frame control */
+ pwlanhdr->frame_ctl = 0;
+ set_frame_sub_type(pframe, attrib->subtype);
+
+ /* Duration */
+ if (is_supported_5g(pmlmeext->cur_wireless_mode) || is_supported_ht(pmlmeext->cur_wireless_mode))
+ aSifsTime = 16;
+ else
+ aSifsTime = 10;
+ duration = 2 * aSifsTime + 44;
+ if (bw == CHANNEL_WIDTH_80)
+ duration += 40;
+ else if (bw == CHANNEL_WIDTH_40)
+ duration += 87;
+ else
+ duration += 180;
+ set_duration(pframe, duration);
+
+ /* RA */
+ memcpy(pwlanhdr->addr1, ra, ETH_ALEN);
+
+ /* TA */
+ memcpy(pwlanhdr->addr2, adapter_mac_addr(adapter), ETH_ALEN);
+
+ /* Sounding Sequence, bit0~1 is reserved */
+ sequence = info->sounding_sequence << 2;
+ if (info->sounding_sequence >= 0x3f)
+ info->sounding_sequence = 0;
+ else
+ info->sounding_sequence++;
+ memcpy(pframe + 16, &sequence, 1);
+
+ attrib->pktlen = 17;
+
+ /*
+ * Construct STA info. for multiple STAs
+ * STA Info1, ..., STA Info n
+ */
+ for (i = 0; i < sounding->candidate_mu_bfee_cnt; i++) {
+ bfee = &info->bfee_entry[sounding->mu_sounding_list[i]];
+ sta_info.aid = bfee->aid;
+ sta_info.feedback_type = 1; /* 1'b1: MU */
+ sta_info.nc_index = 0;
+ memcpy(pframe + attrib->pktlen, (u8 *)&sta_info, 2);
+ attrib->pktlen += 2;
+ }
+
+ attrib->last_txcmdsz = attrib->pktlen;
+
+ dump_mgntframe(adapter, pmgntframe);
+
+ return true;
+}
+
+static u8 _send_bf_report_poll(PADAPTER adapter, u8 *ra, u8 bFinalPoll)
+{
+ /* General */
+ struct xmit_priv *pxmitpriv;
+ struct xmit_frame *pmgntframe;
+ /* MISC */
+ struct pkt_attrib *attrib;
+ struct rtw_ieee80211_hdr *pwlanhdr;
+ u8 *pframe;
+
+
+ RTW_INFO("+%s: Send to " MAC_FMT "\n", __func__, MAC_ARG(ra));
+
+ pxmitpriv = &adapter->xmitpriv;
+
+ pmgntframe = alloc_mgtxmitframe(pxmitpriv);
+ if (!pmgntframe) {
+ RTW_ERR("%s: alloc mgnt frame fail!\n", __func__);
+ return false;
+ }
+
+ /* update attribute */
+ attrib = &pmgntframe->attrib;
+ update_mgntframe_attrib(adapter, attrib);
+ /*attrib->type = WIFI_MGT_TYPE;*/ /* set in update_mgntframe_attrib() */
+ attrib->subtype = WIFI_BF_REPORT_POLL;
+ attrib->bwmode = CHANNEL_WIDTH_20;
+ /*attrib->qsel = QSLT_MGNT;*/ /* set in update_mgntframe_attrib() */
+ attrib->rate = MGN_6M;
+ if (bFinalPoll)
+ attrib->bf_pkt_type = 3;
+ else
+ attrib->bf_pkt_type = 2;
+
+ memset(pmgntframe->buf_addr, 0, TXDESC_OFFSET + WLANHDR_OFFSET);
+ pframe = pmgntframe->buf_addr + TXDESC_OFFSET;
+ pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
+
+ /* Frame control */
+ pwlanhdr->frame_ctl = 0;
+ set_frame_sub_type(pframe, attrib->subtype);
+
+ /* Duration */
+ set_duration(pframe, 100);
+
+ /* RA */
+ memcpy(pwlanhdr->addr1, ra, ETH_ALEN);
+
+ /* TA */
+ memcpy(pwlanhdr->addr2, adapter_mac_addr(adapter), ETH_ALEN);
+
+ /* Feedback Segment Retransmission Bitmap */
+ pframe[16] = 0xFF;
+
+ attrib->pktlen = 17;
+ attrib->last_txcmdsz = attrib->pktlen;
+
+ dump_mgntframe(adapter, pmgntframe);
+
+ return true;
+}
+
+static void _sounding_update_min_period(PADAPTER adapter, u16 period, u8 leave)
+{
+ struct beamforming_info *info;
+ struct beamformee_entry *bfee;
+ u8 i = 0;
+ u16 min_val = 0xFFFF;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+
+ if (leave) {
+ /*
+ * When a BFee left,
+ * we need to find the latest min sounding period
+ * from the remaining BFees
+ */
+ for (i = 0; i < MAX_BEAMFORMEE_ENTRY_NUM; i++) {
+ bfee = &info->bfee_entry[i];
+ if ((bfee->used == true)
+ && (bfee->sound_period < min_val))
+ min_val = bfee->sound_period;
+ }
+
+ if (min_val == 0xFFFF)
+ info->sounding_info.min_sounding_period = 0;
+ else
+ info->sounding_info.min_sounding_period = min_val;
+ } else {
+ if ((info->sounding_info.min_sounding_period == 0)
+ || (period < info->sounding_info.min_sounding_period))
+ info->sounding_info.min_sounding_period = period;
+ }
+}
+
+static void _sounding_init(struct sounding_info *sounding)
+{
+ memset(sounding->su_sounding_list, 0xFF, MAX_NUM_BEAMFORMEE_SU);
+ memset(sounding->mu_sounding_list, 0xFF, MAX_NUM_BEAMFORMEE_MU);
+ sounding->state = SOUNDING_STATE_NONE;
+ sounding->su_bfee_curidx = 0xFF;
+ sounding->candidate_mu_bfee_cnt = 0;
+ sounding->min_sounding_period = 0;
+ sounding->sound_remain_cnt_per_period = 0;
+}
+
+static void _sounding_reset_vars(PADAPTER adapter)
+{
+ struct beamforming_info *info;
+ struct sounding_info *sounding;
+ u8 idx;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+ sounding = &info->sounding_info;
+
+ memset(sounding->su_sounding_list, 0xFF, MAX_NUM_BEAMFORMEE_SU);
+ memset(sounding->mu_sounding_list, 0xFF, MAX_NUM_BEAMFORMEE_MU);
+ sounding->su_bfee_curidx = 0xFF;
+ sounding->candidate_mu_bfee_cnt = 0;
+
+ /* Clear bSound flag for the new period */
+ for (idx = 0; idx < MAX_BEAMFORMEE_ENTRY_NUM; idx++) {
+ if ((info->bfee_entry[idx].used == true)
+ && (info->bfee_entry[idx].sounding == true)) {
+ info->bfee_entry[idx].sounding = false;
+ info->bfee_entry[idx].bCandidateSoundingPeer = false;
+ }
+ }
+}
+
+/*
+ * Return
+ * 0 Prepare sounding list OK
+ * -1 Fail to prepare sounding list, because no beamformee need to souding
+ * -2 Fail to prepare sounding list, because beamformee state not ready
+ *
+ */
+static int _sounding_get_list(PADAPTER adapter)
+{
+ struct beamforming_info *info;
+ struct sounding_info *sounding;
+ struct beamformee_entry *bfee;
+ u8 i, mu_idx = 0, su_idx = 0, not_ready = 0;
+ int ret = 0;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+ sounding = &info->sounding_info;
+
+ /* Add MU BFee list first because MU priority is higher than SU */
+ for (i = 0; i < MAX_BEAMFORMEE_ENTRY_NUM; i++) {
+ bfee = &info->bfee_entry[i];
+ if (bfee->used == false)
+ continue;
+
+ if (bfee->state != BEAMFORM_ENTRY_HW_STATE_ADDED) {
+ RTW_ERR("%s: Invalid BFee idx(%d) Hw state=%d\n", __func__, i, bfee->state);
+ not_ready++;
+ continue;
+ }
+
+ /*
+ * Decrease BFee's SoundCnt per period
+ * If the remain count is 0,
+ * then it can be sounded at this time
+ */
+ if (bfee->SoundCnt) {
+ bfee->SoundCnt--;
+ if (bfee->SoundCnt)
+ continue;
+ }
+
+ /*
+ * <tynli_Note>
+ * If the STA supports MU BFee capability then we add it to MUSoundingList directly
+ * because we can only sound one STA by unicast NDPA with MU cap enabled to get correct channel info.
+ * Suggested by BB team Luke Lee. 2015.11.25.
+ */
+ if (bfee->cap & BEAMFORMEE_CAP_VHT_MU) {
+ /* MU BFee */
+ if (mu_idx >= MAX_NUM_BEAMFORMEE_MU) {
+ RTW_ERR("%s: Too much MU bfee entry(Limit:%d)\n", __func__, MAX_NUM_BEAMFORMEE_MU);
+ continue;
+ }
+
+ if (bfee->bApplySounding == true) {
+ bfee->bCandidateSoundingPeer = true;
+ bfee->SoundCnt = GetInitSoundCnt(bfee->sound_period, sounding->min_sounding_period);
+ sounding->mu_sounding_list[mu_idx] = i;
+ mu_idx++;
+ }
+ } else if (bfee->cap & (BEAMFORMEE_CAP_VHT_SU|BEAMFORMEE_CAP_HT_EXPLICIT)) {
+ /* SU BFee (HT/VHT) */
+ if (su_idx >= MAX_NUM_BEAMFORMEE_SU) {
+ RTW_ERR("%s: Too much SU bfee entry(Limit:%d)\n", __func__, MAX_NUM_BEAMFORMEE_SU);
+ continue;
+ }
+
+ if (bfee->bDeleteSounding == true) {
+ sounding->su_sounding_list[su_idx] = i;
+ su_idx++;
+ } else if ((bfee->bApplySounding == true)
+ && (bfee->bSuspendSUCap == false)) {
+ bfee->bCandidateSoundingPeer = true;
+ bfee->SoundCnt = GetInitSoundCnt(bfee->sound_period, sounding->min_sounding_period);
+ sounding->su_sounding_list[su_idx] = i;
+ su_idx++;
+ }
+ }
+ }
+
+ sounding->candidate_mu_bfee_cnt = mu_idx;
+
+ if (su_idx + mu_idx == 0) {
+ ret = -1;
+ if (not_ready)
+ ret = -2;
+ }
+
+ RTW_INFO("-%s: There are %d SU and %d MU BFees in this sounding period\n", __func__, su_idx, mu_idx);
+
+ return ret;
+}
+
+static void _sounding_handler(PADAPTER adapter)
+{
+ struct beamforming_info *info;
+ struct sounding_info *sounding;
+ struct beamformee_entry *bfee;
+ u8 su_idx, i;
+ u32 timeout_period = 0;
+ u8 set_timer = false;
+ int ret = 0;
+ static u16 wait_cnt = 0;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+ sounding = &info->sounding_info;
+
+ RTW_DBG("+%s: state=%d\n", __func__, sounding->state);
+ if ((sounding->state != SOUNDING_STATE_INIT)
+ && (sounding->state != SOUNDING_STATE_SU_SOUNDDOWN)
+ && (sounding->state != SOUNDING_STATE_MU_SOUNDDOWN)
+ && (sounding->state != SOUNDING_STATE_SOUNDING_TIMEOUT)) {
+ RTW_WARN("%s: Invalid State(%d) and return!\n", __func__, sounding->state);
+ return;
+ }
+
+ if (sounding->state == SOUNDING_STATE_INIT) {
+ RTW_INFO("%s: Sounding start\n", __func__);
+
+ /* Init Var */
+ _sounding_reset_vars(adapter);
+
+ /* Get the sounding list of this sounding period */
+ ret = _sounding_get_list(adapter);
+ if (ret == -1) {
+ wait_cnt = 0;
+ sounding->state = SOUNDING_STATE_NONE;
+ RTW_ERR("%s: No BFees found, set to SOUNDING_STATE_NONE\n", __func__);
+ info->sounding_running--;
+ return;
+ }
+ if (ret == -2) {
+ RTW_WARN("%s: Temporarily cann't find BFee to sounding\n", __func__);
+ if (wait_cnt < 5) {
+ wait_cnt++;
+ } else {
+ wait_cnt = 0;
+ sounding->state = SOUNDING_STATE_NONE;
+ RTW_ERR("%s: Wait changing state timeout!! Set to SOUNDING_STATE_NONE\n", __func__);
+ }
+ info->sounding_running--;
+ return;
+ }
+ if (ret != 0) {
+ wait_cnt = 0;
+ RTW_ERR("%s: Unkown state(%d)!\n", __func__, ret);
+ info->sounding_running--;
+ return;
+
+ }
+
+ wait_cnt = 0;
+
+ if (check_fwstate(&adapter->mlmepriv, WIFI_SITE_MONITOR) == true) {
+ RTW_INFO("%s: Sounding abort! scanning APs...\n", __func__);
+ info->sounding_running--;
+ return;
+ }
+
+ rtw_ps_deny(adapter, PS_DENY_BEAMFORMING);
+ LeaveAllPowerSaveModeDirect(adapter);
+ }
+
+ /* Get non-sound SU BFee index */
+ for (i = 0; i < MAX_NUM_BEAMFORMEE_SU; i++) {
+ su_idx = sounding->su_sounding_list[i];
+ if (su_idx >= MAX_BEAMFORMEE_ENTRY_NUM)
+ continue;
+ bfee = &info->bfee_entry[su_idx];
+ if (false == bfee->sounding)
+ break;
+ }
+ if (i < MAX_NUM_BEAMFORMEE_SU) {
+ sounding->su_bfee_curidx = su_idx;
+ /* Set to sounding start state */
+ sounding->state = SOUNDING_STATE_SU_START;
+ RTW_DBG("%s: Set to SOUNDING_STATE_SU_START\n", __func__);
+
+ bfee->sounding = true;
+ /* Reset sounding timeout flag for the new sounding */
+ bfee->bSoundingTimeout = false;
+
+ if (bfee->bDeleteSounding) {
+ u8 res = false;
+ rtw_bf_cmd(adapter, BEAMFORMING_CTRL_END_PERIOD, &res, 1, 0);
+ return;
+ }
+
+ /* Start SU sounding */
+ if (bfee->cap & BEAMFORMEE_CAP_VHT_SU)
+ _send_vht_ndpa_packet(adapter, bfee->mac_addr, bfee->aid, bfee->sound_bw);
+ else if (bfee->cap & BEAMFORMEE_CAP_HT_EXPLICIT)
+ _send_ht_ndpa_packet(adapter, bfee->mac_addr, bfee->sound_bw);
+
+ /* Set sounding timeout timer */
+ _set_timer(&info->sounding_timeout_timer, SU_SOUNDING_TIMEOUT);
+ return;
+ }
+
+ if (sounding->candidate_mu_bfee_cnt > 0) {
+ /*
+ * If there is no SU BFee then find MU BFee and perform MU sounding
+ *
+ * <tynli_note> Need to check the MU starting condition. 2015.12.15.
+ */
+ sounding->state = SOUNDING_STATE_MU_START;
+ RTW_DBG("%s: Set to SOUNDING_STATE_MU_START\n", __func__);
+
+ /* Update MU BFee info */
+ for (i = 0; i < sounding->candidate_mu_bfee_cnt; i++) {
+ bfee = &info->bfee_entry[sounding->mu_sounding_list[i]];
+ bfee->sounding = true;
+ }
+
+ /* Send MU NDPA */
+ bfee = &info->bfee_entry[sounding->mu_sounding_list[0]];
+ _send_vht_mu_ndpa_packet(adapter, bfee->sound_bw);
+
+ /* Send BF report poll if more than 1 MU STA */
+ for (i = 1; i < sounding->candidate_mu_bfee_cnt; i++) {
+ bfee = &info->bfee_entry[sounding->mu_sounding_list[i]];
+
+ if (i == (sounding->candidate_mu_bfee_cnt - 1))/* The last STA*/
+ _send_bf_report_poll(adapter, bfee->mac_addr, true);
+ else
+ _send_bf_report_poll(adapter, bfee->mac_addr, false);
+ }
+
+ sounding->candidate_mu_bfee_cnt = 0;
+
+ /* Set sounding timeout timer */
+ _set_timer(&info->sounding_timeout_timer, MU_SOUNDING_TIMEOUT);
+ return;
+ }
+
+ info->sounding_running--;
+ sounding->state = SOUNDING_STATE_INIT;
+ RTW_INFO("%s: Sounding finished!\n", __func__);
+ rtw_ps_deny_cancel(adapter, PS_DENY_BEAMFORMING);
+}
+
+static void _sounding_force_stop(PADAPTER adapter)
+{
+ struct beamforming_info *info;
+ struct sounding_info *sounding;
+ u8 cancelled;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+ sounding = &info->sounding_info;
+
+ if ((sounding->state == SOUNDING_STATE_SU_START)
+ || (sounding->state == SOUNDING_STATE_MU_START)) {
+ u8 res = false;
+ _cancel_timer(&info->sounding_timeout_timer, &cancelled);
+ rtw_bf_cmd(adapter, BEAMFORMING_CTRL_END_PERIOD, &res, 1, 1);
+ return;
+ }
+
+ info->sounding_running--;
+ sounding->state = SOUNDING_STATE_INIT;
+ RTW_INFO("%s: Sounding finished!\n", __func__);
+ rtw_ps_deny_cancel(adapter, PS_DENY_BEAMFORMING);
+}
+
+static void _sounding_timer_handler(void *FunctionContext)
+{
+ PADAPTER adapter;
+ struct beamforming_info *info;
+ struct sounding_info *sounding;
+ static u8 delay = 0;
+
+
+ RTW_DBG("+%s\n", __func__);
+
+ adapter = (PADAPTER)FunctionContext;
+ info = GET_BEAMFORM_INFO(adapter);
+ sounding = &info->sounding_info;
+
+ if (SOUNDING_STATE_NONE == sounding->state) {
+ RTW_INFO("%s: Stop!\n", __func__);
+ if (info->sounding_running)
+ RTW_WARN("%s: souding_running=%d when thread stop!\n",
+ __func__, info->sounding_running);
+ return;
+ }
+
+ _set_timer(&info->sounding_timer, sounding->min_sounding_period);
+
+ if (!info->sounding_running) {
+ if (SOUNDING_STATE_INIT != sounding->state) {
+ RTW_WARN("%s: state(%d) != SOUNDING_STATE_INIT!!\n", __func__, sounding->state);
+ sounding->state = SOUNDING_STATE_INIT;
+ }
+ delay = 0;
+ info->sounding_running++;
+ rtw_bf_cmd(adapter, BEAMFORMING_CTRL_START_PERIOD, NULL, 0, 1);
+ } else {
+ if (delay != 0xFF)
+ delay++;
+ RTW_WARN("%s: souding is still processing...(state:%d, running:%d, delay:%d)\n",
+ __func__, sounding->state, info->sounding_running, delay);
+ if (delay > 3) {
+ RTW_WARN("%s: Stop sounding!!\n", __func__);
+ _sounding_force_stop(adapter);
+ }
+ }
+}
+
+static void _sounding_timeout_timer_handler(void *FunctionContext)
+{
+ PADAPTER adapter;
+ struct beamforming_info *info;
+ struct sounding_info *sounding;
+ struct beamformee_entry *bfee;
+
+
+ RTW_WARN("+%s\n", __func__);
+
+ adapter = (PADAPTER)FunctionContext;
+ info = GET_BEAMFORM_INFO(adapter);
+ sounding = &info->sounding_info;
+
+ if (SOUNDING_STATE_SU_START == sounding->state) {
+ sounding->state = SOUNDING_STATE_SOUNDING_TIMEOUT;
+ RTW_ERR("%s: Set to SU SOUNDING_STATE_SOUNDING_TIMEOUT\n", __func__);
+ /* SU BFee */
+ bfee = &info->bfee_entry[sounding->su_bfee_curidx];
+ bfee->bSoundingTimeout = true;
+ RTW_WARN("%s: The BFee entry[%d] is Sounding Timeout!\n", __func__, sounding->su_bfee_curidx);
+ } else if (SOUNDING_STATE_MU_START == sounding->state) {
+ sounding->state = SOUNDING_STATE_SOUNDING_TIMEOUT;
+ RTW_ERR("%s: Set to MU SOUNDING_STATE_SOUNDING_TIMEOUT\n", __func__);
+ } else {
+ RTW_WARN("%s: unexpected sounding state:0x%02x\n", __func__, sounding->state);
+ return;
+ }
+
+ rtw_bf_cmd(adapter, BEAMFORMING_CTRL_START_PERIOD, NULL, 0, 1);
+}
+
+static struct beamformer_entry *_bfer_get_free_entry(PADAPTER adapter)
+{
+ u8 i = 0;
+ struct beamforming_info *info;
+ struct beamformer_entry *bfer;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+
+ for (i = 0; i < MAX_BEAMFORMER_ENTRY_NUM; i++) {
+ bfer = &info->bfer_entry[i];
+ if (bfer->used == false)
+ return bfer;
+ }
+
+ return NULL;
+}
+
+static struct beamformer_entry *_bfer_get_entry_by_addr(PADAPTER adapter, u8 *ra)
+{
+ u8 i = 0;
+ struct beamforming_info *info;
+ struct beamformer_entry *bfer;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+
+ for (i = 0; i < MAX_BEAMFORMER_ENTRY_NUM; i++) {
+ bfer = &info->bfer_entry[i];
+ if (bfer->used == false)
+ continue;
+ if (!memcmp(ra, bfer->mac_addr, ETH_ALEN) == true)
+ return bfer;
+ }
+
+ return NULL;
+}
+
+static struct beamformer_entry *_bfer_add_entry(PADAPTER adapter,
+ struct sta_info *sta, u8 bf_cap, u8 sounding_dim, u8 comp_steering)
+{
+ struct mlme_priv *mlme;
+ struct beamforming_info *info;
+ struct beamformer_entry *bfer;
+ u8 *bssid;
+ u16 val16;
+ u8 i;
+
+
+ mlme = &adapter->mlmepriv;
+ info = GET_BEAMFORM_INFO(adapter);
+
+ bfer = _bfer_get_entry_by_addr(adapter, sta->hwaddr);
+ if (!bfer) {
+ bfer = _bfer_get_free_entry(adapter);
+ if (!bfer)
+ return NULL;
+ }
+
+ bfer->used = true;
+ _get_txvector_parameter(adapter, sta, &bfer->g_id, &bfer->p_aid);
+ memcpy(bfer->mac_addr, sta->hwaddr, ETH_ALEN);
+ bfer->cap = bf_cap;
+ bfer->state = BEAMFORM_ENTRY_HW_STATE_ADD_INIT;
+ bfer->NumofSoundingDim = sounding_dim;
+
+ if (TEST_FLAG(bf_cap, BEAMFORMER_CAP_VHT_MU)) {
+ info->beamformer_mu_cnt += 1;
+ bfer->aid = sta->aid;
+ } else if (TEST_FLAG(bf_cap, BEAMFORMER_CAP_VHT_SU|BEAMFORMER_CAP_HT_EXPLICIT)) {
+ info->beamformer_su_cnt += 1;
+
+ /* Record HW idx info */
+ for (i = 0; i < MAX_NUM_BEAMFORMER_SU; i++) {
+ if ((info->beamformer_su_reg_maping & BIT(i)) == 0) {
+ info->beamformer_su_reg_maping |= BIT(i);
+ bfer->su_reg_index = i;
+ break;
+ }
+ }
+ RTW_INFO("%s: Add BFer entry beamformer_su_reg_maping=%#x, su_reg_index=%d\n",
+ __func__, info->beamformer_su_reg_maping, bfer->su_reg_index);
+ }
+
+ return bfer;
+}
+
+static void _bfer_remove_entry(PADAPTER adapter, struct beamformer_entry *entry)
+{
+ struct beamforming_info *info;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+
+ entry->state = BEAMFORM_ENTRY_HW_STATE_DELETE_INIT;
+
+ if (TEST_FLAG(entry->cap, BEAMFORMER_CAP_VHT_MU)) {
+ info->beamformer_mu_cnt -= 1;
+ memset(entry->gid_valid, 0, 8);
+ memset(entry->user_position, 0, 16);
+ } else if (TEST_FLAG(entry->cap, BEAMFORMER_CAP_VHT_SU|BEAMFORMER_CAP_HT_EXPLICIT)) {
+ info->beamformer_su_cnt -= 1;
+ }
+
+ if (info->beamformer_mu_cnt == 0)
+ info->beamforming_cap &= ~BEAMFORMEE_CAP_VHT_MU;
+ if (info->beamformer_su_cnt == 0)
+ info->beamforming_cap &= ~(BEAMFORMEE_CAP_VHT_SU|BEAMFORMEE_CAP_HT_EXPLICIT);
+}
+
+static u8 _bfer_set_entry_gid(PADAPTER adapter, u8 *addr, u8 *gid, u8 *position)
+{
+ struct beamformer_entry *bfer = NULL;
+
+
+ bfer = _bfer_get_entry_by_addr(adapter, addr);
+ if (!bfer) {
+ RTW_INFO("%s: Cannot find BFer entry!!\n", __func__);
+ return _FAIL;
+ }
+
+ /* Parsing Membership Status Array */
+ memcpy(bfer->gid_valid, gid, 8);
+ /* Parsing User Position Array */
+ memcpy(bfer->user_position, position, 16);
+
+ /* Config HW GID table */
+ rtw_bf_cmd(adapter, BEAMFORMING_CTRL_SET_GID_TABLE, (u8*)&bfer, sizeof(struct beamformer_entry *), 1);
+
+ return _SUCCESS;
+}
+
+static struct beamformee_entry *_bfee_get_free_entry(PADAPTER adapter)
+{
+ u8 i = 0;
+ struct beamforming_info *info;
+ struct beamformee_entry *bfee;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+
+ for (i = 0; i < MAX_BEAMFORMEE_ENTRY_NUM; i++) {
+ bfee = &info->bfee_entry[i];
+ if (bfee->used == false)
+ return bfee;
+ }
+
+ return NULL;
+}
+
+static struct beamformee_entry *_bfee_get_entry_by_addr(PADAPTER adapter, u8 *ra)
+{
+ u8 i = 0;
+ struct beamforming_info *info;
+ struct beamformee_entry *bfee;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+
+ for (i = 0; i < MAX_BEAMFORMEE_ENTRY_NUM; i++) {
+ bfee = &info->bfee_entry[i];
+ if (bfee->used == false)
+ continue;
+ if (!memcmp(ra, bfee->mac_addr, ETH_ALEN) == true)
+ return bfee;
+ }
+
+ return NULL;
+}
+
+static u8 _bfee_get_first_su_entry_idx(PADAPTER adapter, struct beamformee_entry *ignore)
+{
+ struct beamforming_info *info;
+ struct beamformee_entry *bfee;
+ u8 i;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+
+ for (i = 0; i < MAX_BEAMFORMEE_ENTRY_NUM; i++) {
+ bfee = &info->bfee_entry[i];
+ if (ignore && (bfee == ignore))
+ continue;
+ if (bfee->used == false)
+ continue;
+ if ((!TEST_FLAG(bfee->cap, BEAMFORMEE_CAP_VHT_MU))
+ && TEST_FLAG(bfee->cap, BEAMFORMEE_CAP_VHT_SU|BEAMFORMEE_CAP_HT_EXPLICIT))
+ return i;
+ }
+
+ return 0xFF;
+}
+
+/*
+ * Description:
+ * Get the first entry index of MU Beamformee.
+ *
+ * Return Value:
+ * Index of the first MU sta, or 0xFF for invalid index.
+ *
+ * 2015.05.25. Created by tynli.
+ *
+ */
+static u8 _bfee_get_first_mu_entry_idx(PADAPTER adapter, struct beamformee_entry *ignore)
+{
+ struct beamforming_info *info;
+ struct beamformee_entry *bfee;
+ u8 i;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+
+ for (i = 0; i < MAX_BEAMFORMEE_ENTRY_NUM; i++) {
+ bfee = &info->bfee_entry[i];
+ if (ignore && (bfee == ignore))
+ continue;
+ if (bfee->used == false)
+ continue;
+ if (TEST_FLAG(bfee->cap, BEAMFORMEE_CAP_VHT_MU))
+ return i;
+ }
+
+ return 0xFF;
+}
+
+static struct beamformee_entry *_bfee_add_entry(PADAPTER adapter,
+ struct sta_info *sta, u8 bf_cap, u8 sounding_dim, u8 comp_steering)
+{
+ struct mlme_priv *mlme;
+ struct beamforming_info *info;
+ struct beamformee_entry *bfee;
+ u8 *bssid;
+ u16 val16;
+ u8 i;
+
+
+ mlme = &adapter->mlmepriv;
+ info = GET_BEAMFORM_INFO(adapter);
+
+ bfee = _bfee_get_entry_by_addr(adapter, sta->hwaddr);
+ if (!bfee) {
+ bfee = _bfee_get_free_entry(adapter);
+ if (!bfee)
+ return NULL;
+ }
+
+ bfee->used = true;
+ bfee->aid = sta->aid;
+ bfee->mac_id = sta->mac_id;
+ bfee->sound_bw = sta->bw_mode;
+
+ _get_txvector_parameter(adapter, sta, &bfee->g_id, &bfee->p_aid);
+ sta->txbf_gid = bfee->g_id;
+ sta->txbf_paid = bfee->p_aid;
+
+ memcpy(bfee->mac_addr, sta->hwaddr, ETH_ALEN);
+ bfee->txbf = false;
+ bfee->sounding = false;
+ bfee->sound_period = 40;
+ _sounding_update_min_period(adapter, bfee->sound_period, false);
+ bfee->SoundCnt = GetInitSoundCnt(bfee->sound_period, info->sounding_info.min_sounding_period);
+ bfee->cap = bf_cap;
+ bfee->state = BEAMFORM_ENTRY_HW_STATE_ADD_INIT;
+
+ bfee->bCandidateSoundingPeer = false;
+ bfee->bSoundingTimeout = false;
+ bfee->bDeleteSounding = false;
+ bfee->bApplySounding = true;
+
+ bfee->tx_timestamp = 0;
+ bfee->tx_bytes = 0;
+
+ bfee->LogStatusFailCnt = 0;
+ bfee->NumofSoundingDim = sounding_dim;
+ bfee->comp_steering_num_of_bfer = comp_steering;
+ bfee->bSuspendSUCap = false;
+
+ if (TEST_FLAG(bf_cap, BEAMFORMEE_CAP_VHT_MU)) {
+ info->beamformee_mu_cnt += 1;
+ info->first_mu_bfee_index = _bfee_get_first_mu_entry_idx(adapter, NULL);
+
+ if (info->bEnableSUTxBFWorkAround) {
+ /* When the first MU BFee added, discard SU BFee bfee's capability */
+ if ((info->beamformee_mu_cnt == 1) && (info->beamformee_su_cnt > 0)) {
+ if (info->TargetSUBFee) {
+ info->TargetSUBFee->bSuspendSUCap = true;
+ info->TargetSUBFee->bDeleteSounding = true;
+ } else {
+ RTW_ERR("%s: UNEXPECTED!! info->TargetSUBFee is NULL!", __func__);
+ }
+ info->TargetSUBFee = NULL;
+ memset(&info->TargetCSIInfo, 0, sizeof(struct _RT_CSI_INFO));
+ rtw_bf_cmd(adapter, BEAMFORMING_CTRL_SET_CSI_REPORT, (u8*)&info->TargetCSIInfo, sizeof(struct _RT_CSI_INFO), 0);
+ }
+ }
+
+ /* Record HW idx info */
+ for (i = 0; i < MAX_NUM_BEAMFORMEE_MU; i++) {
+ if ((info->beamformee_mu_reg_maping & BIT(i)) == 0) {
+ info->beamformee_mu_reg_maping |= BIT(i);
+ bfee->mu_reg_index = i;
+ break;
+ }
+ }
+ RTW_INFO("%s: Add BFee entry beamformee_mu_reg_maping=%#x, mu_reg_index=%d\n",
+ __func__, info->beamformee_mu_reg_maping, bfee->mu_reg_index);
+
+ } else if (TEST_FLAG(bf_cap, BEAMFORMEE_CAP_VHT_SU|BEAMFORMEE_CAP_HT_EXPLICIT)) {
+ info->beamformee_su_cnt += 1;
+
+ if (info->bEnableSUTxBFWorkAround) {
+ /* Record the first SU BFee index. We only allow the first SU BFee to be sound */
+ if ((info->beamformee_su_cnt == 1) && (info->beamformee_mu_cnt == 0)) {
+ info->TargetSUBFee = bfee;
+ memset(&info->TargetCSIInfo, 0, sizeof(struct _RT_CSI_INFO));
+ bfee->bSuspendSUCap = false;
+ } else {
+ bfee->bSuspendSUCap = true;
+ }
+ }
+
+ /* Record HW idx info */
+ for (i = 0; i < MAX_NUM_BEAMFORMEE_SU; i++) {
+ if ((info->beamformee_su_reg_maping & BIT(i)) == 0) {
+ info->beamformee_su_reg_maping |= BIT(i);
+ bfee->su_reg_index = i;
+ break;
+ }
+ }
+ RTW_INFO("%s: Add BFee entry beamformee_su_reg_maping=%#x, su_reg_index=%d\n",
+ __func__, info->beamformee_su_reg_maping, bfee->su_reg_index);
+ }
+
+ return bfee;
+}
+
+static void _bfee_remove_entry(PADAPTER adapter, struct beamformee_entry *entry)
+{
+ struct beamforming_info *info;
+ u8 idx;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+
+ entry->state = BEAMFORM_ENTRY_HW_STATE_DELETE_INIT;
+
+ if (TEST_FLAG(entry->cap, BEAMFORMEE_CAP_VHT_MU)) {
+ info->beamformee_mu_cnt -= 1;
+ info->first_mu_bfee_index = _bfee_get_first_mu_entry_idx(adapter, entry);
+
+ if (info->bEnableSUTxBFWorkAround) {
+ if ((info->beamformee_mu_cnt == 0) && (info->beamformee_su_cnt > 0)) {
+ idx = _bfee_get_first_su_entry_idx(adapter, NULL);
+ info->TargetSUBFee = &info->bfee_entry[idx];
+ memset(&info->TargetCSIInfo, 0, sizeof(struct _RT_CSI_INFO));
+ info->TargetSUBFee->bSuspendSUCap = false;
+ }
+ }
+ } else if (TEST_FLAG(entry->cap, BEAMFORMEE_CAP_VHT_SU|BEAMFORMEE_CAP_HT_EXPLICIT)) {
+ info->beamformee_su_cnt -= 1;
+
+ /* When the target SU BFee leaves, disable workaround */
+ if ((info->bEnableSUTxBFWorkAround)
+ && (entry == info->TargetSUBFee)) {
+ entry->bSuspendSUCap = true;
+ info->TargetSUBFee = NULL;
+ memset(&info->TargetCSIInfo, 0, sizeof(struct _RT_CSI_INFO));
+ rtw_bf_cmd(adapter, BEAMFORMING_CTRL_SET_CSI_REPORT, (u8*)&info->TargetCSIInfo, sizeof(struct _RT_CSI_INFO), 0);
+ }
+ }
+
+ if (info->beamformee_mu_cnt == 0)
+ info->beamforming_cap &= ~BEAMFORMER_CAP_VHT_MU;
+ if (info->beamformee_su_cnt == 0)
+ info->beamforming_cap &= ~(BEAMFORMER_CAP_VHT_SU|BEAMFORMER_CAP_HT_EXPLICIT);
+
+ _sounding_update_min_period(adapter, 0, true);
+}
+
+static enum beamforming_cap _bfee_get_entry_cap_by_macid(PADAPTER adapter, u8 macid)
+{
+ struct beamforming_info *info;
+ struct beamformee_entry *bfee;
+ u8 i;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+
+ for (i = 0; i < MAX_BEAMFORMER_ENTRY_NUM; i++) {
+ bfee = &info->bfee_entry[i];
+ if (bfee->used == false)
+ continue;
+ if (bfee->mac_id == macid)
+ return bfee->cap;
+ }
+
+ return BEAMFORMING_CAP_NONE;
+}
+
+static void _beamforming_enter(PADAPTER adapter, void *p)
+{
+ struct mlme_priv *mlme;
+ struct ht_priv *htpriv;
+ struct mlme_ext_priv *mlme_ext;
+ struct sta_info *sta, *sta_copy;
+ struct beamforming_info *info;
+ struct beamformer_entry *bfer = NULL;
+ struct beamformee_entry *bfee = NULL;
+ u8 wireless_mode;
+ u8 sta_bf_cap;
+ u8 sounding_dim = 0; /* number of sounding dimensions */
+ u8 comp_steering_num = 0; /* compressed steering number */
+
+
+ mlme = &adapter->mlmepriv;
+ htpriv = &mlme->htpriv;
+ mlme_ext = &adapter->mlmeextpriv;
+ info = GET_BEAMFORM_INFO(adapter);
+
+ sta_copy = (struct sta_info *)p;
+ sta = rtw_get_stainfo(&adapter->stapriv, sta_copy->hwaddr);
+ if (!sta) {
+ RTW_ERR("%s: Cann't find STA info for " MAC_FMT "\n",
+ __func__, MAC_ARG(sta_copy->hwaddr));
+ return;
+ }
+ if (sta != sta_copy) {
+ RTW_WARN("%s: Origin sta(fake)=%p realsta=%p for " MAC_FMT "\n",
+ __func__, sta_copy, sta, MAC_ARG(sta_copy->hwaddr));
+ }
+
+ /* The current setting does not support Beaforming */
+ wireless_mode = sta->wireless_mode;
+ if ((is_supported_ht(wireless_mode) == false)
+ && (is_supported_vht(wireless_mode) == false)) {
+ RTW_WARN("%s: Not support HT or VHT mode\n", __func__);
+ return;
+ }
+
+ if ((0 == htpriv->beamform_cap)) {
+ RTW_INFO("The configuration disabled Beamforming! Skip...\n");
+ return;
+ }
+
+ _get_sta_beamform_cap(adapter, sta,
+ &sta_bf_cap, &sounding_dim, &comp_steering_num);
+ RTW_INFO("STA Beamforming Capability=0x%02X\n", sta_bf_cap);
+ if (sta_bf_cap == BEAMFORMING_CAP_NONE)
+ return;
+ if ((sta_bf_cap & BEAMFORMEE_CAP_HT_EXPLICIT)
+ || (sta_bf_cap & BEAMFORMEE_CAP_VHT_SU)
+ || (sta_bf_cap & BEAMFORMEE_CAP_VHT_MU))
+ sta_bf_cap |= BEAMFORMEE_CAP;
+ if ((sta_bf_cap & BEAMFORMER_CAP_HT_EXPLICIT)
+ || (sta_bf_cap & BEAMFORMER_CAP_VHT_SU)
+ || (sta_bf_cap & BEAMFORMER_CAP_VHT_MU))
+ sta_bf_cap |= BEAMFORMER_CAP;
+
+ if (sta_bf_cap & BEAMFORMER_CAP) {
+ /* The other side is beamformer */
+ bfer = _bfer_add_entry(adapter, sta, sta_bf_cap, sounding_dim, comp_steering_num);
+ if (!bfer)
+ RTW_ERR("%s: Fail to allocate bfer entry!\n", __func__);
+ }
+ if (sta_bf_cap & BEAMFORMEE_CAP) {
+ /* The other side is beamformee */
+ bfee = _bfee_add_entry(adapter, sta, sta_bf_cap, sounding_dim, comp_steering_num);
+ if (!bfee)
+ RTW_ERR("%s: Fail to allocate bfee entry!\n", __func__);
+ }
+ if (!bfer && !bfee)
+ return;
+
+ rtw_hal_set_hwreg(adapter, HW_VAR_SOUNDING_ENTER, (u8*)sta);
+
+ /* Perform sounding if there is BFee */
+ if ((info->beamformee_su_cnt != 0)
+ || (info->beamformee_mu_cnt != 0)) {
+ if (SOUNDING_STATE_NONE == info->sounding_info.state) {
+ info->sounding_info.state = SOUNDING_STATE_INIT;
+ /* Start sounding after 2 sec */
+ _set_timer(&info->sounding_timer, 2000);
+ }
+ }
+}
+
+static void _beamforming_reset(PADAPTER adapter)
+{
+ RTW_ERR("%s: Not ready!!\n", __func__);
+}
+
+static void _beamforming_leave(PADAPTER adapter, u8 *ra)
+{
+ struct beamforming_info *info;
+ struct beamformer_entry *bfer = NULL;
+ struct beamformee_entry *bfee = NULL;
+ u8 bHwStateAddInit = false;
+
+
+ RTW_INFO("+%s\n", __func__);
+
+ info = GET_BEAMFORM_INFO(adapter);
+ bfer = _bfer_get_entry_by_addr(adapter, ra);
+ bfee = _bfee_get_entry_by_addr(adapter, ra);
+
+ if (!bfer && !bfee) {
+ RTW_WARN("%s: " MAC_FMT " is neither beamforming ee or er!!\n",
+ __func__, MAC_ARG(ra));
+ return;
+ }
+
+ if (bfer)
+ _bfer_remove_entry(adapter, bfer);
+
+ if (bfee)
+ _bfee_remove_entry(adapter, bfee);
+
+ rtw_hal_set_hwreg(adapter, HW_VAR_SOUNDING_LEAVE, ra);
+
+ /* Stop sounding if there is no any BFee */
+ if ((info->beamformee_su_cnt == 0)
+ && (info->beamformee_mu_cnt == 0)) {
+ u8 cancelled;
+ _cancel_timer(&info->sounding_timer, &cancelled);
+ _sounding_init(&info->sounding_info);
+ }
+
+ RTW_INFO("-%s\n", __func__);
+}
+
+static void _beamforming_sounding_down(PADAPTER adapter, u8 status)
+{
+ struct beamforming_info *info;
+ struct sounding_info *sounding;
+ struct beamformee_entry *bfee;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+ sounding = &info->sounding_info;
+
+ RTW_INFO("+%s: sounding=%d, status=0x%02x\n", __func__, sounding->state, status);
+
+ if (sounding->state == SOUNDING_STATE_MU_START) {
+ RTW_INFO("%s: MU sounding done\n", __func__);
+ sounding->state = SOUNDING_STATE_MU_SOUNDDOWN;
+ RTW_INFO("%s: Set to SOUNDING_STATE_MU_SOUNDDOWN\n", __func__);
+ info->SetHalSoundownOnDemandCnt++;
+ rtw_hal_set_hwreg(adapter, HW_VAR_SOUNDING_STATUS, &status);
+ } else if (sounding->state == SOUNDING_STATE_SU_START) {
+ RTW_INFO("%s: SU entry[%d] sounding down\n", __func__, sounding->su_bfee_curidx);
+ bfee = &info->bfee_entry[sounding->su_bfee_curidx];
+ sounding->state = SOUNDING_STATE_SU_SOUNDDOWN;
+ RTW_INFO("%s: Set to SOUNDING_STATE_SU_SOUNDDOWN\n", __func__);
+
+ /*
+ * <tynli_note>
+ * bfee->bSoundingTimeout this flag still cannot avoid
+ * old sound down event happens in the new sounding period.
+ * 2015.12.10
+ */
+ if (bfee->bSoundingTimeout) {
+ RTW_WARN("%s: The entry[%d] is bSoundingTimeout!\n", __func__, sounding->su_bfee_curidx);
+ bfee->bSoundingTimeout = false;
+ return;
+ }
+
+ if (status) {
+ /* success */
+ bfee->LogStatusFailCnt = 0;
+ info->SetHalSoundownOnDemandCnt++;
+ rtw_hal_set_hwreg(adapter, HW_VAR_SOUNDING_STATUS, &status);
+ } else if (bfee->bDeleteSounding) {
+ RTW_WARN("%s: Delete entry[%d] sounding info!\n", __func__, sounding->su_bfee_curidx);
+ rtw_hal_set_hwreg(adapter, HW_VAR_SOUNDING_STATUS, &status);
+ bfee->bDeleteSounding = false;
+ } else {
+ bfee->LogStatusFailCnt++;
+ RTW_WARN("%s: LogStatusFailCnt=%d\n", __func__, bfee->LogStatusFailCnt);
+ if (bfee->LogStatusFailCnt > 30) {
+ RTW_ERR("%s: LogStatusFailCnt > 30, Stop SOUNDING!!\n", __func__);
+ rtw_bf_cmd(adapter, BEAMFORMING_CTRL_LEAVE, bfee->mac_addr, ETH_ALEN, 1);
+ }
+ }
+ } else {
+ RTW_WARN("%s: unexpected sounding state:0x%02x\n", __func__, sounding->state);
+ return;
+ }
+
+ rtw_bf_cmd(adapter, BEAMFORMING_CTRL_START_PERIOD, NULL, 0, 0);
+}
+
+static void _c2h_snd_txbf(PADAPTER adapter, u8 *buf, u8 buf_len)
+{
+ struct beamforming_info *info;
+ u8 cancelled;
+ u8 res;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+
+ _cancel_timer(&info->sounding_timeout_timer, &cancelled);
+
+ res = C2H_SND_TXBF_GET_SND_RESULT(buf) ? true : false;
+ RTW_INFO("+%s: %s\n", __func__, res==true?"Success":"Fail!");
+
+ rtw_bf_cmd(adapter, BEAMFORMING_CTRL_END_PERIOD, &res, 1, 1);
+}
+
+/*
+ * Description:
+ * This function is for phydm only
+ */
+enum beamforming_cap rtw_bf_bfee_get_entry_cap_by_macid(void *mlme, u8 macid)
+{
+ PADAPTER adapter;
+ enum beamforming_cap cap = BEAMFORMING_CAP_NONE;
+
+
+ adapter = mlme_to_adapter((struct mlme_priv *)mlme);
+ cap = _bfee_get_entry_cap_by_macid(adapter, macid);
+
+ return cap;
+}
+
+struct beamformer_entry *rtw_bf_bfer_get_entry_by_addr(PADAPTER adapter, u8 *ra)
+{
+ return _bfer_get_entry_by_addr(adapter, ra);
+}
+
+struct beamformee_entry *rtw_bf_bfee_get_entry_by_addr(PADAPTER adapter, u8 *ra)
+{
+ return _bfee_get_entry_by_addr(adapter, ra);
+}
+
+void rtw_bf_get_ndpa_packet(PADAPTER adapter, union recv_frame *precv_frame)
+{
+ RTW_DBG("+%s\n", __func__);
+}
+
+u32 rtw_bf_get_report_packet(PADAPTER adapter, union recv_frame *precv_frame)
+{
+ u32 ret = _SUCCESS;
+ struct beamforming_info *info;
+ struct beamformee_entry *bfee = NULL;
+ u8 *pframe;
+ u32 frame_len;
+ u8 *ta;
+ u8 *frame_body;
+ u8 category, action;
+ u8 *pMIMOCtrlField, *pCSIMatrix;
+ u8 Nc = 0, Nr = 0, CH_W = 0, Ng = 0, CodeBook = 0;
+ u16 CSIMatrixLen = 0;
+
+
+ RTW_INFO("+%s\n", __func__);
+
+ info = GET_BEAMFORM_INFO(adapter);
+ pframe = precv_frame->u.hdr.rx_data;
+ frame_len = precv_frame->u.hdr.len;
+
+ /* Memory comparison to see if CSI report is the same with previous one */
+ ta = get_addr2_ptr(pframe);
+ bfee = _bfee_get_entry_by_addr(adapter, ta);
+ if (!bfee)
+ return _FAIL;
+
+ frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
+ category = frame_body[0];
+ action = frame_body[1];
+
+ if ((category == RTW_WLAN_CATEGORY_VHT)
+ && (action == RTW_WLAN_ACTION_VHT_COMPRESSED_BEAMFORMING)) {
+ pMIMOCtrlField = pframe + 26;
+ Nc = (*pMIMOCtrlField) & 0x7;
+ Nr = ((*pMIMOCtrlField) & 0x38) >> 3;
+ CH_W = (((*pMIMOCtrlField) & 0xC0) >> 6);
+ Ng = (*(pMIMOCtrlField+1)) & 0x3;
+ CodeBook = ((*(pMIMOCtrlField+1)) & 0x4) >> 2;
+ /*
+ * 24+(1+1+3)+2
+ * ==> MAC header+(Category+ActionCode+MIMOControlField)+SNR(Nc=2)
+ */
+ pCSIMatrix = pMIMOCtrlField + 3 + Nc;
+ CSIMatrixLen = frame_len - 26 - 3 - Nc;
+ info->TargetCSIInfo.bVHT = true;
+ } else if ((category == RTW_WLAN_CATEGORY_HT)
+ && (action == RTW_WLAN_ACTION_HT_COMPRESS_BEAMFORMING)) {
+ pMIMOCtrlField = pframe + 26;
+ Nc = (*pMIMOCtrlField) & 0x3;
+ Nr = ((*pMIMOCtrlField) & 0xC) >> 2;
+ CH_W = ((*pMIMOCtrlField) & 0x10) >> 4;
+ Ng = ((*pMIMOCtrlField) & 0x60) >> 5;
+ CodeBook = ((*(pMIMOCtrlField+1)) & 0x6) >> 1;
+ /*
+ * 24+(1+1+6)+2
+ * ==> MAC header+(Category+ActionCode+MIMOControlField)+SNR(Nc=2)
+ */
+ pCSIMatrix = pMIMOCtrlField + 6 + Nr;
+ CSIMatrixLen = frame_len - 26 - 6 - Nr;
+ info->TargetCSIInfo.bVHT = false;
+ }
+
+ /* Update current CSI report info */
+ if ((info->bEnableSUTxBFWorkAround)
+ && (info->TargetSUBFee == bfee)) {
+ if ((info->TargetCSIInfo.Nc != Nc) || (info->TargetCSIInfo.Nr != Nr) ||
+ (info->TargetCSIInfo.ChnlWidth != CH_W) || (info->TargetCSIInfo.Ng != Ng) ||
+ (info->TargetCSIInfo.CodeBook != CodeBook)) {
+ info->TargetCSIInfo.Nc = Nc;
+ info->TargetCSIInfo.Nr = Nr;
+ info->TargetCSIInfo.ChnlWidth = CH_W;
+ info->TargetCSIInfo.Ng = Ng;
+ info->TargetCSIInfo.CodeBook = CodeBook;
+
+ rtw_bf_cmd(adapter, BEAMFORMING_CTRL_SET_CSI_REPORT, (u8*)&info->TargetCSIInfo, sizeof(struct _RT_CSI_INFO), 1);
+ }
+ }
+
+ RTW_INFO("%s: pkt type=%d-%d, Nc=%d, Nr=%d, CH_W=%d, Ng=%d, CodeBook=%d\n",
+ __func__, category, action, Nc, Nr, CH_W, Ng, CodeBook);
+
+ return ret;
+}
+
+u8 rtw_bf_send_vht_gid_mgnt_packet(PADAPTER adapter, u8 *ra, u8 *gid, u8 *position)
+{
+ /* General */
+ struct xmit_priv *xmitpriv;
+ struct mlme_priv *mlmepriv;
+ struct xmit_frame *pmgntframe;
+ /* MISC */
+ struct pkt_attrib *attrib;
+ struct rtw_ieee80211_hdr *wlanhdr;
+ u8 *pframe, *ptr;
+
+
+ xmitpriv = &adapter->xmitpriv;
+ mlmepriv = &adapter->mlmepriv;
+
+ pmgntframe = alloc_mgtxmitframe(xmitpriv);
+ if (!pmgntframe)
+ return false;
+
+ /* update attribute */
+ attrib = &pmgntframe->attrib;
+ update_mgntframe_attrib(adapter, attrib);
+ attrib->rate = MGN_6M;
+ attrib->bwmode = CHANNEL_WIDTH_20;
+ attrib->subtype = WIFI_ACTION;
+
+ memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
+
+ pframe = (u8 *)pmgntframe->buf_addr + TXDESC_OFFSET;
+ wlanhdr = (struct rtw_ieee80211_hdr *)pframe;
+
+ wlanhdr->frame_ctl = 0;
+ set_frame_sub_type(pframe, attrib->subtype);
+ set_duration(pframe, 0);
+ SetFragNum(pframe, 0);
+ SetSeqNum(pframe, 0);
+
+ memcpy(wlanhdr->addr1, ra, ETH_ALEN);
+ memcpy(wlanhdr->addr2, adapter_mac_addr(adapter), ETH_ALEN);
+ memcpy(wlanhdr->addr3, get_bssid(mlmepriv), ETH_ALEN);
+
+ pframe[24] = RTW_WLAN_CATEGORY_VHT;
+ pframe[25] = RTW_WLAN_ACTION_VHT_GROUPID_MANAGEMENT;
+ /* Set Membership Status Array */
+ ptr = pframe + 26;
+ memcpy(ptr, gid, 8);
+ /* Set User Position Array */
+ ptr = pframe + 34;
+ memcpy(ptr, position, 16);
+
+ attrib->pktlen = 54;
+ attrib->last_txcmdsz = attrib->pktlen;
+
+ dump_mgntframe(adapter, pmgntframe);
+
+ return true;
+}
+
+/*
+ * Description:
+ * On VHT GID management frame by an MU beamformee.
+ */
+void rtw_bf_get_vht_gid_mgnt_packet(PADAPTER adapter, union recv_frame *precv_frame)
+{
+ u8 *pframe;
+ u8 *ta, *gid, *position;
+
+
+ RTW_DBG("+%s\n", __func__);
+
+ pframe = precv_frame->u.hdr.rx_data;
+
+ /* Get address by Addr2 */
+ ta = get_addr2_ptr(pframe);
+ /* Remove signaling TA */
+ ta[0] &= 0xFE;
+
+ /* Membership Status Array */
+ gid = pframe + 26;
+ /* User Position Array */
+ position= pframe + 34;
+
+ _bfer_set_entry_gid(adapter, ta, gid, position);
+}
+
+void rtw_bf_init(PADAPTER adapter)
+{
+ struct beamforming_info *info;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+ info->beamforming_cap = BEAMFORMING_CAP_NONE;
+ info->beamforming_state = BEAMFORMING_STATE_IDLE;
+/*
+ info->bfee_entry[MAX_BEAMFORMEE_ENTRY_NUM];
+ info->bfer_entry[MAX_BEAMFORMER_ENTRY_NUM];
+*/
+ info->sounding_sequence = 0;
+ info->beamformee_su_cnt = 0;
+ info->beamformer_su_cnt = 0;
+ info->beamformee_su_reg_maping = 0;
+ info->beamformer_su_reg_maping = 0;
+ info->beamformee_mu_cnt = 0;
+ info->beamformer_mu_cnt = 0;
+ info->beamformee_mu_reg_maping = 0;
+ info->first_mu_bfee_index = 0xFF;
+ info->mu_bfer_curidx = 0xFF;
+
+ _sounding_init(&info->sounding_info);
+ _init_timer(&info->sounding_timer, adapter->pnetdev, _sounding_timer_handler, adapter);
+ _init_timer(&info->sounding_timeout_timer, adapter->pnetdev, _sounding_timeout_timer_handler, adapter);
+
+ info->SetHalBFEnterOnDemandCnt = 0;
+ info->SetHalBFLeaveOnDemandCnt = 0;
+ info->SetHalSoundownOnDemandCnt = 0;
+
+ info->bEnableSUTxBFWorkAround = true;
+ info->TargetSUBFee = NULL;
+
+ info->sounding_running = 0;
+}
+
+void rtw_bf_cmd_hdl(PADAPTER adapter, u8 type, u8 *pbuf)
+{
+ switch (type) {
+ case BEAMFORMING_CTRL_ENTER:
+ _beamforming_enter(adapter, pbuf);
+ break;
+
+ case BEAMFORMING_CTRL_LEAVE:
+ if (pbuf == NULL)
+ _beamforming_reset(adapter);
+ else
+ _beamforming_leave(adapter, pbuf);
+ break;
+
+ case BEAMFORMING_CTRL_START_PERIOD:
+ _sounding_handler(adapter);
+ break;
+
+ case BEAMFORMING_CTRL_END_PERIOD:
+ _beamforming_sounding_down(adapter, *pbuf);
+ break;
+
+ case BEAMFORMING_CTRL_SET_GID_TABLE:
+ rtw_hal_set_hwreg(adapter, HW_VAR_SOUNDING_SET_GID_TABLE, *(void**)pbuf);
+ break;
+
+ case BEAMFORMING_CTRL_SET_CSI_REPORT:
+ rtw_hal_set_hwreg(adapter, HW_VAR_SOUNDING_CSI_REPORT, pbuf);
+ break;
+
+ default:
+ break;
+ }
+}
+
+u8 rtw_bf_cmd(PADAPTER adapter, s32 type, u8 *pbuf, s32 size, u8 enqueue)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct cmd_priv *pcmdpriv = &adapter->cmdpriv;
+ u8 *wk_buf;
+ u8 res = _SUCCESS;
+
+
+ if (!enqueue) {
+ rtw_bf_cmd_hdl(adapter, type, pbuf);
+ goto exit;
+ }
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (ph2c == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (pdrvextra_cmd_parm == NULL) {
+ rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ if (pbuf != NULL) {
+ wk_buf = rtw_zmalloc(size);
+ if (wk_buf == NULL) {
+ rtw_mfree((u8 *)ph2c, sizeof(struct cmd_obj));
+ rtw_mfree((u8 *)pdrvextra_cmd_parm, sizeof(struct drvextra_cmd_parm));
+ res = _FAIL;
+ goto exit;
+ }
+
+ memcpy(wk_buf, pbuf, size);
+ } else {
+ wk_buf = NULL;
+ size = 0;
+ }
+
+ pdrvextra_cmd_parm->ec_id = BEAMFORMING_WK_CID;
+ pdrvextra_cmd_parm->type = type;
+ pdrvextra_cmd_parm->size = size;
+ pdrvextra_cmd_parm->pbuf = wk_buf;
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+ return res;
+}
+
+void rtw_bf_update_attrib(PADAPTER adapter, struct pkt_attrib *attrib, struct sta_info *sta)
+{
+ if (sta) {
+ attrib->txbf_g_id = sta->txbf_gid;
+ attrib->txbf_p_aid = sta->txbf_paid;
+ }
+}
+
+void rtw_bf_c2h_handler(PADAPTER adapter, u8 id, u8 *buf, u8 buf_len)
+{
+ switch (id) {
+ case CMD_ID_C2H_SND_TXBF:
+ _c2h_snd_txbf(adapter, buf, buf_len);
+ break;
+ }
+}
+
+#define toMbps(bytes, secs) (rtw_division64(bytes >> 17, secs))
+void rtw_bf_update_traffic(PADAPTER adapter)
+{
+ struct beamforming_info *info;
+ struct sounding_info *sounding;
+ struct beamformee_entry *bfee;
+ struct sta_info *sta;
+ u8 bfee_cnt, sounding_idx, i;
+ u16 tp[MAX_BEAMFORMEE_ENTRY_NUM] = {0};
+ u8 tx_rate[MAX_BEAMFORMEE_ENTRY_NUM] = {0};
+ u64 tx_bytes, last_bytes;
+ u32 time, last_timestamp;
+ u8 set_timer = false;
+
+
+ info = GET_BEAMFORM_INFO(adapter);
+ sounding = &info->sounding_info;
+
+ /* Check any bfee exist? */
+ bfee_cnt = info->beamformee_su_cnt + info->beamformee_mu_cnt;
+ if (bfee_cnt == 0)
+ return;
+
+ for (i = 0; i < MAX_BEAMFORMEE_ENTRY_NUM; i++) {
+ bfee = &info->bfee_entry[i];
+ if (false == bfee->used)
+ continue;
+
+ sta = rtw_get_stainfo(&adapter->stapriv, bfee->mac_addr);
+ if (!sta) {
+ RTW_ERR("%s: Cann't find sta_info for " MAC_FMT "!\n", __func__, MAC_ARG(bfee->mac_addr));
+ continue;
+ }
+
+ last_timestamp = bfee->tx_timestamp;
+ last_bytes = bfee->tx_bytes;
+ bfee->tx_timestamp = jiffies;
+ bfee->tx_bytes = sta->sta_stats.tx_bytes;
+ if (last_timestamp) {
+ if (bfee->tx_bytes >= last_bytes)
+ tx_bytes = bfee->tx_bytes - last_bytes;
+ else
+ tx_bytes = bfee->tx_bytes + (~last_bytes);
+ time = rtw_get_time_interval_ms(last_timestamp, bfee->tx_timestamp);
+ time = (time > 1000) ? time/1000 : 1;
+ tp[i] = toMbps(tx_bytes, time);
+ tx_rate[i] = rtw_get_current_tx_rate(adapter, bfee->mac_id);
+ RTW_INFO("%s: BFee idx(%d), MadId(%d), TxTP=%lld bytes (%d Mbps), txrate=%d\n",
+ __func__, i, bfee->mac_id, tx_bytes, tp[i], tx_rate[i]);
+ }
+ }
+
+ sounding_idx = phydm_get_beamforming_sounding_info(GET_PDM_ODM(adapter), tp, MAX_BEAMFORMEE_ENTRY_NUM, tx_rate);
+
+ for (i = 0; i < MAX_BEAMFORMEE_ENTRY_NUM; i++) {
+ bfee = &info->bfee_entry[i];
+ if (false == bfee->used) {
+ if (sounding_idx & BIT(i))
+ RTW_WARN("%s: bfee(%d) not in used but need sounding?!\n", __func__, i);
+ continue;
+ }
+
+ if (sounding_idx & BIT(i)) {
+ if (false == bfee->bApplySounding) {
+ bfee->bApplySounding = true;
+ bfee->SoundCnt = 0;
+ set_timer = true;
+ }
+ } else {
+ if (bfee->bApplySounding) {
+ bfee->bApplySounding = false;
+ bfee->bDeleteSounding = true;
+ bfee->SoundCnt = 0;
+ set_timer = true;
+ }
+ }
+ }
+
+ if (set_timer) {
+ if (SOUNDING_STATE_NONE == info->sounding_info.state) {
+ info->sounding_info.state = SOUNDING_STATE_INIT;
+ _set_timer(&info->sounding_timer, 0);
+ }
+ }
+}
+
+#else /* !RTW_BEAMFORMING_VERSION_2 */
+
+#if (BEAMFORMING_SUPPORT == 0) /*for diver defined beamforming*/
+struct beamforming_entry *beamforming_get_entry_by_addr(struct mlme_priv *pmlmepriv, u8 *ra, u8 *idx)
+{
+ u8 i = 0;
+ struct beamforming_info *pBeamInfo = GET_BEAMFORM_INFO(pmlmepriv);
+
+ for (i = 0; i < BEAMFORMING_ENTRY_NUM; i++) {
+ if (pBeamInfo->beamforming_entry[i].bUsed &&
+ (!memcmp(ra, pBeamInfo->beamforming_entry[i].mac_addr, ETH_ALEN))) {
+ *idx = i;
+ return &(pBeamInfo->beamforming_entry[i]);
+ }
+ }
+
+ return NULL;
+}
+
+BEAMFORMING_CAP beamforming_get_entry_beam_cap_by_mac_id(void * pmlmepriv , u8 mac_id)
+{
+ u8 i = 0;
+ struct beamforming_info *pBeamInfo = GET_BEAMFORM_INFO((struct mlme_priv *)pmlmepriv);
+ BEAMFORMING_CAP BeamformEntryCap = BEAMFORMING_CAP_NONE;
+
+ for (i = 0; i < BEAMFORMING_ENTRY_NUM; i++) {
+ if (pBeamInfo->beamforming_entry[i].bUsed &&
+ (mac_id == pBeamInfo->beamforming_entry[i].mac_id)) {
+ BeamformEntryCap = pBeamInfo->beamforming_entry[i].beamforming_entry_cap;
+ i = BEAMFORMING_ENTRY_NUM;
+ }
+ }
+
+ return BeamformEntryCap;
+}
+
+struct beamforming_entry *beamforming_get_free_entry(struct mlme_priv *pmlmepriv, u8 *idx)
+{
+ u8 i = 0;
+ struct beamforming_info *pBeamInfo = GET_BEAMFORM_INFO(pmlmepriv);
+
+ for (i = 0; i < BEAMFORMING_ENTRY_NUM; i++) {
+ if (pBeamInfo->beamforming_entry[i].bUsed == false) {
+ *idx = i;
+ return &(pBeamInfo->beamforming_entry[i]);
+ }
+ }
+ return NULL;
+}
+
+
+struct beamforming_entry *beamforming_add_entry(PADAPTER adapter, u8 *ra, u16 aid,
+ u16 mac_id, CHANNEL_WIDTH bw, BEAMFORMING_CAP beamfrom_cap, u8 *idx)
+{
+ struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
+ struct beamforming_entry *pEntry = beamforming_get_free_entry(pmlmepriv, idx);
+
+ if (pEntry != NULL) {
+ pEntry->bUsed = true;
+ pEntry->aid = aid;
+ pEntry->mac_id = mac_id;
+ pEntry->sound_bw = bw;
+ if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
+ u16 BSSID = ((*(adapter_mac_addr(adapter) + 5) & 0xf0) >> 4) ^
+ (*(adapter_mac_addr(adapter) + 5) & 0xf); /* BSSID[44:47] xor BSSID[40:43] */
+ pEntry->p_aid = (aid + BSSID * 32) & 0x1ff; /* (dec(A) + dec(B)*32) mod 512 */
+ pEntry->g_id = 63;
+ } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) || check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
+ pEntry->p_aid = 0;
+ pEntry->g_id = 63;
+ } else {
+ pEntry->p_aid = ra[5]; /* BSSID[39:47] */
+ pEntry->p_aid = (pEntry->p_aid << 1) | (ra[4] >> 7);
+ pEntry->g_id = 0;
+ }
+ memcpy(pEntry->mac_addr, ra, ETH_ALEN);
+ pEntry->bSound = false;
+
+ /* 3 TODO SW/FW sound period */
+ pEntry->sound_period = 200;
+ pEntry->beamforming_entry_cap = beamfrom_cap;
+ pEntry->beamforming_entry_state = BEAMFORMING_ENTRY_STATE_UNINITIALIZE;
+
+
+ pEntry->PreLogSeq = 0; /*Modified by Jeffery @2015-04-13*/
+ pEntry->LogSeq = 0; /*Modified by Jeffery @2014-10-29*/
+ pEntry->LogRetryCnt = 0; /*Modified by Jeffery @2014-10-29*/
+ pEntry->LogSuccess = 0; /*LogSuccess is NOT needed to be accumulated, so LogSuccessCnt->LogSuccess, 2015-04-13, Jeffery*/
+ pEntry->ClockResetTimes = 0; /*Modified by Jeffery @2015-04-13*/
+ pEntry->LogStatusFailCnt = 0;
+
+ return pEntry;
+ } else
+ return NULL;
+}
+
+bool beamforming_remove_entry(struct mlme_priv *pmlmepriv, u8 *ra, u8 *idx)
+{
+ struct beamforming_entry *pEntry = beamforming_get_entry_by_addr(pmlmepriv, ra, idx);
+
+ if (pEntry != NULL) {
+ pEntry->bUsed = false;
+ pEntry->beamforming_entry_cap = BEAMFORMING_CAP_NONE;
+ pEntry->beamforming_entry_state = BEAMFORMING_ENTRY_STATE_UNINITIALIZE;
+ return true;
+ } else
+ return false;
+}
+
+/* Used for BeamformingStart_V1 */
+void beamforming_dym_ndpa_rate(PADAPTER adapter)
+{
+ u16 NDPARate = MGN_6M;
+ PHAL_DATA_TYPE pHalData = GET_HAL_DATA(adapter);
+
+ if (pHalData->min_undecorated_pwdb_for_dm > 30) /* link RSSI > 30% */
+ NDPARate = MGN_24M;
+ else
+ NDPARate = MGN_6M;
+
+ /* BW = CHANNEL_WIDTH_20; */
+ NDPARate = NDPARate << 8;
+ rtw_hal_set_hwreg(adapter, HW_VAR_SOUNDING_RATE, (u8 *)&NDPARate);
+}
+
+void beamforming_dym_period(PADAPTER Adapter)
+{
+ u8 Idx;
+ bool bChangePeriod = false;
+ u16 SoundPeriod_SW, SoundPeriod_FW;
+ PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
+ struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(Adapter);
+ struct beamforming_entry *pBeamformEntry;
+ struct beamforming_info *pBeamInfo = GET_BEAMFORM_INFO((&Adapter->mlmepriv));
+ struct sounding_info *pSoundInfo = &(pBeamInfo->sounding_info);
+
+ /* 3 TODO per-client throughput caculation. */
+
+ if (pdvobjpriv->traffic_stat.cur_tx_tp + pdvobjpriv->traffic_stat.cur_rx_tp > 2) {
+ SoundPeriod_SW = 32 * 20;
+ SoundPeriod_FW = 2;
+ } else {
+ SoundPeriod_SW = 32 * 2000;
+ SoundPeriod_FW = 200;
+ }
+
+ for (Idx = 0; Idx < BEAMFORMING_ENTRY_NUM; Idx++) {
+ pBeamformEntry = pBeamInfo->beamforming_entry + Idx;
+ if (pBeamformEntry->bDefaultCSI) {
+ SoundPeriod_SW = 32 * 2000;
+ SoundPeriod_FW = 200;
+ }
+
+ if (pBeamformEntry->beamforming_entry_cap & (BEAMFORMER_CAP_HT_EXPLICIT | BEAMFORMER_CAP_VHT_SU)) {
+ if (pSoundInfo->sound_mode == SOUNDING_FW_VHT_TIMER || pSoundInfo->sound_mode == SOUNDING_FW_HT_TIMER) {
+ if (pBeamformEntry->sound_period != SoundPeriod_FW) {
+ pBeamformEntry->sound_period = SoundPeriod_FW;
+ bChangePeriod = true; /* Only FW sounding need to send H2C packet to change sound period. */
+ }
+ } else if (pBeamformEntry->sound_period != SoundPeriod_SW)
+ pBeamformEntry->sound_period = SoundPeriod_SW;
+ }
+ }
+
+ if (bChangePeriod)
+ rtw_hal_set_hwreg(Adapter, HW_VAR_SOUNDING_FW_NDPA, (u8 *)&Idx);
+}
+
+bool issue_ht_sw_ndpa_packet(PADAPTER Adapter, u8 *ra, CHANNEL_WIDTH bw, u8 qidx)
+{
+ struct xmit_frame *pmgntframe;
+ struct pkt_attrib *pattrib;
+ struct rtw_ieee80211_hdr *pwlanhdr;
+ struct xmit_priv *pxmitpriv = &(Adapter->xmitpriv);
+ struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ u8 ActionHdr[4] = {ACT_CAT_VENDOR, 0x00, 0xe0, 0x4c};
+ u8 *pframe;
+ u16 *fctrl;
+ u16 duration = 0;
+ u8 aSifsTime = 0;
+ u8 NDPTxRate = 0;
+
+ RTW_INFO("%s: issue_ht_sw_ndpa_packet!\n", __func__);
+
+ NDPTxRate = MGN_MCS8;
+ RTW_INFO("%s: NDPTxRate =%d\n", __func__, NDPTxRate);
+ pmgntframe = alloc_mgtxmitframe(pxmitpriv);
+
+ if (pmgntframe == NULL)
+ return false;
+
+ /*update attribute*/
+ pattrib = &pmgntframe->attrib;
+ update_mgntframe_attrib(Adapter, pattrib);
+ pattrib->qsel = QSLT_MGNT;
+ pattrib->rate = NDPTxRate;
+ pattrib->bwmode = bw;
+ pattrib->order = 1;
+ pattrib->subtype = WIFI_ACTION_NOACK;
+
+ memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
+
+ pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
+
+ pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
+
+ fctrl = &pwlanhdr->frame_ctl;
+ *(fctrl) = 0;
+
+ set_order_bit(pframe);
+ set_frame_sub_type(pframe, WIFI_ACTION_NOACK);
+
+ memcpy(pwlanhdr->addr1, ra, ETH_ALEN);
+ memcpy(pwlanhdr->addr2, adapter_mac_addr(Adapter), ETH_ALEN);
+ memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
+
+ if (pmlmeext->cur_wireless_mode == WIRELESS_11B)
+ aSifsTime = 10;
+ else
+ aSifsTime = 16;
+
+ duration = 2 * aSifsTime + 40;
+
+ if (bw == CHANNEL_WIDTH_40)
+ duration += 87;
+ else
+ duration += 180;
+
+ set_duration(pframe, duration);
+
+ /*HT control field*/
+ SET_HT_CTRL_CSI_STEERING(pframe + 24, 3);
+ SET_HT_CTRL_NDP_ANNOUNCEMENT(pframe + 24, 1);
+
+ memcpy(pframe + 28, ActionHdr, 4);
+
+ pattrib->pktlen = 32;
+
+ pattrib->last_txcmdsz = pattrib->pktlen;
+
+ dump_mgntframe(Adapter, pmgntframe);
+
+ return true;
+
+
+}
+bool issue_ht_ndpa_packet(PADAPTER Adapter, u8 *ra, CHANNEL_WIDTH bw, u8 qidx)
+{
+ struct xmit_frame *pmgntframe;
+ struct pkt_attrib *pattrib;
+ struct rtw_ieee80211_hdr *pwlanhdr;
+ struct xmit_priv *pxmitpriv = &(Adapter->xmitpriv);
+ struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ u8 ActionHdr[4] = {ACT_CAT_VENDOR, 0x00, 0xe0, 0x4c};
+ u8 *pframe;
+ u16 *fctrl;
+ u16 duration = 0;
+ u8 aSifsTime = 0;
+
+ pmgntframe = alloc_mgtxmitframe(pxmitpriv);
+
+ if (pmgntframe == NULL)
+ return false;
+
+ /*update attribute*/
+ pattrib = &pmgntframe->attrib;
+ update_mgntframe_attrib(Adapter, pattrib);
+
+ if (qidx == BCN_QUEUE_INX)
+ pattrib->qsel = QSLT_BEACON;
+ pattrib->rate = MGN_MCS8;
+ pattrib->bwmode = bw;
+ pattrib->order = 1;
+ pattrib->subtype = WIFI_ACTION_NOACK;
+
+ memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
+
+ pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
+
+ pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
+
+ fctrl = &pwlanhdr->frame_ctl;
+ *(fctrl) = 0;
+
+ set_order_bit(pframe);
+ set_frame_sub_type(pframe, WIFI_ACTION_NOACK);
+
+ memcpy(pwlanhdr->addr1, ra, ETH_ALEN);
+ memcpy(pwlanhdr->addr2, adapter_mac_addr(Adapter), ETH_ALEN);
+ memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
+
+ if (pmlmeext->cur_wireless_mode == WIRELESS_11B)
+ aSifsTime = 10;
+ else
+ aSifsTime = 16;
+
+ duration = 2 * aSifsTime + 40;
+
+ if (bw == CHANNEL_WIDTH_40)
+ duration += 87;
+ else
+ duration += 180;
+
+ set_duration(pframe, duration);
+
+ /* HT control field */
+ SET_HT_CTRL_CSI_STEERING(pframe + 24, 3);
+ SET_HT_CTRL_NDP_ANNOUNCEMENT(pframe + 24, 1);
+
+ memcpy(pframe + 28, ActionHdr, 4);
+
+ pattrib->pktlen = 32;
+
+ pattrib->last_txcmdsz = pattrib->pktlen;
+
+ dump_mgntframe(Adapter, pmgntframe);
+
+ return true;
+}
+
+bool beamforming_send_ht_ndpa_packet(PADAPTER Adapter, u8 *ra, CHANNEL_WIDTH bw, u8 qidx)
+{
+ return issue_ht_ndpa_packet(Adapter, ra, bw, qidx);
+}
+bool issue_vht_sw_ndpa_packet(PADAPTER Adapter, u8 *ra, u16 aid, CHANNEL_WIDTH bw, u8 qidx)
+{
+ struct xmit_frame *pmgntframe;
+ struct pkt_attrib *pattrib;
+ struct rtw_ieee80211_hdr *pwlanhdr;
+ struct xmit_priv *pxmitpriv = &(Adapter->xmitpriv);
+ struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
+ struct beamforming_info *pBeamInfo = GET_BEAMFORM_INFO(pmlmepriv);
+ struct rtw_ndpa_sta_info sta_info;
+ u8 NDPTxRate = 0;
+
+ u8 *pframe;
+ u16 *fctrl;
+ u16 duration = 0;
+ u8 sequence = 0, aSifsTime = 0;
+
+ RTW_INFO("%s: issue_vht_sw_ndpa_packet!\n", __func__);
+
+
+ NDPTxRate = MGN_VHT2SS_MCS0;
+ RTW_INFO("%s: NDPTxRate =%d\n", __func__, NDPTxRate);
+ pmgntframe = alloc_mgtxmitframe(pxmitpriv);
+
+ if (pmgntframe == NULL) {
+ RTW_INFO("%s, alloc mgnt frame fail\n", __func__);
+ return false;
+ }
+
+ /*update attribute*/
+ pattrib = &pmgntframe->attrib;
+ update_mgntframe_attrib(Adapter, pattrib);
+ pattrib->qsel = QSLT_MGNT;
+ pattrib->rate = NDPTxRate;
+ pattrib->bwmode = bw;
+ pattrib->subtype = WIFI_NDPA;
+
+ memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
+
+ pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
+
+ pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
+
+ fctrl = &pwlanhdr->frame_ctl;
+ *(fctrl) = 0;
+
+ set_frame_sub_type(pframe, WIFI_NDPA);
+
+ memcpy(pwlanhdr->addr1, ra, ETH_ALEN);
+ memcpy(pwlanhdr->addr2, adapter_mac_addr(Adapter), ETH_ALEN);
+
+ if (is_supported_5g(pmlmeext->cur_wireless_mode) || is_supported_ht(pmlmeext->cur_wireless_mode))
+ aSifsTime = 16;
+ else
+ aSifsTime = 10;
+
+ duration = 2 * aSifsTime + 44;
+
+ if (bw == CHANNEL_WIDTH_80)
+ duration += 40;
+ else if (bw == CHANNEL_WIDTH_40)
+ duration += 87;
+ else
+ duration += 180;
+
+ set_duration(pframe, duration);
+
+ sequence = pBeamInfo->sounding_sequence << 2;
+ if (pBeamInfo->sounding_sequence >= 0x3f)
+ pBeamInfo->sounding_sequence = 0;
+ else
+ pBeamInfo->sounding_sequence++;
+
+ memcpy(pframe + 16, &sequence, 1);
+ if (((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE))
+ aid = 0;
+
+ sta_info.aid = aid;
+ sta_info.feedback_type = 0;
+ sta_info.nc_index = 0;
+
+ memcpy(pframe + 17, (u8 *)&sta_info, 2);
+
+ pattrib->pktlen = 19;
+
+ pattrib->last_txcmdsz = pattrib->pktlen;
+
+ dump_mgntframe(Adapter, pmgntframe);
+
+
+ return true;
+
+}
+bool issue_vht_ndpa_packet(PADAPTER Adapter, u8 *ra, u16 aid, CHANNEL_WIDTH bw, u8 qidx)
+{
+ struct xmit_frame *pmgntframe;
+ struct pkt_attrib *pattrib;
+ struct rtw_ieee80211_hdr *pwlanhdr;
+ struct xmit_priv *pxmitpriv = &(Adapter->xmitpriv);
+ struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
+ struct beamforming_info *pBeamInfo = GET_BEAMFORM_INFO(pmlmepriv);
+ struct rtw_ndpa_sta_info sta_info;
+ u8 *pframe;
+ u16 *fctrl;
+ u16 duration = 0;
+ u8 sequence = 0, aSifsTime = 0;
+
+ pmgntframe = alloc_mgtxmitframe(pxmitpriv);
+ if (pmgntframe == NULL)
+ return false;
+
+ /*update attribute*/
+ pattrib = &pmgntframe->attrib;
+ update_mgntframe_attrib(Adapter, pattrib);
+
+ if (qidx == BCN_QUEUE_INX)
+ pattrib->qsel = QSLT_BEACON;
+ pattrib->rate = MGN_VHT2SS_MCS0;
+ pattrib->bwmode = bw;
+ pattrib->subtype = WIFI_NDPA;
+
+ memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
+
+ pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
+
+ pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
+
+ fctrl = &pwlanhdr->frame_ctl;
+ *(fctrl) = 0;
+
+ set_frame_sub_type(pframe, WIFI_NDPA);
+
+ memcpy(pwlanhdr->addr1, ra, ETH_ALEN);
+ memcpy(pwlanhdr->addr2, adapter_mac_addr(Adapter), ETH_ALEN);
+
+ if (is_supported_5g(pmlmeext->cur_wireless_mode) || is_supported_ht(pmlmeext->cur_wireless_mode))
+ aSifsTime = 16;
+ else
+ aSifsTime = 10;
+
+ duration = 2 * aSifsTime + 44;
+
+ if (bw == CHANNEL_WIDTH_80)
+ duration += 40;
+ else if (bw == CHANNEL_WIDTH_40)
+ duration += 87;
+ else
+ duration += 180;
+
+ set_duration(pframe, duration);
+
+ sequence = pBeamInfo->sounding_sequence << 2;
+ if (pBeamInfo->sounding_sequence >= 0x3f)
+ pBeamInfo->sounding_sequence = 0;
+ else
+ pBeamInfo->sounding_sequence++;
+
+ memcpy(pframe + 16, &sequence, 1);
+
+ if (((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE))
+ aid = 0;
+
+ sta_info.aid = aid;
+ sta_info.feedback_type = 0;
+ sta_info.nc_index = 0;
+
+ memcpy(pframe + 17, (u8 *)&sta_info, 2);
+
+ pattrib->pktlen = 19;
+
+ pattrib->last_txcmdsz = pattrib->pktlen;
+
+ dump_mgntframe(Adapter, pmgntframe);
+
+ return true;
+}
+
+bool beamforming_send_vht_ndpa_packet(PADAPTER Adapter, u8 *ra, u16 aid, CHANNEL_WIDTH bw, u8 qidx)
+{
+ return issue_vht_ndpa_packet(Adapter, ra, aid, bw, qidx);
+}
+
+bool beamfomring_bSounding(struct beamforming_info *pBeamInfo)
+{
+ bool bSounding = false;
+
+ if ((beamforming_get_beamform_cap(pBeamInfo) & BEAMFORMER_CAP) == 0)
+ bSounding = false;
+ else
+ bSounding = true;
+
+ return bSounding;
+}
+
+u8 beamforming_sounding_idx(struct beamforming_info *pBeamInfo)
+{
+ u8 idx = 0;
+ u8 i;
+
+ for (i = 0; i < BEAMFORMING_ENTRY_NUM; i++) {
+ if (pBeamInfo->beamforming_entry[i].bUsed &&
+ (false == pBeamInfo->beamforming_entry[i].bSound)) {
+ idx = i;
+ break;
+ }
+ }
+
+ return idx;
+}
+
+SOUNDING_MODE beamforming_sounding_mode(struct beamforming_info *pBeamInfo, u8 idx)
+{
+ struct beamforming_entry BeamEntry = pBeamInfo->beamforming_entry[idx];
+ SOUNDING_MODE mode;
+
+ if (BeamEntry.beamforming_entry_cap & BEAMFORMER_CAP_VHT_SU)
+ mode = SOUNDING_FW_VHT_TIMER;
+ else if (BeamEntry.beamforming_entry_cap & BEAMFORMER_CAP_HT_EXPLICIT)
+ mode = SOUNDING_FW_HT_TIMER;
+ else
+ mode = SOUNDING_STOP_All_TIMER;
+
+ return mode;
+}
+
+u16 beamforming_sounding_time(struct beamforming_info *pBeamInfo, SOUNDING_MODE mode, u8 idx)
+{
+ u16 sounding_time = 0xffff;
+ struct beamforming_entry BeamEntry = pBeamInfo->beamforming_entry[idx];
+
+ sounding_time = BeamEntry.sound_period;
+
+ return sounding_time;
+}
+
+CHANNEL_WIDTH beamforming_sounding_bw(struct beamforming_info *pBeamInfo, SOUNDING_MODE mode, u8 idx)
+{
+ CHANNEL_WIDTH sounding_bw = CHANNEL_WIDTH_20;
+ struct beamforming_entry BeamEntry = pBeamInfo->beamforming_entry[idx];
+
+ sounding_bw = BeamEntry.sound_bw;
+
+ return sounding_bw;
+}
+
+bool beamforming_select_beam_entry(struct beamforming_info *pBeamInfo)
+{
+ struct sounding_info *pSoundInfo = &(pBeamInfo->sounding_info);
+
+ pSoundInfo->sound_idx = beamforming_sounding_idx(pBeamInfo);
+
+ if (pSoundInfo->sound_idx < BEAMFORMING_ENTRY_NUM)
+ pSoundInfo->sound_mode = beamforming_sounding_mode(pBeamInfo, pSoundInfo->sound_idx);
+ else
+ pSoundInfo->sound_mode = SOUNDING_STOP_All_TIMER;
+
+ if (SOUNDING_STOP_All_TIMER == pSoundInfo->sound_mode)
+ return false;
+ else {
+ pSoundInfo->sound_bw = beamforming_sounding_bw(pBeamInfo, pSoundInfo->sound_mode, pSoundInfo->sound_idx);
+ pSoundInfo->sound_period = beamforming_sounding_time(pBeamInfo, pSoundInfo->sound_mode, pSoundInfo->sound_idx);
+ return true;
+ }
+}
+
+bool beamforming_start_fw(PADAPTER adapter, u8 idx)
+{
+ u8 *RA = NULL;
+ struct beamforming_entry *pEntry;
+ bool ret = true;
+ struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
+ struct beamforming_info *pBeamInfo = GET_BEAMFORM_INFO(pmlmepriv);
+
+ pEntry = &(pBeamInfo->beamforming_entry[idx]);
+ if (pEntry->bUsed == false) {
+ RTW_INFO("Skip Beamforming, no entry for Idx =%d\n", idx);
+ return false;
+ }
+
+ pEntry->beamforming_entry_state = BEAMFORMING_ENTRY_STATE_PROGRESSING;
+ pEntry->bSound = true;
+ rtw_hal_set_hwreg(adapter, HW_VAR_SOUNDING_FW_NDPA, (u8 *)&idx);
+
+ return true;
+}
+
+void beamforming_end_fw(PADAPTER adapter)
+{
+ u8 idx = 0;
+
+ rtw_hal_set_hwreg(adapter, HW_VAR_SOUNDING_FW_NDPA, (u8 *)&idx);
+
+ RTW_INFO("%s\n", __func__);
+}
+
+bool beamforming_start_period(PADAPTER adapter)
+{
+ bool ret = true;
+ struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
+ struct beamforming_info *pBeamInfo = GET_BEAMFORM_INFO(pmlmepriv);
+ struct sounding_info *pSoundInfo = &(pBeamInfo->sounding_info);
+
+ beamforming_dym_ndpa_rate(adapter);
+
+ beamforming_select_beam_entry(pBeamInfo);
+
+ if (pSoundInfo->sound_mode == SOUNDING_FW_VHT_TIMER || pSoundInfo->sound_mode == SOUNDING_FW_HT_TIMER)
+ ret = beamforming_start_fw(adapter, pSoundInfo->sound_idx);
+ else
+ ret = false;
+
+ RTW_INFO("%s Idx %d Mode %d BW %d Period %d\n", __func__,
+ pSoundInfo->sound_idx, pSoundInfo->sound_mode, pSoundInfo->sound_bw, pSoundInfo->sound_period);
+
+ return ret;
+}
+
+void beamforming_end_period(PADAPTER adapter)
+{
+ u8 idx = 0;
+ struct beamforming_entry *pBeamformEntry;
+ struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
+ struct beamforming_info *pBeamInfo = GET_BEAMFORM_INFO(pmlmepriv);
+ struct sounding_info *pSoundInfo = &(pBeamInfo->sounding_info);
+
+
+ if (pSoundInfo->sound_mode == SOUNDING_FW_VHT_TIMER || pSoundInfo->sound_mode == SOUNDING_FW_HT_TIMER)
+ beamforming_end_fw(adapter);
+}
+
+void beamforming_notify(PADAPTER adapter)
+{
+ bool bSounding = false;
+ struct beamforming_info *pBeamInfo = GET_BEAMFORM_INFO(&(adapter->mlmepriv));
+
+ bSounding = beamfomring_bSounding(pBeamInfo);
+
+ if (pBeamInfo->beamforming_state == BEAMFORMING_STATE_IDLE) {
+ if (bSounding) {
+ if (beamforming_start_period(adapter) == true)
+ pBeamInfo->beamforming_state = BEAMFORMING_STATE_START;
+ }
+ } else if (pBeamInfo->beamforming_state == BEAMFORMING_STATE_START) {
+ if (bSounding) {
+ if (beamforming_start_period(adapter) == false)
+ pBeamInfo->beamforming_state = BEAMFORMING_STATE_END;
+ } else {
+ beamforming_end_period(adapter);
+ pBeamInfo->beamforming_state = BEAMFORMING_STATE_END;
+ }
+ } else if (pBeamInfo->beamforming_state == BEAMFORMING_STATE_END) {
+ if (bSounding) {
+ if (beamforming_start_period(adapter) == true)
+ pBeamInfo->beamforming_state = BEAMFORMING_STATE_START;
+ }
+ } else
+ RTW_INFO("%s BeamformState %d\n", __func__, pBeamInfo->beamforming_state);
+
+ RTW_INFO("%s BeamformState %d bSounding %d\n", __func__, pBeamInfo->beamforming_state, bSounding);
+}
+
+bool beamforming_init_entry(PADAPTER adapter, struct sta_info *psta, u8 *idx)
+{
+ struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
+ struct ht_priv *phtpriv = &(pmlmepriv->htpriv);
+ struct mlme_ext_priv *pmlmeext = &(adapter->mlmeextpriv);
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ struct beamforming_entry *pBeamformEntry = NULL;
+ u8 *ra;
+ u16 aid, mac_id;
+ u8 wireless_mode;
+ CHANNEL_WIDTH bw = CHANNEL_WIDTH_20;
+ BEAMFORMING_CAP beamform_cap = BEAMFORMING_CAP_NONE;
+
+ /* The current setting does not support Beaforming */
+ if (0 == phtpriv->beamform_cap) {
+ RTW_INFO("The configuration disabled Beamforming! Skip...\n");
+ return false;
+ }
+
+ aid = psta->aid;
+ ra = psta->hwaddr;
+ mac_id = psta->mac_id;
+ wireless_mode = psta->wireless_mode;
+ bw = psta->bw_mode;
+
+ if (is_supported_ht(wireless_mode) || is_supported_vht(wireless_mode)) {
+ /* 3 */ /* HT */
+ u8 cur_beamform;
+
+ cur_beamform = psta->htpriv.beamform_cap;
+
+ /* We are Beamformee because the STA is Beamformer */
+ if (TEST_FLAG(cur_beamform, BEAMFORMING_HT_BEAMFORMER_ENABLE))
+ beamform_cap = (BEAMFORMING_CAP)(beamform_cap | BEAMFORMEE_CAP_HT_EXPLICIT);
+
+ /* We are Beamformer because the STA is Beamformee */
+ if (TEST_FLAG(cur_beamform, BEAMFORMING_HT_BEAMFORMEE_ENABLE))
+ beamform_cap = (BEAMFORMING_CAP)(beamform_cap | BEAMFORMER_CAP_HT_EXPLICIT);
+
+ if (beamform_cap == BEAMFORMING_CAP_NONE)
+ return false;
+
+ RTW_INFO("Beamforming Config Capability = 0x%02X\n", beamform_cap);
+
+ pBeamformEntry = beamforming_get_entry_by_addr(pmlmepriv, ra, idx);
+ if (pBeamformEntry == NULL) {
+ pBeamformEntry = beamforming_add_entry(adapter, ra, aid, mac_id, bw, beamform_cap, idx);
+ if (pBeamformEntry == NULL)
+ return false;
+ else
+ pBeamformEntry->beamforming_entry_state = BEAMFORMING_ENTRY_STATE_INITIALIZEING;
+ } else {
+ /* Entry has been created. If entry is initialing or progressing then errors occur. */
+ if (pBeamformEntry->beamforming_entry_state != BEAMFORMING_ENTRY_STATE_INITIALIZED &&
+ pBeamformEntry->beamforming_entry_state != BEAMFORMING_ENTRY_STATE_PROGRESSED) {
+ RTW_INFO("Error State of Beamforming");
+ return false;
+ } else
+ pBeamformEntry->beamforming_entry_state = BEAMFORMING_ENTRY_STATE_INITIALIZEING;
+ }
+
+ pBeamformEntry->beamforming_entry_state = BEAMFORMING_ENTRY_STATE_INITIALIZED;
+ psta->txbf_paid = pBeamformEntry->p_aid;
+ psta->txbf_gid = pBeamformEntry->g_id;
+
+ RTW_INFO("%s Idx %d\n", __func__, *idx);
+ } else
+ return false;
+
+ return _SUCCESS;
+}
+
+void beamforming_deinit_entry(PADAPTER adapter, u8 *ra)
+{
+ u8 idx = 0;
+ struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
+
+ if (beamforming_remove_entry(pmlmepriv, ra, &idx) == true)
+ rtw_hal_set_hwreg(adapter, HW_VAR_SOUNDING_LEAVE, (u8 *)&idx);
+
+ RTW_INFO("%s Idx %d\n", __func__, idx);
+}
+
+void beamforming_reset(PADAPTER adapter)
+{
+ u8 idx = 0;
+ struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
+ struct beamforming_info *pBeamInfo = GET_BEAMFORM_INFO(pmlmepriv);
+
+ for (idx = 0; idx < BEAMFORMING_ENTRY_NUM; idx++) {
+ if (pBeamInfo->beamforming_entry[idx].bUsed == true) {
+ pBeamInfo->beamforming_entry[idx].bUsed = false;
+ pBeamInfo->beamforming_entry[idx].beamforming_entry_cap = BEAMFORMING_CAP_NONE;
+ pBeamInfo->beamforming_entry[idx].beamforming_entry_state = BEAMFORMING_ENTRY_STATE_UNINITIALIZE;
+ rtw_hal_set_hwreg(adapter, HW_VAR_SOUNDING_LEAVE, (u8 *)&idx);
+ }
+ }
+
+ RTW_INFO("%s\n", __func__);
+}
+
+void beamforming_sounding_fail(PADAPTER Adapter)
+{
+ struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
+ struct beamforming_info *pBeamInfo = GET_BEAMFORM_INFO(pmlmepriv);
+ struct beamforming_entry *pEntry = &(pBeamInfo->beamforming_entry[pBeamInfo->beamforming_cur_idx]);
+
+ pEntry->bSound = false;
+ rtw_hal_set_hwreg(Adapter, HW_VAR_SOUNDING_FW_NDPA, (u8 *)&pBeamInfo->beamforming_cur_idx);
+ beamforming_deinit_entry(Adapter, pEntry->mac_addr);
+}
+
+void beamforming_check_sounding_success(PADAPTER Adapter, bool status)
+{
+ struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
+ struct beamforming_info *pBeamInfo = GET_BEAMFORM_INFO(pmlmepriv);
+ struct beamforming_entry *pEntry = &(pBeamInfo->beamforming_entry[pBeamInfo->beamforming_cur_idx]);
+
+ if (status == 1)
+ pEntry->LogStatusFailCnt = 0;
+ else {
+ pEntry->LogStatusFailCnt++;
+ RTW_INFO("%s LogStatusFailCnt %d\n", __func__, pEntry->LogStatusFailCnt);
+ }
+ if (pEntry->LogStatusFailCnt > 20) {
+ RTW_INFO("%s LogStatusFailCnt > 20, Stop SOUNDING\n", __func__);
+ /* pEntry->bSound = false; */
+ /* rtw_hal_set_hwreg(Adapter, HW_VAR_SOUNDING_FW_NDPA, (u8 *)&pBeamInfo->beamforming_cur_idx); */
+ /* beamforming_deinit_entry(Adapter, pEntry->mac_addr); */
+ beamforming_wk_cmd(Adapter, BEAMFORMING_CTRL_SOUNDING_FAIL, NULL, 0, 1);
+ }
+}
+
+void beamforming_enter(PADAPTER adapter, void * psta)
+{
+ u8 idx = 0xff;
+
+ if (beamforming_init_entry(adapter, (struct sta_info *)psta, &idx))
+ rtw_hal_set_hwreg(adapter, HW_VAR_SOUNDING_ENTER, (u8 *)&idx);
+
+ /* RTW_INFO("%s Idx %d\n", __func__, idx); */
+}
+
+void beamforming_leave(PADAPTER adapter, u8 *ra)
+{
+ if (ra == NULL)
+ beamforming_reset(adapter);
+ else
+ beamforming_deinit_entry(adapter, ra);
+
+ beamforming_notify(adapter);
+}
+
+BEAMFORMING_CAP beamforming_get_beamform_cap(struct beamforming_info *pBeamInfo)
+{
+ u8 i;
+ bool bSelfBeamformer = false;
+ bool bSelfBeamformee = false;
+ struct beamforming_entry beamforming_entry;
+ BEAMFORMING_CAP beamform_cap = BEAMFORMING_CAP_NONE;
+
+ for (i = 0; i < BEAMFORMING_ENTRY_NUM; i++) {
+ beamforming_entry = pBeamInfo->beamforming_entry[i];
+
+ if (beamforming_entry.bUsed) {
+ if ((beamforming_entry.beamforming_entry_cap & BEAMFORMEE_CAP_VHT_SU) ||
+ (beamforming_entry.beamforming_entry_cap & BEAMFORMEE_CAP_HT_EXPLICIT))
+ bSelfBeamformee = true;
+ if ((beamforming_entry.beamforming_entry_cap & BEAMFORMER_CAP_VHT_SU) ||
+ (beamforming_entry.beamforming_entry_cap & BEAMFORMER_CAP_HT_EXPLICIT))
+ bSelfBeamformer = true;
+ }
+
+ if (bSelfBeamformer && bSelfBeamformee)
+ i = BEAMFORMING_ENTRY_NUM;
+ }
+
+ if (bSelfBeamformer)
+ beamform_cap |= BEAMFORMER_CAP;
+ if (bSelfBeamformee)
+ beamform_cap |= BEAMFORMEE_CAP;
+
+ return beamform_cap;
+}
+
+void beamforming_watchdog(PADAPTER Adapter)
+{
+ struct beamforming_info *pBeamInfo = GET_BEAMFORM_INFO((&(Adapter->mlmepriv)));
+
+ if (pBeamInfo->beamforming_state != BEAMFORMING_STATE_START)
+ return;
+
+ beamforming_dym_period(Adapter);
+ beamforming_dym_ndpa_rate(Adapter);
+}
+#endif/* #if (BEAMFORMING_SUPPORT ==0) - for diver defined beamforming*/
+
+u32 rtw_beamforming_get_report_frame(PADAPTER Adapter, union recv_frame *precv_frame)
+{
+ u32 ret = _SUCCESS;
+#if (BEAMFORMING_SUPPORT == 1)
+ PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
+ struct PHY_DM_STRUCT *pDM_Odm = &(pHalData->odmpriv);
+
+ ret = beamforming_get_report_frame(pDM_Odm, precv_frame);
+
+#else /*(BEAMFORMING_SUPPORT == 0)- for drv beamfoming*/
+ struct beamforming_entry *pBeamformEntry = NULL;
+ struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
+ u8 *pframe = precv_frame->u.hdr.rx_data;
+ u32 frame_len = precv_frame->u.hdr.len;
+ u8 *ta;
+ u8 idx, offset;
+
+ /*RTW_INFO("rtw_beamforming_get_report_frame\n");*/
+
+ /*Memory comparison to see if CSI report is the same with previous one*/
+ ta = get_addr2_ptr(pframe);
+ pBeamformEntry = beamforming_get_entry_by_addr(pmlmepriv, ta, &idx);
+ if (pBeamformEntry->beamforming_entry_cap & BEAMFORMER_CAP_VHT_SU)
+ offset = 31; /*24+(1+1+3)+2 MAC header+(Category+ActionCode+MIMOControlField)+SNR(Nc=2)*/
+ else if (pBeamformEntry->beamforming_entry_cap & BEAMFORMER_CAP_HT_EXPLICIT)
+ offset = 34; /*24+(1+1+6)+2 MAC header+(Category+ActionCode+MIMOControlField)+SNR(Nc=2)*/
+ else
+ return ret;
+
+ /*RTW_INFO("%s MacId %d offset=%d\n", __func__, pBeamformEntry->mac_id, offset);*/
+
+ if (!memcmp(pBeamformEntry->PreCsiReport + offset, pframe + offset, frame_len - offset) == false)
+ pBeamformEntry->DefaultCsiCnt = 0;
+ else
+ pBeamformEntry->DefaultCsiCnt++;
+
+ memcpy(&pBeamformEntry->PreCsiReport, pframe, frame_len);
+
+ pBeamformEntry->bDefaultCSI = false;
+
+ if (pBeamformEntry->DefaultCsiCnt > 20)
+ pBeamformEntry->bDefaultCSI = true;
+ else
+ pBeamformEntry->bDefaultCSI = false;
+#endif
+ return ret;
+}
+
+void rtw_beamforming_get_ndpa_frame(PADAPTER Adapter, union recv_frame *precv_frame)
+{
+#if (BEAMFORMING_SUPPORT == 1)
+ PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
+ struct PHY_DM_STRUCT *pDM_Odm = &(pHalData->odmpriv);
+
+ beamforming_get_ndpa_frame(pDM_Odm, precv_frame);
+
+#else /*(BEAMFORMING_SUPPORT == 0)- for drv beamfoming*/
+ u8 *ta;
+ u8 idx, Sequence;
+ u8 *pframe = precv_frame->u.hdr.rx_data;
+ struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
+ struct beamforming_entry *pBeamformEntry = NULL;
+
+ /*RTW_INFO("rtw_beamforming_get_ndpa_frame\n");*/
+
+ if (IS_HARDWARE_TYPE_8812(Adapter) == false)
+ return;
+ else if (get_frame_sub_type(pframe) != WIFI_NDPA)
+ return;
+
+ ta = get_addr2_ptr(pframe);
+ /*Remove signaling TA. */
+ ta[0] = ta[0] & 0xFE;
+
+ pBeamformEntry = beamforming_get_entry_by_addr(pmlmepriv, ta, &idx);
+
+ if (pBeamformEntry == NULL)
+ return;
+ else if (!(pBeamformEntry->beamforming_entry_cap & BEAMFORMEE_CAP_VHT_SU))
+ return;
+ /*LogSuccess: As long as 8812A receive NDPA and feedback CSI succeed once, clock reset is NO LONGER needed !2015-04-10, Jeffery*/
+ /*ClockResetTimes: While BFer entry always doesn't receive our CSI, clock will reset again and again.So ClockResetTimes is limited to 5 times.2015-04-13, Jeffery*/
+ else if ((pBeamformEntry->LogSuccess == 1) || (pBeamformEntry->ClockResetTimes == 5)) {
+ RTW_INFO("[%s] LogSeq=%d, PreLogSeq=%d\n", __func__, pBeamformEntry->LogSeq, pBeamformEntry->PreLogSeq);
+ return;
+ }
+
+ Sequence = (pframe[16]) >> 2;
+ RTW_INFO("[%s] Start, Sequence=%d, LogSeq=%d, PreLogSeq=%d, LogRetryCnt=%d, ClockResetTimes=%d, LogSuccess=%d\n",
+ __func__, Sequence, pBeamformEntry->LogSeq, pBeamformEntry->PreLogSeq, pBeamformEntry->LogRetryCnt, pBeamformEntry->ClockResetTimes, pBeamformEntry->LogSuccess);
+
+ if ((pBeamformEntry->LogSeq != 0) && (pBeamformEntry->PreLogSeq != 0)) {
+ /*Success condition*/
+ if ((pBeamformEntry->LogSeq != Sequence) && (pBeamformEntry->PreLogSeq != pBeamformEntry->LogSeq)) {
+ /* break option for clcok reset, 2015-03-30, Jeffery */
+ pBeamformEntry->LogRetryCnt = 0;
+ /*As long as 8812A receive NDPA and feedback CSI succeed once, clock reset is no longer needed.*/
+ /*That is, LogSuccess is NOT needed to be reset to zero, 2015-04-13, Jeffery*/
+ pBeamformEntry->LogSuccess = 1;
+
+ } else {/*Fail condition*/
+
+ if (pBeamformEntry->LogRetryCnt == 5) {
+ pBeamformEntry->ClockResetTimes++;
+ pBeamformEntry->LogRetryCnt = 0;
+
+ RTW_INFO("[%s] Clock Reset!!! ClockResetTimes=%d\n", __func__, pBeamformEntry->ClockResetTimes);
+ beamforming_wk_cmd(Adapter, BEAMFORMING_CTRL_SOUNDING_CLK, NULL, 0, 1);
+
+ } else
+ pBeamformEntry->LogRetryCnt++;
+ }
+ }
+
+ /*Update LogSeq & PreLogSeq*/
+ pBeamformEntry->PreLogSeq = pBeamformEntry->LogSeq;
+ pBeamformEntry->LogSeq = Sequence;
+
+#endif
+
+}
+
+
+
+
+void beamforming_wk_hdl(_adapter *padapter, u8 type, u8 *pbuf)
+{
+ PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
+ struct PHY_DM_STRUCT *pDM_Odm = &(pHalData->odmpriv);
+
+#if (BEAMFORMING_SUPPORT == 1) /*(BEAMFORMING_SUPPORT == 1)- for PHYDM beamfoming*/
+ switch (type) {
+ case BEAMFORMING_CTRL_ENTER: {
+ struct sta_info *psta = (void *)pbuf;
+ u16 staIdx = psta->mac_id;
+
+ beamforming_enter(pDM_Odm, staIdx);
+ break;
+ }
+ case BEAMFORMING_CTRL_LEAVE:
+ beamforming_leave(pDM_Odm, pbuf);
+ break;
+ default:
+ break;
+
+ }
+#else /*(BEAMFORMING_SUPPORT == 0)- for drv beamfoming*/
+ switch (type) {
+ case BEAMFORMING_CTRL_ENTER:
+ beamforming_enter(padapter, (void *)pbuf);
+ break;
+
+ case BEAMFORMING_CTRL_LEAVE:
+ beamforming_leave(padapter, pbuf);
+ break;
+
+ case BEAMFORMING_CTRL_SOUNDING_FAIL:
+ beamforming_sounding_fail(padapter);
+ break;
+
+ case BEAMFORMING_CTRL_SOUNDING_CLK:
+ rtw_hal_set_hwreg(padapter, HW_VAR_SOUNDING_CLK, NULL);
+ break;
+
+ default:
+ break;
+ }
+#endif
+}
+
+u8 beamforming_wk_cmd(_adapter *padapter, s32 type, u8 *pbuf, s32 size, u8 enqueue)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+
+ if (enqueue) {
+ u8 *wk_buf;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (ph2c == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (pdrvextra_cmd_parm == NULL) {
+ rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ if (pbuf != NULL) {
+ wk_buf = rtw_zmalloc(size);
+ if (wk_buf == NULL) {
+ rtw_mfree((u8 *)ph2c, sizeof(struct cmd_obj));
+ rtw_mfree((u8 *)pdrvextra_cmd_parm, sizeof(struct drvextra_cmd_parm));
+ res = _FAIL;
+ goto exit;
+ }
+
+ memcpy(wk_buf, pbuf, size);
+ } else {
+ wk_buf = NULL;
+ size = 0;
+ }
+
+ pdrvextra_cmd_parm->ec_id = BEAMFORMING_WK_CID;
+ pdrvextra_cmd_parm->type = type;
+ pdrvextra_cmd_parm->size = size;
+ pdrvextra_cmd_parm->pbuf = wk_buf;
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+ } else
+ beamforming_wk_hdl(padapter, type, pbuf);
+
+exit:
+
+
+ return res;
+}
+
+void update_attrib_txbf_info(_adapter *padapter, struct pkt_attrib *pattrib, struct sta_info *psta)
+{
+ if (psta) {
+ pattrib->txbf_g_id = psta->txbf_gid;
+ pattrib->txbf_p_aid = psta->txbf_paid;
+ }
+}
+#endif /* !RTW_BEAMFORMING_VERSION_2 */
+
+#endif /* CONFIG_BEAMFORMING */
diff --git a/drivers/staging/rtl8188eu/core/rtw_br_ext.c b/drivers/staging/rtl8188eu/core/rtw_br_ext.c
new file mode 100644
index 000000000000..9cd8d3ba37f2
--- /dev/null
+++ b/drivers/staging/rtl8188eu/core/rtw_br_ext.c
@@ -0,0 +1,1529 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved. */
+
+#define _RTW_BR_EXT_C_
+
+#ifdef __KERNEL__
+ #include <linux/if_arp.h>
+ #include <net/ip.h>
+ #include <net/ipx.h>
+ #include <linux/atalk.h>
+ #include <linux/udp.h>
+ #include <linux/if_pppox.h>
+#endif
+
+#include <drv_types.h>
+#include <usb_osintf.h>
+
+#ifdef CL_IPV6_PASS
+ #ifdef __KERNEL__
+ #include <linux/ipv6.h>
+ #include <linux/icmpv6.h>
+ #include <net/ndisc.h>
+ #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24))
+ #include <net/ip6_checksum.h>
+ #else
+ #include <net/checksum.h>
+ #endif
+ #endif
+#endif
+
+#ifdef CONFIG_BR_EXT
+#include <hal_data.h>
+
+/* #define BR_EXT_DEBUG */
+
+#define NAT25_IPV4 01
+#define NAT25_IPV6 02
+#define NAT25_IPX 03
+#define NAT25_APPLE 04
+#define NAT25_PPPOE 05
+
+#define RTL_RELAY_TAG_LEN (ETH_ALEN)
+#define TAG_HDR_LEN 4
+
+#define MAGIC_CODE 0x8186
+#define MAGIC_CODE_LEN 2
+#define WAIT_TIME_PPPOE 5 /* waiting time for pppoe server in sec */
+
+/*-----------------------------------------------------------------
+ How database records network address:
+ 0 1 2 3 4 5 6 7 8 9 10
+ |----|----|----|----|----|----|----|----|----|----|----|
+ IPv4 |type| | IP addr |
+ IPX |type| Net addr | Node addr |
+ IPX |type| Net addr |Sckt addr|
+ Apple |type| Network |node|
+ PPPoE |type| SID | AC MAC |
+-----------------------------------------------------------------*/
+
+
+/* Find a tag in pppoe frame and return the pointer */
+static __inline__ unsigned char *__nat25_find_pppoe_tag(struct pppoe_hdr *ph, unsigned short type)
+{
+ unsigned char *cur_ptr, *start_ptr;
+ unsigned short tagLen, tagType;
+
+ start_ptr = cur_ptr = (unsigned char *)ph->tag;
+ while ((cur_ptr - start_ptr) < ntohs(ph->length)) {
+ /* prevent un-alignment access */
+ tagType = (unsigned short)((cur_ptr[0] << 8) + cur_ptr[1]);
+ tagLen = (unsigned short)((cur_ptr[2] << 8) + cur_ptr[3]);
+ if (tagType == type)
+ return cur_ptr;
+ cur_ptr = cur_ptr + TAG_HDR_LEN + tagLen;
+ }
+ return NULL;
+}
+
+static __inline__ int __nat25_add_pppoe_tag(struct sk_buff *skb, struct pppoe_tag *tag)
+{
+ struct pppoe_hdr *ph = (struct pppoe_hdr *)(skb->data + ETH_HLEN);
+ int data_len;
+
+ data_len = be16_to_cpu(tag->tag_len) + TAG_HDR_LEN;
+ if (skb_tailroom(skb) < data_len) {
+ _DEBUG_ERR("skb_tailroom() failed in add SID tag!\n");
+ return -1;
+ }
+
+ skb_put(skb, data_len);
+ /* have a room for new tag */
+ memmove(((unsigned char *)ph->tag + data_len), (unsigned char *)ph->tag, ntohs(ph->length));
+ ph->length = htons(ntohs(ph->length) + data_len);
+ memcpy((unsigned char *)ph->tag, tag, data_len);
+ return data_len;
+}
+
+static int skb_pull_and_merge(struct sk_buff *skb, unsigned char *src, int len)
+{
+ int tail_len;
+ unsigned long end, tail;
+
+ if ((src + len) > skb_tail_pointer(skb) || skb->len < len)
+ return -1;
+
+ tail = (unsigned long)skb_tail_pointer(skb);
+ end = (unsigned long)src + len;
+ if (tail < end)
+ return -1;
+
+ tail_len = (int)(tail - end);
+ if (tail_len > 0)
+ memmove(src, src + len, tail_len);
+
+ skb_trim(skb, skb->len - len);
+ return 0;
+}
+
+static __inline__ unsigned long __nat25_timeout(_adapter *priv)
+{
+ unsigned long timeout;
+
+ timeout = jiffies - NAT25_AGEING_TIME * HZ;
+
+ return timeout;
+}
+
+
+static __inline__ int __nat25_has_expired(_adapter *priv,
+ struct nat25_network_db_entry *fdb)
+{
+ if (time_before_eq(fdb->ageing_timer, __nat25_timeout(priv)))
+ return 1;
+
+ return 0;
+}
+
+
+static __inline__ void __nat25_generate_ipv4_network_addr(unsigned char *networkAddr,
+ u32 *ipAddr)
+{
+ memset(networkAddr, 0, MAX_NETWORK_ADDR_LEN);
+
+ networkAddr[0] = NAT25_IPV4;
+ memcpy(networkAddr + 7, (unsigned char *)ipAddr, 4);
+}
+
+
+static __inline__ void __nat25_generate_ipx_network_addr_with_node(unsigned char *networkAddr,
+ __be32 *ipxNetAddr, unsigned char *ipxNodeAddr)
+{
+ memset(networkAddr, 0, MAX_NETWORK_ADDR_LEN);
+
+ networkAddr[0] = NAT25_IPX;
+ memcpy(networkAddr + 1, (unsigned char *)ipxNetAddr, 4);
+ memcpy(networkAddr + 5, ipxNodeAddr, 6);
+}
+
+
+static __inline__ void __nat25_generate_ipx_network_addr_with_socket(unsigned char *networkAddr,
+ __be32 *ipxNetAddr, __be16 *ipxSocketAddr)
+{
+ memset(networkAddr, 0, MAX_NETWORK_ADDR_LEN);
+
+ networkAddr[0] = NAT25_IPX;
+ memcpy(networkAddr + 1, (unsigned char *)ipxNetAddr, 4);
+ memcpy(networkAddr + 5, (unsigned char *)ipxSocketAddr, 2);
+}
+
+
+static __inline__ void __nat25_generate_apple_network_addr(unsigned char *networkAddr,
+ __be16 *network, unsigned char *node)
+{
+ memset(networkAddr, 0, MAX_NETWORK_ADDR_LEN);
+
+ networkAddr[0] = NAT25_APPLE;
+ memcpy(networkAddr + 1, (unsigned char *)network, 2);
+ networkAddr[3] = *node;
+}
+
+
+static __inline__ void __nat25_generate_pppoe_network_addr(unsigned char *networkAddr,
+ unsigned char *ac_mac, __be16 *sid)
+{
+ memset(networkAddr, 0, MAX_NETWORK_ADDR_LEN);
+
+ networkAddr[0] = NAT25_PPPOE;
+ memcpy(networkAddr + 1, (unsigned char *)sid, 2);
+ memcpy(networkAddr + 3, (unsigned char *)ac_mac, 6);
+}
+
+
+#ifdef CL_IPV6_PASS
+static void __nat25_generate_ipv6_network_addr(unsigned char *networkAddr,
+ unsigned int *ipAddr)
+{
+ memset(networkAddr, 0, MAX_NETWORK_ADDR_LEN);
+
+ networkAddr[0] = NAT25_IPV6;
+ memcpy(networkAddr + 1, (unsigned char *)ipAddr, 16);
+}
+
+
+static unsigned char *scan_tlv(unsigned char *data, int len, unsigned char tag, unsigned char len8b)
+{
+ while (len > 0) {
+ if (*data == tag && *(data + 1) == len8b && len >= len8b * 8)
+ return data + 2;
+
+ len -= (*(data + 1)) * 8;
+ data += (*(data + 1)) * 8;
+ }
+ return NULL;
+}
+
+
+static int update_nd_link_layer_addr(unsigned char *data, int len, unsigned char *replace_mac)
+{
+ struct icmp6hdr *icmphdr = (struct icmp6hdr *)data;
+ unsigned char *mac;
+
+ if (icmphdr->icmp6_type == NDISC_ROUTER_SOLICITATION) {
+ if (len >= 8) {
+ mac = scan_tlv(&data[8], len - 8, 1, 1);
+ if (mac) {
+ RTW_INFO("Router Solicitation, replace MAC From: %02x:%02x:%02x:%02x:%02x:%02x, To: %02x:%02x:%02x:%02x:%02x:%02x\n",
+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
+ replace_mac[0], replace_mac[1], replace_mac[2], replace_mac[3], replace_mac[4], replace_mac[5]);
+ memcpy(mac, replace_mac, 6);
+ return 1;
+ }
+ }
+ } else if (icmphdr->icmp6_type == NDISC_ROUTER_ADVERTISEMENT) {
+ if (len >= 16) {
+ mac = scan_tlv(&data[16], len - 16, 1, 1);
+ if (mac) {
+ RTW_INFO("Router Advertisement, replace MAC From: %02x:%02x:%02x:%02x:%02x:%02x, To: %02x:%02x:%02x:%02x:%02x:%02x\n",
+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
+ replace_mac[0], replace_mac[1], replace_mac[2], replace_mac[3], replace_mac[4], replace_mac[5]);
+ memcpy(mac, replace_mac, 6);
+ return 1;
+ }
+ }
+ } else if (icmphdr->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) {
+ if (len >= 24) {
+ mac = scan_tlv(&data[24], len - 24, 1, 1);
+ if (mac) {
+ RTW_INFO("Neighbor Solicitation, replace MAC From: %02x:%02x:%02x:%02x:%02x:%02x, To: %02x:%02x:%02x:%02x:%02x:%02x\n",
+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
+ replace_mac[0], replace_mac[1], replace_mac[2], replace_mac[3], replace_mac[4], replace_mac[5]);
+ memcpy(mac, replace_mac, 6);
+ return 1;
+ }
+ }
+ } else if (icmphdr->icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT) {
+ if (len >= 24) {
+ mac = scan_tlv(&data[24], len - 24, 2, 1);
+ if (mac) {
+ RTW_INFO("Neighbor Advertisement, replace MAC From: %02x:%02x:%02x:%02x:%02x:%02x, To: %02x:%02x:%02x:%02x:%02x:%02x\n",
+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
+ replace_mac[0], replace_mac[1], replace_mac[2], replace_mac[3], replace_mac[4], replace_mac[5]);
+ memcpy(mac, replace_mac, 6);
+ return 1;
+ }
+ }
+ } else if (icmphdr->icmp6_type == NDISC_REDIRECT) {
+ if (len >= 40) {
+ mac = scan_tlv(&data[40], len - 40, 2, 1);
+ if (mac) {
+ RTW_INFO("Redirect, replace MAC From: %02x:%02x:%02x:%02x:%02x:%02x, To: %02x:%02x:%02x:%02x:%02x:%02x\n",
+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
+ replace_mac[0], replace_mac[1], replace_mac[2], replace_mac[3], replace_mac[4], replace_mac[5]);
+ memcpy(mac, replace_mac, 6);
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
+
+
+static void convert_ipv6_mac_to_mc(struct sk_buff *skb)
+{
+ struct ipv6hdr *iph = (struct ipv6hdr *)(skb->data + ETH_HLEN);
+ unsigned char *dst_mac = skb->data;
+
+ /* dst_mac[0] = 0xff; */
+ /* dst_mac[1] = 0xff; */
+ /*modified by qinjunjie,ipv6 multicast address ix 0x33-33-xx-xx-xx-xx*/
+ dst_mac[0] = 0x33;
+ dst_mac[1] = 0x33;
+ memcpy(&dst_mac[2], &iph->daddr.s6_addr32[3], 4);
+#if defined(__LINUX_2_6__)
+ /*modified by qinjunjie,warning:should not remove next line*/
+ skb->pkt_type = PACKET_MULTICAST;
+#endif
+}
+#endif /* CL_IPV6_PASS */
+
+
+static __inline__ int __nat25_network_hash(unsigned char *networkAddr)
+{
+ if (networkAddr[0] == NAT25_IPV4) {
+ unsigned long x;
+
+ x = networkAddr[7] ^ networkAddr[8] ^ networkAddr[9] ^ networkAddr[10];
+
+ return x & (NAT25_HASH_SIZE - 1);
+ } else if (networkAddr[0] == NAT25_IPX) {
+ unsigned long x;
+
+ x = networkAddr[1] ^ networkAddr[2] ^ networkAddr[3] ^ networkAddr[4] ^ networkAddr[5] ^
+ networkAddr[6] ^ networkAddr[7] ^ networkAddr[8] ^ networkAddr[9] ^ networkAddr[10];
+
+ return x & (NAT25_HASH_SIZE - 1);
+ } else if (networkAddr[0] == NAT25_APPLE) {
+ unsigned long x;
+
+ x = networkAddr[1] ^ networkAddr[2] ^ networkAddr[3];
+
+ return x & (NAT25_HASH_SIZE - 1);
+ } else if (networkAddr[0] == NAT25_PPPOE) {
+ unsigned long x;
+
+ x = networkAddr[0] ^ networkAddr[1] ^ networkAddr[2] ^ networkAddr[3] ^ networkAddr[4] ^ networkAddr[5] ^ networkAddr[6] ^ networkAddr[7] ^ networkAddr[8];
+
+ return x & (NAT25_HASH_SIZE - 1);
+ }
+#ifdef CL_IPV6_PASS
+ else if (networkAddr[0] == NAT25_IPV6) {
+ unsigned long x;
+
+ x = networkAddr[1] ^ networkAddr[2] ^ networkAddr[3] ^ networkAddr[4] ^ networkAddr[5] ^
+ networkAddr[6] ^ networkAddr[7] ^ networkAddr[8] ^ networkAddr[9] ^ networkAddr[10] ^
+ networkAddr[11] ^ networkAddr[12] ^ networkAddr[13] ^ networkAddr[14] ^ networkAddr[15] ^
+ networkAddr[16];
+
+ return x & (NAT25_HASH_SIZE - 1);
+ }
+#endif
+ else {
+ unsigned long x = 0;
+ int i;
+
+ for (i = 0; i < MAX_NETWORK_ADDR_LEN; i++)
+ x ^= networkAddr[i];
+
+ return x & (NAT25_HASH_SIZE - 1);
+ }
+}
+
+
+static __inline__ void __network_hash_link(_adapter *priv,
+ struct nat25_network_db_entry *ent, int hash)
+{
+ /* Caller must _enter_critical_bh already! */
+ /* unsigned long irqL; */
+ /* _enter_critical_bh(&priv->br_ext_lock, &irqL); */
+
+ ent->next_hash = priv->nethash[hash];
+ if (ent->next_hash != NULL)
+ ent->next_hash->pprev_hash = &ent->next_hash;
+ priv->nethash[hash] = ent;
+ ent->pprev_hash = &priv->nethash[hash];
+
+ /* _exit_critical_bh(&priv->br_ext_lock, &irqL); */
+}
+
+
+static __inline__ void __network_hash_unlink(struct nat25_network_db_entry *ent)
+{
+ /* Caller must _enter_critical_bh already! */
+ /* unsigned long irqL; */
+ /* _enter_critical_bh(&priv->br_ext_lock, &irqL); */
+
+ *(ent->pprev_hash) = ent->next_hash;
+ if (ent->next_hash != NULL)
+ ent->next_hash->pprev_hash = ent->pprev_hash;
+ ent->next_hash = NULL;
+ ent->pprev_hash = NULL;
+
+ /* _exit_critical_bh(&priv->br_ext_lock, &irqL); */
+}
+
+
+static int __nat25_db_network_lookup_and_replace(_adapter *priv,
+ struct sk_buff *skb, unsigned char *networkAddr)
+{
+ struct nat25_network_db_entry *db;
+ unsigned long irqL;
+ _enter_critical_bh(&priv->br_ext_lock, &irqL);
+
+ db = priv->nethash[__nat25_network_hash(networkAddr)];
+ while (db != NULL) {
+ if (!memcmp(db->networkAddr, networkAddr, MAX_NETWORK_ADDR_LEN)) {
+ if (!__nat25_has_expired(priv, db)) {
+ /* replace the destination mac address */
+ memcpy(skb->data, db->macAddr, ETH_ALEN);
+ atomic_inc(&db->use_count);
+
+#ifdef CL_IPV6_PASS
+ RTW_INFO("NAT25: Lookup M:%02x%02x%02x%02x%02x%02x N:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
+ "%02x%02x%02x%02x%02x%02x\n",
+ db->macAddr[0],
+ db->macAddr[1],
+ db->macAddr[2],
+ db->macAddr[3],
+ db->macAddr[4],
+ db->macAddr[5],
+ db->networkAddr[0],
+ db->networkAddr[1],
+ db->networkAddr[2],
+ db->networkAddr[3],
+ db->networkAddr[4],
+ db->networkAddr[5],
+ db->networkAddr[6],
+ db->networkAddr[7],
+ db->networkAddr[8],
+ db->networkAddr[9],
+ db->networkAddr[10],
+ db->networkAddr[11],
+ db->networkAddr[12],
+ db->networkAddr[13],
+ db->networkAddr[14],
+ db->networkAddr[15],
+ db->networkAddr[16]);
+#else
+ RTW_INFO("NAT25: Lookup M:%02x%02x%02x%02x%02x%02x N:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
+ db->macAddr[0],
+ db->macAddr[1],
+ db->macAddr[2],
+ db->macAddr[3],
+ db->macAddr[4],
+ db->macAddr[5],
+ db->networkAddr[0],
+ db->networkAddr[1],
+ db->networkAddr[2],
+ db->networkAddr[3],
+ db->networkAddr[4],
+ db->networkAddr[5],
+ db->networkAddr[6],
+ db->networkAddr[7],
+ db->networkAddr[8],
+ db->networkAddr[9],
+ db->networkAddr[10]);
+#endif
+ }
+ _exit_critical_bh(&priv->br_ext_lock, &irqL);
+ return 1;
+ }
+
+ db = db->next_hash;
+ }
+
+ _exit_critical_bh(&priv->br_ext_lock, &irqL);
+ return 0;
+}
+
+
+static void __nat25_db_network_insert(_adapter *priv,
+ unsigned char *macAddr, unsigned char *networkAddr)
+{
+ struct nat25_network_db_entry *db;
+ int hash;
+ unsigned long irqL;
+ _enter_critical_bh(&priv->br_ext_lock, &irqL);
+
+ hash = __nat25_network_hash(networkAddr);
+ db = priv->nethash[hash];
+ while (db != NULL) {
+ if (!memcmp(db->networkAddr, networkAddr, MAX_NETWORK_ADDR_LEN)) {
+ memcpy(db->macAddr, macAddr, ETH_ALEN);
+ db->ageing_timer = jiffies;
+ _exit_critical_bh(&priv->br_ext_lock, &irqL);
+ return;
+ }
+
+ db = db->next_hash;
+ }
+
+ db = (struct nat25_network_db_entry *) rtw_malloc(sizeof(*db));
+ if (db == NULL) {
+ _exit_critical_bh(&priv->br_ext_lock, &irqL);
+ return;
+ }
+
+ memcpy(db->networkAddr, networkAddr, MAX_NETWORK_ADDR_LEN);
+ memcpy(db->macAddr, macAddr, ETH_ALEN);
+ atomic_set(&db->use_count, 1);
+ db->ageing_timer = jiffies;
+
+ __network_hash_link(priv, db, hash);
+
+ _exit_critical_bh(&priv->br_ext_lock, &irqL);
+}
+
+
+static void __nat25_db_print(_adapter *priv)
+{
+ unsigned long irqL;
+ _enter_critical_bh(&priv->br_ext_lock, &irqL);
+
+#ifdef BR_EXT_DEBUG
+ static int counter = 0;
+ int i, j;
+ struct nat25_network_db_entry *db;
+
+ counter++;
+ if ((counter % 16) != 0)
+ return;
+
+ for (i = 0, j = 0; i < NAT25_HASH_SIZE; i++) {
+ db = priv->nethash[i];
+
+ while (db != NULL) {
+#ifdef CL_IPV6_PASS
+ panic_RTW_INFO("NAT25: DB(%d) H(%02d) C(%d) M:%02x%02x%02x%02x%02x%02x N:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
+ "%02x%02x%02x%02x%02x%02x\n",
+ j,
+ i,
+ atomic_read(&db->use_count),
+ db->macAddr[0],
+ db->macAddr[1],
+ db->macAddr[2],
+ db->macAddr[3],
+ db->macAddr[4],
+ db->macAddr[5],
+ db->networkAddr[0],
+ db->networkAddr[1],
+ db->networkAddr[2],
+ db->networkAddr[3],
+ db->networkAddr[4],
+ db->networkAddr[5],
+ db->networkAddr[6],
+ db->networkAddr[7],
+ db->networkAddr[8],
+ db->networkAddr[9],
+ db->networkAddr[10],
+ db->networkAddr[11],
+ db->networkAddr[12],
+ db->networkAddr[13],
+ db->networkAddr[14],
+ db->networkAddr[15],
+ db->networkAddr[16]);
+#else
+ panic_RTW_INFO("NAT25: DB(%d) H(%02d) C(%d) M:%02x%02x%02x%02x%02x%02x N:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
+ j,
+ i,
+ atomic_read(&db->use_count),
+ db->macAddr[0],
+ db->macAddr[1],
+ db->macAddr[2],
+ db->macAddr[3],
+ db->macAddr[4],
+ db->macAddr[5],
+ db->networkAddr[0],
+ db->networkAddr[1],
+ db->networkAddr[2],
+ db->networkAddr[3],
+ db->networkAddr[4],
+ db->networkAddr[5],
+ db->networkAddr[6],
+ db->networkAddr[7],
+ db->networkAddr[8],
+ db->networkAddr[9],
+ db->networkAddr[10]);
+#endif
+ j++;
+
+ db = db->next_hash;
+ }
+ }
+#endif
+
+ _exit_critical_bh(&priv->br_ext_lock, &irqL);
+}
+
+
+
+
+/*
+ * NAT2.5 interface
+ */
+
+void nat25_db_cleanup(_adapter *priv)
+{
+ int i;
+ unsigned long irqL;
+ _enter_critical_bh(&priv->br_ext_lock, &irqL);
+
+ for (i = 0; i < NAT25_HASH_SIZE; i++) {
+ struct nat25_network_db_entry *f;
+ f = priv->nethash[i];
+ while (f != NULL) {
+ struct nat25_network_db_entry *g;
+
+ g = f->next_hash;
+ if (priv->scdb_entry == f) {
+ memset(priv->scdb_mac, 0, ETH_ALEN);
+ memset(priv->scdb_ip, 0, 4);
+ priv->scdb_entry = NULL;
+ }
+ __network_hash_unlink(f);
+ rtw_mfree((u8 *) f, sizeof(struct nat25_network_db_entry));
+
+ f = g;
+ }
+ }
+
+ _exit_critical_bh(&priv->br_ext_lock, &irqL);
+}
+
+
+void nat25_db_expire(_adapter *priv)
+{
+ int i;
+ unsigned long irqL;
+ _enter_critical_bh(&priv->br_ext_lock, &irqL);
+
+ /* if(!priv->ethBrExtInfo.nat25_disable) */
+ {
+ for (i = 0; i < NAT25_HASH_SIZE; i++) {
+ struct nat25_network_db_entry *f;
+ f = priv->nethash[i];
+
+ while (f != NULL) {
+ struct nat25_network_db_entry *g;
+ g = f->next_hash;
+
+ if (__nat25_has_expired(priv, f)) {
+ if (atomic_dec_and_test(&f->use_count)) {
+#ifdef BR_EXT_DEBUG
+#ifdef CL_IPV6_PASS
+ panic_RTW_INFO("NAT25 Expire H(%02d) M:%02x%02x%02x%02x%02x%02x N:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
+ "%02x%02x%02x%02x%02x%02x\n",
+ i,
+ f->macAddr[0],
+ f->macAddr[1],
+ f->macAddr[2],
+ f->macAddr[3],
+ f->macAddr[4],
+ f->macAddr[5],
+ f->networkAddr[0],
+ f->networkAddr[1],
+ f->networkAddr[2],
+ f->networkAddr[3],
+ f->networkAddr[4],
+ f->networkAddr[5],
+ f->networkAddr[6],
+ f->networkAddr[7],
+ f->networkAddr[8],
+ f->networkAddr[9],
+ f->networkAddr[10],
+ f->networkAddr[11],
+ f->networkAddr[12],
+ f->networkAddr[13],
+ f->networkAddr[14],
+ f->networkAddr[15],
+ f->networkAddr[16]);
+#else
+
+ panic_RTW_INFO("NAT25 Expire H(%02d) M:%02x%02x%02x%02x%02x%02x N:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
+ i,
+ f->macAddr[0],
+ f->macAddr[1],
+ f->macAddr[2],
+ f->macAddr[3],
+ f->macAddr[4],
+ f->macAddr[5],
+ f->networkAddr[0],
+ f->networkAddr[1],
+ f->networkAddr[2],
+ f->networkAddr[3],
+ f->networkAddr[4],
+ f->networkAddr[5],
+ f->networkAddr[6],
+ f->networkAddr[7],
+ f->networkAddr[8],
+ f->networkAddr[9],
+ f->networkAddr[10]);
+#endif
+#endif
+ if (priv->scdb_entry == f) {
+ memset(priv->scdb_mac, 0, ETH_ALEN);
+ memset(priv->scdb_ip, 0, 4);
+ priv->scdb_entry = NULL;
+ }
+ __network_hash_unlink(f);
+ rtw_mfree((u8 *) f, sizeof(struct nat25_network_db_entry));
+ }
+ }
+
+ f = g;
+ }
+ }
+ }
+
+ _exit_critical_bh(&priv->br_ext_lock, &irqL);
+}
+
+
+#ifdef SUPPORT_TX_MCAST2UNI
+static int checkIPMcAndReplace(_adapter *priv, struct sk_buff *skb, unsigned int *dst_ip)
+{
+ struct stat_info *pstat;
+ struct list_head *phead, *plist;
+ int i;
+
+ phead = &priv->asoc_list;
+ plist = phead->next;
+
+ while (plist != phead) {
+ pstat = list_entry(plist, struct stat_info, asoc_list);
+ plist = plist->next;
+
+ if (pstat->ipmc_num == 0)
+ continue;
+
+ for (i = 0; i < MAX_IP_MC_ENTRY; i++) {
+ if (pstat->ipmc[i].used && !memcmp(&pstat->ipmc[i].mcmac[3], ((unsigned char *)dst_ip) + 1, 3)) {
+ memcpy(skb->data, pstat->ipmc[i].mcmac, ETH_ALEN);
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
+#endif
+
+int nat25_db_handle(_adapter *priv, struct sk_buff *skb, int method)
+{
+ __be16 protocol;
+ unsigned char networkAddr[MAX_NETWORK_ADDR_LEN];
+ unsigned int tmp;
+
+ if (skb == NULL)
+ return -1;
+
+ if ((method <= NAT25_MIN) || (method >= NAT25_MAX))
+ return -1;
+
+ protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
+
+ /*---------------------------------------------------*/
+ /* Handle IP frame */
+ /*---------------------------------------------------*/
+ if (protocol == __constant_htons(ETH_P_IP)) {
+ struct iphdr *iph = (struct iphdr *)(skb->data + ETH_HLEN);
+
+ if (((unsigned char *)(iph) + (iph->ihl << 2)) >= (skb->data + ETH_HLEN + skb->len)) {
+ DEBUG_WARN("NAT25: malformed IP packet !\n");
+ return -1;
+ }
+
+ switch (method) {
+ case NAT25_CHECK:
+ return -1;
+
+ case NAT25_INSERT: {
+ /* some muticast with source IP is all zero, maybe other case is illegal */
+ /* in class A, B, C, host address is all zero or all one is illegal */
+ if (iph->saddr == 0)
+ return 0;
+ tmp = be32_to_cpu(iph->saddr);
+ RTW_INFO("NAT25: Insert IP, SA=%08x, DA=%08x\n", iph->saddr, iph->daddr);
+ __nat25_generate_ipv4_network_addr(networkAddr, &tmp);
+ /* record source IP address and , source mac address into db */
+ __nat25_db_network_insert(priv, skb->data + ETH_ALEN, networkAddr);
+
+ __nat25_db_print(priv);
+ }
+ return 0;
+
+ case NAT25_LOOKUP: {
+ RTW_INFO("NAT25: Lookup IP, SA=%08x, DA=%08x\n", iph->saddr, iph->daddr);
+#ifdef SUPPORT_TX_MCAST2UNI
+ if (priv->pshare->rf_ft_var.mc2u_disable ||
+ ((((OPMODE & (WIFI_STATION_STATE | WIFI_ASOC_STATE))
+ == (WIFI_STATION_STATE | WIFI_ASOC_STATE)) &&
+ !checkIPMcAndReplace(priv, skb, &iph->daddr)) ||
+ (OPMODE & WIFI_ADHOC_STATE)))
+#endif
+ {
+ tmp = be32_to_cpu(iph->daddr);
+ __nat25_generate_ipv4_network_addr(networkAddr, &tmp);
+
+ if (!__nat25_db_network_lookup_and_replace(priv, skb, networkAddr)) {
+ if (*((unsigned char *)&iph->daddr + 3) == 0xff) {
+ /* L2 is unicast but L3 is broadcast, make L2 bacome broadcast */
+ RTW_INFO("NAT25: Set DA as boardcast\n");
+ memset(skb->data, 0xff, ETH_ALEN);
+ } else {
+ /* forward unknow IP packet to upper TCP/IP */
+ RTW_INFO("NAT25: Replace DA with BR's MAC\n");
+ if ((*(u32 *)priv->br_mac) == 0 && (*(u16 *)(priv->br_mac + 4)) == 0) {
+ RTW_INFO("Re-init netdev_br_init() due to br_mac==0!\n");
+ netdev_br_init(priv->pnetdev);
+ }
+ memcpy(skb->data, priv->br_mac, ETH_ALEN);
+ }
+ }
+ }
+ }
+ return 0;
+
+ default:
+ return -1;
+ }
+ }
+
+ /*---------------------------------------------------*/
+ /* Handle ARP frame */
+ /*---------------------------------------------------*/
+ else if (protocol == __constant_htons(ETH_P_ARP)) {
+ struct arphdr *arp = (struct arphdr *)(skb->data + ETH_HLEN);
+ unsigned char *arp_ptr = (unsigned char *)(arp + 1);
+ unsigned int *sender, *target;
+
+ if (arp->ar_pro != __constant_htons(ETH_P_IP)) {
+ DEBUG_WARN("NAT25: arp protocol unknown (%4x)!\n", be16_to_cpu(arp->ar_pro));
+ return -1;
+ }
+
+ switch (method) {
+ case NAT25_CHECK:
+ return 0; /* skb_copy for all ARP frame */
+
+ case NAT25_INSERT: {
+ RTW_INFO("NAT25: Insert ARP, MAC=%02x%02x%02x%02x%02x%02x\n", arp_ptr[0],
+ arp_ptr[1], arp_ptr[2], arp_ptr[3], arp_ptr[4], arp_ptr[5]);
+
+ /* change to ARP sender mac address to wlan STA address */
+ memcpy(arp_ptr, GET_MY_HWADDR(priv), ETH_ALEN);
+
+ arp_ptr += arp->ar_hln;
+ sender = (unsigned int *)arp_ptr;
+
+ __nat25_generate_ipv4_network_addr(networkAddr, sender);
+
+ __nat25_db_network_insert(priv, skb->data + ETH_ALEN, networkAddr);
+
+ __nat25_db_print(priv);
+ }
+ return 0;
+
+ case NAT25_LOOKUP: {
+ RTW_INFO("NAT25: Lookup ARP\n");
+
+ arp_ptr += arp->ar_hln;
+ sender = (unsigned int *)arp_ptr;
+ arp_ptr += (arp->ar_hln + arp->ar_pln);
+ target = (unsigned int *)arp_ptr;
+
+ __nat25_generate_ipv4_network_addr(networkAddr, target);
+
+ __nat25_db_network_lookup_and_replace(priv, skb, networkAddr);
+
+ /* change to ARP target mac address to Lookup result */
+ arp_ptr = (unsigned char *)(arp + 1);
+ arp_ptr += (arp->ar_hln + arp->ar_pln);
+ memcpy(arp_ptr, skb->data, ETH_ALEN);
+ }
+ return 0;
+
+ default:
+ return -1;
+ }
+ }
+
+ /*---------------------------------------------------*/
+ /* Handle IPX and Apple Talk frame */
+ /*---------------------------------------------------*/
+ else if ((protocol == __constant_htons(ETH_P_IPX)) ||
+ (protocol == __constant_htons(ETH_P_ATALK)) ||
+ (protocol == __constant_htons(ETH_P_AARP))) {
+ unsigned char ipx_header[2] = {0xFF, 0xFF};
+ struct ipxhdr *ipx = NULL;
+ struct elapaarp *ea = NULL;
+ struct ddpehdr *ddp = NULL;
+ unsigned char *framePtr = skb->data + ETH_HLEN;
+
+ if (protocol == __constant_htons(ETH_P_IPX)) {
+ RTW_INFO("NAT25: Protocol=IPX (Ethernet II)\n");
+ ipx = (struct ipxhdr *)framePtr;
+ } else { /* if(protocol <= __constant_htons(ETH_FRAME_LEN)) */
+ if (!memcmp(ipx_header, framePtr, 2)) {
+ RTW_INFO("NAT25: Protocol=IPX (Ethernet 802.3)\n");
+ ipx = (struct ipxhdr *)framePtr;
+ } else {
+ unsigned char ipx_8022_type = 0xE0;
+ unsigned char snap_8022_type = 0xAA;
+
+ if (*framePtr == snap_8022_type) {
+ unsigned char ipx_snap_id[5] = {0x0, 0x0, 0x0, 0x81, 0x37}; /* IPX SNAP ID */
+ unsigned char aarp_snap_id[5] = {0x00, 0x00, 0x00, 0x80, 0xF3}; /* Apple Talk AARP SNAP ID */
+ unsigned char ddp_snap_id[5] = {0x08, 0x00, 0x07, 0x80, 0x9B}; /* Apple Talk DDP SNAP ID */
+
+ framePtr += 3; /* eliminate the 802.2 header */
+
+ if (!memcmp(ipx_snap_id, framePtr, 5)) {
+ framePtr += 5; /* eliminate the SNAP header */
+
+ RTW_INFO("NAT25: Protocol=IPX (Ethernet SNAP)\n");
+ ipx = (struct ipxhdr *)framePtr;
+ } else if (!memcmp(aarp_snap_id, framePtr, 5)) {
+ framePtr += 5; /* eliminate the SNAP header */
+
+ ea = (struct elapaarp *)framePtr;
+ } else if (!memcmp(ddp_snap_id, framePtr, 5)) {
+ framePtr += 5; /* eliminate the SNAP header */
+
+ ddp = (struct ddpehdr *)framePtr;
+ } else {
+ DEBUG_WARN("NAT25: Protocol=Ethernet SNAP %02x%02x%02x%02x%02x\n", framePtr[0],
+ framePtr[1], framePtr[2], framePtr[3], framePtr[4]);
+ return -1;
+ }
+ } else if (*framePtr == ipx_8022_type) {
+ framePtr += 3; /* eliminate the 802.2 header */
+
+ if (!memcmp(ipx_header, framePtr, 2)) {
+ RTW_INFO("NAT25: Protocol=IPX (Ethernet 802.2)\n");
+ ipx = (struct ipxhdr *)framePtr;
+ } else
+ return -1;
+ }
+ }
+ }
+
+ /* IPX */
+ if (ipx != NULL) {
+ switch (method) {
+ case NAT25_CHECK:
+ if (!memcmp(skb->data + ETH_ALEN, ipx->ipx_source.node, ETH_ALEN)) {
+ RTW_INFO("NAT25: Check IPX skb_copy\n");
+ return 0;
+ }
+ return -1;
+
+ case NAT25_INSERT: {
+ RTW_INFO("NAT25: Insert IPX, Dest=%08x,%02x%02x%02x%02x%02x%02x,%04x Source=%08x,%02x%02x%02x%02x%02x%02x,%04x\n",
+ ipx->ipx_dest.net,
+ ipx->ipx_dest.node[0],
+ ipx->ipx_dest.node[1],
+ ipx->ipx_dest.node[2],
+ ipx->ipx_dest.node[3],
+ ipx->ipx_dest.node[4],
+ ipx->ipx_dest.node[5],
+ ipx->ipx_dest.sock,
+ ipx->ipx_source.net,
+ ipx->ipx_source.node[0],
+ ipx->ipx_source.node[1],
+ ipx->ipx_source.node[2],
+ ipx->ipx_source.node[3],
+ ipx->ipx_source.node[4],
+ ipx->ipx_source.node[5],
+ ipx->ipx_source.sock);
+
+ if (!memcmp(skb->data + ETH_ALEN, ipx->ipx_source.node, ETH_ALEN)) {
+ RTW_INFO("NAT25: Use IPX Net, and Socket as network addr\n");
+
+ __nat25_generate_ipx_network_addr_with_socket(networkAddr, &ipx->ipx_source.net, &ipx->ipx_source.sock);
+
+ /* change IPX source node addr to wlan STA address */
+ memcpy(ipx->ipx_source.node, GET_MY_HWADDR(priv), ETH_ALEN);
+ } else
+ __nat25_generate_ipx_network_addr_with_node(networkAddr, &ipx->ipx_source.net, ipx->ipx_source.node);
+
+ __nat25_db_network_insert(priv, skb->data + ETH_ALEN, networkAddr);
+
+ __nat25_db_print(priv);
+ }
+ return 0;
+
+ case NAT25_LOOKUP: {
+ if (!memcmp(GET_MY_HWADDR(priv), ipx->ipx_dest.node, ETH_ALEN)) {
+ RTW_INFO("NAT25: Lookup IPX, Modify Destination IPX Node addr\n");
+
+ __nat25_generate_ipx_network_addr_with_socket(networkAddr, &ipx->ipx_dest.net, &ipx->ipx_dest.sock);
+
+ __nat25_db_network_lookup_and_replace(priv, skb, networkAddr);
+
+ /* replace IPX destination node addr with Lookup destination MAC addr */
+ memcpy(ipx->ipx_dest.node, skb->data, ETH_ALEN);
+ } else {
+ __nat25_generate_ipx_network_addr_with_node(networkAddr, &ipx->ipx_dest.net, ipx->ipx_dest.node);
+
+ __nat25_db_network_lookup_and_replace(priv, skb, networkAddr);
+ }
+ }
+ return 0;
+
+ default:
+ return -1;
+ }
+ }
+
+ /* AARP */
+ else if (ea != NULL) {
+ /* Sanity check fields. */
+ if (ea->hw_len != ETH_ALEN || ea->pa_len != AARP_PA_ALEN) {
+ DEBUG_WARN("NAT25: Appletalk AARP Sanity check fail!\n");
+ return -1;
+ }
+
+ switch (method) {
+ case NAT25_CHECK:
+ return 0;
+
+ case NAT25_INSERT: {
+ /* change to AARP source mac address to wlan STA address */
+ memcpy(ea->hw_src, GET_MY_HWADDR(priv), ETH_ALEN);
+
+ RTW_INFO("NAT25: Insert AARP, Source=%d,%d Destination=%d,%d\n",
+ ea->pa_src_net,
+ ea->pa_src_node,
+ ea->pa_dst_net,
+ ea->pa_dst_node);
+
+ __nat25_generate_apple_network_addr(networkAddr, &ea->pa_src_net, &ea->pa_src_node);
+
+ __nat25_db_network_insert(priv, skb->data + ETH_ALEN, networkAddr);
+
+ __nat25_db_print(priv);
+ }
+ return 0;
+
+ case NAT25_LOOKUP: {
+ RTW_INFO("NAT25: Lookup AARP, Source=%d,%d Destination=%d,%d\n",
+ ea->pa_src_net,
+ ea->pa_src_node,
+ ea->pa_dst_net,
+ ea->pa_dst_node);
+
+ __nat25_generate_apple_network_addr(networkAddr, &ea->pa_dst_net, &ea->pa_dst_node);
+
+ __nat25_db_network_lookup_and_replace(priv, skb, networkAddr);
+
+ /* change to AARP destination mac address to Lookup result */
+ memcpy(ea->hw_dst, skb->data, ETH_ALEN);
+ }
+ return 0;
+
+ default:
+ return -1;
+ }
+ }
+
+ /* DDP */
+ else if (ddp != NULL) {
+ switch (method) {
+ case NAT25_CHECK:
+ return -1;
+
+ case NAT25_INSERT: {
+ RTW_INFO("NAT25: Insert DDP, Source=%d,%d Destination=%d,%d\n",
+ ddp->deh_snet,
+ ddp->deh_snode,
+ ddp->deh_dnet,
+ ddp->deh_dnode);
+
+ __nat25_generate_apple_network_addr(networkAddr, &ddp->deh_snet, &ddp->deh_snode);
+
+ __nat25_db_network_insert(priv, skb->data + ETH_ALEN, networkAddr);
+
+ __nat25_db_print(priv);
+ }
+ return 0;
+
+ case NAT25_LOOKUP: {
+ RTW_INFO("NAT25: Lookup DDP, Source=%d,%d Destination=%d,%d\n",
+ ddp->deh_snet,
+ ddp->deh_snode,
+ ddp->deh_dnet,
+ ddp->deh_dnode);
+
+ __nat25_generate_apple_network_addr(networkAddr, &ddp->deh_dnet, &ddp->deh_dnode);
+
+ __nat25_db_network_lookup_and_replace(priv, skb, networkAddr);
+ }
+ return 0;
+
+ default:
+ return -1;
+ }
+ }
+
+ return -1;
+ }
+
+ /*---------------------------------------------------*/
+ /* Handle PPPoE frame */
+ /*---------------------------------------------------*/
+ else if ((protocol == __constant_htons(ETH_P_PPP_DISC)) ||
+ (protocol == __constant_htons(ETH_P_PPP_SES))) {
+ struct pppoe_hdr *ph = (struct pppoe_hdr *)(skb->data + ETH_HLEN);
+ __be16 *pMagic;
+
+ switch (method) {
+ case NAT25_CHECK:
+ if (ph->sid == 0)
+ return 0;
+ return 1;
+
+ case NAT25_INSERT:
+ if (ph->sid == 0) { /* Discovery phase according to tag */
+ if (ph->code == PADI_CODE || ph->code == PADR_CODE) {
+ if (priv->ethBrExtInfo.addPPPoETag) {
+ struct pppoe_tag *tag, *pOldTag;
+ unsigned char tag_buf[40];
+ int old_tag_len = 0;
+
+ tag = (struct pppoe_tag *)tag_buf;
+ pOldTag = (struct pppoe_tag *)__nat25_find_pppoe_tag(ph, ntohs(PTT_RELAY_SID));
+ if (pOldTag) { /* if SID existed, copy old value and delete it */
+ old_tag_len = ntohs(pOldTag->tag_len);
+ if (old_tag_len + TAG_HDR_LEN + MAGIC_CODE_LEN + RTL_RELAY_TAG_LEN > sizeof(tag_buf)) {
+ DEBUG_ERR("SID tag length too long!\n");
+ return -1;
+ }
+
+ memcpy(tag->tag_data + MAGIC_CODE_LEN + RTL_RELAY_TAG_LEN,
+ pOldTag->tag_data, old_tag_len);
+
+ if (skb_pull_and_merge(skb, (unsigned char *)pOldTag, TAG_HDR_LEN + old_tag_len) < 0) {
+ DEBUG_ERR("call skb_pull_and_merge() failed in PADI/R packet!\n");
+ return -1;
+ }
+ ph->length = htons(ntohs(ph->length) - TAG_HDR_LEN - old_tag_len);
+ }
+
+ tag->tag_type = PTT_RELAY_SID;
+ tag->tag_len = htons(MAGIC_CODE_LEN + RTL_RELAY_TAG_LEN + old_tag_len);
+
+ /* insert the magic_code+client mac in relay tag */
+ pMagic = (__be16 *)tag->tag_data;
+ *pMagic = htons(MAGIC_CODE);
+ memcpy(tag->tag_data + MAGIC_CODE_LEN, skb->data + ETH_ALEN, ETH_ALEN);
+
+ /* Add relay tag */
+ if (__nat25_add_pppoe_tag(skb, tag) < 0)
+ return -1;
+
+ RTW_INFO("NAT25: Insert PPPoE, forward %s packet\n",
+ (ph->code == PADI_CODE ? "PADI" : "PADR"));
+ } else { /* not add relay tag */
+ if (priv->pppoe_connection_in_progress &&
+ memcmp(skb->data + ETH_ALEN, priv->pppoe_addr, ETH_ALEN)) {
+ DEBUG_ERR("Discard PPPoE packet due to another PPPoE connection is in progress!\n");
+ return -2;
+ }
+
+ if (priv->pppoe_connection_in_progress == 0)
+ memcpy(priv->pppoe_addr, skb->data + ETH_ALEN, ETH_ALEN);
+
+ priv->pppoe_connection_in_progress = WAIT_TIME_PPPOE;
+ }
+ } else
+ return -1;
+ } else { /* session phase */
+ RTW_INFO("NAT25: Insert PPPoE, insert session packet to %s\n", skb->dev->name);
+
+ __nat25_generate_pppoe_network_addr(networkAddr, skb->data, &(ph->sid));
+
+ __nat25_db_network_insert(priv, skb->data + ETH_ALEN, networkAddr);
+
+ __nat25_db_print(priv);
+
+ if (!priv->ethBrExtInfo.addPPPoETag &&
+ priv->pppoe_connection_in_progress &&
+ !memcmp(skb->data + ETH_ALEN, priv->pppoe_addr, ETH_ALEN))
+ priv->pppoe_connection_in_progress = 0;
+ }
+ return 0;
+
+ case NAT25_LOOKUP:
+ if (ph->code == PADO_CODE || ph->code == PADS_CODE) {
+ if (priv->ethBrExtInfo.addPPPoETag) {
+ struct pppoe_tag *tag;
+ unsigned char *ptr;
+ unsigned short tagType, tagLen;
+ int offset = 0;
+
+ ptr = __nat25_find_pppoe_tag(ph, ntohs(PTT_RELAY_SID));
+ if (!ptr) {
+ DEBUG_ERR("Fail to find PTT_RELAY_SID in FADO!\n");
+ return -1;
+ }
+
+ tag = (struct pppoe_tag *)ptr;
+ tagType = (unsigned short)((ptr[0] << 8) + ptr[1]);
+ tagLen = (unsigned short)((ptr[2] << 8) + ptr[3]);
+
+ if ((tagType != ntohs(PTT_RELAY_SID)) || (tagLen < (MAGIC_CODE_LEN + RTL_RELAY_TAG_LEN))) {
+ DEBUG_ERR("Invalid PTT_RELAY_SID tag length [%d]!\n", tagLen);
+ return -1;
+ }
+
+ pMagic = (__be16 *)tag->tag_data;
+ if (ntohs(*pMagic) != MAGIC_CODE) {
+ DEBUG_ERR("Can't find MAGIC_CODE in %s packet!\n",
+ (ph->code == PADO_CODE ? "PADO" : "PADS"));
+ return -1;
+ }
+
+ memcpy(skb->data, tag->tag_data + MAGIC_CODE_LEN, ETH_ALEN);
+
+ if (tagLen > MAGIC_CODE_LEN + RTL_RELAY_TAG_LEN)
+ offset = TAG_HDR_LEN;
+
+ if (skb_pull_and_merge(skb, ptr + offset, TAG_HDR_LEN + MAGIC_CODE_LEN + RTL_RELAY_TAG_LEN - offset) < 0) {
+ DEBUG_ERR("call skb_pull_and_merge() failed in PADO packet!\n");
+ return -1;
+ }
+ ph->length = htons(ntohs(ph->length) - (TAG_HDR_LEN + MAGIC_CODE_LEN + RTL_RELAY_TAG_LEN - offset));
+ if (offset > 0)
+ tag->tag_len = htons(tagLen - MAGIC_CODE_LEN - RTL_RELAY_TAG_LEN);
+
+ RTW_INFO("NAT25: Lookup PPPoE, forward %s Packet from %s\n",
+ (ph->code == PADO_CODE ? "PADO" : "PADS"), skb->dev->name);
+ } else { /* not add relay tag */
+ if (!priv->pppoe_connection_in_progress) {
+ DEBUG_ERR("Discard PPPoE packet due to no connection in progresss!\n");
+ return -1;
+ }
+ memcpy(skb->data, priv->pppoe_addr, ETH_ALEN);
+ priv->pppoe_connection_in_progress = WAIT_TIME_PPPOE;
+ }
+ } else {
+ if (ph->sid != 0) {
+ RTW_INFO("NAT25: Lookup PPPoE, lookup session packet from %s\n", skb->dev->name);
+ __nat25_generate_pppoe_network_addr(networkAddr, skb->data + ETH_ALEN, &(ph->sid));
+
+ __nat25_db_network_lookup_and_replace(priv, skb, networkAddr);
+
+ __nat25_db_print(priv);
+ } else
+ return -1;
+
+ }
+ return 0;
+
+ default:
+ return -1;
+ }
+ }
+
+ /*---------------------------------------------------*/
+ /* Handle EAP frame */
+ /*---------------------------------------------------*/
+ else if (protocol == __constant_htons(0x888e)) {
+ switch (method) {
+ case NAT25_CHECK:
+ return -1;
+
+ case NAT25_INSERT:
+ return 0;
+
+ case NAT25_LOOKUP:
+ return 0;
+
+ default:
+ return -1;
+ }
+ }
+
+ /*---------------------------------------------------*/
+ /* Handle C-Media proprietary frame */
+ /*---------------------------------------------------*/
+ else if ((protocol == __constant_htons(0xe2ae)) ||
+ (protocol == __constant_htons(0xe2af))) {
+ switch (method) {
+ case NAT25_CHECK:
+ return -1;
+
+ case NAT25_INSERT:
+ return 0;
+
+ case NAT25_LOOKUP:
+ return 0;
+
+ default:
+ return -1;
+ }
+ }
+
+ /*---------------------------------------------------*/
+ /* Handle IPV6 frame */
+ /*---------------------------------------------------*/
+#ifdef CL_IPV6_PASS
+ else if (protocol == __constant_htons(ETH_P_IPV6)) {
+ struct ipv6hdr *iph = (struct ipv6hdr *)(skb->data + ETH_HLEN);
+
+ if (sizeof(*iph) >= (skb->len - ETH_HLEN)) {
+ DEBUG_WARN("NAT25: malformed IPv6 packet !\n");
+ return -1;
+ }
+
+ switch (method) {
+ case NAT25_CHECK:
+ if (skb->data[0] & 1)
+ return 0;
+ return -1;
+
+ case NAT25_INSERT: {
+ RTW_INFO("NAT25: Insert IP, SA=%4x:%4x:%4x:%4x:%4x:%4x:%4x:%4x,"
+ " DA=%4x:%4x:%4x:%4x:%4x:%4x:%4x:%4x\n",
+ iph->saddr.s6_addr16[0], iph->saddr.s6_addr16[1], iph->saddr.s6_addr16[2], iph->saddr.s6_addr16[3],
+ iph->saddr.s6_addr16[4], iph->saddr.s6_addr16[5], iph->saddr.s6_addr16[6], iph->saddr.s6_addr16[7],
+ iph->daddr.s6_addr16[0], iph->daddr.s6_addr16[1], iph->daddr.s6_addr16[2], iph->daddr.s6_addr16[3],
+ iph->daddr.s6_addr16[4], iph->daddr.s6_addr16[5], iph->daddr.s6_addr16[6], iph->daddr.s6_addr16[7]);
+
+ if (memcmp(&iph->saddr, "\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0", 16)) {
+ __nat25_generate_ipv6_network_addr(networkAddr, (unsigned int *)&iph->saddr);
+ __nat25_db_network_insert(priv, skb->data + ETH_ALEN, networkAddr);
+ __nat25_db_print(priv);
+
+ if (iph->nexthdr == IPPROTO_ICMPV6 &&
+ skb->len > (ETH_HLEN + sizeof(*iph) + 4)) {
+ if (update_nd_link_layer_addr(skb->data + ETH_HLEN + sizeof(*iph),
+ skb->len - ETH_HLEN - sizeof(*iph), GET_MY_HWADDR(priv))) {
+ struct icmp6hdr *hdr = (struct icmp6hdr *)(skb->data + ETH_HLEN + sizeof(*iph));
+ hdr->icmp6_cksum = 0;
+ hdr->icmp6_cksum = csum_ipv6_magic(&iph->saddr, &iph->daddr,
+ be16_to_cpu(iph->payload_len),
+ IPPROTO_ICMPV6,
+ csum_partial((__u8 *)hdr, be16_to_cpu(iph->payload_len), 0));
+ }
+ }
+ }
+ }
+ return 0;
+
+ case NAT25_LOOKUP:
+ RTW_INFO("NAT25: Lookup IP, SA=%4x:%4x:%4x:%4x:%4x:%4x:%4x:%4x,"
+ " DA=%4x:%4x:%4x:%4x:%4x:%4x:%4x:%4x\n",
+ iph->saddr.s6_addr16[0], iph->saddr.s6_addr16[1], iph->saddr.s6_addr16[2], iph->saddr.s6_addr16[3],
+ iph->saddr.s6_addr16[4], iph->saddr.s6_addr16[5], iph->saddr.s6_addr16[6], iph->saddr.s6_addr16[7],
+ iph->daddr.s6_addr16[0], iph->daddr.s6_addr16[1], iph->daddr.s6_addr16[2], iph->daddr.s6_addr16[3],
+ iph->daddr.s6_addr16[4], iph->daddr.s6_addr16[5], iph->daddr.s6_addr16[6], iph->daddr.s6_addr16[7]);
+
+
+ __nat25_generate_ipv6_network_addr(networkAddr, (unsigned int *)&iph->daddr);
+ if (!__nat25_db_network_lookup_and_replace(priv, skb, networkAddr)) {
+#ifdef SUPPORT_RX_UNI2MCAST
+ if (iph->daddr.s6_addr[0] == 0xff)
+ convert_ipv6_mac_to_mc(skb);
+#endif
+ }
+ return 0;
+
+ default:
+ return -1;
+ }
+ }
+#endif /* CL_IPV6_PASS */
+
+ return -1;
+}
+
+
+int nat25_handle_frame(_adapter *priv, struct sk_buff *skb)
+{
+#ifdef BR_EXT_DEBUG
+ if ((!priv->ethBrExtInfo.nat25_disable) && (!(skb->data[0] & 1))) {
+ panic_RTW_INFO("NAT25: Input Frame: DA=%02x%02x%02x%02x%02x%02x SA=%02x%02x%02x%02x%02x%02x\n",
+ skb->data[0],
+ skb->data[1],
+ skb->data[2],
+ skb->data[3],
+ skb->data[4],
+ skb->data[5],
+ skb->data[6],
+ skb->data[7],
+ skb->data[8],
+ skb->data[9],
+ skb->data[10],
+ skb->data[11]);
+ }
+#endif
+
+ if (!(skb->data[0] & 1)) {
+ int is_vlan_tag = 0, i, retval = 0;
+ unsigned short vlan_hdr = 0;
+
+ if (*((__be16 *)(skb->data + ETH_ALEN * 2)) == __constant_htons(ETH_P_8021Q)) {
+ is_vlan_tag = 1;
+ vlan_hdr = *((unsigned short *)(skb->data + ETH_ALEN * 2 + 2));
+ for (i = 0; i < 6; i++)
+ *((unsigned short *)(skb->data + ETH_ALEN * 2 + 2 - i * 2)) = *((unsigned short *)(skb->data + ETH_ALEN * 2 - 2 - i * 2));
+ skb_pull(skb, 4);
+ }
+
+ if (!priv->ethBrExtInfo.nat25_disable) {
+ unsigned long irqL;
+ _enter_critical_bh(&priv->br_ext_lock, &irqL);
+ /*
+ * This function look up the destination network address from
+ * the NAT2.5 database. Return value = -1 means that the
+ * corresponding network protocol is NOT support.
+ */
+ if (!priv->ethBrExtInfo.nat25sc_disable &&
+ (*((__be16 *)(skb->data + ETH_ALEN * 2)) == __constant_htons(ETH_P_IP)) &&
+ !memcmp(priv->scdb_ip, skb->data + ETH_HLEN + 16, 4)) {
+ memcpy(skb->data, priv->scdb_mac, ETH_ALEN);
+
+ _exit_critical_bh(&priv->br_ext_lock, &irqL);
+ } else {
+ _exit_critical_bh(&priv->br_ext_lock, &irqL);
+
+ retval = nat25_db_handle(priv, skb, NAT25_LOOKUP);
+ }
+ } else {
+ if (((*((__be16 *)(skb->data + ETH_ALEN * 2)) == __constant_htons(ETH_P_IP)) &&
+ !memcmp(priv->br_ip, skb->data + ETH_HLEN + 16, 4)) ||
+ ((*((__be16 *)(skb->data + ETH_ALEN * 2)) == __constant_htons(ETH_P_ARP)) &&
+ !memcmp(priv->br_ip, skb->data + ETH_HLEN + 24, 4))) {
+ /* for traffic to upper TCP/IP */
+ retval = nat25_db_handle(priv, skb, NAT25_LOOKUP);
+ }
+ }
+
+ if (is_vlan_tag) {
+ skb_push(skb, 4);
+ for (i = 0; i < 6; i++)
+ *((__be16 *)(skb->data + i * 2)) = *((__be16 *)(skb->data + 4 + i * 2));
+ *((__be16 *)(skb->data + ETH_ALEN * 2)) = __constant_htons(ETH_P_8021Q);
+ *((u16 *)(skb->data + ETH_ALEN * 2 + 2)) = vlan_hdr;
+ }
+
+ if (retval == -1) {
+ /* DEBUG_ERR("NAT25: Lookup fail!\n"); */
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+#define SERVER_PORT 67
+#define CLIENT_PORT 68
+#define DHCP_MAGIC 0x63825363
+#define BROADCAST_FLAG 0x8000
+
+struct dhcpMessage {
+ u_int8_t op;
+ u_int8_t htype;
+ u_int8_t hlen;
+ u_int8_t hops;
+ u_int32_t xid;
+ u_int16_t secs;
+ u_int16_t flags;
+ u_int32_t ciaddr;
+ u_int32_t yiaddr;
+ u_int32_t siaddr;
+ u_int32_t giaddr;
+ u_int8_t chaddr[16];
+ u_int8_t sname[64];
+ u_int8_t file[128];
+ u_int32_t cookie;
+ u_int8_t options[308]; /* 312 - cookie */
+};
+
+void dhcp_flag_bcast(_adapter *priv, struct sk_buff *skb)
+{
+ if (!skb)
+ return;
+
+ if (!priv->ethBrExtInfo.dhcp_bcst_disable) {
+ __be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
+
+ if (protocol == __constant_htons(ETH_P_IP)) { /* IP */
+ struct iphdr *iph = (struct iphdr *)(skb->data + ETH_HLEN);
+
+ if (iph->protocol == IPPROTO_UDP) { /* UDP */
+ struct udphdr *udph = (struct udphdr *)((SIZE_PTR)iph + (iph->ihl << 2));
+
+ if ((udph->source == __constant_htons(CLIENT_PORT))
+ && (udph->dest == __constant_htons(SERVER_PORT))) { /* DHCP request */
+ struct dhcpMessage *dhcph =
+ (struct dhcpMessage *)((SIZE_PTR)udph + sizeof(struct udphdr));
+
+ if (dhcph->cookie == DHCP_MAGIC) { /* match magic word */
+ if (!(dhcph->flags & BROADCAST_FLAG)) { /* if not broadcast */
+ register int sum = 0;
+
+ RTW_INFO("DHCP: change flag of DHCP request to broadcast.\n");
+ /* or BROADCAST flag */
+ dhcph->flags |= BROADCAST_FLAG;
+ /* recalculate checksum */
+ sum = ~(udph->check) & 0xffff;
+ sum += dhcph->flags;
+ while (sum >> 16)
+ sum = (sum & 0xffff) + (sum >> 16);
+ udph->check = ~sum;
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+void *scdb_findEntry(_adapter *priv, unsigned char *macAddr,
+ unsigned char *ipAddr)
+{
+ unsigned char networkAddr[MAX_NETWORK_ADDR_LEN];
+ struct nat25_network_db_entry *db;
+ int hash;
+ /* unsigned long irqL; */
+ /* _enter_critical_bh(&priv->br_ext_lock, &irqL); */
+
+ __nat25_generate_ipv4_network_addr(networkAddr, (unsigned int *)ipAddr);
+ hash = __nat25_network_hash(networkAddr);
+ db = priv->nethash[hash];
+ while (db != NULL) {
+ if (!memcmp(db->networkAddr, networkAddr, MAX_NETWORK_ADDR_LEN)) {
+ /* _exit_critical_bh(&priv->br_ext_lock, &irqL); */
+ return (void *)db;
+ }
+
+ db = db->next_hash;
+ }
+
+ /* _exit_critical_bh(&priv->br_ext_lock, &irqL); */
+ return NULL;
+}
+
+#endif /* CONFIG_BR_EXT */
diff --git a/drivers/staging/rtl8188eu/core/rtw_btcoex.c b/drivers/staging/rtl8188eu/core/rtw_btcoex.c
new file mode 100644
index 000000000000..f1a2f195fb98
--- /dev/null
+++ b/drivers/staging/rtl8188eu/core/rtw_btcoex.c
@@ -0,0 +1,1632 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved. */
+
+#ifdef CONFIG_BT_COEXIST
+
+#include <drv_types.h>
+#include <hal_btcoex.h>
+#include <hal_data.h>
+
+
+void rtw_btcoex_Initialize(PADAPTER padapter)
+{
+ hal_btcoex_Initialize(padapter);
+}
+
+void rtw_btcoex_PowerOnSetting(PADAPTER padapter)
+{
+ hal_btcoex_PowerOnSetting(padapter);
+}
+
+void rtw_btcoex_PreLoadFirmware(PADAPTER padapter)
+{
+ hal_btcoex_PreLoadFirmware(padapter);
+}
+
+void rtw_btcoex_HAL_Initialize(PADAPTER padapter, u8 bWifiOnly)
+{
+ hal_btcoex_InitHwConfig(padapter, bWifiOnly);
+}
+
+void rtw_btcoex_IpsNotify(PADAPTER padapter, u8 type)
+{
+ PHAL_DATA_TYPE pHalData;
+
+ pHalData = GET_HAL_DATA(padapter);
+ if (false == pHalData->EEPROMBluetoothCoexist)
+ return;
+
+ hal_btcoex_IpsNotify(padapter, type);
+}
+
+void rtw_btcoex_LpsNotify(PADAPTER padapter, u8 type)
+{
+ PHAL_DATA_TYPE pHalData;
+
+ pHalData = GET_HAL_DATA(padapter);
+ if (false == pHalData->EEPROMBluetoothCoexist)
+ return;
+
+ hal_btcoex_LpsNotify(padapter, type);
+}
+
+void rtw_btcoex_ScanNotify(PADAPTER padapter, u8 type)
+{
+ PHAL_DATA_TYPE pHalData;
+#ifdef CONFIG_BT_COEXIST_SOCKET_TRX
+ struct bt_coex_info *pcoex_info = &padapter->coex_info;
+ PBT_MGNT pBtMgnt = &pcoex_info->BtMgnt;
+#endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
+
+ pHalData = GET_HAL_DATA(padapter);
+ if (false == pHalData->EEPROMBluetoothCoexist)
+ return;
+
+ if (false == type) {
+ #ifdef CONFIG_CONCURRENT_MODE
+ if (rtw_mi_buddy_check_fwstate(padapter, WIFI_SITE_MONITOR))
+ return;
+ #endif
+
+ if (DEV_MGMT_TX_NUM(adapter_to_dvobj(padapter))
+ || DEV_ROCH_NUM(adapter_to_dvobj(padapter)))
+ return;
+ }
+
+#ifdef CONFIG_BT_COEXIST_SOCKET_TRX
+ if (pBtMgnt->ExtConfig.bEnableWifiScanNotify)
+ rtw_btcoex_SendScanNotify(padapter, type);
+#endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
+
+ hal_btcoex_ScanNotify(padapter, type);
+}
+
+void rtw_btcoex_ConnectNotify(PADAPTER padapter, u8 action)
+{
+ PHAL_DATA_TYPE pHalData;
+
+ pHalData = GET_HAL_DATA(padapter);
+ if (false == pHalData->EEPROMBluetoothCoexist)
+ return;
+
+#ifdef DBG_CONFIG_ERROR_RESET
+ if (rtw_hal_sreset_inprogress(padapter)) {
+ RTW_INFO(FUNC_ADPT_FMT ": [BTCoex] under reset, skip notify!\n",
+ FUNC_ADPT_ARG(padapter));
+ return;
+ }
+#endif /* DBG_CONFIG_ERROR_RESET */
+
+#ifdef CONFIG_CONCURRENT_MODE
+ if (false == action) {
+ if (rtw_mi_buddy_check_fwstate(padapter, WIFI_UNDER_LINKING))
+ return;
+ }
+#endif
+
+ hal_btcoex_ConnectNotify(padapter, action);
+}
+
+void rtw_btcoex_MediaStatusNotify(PADAPTER padapter, u8 mediaStatus)
+{
+ PHAL_DATA_TYPE pHalData;
+
+ pHalData = GET_HAL_DATA(padapter);
+ if (false == pHalData->EEPROMBluetoothCoexist)
+ return;
+
+#ifdef DBG_CONFIG_ERROR_RESET
+ if (rtw_hal_sreset_inprogress(padapter)) {
+ RTW_INFO(FUNC_ADPT_FMT ": [BTCoex] under reset, skip notify!\n",
+ FUNC_ADPT_ARG(padapter));
+ return;
+ }
+#endif /* DBG_CONFIG_ERROR_RESET */
+
+#ifdef CONFIG_CONCURRENT_MODE
+ if (RT_MEDIA_DISCONNECT == mediaStatus) {
+ if (rtw_mi_buddy_check_fwstate(padapter, WIFI_ASOC_STATE))
+ return;
+ }
+#endif /* CONFIG_CONCURRENT_MODE */
+
+ if ((RT_MEDIA_CONNECT == mediaStatus)
+ && (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE) == true))
+ rtw_hal_set_hwreg(padapter, HW_VAR_DL_RSVD_PAGE, NULL);
+
+ hal_btcoex_MediaStatusNotify(padapter, mediaStatus);
+}
+
+void rtw_btcoex_SpecialPacketNotify(PADAPTER padapter, u8 pktType)
+{
+ PHAL_DATA_TYPE pHalData;
+
+ pHalData = GET_HAL_DATA(padapter);
+ if (false == pHalData->EEPROMBluetoothCoexist)
+ return;
+
+ hal_btcoex_SpecialPacketNotify(padapter, pktType);
+}
+
+void rtw_btcoex_IQKNotify(PADAPTER padapter, u8 state)
+{
+ PHAL_DATA_TYPE pHalData;
+
+ pHalData = GET_HAL_DATA(padapter);
+ if (false == pHalData->EEPROMBluetoothCoexist)
+ return;
+
+ hal_btcoex_IQKNotify(padapter, state);
+}
+
+void rtw_btcoex_BtInfoNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
+{
+ PHAL_DATA_TYPE pHalData;
+
+ pHalData = GET_HAL_DATA(padapter);
+ if (false == pHalData->EEPROMBluetoothCoexist)
+ return;
+
+ hal_btcoex_BtInfoNotify(padapter, length, tmpBuf);
+}
+
+void rtw_btcoex_BtMpRptNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
+{
+ PHAL_DATA_TYPE pHalData;
+
+ pHalData = GET_HAL_DATA(padapter);
+ if (false == pHalData->EEPROMBluetoothCoexist)
+ return;
+
+ if (padapter->registrypriv.mp_mode == 1)
+ return;
+
+ hal_btcoex_BtMpRptNotify(padapter, length, tmpBuf);
+}
+
+void rtw_btcoex_SuspendNotify(PADAPTER padapter, u8 state)
+{
+ PHAL_DATA_TYPE pHalData;
+
+ pHalData = GET_HAL_DATA(padapter);
+ if (false == pHalData->EEPROMBluetoothCoexist)
+ return;
+
+ hal_btcoex_SuspendNotify(padapter, state);
+}
+
+void rtw_btcoex_HaltNotify(PADAPTER padapter)
+{
+ PHAL_DATA_TYPE pHalData;
+ u8 do_halt = 1;
+
+ pHalData = GET_HAL_DATA(padapter);
+ if (false == pHalData->EEPROMBluetoothCoexist)
+ do_halt = 0;
+
+ if (false == padapter->bup) {
+ RTW_INFO(FUNC_ADPT_FMT ": bup=%d Skip!\n",
+ FUNC_ADPT_ARG(padapter), padapter->bup);
+ do_halt = 0;
+ }
+
+ if (rtw_is_surprise_removed(padapter)) {
+ RTW_INFO(FUNC_ADPT_FMT ": bSurpriseRemoved=%s Skip!\n",
+ FUNC_ADPT_ARG(padapter), rtw_is_surprise_removed(padapter) ? "True" : "False");
+ do_halt = 0;
+ }
+
+ hal_btcoex_HaltNotify(padapter, do_halt);
+}
+
+void rtw_btcoex_switchband_notify(u8 under_scan, u8 band_type)
+{
+ hal_btcoex_switchband_notify(under_scan, band_type);
+}
+
+void rtw_btcoex_SwitchBtTRxMask(PADAPTER padapter)
+{
+ hal_btcoex_SwitchBtTRxMask(padapter);
+}
+
+void rtw_btcoex_Switch(PADAPTER padapter, u8 enable)
+{
+ hal_btcoex_SetBTCoexist(padapter, enable);
+}
+
+u8 rtw_btcoex_IsBtDisabled(PADAPTER padapter)
+{
+ return hal_btcoex_IsBtDisabled(padapter);
+}
+
+void rtw_btcoex_Handler(PADAPTER padapter)
+{
+ PHAL_DATA_TYPE pHalData;
+
+ pHalData = GET_HAL_DATA(padapter);
+
+ if (false == pHalData->EEPROMBluetoothCoexist)
+ return;
+
+ hal_btcoex_Hanlder(padapter);
+}
+
+s32 rtw_btcoex_IsBTCoexRejectAMPDU(PADAPTER padapter)
+{
+ s32 coexctrl;
+
+ coexctrl = hal_btcoex_IsBTCoexRejectAMPDU(padapter);
+
+ return coexctrl;
+}
+
+s32 rtw_btcoex_IsBTCoexCtrlAMPDUSize(PADAPTER padapter)
+{
+ s32 coexctrl;
+
+ coexctrl = hal_btcoex_IsBTCoexCtrlAMPDUSize(padapter);
+
+ return coexctrl;
+}
+
+u32 rtw_btcoex_GetAMPDUSize(PADAPTER padapter)
+{
+ u32 size;
+
+ size = hal_btcoex_GetAMPDUSize(padapter);
+
+ return size;
+}
+
+void rtw_btcoex_SetManualControl(PADAPTER padapter, u8 manual)
+{
+ if (manual)
+ hal_btcoex_SetManualControl(padapter, true);
+ else
+ hal_btcoex_SetManualControl(padapter, false);
+}
+
+u8 rtw_btcoex_1Ant(PADAPTER padapter)
+{
+ return hal_btcoex_1Ant(padapter);
+}
+
+u8 rtw_btcoex_IsBtControlLps(PADAPTER padapter)
+{
+ return hal_btcoex_IsBtControlLps(padapter);
+}
+
+u8 rtw_btcoex_IsLpsOn(PADAPTER padapter)
+{
+ return hal_btcoex_IsLpsOn(padapter);
+}
+
+u8 rtw_btcoex_RpwmVal(PADAPTER padapter)
+{
+ return hal_btcoex_RpwmVal(padapter);
+}
+
+u8 rtw_btcoex_LpsVal(PADAPTER padapter)
+{
+ return hal_btcoex_LpsVal(padapter);
+}
+
+u32 rtw_btcoex_GetRaMask(PADAPTER padapter)
+{
+ return hal_btcoex_GetRaMask(padapter);
+}
+
+void rtw_btcoex_RecordPwrMode(PADAPTER padapter, u8 *pCmdBuf, u8 cmdLen)
+{
+ hal_btcoex_RecordPwrMode(padapter, pCmdBuf, cmdLen);
+}
+
+void rtw_btcoex_DisplayBtCoexInfo(PADAPTER padapter, u8 *pbuf, u32 bufsize)
+{
+ hal_btcoex_DisplayBtCoexInfo(padapter, pbuf, bufsize);
+}
+
+void rtw_btcoex_SetDBG(PADAPTER padapter, u32 *pDbgModule)
+{
+ hal_btcoex_SetDBG(padapter, pDbgModule);
+}
+
+u32 rtw_btcoex_GetDBG(PADAPTER padapter, u8 *pStrBuf, u32 bufSize)
+{
+ return hal_btcoex_GetDBG(padapter, pStrBuf, bufSize);
+}
+
+u8 rtw_btcoex_IncreaseScanDeviceNum(PADAPTER padapter)
+{
+ return hal_btcoex_IncreaseScanDeviceNum(padapter);
+}
+
+u8 rtw_btcoex_IsBtLinkExist(PADAPTER padapter)
+{
+ return hal_btcoex_IsBtLinkExist(padapter);
+}
+
+void rtw_btcoex_SetBtPatchVersion(PADAPTER padapter, u16 btHciVer, u16 btPatchVer)
+{
+ hal_btcoex_SetBtPatchVersion(padapter, btHciVer, btPatchVer);
+}
+
+void rtw_btcoex_SetHciVersion(PADAPTER padapter, u16 hciVersion)
+{
+ hal_btcoex_SetHciVersion(padapter, hciVersion);
+}
+
+void rtw_btcoex_StackUpdateProfileInfo(void)
+{
+ hal_btcoex_StackUpdateProfileInfo();
+}
+
+void rtw_btcoex_pta_off_on_notify(PADAPTER padapter, u8 bBTON)
+{
+ hal_btcoex_pta_off_on_notify(padapter, bBTON);
+}
+
+/* ==================================================
+ * Below Functions are called by BT-Coex
+ * ================================================== */
+void rtw_btcoex_rx_ampdu_apply(PADAPTER padapter)
+{
+ rtw_rx_ampdu_apply(padapter);
+}
+
+void rtw_btcoex_LPS_Enter(PADAPTER padapter)
+{
+ struct pwrctrl_priv *pwrpriv;
+ u8 lpsVal;
+
+
+ pwrpriv = adapter_to_pwrctl(padapter);
+
+ pwrpriv->bpower_saving = true;
+ lpsVal = rtw_btcoex_LpsVal(padapter);
+ rtw_set_ps_mode(padapter, PS_MODE_MIN, 0, lpsVal, "BTCOEX");
+}
+
+void rtw_btcoex_LPS_Leave(PADAPTER padapter)
+{
+ struct pwrctrl_priv *pwrpriv;
+
+
+ pwrpriv = adapter_to_pwrctl(padapter);
+
+ if (pwrpriv->pwr_mode != PS_MODE_ACTIVE) {
+ rtw_set_ps_mode(padapter, PS_MODE_ACTIVE, 0, 0, "BTCOEX");
+ LPS_RF_ON_check(padapter, 100);
+ pwrpriv->bpower_saving = false;
+ }
+}
+
+u16 rtw_btcoex_btreg_read(PADAPTER padapter, u8 type, u16 addr, u32 *data)
+{
+ return hal_btcoex_btreg_read(padapter, type, addr, data);
+}
+
+u16 rtw_btcoex_btreg_write(PADAPTER padapter, u8 type, u16 addr, u16 val)
+{
+ return hal_btcoex_btreg_write(padapter, type, addr, val);
+}
+
+u8 rtw_btcoex_get_bt_coexist(PADAPTER padapter)
+{
+ HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
+
+ return pHalData->EEPROMBluetoothCoexist;
+}
+
+u8 rtw_btcoex_get_chip_type(PADAPTER padapter)
+{
+ HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
+
+ return pHalData->EEPROMBluetoothType;
+}
+
+u8 rtw_btcoex_get_pg_ant_num(PADAPTER padapter)
+{
+ HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
+
+ return pHalData->EEPROMBluetoothAntNum == Ant_x2 ? 2 : 1;
+}
+
+u8 rtw_btcoex_get_pg_single_ant_path(PADAPTER padapter)
+{
+ HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
+
+ return pHalData->ant_path;
+}
+
+u8 rtw_btcoex_get_pg_rfe_type(PADAPTER padapter)
+{
+ HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
+
+ return pHalData->rfe_type;
+}
+
+u8 rtw_btcoex_is_tfbga_package_type(PADAPTER padapter)
+{
+ return false;
+}
+
+u8 rtw_btcoex_get_ant_div_cfg(PADAPTER padapter)
+{
+ PHAL_DATA_TYPE pHalData;
+
+ pHalData = GET_HAL_DATA(padapter);
+
+ return (pHalData->AntDivCfg == 0) ? false : true;
+}
+
+/* ==================================================
+ * Below Functions are BT-Coex socket related function
+ * ================================================== */
+
+#ifdef CONFIG_BT_COEXIST_SOCKET_TRX
+_adapter *pbtcoexadapter; /* = NULL; */ /* do not initialise globals to 0 or NULL */
+u8 rtw_btcoex_btinfo_cmd(_adapter *adapter, u8 *buf, u16 len)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ u8 *btinfo;
+ struct cmd_priv *pcmdpriv = &adapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (ph2c == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (pdrvextra_cmd_parm == NULL) {
+ rtw_mfree((u8 *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ btinfo = rtw_zmalloc(len);
+ if (btinfo == NULL) {
+ rtw_mfree((u8 *)ph2c, sizeof(struct cmd_obj));
+ rtw_mfree((u8 *)pdrvextra_cmd_parm, sizeof(struct drvextra_cmd_parm));
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm->ec_id = BTINFO_WK_CID;
+ pdrvextra_cmd_parm->type = 0;
+ pdrvextra_cmd_parm->size = len;
+ pdrvextra_cmd_parm->pbuf = btinfo;
+
+ memcpy(btinfo, buf, len);
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+ return res;
+}
+
+u8 rtw_btcoex_send_event_to_BT(_adapter *padapter, u8 status, u8 event_code, u8 opcode_low, u8 opcode_high, u8 *dbg_msg)
+{
+ u8 localBuf[6] = "";
+ u8 *pRetPar;
+ u8 len = 0, tx_event_length = 0;
+ rtw_HCI_event *pEvent;
+
+ pEvent = (rtw_HCI_event *)(&localBuf[0]);
+
+ pEvent->EventCode = event_code;
+ pEvent->Data[0] = 0x1; /* packet # */
+ pEvent->Data[1] = opcode_low;
+ pEvent->Data[2] = opcode_high;
+ len = len + 3;
+
+ /* Return parameters starts from here */
+ pRetPar = &pEvent->Data[len];
+ pRetPar[0] = status; /* status */
+
+ len++;
+ pEvent->Length = len;
+
+ /* total tx event length + EventCode length + sizeof(length) */
+ tx_event_length = pEvent->Length + 2;
+ status = rtw_btcoex_sendmsgbysocket(padapter, (u8 *)pEvent, tx_event_length, false);
+
+ return status;
+}
+
+/*
+Ref:
+Realtek Wi-Fi Driver
+Host Controller Interface for
+Bluetooth 3.0 + HS V1.4 2013/02/07
+
+Window team code & BT team code
+ */
+
+
+u8 rtw_btcoex_parse_BT_info_notify_cmd(_adapter *padapter, u8 *pcmd, u16 cmdlen)
+{
+#define BT_INFO_LENGTH 8
+
+ u8 curPollEnable = pcmd[0];
+ u8 curPollTime = pcmd[1];
+ u8 btInfoReason = pcmd[2];
+ u8 btInfoLen = pcmd[3];
+ u8 btinfo[BT_INFO_LENGTH];
+
+ u8 localBuf[6] = "";
+ u8 *pRetPar;
+ u8 len = 0, tx_event_length = 0;
+ RTW_HCI_STATUS status = HCI_STATUS_SUCCESS;
+ rtw_HCI_event *pEvent;
+
+ /* RTW_INFO("%s\n",__func__);
+ RTW_INFO("current Poll Enable: %d, currrent Poll Time: %d\n",curPollEnable,curPollTime);
+ RTW_INFO("BT Info reason: %d, BT Info length: %d\n",btInfoReason,btInfoLen);
+ RTW_INFO("%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n"
+ ,pcmd[4],pcmd[5],pcmd[6],pcmd[7],pcmd[8],pcmd[9],pcmd[10],pcmd[11]);*/
+
+ memset(btinfo, 0, BT_INFO_LENGTH);
+
+ if (BT_INFO_LENGTH != btInfoLen) {
+ status = HCI_STATUS_INVALID_HCI_CMD_PARA_VALUE;
+ RTW_INFO("Error BT Info Length: %d\n", btInfoLen);
+ /* return _FAIL; */
+ } else {
+ if (0x1 == btInfoReason || 0x2 == btInfoReason) {
+ memcpy(btinfo, &pcmd[4], btInfoLen);
+ btinfo[0] = btInfoReason;
+ rtw_btcoex_btinfo_cmd(padapter, btinfo, btInfoLen);
+ } else
+ RTW_INFO("Other BT info reason\n");
+ }
+
+ /* send complete event to BT */
+ {
+
+ pEvent = (rtw_HCI_event *)(&localBuf[0]);
+
+ pEvent->EventCode = HCI_EVENT_COMMAND_COMPLETE;
+ pEvent->Data[0] = 0x1; /* packet # */
+ pEvent->Data[1] = HCIOPCODELOW(HCI_BT_INFO_NOTIFY, OGF_EXTENSION);
+ pEvent->Data[2] = HCIOPCODEHIGHT(HCI_BT_INFO_NOTIFY, OGF_EXTENSION);
+ len = len + 3;
+
+ /* Return parameters starts from here */
+ pRetPar = &pEvent->Data[len];
+ pRetPar[0] = status; /* status */
+
+ len++;
+ pEvent->Length = len;
+
+ /* total tx event length + EventCode length + sizeof(length) */
+ tx_event_length = pEvent->Length + 2;
+ status = rtw_btcoex_sendmsgbysocket(padapter, (u8 *)pEvent, tx_event_length, false);
+
+ return status;
+ /* bthci_IndicateEvent(Adapter, PPacketIrpEvent, len+2); */
+ }
+}
+
+u8 rtw_btcoex_parse_BT_patch_ver_info_cmd(_adapter *padapter, u8 *pcmd, u16 cmdlen)
+{
+ RTW_HCI_STATUS status = HCI_STATUS_SUCCESS;
+ u16 btPatchVer = 0x0, btHciVer = 0x0;
+ /* u16 *pU2tmp; */
+
+ u8 localBuf[6] = "";
+ u8 *pRetPar;
+ u8 len = 0, tx_event_length = 0;
+ rtw_HCI_event *pEvent;
+
+ btHciVer = pcmd[0] | pcmd[1] << 8;
+ btPatchVer = pcmd[2] | pcmd[3] << 8;
+
+
+ RTW_INFO("%s, cmd:%02x %02x %02x %02x\n", __func__, pcmd[0] , pcmd[1] , pcmd[2] , pcmd[3]);
+ RTW_INFO("%s, HCI Ver:%d, Patch Ver:%d\n", __func__, btHciVer, btPatchVer);
+
+ rtw_btcoex_SetBtPatchVersion(padapter, btHciVer, btPatchVer);
+
+
+ /* send complete event to BT */
+ {
+ pEvent = (rtw_HCI_event *)(&localBuf[0]);
+
+
+ pEvent->EventCode = HCI_EVENT_COMMAND_COMPLETE;
+ pEvent->Data[0] = 0x1; /* packet # */
+ pEvent->Data[1] = HCIOPCODELOW(HCI_BT_PATCH_VERSION_NOTIFY, OGF_EXTENSION);
+ pEvent->Data[2] = HCIOPCODEHIGHT(HCI_BT_PATCH_VERSION_NOTIFY, OGF_EXTENSION);
+ len = len + 3;
+
+ /* Return parameters starts from here */
+ pRetPar = &pEvent->Data[len];
+ pRetPar[0] = status; /* status */
+
+ len++;
+ pEvent->Length = len;
+
+ /* total tx event length + EventCode length + sizeof(length) */
+ tx_event_length = pEvent->Length + 2;
+ status = rtw_btcoex_sendmsgbysocket(padapter, (u8 *)pEvent, tx_event_length, false);
+ return status;
+ /* bthci_IndicateEvent(Adapter, PPacketIrpEvent, len+2); */
+ }
+}
+
+u8 rtw_btcoex_parse_HCI_Ver_notify_cmd(_adapter *padapter, u8 *pcmd, u16 cmdlen)
+{
+ RTW_HCI_STATUS status = HCI_STATUS_SUCCESS;
+ u16 hciver = pcmd[0] | pcmd[1] << 8;
+
+ u8 localBuf[6] = "";
+ u8 *pRetPar;
+ u8 len = 0, tx_event_length = 0;
+ rtw_HCI_event *pEvent;
+
+ struct bt_coex_info *pcoex_info = &padapter->coex_info;
+ PBT_MGNT pBtMgnt = &pcoex_info->BtMgnt;
+ pBtMgnt->ExtConfig.HCIExtensionVer = hciver;
+ RTW_INFO("%s, HCI Version: %d\n", __func__, pBtMgnt->ExtConfig.HCIExtensionVer);
+ if (pBtMgnt->ExtConfig.HCIExtensionVer < 4) {
+ status = HCI_STATUS_INVALID_HCI_CMD_PARA_VALUE;
+ RTW_INFO("%s, Version = %d, HCI Version < 4\n", __func__, pBtMgnt->ExtConfig.HCIExtensionVer);
+ } else
+ rtw_btcoex_SetHciVersion(padapter, hciver);
+ /* send complete event to BT */
+ {
+ pEvent = (rtw_HCI_event *)(&localBuf[0]);
+
+
+ pEvent->EventCode = HCI_EVENT_COMMAND_COMPLETE;
+ pEvent->Data[0] = 0x1; /* packet # */
+ pEvent->Data[1] = HCIOPCODELOW(HCI_EXTENSION_VERSION_NOTIFY, OGF_EXTENSION);
+ pEvent->Data[2] = HCIOPCODEHIGHT(HCI_EXTENSION_VERSION_NOTIFY, OGF_EXTENSION);
+ len = len + 3;
+
+ /* Return parameters starts from here */
+ pRetPar = &pEvent->Data[len];
+ pRetPar[0] = status; /* status */
+
+ len++;
+ pEvent->Length = len;
+
+ /* total tx event length + EventCode length + sizeof(length) */
+ tx_event_length = pEvent->Length + 2;
+
+ status = rtw_btcoex_sendmsgbysocket(padapter, (u8 *)pEvent, tx_event_length, false);
+ return status;
+ /* bthci_IndicateEvent(Adapter, PPacketIrpEvent, len+2); */
+ }
+
+}
+
+u8 rtw_btcoex_parse_WIFI_scan_notify_cmd(_adapter *padapter, u8 *pcmd, u16 cmdlen)
+{
+ RTW_HCI_STATUS status = HCI_STATUS_SUCCESS;
+
+ u8 localBuf[6] = "";
+ u8 *pRetPar;
+ u8 len = 0, tx_event_length = 0;
+ rtw_HCI_event *pEvent;
+
+ struct bt_coex_info *pcoex_info = &padapter->coex_info;
+ PBT_MGNT pBtMgnt = &pcoex_info->BtMgnt;
+ pBtMgnt->ExtConfig.bEnableWifiScanNotify = pcmd[0];
+ RTW_INFO("%s, bEnableWifiScanNotify: %d\n", __func__, pBtMgnt->ExtConfig.bEnableWifiScanNotify);
+
+ /* send complete event to BT */
+ {
+ pEvent = (rtw_HCI_event *)(&localBuf[0]);
+
+
+ pEvent->EventCode = HCI_EVENT_COMMAND_COMPLETE;
+ pEvent->Data[0] = 0x1; /* packet # */
+ pEvent->Data[1] = HCIOPCODELOW(HCI_ENABLE_WIFI_SCAN_NOTIFY, OGF_EXTENSION);
+ pEvent->Data[2] = HCIOPCODEHIGHT(HCI_ENABLE_WIFI_SCAN_NOTIFY, OGF_EXTENSION);
+ len = len + 3;
+
+ /* Return parameters starts from here */
+ pRetPar = &pEvent->Data[len];
+ pRetPar[0] = status; /* status */
+
+ len++;
+ pEvent->Length = len;
+
+ /* total tx event length + EventCode length + sizeof(length) */
+ tx_event_length = pEvent->Length + 2;
+
+ status = rtw_btcoex_sendmsgbysocket(padapter, (u8 *)pEvent, tx_event_length, false);
+ return status;
+ /* bthci_IndicateEvent(Adapter, PPacketIrpEvent, len+2); */
+ }
+}
+
+u8 rtw_btcoex_parse_HCI_link_status_notify_cmd(_adapter *padapter, u8 *pcmd, u16 cmdlen)
+{
+ RTW_HCI_STATUS status = HCI_STATUS_SUCCESS;
+ struct bt_coex_info *pcoex_info = &padapter->coex_info;
+ PBT_MGNT pBtMgnt = &pcoex_info->BtMgnt;
+ /* PBT_DBG pBtDbg=&padapter->MgntInfo.BtInfo.BtDbg; */
+ u8 i, numOfHandle = 0, numOfAcl = 0;
+ u16 conHandle;
+ u8 btProfile, btCoreSpec, linkRole;
+ u8 *pTriple;
+
+ u8 localBuf[6] = "";
+ u8 *pRetPar;
+ u8 len = 0, tx_event_length = 0;
+ rtw_HCI_event *pEvent;
+
+ /* pBtDbg->dbgHciInfo.hciCmdCntLinkStatusNotify++; */
+ /* RT_DISP_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "LinkStatusNotify, Hex Data :\n", */
+ /* &pHciCmd->Data[0], pHciCmd->Length); */
+
+ RTW_INFO("BTLinkStatusNotify\n");
+
+ /* Current only RTL8723 support this command. */
+ /* pBtMgnt->bSupportProfile = true; */
+ pBtMgnt->bSupportProfile = false;
+
+ pBtMgnt->ExtConfig.NumberOfACL = 0;
+ pBtMgnt->ExtConfig.NumberOfSCO = 0;
+
+ numOfHandle = pcmd[0];
+ /* RT_DISP(FIOCTL, IOCTL_BT_HCICMD_EXT, ("numOfHandle = 0x%x\n", numOfHandle)); */
+ /* RT_DISP(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCIExtensionVer = %d\n", pBtMgnt->ExtConfig.HCIExtensionVer)); */
+ RTW_INFO("numOfHandle = 0x%x\n", numOfHandle);
+ RTW_INFO("HCIExtensionVer = %d\n", pBtMgnt->ExtConfig.HCIExtensionVer);
+
+ pTriple = &pcmd[1];
+ for (i = 0; i < numOfHandle; i++) {
+ if (pBtMgnt->ExtConfig.HCIExtensionVer < 1) {
+ conHandle = *((u8 *)&pTriple[0]);
+ btProfile = pTriple[2];
+ btCoreSpec = pTriple[3];
+ if (BT_PROFILE_SCO == btProfile)
+ pBtMgnt->ExtConfig.NumberOfSCO++;
+ else {
+ pBtMgnt->ExtConfig.NumberOfACL++;
+ pBtMgnt->ExtConfig.aclLink[i].ConnectHandle = conHandle;
+ pBtMgnt->ExtConfig.aclLink[i].BTProfile = btProfile;
+ pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec = btCoreSpec;
+ }
+ /* RT_DISP(FIOCTL, IOCTL_BT_HCICMD_EXT, */
+ /* ("Connection_Handle=0x%x, BTProfile=%d, BTSpec=%d\n", */
+ /* conHandle, btProfile, btCoreSpec)); */
+ RTW_INFO("Connection_Handle=0x%x, BTProfile=%d, BTSpec=%d\n", conHandle, btProfile, btCoreSpec);
+ pTriple += 4;
+ } else if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
+ conHandle = *((u16 *)&pTriple[0]);
+ btProfile = pTriple[2];
+ btCoreSpec = pTriple[3];
+ linkRole = pTriple[4];
+ if (BT_PROFILE_SCO == btProfile)
+ pBtMgnt->ExtConfig.NumberOfSCO++;
+ else {
+ pBtMgnt->ExtConfig.NumberOfACL++;
+ pBtMgnt->ExtConfig.aclLink[i].ConnectHandle = conHandle;
+ pBtMgnt->ExtConfig.aclLink[i].BTProfile = btProfile;
+ pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec = btCoreSpec;
+ pBtMgnt->ExtConfig.aclLink[i].linkRole = linkRole;
+ }
+ /* RT_DISP(FIOCTL, IOCTL_BT_HCICMD_EXT, */
+ RTW_INFO("Connection_Handle=0x%x, BTProfile=%d, BTSpec=%d, LinkRole=%d\n",
+ conHandle, btProfile, btCoreSpec, linkRole);
+ pTriple += 5;
+ }
+ }
+ rtw_btcoex_StackUpdateProfileInfo();
+
+ /* send complete event to BT */
+ {
+ pEvent = (rtw_HCI_event *)(&localBuf[0]);
+
+
+ pEvent->EventCode = HCI_EVENT_COMMAND_COMPLETE;
+ pEvent->Data[0] = 0x1; /* packet # */
+ pEvent->Data[1] = HCIOPCODELOW(HCI_LINK_STATUS_NOTIFY, OGF_EXTENSION);
+ pEvent->Data[2] = HCIOPCODEHIGHT(HCI_LINK_STATUS_NOTIFY, OGF_EXTENSION);
+ len = len + 3;
+
+ /* Return parameters starts from here */
+ pRetPar = &pEvent->Data[len];
+ pRetPar[0] = status; /* status */
+
+ len++;
+ pEvent->Length = len;
+
+ /* total tx event length + EventCode length + sizeof(length) */
+ tx_event_length = pEvent->Length + 2;
+
+ status = rtw_btcoex_sendmsgbysocket(padapter, (u8 *)pEvent, tx_event_length, false);
+ return status;
+ /* bthci_IndicateEvent(Adapter, PPacketIrpEvent, len+2); */
+ }
+
+
+}
+
+u8 rtw_btcoex_parse_HCI_BT_coex_notify_cmd(_adapter *padapter, u8 *pcmd, u16 cmdlen)
+{
+ u8 localBuf[6] = "";
+ u8 *pRetPar;
+ u8 len = 0, tx_event_length = 0;
+ rtw_HCI_event *pEvent;
+ RTW_HCI_STATUS status = HCI_STATUS_SUCCESS;
+
+ {
+ pEvent = (rtw_HCI_event *)(&localBuf[0]);
+
+
+ pEvent->EventCode = HCI_EVENT_COMMAND_COMPLETE;
+ pEvent->Data[0] = 0x1; /* packet # */
+ pEvent->Data[1] = HCIOPCODELOW(HCI_BT_COEX_NOTIFY, OGF_EXTENSION);
+ pEvent->Data[2] = HCIOPCODEHIGHT(HCI_BT_COEX_NOTIFY, OGF_EXTENSION);
+ len = len + 3;
+
+ /* Return parameters starts from here */
+ pRetPar = &pEvent->Data[len];
+ pRetPar[0] = status; /* status */
+
+ len++;
+ pEvent->Length = len;
+
+ /* total tx event length + EventCode length + sizeof(length) */
+ tx_event_length = pEvent->Length + 2;
+
+ status = rtw_btcoex_sendmsgbysocket(padapter, (u8 *)pEvent, tx_event_length, false);
+ return status;
+ /* bthci_IndicateEvent(Adapter, PPacketIrpEvent, len+2); */
+ }
+}
+
+u8 rtw_btcoex_parse_HCI_BT_operation_notify_cmd(_adapter *padapter, u8 *pcmd, u16 cmdlen)
+{
+ u8 localBuf[6] = "";
+ u8 *pRetPar;
+ u8 len = 0, tx_event_length = 0;
+ rtw_HCI_event *pEvent;
+ RTW_HCI_STATUS status = HCI_STATUS_SUCCESS;
+
+ RTW_INFO("%s, OP code: %d\n", __func__, pcmd[0]);
+
+ switch (pcmd[0]) {
+ case HCI_BT_OP_NONE:
+ RTW_INFO("[bt operation] : Operation None!!\n");
+ break;
+ case HCI_BT_OP_INQUIRY_START:
+ RTW_INFO("[bt operation] : Inquiry start!!\n");
+ break;
+ case HCI_BT_OP_INQUIRY_FINISH:
+ RTW_INFO("[bt operation] : Inquiry finished!!\n");
+ break;
+ case HCI_BT_OP_PAGING_START:
+ RTW_INFO("[bt operation] : Paging is started!!\n");
+ break;
+ case HCI_BT_OP_PAGING_SUCCESS:
+ RTW_INFO("[bt operation] : Paging complete successfully!!\n");
+ break;
+ case HCI_BT_OP_PAGING_UNSUCCESS:
+ RTW_INFO("[bt operation] : Paging complete unsuccessfully!!\n");
+ break;
+ case HCI_BT_OP_PAIRING_START:
+ RTW_INFO("[bt operation] : Pairing start!!\n");
+ break;
+ case HCI_BT_OP_PAIRING_FINISH:
+ RTW_INFO("[bt operation] : Pairing finished!!\n");
+ break;
+ case HCI_BT_OP_BT_DEV_ENABLE:
+ RTW_INFO("[bt operation] : BT Device is enabled!!\n");
+ break;
+ case HCI_BT_OP_BT_DEV_DISABLE:
+ RTW_INFO("[bt operation] : BT Device is disabled!!\n");
+ break;
+ default:
+ RTW_INFO("[bt operation] : Unknown, error!!\n");
+ break;
+ }
+
+ /* send complete event to BT */
+ {
+ pEvent = (rtw_HCI_event *)(&localBuf[0]);
+
+
+ pEvent->EventCode = HCI_EVENT_COMMAND_COMPLETE;
+ pEvent->Data[0] = 0x1; /* packet # */
+ pEvent->Data[1] = HCIOPCODELOW(HCI_BT_OPERATION_NOTIFY, OGF_EXTENSION);
+ pEvent->Data[2] = HCIOPCODEHIGHT(HCI_BT_OPERATION_NOTIFY, OGF_EXTENSION);
+ len = len + 3;
+
+ /* Return parameters starts from here */
+ pRetPar = &pEvent->Data[len];
+ pRetPar[0] = status; /* status */
+
+ len++;
+ pEvent->Length = len;
+
+ /* total tx event length + EventCode length + sizeof(length) */
+ tx_event_length = pEvent->Length + 2;
+
+ status = rtw_btcoex_sendmsgbysocket(padapter, (u8 *)pEvent, tx_event_length, false);
+ return status;
+ /* bthci_IndicateEvent(Adapter, PPacketIrpEvent, len+2); */
+ }
+}
+
+u8 rtw_btcoex_parse_BT_AFH_MAP_notify_cmd(_adapter *padapter, u8 *pcmd, u16 cmdlen)
+{
+ u8 localBuf[6] = "";
+ u8 *pRetPar;
+ u8 len = 0, tx_event_length = 0;
+ rtw_HCI_event *pEvent;
+ RTW_HCI_STATUS status = HCI_STATUS_SUCCESS;
+
+ {
+ pEvent = (rtw_HCI_event *)(&localBuf[0]);
+
+
+ pEvent->EventCode = HCI_EVENT_COMMAND_COMPLETE;
+ pEvent->Data[0] = 0x1; /* packet # */
+ pEvent->Data[1] = HCIOPCODELOW(HCI_BT_AFH_MAP_NOTIFY, OGF_EXTENSION);
+ pEvent->Data[2] = HCIOPCODEHIGHT(HCI_BT_AFH_MAP_NOTIFY, OGF_EXTENSION);
+ len = len + 3;
+
+ /* Return parameters starts from here */
+ pRetPar = &pEvent->Data[len];
+ pRetPar[0] = status; /* status */
+
+ len++;
+ pEvent->Length = len;
+
+ /* total tx event length + EventCode length + sizeof(length) */
+ tx_event_length = pEvent->Length + 2;
+
+ status = rtw_btcoex_sendmsgbysocket(padapter, (u8 *)pEvent, tx_event_length, false);
+ return status;
+ /* bthci_IndicateEvent(Adapter, PPacketIrpEvent, len+2); */
+ }
+}
+
+u8 rtw_btcoex_parse_BT_register_val_notify_cmd(_adapter *padapter, u8 *pcmd, u16 cmdlen)
+{
+
+ u8 localBuf[6] = "";
+ u8 *pRetPar;
+ u8 len = 0, tx_event_length = 0;
+ rtw_HCI_event *pEvent;
+ RTW_HCI_STATUS status = HCI_STATUS_SUCCESS;
+
+ {
+ pEvent = (rtw_HCI_event *)(&localBuf[0]);
+
+
+ pEvent->EventCode = HCI_EVENT_COMMAND_COMPLETE;
+ pEvent->Data[0] = 0x1; /* packet # */
+ pEvent->Data[1] = HCIOPCODELOW(HCI_BT_REGISTER_VALUE_NOTIFY, OGF_EXTENSION);
+ pEvent->Data[2] = HCIOPCODEHIGHT(HCI_BT_REGISTER_VALUE_NOTIFY, OGF_EXTENSION);
+ len = len + 3;
+
+ /* Return parameters starts from here */
+ pRetPar = &pEvent->Data[len];
+ pRetPar[0] = status; /* status */
+
+ len++;
+ pEvent->Length = len;
+
+ /* total tx event length + EventCode length + sizeof(length) */
+ tx_event_length = pEvent->Length + 2;
+
+ status = rtw_btcoex_sendmsgbysocket(padapter, (u8 *)pEvent, tx_event_length, false);
+ return status;
+ /* bthci_IndicateEvent(Adapter, PPacketIrpEvent, len+2); */
+ }
+}
+
+u8 rtw_btcoex_parse_HCI_BT_abnormal_notify_cmd(_adapter *padapter, u8 *pcmd, u16 cmdlen)
+{
+ u8 localBuf[6] = "";
+ u8 *pRetPar;
+ u8 len = 0, tx_event_length = 0;
+ rtw_HCI_event *pEvent;
+ RTW_HCI_STATUS status = HCI_STATUS_SUCCESS;
+
+ {
+ pEvent = (rtw_HCI_event *)(&localBuf[0]);
+
+
+ pEvent->EventCode = HCI_EVENT_COMMAND_COMPLETE;
+ pEvent->Data[0] = 0x1; /* packet # */
+ pEvent->Data[1] = HCIOPCODELOW(HCI_BT_ABNORMAL_NOTIFY, OGF_EXTENSION);
+ pEvent->Data[2] = HCIOPCODEHIGHT(HCI_BT_ABNORMAL_NOTIFY, OGF_EXTENSION);
+ len = len + 3;
+
+ /* Return parameters starts from here */
+ pRetPar = &pEvent->Data[len];
+ pRetPar[0] = status; /* status */
+
+ len++;
+ pEvent->Length = len;
+
+ /* total tx event length + EventCode length + sizeof(length) */
+ tx_event_length = pEvent->Length + 2;
+
+ status = rtw_btcoex_sendmsgbysocket(padapter, (u8 *)pEvent, tx_event_length, false);
+ return status;
+ /* bthci_IndicateEvent(Adapter, PPacketIrpEvent, len+2); */
+ }
+}
+
+u8 rtw_btcoex_parse_HCI_query_RF_status_cmd(_adapter *padapter, u8 *pcmd, u16 cmdlen)
+{
+ u8 localBuf[6] = "";
+ u8 *pRetPar;
+ u8 len = 0, tx_event_length = 0;
+ rtw_HCI_event *pEvent;
+ RTW_HCI_STATUS status = HCI_STATUS_SUCCESS;
+
+ {
+ pEvent = (rtw_HCI_event *)(&localBuf[0]);
+
+
+ pEvent->EventCode = HCI_EVENT_COMMAND_COMPLETE;
+ pEvent->Data[0] = 0x1; /* packet # */
+ pEvent->Data[1] = HCIOPCODELOW(HCI_QUERY_RF_STATUS, OGF_EXTENSION);
+ pEvent->Data[2] = HCIOPCODEHIGHT(HCI_QUERY_RF_STATUS, OGF_EXTENSION);
+ len = len + 3;
+
+ /* Return parameters starts from here */
+ pRetPar = &pEvent->Data[len];
+ pRetPar[0] = status; /* status */
+
+ len++;
+ pEvent->Length = len;
+
+ /* total tx event length + EventCode length + sizeof(length) */
+ tx_event_length = pEvent->Length + 2;
+
+ status = rtw_btcoex_sendmsgbysocket(padapter, (u8 *)pEvent, tx_event_length, false);
+ return status;
+ /* bthci_IndicateEvent(Adapter, PPacketIrpEvent, len+2); */
+ }
+}
+
+/*****************************************
+* HCI cmd format :
+*| 15 - 0 |
+*| OPcode (OCF|OGF<<10) |
+*| 15 - 8 |7 - 0 |
+*|Cmd para |Cmd para Length |
+*|Cmd para...... |
+******************************************/
+
+/* bit 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
+ * | OCF | OGF | */
+void rtw_btcoex_parse_hci_extend_cmd(_adapter *padapter, u8 *pcmd, u16 len, const u16 hci_OCF)
+{
+
+ RTW_INFO("%s: OCF: %x\n", __func__, hci_OCF);
+ switch (hci_OCF) {
+ case HCI_EXTENSION_VERSION_NOTIFY:
+ RTW_INFO("HCI_EXTENSION_VERSION_NOTIFY\n");
+ rtw_btcoex_parse_HCI_Ver_notify_cmd(padapter, pcmd, len);
+ break;
+ case HCI_LINK_STATUS_NOTIFY:
+ RTW_INFO("HCI_LINK_STATUS_NOTIFY\n");
+ rtw_btcoex_parse_HCI_link_status_notify_cmd(padapter, pcmd, len);
+ break;
+ case HCI_BT_OPERATION_NOTIFY:
+ /* only for 8723a 2ant */
+ RTW_INFO("HCI_BT_OPERATION_NOTIFY\n");
+ rtw_btcoex_parse_HCI_BT_operation_notify_cmd(padapter, pcmd, len);
+ /* */
+ break;
+ case HCI_ENABLE_WIFI_SCAN_NOTIFY:
+ RTW_INFO("HCI_ENABLE_WIFI_SCAN_NOTIFY\n");
+ rtw_btcoex_parse_WIFI_scan_notify_cmd(padapter, pcmd, len);
+ break;
+ case HCI_QUERY_RF_STATUS:
+ /* only for 8723b 2ant */
+ RTW_INFO("HCI_QUERY_RF_STATUS\n");
+ rtw_btcoex_parse_HCI_query_RF_status_cmd(padapter, pcmd, len);
+ break;
+ case HCI_BT_ABNORMAL_NOTIFY:
+ RTW_INFO("HCI_BT_ABNORMAL_NOTIFY\n");
+ rtw_btcoex_parse_HCI_BT_abnormal_notify_cmd(padapter, pcmd, len);
+ break;
+ case HCI_BT_INFO_NOTIFY:
+ RTW_INFO("HCI_BT_INFO_NOTIFY\n");
+ rtw_btcoex_parse_BT_info_notify_cmd(padapter, pcmd, len);
+ break;
+ case HCI_BT_COEX_NOTIFY:
+ RTW_INFO("HCI_BT_COEX_NOTIFY\n");
+ rtw_btcoex_parse_HCI_BT_coex_notify_cmd(padapter, pcmd, len);
+ break;
+ case HCI_BT_PATCH_VERSION_NOTIFY:
+ RTW_INFO("HCI_BT_PATCH_VERSION_NOTIFY\n");
+ rtw_btcoex_parse_BT_patch_ver_info_cmd(padapter, pcmd, len);
+ break;
+ case HCI_BT_AFH_MAP_NOTIFY:
+ RTW_INFO("HCI_BT_AFH_MAP_NOTIFY\n");
+ rtw_btcoex_parse_BT_AFH_MAP_notify_cmd(padapter, pcmd, len);
+ break;
+ case HCI_BT_REGISTER_VALUE_NOTIFY:
+ RTW_INFO("HCI_BT_REGISTER_VALUE_NOTIFY\n");
+ rtw_btcoex_parse_BT_register_val_notify_cmd(padapter, pcmd, len);
+ break;
+ default:
+ RTW_INFO("ERROR!!! Unknown OCF: %x\n", hci_OCF);
+ break;
+
+ }
+}
+
+void rtw_btcoex_parse_hci_cmd(_adapter *padapter, u8 *pcmd, u16 len)
+{
+ u16 opcode = pcmd[0] | pcmd[1] << 8;
+ u16 hci_OGF = HCI_OGF(opcode);
+ u16 hci_OCF = HCI_OCF(opcode);
+ u8 cmdlen = len - 3;
+ u8 pare_len = pcmd[2];
+
+ RTW_INFO("%s OGF: %x,OCF: %x\n", __func__, hci_OGF, hci_OCF);
+ switch (hci_OGF) {
+ case OGF_EXTENSION:
+ RTW_INFO("HCI_EXTENSION_CMD_OGF\n");
+ rtw_btcoex_parse_hci_extend_cmd(padapter, &pcmd[3], cmdlen, hci_OCF);
+ break;
+ default:
+ RTW_INFO("Other OGF: %x\n", hci_OGF);
+ break;
+ }
+}
+
+u16 rtw_btcoex_parse_recv_data(u8 *msg, u8 msg_size)
+{
+ u8 cmp_msg1[32] = attend_ack;
+ u8 cmp_msg2[32] = leave_ack;
+ u8 cmp_msg3[32] = bt_leave;
+ u8 cmp_msg4[32] = invite_req;
+ u8 cmp_msg5[32] = attend_req;
+ u8 cmp_msg6[32] = invite_rsp;
+ u8 res = OTHER;
+
+ if (!memcmp(cmp_msg1, msg, msg_size) == true) {
+ /*RTW_INFO("%s, msg:%s\n",__func__,msg);*/
+ res = RX_ATTEND_ACK;
+ } else if (!memcmp(cmp_msg2, msg, msg_size) == true) {
+ /*RTW_INFO("%s, msg:%s\n",__func__,msg);*/
+ res = RX_LEAVE_ACK;
+ } else if (!memcmp(cmp_msg3, msg, msg_size) == true) {
+ /*RTW_INFO("%s, msg:%s\n",__func__,msg);*/
+ res = RX_BT_LEAVE;
+ } else if (!memcmp(cmp_msg4, msg, msg_size) == true) {
+ /*RTW_INFO("%s, msg:%s\n",__func__,msg);*/
+ res = RX_INVITE_REQ;
+ } else if (!memcmp(cmp_msg5, msg, msg_size) == true)
+ res = RX_ATTEND_REQ;
+ else if (!memcmp(cmp_msg6, msg, msg_size) == true)
+ res = RX_INVITE_RSP;
+ else {
+ /*RTW_INFO("%s, %s\n", __func__, msg);*/
+ res = OTHER;
+ }
+
+ /*RTW_INFO("%s, res:%d\n", __func__, res);*/
+
+ return res;
+}
+
+void rtw_btcoex_recvmsgbysocket(void *data)
+{
+ u8 recv_data[255];
+ u8 tx_msg[255] = leave_ack;
+ u32 len = 0;
+ u16 recv_length = 0;
+ u16 parse_res = 0;
+
+ struct bt_coex_info *pcoex_info = NULL;
+ struct sock *sk = NULL;
+ struct sk_buff *skb = NULL;
+
+ /*RTW_INFO("%s\n",__func__);*/
+
+ if (pbtcoexadapter == NULL) {
+ RTW_INFO("%s: btcoexadapter NULL!\n", __func__);
+ return;
+ }
+
+ pcoex_info = &pbtcoexadapter->coex_info;
+ sk = pcoex_info->sk_store;
+
+ if (sk == NULL) {
+ RTW_INFO("%s: critical error when receive socket data!\n", __func__);
+ return;
+ }
+
+ len = skb_queue_len(&sk->sk_receive_queue);
+ while (len > 0) {
+ skb = skb_dequeue(&sk->sk_receive_queue);
+
+ /*important: cut the udp header from skb->data! header length is 8 byte*/
+ recv_length = skb->len - 8;
+ memset(recv_data, 0, sizeof(recv_data));
+ memcpy(recv_data, skb->data + 8, recv_length);
+
+ parse_res = rtw_btcoex_parse_recv_data(recv_data, recv_length);
+ switch (parse_res) {
+ case RX_ATTEND_ACK:
+ /* attend ack */
+ pcoex_info->BT_attend = true;
+ RTW_INFO("RX_ATTEND_ACK!,sock_open:%d, BT_attend:%d\n", pcoex_info->sock_open, pcoex_info->BT_attend);
+ rtw_btcoex_pta_off_on_notify(pbtcoexadapter, pcoex_info->BT_attend);
+ break;
+
+ case RX_ATTEND_REQ:
+ pcoex_info->BT_attend = true;
+ RTW_INFO("RX_BT_ATTEND_REQ!,sock_open:%d, BT_attend:%d\n", pcoex_info->sock_open, pcoex_info->BT_attend);
+ rtw_btcoex_sendmsgbysocket(pbtcoexadapter, attend_ack, sizeof(attend_ack), false);
+ rtw_btcoex_pta_off_on_notify(pbtcoexadapter, pcoex_info->BT_attend);
+ break;
+
+ case RX_INVITE_REQ:
+ /* invite req from BT */
+ pcoex_info->BT_attend = true;
+ RTW_INFO("RX_INVITE_REQ!,sock_open:%d, BT_attend:%d\n", pcoex_info->sock_open, pcoex_info->BT_attend);
+ rtw_btcoex_sendmsgbysocket(pbtcoexadapter, invite_rsp, sizeof(invite_rsp), false);
+ rtw_btcoex_pta_off_on_notify(pbtcoexadapter, pcoex_info->BT_attend);
+ break;
+
+ case RX_INVITE_RSP:
+ /*invite rsp*/
+ pcoex_info->BT_attend = true;
+ RTW_INFO("RX_INVITE_RSP!,sock_open:%d, BT_attend:%d\n", pcoex_info->sock_open, pcoex_info->BT_attend);
+ rtw_btcoex_pta_off_on_notify(pbtcoexadapter, pcoex_info->BT_attend);
+ break;
+
+ case RX_LEAVE_ACK:
+ /* mean BT know wifi will leave */
+ pcoex_info->BT_attend = false;
+ RTW_INFO("RX_LEAVE_ACK!,sock_open:%d, BT_attend:%d\n", pcoex_info->sock_open, pcoex_info->BT_attend);
+ rtw_btcoex_pta_off_on_notify(pbtcoexadapter, pcoex_info->BT_attend);
+ break;
+
+ case RX_BT_LEAVE:
+ /* BT leave */
+ rtw_btcoex_sendmsgbysocket(pbtcoexadapter, leave_ack, sizeof(leave_ack), false); /* no ack */
+ pcoex_info->BT_attend = false;
+ RTW_INFO("RX_BT_LEAVE!sock_open:%d, BT_attend:%d\n", pcoex_info->sock_open, pcoex_info->BT_attend);
+ rtw_btcoex_pta_off_on_notify(pbtcoexadapter, pcoex_info->BT_attend);
+ break;
+
+ default:
+ if (pcoex_info->BT_attend)
+ rtw_btcoex_parse_hci_cmd(pbtcoexadapter, recv_data, recv_length);
+ else
+ RTW_INFO("ERROR!! BT is UP\n");
+ break;
+
+ }
+
+ len--;
+ kfree_skb(skb);
+ }
+}
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0))
+ void rtw_btcoex_recvmsg_init(struct sock *sk_in, s32 bytes)
+#else
+ void rtw_btcoex_recvmsg_init(struct sock *sk_in)
+#endif
+{
+ struct bt_coex_info *pcoex_info = NULL;
+
+ if (pbtcoexadapter == NULL) {
+ RTW_INFO("%s: btcoexadapter NULL\n", __func__);
+ return;
+ }
+ pcoex_info = &pbtcoexadapter->coex_info;
+ pcoex_info->sk_store = sk_in;
+ if (pcoex_info->btcoex_wq != NULL)
+ queue_delayed_work(pcoex_info->btcoex_wq, &pcoex_info->recvmsg_work, 0);
+ else
+ RTW_INFO("%s: BTCOEX workqueue NULL\n", __func__);
+}
+
+u8 rtw_btcoex_sendmsgbysocket(_adapter *padapter, u8 *msg, u8 msg_size, bool force)
+{
+ u8 error;
+ struct msghdr udpmsg;
+ mm_segment_t oldfs;
+ struct iovec iov;
+ struct bt_coex_info *pcoex_info = &padapter->coex_info;
+
+ /* RTW_INFO("%s: msg:%s, force:%s\n", __func__, msg, force == true?"true":"false"); */
+ if (false == force) {
+ if (false == pcoex_info->BT_attend) {
+ RTW_INFO("TX Blocked: WiFi-BT disconnected\n");
+ return _FAIL;
+ }
+ }
+
+ iov.iov_base = (void *)msg;
+ iov.iov_len = msg_size;
+ udpmsg.msg_name = &pcoex_info->bt_sockaddr;
+ udpmsg.msg_namelen = sizeof(struct sockaddr_in);
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0))
+ /* referece:sock_xmit in kernel code
+ * WRITE for sock_sendmsg, READ for sock_recvmsg
+ * third parameter for msg_iovlen
+ * last parameter for iov_len
+ */
+ iov_iter_init(&udpmsg.msg_iter, WRITE, &iov, 1, msg_size);
+#else
+ udpmsg.msg_iov = &iov;
+ udpmsg.msg_iovlen = 1;
+#endif
+ udpmsg.msg_control = NULL;
+ udpmsg.msg_controllen = 0;
+ udpmsg.msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL;
+ oldfs = get_fs();
+ set_fs(KERNEL_DS);
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0))
+ error = sock_sendmsg(pcoex_info->udpsock, &udpmsg);
+#else
+ error = sock_sendmsg(pcoex_info->udpsock, &udpmsg, msg_size);
+#endif
+ set_fs(oldfs);
+ if (error < 0) {
+ RTW_INFO("Error when sendimg msg, error:%d\n", error);
+ return _FAIL;
+ } else
+ return _SUCCESS;
+}
+
+u8 rtw_btcoex_create_kernel_socket(_adapter *padapter)
+{
+ s8 kernel_socket_err;
+ u8 tx_msg[255] = attend_req;
+ struct bt_coex_info *pcoex_info = &padapter->coex_info;
+ s32 sock_reuse = 1;
+ u8 status = _FAIL;
+
+ RTW_INFO("%s CONNECT_PORT %d\n", __func__, CONNECT_PORT);
+
+ if (NULL == pcoex_info) {
+ RTW_INFO("coex_info: NULL\n");
+ status = _FAIL;
+ }
+
+ kernel_socket_err = sock_create(PF_INET, SOCK_DGRAM, 0, &pcoex_info->udpsock);
+
+ if (kernel_socket_err < 0) {
+ RTW_INFO("Error during creation of socket error:%d\n", kernel_socket_err);
+ status = _FAIL;
+ } else {
+ memset(&(pcoex_info->wifi_sockaddr), 0, sizeof(pcoex_info->wifi_sockaddr));
+ pcoex_info->wifi_sockaddr.sin_family = AF_INET;
+ pcoex_info->wifi_sockaddr.sin_port = htons(CONNECT_PORT);
+ pcoex_info->wifi_sockaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+ memset(&(pcoex_info->bt_sockaddr), 0, sizeof(pcoex_info->bt_sockaddr));
+ pcoex_info->bt_sockaddr.sin_family = AF_INET;
+ pcoex_info->bt_sockaddr.sin_port = htons(CONNECT_PORT_BT);
+ pcoex_info->bt_sockaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+ pcoex_info->sk_store = NULL;
+ kernel_socket_err = pcoex_info->udpsock->ops->bind(pcoex_info->udpsock, (struct sockaddr *)&pcoex_info->wifi_sockaddr,
+ sizeof(pcoex_info->wifi_sockaddr));
+ if (kernel_socket_err == 0) {
+ RTW_INFO("binding socket success\n");
+ pcoex_info->udpsock->sk->sk_data_ready = rtw_btcoex_recvmsg_init;
+ pcoex_info->sock_open |= KERNEL_SOCKET_OK;
+ pcoex_info->BT_attend = false;
+ RTW_INFO("WIFI sending attend_req\n");
+ rtw_btcoex_sendmsgbysocket(padapter, attend_req, sizeof(attend_req), true);
+ status = _SUCCESS;
+ } else {
+ pcoex_info->BT_attend = false;
+ sock_release(pcoex_info->udpsock); /* bind fail release socket */
+ RTW_INFO("Error binding socket: %d\n", kernel_socket_err);
+ status = _FAIL;
+ }
+
+ }
+
+ return status;
+}
+
+void rtw_btcoex_close_kernel_socket(_adapter *padapter)
+{
+ struct bt_coex_info *pcoex_info = &padapter->coex_info;
+ if (pcoex_info->sock_open & KERNEL_SOCKET_OK) {
+ RTW_INFO("release kernel socket\n");
+ sock_release(pcoex_info->udpsock);
+ pcoex_info->sock_open &= ~(KERNEL_SOCKET_OK);
+ if (pcoex_info->BT_attend)
+ pcoex_info->BT_attend = false;
+
+ RTW_INFO("sock_open:%d, BT_attend:%d\n", pcoex_info->sock_open, pcoex_info->BT_attend);
+ }
+}
+
+void rtw_btcoex_init_socket(_adapter *padapter)
+{
+
+ u8 is_invite = false;
+ struct bt_coex_info *pcoex_info = &padapter->coex_info;
+ RTW_INFO("%s\n", __func__);
+ if (false == pcoex_info->is_exist) {
+ memset(pcoex_info, 0, sizeof(struct bt_coex_info));
+ pcoex_info->btcoex_wq = create_workqueue("BTCOEX");
+ INIT_DELAYED_WORK(&pcoex_info->recvmsg_work,
+ (void *)rtw_btcoex_recvmsgbysocket);
+ pbtcoexadapter = padapter;
+ /* We expect BT is off if BT don't send ack to wifi */
+ RTW_INFO("We expect BT is off if BT send ack to wifi\n");
+ rtw_btcoex_pta_off_on_notify(pbtcoexadapter, false);
+ if (rtw_btcoex_create_kernel_socket(padapter) == _SUCCESS)
+ pcoex_info->is_exist = true;
+ else {
+ pcoex_info->is_exist = false;
+ pbtcoexadapter = NULL;
+ }
+
+ RTW_INFO("%s: pbtcoexadapter:%p, coex_info->is_exist: %s\n"
+ , __func__, pbtcoexadapter, pcoex_info->is_exist == true ? "true" : "false");
+ }
+}
+
+void rtw_btcoex_close_socket(_adapter *padapter)
+{
+ struct bt_coex_info *pcoex_info = &padapter->coex_info;
+
+ RTW_INFO("%s--coex_info->is_exist: %s, pcoex_info->BT_attend:%s\n"
+ , __func__, pcoex_info->is_exist == true ? "true" : "false", pcoex_info->BT_attend == true ? "true" : "false");
+
+ if (pcoex_info->is_exist) {
+ if (pcoex_info->BT_attend) {
+ /*inform BT wifi leave*/
+ rtw_btcoex_sendmsgbysocket(padapter, wifi_leave, sizeof(wifi_leave), false);
+ msleep(50);
+ }
+
+ if (pcoex_info->btcoex_wq != NULL) {
+ flush_workqueue(pcoex_info->btcoex_wq);
+ destroy_workqueue(pcoex_info->btcoex_wq);
+ }
+
+ rtw_btcoex_close_kernel_socket(padapter);
+ pbtcoexadapter = NULL;
+ pcoex_info->is_exist = false;
+ }
+}
+
+void rtw_btcoex_dump_tx_msg(u8 *tx_msg, u8 len, u8 *msg_name)
+{
+ u8 i = 0;
+ RTW_INFO("======> Msg name: %s\n", msg_name);
+ for (i = 0; i < len; i++)
+ RTW_INFO("%02x ", tx_msg[i]);
+ RTW_INFO("\n");
+ RTW_INFO("Msg name: %s <======\n", msg_name);
+}
+
+/* Porting from Windows team */
+void rtw_btcoex_SendEventExtBtCoexControl(PADAPTER padapter, u8 bNeedDbgRsp, u8 dataLen, void *pData)
+{
+ u8 len = 0, tx_event_length = 0;
+ u8 localBuf[32] = "";
+ u8 *pRetPar;
+ u8 opCode = 0;
+ u8 *pInBuf = (u8 *)pData;
+ u8 *pOpCodeContent;
+ rtw_HCI_event *pEvent;
+
+ opCode = pInBuf[0];
+
+ RTW_INFO("%s, OPCode:%02x\n", __func__, opCode);
+
+ pEvent = (rtw_HCI_event *)(&localBuf[0]);
+
+ /* len += bthci_ExtensionEventHeaderRtk(&localBuf[0], */
+ /* HCI_EVENT_EXT_BT_COEX_CONTROL); */
+ pEvent->EventCode = HCI_EVENT_EXTENSION_RTK;
+ pEvent->Data[0] = HCI_EVENT_EXT_BT_COEX_CONTROL; /* extension event code */
+ len++;
+
+ /* Return parameters starts from here */
+ pRetPar = &pEvent->Data[len];
+ memcpy(&pRetPar[0], pData, dataLen);
+
+ len += dataLen;
+
+ pEvent->Length = len;
+
+ /* total tx event length + EventCode length + sizeof(length) */
+ tx_event_length = pEvent->Length + 2;
+ rtw_btcoex_sendmsgbysocket(padapter, (u8 *)pEvent, tx_event_length, false);
+}
+
+/* Porting from Windows team */
+void rtw_btcoex_SendEventExtBtInfoControl(PADAPTER padapter, u8 dataLen, void *pData)
+{
+ rtw_HCI_event *pEvent;
+ u8 *pRetPar;
+ u8 len = 0, tx_event_length = 0;
+ u8 localBuf[32] = "";
+
+ struct bt_coex_info *pcoex_info = &padapter->coex_info;
+ PBT_MGNT pBtMgnt = &pcoex_info->BtMgnt;
+
+ /* RTW_INFO("%s\n",__func__);*/
+ if (pBtMgnt->ExtConfig.HCIExtensionVer < 4) { /* not support */
+ RTW_INFO("ERROR: HCIExtensionVer = %d, HCIExtensionVer<4 !!!!\n", pBtMgnt->ExtConfig.HCIExtensionVer);
+ return;
+ }
+
+ pEvent = (rtw_HCI_event *)(&localBuf[0]);
+
+ /* len += bthci_ExtensionEventHeaderRtk(&localBuf[0], */
+ /* HCI_EVENT_EXT_BT_INFO_CONTROL); */
+ pEvent->EventCode = HCI_EVENT_EXTENSION_RTK;
+ pEvent->Data[0] = HCI_EVENT_EXT_BT_INFO_CONTROL; /* extension event code */
+ len++;
+
+ /* Return parameters starts from here */
+ pRetPar = &pEvent->Data[len];
+ memcpy(&pRetPar[0], pData, dataLen);
+
+ len += dataLen;
+
+ pEvent->Length = len;
+
+ /* total tx event length + EventCode length + sizeof(length) */
+ tx_event_length = pEvent->Length + 2;
+ rtw_btcoex_sendmsgbysocket(padapter, (u8 *)pEvent, tx_event_length, false);
+}
+
+void rtw_btcoex_SendScanNotify(PADAPTER padapter, u8 scanType)
+{
+ u8 len = 0, tx_event_length = 0;
+ u8 localBuf[7] = "";
+ u8 *pRetPar;
+ u8 *pu1Temp;
+ rtw_HCI_event *pEvent;
+ struct bt_coex_info *pcoex_info = &padapter->coex_info;
+ PBT_MGNT pBtMgnt = &pcoex_info->BtMgnt;
+
+ /* if(!pBtMgnt->BtOperationOn)
+ * return; */
+
+ pEvent = (rtw_HCI_event *)(&localBuf[0]);
+
+ /* len += bthci_ExtensionEventHeaderRtk(&localBuf[0],
+ * HCI_EVENT_EXT_WIFI_SCAN_NOTIFY); */
+
+ pEvent->EventCode = HCI_EVENT_EXTENSION_RTK;
+ pEvent->Data[0] = HCI_EVENT_EXT_WIFI_SCAN_NOTIFY; /* extension event code */
+ len++;
+
+ /* Return parameters starts from here */
+ /* pRetPar = &PPacketIrpEvent->Data[len]; */
+ /* pu1Temp = (u8 *)&pRetPar[0]; */
+ /* *pu1Temp = scanType; */
+ pEvent->Data[len] = scanType;
+ len += 1;
+
+ pEvent->Length = len;
+
+ /* total tx event length + EventCode length + sizeof(length) */
+ tx_event_length = pEvent->Length + 2;
+ rtw_btcoex_sendmsgbysocket(padapter, (u8 *)pEvent, tx_event_length, false);
+}
+#endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
+#endif /* CONFIG_BT_COEXIST */
diff --git a/drivers/staging/rtl8188eu/core/rtw_btcoex_wifionly.c b/drivers/staging/rtl8188eu/core/rtw_btcoex_wifionly.c
new file mode 100644
index 000000000000..3dc651a95264
--- /dev/null
+++ b/drivers/staging/rtl8188eu/core/rtw_btcoex_wifionly.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved. */
+
+#include <drv_types.h>
+#include <hal_btcoex_wifionly.h>
+#include <hal_data.h>
+
+void rtw_btcoex_wifionly_switchband_notify(PADAPTER padapter)
+{
+ hal_btcoex_wifionly_switchband_notify(padapter);
+}
+
+void rtw_btcoex_wifionly_scan_notify(PADAPTER padapter)
+{
+ hal_btcoex_wifionly_scan_notify(padapter);
+}
+
+void rtw_btcoex_wifionly_hw_config(PADAPTER padapter)
+{
+ hal_btcoex_wifionly_hw_config(padapter);
+}
+
+void rtw_btcoex_wifionly_initialize(PADAPTER padapter)
+{
+ hal_btcoex_wifionly_initlizevariables(padapter);
+}
diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c b/drivers/staging/rtl8188eu/core/rtw_cmd.c
new file mode 100644
index 000000000000..162725e43e45
--- /dev/null
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -0,0 +1,4433 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved. */
+
+#define _RTW_CMD_C_
+
+#include <drv_types.h>
+#include <hal_data.h>
+
+#ifndef DBG_CMD_EXECUTE
+ #define DBG_CMD_EXECUTE 0
+#endif
+
+/* Caller and the rtw_cmd_thread can protect cmd_q by spin_lock.
+ * No irqsave is necessary.
+ */
+
+sint _rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
+{
+ sint res = _SUCCESS;
+
+ sema_init(&(pcmdpriv->cmd_queue_sema), 0);
+ sema_init(&(pcmdpriv->terminate_cmdthread_sema), 0);
+
+
+ _rtw_init_queue(&(pcmdpriv->cmd_queue));
+
+ /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
+ pcmdpriv->cmd_seq = 1;
+
+ pcmdpriv->cmd_allocated_buf = rtw_zmalloc(MAX_CMDSZ + CMDBUFF_ALIGN_SZ);
+
+ if (!pcmdpriv->cmd_allocated_buf) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pcmdpriv->cmd_buf = pcmdpriv->cmd_allocated_buf + CMDBUFF_ALIGN_SZ - ((SIZE_PTR)(pcmdpriv->cmd_allocated_buf) & (CMDBUFF_ALIGN_SZ - 1));
+
+ pcmdpriv->rsp_allocated_buf = rtw_zmalloc(MAX_RSPSZ + 4);
+
+ if (!pcmdpriv->rsp_allocated_buf) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pcmdpriv->rsp_buf = pcmdpriv->rsp_allocated_buf + 4 - ((SIZE_PTR)(pcmdpriv->rsp_allocated_buf) & 3);
+
+ pcmdpriv->cmd_issued_cnt = pcmdpriv->cmd_done_cnt = pcmdpriv->rsp_cnt = 0;
+
+ _rtw_mutex_init(&pcmdpriv->sctx_mutex);
+exit:
+
+
+ return res;
+
+}
+
+#ifdef CONFIG_C2H_WK
+static void c2h_wk_callback(_workitem *work)
+{
+ struct evt_priv *evtpriv = container_of(work, struct evt_priv, c2h_wk);
+ _adapter *adapter = container_of(evtpriv, _adapter, evtpriv);
+ u8 *c2h_evt;
+ c2h_id_filter direct_hdl_filter = rtw_hal_c2h_id_handle_directly;
+ u8 id, seq, plen;
+ u8 *payload;
+
+ evtpriv->c2h_wk_alive = true;
+
+ while (!rtw_cbuf_empty(evtpriv->c2h_queue)) {
+ c2h_evt = (u8 *)rtw_cbuf_pop(evtpriv->c2h_queue);
+ if (c2h_evtL) {
+ /* This C2H event is read, clear it */
+ c2h_evt_clear(adapter);
+ } else {
+ c2h_evt = (u8 *)rtw_malloc(C2H_REG_LEN);
+ if (!c2h_evt) {
+ rtw_warn_on(1);
+ continue;
+ }
+
+ /* This C2H event is not read, read & clear now */
+ if (rtw_hal_c2h_evt_read(adapter, c2h_evt) != _SUCCESS) {
+ rtw_mfree(c2h_evt, C2H_REG_LEN);
+ continue;
+ }
+ }
+
+ /* Special pointer to trigger c2h_evt_clear only */
+ if ((void *)c2h_evt == (void *)evtpriv)
+ continue;
+
+ if (!rtw_hal_c2h_valid(adapter, c2h_evt)
+ || rtw_hal_c2h_reg_hdr_parse(adapter, c2h_evt, &id, &seq, &plen, &payload) != _SUCCESS
+ ) {
+ rtw_mfree(c2h_evt, C2H_REG_LEN);
+ continue;
+ }
+
+ if (direct_hdl_filter(adapter, id, seq, plen, payload) == true) {
+ /* Handle directly */
+ rtw_hal_c2h_handler(adapter, id, seq, plen, payload);
+ rtw_mfree(c2h_evt, C2H_REG_LEN);
+ } else {
+ /* Enqueue into cmd_thread for others */
+ rtw_c2h_reg_wk_cmd(adapter, c2h_evt);
+ rtw_mfree(c2h_evt, C2H_REG_LEN);
+ }
+ }
+
+ evtpriv->c2h_wk_alive = false;
+}
+#endif /* CONFIG_C2H_WK */
+
+sint _rtw_init_evt_priv(struct evt_priv *pevtpriv)
+{
+ sint res = _SUCCESS;
+
+
+#ifdef CONFIG_H2CLBK
+ sema_init(&(pevtpriv->lbkevt_done), 0);
+ pevtpriv->lbkevt_limit = 0;
+ pevtpriv->lbkevt_num = 0;
+ pevtpriv->cmdevt_parm = NULL;
+#endif
+
+ /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
+ ATOMIC_SET(&pevtpriv->event_seq, 0);
+ pevtpriv->evt_done_cnt = 0;
+
+#ifdef CONFIG_EVENT_THREAD_MODE
+
+ sema_init(&(pevtpriv->evt_notify), 0);
+ sema_init(&(pevtpriv->terminate_evtthread_sema), 0);
+
+ pevtpriv->evt_allocated_buf = rtw_zmalloc(MAX_EVTSZ + 4);
+ if (!pevtpriv->evt_allocated_buf) {
+ res = _FAIL;
+ goto exit;
+ }
+ pevtpriv->evt_buf = pevtpriv->evt_allocated_buf + 4 - ((unsigned int)(pevtpriv->evt_allocated_buf) & 3);
+
+
+#if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
+ pevtpriv->allocated_c2h_mem = rtw_zmalloc(C2H_MEM_SZ + 4);
+
+ if (!pevtpriv->allocated_c2h_mem) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pevtpriv->c2h_mem = pevtpriv->allocated_c2h_mem + 4 -
+ ((u32)(pevtpriv->allocated_c2h_mem) & 3);
+#endif /* end of CONFIG_SDIO_HCI */
+
+ _rtw_init_queue(&(pevtpriv->evt_queue));
+
+exit:
+
+#endif /* end of CONFIG_EVENT_THREAD_MODE */
+
+#ifdef CONFIG_C2H_WK
+ _init_workitem(&pevtpriv->c2h_wk, c2h_wk_callback, NULL);
+ pevtpriv->c2h_wk_alive = false;
+ pevtpriv->c2h_queue = rtw_cbuf_alloc(C2H_QUEUE_MAX_LEN + 1);
+#endif
+
+
+ return res;
+}
+
+void _rtw_free_evt_priv(struct evt_priv *pevtpriv)
+{
+#ifdef CONFIG_EVENT_THREAD_MODE
+ if (pevtpriv->evt_allocated_buf)
+ rtw_mfree(pevtpriv->evt_allocated_buf, MAX_EVTSZ + 4);
+#endif
+
+#ifdef CONFIG_C2H_WK
+ _cancel_workitem_sync(&pevtpriv->c2h_wk);
+ while (pevtpriv->c2h_wk_alive)
+ rtw_msleep_os(10);
+
+ while (!rtw_cbuf_empty(pevtpriv->c2h_queue)) {
+ void *c2h;
+
+ c2h = rtw_cbuf_pop(pevtpriv->c2h_queue);
+ if (c2h && c2h != (void *)pevtpriv)
+ rtw_mfree(c2h, 16);
+ }
+ rtw_cbuf_free(pevtpriv->c2h_queue);
+#endif
+}
+
+void _rtw_free_cmd_priv(struct cmd_priv *pcmdpriv)
+{
+ if (pcmdpriv) {
+ if (pcmdpriv->cmd_allocated_buf)
+ rtw_mfree(pcmdpriv->cmd_allocated_buf, MAX_CMDSZ + CMDBUFF_ALIGN_SZ);
+
+ if (pcmdpriv->rsp_allocated_buf)
+ rtw_mfree(pcmdpriv->rsp_allocated_buf, MAX_RSPSZ + 4);
+
+ _rtw_mutex_free(&pcmdpriv->sctx_mutex);
+ }
+}
+
+/* Calling Context:
+ * rtw_enqueue_cmd can only be called between kernel thread,
+ * since only spin_lock is used.
+
+ * ISR/Call-Back functions can't call this sub-function.
+ */
+#ifdef DBG_CMD_QUEUE
+extern u8 dump_cmd_id;
+#endif
+
+sint _rtw_enqueue_cmd(_queue *queue, struct cmd_obj *obj, bool to_head)
+{
+ unsigned long irqL;
+
+ if (!obj)
+ goto exit;
+
+ _enter_critical(&queue->lock, &irqL);
+
+ if (to_head)
+ list_add(&obj->list, &queue->queue);
+ else
+ list_add_tail(&obj->list, &queue->queue);
+
+#ifdef DBG_CMD_QUEUE
+ if (dump_cmd_id) {
+ RTW_INFO("%s===> cmdcode:0x%02x\n", __func__, obj->cmdcode);
+ if (obj->cmdcode == GEN_CMD_CODE(_Set_MLME_EVT)) {
+ if (obj->parmbuf) {
+ struct C2HEvent_Header *pc2h_evt_hdr = (struct C2HEvent_Header *)(obj->parmbuf);
+
+ RTW_INFO("pc2h_evt_hdr->ID:0x%02x(%d)\n", pc2h_evt_hdr->ID, pc2h_evt_hdr->ID);
+ }
+ }
+ if (obj->cmdcode == GEN_CMD_CODE(_Set_Drv_Extra)) {
+ if (obj->parmbuf) {
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)(obj->parmbuf);
+
+ RTW_INFO("pdrvextra_cmd_parm->ec_id:0x%02x\n", pdrvextra_cmd_parm->ec_id);
+ }
+ }
+ }
+
+ if (queue->queue.prev->next != &queue->queue) {
+ RTW_INFO("[%d] head %p, tail %p, tail->prev->next %p[tail], tail->next %p[head]\n", __LINE__,
+ &queue->queue, queue->queue.prev, queue->queue.prev->prev->next, queue->queue.prev->next);
+
+ RTW_INFO("==========%s============\n", __func__);
+ RTW_INFO("head:%p,obj_addr:%p\n", &queue->queue, obj);
+ RTW_INFO("padapter: %p\n", obj->padapter);
+ RTW_INFO("cmdcode: 0x%02x\n", obj->cmdcode);
+ RTW_INFO("res: %d\n", obj->res);
+ RTW_INFO("parmbuf: %p\n", obj->parmbuf);
+ RTW_INFO("cmdsz: %d\n", obj->cmdsz);
+ RTW_INFO("rsp: %p\n", obj->rsp);
+ RTW_INFO("rspsz: %d\n", obj->rspsz);
+ RTW_INFO("sctx: %p\n", obj->sctx);
+ RTW_INFO("list->next: %p\n", obj->list.next);
+ RTW_INFO("list->prev: %p\n", obj->list.prev);
+ }
+#endif /* DBG_CMD_QUEUE */
+
+ _exit_critical(&queue->lock, &irqL);
+exit:
+ return _SUCCESS;
+}
+
+struct cmd_obj *_rtw_dequeue_cmd(_queue *queue)
+{
+ unsigned long irqL;
+ struct cmd_obj *obj;
+
+ _enter_critical(&queue->lock, &irqL);
+
+#ifdef DBG_CMD_QUEUE
+ if (queue->queue.prev->next != &queue->queue) {
+ RTW_INFO("[%d] head %p, tail %p, tail->prev->next %p[tail], tail->next %p[head]\n", __LINE__,
+ &queue->queue, queue->queue.prev, queue->queue.prev->prev->next, queue->queue.prev->next);
+ }
+#endif /* DBG_CMD_QUEUE */
+
+ if (list_empty(&(queue->queue))) {
+ obj = NULL;
+ } else {
+ obj = LIST_CONTAINOR(get_next(&(queue->queue)), struct cmd_obj, list);
+#ifdef DBG_CMD_QUEUE
+ if (queue->queue.prev->next != &queue->queue) {
+ RTW_INFO("==========%s============\n", __func__);
+ RTW_INFO("head:%p,obj_addr:%p\n", &queue->queue, obj);
+ RTW_INFO("padapter: %p\n", obj->padapter);
+ RTW_INFO("cmdcode: 0x%02x\n", obj->cmdcode);
+ RTW_INFO("res: %d\n", obj->res);
+ RTW_INFO("parmbuf: %p\n", obj->parmbuf);
+ RTW_INFO("cmdsz: %d\n", obj->cmdsz);
+ RTW_INFO("rsp: %p\n", obj->rsp);
+ RTW_INFO("rspsz: %d\n", obj->rspsz);
+ RTW_INFO("sctx: %p\n", obj->sctx);
+ RTW_INFO("list->next: %p\n", obj->list.next);
+ RTW_INFO("list->prev: %p\n", obj->list.prev);
+ }
+
+ if (dump_cmd_id) {
+ RTW_INFO("%s===> cmdcode:0x%02x\n", __func__, obj->cmdcode);
+ if (obj->cmdcode == GEN_CMD_CODE(_Set_Drv_Extra)) {
+ if (obj->parmbuf) {
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)(obj->parmbuf);
+
+ RTW_INFO("pdrvextra_cmd_parm->ec_id:0x%02x\n", pdrvextra_cmd_parm->ec_id);
+ }
+ }
+
+ }
+#endif /* DBG_CMD_QUEUE */
+
+ list_del_init(&obj->list);
+ }
+ _exit_critical(&queue->lock, &irqL);
+
+ return obj;
+}
+
+u32 rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
+{
+ u32 res;
+
+ res = _rtw_init_cmd_priv(pcmdpriv);
+ return res;
+}
+
+u32 rtw_init_evt_priv(struct evt_priv *pevtpriv)
+{
+ int res;
+
+ res = _rtw_init_evt_priv(pevtpriv);
+ return res;
+}
+
+void rtw_free_evt_priv(struct evt_priv *pevtpriv)
+{
+ _rtw_free_evt_priv(pevtpriv);
+}
+
+void rtw_free_cmd_priv(struct cmd_priv *pcmdpriv)
+{
+ _rtw_free_cmd_priv(pcmdpriv);
+}
+
+int rtw_cmd_filter(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
+{
+ u8 bAllow = false; /* set to true to allow enqueuing cmd when hw_init_completed is false */
+
+#ifdef SUPPORT_HW_RFOFF_DETECTED
+ /* To decide allow or not */
+ if ((adapter_to_pwrctl(pcmdpriv->padapter)->bHWPwrPindetect) &&
+ (!pcmdpriv->padapter->registrypriv.usbss_enable)) {
+ if (cmd_obj->cmdcode == GEN_CMD_CODE(_Set_Drv_Extra)) {
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)cmd_obj->parmbuf;
+
+ if (pdrvextra_cmd_parm->ec_id == POWER_SAVING_CTRL_WK_CID)
+ bAllow = true;
+ }
+ }
+#endif
+
+ if (cmd_obj->cmdcode == GEN_CMD_CODE(_SetChannelPlan))
+ bAllow = true;
+
+ if (cmd_obj->no_io)
+ bAllow = true;
+
+ if ((!rtw_is_hw_init_completed(pcmdpriv->padapter) && (bAllow == false))
+ || ATOMIC_READ(&(pcmdpriv->cmdthd_running)) == false /* com_thread not running */
+ ) {
+ if (DBG_CMD_EXECUTE)
+ RTW_INFO(ADPT_FMT" drop "CMD_FMT" hw_init_completed:%u, cmdthd_running:%u\n", ADPT_ARG(cmd_obj->padapter)
+ , CMD_ARG(cmd_obj), rtw_get_hw_init_completed(cmd_obj->padapter), ATOMIC_READ(&pcmdpriv->cmdthd_running));
+ if (0)
+ rtw_warn_on(1);
+
+ return _FAIL;
+ }
+ return _SUCCESS;
+}
+
+
+
+u32 rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
+{
+ int res = _FAIL;
+ PADAPTER padapter = pcmdpriv->padapter;
+
+
+ if (!cmd_obj)
+ goto exit;
+
+ cmd_obj->padapter = padapter;
+
+#ifdef CONFIG_CONCURRENT_MODE
+ /* change pcmdpriv to primary's pcmdpriv */
+ if (padapter->adapter_type != PRIMARY_ADAPTER)
+ pcmdpriv = &(GET_PRIMARY_ADAPTER(padapter)->cmdpriv);
+#endif
+
+ res = rtw_cmd_filter(pcmdpriv, cmd_obj);
+ if ((res == _FAIL) || (cmd_obj->cmdsz > MAX_CMDSZ)) {
+ if (cmd_obj->cmdsz > MAX_CMDSZ) {
+ RTW_INFO("%s failed due to obj->cmdsz(%d) > MAX_CMDSZ(%d)\n", __func__, cmd_obj->cmdsz, MAX_CMDSZ);
+ rtw_warn_on(1);
+ }
+
+ if (cmd_obj->cmdcode == GEN_CMD_CODE(_Set_Drv_Extra)) {
+ struct drvextra_cmd_parm *extra_parm = (struct drvextra_cmd_parm *)cmd_obj->parmbuf;
+
+ if (extra_parm->pbuf && extra_parm->size > 0)
+ rtw_mfree(extra_parm->pbuf, extra_parm->size);
+ }
+ rtw_free_cmd_obj(cmd_obj);
+ goto exit;
+ }
+
+ res = _rtw_enqueue_cmd(&pcmdpriv->cmd_queue, cmd_obj, 0);
+
+ if (res == _SUCCESS)
+ up(&pcmdpriv->cmd_queue_sema);
+
+exit:
+
+
+ return res;
+}
+
+struct cmd_obj *rtw_dequeue_cmd(struct cmd_priv *pcmdpriv)
+{
+ struct cmd_obj *cmd_obj;
+
+
+ cmd_obj = _rtw_dequeue_cmd(&pcmdpriv->cmd_queue);
+
+ return cmd_obj;
+}
+
+void rtw_cmd_clr_isr(struct cmd_priv *pcmdpriv)
+{
+ pcmdpriv->cmd_done_cnt++;
+ /* up(&(pcmdpriv->cmd_done_sema)); */
+}
+
+void rtw_free_cmd_obj(struct cmd_obj *pcmd)
+{
+ struct drvextra_cmd_parm *extra_parm = NULL;
+
+ if (pcmd->parmbuf) {
+ /* free parmbuf in cmd_obj */
+ rtw_mfree((unsigned char *)pcmd->parmbuf, pcmd->cmdsz);
+ }
+ if (pcmd->rsp) {
+ if (pcmd->rspsz != 0) {
+ /* free rsp in cmd_obj */
+ rtw_mfree((unsigned char *)pcmd->rsp, pcmd->rspsz);
+ }
+ }
+
+ /* free cmd_obj */
+ rtw_mfree((unsigned char *)pcmd, sizeof(struct cmd_obj));
+}
+
+
+void rtw_stop_cmd_thread(_adapter *adapter)
+{
+ if (adapter->cmdThread &&
+ ATOMIC_READ(&(adapter->cmdpriv.cmdthd_running)) == true &&
+ adapter->cmdpriv.stop_req == 0) {
+ adapter->cmdpriv.stop_req = 1;
+ up(&adapter->cmdpriv.cmd_queue_sema);
+ _rtw_down_sema(&adapter->cmdpriv.terminate_cmdthread_sema);
+ }
+}
+
+thread_return rtw_cmd_thread(thread_context context)
+{
+ u8 ret;
+ struct cmd_obj *pcmd;
+ u8 *pcmdbuf, *prspbuf;
+ u32 cmd_start_time;
+ u32 cmd_process_time;
+ u8 (*cmd_hdl)(_adapter *padapter, u8 *pbuf);
+ void (*pcmd_callback)(_adapter *dev, struct cmd_obj *pcmd);
+ PADAPTER padapter = (PADAPTER)context;
+ struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
+ struct drvextra_cmd_parm *extra_parm = NULL;
+ unsigned long irqL;
+
+ thread_enter("RTW_CMD_THREAD");
+
+ pcmdbuf = pcmdpriv->cmd_buf;
+ prspbuf = pcmdpriv->rsp_buf;
+
+ pcmdpriv->stop_req = 0;
+ ATOMIC_SET(&(pcmdpriv->cmdthd_running), true);
+ up(&pcmdpriv->terminate_cmdthread_sema);
+
+
+ while (1) {
+ if (_rtw_down_sema(&pcmdpriv->cmd_queue_sema) == _FAIL) {
+ RTW_PRINT(FUNC_ADPT_FMT" _rtw_down_sema(&pcmdpriv->cmd_queue_sema) return _FAIL, break\n", FUNC_ADPT_ARG(padapter));
+ break;
+ }
+
+ if (RTW_CANNOT_RUN(padapter)) {
+ RTW_PRINT("%s: DriverStopped(%s) SurpriseRemoved(%s) break at line %d\n",
+ __func__
+ , rtw_is_drv_stopped(padapter) ? "True" : "False"
+ , rtw_is_surprise_removed(padapter) ? "True" : "False"
+ , __LINE__);
+ break;
+ }
+
+ if (pcmdpriv->stop_req) {
+ RTW_PRINT(FUNC_ADPT_FMT" stop_req:%u, break\n", FUNC_ADPT_ARG(padapter), pcmdpriv->stop_req);
+ break;
+ }
+
+ _enter_critical(&pcmdpriv->cmd_queue.lock, &irqL);
+ if (list_empty(&(pcmdpriv->cmd_queue.queue))) {
+ /* RTW_INFO("%s: cmd queue is empty!\n", __func__); */
+ _exit_critical(&pcmdpriv->cmd_queue.lock, &irqL);
+ continue;
+ }
+ _exit_critical(&pcmdpriv->cmd_queue.lock, &irqL);
+
+_next:
+ if (RTW_CANNOT_RUN(padapter)) {
+ RTW_PRINT("%s: DriverStopped(%s) SurpriseRemoved(%s) break at line %d\n",
+ __func__
+ , rtw_is_drv_stopped(padapter) ? "True" : "False"
+ , rtw_is_surprise_removed(padapter) ? "True" : "False"
+ , __LINE__);
+ break;
+ }
+
+ pcmd = rtw_dequeue_cmd(pcmdpriv);
+ if (!pcmd) {
+#ifdef CONFIG_LPS_LCLK
+ rtw_unregister_cmd_alive(padapter);
+#endif
+ continue;
+ }
+
+ cmd_start_time = jiffies;
+ pcmdpriv->cmd_issued_cnt++;
+
+ if (pcmd->cmdsz > MAX_CMDSZ) {
+ RTW_ERR("%s cmdsz:%d > MAX_CMDSZ:%d\n", __func__, pcmd->cmdsz, MAX_CMDSZ);
+ pcmd->res = H2C_PARAMETERS_ERROR;
+ goto post_process;
+ }
+
+ if (pcmd->cmdcode >= (sizeof(wlancmds) / sizeof(struct cmd_hdl))) {
+ RTW_ERR("%s undefined cmdcode:%d\n", __func__, pcmd->cmdcode);
+ pcmd->res = H2C_PARAMETERS_ERROR;
+ goto post_process;
+ }
+
+ cmd_hdl = wlancmds[pcmd->cmdcode].h2cfuns;
+ if (!cmd_hdl) {
+ RTW_ERR("%s no cmd_hdl for cmdcode:%d\n", __func__, pcmd->cmdcode);
+ pcmd->res = H2C_PARAMETERS_ERROR;
+ goto post_process;
+ }
+
+ if (rtw_cmd_filter(pcmdpriv, pcmd) == _FAIL) {
+ pcmd->res = H2C_DROPPED;
+ if (pcmd->cmdcode == GEN_CMD_CODE(_Set_Drv_Extra)) {
+ extra_parm = (struct drvextra_cmd_parm *)pcmd->parmbuf;
+ if (extra_parm && extra_parm->pbuf && extra_parm->size > 0)
+ rtw_mfree(extra_parm->pbuf, extra_parm->size);
+ }
+ goto post_process;
+ }
+
+#ifdef CONFIG_LPS_LCLK
+ if (pcmd->no_io)
+ rtw_unregister_cmd_alive(padapter);
+ else {
+ if (rtw_register_cmd_alive(padapter) != _SUCCESS) {
+ if (DBG_CMD_EXECUTE)
+ RTW_PRINT("%s: wait to leave LPS_LCLK\n", __func__);
+
+ pcmd->res = H2C_ENQ_HEAD;
+ ret = _rtw_enqueue_cmd(&pcmdpriv->cmd_queue, pcmd, 1);
+ if (ret == _SUCCESS) {
+ if (DBG_CMD_EXECUTE)
+ RTW_INFO(ADPT_FMT" "CMD_FMT" ENQ_HEAD\n", ADPT_ARG(pcmd->padapter), CMD_ARG(pcmd));
+ continue;
+ }
+
+ RTW_INFO(ADPT_FMT" "CMD_FMT" ENQ_HEAD_FAIL\n", ADPT_ARG(pcmd->padapter), CMD_ARG(pcmd));
+ pcmd->res = H2C_ENQ_HEAD_FAIL;
+ rtw_warn_on(1);
+ }
+ }
+#endif /* CONFIG_LPS_LCLK */
+
+ if (DBG_CMD_EXECUTE)
+ RTW_INFO(ADPT_FMT" "CMD_FMT" %sexecute\n", ADPT_ARG(pcmd->padapter), CMD_ARG(pcmd)
+ , pcmd->res == H2C_ENQ_HEAD ? "ENQ_HEAD " : (pcmd->res == H2C_ENQ_HEAD_FAIL ? "ENQ_HEAD_FAIL " : ""));
+
+ memcpy(pcmdbuf, pcmd->parmbuf, pcmd->cmdsz);
+ ret = cmd_hdl(pcmd->padapter, pcmdbuf);
+ pcmd->res = ret;
+
+ pcmdpriv->cmd_seq++;
+
+post_process:
+
+ _enter_critical_mutex(&(pcmd->padapter->cmdpriv.sctx_mutex), NULL);
+ if (pcmd->sctx) {
+ if (0)
+ RTW_PRINT(FUNC_ADPT_FMT" pcmd->sctx\n",
+ FUNC_ADPT_ARG(pcmd->padapter));
+ if (pcmd->res == H2C_SUCCESS)
+ rtw_sctx_done(&pcmd->sctx);
+ else
+ rtw_sctx_done_err(&pcmd->sctx, RTW_SCTX_DONE_CMD_ERROR);
+ }
+ _exit_critical_mutex(&(pcmd->padapter->cmdpriv.sctx_mutex), NULL);
+
+ cmd_process_time = rtw_get_passing_time_ms(cmd_start_time);
+ if (cmd_process_time > 1000) {
+ RTW_INFO(ADPT_FMT" "CMD_FMT" process_time=%d\n", ADPT_ARG(pcmd->padapter), CMD_ARG(pcmd), cmd_process_time);
+ if (0)
+ rtw_warn_on(1);
+ }
+
+ /* call callback function for post-processed */
+ if (pcmd->cmdcode < (sizeof(rtw_cmd_callback) / sizeof(struct _cmd_callback))) {
+ pcmd_callback = rtw_cmd_callback[pcmd->cmdcode].callback;
+ if (!pcmd_callback) {
+ rtw_free_cmd_obj(pcmd);
+ } else {
+ /* todo: !!! fill rsp_buf to pcmd->rsp if (pcmd->rsp!=NULL) */
+ pcmd_callback(pcmd->padapter, pcmd);/* need conider that free cmd_obj in rtw_cmd_callback */
+ }
+ } else {
+ rtw_free_cmd_obj(pcmd);
+ }
+
+ flush_signals_thread();
+
+ goto _next;
+
+ }
+
+#ifdef CONFIG_LPS_LCLK
+ rtw_unregister_cmd_alive(padapter);
+#endif
+
+ /* to avoid enqueue cmd after free all cmd_obj */
+ ATOMIC_SET(&(pcmdpriv->cmdthd_running), false);
+
+ /* free all cmd_obj resources */
+ do {
+ pcmd = rtw_dequeue_cmd(pcmdpriv);
+ if (!pcmd)
+ break;
+
+ if (pcmd->cmdcode == GEN_CMD_CODE(_Set_Drv_Extra)) {
+ extra_parm = (struct drvextra_cmd_parm *)pcmd->parmbuf;
+ if (extra_parm->pbuf && extra_parm->size > 0)
+ rtw_mfree(extra_parm->pbuf, extra_parm->size);
+ }
+
+ rtw_free_cmd_obj(pcmd);
+ } while (1);
+
+ up(&pcmdpriv->terminate_cmdthread_sema);
+
+
+ thread_exit();
+
+}
+
+
+#ifdef CONFIG_EVENT_THREAD_MODE
+u32 rtw_enqueue_evt(struct evt_priv *pevtpriv, struct evt_obj *obj)
+{
+ unsigned long irqL;
+ int res;
+ _queue *queue = &pevtpriv->evt_queue;
+
+
+ res = _SUCCESS;
+
+ if (!obj) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ _enter_critical_bh(&queue->lock, &irqL);
+
+ list_add_tail(&obj->list, &queue->queue);
+
+ _exit_critical_bh(&queue->lock, &irqL);
+
+exit:
+
+ return res;
+}
+
+struct evt_obj *rtw_dequeue_evt(_queue *queue)
+{
+ unsigned long irqL;
+ struct evt_obj *pevtobj;
+
+
+ _enter_critical_bh(&queue->lock, &irqL);
+
+ if (list_empty(&(queue->queue)))
+ pevtobj = NULL;
+ else {
+ pevtobj = LIST_CONTAINOR(get_next(&(queue->queue)), struct evt_obj, list);
+ list_del_init(&pevtobj->list);
+ }
+
+ _exit_critical_bh(&queue->lock, &irqL);
+
+
+ return pevtobj;
+}
+
+void rtw_free_evt_obj(struct evt_obj *pevtobj)
+{
+
+ if (pevtobj->parmbuf)
+ rtw_mfree((unsigned char *)pevtobj->parmbuf, pevtobj->evtsz);
+
+ rtw_mfree((unsigned char *)pevtobj, sizeof(struct evt_obj));
+
+}
+
+void rtw_evt_notify_isr(struct evt_priv *pevtpriv)
+{
+ pevtpriv->evt_done_cnt++;
+ up(&(pevtpriv->evt_notify));
+}
+#endif
+
+u8 rtw_setstandby_cmd(_adapter *padapter, uint action)
+{
+ struct cmd_obj *ph2c;
+ struct usb_suspend_parm *psetusbsuspend;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 ret = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (ph2c == NULL) {
+ ret = _FAIL;
+ goto exit;
+ }
+ psetusbsuspend = (struct usb_suspend_parm *)rtw_zmalloc(sizeof(struct usb_suspend_parm));
+ if (psetusbsuspend == NULL) {
+ rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
+ ret = _FAIL;
+ goto exit;
+ }
+ psetusbsuspend->action = action;
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, psetusbsuspend, GEN_CMD_CODE(_SetUsbSuspend));
+
+ ret = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+ return ret;
+}
+
+/* ### NOTE:#### (!!!!)
+ * MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock
+ */
+u8 rtw_sitesurvey_cmd(_adapter *padapter, NDIS_802_11_SSID *ssid, int ssid_num,
+ struct rtw_ieee80211_channel *ch, int ch_num)
+{
+ u8 res = _FAIL;
+ struct cmd_obj *ph2c;
+ struct sitesurvey_parm *psurveyPara;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+#ifdef CONFIG_P2P
+ struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
+#endif /* CONFIG_P2P */
+
+#ifdef CONFIG_LPS
+ if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
+ rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SCAN, 1);
+#endif
+
+#ifdef CONFIG_P2P_PS
+ if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
+ p2p_ps_wk_cmd(padapter, P2P_PS_SCAN, 1);
+#endif /* CONFIG_P2P_PS */
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c)
+ return _FAIL;
+
+ psurveyPara = (struct sitesurvey_parm *)rtw_zmalloc(sizeof(struct sitesurvey_parm));
+ if (!psurveyPara) {
+ rtw_mfree((unsigned char *) ph2c, sizeof(struct cmd_obj));
+ return _FAIL;
+ }
+
+ rtw_free_network_queue(padapter, false);
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara, GEN_CMD_CODE(_SiteSurvey));
+
+ psurveyPara->scan_mode = pmlmepriv->scan_mode;
+
+ /* prepare ssid list */
+ if (ssid) {
+ int i;
+
+ for (i = 0; i < ssid_num && i < RTW_SSID_SCAN_AMOUNT; i++) {
+ if (ssid[i].SsidLength) {
+ memcpy(&psurveyPara->ssid[i], &ssid[i], sizeof(NDIS_802_11_SSID));
+ psurveyPara->ssid_num++;
+ }
+ }
+ }
+
+ /* prepare channel list */
+ if (ch) {
+ int i;
+
+ for (i = 0; i < ch_num && i < RTW_CHANNEL_SCAN_AMOUNT; i++) {
+ if (ch[i].hw_value && !(ch[i].flags & RTW_IEEE80211_CHAN_DISABLED)) {
+ memcpy(&psurveyPara->ch[i], &ch[i], sizeof(struct rtw_ieee80211_channel));
+ psurveyPara->ch_num++;
+ }
+ }
+ }
+
+ set_fwstate(pmlmepriv, _FW_UNDER_SURVEY);
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+ if (res == _SUCCESS) {
+
+ pmlmepriv->scan_start_time = jiffies;
+
+#ifdef CONFIG_SCAN_BACKOP
+ if (rtw_mi_buddy_check_mlmeinfo_state(padapter, WIFI_FW_AP_STATE)) {
+ if (is_supported_5g(padapter->registrypriv.wireless_mode)
+ && IsSupported24G(padapter->registrypriv.wireless_mode)) /* dual band */
+ mlme_set_scan_to_timer(pmlmepriv, CONC_SCANNING_TIMEOUT_DUAL_BAND);
+ else /* single band */
+ mlme_set_scan_to_timer(pmlmepriv, CONC_SCANNING_TIMEOUT_SINGLE_BAND);
+ } else
+#endif /* CONFIG_SCAN_BACKOP */
+ mlme_set_scan_to_timer(pmlmepriv, SCANNING_TIMEOUT);
+
+ rtw_led_control(padapter, LED_CTL_SITE_SURVEY);
+ } else
+ _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY);
+
+ return res;
+}
+
+u8 rtw_setdatarate_cmd(_adapter *padapter, u8 *rateset)
+{
+ struct cmd_obj *ph2c;
+ struct setdatarate_parm *pbsetdataratepara;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pbsetdataratepara = (struct setdatarate_parm *)rtw_zmalloc(sizeof(struct setdatarate_parm));
+ if (!pbsetdataratepara) {
+ rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pbsetdataratepara, GEN_CMD_CODE(_SetDataRate));
+#ifdef MP_FIRMWARE_OFFLOAD
+ pbsetdataratepara->curr_rateidx = *(u32 *)rateset;
+#else
+ pbsetdataratepara->mac_id = 5;
+ memcpy(pbsetdataratepara->datarates, rateset, NumRates);
+#endif
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+exit:
+ return res;
+}
+
+u8 rtw_setbasicrate_cmd(_adapter *padapter, u8 *rateset)
+{
+ struct cmd_obj *ph2c;
+ struct setbasicrate_parm *pssetbasicratepara;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+ pssetbasicratepara = (struct setbasicrate_parm *)rtw_zmalloc(sizeof(struct setbasicrate_parm));
+
+ if (!pssetbasicratepara) {
+ rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pssetbasicratepara, _SetBasicRate_CMD_);
+
+ memcpy(pssetbasicratepara->basicrates, rateset, NumRates);
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+exit:
+
+ return res;
+}
+
+/* unsigned char rtw_setphy_cmd(unsigned char *adapter)
+ * 1. be called only after rtw_update_registrypriv_dev_network( ~) or mp testing program
+ * 2. for AdHoc/Ap mode or mp mode?
+ */
+u8 rtw_setphy_cmd(_adapter *padapter, u8 modem, u8 ch)
+{
+ struct cmd_obj *ph2c;
+ struct setphy_parm *psetphypara;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+ psetphypara = (struct setphy_parm *)rtw_zmalloc(sizeof(struct setphy_parm));
+
+ if (!psetphypara) {
+ rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, psetphypara, _SetPhy_CMD_);
+
+ psetphypara->modem = modem;
+ psetphypara->rfchannel = ch;
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+exit:
+ return res;
+}
+
+u8 rtw_getmacreg_cmd(_adapter *padapter, u8 len, u32 addr)
+{
+ struct cmd_obj *ph2c;
+ struct readMAC_parm *preadmacparm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+ preadmacparm = (struct readMAC_parm *)rtw_zmalloc(sizeof(struct readMAC_parm));
+
+ if (!preadmacparm) {
+ rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+ init_h2fwcmd_w_parm_no_rsp(ph2c, preadmacparm, GEN_CMD_CODE(_GetMACReg));
+
+ preadmacparm->len = len;
+ preadmacparm->addr = addr;
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+ return res;
+}
+
+void rtw_usb_catc_trigger_cmd(_adapter *padapter, const char *caller)
+{
+ RTW_INFO("%s caller:%s\n", __func__, caller);
+ rtw_getmacreg_cmd(padapter, 1, 0x1c4);
+}
+
+u8 rtw_setbbreg_cmd(_adapter *padapter, u8 offset, u8 val)
+{
+ struct cmd_obj *ph2c;
+ struct writeBB_parm *pwritebbparm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+ pwritebbparm = (struct writeBB_parm *)rtw_zmalloc(sizeof(struct writeBB_parm));
+
+ if (!pwritebbparm) {
+ rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pwritebbparm, GEN_CMD_CODE(_SetBBReg));
+ pwritebbparm->offset = offset;
+ pwritebbparm->value = val;
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+exit:
+ return res;
+}
+
+u8 rtw_getbbreg_cmd(_adapter *padapter, u8 offset, u8 *pval)
+{
+ struct cmd_obj *ph2c;
+ struct readBB_parm *prdbbparm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+ prdbbparm = (struct readBB_parm *)rtw_zmalloc(sizeof(struct readBB_parm));
+
+ if (!prdbbparm) {
+ rtw_mfree((unsigned char *) ph2c, sizeof(struct cmd_obj));
+ return _FAIL;
+ }
+ INIT_LIST_HEAD(&ph2c->list);
+ ph2c->cmdcode = GEN_CMD_CODE(_GetBBReg);
+ ph2c->parmbuf = (unsigned char *)prdbbparm;
+ ph2c->cmdsz = sizeof(struct readBB_parm);
+ ph2c->rsp = pval;
+ ph2c->rspsz = sizeof(struct readBB_rsp);
+ prdbbparm->offset = offset;
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+exit:
+ return res;
+}
+
+u8 rtw_setrfreg_cmd(_adapter *padapter, u8 offset, u32 val)
+{
+ struct cmd_obj *ph2c;
+ struct writeRF_parm *pwriterfparm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+ pwriterfparm = (struct writeRF_parm *)rtw_zmalloc(sizeof(struct writeRF_parm));
+
+ if (!pwriterfparm) {
+ rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pwriterfparm, GEN_CMD_CODE(_SetRFReg));
+
+ pwriterfparm->offset = offset;
+ pwriterfparm->value = val;
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+exit:
+ return res;
+}
+
+u8 rtw_getrfreg_cmd(_adapter *padapter, u8 offset, u8 *pval)
+{
+ struct cmd_obj *ph2c;
+ struct readRF_parm *prdrfparm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+ prdrfparm = (struct readRF_parm *)rtw_zmalloc(sizeof(struct readRF_parm));
+ if (!prdrfparm) {
+ rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+ INIT_LIST_HEAD(&ph2c->list);
+ ph2c->cmdcode = GEN_CMD_CODE(_GetRFReg);
+ ph2c->parmbuf = (unsigned char *)prdrfparm;
+ ph2c->cmdsz = sizeof(struct readRF_parm);
+ ph2c->rsp = pval;
+ ph2c->rspsz = sizeof(struct readRF_rsp);
+
+ prdrfparm->offset = offset;
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+exit:
+ return res;
+}
+
+void rtw_getbbrfreg_cmdrsp_callback(_adapter *padapter, struct cmd_obj *pcmd)
+{
+ rtw_mfree((unsigned char *) pcmd->parmbuf, pcmd->cmdsz);
+ rtw_mfree((unsigned char *) pcmd, sizeof(struct cmd_obj));
+
+#ifdef CONFIG_MP_INCLUDED
+ if (padapter->registrypriv.mp_mode == 1)
+ padapter->mppriv.workparam.bcompleted = true;
+#endif
+}
+
+void rtw_readtssi_cmdrsp_callback(_adapter *padapter, struct cmd_obj *pcmd)
+{
+ rtw_mfree((unsigned char *) pcmd->parmbuf, pcmd->cmdsz);
+ rtw_mfree((unsigned char *) pcmd, sizeof(struct cmd_obj));
+
+#ifdef CONFIG_MP_INCLUDED
+ if (padapter->registrypriv.mp_mode == 1)
+ padapter->mppriv.workparam.bcompleted = true;
+#endif
+
+}
+
+static u8 rtw_createbss_cmd(_adapter *adapter, int flags, bool adhoc,
+ s16 req_ch, s8 req_bw, s8 req_offset)
+{
+ struct cmd_obj *cmdobj;
+ struct createbss_parm *parm;
+ struct cmd_priv *pcmdpriv = &adapter->cmdpriv;
+ struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
+ struct submit_ctx sctx;
+ u8 res = _SUCCESS;
+
+ if (req_ch > 0 && req_bw >= 0 && req_offset >= 0) {
+ if (!rtw_chset_is_chbw_valid(adapter->mlmeextpriv.channel_set, req_ch, req_bw, req_offset)) {
+ res = _FAIL;
+ goto exit;
+ }
+ }
+
+ /* prepare cmd parameter */
+ parm = (struct createbss_parm *)rtw_zmalloc(sizeof(*parm));
+ if (!parm) {
+ res = _FAIL;
+ goto exit;
+ }
+ if (adhoc) {
+ /* for now, adhoc doesn't support ch,bw,offset request */
+ parm->adhoc = 1;
+ } else {
+ parm->adhoc = 0;
+ parm->req_ch = req_ch;
+ parm->req_bw = req_bw;
+ parm->req_offset = req_offset;
+ }
+
+ if (flags & RTW_CMDF_DIRECTLY) {
+ /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
+ if (createbss_hdl(adapter, (u8 *)parm) != H2C_SUCCESS)
+ res = _FAIL;
+ rtw_mfree((u8 *)parm, sizeof(*parm));
+ } else {
+ /* need enqueue, prepare cmd_obj and enqueue */
+ cmdobj = (struct cmd_obj *)rtw_zmalloc(sizeof(*cmdobj));
+ if (cmdobj == NULL) {
+ res = _FAIL;
+ rtw_mfree((u8 *)parm, sizeof(*parm));
+ goto exit;
+ }
+
+ init_h2fwcmd_w_parm_no_rsp(cmdobj, parm, GEN_CMD_CODE(_CreateBss));
+
+ if (flags & RTW_CMDF_WAIT_ACK) {
+ cmdobj->sctx = &sctx;
+ rtw_sctx_init(&sctx, 2000);
+ }
+
+ res = rtw_enqueue_cmd(pcmdpriv, cmdobj);
+
+ if (res == _SUCCESS && (flags & RTW_CMDF_WAIT_ACK)) {
+ rtw_sctx_wait(&sctx, __func__);
+ _enter_critical_mutex(&pcmdpriv->sctx_mutex, NULL);
+ if (sctx.status == RTW_SCTX_SUBMITTED)
+ cmdobj->sctx = NULL;
+ _exit_critical_mutex(&pcmdpriv->sctx_mutex, NULL);
+ }
+ }
+
+exit:
+ return res;
+}
+
+inline u8 rtw_create_ibss_cmd(_adapter *adapter, int flags)
+{
+/* for now, adhoc doesn't support ch,bw,offset request */
+ return rtw_createbss_cmd(adapter, flags, 1,
+ 0, -1, -1);
+}
+
+inline u8 rtw_startbss_cmd(_adapter *adapter, int flags)
+{
+/* excute entire AP setup cmd */
+ return rtw_createbss_cmd(adapter, flags, 0, 0, -1, -1);
+}
+
+inline u8 rtw_change_bss_chbw_cmd(_adapter *adapter, int flags, s16 req_ch, s8 req_bw, s8 req_offset)
+{
+ return rtw_createbss_cmd(adapter, flags, 0,
+ req_ch, req_bw, req_offset);
+}
+
+u8 rtw_joinbss_cmd(_adapter *padapter, struct wlan_network *pnetwork)
+{
+ u8 *auth, res = _SUCCESS;
+ uint t_len = 0;
+ WLAN_BSSID_EX *psecnetwork;
+ struct cmd_obj *pcmd;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ struct qos_priv *pqospriv = &pmlmepriv->qospriv;
+ struct security_priv *psecuritypriv = &padapter->securitypriv;
+ struct registry_priv *pregistrypriv = &padapter->registrypriv;
+ struct ht_priv *phtpriv = &pmlmepriv->htpriv;
+ NDIS_802_11_NETWORK_INFRASTRUCTURE ndis_network_mode = pnetwork->network.InfrastructureMode;
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ u32 tmp_len;
+ u8 *ptmp = NULL;
+#ifdef CONFIG_RTW_80211R
+ struct _ft_priv *pftpriv = &pmlmepriv->ftpriv;
+#endif
+
+ rtw_led_control(padapter, LED_CTL_START_TO_LINK);
+
+ pcmd = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!pcmd) {
+ res = _FAIL;
+ goto exit;
+ }
+ /* for IEs is fix buf size */
+ t_len = sizeof(WLAN_BSSID_EX);
+
+ /* for hidden ap to set fw_state here */
+ if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_ADHOC_STATE) != true) {
+ switch (ndis_network_mode) {
+ case Ndis802_11IBSS:
+ set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
+ break;
+ case Ndis802_11Infrastructure:
+ set_fwstate(pmlmepriv, WIFI_STATION_STATE);
+ break;
+ case Ndis802_11APMode:
+ case Ndis802_11AutoUnknown:
+ case Ndis802_11InfrastructureMax:
+ case Ndis802_11Monitor:
+ break;
+ }
+ }
+
+ pmlmeinfo->assoc_AP_vendor = check_assoc_AP(pnetwork->network.IEs, pnetwork->network.IELength);
+
+ /* Solution for allocating a new WLAN_BSSID_EX to avoid race condition issue between disconnect and joinbss
+ */
+ psecnetwork = (WLAN_BSSID_EX *)rtw_zmalloc(sizeof(WLAN_BSSID_EX));
+ if (!psecnetwork) {
+ if (pcmd)
+ rtw_mfree((unsigned char *)pcmd, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ memset(psecnetwork, 0, t_len);
+
+ memcpy(psecnetwork, &pnetwork->network, get_WLAN_BSSID_EX_sz(&pnetwork->network));
+
+ auth = &psecuritypriv->authenticator_ie[0];
+ psecuritypriv->authenticator_ie[0] = (unsigned char)psecnetwork->IELength;
+
+ if ((psecnetwork->IELength - 12) < (256 - 1))
+ memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->IEs[12], psecnetwork->IELength - 12);
+ else
+ memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->IEs[12], (256 - 1));
+
+ psecnetwork->IELength = 0;
+ /* If the driver wants to use the bssid to create the connection. */
+ /* If not, we have to copy the connecting AP's MAC address to it so that */
+ /* the driver just has the bssid information for PMKIDList searching. */
+
+ if (!pmlmepriv->assoc_by_bssid)
+ memcpy(&pmlmepriv->assoc_bssid[0], &pnetwork->network.MacAddress[0], ETH_ALEN);
+
+ psecnetwork->IELength = rtw_restruct_sec_ie(padapter, &pnetwork->network.IEs[0], &psecnetwork->IEs[0], pnetwork->network.IELength);
+
+ pqospriv->qos_option = 0;
+
+ if (pregistrypriv->wmm_enable) {
+ tmp_len = rtw_restruct_wmm_ie(padapter, &pnetwork->network.IEs[0], &psecnetwork->IEs[0], pnetwork->network.IELength, psecnetwork->IELength);
+
+ if (psecnetwork->IELength != tmp_len) {
+ psecnetwork->IELength = tmp_len;
+ pqospriv->qos_option = 1; /* There is WMM IE in this corresp. beacon */
+ } else {
+ pqospriv->qos_option = 0;/* There is no WMM IE in this corresp. beacon */
+ }
+ }
+
+ phtpriv->ht_option = false;
+ ptmp = rtw_get_ie(&pnetwork->network.IEs[12], _HT_CAPABILITY_IE_, &tmp_len, pnetwork->network.IELength - 12);
+ if (pregistrypriv->ht_enable && ptmp && tmp_len > 0) {
+ /* For the WEP mode, we will use the bg mode to do the connection to avoid some IOT issue. */
+ /* Especially for Realtek 8192u SoftAP. */
+ if ((padapter->securitypriv.dot11PrivacyAlgrthm != _WEP40_) &&
+ (padapter->securitypriv.dot11PrivacyAlgrthm != _WEP104_) &&
+ (padapter->securitypriv.dot11PrivacyAlgrthm != _TKIP_)) {
+ rtw_ht_use_default_setting(padapter);
+
+ rtw_build_wmm_ie_ht(padapter, &psecnetwork->IEs[0], &psecnetwork->IELength);
+
+ /* rtw_restructure_ht_ie */
+ rtw_restructure_ht_ie(padapter, &pnetwork->network.IEs[12], &psecnetwork->IEs[0],
+ pnetwork->network.IELength - 12, &psecnetwork->IELength,
+ pnetwork->network.Configuration.DSConfig);
+ }
+ }
+ rtw_append_exented_cap(padapter, &psecnetwork->IEs[0], &psecnetwork->IELength);
+
+#ifdef CONFIG_RTW_80211R
+ /*IEEE802.11-2012 Std. Table 8-101�XAKM suite selectors*/
+ if ((rtw_chk_ft_flags(padapter, RTW_FT_STA_SUPPORTED)) &&
+ ((psecuritypriv->rsn_akm_suite_type == 3) ||
+ (psecuritypriv->rsn_akm_suite_type == 4))) {
+ ptmp = rtw_get_ie(&pnetwork->network.IEs[12], _MDIE_, &tmp_len, pnetwork->network.IELength-12);
+ if (ptmp) {
+ memcpy(&pftpriv->mdid, ptmp+2, 2);
+ pftpriv->ft_cap = *(ptmp+4);
+
+ RTW_INFO("FT: Target AP "MAC_FMT" MDID=(0x%2x), capacity=(0x%2x)\n", MAC_ARG(pnetwork->network.MacAddress), pftpriv->mdid, pftpriv->ft_cap);
+ rtw_set_ft_flags(padapter, RTW_FT_SUPPORTED);
+ if ((rtw_chk_ft_flags(padapter, RTW_FT_STA_OVER_DS_SUPPORTED)) && (pftpriv->ft_roam_on_expired == false) && (pftpriv->ft_cap & 0x01))
+ rtw_set_ft_flags(padapter, RTW_FT_OVER_DS_SUPPORTED);
+ } else {
+ /*Don't use FT roaming if Target AP cannot support FT*/
+ RTW_INFO("FT: Target AP "MAC_FMT" could not support FT\n", MAC_ARG(pnetwork->network.MacAddress));
+ rtw_clr_ft_flags(padapter, RTW_FT_SUPPORTED|RTW_FT_OVER_DS_SUPPORTED);
+ rtw_reset_ft_status(padapter);
+ }
+ } else {
+ /*It could be a non-FT connection*/
+ RTW_INFO("FT: %s\n", __func__);
+ rtw_clr_ft_flags(padapter, RTW_FT_SUPPORTED|RTW_FT_OVER_DS_SUPPORTED);
+ rtw_reset_ft_status(padapter);
+ }
+#endif
+ pcmd->cmdsz = sizeof(WLAN_BSSID_EX);
+ INIT_LIST_HEAD(&pcmd->list);
+ pcmd->cmdcode = _JoinBss_CMD_;/* GEN_CMD_CODE(_JoinBss) */
+ pcmd->parmbuf = (unsigned char *)psecnetwork;
+ pcmd->rsp = NULL;
+ pcmd->rspsz = 0;
+ res = rtw_enqueue_cmd(pcmdpriv, pcmd);
+exit:
+ return res;
+}
+
+u8 rtw_disassoc_cmd(_adapter *padapter, u32 deauth_timeout_ms, bool enqueue) /* for sta_mode */
+{
+ struct cmd_obj *cmdobj = NULL;
+ struct disconnect_parm *param = NULL;
+ struct cmd_priv *cmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ /* prepare cmd parameter */
+ param = (struct disconnect_parm *)rtw_zmalloc(sizeof(*param));
+ if (!param) {
+ res = _FAIL;
+ goto exit;
+ }
+ param->deauth_timeout_ms = deauth_timeout_ms;
+
+ if (enqueue) {
+ /* need enqueue, prepare cmd_obj and enqueue */
+ cmdobj = (struct cmd_obj *)rtw_zmalloc(sizeof(*cmdobj));
+ if (!cmdobj) {
+ res = _FAIL;
+ rtw_mfree((u8 *)param, sizeof(*param));
+ goto exit;
+ }
+ init_h2fwcmd_w_parm_no_rsp(cmdobj, param, _DisConnect_CMD_);
+ res = rtw_enqueue_cmd(cmdpriv, cmdobj);
+ } else {
+ /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
+ if (disconnect_hdl(padapter, (u8 *)param) != H2C_SUCCESS)
+ res = _FAIL;
+ rtw_mfree((u8 *)param, sizeof(*param));
+ }
+
+exit:
+ return res;
+}
+
+u8 rtw_setopmode_cmd(_adapter *padapter, NDIS_802_11_NETWORK_INFRASTRUCTURE networktype, bool enqueue)
+{
+ struct cmd_obj *ph2c;
+ struct setopmode_parm *psetop;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ psetop = (struct setopmode_parm *)rtw_zmalloc(sizeof(struct setopmode_parm));
+ if (!psetop) {
+ res = _FAIL;
+ goto exit;
+ }
+ psetop->mode = (u8)networktype;
+
+ if (enqueue) {
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ rtw_mfree((u8 *)psetop, sizeof(*psetop));
+ res = _FAIL;
+ goto exit;
+ }
+ init_h2fwcmd_w_parm_no_rsp(ph2c, psetop, _SetOpMode_CMD_);
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+ } else {
+ setopmode_hdl(padapter, (u8 *)psetop);
+ rtw_mfree((u8 *)psetop, sizeof(*psetop));
+ }
+exit:
+ return res;
+}
+
+u8 rtw_setstakey_cmd(_adapter *padapter, struct sta_info *sta, u8 key_type, bool enqueue)
+{
+ struct cmd_obj *ph2c;
+ struct set_stakey_parm *psetstakey_para;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ struct set_stakey_rsp *psetstakey_rsp = NULL;
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ struct security_priv *psecuritypriv = &padapter->securitypriv;
+ u8 res = _SUCCESS;
+
+ psetstakey_para = (struct set_stakey_parm *)rtw_zmalloc(sizeof(struct set_stakey_parm));
+ if (!psetstakey_para) {
+ res = _FAIL;
+ goto exit;
+ }
+ memcpy(psetstakey_para->addr, sta->hwaddr, ETH_ALEN);
+
+ if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
+ psetstakey_para->algorithm = (unsigned char) psecuritypriv->dot11PrivacyAlgrthm;
+ else
+ GET_ENCRY_ALGO(psecuritypriv, sta, psetstakey_para->algorithm, false);
+
+ if (key_type == GROUP_KEY)
+ memcpy(&psetstakey_para->key, &psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey, 16);
+ else if (key_type == UNICAST_KEY)
+ memcpy(&psetstakey_para->key, &sta->dot118021x_UncstKey, 16);
+#ifdef CONFIG_TDLS
+ else if (key_type == TDLS_KEY) {
+ memcpy(&psetstakey_para->key, sta->tpk.tk, 16);
+ psetstakey_para->algorithm = (u8)sta->dot118021XPrivacy;
+ }
+#endif /* CONFIG_TDLS */
+
+ /* jeff: set this becasue at least sw key is ready */
+ padapter->securitypriv.busetkipkey = true;
+
+ if (enqueue) {
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ rtw_mfree((u8 *) psetstakey_para, sizeof(struct set_stakey_parm));
+ res = _FAIL;
+ goto exit;
+ }
+ psetstakey_rsp = (struct set_stakey_rsp *)rtw_zmalloc(sizeof(struct set_stakey_rsp));
+ if (!psetstakey_rsp) {
+ rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
+ rtw_mfree((u8 *) psetstakey_para, sizeof(struct set_stakey_parm));
+ res = _FAIL;
+ goto exit;
+ }
+ init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
+ ph2c->rsp = (u8 *) psetstakey_rsp;
+ ph2c->rspsz = sizeof(struct set_stakey_rsp);
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+ } else {
+ set_stakey_hdl(padapter, (u8 *)psetstakey_para);
+ rtw_mfree((u8 *) psetstakey_para, sizeof(struct set_stakey_parm));
+ }
+exit:
+ return res;
+}
+
+u8 rtw_clearstakey_cmd(_adapter *padapter, struct sta_info *sta, u8 enqueue)
+{
+ struct cmd_obj *ph2c;
+ struct set_stakey_parm *psetstakey_para;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ struct set_stakey_rsp *psetstakey_rsp = NULL;
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ struct security_priv *psecuritypriv = &padapter->securitypriv;
+ s16 cam_id = 0;
+ u8 res = _SUCCESS;
+
+ if (!enqueue) {
+ while ((cam_id = rtw_camid_search(padapter, sta->hwaddr, -1, -1)) >= 0) {
+ RTW_PRINT("clear key for addr:"MAC_FMT", camid:%d\n", MAC_ARG(sta->hwaddr), cam_id);
+ clear_cam_entry(padapter, cam_id);
+ rtw_camid_free(padapter, cam_id);
+ }
+ } else {
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ psetstakey_para = (struct set_stakey_parm *)rtw_zmalloc(sizeof(struct set_stakey_parm));
+ if (!psetstakey_para) {
+ rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+ psetstakey_rsp = (struct set_stakey_rsp *)rtw_zmalloc(sizeof(struct set_stakey_rsp));
+ if (!psetstakey_rsp) {
+ rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
+ rtw_mfree((u8 *) psetstakey_para, sizeof(struct set_stakey_parm));
+ res = _FAIL;
+ goto exit;
+ }
+ init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
+ ph2c->rsp = (u8 *) psetstakey_rsp;
+ ph2c->rspsz = sizeof(struct set_stakey_rsp);
+
+ memcpy(psetstakey_para->addr, sta->hwaddr, ETH_ALEN);
+
+ psetstakey_para->algorithm = _NO_PRIVACY_;
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+ }
+
+exit:
+ return res;
+}
+
+u8 rtw_setrttbl_cmd(_adapter *padapter, struct setratable_parm *prate_table)
+{
+ struct cmd_obj *ph2c;
+ struct setratable_parm *psetrttblparm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+ psetrttblparm = (struct setratable_parm *)rtw_zmalloc(sizeof(struct setratable_parm));
+
+ if (!psetrttblparm) {
+ rtw_mfree((unsigned char *) ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, psetrttblparm, GEN_CMD_CODE(_SetRaTable));
+
+ memcpy(psetrttblparm, prate_table, sizeof(struct setratable_parm));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+exit:
+ return res;
+
+}
+
+u8 rtw_getrttbl_cmd(_adapter *padapter, struct getratable_rsp *pval)
+{
+ struct cmd_obj *ph2c;
+ struct getratable_parm *pgetrttblparm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+ pgetrttblparm = (struct getratable_parm *)rtw_zmalloc(sizeof(struct getratable_parm));
+
+ if (!pgetrttblparm) {
+ rtw_mfree((unsigned char *) ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+ INIT_LIST_HEAD(&ph2c->list);
+ ph2c->cmdcode = GEN_CMD_CODE(_GetRaTable);
+ ph2c->parmbuf = (unsigned char *)pgetrttblparm;
+ ph2c->cmdsz = sizeof(struct getratable_parm);
+ ph2c->rsp = (u8 *)pval;
+ ph2c->rspsz = sizeof(struct getratable_rsp);
+
+ pgetrttblparm->rsvd = 0x0;
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+exit:
+ return res;
+}
+
+u8 rtw_setassocsta_cmd(_adapter *padapter, u8 *mac_addr)
+{
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ struct cmd_obj *ph2c;
+ struct set_assocsta_parm *psetassocsta_para;
+ struct set_stakey_rsp *psetassocsta_rsp = NULL;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+ psetassocsta_para = (struct set_assocsta_parm *)rtw_zmalloc(sizeof(struct set_assocsta_parm));
+ if (!psetassocsta_para) {
+ rtw_mfree((u8 *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ psetassocsta_rsp = (struct set_stakey_rsp *)rtw_zmalloc(sizeof(struct set_assocsta_rsp));
+ if (!psetassocsta_rsp) {
+ rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
+ rtw_mfree((u8 *) psetassocsta_para, sizeof(struct set_assocsta_parm));
+ return _FAIL;
+ }
+ init_h2fwcmd_w_parm_no_rsp(ph2c, psetassocsta_para, _SetAssocSta_CMD_);
+ ph2c->rsp = (u8 *)psetassocsta_rsp;
+ ph2c->rspsz = sizeof(struct set_assocsta_rsp);
+
+ memcpy(psetassocsta_para->addr, mac_addr, ETH_ALEN);
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+ return res;
+}
+
+u8 rtw_addbareq_cmd(_adapter *padapter, u8 tid, u8 *addr)
+{
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ struct cmd_obj *ph2c;
+ struct addBaReq_parm *paddbareq_parm;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ paddbareq_parm = (struct addBaReq_parm *)rtw_zmalloc(sizeof(struct addBaReq_parm));
+ if (paddbareq_parm == NULL) {
+ rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+ paddbareq_parm->tid = tid;
+ memcpy(paddbareq_parm->addr, addr, ETH_ALEN);
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, paddbareq_parm, GEN_CMD_CODE(_AddBAReq));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+ return res;
+}
+
+u8 rtw_addbarsp_cmd(_adapter *padapter, u8 *addr, u16 tid, u8 status, u8 size, u16 start_seq)
+{
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ struct cmd_obj *ph2c;
+ struct addBaRsp_parm *paddBaRsp_parm;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ paddBaRsp_parm = (struct addBaRsp_parm *)rtw_zmalloc(sizeof(struct addBaRsp_parm));
+
+ if (!paddBaRsp_parm) {
+ rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ memcpy(paddBaRsp_parm->addr, addr, ETH_ALEN);
+ paddBaRsp_parm->tid = tid;
+ paddBaRsp_parm->status = status;
+ paddBaRsp_parm->size = size;
+ paddBaRsp_parm->start_seq = start_seq;
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, paddBaRsp_parm, GEN_CMD_CODE(_AddBARsp));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+ return res;
+}
+
+/* add for CONFIG_IEEE80211W, none 11w can use it */
+u8 rtw_reset_securitypriv_cmd(_adapter *padapter)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (!pdrvextra_cmd_parm) {
+ rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm->ec_id = RESET_SECURITYPRIV;
+ pdrvextra_cmd_parm->type = 0;
+ pdrvextra_cmd_parm->size = 0;
+ pdrvextra_cmd_parm->pbuf = NULL;
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+ return res;
+}
+
+u8 rtw_free_assoc_resources_cmd(_adapter *padapter)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (!pdrvextra_cmd_parm) {
+ rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm->ec_id = FREE_ASSOC_RESOURCES;
+ pdrvextra_cmd_parm->type = 0;
+ pdrvextra_cmd_parm->size = 0;
+ pdrvextra_cmd_parm->pbuf = NULL;
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+exit:
+ return res;
+}
+
+u8 rtw_dynamic_chk_wk_cmd(_adapter *padapter)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ /* only primary padapter does this cmd */
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (!pdrvextra_cmd_parm) {
+ rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm->ec_id = DYNAMIC_CHK_WK_CID;
+ pdrvextra_cmd_parm->type = 0;
+ pdrvextra_cmd_parm->size = 0;
+ pdrvextra_cmd_parm->pbuf = NULL;
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+ return res;
+}
+
+u8 rtw_set_ch_cmd(_adapter *padapter, u8 ch, u8 bw, u8 ch_offset, u8 enqueue)
+{
+ struct cmd_obj *pcmdobj;
+ struct set_ch_parm *set_ch_parm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ RTW_INFO(FUNC_NDEV_FMT" ch:%u, bw:%u, ch_offset:%u\n",
+ FUNC_NDEV_ARG(padapter->pnetdev), ch, bw, ch_offset);
+
+ /* prepare cmd parameter */
+ set_ch_parm = (struct set_ch_parm *)rtw_zmalloc(sizeof(*set_ch_parm));
+ if (!set_ch_parm) {
+ res = _FAIL;
+ goto exit;
+ }
+ set_ch_parm->ch = ch;
+ set_ch_parm->bw = bw;
+ set_ch_parm->ch_offset = ch_offset;
+
+ if (enqueue) {
+ /* need enqueue, prepare cmd_obj and enqueue */
+ pcmdobj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!pcmdobj) {
+ rtw_mfree((u8 *)set_ch_parm, sizeof(*set_ch_parm));
+ res = _FAIL;
+ goto exit;
+ }
+
+ init_h2fwcmd_w_parm_no_rsp(pcmdobj, set_ch_parm, GEN_CMD_CODE(_SetChannel));
+ res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
+ } else {
+ /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
+ if (set_ch_hdl(padapter, (u8 *)set_ch_parm) != H2C_SUCCESS)
+ res = _FAIL;
+
+ rtw_mfree((u8 *)set_ch_parm, sizeof(*set_ch_parm));
+ }
+
+exit:
+
+ RTW_INFO(FUNC_NDEV_FMT" res:%u\n", FUNC_NDEV_ARG(padapter->pnetdev), res);
+
+ return res;
+}
+
+static u8 _rtw_set_chplan_cmd(_adapter *adapter, int flags, u8 chplan, const struct country_chplan *country_ent, u8 swconfig)
+{
+ struct cmd_obj *cmdobj;
+ struct SetChannelPlan_param *parm;
+ struct cmd_priv *pcmdpriv = &adapter->cmdpriv;
+ struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
+ struct submit_ctx sctx;
+ u8 res = _SUCCESS;
+
+
+ /* check if allow software config */
+ if (swconfig && rtw_hal_is_disable_sw_channel_plan(adapter)) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ /* if country_entry is provided, replace chplan */
+ if (country_ent)
+ chplan = country_ent->chplan;
+
+ /* check input parameter */
+ if (!rtw_is_channel_plan_valid(chplan)) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ /* prepare cmd parameter */
+ parm = (struct SetChannelPlan_param *)rtw_zmalloc(sizeof(*parm));
+ if (!parm) {
+ res = _FAIL;
+ goto exit;
+ }
+ parm->country_ent = country_ent;
+ parm->channel_plan = chplan;
+
+ if (flags & RTW_CMDF_DIRECTLY) {
+ /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
+ if (set_chplan_hdl(adapter, (u8 *)parm) != H2C_SUCCESS)
+ res = _FAIL;
+ rtw_mfree((u8 *)parm, sizeof(*parm));
+ } else {
+ /* need enqueue, prepare cmd_obj and enqueue */
+ cmdobj = (struct cmd_obj *)rtw_zmalloc(sizeof(*cmdobj));
+ if (!cmdobj) {
+ res = _FAIL;
+ rtw_mfree((u8 *)parm, sizeof(*parm));
+ goto exit;
+ }
+
+ init_h2fwcmd_w_parm_no_rsp(cmdobj, parm, GEN_CMD_CODE(_SetChannelPlan));
+
+ if (flags & RTW_CMDF_WAIT_ACK) {
+ cmdobj->sctx = &sctx;
+ rtw_sctx_init(&sctx, 2000);
+ }
+
+ res = rtw_enqueue_cmd(pcmdpriv, cmdobj);
+
+ if (res == _SUCCESS && (flags & RTW_CMDF_WAIT_ACK)) {
+ rtw_sctx_wait(&sctx, __func__);
+ _enter_critical_mutex(&pcmdpriv->sctx_mutex, NULL);
+ if (sctx.status == RTW_SCTX_SUBMITTED)
+ cmdobj->sctx = NULL;
+ _exit_critical_mutex(&pcmdpriv->sctx_mutex, NULL);
+ }
+ }
+
+exit:
+ return res;
+}
+
+inline u8 rtw_set_chplan_cmd(_adapter *adapter, int flags, u8 chplan, u8 swconfig)
+{
+ return _rtw_set_chplan_cmd(adapter, flags, chplan, NULL, swconfig);
+}
+
+inline u8 rtw_set_country_cmd(_adapter *adapter, int flags, const char *country_code, u8 swconfig)
+{
+ const struct country_chplan *ent;
+
+ if (!is_alpha(country_code[0]) || !is_alpha(country_code[1])) {
+ RTW_PRINT("%s input country_code is not alpha2\n", __func__);
+ return _FAIL;
+ }
+
+ ent = rtw_get_chplan_from_country(country_code);
+
+ if (!ent) {
+ RTW_PRINT("%s unsupported country_code:\"%c%c\"\n", __func__, country_code[0], country_code[1]);
+ return _FAIL;
+ }
+
+ RTW_PRINT("%s country_code:\"%c%c\" mapping to chplan:0x%02x\n", __func__, country_code[0], country_code[1], ent->chplan);
+
+ return _rtw_set_chplan_cmd(adapter, flags, RTW_CHPLAN_MAX, ent, swconfig);
+}
+
+u8 rtw_led_blink_cmd(_adapter *padapter, void *pLed)
+{
+ struct cmd_obj *pcmdobj;
+ struct LedBlink_param *ledBlink_param;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ pcmdobj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!pcmdobj) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ ledBlink_param = (struct LedBlink_param *)rtw_zmalloc(sizeof(struct LedBlink_param));
+ if (!ledBlink_param) {
+ rtw_mfree((u8 *)pcmdobj, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+ ledBlink_param->pLed = pLed;
+
+ init_h2fwcmd_w_parm_no_rsp(pcmdobj, ledBlink_param, GEN_CMD_CODE(_LedBlink));
+ res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
+
+exit:
+ return res;
+}
+
+u8 rtw_set_csa_cmd(_adapter *padapter, u8 new_ch_no)
+{
+ struct cmd_obj *pcmdobj;
+ struct SetChannelSwitch_param *setChannelSwitch_param;
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ pcmdobj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!pcmdobj) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ setChannelSwitch_param = (struct SetChannelSwitch_param *)rtw_zmalloc(sizeof(struct SetChannelSwitch_param));
+ if (!setChannelSwitch_param) {
+ rtw_mfree((u8 *)pcmdobj, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+ setChannelSwitch_param->new_ch_no = new_ch_no;
+
+ init_h2fwcmd_w_parm_no_rsp(pcmdobj, setChannelSwitch_param, GEN_CMD_CODE(_SetChannelSwitch));
+ res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
+
+exit:
+ return res;
+}
+
+u8 rtw_tdls_cmd(_adapter *padapter, u8 *addr, u8 option)
+{
+ struct cmd_obj *pcmdobj;
+ struct TDLSoption_param *TDLSoption;
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+#ifdef CONFIG_TDLS
+ pcmdobj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!pcmdobj) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ TDLSoption = (struct TDLSoption_param *)rtw_zmalloc(sizeof(struct TDLSoption_param));
+ if (!TDLSoption) {
+ rtw_mfree((u8 *)pcmdobj, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ spin_lock(&(padapter->tdlsinfo.cmd_lock));
+ if (!addr)
+ memcpy(TDLSoption->addr, addr, 6);
+ TDLSoption->option = option;
+ spin_unlock(&(padapter->tdlsinfo.cmd_lock));
+ init_h2fwcmd_w_parm_no_rsp(pcmdobj, TDLSoption, GEN_CMD_CODE(_TDLS));
+ res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
+
+#endif /* CONFIG_TDLS */
+
+exit:
+ return res;
+}
+
+u8 rtw_enable_hw_update_tsf_cmd(_adapter *padapter)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (!pdrvextra_cmd_parm) {
+ rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+ pdrvextra_cmd_parm->ec_id = EN_HW_UPDATE_TSF_WK_CID;
+ pdrvextra_cmd_parm->type = 0;
+ pdrvextra_cmd_parm->size = 0;
+ pdrvextra_cmd_parm->pbuf = NULL;
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+ return res;
+}
+
+/* from_timer == 1 means driver is in LPS */
+u8 traffic_status_watchdog(_adapter *padapter, u8 from_timer)
+{
+ u8 bEnterPS = false;
+ u16 BusyThresholdHigh;
+ u16 BusyThresholdLow;
+ u16 BusyThreshold;
+ u8 bBusyTraffic = false, bTxBusyTraffic = false, bRxBusyTraffic = false;
+ u8 bHigherBusyTraffic = false, bHigherBusyRxTraffic = false, bHigherBusyTxTraffic = false;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+#ifdef CONFIG_TDLS
+ struct tdls_info *ptdlsinfo = &(padapter->tdlsinfo);
+ struct tdls_txmgmt txmgmt;
+ u8 baddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+#endif /* CONFIG_TDLS */
+
+ RT_LINK_DETECT_T *link_detect = &pmlmepriv->LinkDetectInfo;
+
+#ifdef CONFIG_BT_COEXIST
+ if (padapter->registrypriv.wifi_spec != 1) {
+ BusyThresholdHigh = 25;
+ BusyThresholdLow = 10;
+ } else
+#endif /* CONFIG_BT_COEXIST */
+ {
+ BusyThresholdHigh = 100;
+ BusyThresholdLow = 75;
+ }
+ BusyThreshold = BusyThresholdHigh;
+
+
+ /* Determine if our traffic is busy now */
+ if (check_fwstate(pmlmepriv, _FW_LINKED)) {
+ /* if we raise bBusyTraffic in last watchdog, using lower threshold. */
+ if (pmlmepriv->LinkDetectInfo.bBusyTraffic)
+ BusyThreshold = BusyThresholdLow;
+
+ if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > BusyThreshold ||
+ pmlmepriv->LinkDetectInfo.NumTxOkInPeriod > BusyThreshold) {
+ bBusyTraffic = true;
+
+ if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > pmlmepriv->LinkDetectInfo.NumTxOkInPeriod)
+ bRxBusyTraffic = true;
+ else
+ bTxBusyTraffic = true;
+ }
+
+ /* Higher Tx/Rx data. */
+ if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > 4000 ||
+ pmlmepriv->LinkDetectInfo.NumTxOkInPeriod > 4000) {
+ bHigherBusyTraffic = true;
+
+ if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > pmlmepriv->LinkDetectInfo.NumTxOkInPeriod)
+ bHigherBusyRxTraffic = true;
+ else
+ bHigherBusyTxTraffic = true;
+ }
+
+#ifdef CONFIG_TRAFFIC_PROTECT
+#define TX_ACTIVE_TH 10
+#define RX_ACTIVE_TH 20
+#define TRAFFIC_PROTECT_PERIOD_MS 4500
+
+ if (link_detect->NumTxOkInPeriod > TX_ACTIVE_TH
+ || link_detect->NumRxUnicastOkInPeriod > RX_ACTIVE_TH) {
+
+ RTW_INFO(FUNC_ADPT_FMT" acqiure wake_lock for %u ms(tx:%d,rx_unicast:%d)\n",
+ FUNC_ADPT_ARG(padapter),
+ TRAFFIC_PROTECT_PERIOD_MS,
+ link_detect->NumTxOkInPeriod,
+ link_detect->NumRxUnicastOkInPeriod);
+
+ rtw_lock_traffic_suspend_timeout(TRAFFIC_PROTECT_PERIOD_MS);
+ }
+#endif
+
+#ifdef CONFIG_TDLS
+#ifdef CONFIG_TDLS_AUTOSETUP
+ /* TDLS_WATCHDOG_PERIOD * 2sec, periodically send */
+ if (hal_chk_wl_func(padapter, WL_FUNC_TDLS) == true) {
+ if ((ptdlsinfo->watchdog_count % TDLS_WATCHDOG_PERIOD) == 0) {
+ memcpy(txmgmt.peer, baddr, ETH_ALEN);
+ issue_tdls_dis_req(padapter, &txmgmt);
+ }
+ ptdlsinfo->watchdog_count++;
+ }
+#endif /* CONFIG_TDLS_AUTOSETUP */
+#endif /* CONFIG_TDLS */
+
+#ifdef CONFIG_LPS
+ /* check traffic for powersaving. */
+ if (((pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod + pmlmepriv->LinkDetectInfo.NumTxOkInPeriod) > 8) ||
+#ifdef CONFIG_LPS_SLOW_TRANSITION
+ (pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod > 2)
+#else /* CONFIG_LPS_SLOW_TRANSITION */
+ (pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod > 4)
+#endif /* CONFIG_LPS_SLOW_TRANSITION */
+ ) {
+#ifdef DBG_RX_COUNTER_DUMP
+ if (padapter->dump_rx_cnt_mode & DUMP_DRV_TRX_COUNTER_DATA)
+ RTW_INFO("(-)Tx = %d, Rx = %d\n", pmlmepriv->LinkDetectInfo.NumTxOkInPeriod, pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod);
+#endif
+ bEnterPS = false;
+#ifdef CONFIG_LPS_SLOW_TRANSITION
+ if (bBusyTraffic == true) {
+ if (pmlmepriv->LinkDetectInfo.TrafficTransitionCount <= 4)
+ pmlmepriv->LinkDetectInfo.TrafficTransitionCount = 4;
+
+ pmlmepriv->LinkDetectInfo.TrafficTransitionCount++;
+
+ /* RTW_INFO("Set TrafficTransitionCount to %d\n", pmlmepriv->LinkDetectInfo.TrafficTransitionCount); */
+
+ if (pmlmepriv->LinkDetectInfo.TrafficTransitionCount > 30/*TrafficTransitionLevel*/)
+ pmlmepriv->LinkDetectInfo.TrafficTransitionCount = 30;
+ }
+#endif /* CONFIG_LPS_SLOW_TRANSITION */
+
+ } else {
+#ifdef DBG_RX_COUNTER_DUMP
+ if (padapter->dump_rx_cnt_mode & DUMP_DRV_TRX_COUNTER_DATA)
+ RTW_INFO("(+)Tx = %d, Rx = %d\n", pmlmepriv->LinkDetectInfo.NumTxOkInPeriod, pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod);
+#endif
+#ifdef CONFIG_LPS_SLOW_TRANSITION
+ if (pmlmepriv->LinkDetectInfo.TrafficTransitionCount >= 2)
+ pmlmepriv->LinkDetectInfo.TrafficTransitionCount -= 2;
+ else
+ pmlmepriv->LinkDetectInfo.TrafficTransitionCount = 0;
+
+ if (pmlmepriv->LinkDetectInfo.TrafficTransitionCount == 0)
+ bEnterPS = true;
+#else /* CONFIG_LPS_SLOW_TRANSITION */
+ bEnterPS = true;
+#endif /* CONFIG_LPS_SLOW_TRANSITION */
+ }
+
+#ifdef CONFIG_DYNAMIC_DTIM
+ if (pmlmepriv->LinkDetectInfo.LowPowerTransitionCount == 8)
+ bEnterPS = false;
+
+ RTW_INFO("LowPowerTransitionCount=%d\n", pmlmepriv->LinkDetectInfo.LowPowerTransitionCount);
+#endif /* CONFIG_DYNAMIC_DTIM */
+
+ /* LeisurePS only work in infra mode. */
+ if (bEnterPS) {
+ if (!from_timer) {
+#ifdef CONFIG_DYNAMIC_DTIM
+ if (pmlmepriv->LinkDetectInfo.LowPowerTransitionCount < 8)
+ adapter_to_pwrctl(padapter)->dtim = 1;
+ else
+ adapter_to_pwrctl(padapter)->dtim = 3;
+#endif /* CONFIG_DYNAMIC_DTIM */
+ LPS_Enter(padapter, "TRAFFIC_IDLE");
+ } else {
+ /* do this at caller */
+ /* rtw_lps_ctrl_wk_cmd(adapter, LPS_CTRL_ENTER, 1); */
+ /* rtw_hal_dm_watchdog_in_lps(padapter); */
+ }
+#ifdef CONFIG_DYNAMIC_DTIM
+ if (adapter_to_pwrctl(padapter)->bFwCurrentInPSMode == true)
+ pmlmepriv->LinkDetectInfo.LowPowerTransitionCount++;
+#endif /* CONFIG_DYNAMIC_DTIM */
+ } else {
+#ifdef CONFIG_DYNAMIC_DTIM
+ if (pmlmepriv->LinkDetectInfo.LowPowerTransitionCount != 8)
+ pmlmepriv->LinkDetectInfo.LowPowerTransitionCount = 0;
+ else
+ pmlmepriv->LinkDetectInfo.LowPowerTransitionCount++;
+#endif /* CONFIG_DYNAMIC_DTIM */
+ if (!from_timer)
+ LPS_Leave(padapter, "TRAFFIC_BUSY");
+ else {
+#ifdef CONFIG_CONCURRENT_MODE
+ #ifndef CONFIG_FW_MULTI_PORT_SUPPORT
+ if (padapter->hw_port == HW_PORT0)
+ #endif
+#endif
+ rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_TRAFFIC_BUSY, 1);
+ }
+ }
+
+#endif /* CONFIG_LPS */
+ } else {
+#ifdef CONFIG_LPS
+ struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
+ int n_assoc_iface = 0;
+ int i;
+
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ if (check_fwstate(&(dvobj->padapters[i]->mlmepriv), WIFI_ASOC_STATE))
+ n_assoc_iface++;
+ }
+
+ if (!from_timer && n_assoc_iface == 0)
+ LPS_Leave(padapter, "NON_LINKED");
+#endif
+ }
+
+ session_tracker_chk_cmd(padapter, NULL);
+
+#ifdef CONFIG_BEAMFORMING
+#ifdef RTW_BEAMFORMING_VERSION_2
+ rtw_bf_update_traffic(padapter);
+#endif /* RTW_BEAMFORMING_VERSION_2 */
+#endif /* CONFIG_BEAMFORMING */
+
+ pmlmepriv->LinkDetectInfo.NumRxOkInPeriod = 0;
+ pmlmepriv->LinkDetectInfo.NumTxOkInPeriod = 0;
+ pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
+ pmlmepriv->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
+ pmlmepriv->LinkDetectInfo.bTxBusyTraffic = bTxBusyTraffic;
+ pmlmepriv->LinkDetectInfo.bRxBusyTraffic = bRxBusyTraffic;
+ pmlmepriv->LinkDetectInfo.bHigherBusyTraffic = bHigherBusyTraffic;
+ pmlmepriv->LinkDetectInfo.bHigherBusyRxTraffic = bHigherBusyRxTraffic;
+ pmlmepriv->LinkDetectInfo.bHigherBusyTxTraffic = bHigherBusyTxTraffic;
+
+ return bEnterPS;
+
+}
+
+
+/* for 11n Logo 4.2.31/4.2.32 */
+static void dynamic_update_bcn_check(_adapter *padapter)
+{
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+
+ if (!padapter->registrypriv.wifi_spec)
+ return;
+
+ if (!MLME_IS_AP(padapter))
+ return;
+
+ if (pmlmeext->bstart_bss) {
+ /* In 10 * 2 = 20s, there are no legacy AP, update HT info */
+ static u8 count = 1;
+
+ if (count % 10 == 0) {
+ count = 1;
+
+ if (false == ATOMIC_READ(&pmlmepriv->olbc)
+ && false == ATOMIC_READ(&pmlmepriv->olbc_ht)) {
+
+ if (rtw_ht_operation_update(padapter) > 0) {
+ update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, false);
+ update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, true);
+ }
+ }
+ }
+
+ /* In 2s, there are any legacy AP, update HT info, and then reset count */
+
+ if (ATOMIC_READ(&pmlmepriv->olbc) && ATOMIC_READ(&pmlmepriv->olbc_ht)) {
+ if (rtw_ht_operation_update(padapter) > 0) {
+ update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, false);
+ update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, true);
+
+ }
+ ATOMIC_SET(&pmlmepriv->olbc, false);
+ ATOMIC_SET(&pmlmepriv->olbc_ht, false);
+ count = 0;
+ }
+
+ count++;
+ }
+}
+void rtw_iface_dynamic_chk_wk_hdl(_adapter *padapter)
+{
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+
+ #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
+ #ifdef CONFIG_AP_MODE
+ if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
+ expire_timeout_chk(padapter);
+ #endif
+ #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
+ dynamic_update_bcn_check(padapter);
+
+ linked_status_chk(padapter, 0);
+ traffic_status_watchdog(padapter, 0);
+
+ /* for debug purpose */
+ _linked_info_dump(padapter);
+
+ #ifdef CONFIG_BEAMFORMING
+ #ifndef RTW_BEAMFORMING_VERSION_2
+ #if (BEAMFORMING_SUPPORT == 0) /*for diver defined beamforming*/
+ beamforming_watchdog(padapter);
+ #endif
+ #endif /* !RTW_BEAMFORMING_VERSION_2 */
+ #endif
+
+}
+static void rtw_dynamic_chk_wk_hdl(_adapter *padapter)
+{
+ rtw_mi_dynamic_chk_wk_hdl(padapter);
+
+#ifdef DBG_CONFIG_ERROR_DETECT
+ rtw_hal_sreset_xmit_status_check(padapter);
+ rtw_hal_sreset_linked_status_check(padapter);
+#endif
+
+ /* if(check_fwstate(pmlmepriv, _FW_UNDER_LINKING|_FW_UNDER_SURVEY)==false) */
+ {
+#ifdef DBG_RX_COUNTER_DUMP
+ rtw_dump_rx_counters(padapter);
+#endif
+ dm_DynamicUsbTxAgg(padapter, 0);
+ }
+ rtw_hal_dm_watchdog(padapter);
+
+ /* check_hw_pbc(padapter, pdrvextra_cmd->pbuf, pdrvextra_cmd->type); */
+
+#ifdef CONFIG_BT_COEXIST
+ /* BT-Coexist */
+ rtw_btcoex_Handler(padapter);
+#endif
+
+#ifdef CONFIG_IPS_CHECK_IN_WD
+ /* always call rtw_ps_processor() at last one. */
+ rtw_ps_processor(padapter);
+#endif
+
+#ifdef CONFIG_MCC_MODE
+ rtw_hal_mcc_sw_status_check(padapter);
+#endif /* CONFIG_MCC_MODE */
+
+}
+
+#ifdef CONFIG_LPS
+
+void lps_ctrl_wk_hdl(_adapter *padapter, u8 lps_ctrl_type);
+void lps_ctrl_wk_hdl(_adapter *padapter, u8 lps_ctrl_type)
+{
+ struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ u8 mstatus;
+
+
+ if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)
+ || (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true))
+ return;
+
+ switch (lps_ctrl_type) {
+ case LPS_CTRL_SCAN:
+ /* RTW_INFO("LPS_CTRL_SCAN\n"); */
+#ifdef CONFIG_BT_COEXIST
+ rtw_btcoex_ScanNotify(padapter, true);
+#endif /* CONFIG_BT_COEXIST */
+ if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
+ /* connect */
+ LPS_Leave(padapter, "LPS_CTRL_SCAN");
+ }
+ break;
+ case LPS_CTRL_JOINBSS:
+ /* RTW_INFO("LPS_CTRL_JOINBSS\n"); */
+ LPS_Leave(padapter, "LPS_CTRL_JOINBSS");
+ break;
+ case LPS_CTRL_CONNECT:
+ /* RTW_INFO("LPS_CTRL_CONNECT\n"); */
+ mstatus = 1;/* connect */
+ /* Reset LPS Setting */
+ pwrpriv->LpsIdleCount = 0;
+ rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_JOINBSSRPT, (u8 *)(&mstatus));
+#ifdef CONFIG_BT_COEXIST
+ rtw_btcoex_MediaStatusNotify(padapter, mstatus);
+#endif /* CONFIG_BT_COEXIST */
+ break;
+ case LPS_CTRL_DISCONNECT:
+ /* RTW_INFO("LPS_CTRL_DISCONNECT\n"); */
+ mstatus = 0;/* disconnect */
+#ifdef CONFIG_BT_COEXIST
+ rtw_btcoex_MediaStatusNotify(padapter, mstatus);
+#endif /* CONFIG_BT_COEXIST */
+ LPS_Leave(padapter, "LPS_CTRL_DISCONNECT");
+ rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_JOINBSSRPT, (u8 *)(&mstatus));
+ break;
+ case LPS_CTRL_SPECIAL_PACKET:
+ /* RTW_INFO("LPS_CTRL_SPECIAL_PACKET\n"); */
+ pwrpriv->DelayLPSLastTimeStamp = jiffies;
+#ifdef CONFIG_BT_COEXIST
+ rtw_btcoex_SpecialPacketNotify(padapter, PACKET_DHCP);
+#endif /* CONFIG_BT_COEXIST */
+ LPS_Leave(padapter, "LPS_CTRL_SPECIAL_PACKET");
+ break;
+ case LPS_CTRL_LEAVE:
+ LPS_Leave(padapter, "LPS_CTRL_LEAVE");
+ break;
+ case LPS_CTRL_LEAVE_CFG80211_PWRMGMT:
+ LPS_Leave(padapter, "CFG80211_PWRMGMT");
+ break;
+ case LPS_CTRL_TRAFFIC_BUSY:
+ LPS_Leave(padapter, "LPS_CTRL_TRAFFIC_BUSY");
+ break;
+ case LPS_CTRL_TX_TRAFFIC_LEAVE:
+ LPS_Leave(padapter, "LPS_CTRL_TX_TRAFFIC_LEAVE");
+ break;
+ case LPS_CTRL_RX_TRAFFIC_LEAVE:
+ LPS_Leave(padapter, "LPS_CTRL_RX_TRAFFIC_LEAVE");
+ break;
+ case LPS_CTRL_ENTER:
+ LPS_Enter(padapter, "TRAFFIC_IDLE_1");
+ break;
+ default:
+ break;
+ }
+
+}
+
+u8 rtw_lps_ctrl_wk_cmd(_adapter *padapter, u8 lps_ctrl_type, u8 enqueue)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ /* struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter); */
+ u8 res = _SUCCESS;
+
+
+ /* if(!pwrctrlpriv->bLeisurePs) */
+ /* return res; */
+
+ if (enqueue) {
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (ph2c == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (pdrvextra_cmd_parm == NULL) {
+ rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm->ec_id = LPS_CTRL_WK_CID;
+ pdrvextra_cmd_parm->type = lps_ctrl_type;
+ pdrvextra_cmd_parm->size = 0;
+ pdrvextra_cmd_parm->pbuf = NULL;
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+ } else
+ lps_ctrl_wk_hdl(padapter, lps_ctrl_type);
+
+exit:
+
+
+ return res;
+
+}
+
+static void rtw_dm_in_lps_hdl(_adapter *padapter)
+{
+ rtw_hal_set_hwreg(padapter, HW_VAR_DM_IN_LPS, NULL);
+}
+
+u8 rtw_dm_in_lps_wk_cmd(_adapter *padapter)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (ph2c == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (pdrvextra_cmd_parm == NULL) {
+ rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm->ec_id = DM_IN_LPS_WK_CID;
+ pdrvextra_cmd_parm->type = 0;
+ pdrvextra_cmd_parm->size = 0;
+ pdrvextra_cmd_parm->pbuf = NULL;
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+
+ return res;
+
+}
+
+static void rtw_lps_change_dtim_hdl(_adapter *padapter, u8 dtim)
+{
+ struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
+
+ if (dtim <= 0 || dtim > 16)
+ return;
+
+#ifdef CONFIG_BT_COEXIST
+ if (rtw_btcoex_IsBtControlLps(padapter) == true)
+ return;
+#endif
+
+#ifdef CONFIG_LPS_LCLK
+ _enter_pwrlock(&pwrpriv->lock);
+#endif
+
+ if (pwrpriv->dtim != dtim) {
+ RTW_INFO("change DTIM from %d to %d, bFwCurrentInPSMode=%d, ps_mode=%d\n", pwrpriv->dtim, dtim,
+ pwrpriv->bFwCurrentInPSMode, pwrpriv->pwr_mode);
+
+ pwrpriv->dtim = dtim;
+ }
+
+ if ((pwrpriv->bFwCurrentInPSMode == true) && (pwrpriv->pwr_mode > PS_MODE_ACTIVE)) {
+ u8 ps_mode = pwrpriv->pwr_mode;
+
+ /* RTW_INFO("change DTIM from %d to %d, ps_mode=%d\n", pwrpriv->dtim, dtim, ps_mode); */
+
+ rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&ps_mode));
+ }
+
+#ifdef CONFIG_LPS_LCLK
+ _exit_pwrlock(&pwrpriv->lock);
+#endif
+
+}
+
+#endif
+
+u8 rtw_lps_change_dtim_cmd(_adapter *padapter, u8 dtim)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (!pdrvextra_cmd_parm) {
+ rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm->ec_id = LPS_CHANGE_DTIM_CID;
+ pdrvextra_cmd_parm->type = dtim;
+ pdrvextra_cmd_parm->size = 0;
+ pdrvextra_cmd_parm->pbuf = NULL;
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+
+ return res;
+}
+
+#if (RATE_ADAPTIVE_SUPPORT == 1)
+static void rpt_timer_setting_wk_hdl(_adapter *padapter, u16 minRptTime)
+{
+ rtw_hal_set_hwreg(padapter, HW_VAR_RPT_TIMER_SETTING, (u8 *)(&minRptTime));
+}
+
+u8 rtw_rpt_timer_cfg_cmd(_adapter *padapter, u16 minRptTime)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (ph2c == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (pdrvextra_cmd_parm == NULL) {
+ rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm->ec_id = RTP_TIMER_CFG_WK_CID;
+ pdrvextra_cmd_parm->type = minRptTime;
+ pdrvextra_cmd_parm->size = 0;
+ pdrvextra_cmd_parm->pbuf = NULL;
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+exit:
+
+
+ return res;
+
+}
+
+#endif
+
+#ifdef CONFIG_ANTENNA_DIVERSITY
+void antenna_select_wk_hdl(_adapter *padapter, u8 antenna)
+{
+ rtw_hal_set_odm_var(padapter, HAL_ODM_ANTDIV_SELECT, &antenna, true);
+}
+
+u8 rtw_antenna_select_cmd(_adapter *padapter, u8 antenna, u8 enqueue)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
+ u8 bSupportAntDiv = false;
+ u8 res = _SUCCESS;
+ int i;
+
+ rtw_hal_get_def_var(padapter, HAL_DEF_IS_SUPPORT_ANT_DIV, &(bSupportAntDiv));
+ if (false == bSupportAntDiv)
+ return _FAIL;
+
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ if (rtw_linked_check(dvobj->padapters[i]))
+ return _FAIL;
+ }
+
+ if (enqueue) {
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (ph2c == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (pdrvextra_cmd_parm == NULL) {
+ rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm->ec_id = ANT_SELECT_WK_CID;
+ pdrvextra_cmd_parm->type = antenna;
+ pdrvextra_cmd_parm->size = 0;
+ pdrvextra_cmd_parm->pbuf = NULL;
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+ } else
+ antenna_select_wk_hdl(padapter, antenna);
+exit:
+
+
+ return res;
+
+}
+#endif
+
+static void rtw_dm_ra_mask_hdl(_adapter *padapter, struct sta_info *psta)
+{
+ if (psta)
+ set_sta_rate(padapter, psta);
+}
+
+u8 rtw_dm_ra_mask_wk_cmd(_adapter *padapter, u8 *psta)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (ph2c == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (pdrvextra_cmd_parm == NULL) {
+ rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm->ec_id = DM_RA_MSK_WK_CID;
+ pdrvextra_cmd_parm->type = 0;
+ pdrvextra_cmd_parm->size = 0;
+ pdrvextra_cmd_parm->pbuf = psta;
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+
+ return res;
+
+}
+
+static void power_saving_wk_hdl(_adapter *padapter)
+{
+ rtw_ps_processor(padapter);
+}
+
+/* add for CONFIG_IEEE80211W, none 11w can use it */
+static void reset_securitypriv_hdl(_adapter *padapter)
+{
+ rtw_reset_securitypriv(padapter);
+}
+
+static void free_assoc_resources_hdl(_adapter *padapter)
+{
+ rtw_free_assoc_resources(padapter, 1);
+}
+
+#ifdef CONFIG_P2P
+u8 p2p_protocol_wk_cmd(_adapter *padapter, int intCmdType)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+
+ if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
+ return res;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (ph2c == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (pdrvextra_cmd_parm == NULL) {
+ rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm->ec_id = P2P_PROTO_WK_CID;
+ pdrvextra_cmd_parm->type = intCmdType; /* As the command tppe. */
+ pdrvextra_cmd_parm->size = 0;
+ pdrvextra_cmd_parm->pbuf = NULL; /* Must be NULL here */
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+
+
+ return res;
+
+}
+
+#ifdef CONFIG_IOCTL_CFG80211
+static u8 _p2p_roch_cmd(_adapter *adapter, u64 cookie,
+ struct wireless_dev *wdev,
+ struct ieee80211_channel *ch,
+ enum nl80211_channel_type ch_type,
+ unsigned int duration, u8 flags)
+{
+ struct cmd_obj *cmdobj;
+ struct drvextra_cmd_parm *parm;
+ struct p2p_roch_parm *roch_parm;
+ struct cmd_priv *pcmdpriv = &adapter->cmdpriv;
+ struct submit_ctx sctx;
+ u8 cancel = duration ? 0 : 1;
+ u8 res = _SUCCESS;
+
+ roch_parm = (struct p2p_roch_parm *)rtw_zmalloc(sizeof(struct p2p_roch_parm));
+ if (!roch_parm) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ roch_parm->cookie = cookie;
+ roch_parm->wdev = wdev;
+ if (!cancel) {
+ memcpy(&roch_parm->ch, ch, sizeof(struct ieee80211_channel));
+ roch_parm->ch_type = ch_type;
+ roch_parm->duration = duration;
+ }
+
+ if (flags & RTW_CMDF_DIRECTLY) {
+ /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
+ if (p2p_protocol_wk_hdl(adapter,
+ cancel ? P2P_CANCEL_RO_CH_WK : P2P_RO_CH_WK,
+ (u8 *)roch_parm) != H2C_SUCCESS)
+ res = _FAIL;
+ rtw_mfree((u8 *)roch_parm, sizeof(*roch_parm));
+ } else {
+ /* need enqueue, prepare cmd_obj and enqueue */
+ parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (parm == NULL) {
+ rtw_mfree((u8 *)roch_parm, sizeof(*roch_parm));
+ res = _FAIL;
+ goto exit;
+ }
+
+ parm->ec_id = P2P_PROTO_WK_CID;
+ parm->type = cancel ? P2P_CANCEL_RO_CH_WK : P2P_RO_CH_WK;
+ parm->size = sizeof(*roch_parm);
+ parm->pbuf = (u8 *)roch_parm;
+
+ cmdobj = (struct cmd_obj *)rtw_zmalloc(sizeof(*cmdobj));
+ if (cmdobj == NULL) {
+ res = _FAIL;
+ rtw_mfree((u8 *)roch_parm, sizeof(*roch_parm));
+ rtw_mfree((u8 *)parm, sizeof(*parm));
+ goto exit;
+ }
+
+ init_h2fwcmd_w_parm_no_rsp(cmdobj, parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ if (flags & RTW_CMDF_WAIT_ACK) {
+ cmdobj->sctx = &sctx;
+ rtw_sctx_init(&sctx, 10 * 1000);
+ }
+
+ res = rtw_enqueue_cmd(pcmdpriv, cmdobj);
+
+ if (res == _SUCCESS && (flags & RTW_CMDF_WAIT_ACK)) {
+ rtw_sctx_wait(&sctx, __func__);
+ _enter_critical_mutex(&pcmdpriv->sctx_mutex, NULL);
+ if (sctx.status == RTW_SCTX_SUBMITTED)
+ cmdobj->sctx = NULL;
+ _exit_critical_mutex(&pcmdpriv->sctx_mutex, NULL);
+ if (sctx.status != RTW_SCTX_DONE_SUCCESS)
+ res = _FAIL;
+ }
+ }
+
+exit:
+ return res;
+}
+
+inline u8 p2p_roch_cmd(_adapter *adapter
+ , u64 cookie, struct wireless_dev *wdev
+ , struct ieee80211_channel *ch, enum nl80211_channel_type ch_type
+ , unsigned int duration
+ , u8 flags
+)
+{
+ return _p2p_roch_cmd(adapter, cookie, wdev, ch, ch_type, duration, flags);
+}
+
+inline u8 p2p_cancel_roch_cmd(_adapter *adapter, u64 cookie, struct wireless_dev *wdev, u8 flags)
+{
+ return _p2p_roch_cmd(adapter, cookie, wdev, NULL, 0, 0, flags);
+}
+#endif /* CONFIG_IOCTL_CFG80211 */
+#endif /* CONFIG_P2P */
+
+u8 rtw_ps_cmd(_adapter *padapter)
+{
+ struct cmd_obj *ppscmd;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+
+ u8 res = _SUCCESS;
+
+#ifdef CONFIG_CONCURRENT_MODE
+ if (padapter->adapter_type != PRIMARY_ADAPTER)
+ goto exit;
+#endif
+
+ ppscmd = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (ppscmd == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (pdrvextra_cmd_parm == NULL) {
+ rtw_mfree((unsigned char *)ppscmd, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm->ec_id = POWER_SAVING_CTRL_WK_CID;
+ pdrvextra_cmd_parm->type = 0;
+ pdrvextra_cmd_parm->size = 0;
+ pdrvextra_cmd_parm->pbuf = NULL;
+ init_h2fwcmd_w_parm_no_rsp(ppscmd, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ppscmd);
+
+exit:
+
+
+ return res;
+
+}
+
+#ifdef CONFIG_AP_MODE
+
+static void rtw_chk_hi_queue_hdl(_adapter *padapter)
+{
+ struct sta_info *psta_bmc;
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ u32 start = jiffies;
+ u8 empty = false;
+
+ psta_bmc = rtw_get_bcmc_stainfo(padapter);
+ if (!psta_bmc)
+ return;
+
+ rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty);
+
+ while (false == empty && rtw_get_passing_time_ms(start) < rtw_get_wait_hiq_empty_ms()) {
+ rtw_msleep_os(100);
+ rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty);
+ }
+
+ if (psta_bmc->sleepq_len == 0) {
+ if (empty == _SUCCESS) {
+ bool update_tim = false;
+
+ if (pstapriv->tim_bitmap & BIT(0))
+ update_tim = true;
+
+ pstapriv->tim_bitmap &= ~BIT(0);
+ pstapriv->sta_dz_bitmap &= ~BIT(0);
+
+ if (update_tim == true)
+ _update_beacon(padapter, _TIM_IE_, NULL, true, "bmc sleepq and HIQ empty");
+ } else /* re check again */
+ rtw_chk_hi_queue_cmd(padapter);
+
+ }
+
+}
+
+u8 rtw_chk_hi_queue_cmd(_adapter *padapter)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (ph2c == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (pdrvextra_cmd_parm == NULL) {
+ rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm->ec_id = CHECK_HIQ_WK_CID;
+ pdrvextra_cmd_parm->type = 0;
+ pdrvextra_cmd_parm->size = 0;
+ pdrvextra_cmd_parm->pbuf = NULL;
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+
+ return res;
+
+}
+
+#ifdef CONFIG_DFS_MASTER
+u8 rtw_dfs_master_hdl(_adapter *adapter)
+{
+ struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
+ struct mlme_priv *mlme = &adapter->mlmepriv;
+
+ if (!rfctl->dfs_master_enabled)
+ goto exit;
+
+ if (rtw_get_on_cur_ch_time(adapter) == 0
+ || rtw_get_passing_time_ms(rtw_get_on_cur_ch_time(adapter)) < 300
+ ) {
+ /* offchannel , bypass radar detect */
+ goto cac_status_chk;
+ }
+
+ if (IS_CH_WAITING(rfctl) && !IS_UNDER_CAC(rfctl)) {
+ /* non_ocp, bypass radar detect */
+ goto cac_status_chk;
+ }
+
+ if (!rfctl->dbg_dfs_master_fake_radar_detect_cnt
+ && rtw_odm_radar_detect(adapter) != true)
+ goto cac_status_chk;
+
+ if (rfctl->dbg_dfs_master_fake_radar_detect_cnt != 0) {
+ RTW_INFO(FUNC_ADPT_FMT" fake radar detect, cnt:%d\n", FUNC_ADPT_ARG(adapter)
+ , rfctl->dbg_dfs_master_fake_radar_detect_cnt);
+ rfctl->dbg_dfs_master_fake_radar_detect_cnt--;
+ }
+
+ if (rfctl->dbg_dfs_master_radar_detect_trigger_non) {
+ /* radar detect debug mode, trigger no mlme flow */
+ if (0)
+ RTW_INFO(FUNC_ADPT_FMT" radar detected, trigger no mlme flow for debug\n", FUNC_ADPT_ARG(adapter));
+ } else {
+ /* TODO: move timer to rfctl */
+ struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
+ int i;
+
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ if (!dvobj->padapters[i])
+ continue;
+ if (check_fwstate(&dvobj->padapters[i]->mlmepriv, WIFI_AP_STATE)
+ && check_fwstate(&dvobj->padapters[i]->mlmepriv, WIFI_ASOC_STATE))
+ break;
+ }
+
+ if (i >= dvobj->iface_nums) {
+ /* what? */
+ rtw_warn_on(1);
+ } else {
+ rtw_chset_update_non_ocp(dvobj->padapters[i]->mlmeextpriv.channel_set
+ , rfctl->radar_detect_ch, rfctl->radar_detect_bw, rfctl->radar_detect_offset);
+ rfctl->radar_detected = 1;
+
+ /* trigger channel selection */
+ rtw_change_bss_chbw_cmd(dvobj->padapters[i], RTW_CMDF_DIRECTLY, -1, dvobj->padapters[i]->mlmepriv.ori_bw, -1);
+ }
+
+ if (rfctl->dfs_master_enabled)
+ goto set_timer;
+ goto exit;
+ }
+
+cac_status_chk:
+
+ if (!IS_CH_WAITING(rfctl) && !IS_CAC_STOPPED(rfctl)) {
+ u8 pause = 0x00;
+
+ rtw_hal_set_hwreg(adapter, HW_VAR_TXPAUSE, &pause);
+ rfctl->cac_start_time = rfctl->cac_end_time = RTW_CAC_STOPPED;
+ }
+
+set_timer:
+ _set_timer(&mlme->dfs_master_timer, DFS_MASTER_TIMER_MS);
+
+exit:
+ return H2C_SUCCESS;
+}
+
+u8 rtw_dfs_master_cmd(_adapter *adapter, bool enqueue)
+{
+ struct cmd_obj *cmdobj;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct cmd_priv *pcmdpriv = &adapter->cmdpriv;
+ u8 res = _FAIL;
+
+ if (enqueue) {
+ cmdobj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (cmdobj == NULL)
+ goto exit;
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (pdrvextra_cmd_parm == NULL) {
+ rtw_mfree((u8 *)cmdobj, sizeof(struct cmd_obj));
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm->ec_id = DFS_MASTER_WK_CID;
+ pdrvextra_cmd_parm->type = 0;
+ pdrvextra_cmd_parm->size = 0;
+ pdrvextra_cmd_parm->pbuf = NULL;
+
+ init_h2fwcmd_w_parm_no_rsp(cmdobj, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+ res = rtw_enqueue_cmd(pcmdpriv, cmdobj);
+ } else {
+ rtw_dfs_master_hdl(adapter);
+ res = _SUCCESS;
+ }
+
+exit:
+ return res;
+}
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0)
+void rtw_dfs_master_timer_hdl(RTW_TIMER_HDL_ARGS)
+#else
+void rtw_dfs_master_timer_hdl(struct timer_list *t)
+#endif
+{
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0)
+ _adapter *adapter = (_adapter *)FunctionContext;
+#else
+ _adapter *adapter = from_timer(adapter, t, dfs_master_timer);
+#endif
+ rtw_dfs_master_cmd(adapter, true);
+}
+
+void rtw_dfs_master_enable(_adapter *adapter, u8 ch, u8 bw, u8 offset)
+{
+ struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
+
+ /* TODO: move timer to rfctl */
+ adapter = GET_PRIMARY_ADAPTER(adapter);
+
+ RTW_INFO(FUNC_ADPT_FMT" on %u,%u,%u\n", FUNC_ADPT_ARG(adapter), ch, bw, offset);
+
+ if (rtw_is_cac_reset_needed(adapter, ch, bw, offset) == true)
+ rtw_reset_cac(adapter, ch, bw, offset);
+
+ rfctl->radar_detect_by_others = false;
+ rfctl->radar_detect_ch = ch;
+ rfctl->radar_detect_bw = bw;
+ rfctl->radar_detect_offset = offset;
+
+ rfctl->radar_detected = 0;
+
+ if (!rfctl->dfs_master_enabled) {
+ RTW_INFO(FUNC_ADPT_FMT" set dfs_master_enabled\n", FUNC_ADPT_ARG(adapter));
+ rfctl->dfs_master_enabled = 1;
+ _set_timer(&adapter->mlmepriv.dfs_master_timer, DFS_MASTER_TIMER_MS);
+
+ if (rtw_rfctl_overlap_radar_detect_ch(rfctl)) {
+ if (IS_CH_WAITING(rfctl)) {
+ u8 pause = 0xFF;
+
+ rtw_hal_set_hwreg(adapter, HW_VAR_TXPAUSE, &pause);
+ }
+ rtw_odm_radar_detect_enable(adapter);
+ }
+ }
+}
+
+void rtw_dfs_master_disable(_adapter *adapter, u8 ch, u8 bw, u8 offset, bool by_others)
+{
+ struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
+
+ /* TODO: move timer to rfctl */
+ adapter = GET_PRIMARY_ADAPTER(adapter);
+
+ rfctl->radar_detect_by_others = by_others;
+
+ if (rfctl->dfs_master_enabled) {
+ bool overlap_radar_detect_ch = rtw_rfctl_overlap_radar_detect_ch(rfctl);
+
+ RTW_INFO(FUNC_ADPT_FMT" clear dfs_master_enabled\n", FUNC_ADPT_ARG(adapter));
+
+ rfctl->dfs_master_enabled = 0;
+ rfctl->radar_detected = 0;
+ rfctl->radar_detect_ch = 0;
+ rfctl->radar_detect_bw = 0;
+ rfctl->radar_detect_offset = 0;
+ rfctl->cac_start_time = rfctl->cac_end_time = RTW_CAC_STOPPED;
+ _cancel_timer_ex(&adapter->mlmepriv.dfs_master_timer);
+
+ if (overlap_radar_detect_ch) {
+ u8 pause = 0x00;
+
+ rtw_hal_set_hwreg(adapter, HW_VAR_TXPAUSE, &pause);
+ rtw_odm_radar_detect_disable(adapter);
+ }
+ }
+
+ if (by_others) {
+ rfctl->radar_detect_ch = ch;
+ rfctl->radar_detect_bw = bw;
+ rfctl->radar_detect_offset = offset;
+ }
+}
+
+void rtw_dfs_master_status_apply(_adapter *adapter, u8 self_action)
+{
+ struct mlme_ext_priv *mlmeext = &adapter->mlmeextpriv;
+ struct mi_state mstate;
+ u8 u_ch, u_bw, u_offset;
+ bool ld_sta_in_dfs = false;
+ bool sync_ch = false; /* false: asign channel directly */
+ bool needed = false;
+
+ rtw_mi_status_no_self(adapter, &mstate);
+ rtw_mi_get_ch_setting_union_no_self(adapter, &u_ch, &u_bw, &u_offset);
+ if (u_ch != 0)
+ sync_ch = true;
+
+ switch (self_action) {
+ case MLME_STA_CONNECTING:
+ MSTATE_STA_LG_NUM(&mstate)++;
+ break;
+ case MLME_STA_CONNECTED:
+ MSTATE_STA_LD_NUM(&mstate)++;
+ break;
+ case MLME_AP_STARTED:
+ MSTATE_AP_NUM(&mstate)++;
+ break;
+ case MLME_AP_STOPPED:
+ case MLME_STA_DISCONNECTED:
+ default:
+ break;
+ }
+
+ if (sync_ch == true) {
+ if (!rtw_is_chbw_grouped(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset, u_ch, u_bw, u_offset)) {
+ RTW_INFO(FUNC_ADPT_FMT" can't sync %u,%u,%u with %u,%u,%u\n", FUNC_ADPT_ARG(adapter)
+ , mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset, u_ch, u_bw, u_offset);
+ goto apply;
+ }
+
+ rtw_sync_chbw(&mlmeext->cur_channel, &mlmeext->cur_bwmode, &mlmeext->cur_ch_offset
+ , &u_ch, &u_bw, &u_offset);
+ } else {
+ u_ch = mlmeext->cur_channel;
+ u_bw = mlmeext->cur_bwmode;
+ u_offset = mlmeext->cur_ch_offset;
+ }
+
+ if (MSTATE_STA_LD_NUM(&mstate) > 0) {
+ /* rely on AP on which STA mode connects */
+ if (rtw_is_dfs_ch(u_ch, u_bw, u_offset))
+ ld_sta_in_dfs = true;
+ goto apply;
+ }
+
+ if (MSTATE_STA_LG_NUM(&mstate) > 0) {
+ /* STA mode is linking */
+ goto apply;
+ }
+
+ if (MSTATE_AP_NUM(&mstate) == 0) {
+ /* No working AP mode */
+ goto apply;
+ }
+
+ if (rtw_is_dfs_ch(u_ch, u_bw, u_offset))
+ needed = true;
+
+apply:
+
+ RTW_INFO(FUNC_ADPT_FMT" needed:%d, self_action:%u\n"
+ , FUNC_ADPT_ARG(adapter), needed, self_action);
+ RTW_INFO(FUNC_ADPT_FMT" ld_sta_num:%u, lg_sta_num:%u, ap_num:%u, %u,%u,%u\n"
+ , FUNC_ADPT_ARG(adapter), MSTATE_STA_LD_NUM(&mstate), MSTATE_STA_LG_NUM(&mstate), MSTATE_AP_NUM(&mstate)
+ , u_ch, u_bw, u_offset);
+
+ if (needed == true)
+ rtw_dfs_master_enable(adapter, u_ch, u_bw, u_offset);
+ else
+ rtw_dfs_master_disable(adapter, u_ch, u_bw, u_offset, ld_sta_in_dfs);
+}
+#endif /* CONFIG_DFS_MASTER */
+
+#endif /* CONFIG_AP_MODE */
+
+#ifdef CONFIG_BT_COEXIST
+struct btinfo {
+ u8 cid;
+ u8 len;
+
+ u8 bConnection:1;
+ u8 bSCOeSCO:1;
+ u8 bInQPage:1;
+ u8 bACLBusy:1;
+ u8 bSCOBusy:1;
+ u8 bHID:1;
+ u8 bA2DP:1;
+ u8 bFTP:1;
+
+ u8 retry_cnt:4;
+ u8 rsvd_34:1;
+ u8 rsvd_35:1;
+ u8 rsvd_36:1;
+ u8 rsvd_37:1;
+
+ u8 rssi;
+
+ u8 rsvd_50:1;
+ u8 rsvd_51:1;
+ u8 rsvd_52:1;
+ u8 rsvd_53:1;
+ u8 rsvd_54:1;
+ u8 rsvd_55:1;
+ u8 eSCO_SCO:1;
+ u8 Master_Slave:1;
+
+ u8 rsvd_6;
+ u8 rsvd_7;
+};
+
+void btinfo_evt_dump(void *sel, void *buf)
+{
+ struct btinfo *info = (struct btinfo *)buf;
+
+ RTW_PRINT_SEL(sel, "cid:0x%02x, len:%u\n", info->cid, info->len);
+
+ if (info->len > 2)
+ RTW_PRINT_SEL(sel, "byte2:%s%s%s%s%s%s%s%s\n"
+ , info->bConnection ? "bConnection " : ""
+ , info->bSCOeSCO ? "bSCOeSCO " : ""
+ , info->bInQPage ? "bInQPage " : ""
+ , info->bACLBusy ? "bACLBusy " : ""
+ , info->bSCOBusy ? "bSCOBusy " : ""
+ , info->bHID ? "bHID " : ""
+ , info->bA2DP ? "bA2DP " : ""
+ , info->bFTP ? "bFTP" : ""
+ );
+
+ if (info->len > 3)
+ RTW_PRINT_SEL(sel, "retry_cnt:%u\n", info->retry_cnt);
+
+ if (info->len > 4)
+ RTW_PRINT_SEL(sel, "rssi:%u\n", info->rssi);
+
+ if (info->len > 5)
+ RTW_PRINT_SEL(sel, "byte5:%s%s\n"
+ , info->eSCO_SCO ? "eSCO_SCO " : ""
+ , info->Master_Slave ? "Master_Slave " : ""
+ );
+}
+
+static void rtw_btinfo_hdl(_adapter *adapter, u8 *buf, u16 buf_len)
+{
+#define BTINFO_WIFI_FETCH 0x23
+#define BTINFO_BT_AUTO_RPT 0x27
+#ifdef CONFIG_BT_COEXIST_SOCKET_TRX
+ struct btinfo_8761ATV *info = (struct btinfo_8761ATV *)buf;
+#else /* !CONFIG_BT_COEXIST_SOCKET_TRX */
+ struct btinfo *info = (struct btinfo *)buf;
+#endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
+ u8 cmd_idx;
+ u8 len;
+
+ cmd_idx = info->cid;
+
+ if (info->len > buf_len - 2) {
+ rtw_warn_on(1);
+ len = buf_len - 2;
+ } else
+ len = info->len;
+
+ /* #define DBG_PROC_SET_BTINFO_EVT */
+#ifdef DBG_PROC_SET_BTINFO_EVT
+#ifdef CONFIG_BT_COEXIST_SOCKET_TRX
+ RTW_INFO("%s: btinfo[0]=%x,btinfo[1]=%x,btinfo[2]=%x,btinfo[3]=%x btinfo[4]=%x,btinfo[5]=%x,btinfo[6]=%x,btinfo[7]=%x\n"
+ , __func__, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
+#else/* !CONFIG_BT_COEXIST_SOCKET_TRX */
+ btinfo_evt_dump(RTW_DBGDUMP, info);
+#endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
+#endif /* DBG_PROC_SET_BTINFO_EVT */
+
+ /* transform BT-FW btinfo to WiFI-FW C2H format and notify */
+ if (cmd_idx == BTINFO_WIFI_FETCH)
+ buf[1] = 0;
+ else if (cmd_idx == BTINFO_BT_AUTO_RPT)
+ buf[1] = 2;
+#ifdef CONFIG_BT_COEXIST_SOCKET_TRX
+ else if (cmd_idx == 0x01 || cmd_idx == 0x02)
+ buf[1] = buf[0];
+#endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
+ rtw_btcoex_BtInfoNotify(adapter, len + 1, &buf[1]);
+}
+
+u8 rtw_btinfo_cmd(_adapter *adapter, u8 *buf, u16 len)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ u8 *btinfo;
+ struct cmd_priv *pcmdpriv = &adapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (ph2c == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (pdrvextra_cmd_parm == NULL) {
+ rtw_mfree((u8 *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ btinfo = rtw_zmalloc(len);
+ if (btinfo == NULL) {
+ rtw_mfree((u8 *)ph2c, sizeof(struct cmd_obj));
+ rtw_mfree((u8 *)pdrvextra_cmd_parm, sizeof(struct drvextra_cmd_parm));
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm->ec_id = BTINFO_WK_CID;
+ pdrvextra_cmd_parm->type = 0;
+ pdrvextra_cmd_parm->size = len;
+ pdrvextra_cmd_parm->pbuf = btinfo;
+
+ memcpy(btinfo, buf, len);
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+ return res;
+}
+#endif /* CONFIG_BT_COEXIST */
+
+u8 rtw_test_h2c_cmd(_adapter *adapter, u8 *buf, u8 len)
+{
+ struct cmd_obj *pcmdobj;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ u8 *ph2c_content;
+ struct cmd_priv *pcmdpriv = &adapter->cmdpriv;
+ u8 res = _SUCCESS;
+
+ pcmdobj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (pcmdobj == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (pdrvextra_cmd_parm == NULL) {
+ rtw_mfree((u8 *)pcmdobj, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ ph2c_content = rtw_zmalloc(len);
+ if (ph2c_content == NULL) {
+ rtw_mfree((u8 *)pcmdobj, sizeof(struct cmd_obj));
+ rtw_mfree((u8 *)pdrvextra_cmd_parm, sizeof(struct drvextra_cmd_parm));
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm->ec_id = TEST_H2C_CID;
+ pdrvextra_cmd_parm->type = 0;
+ pdrvextra_cmd_parm->size = len;
+ pdrvextra_cmd_parm->pbuf = ph2c_content;
+
+ memcpy(ph2c_content, buf, len);
+
+ init_h2fwcmd_w_parm_no_rsp(pcmdobj, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
+
+exit:
+ return res;
+}
+
+static s32 rtw_mp_cmd_hdl(_adapter *padapter, u8 mp_cmd_id)
+{
+ HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
+ int ret = H2C_SUCCESS;
+ u8 rfreg0;
+
+ if (mp_cmd_id == MP_START) {
+ if (padapter->registrypriv.mp_mode == 0) {
+ rtw_hal_deinit(padapter);
+ padapter->registrypriv.mp_mode = 1;
+#ifdef CONFIG_RF_POWER_TRIM
+ if (!IS_HARDWARE_TYPE_8814A(padapter) && !IS_HARDWARE_TYPE_8822B(padapter)) {
+ padapter->registrypriv.RegPwrTrimEnable = 1;
+ rtw_hal_read_chip_info(padapter);
+ }
+#endif /*CONFIG_RF_POWER_TRIM*/
+ rtw_hal_init(padapter);
+#ifdef RTW_HALMAC /*for New IC*/
+ MPT_InitializeAdapter(padapter, 1);
+#endif /* CONFIG_MP_INCLUDED */
+ }
+
+ if (padapter->registrypriv.mp_mode == 0) {
+ ret = H2C_REJECTED;
+ goto exit;
+ }
+
+ if (padapter->mppriv.mode == MP_OFF) {
+ if (mp_start_test(padapter) == _FAIL) {
+ ret = H2C_REJECTED;
+ goto exit;
+ }
+ padapter->mppriv.mode = MP_ON;
+ MPT_PwrCtlDM(padapter, 0);
+ }
+ padapter->mppriv.bmac_filter = false;
+ odm_write_dig(&pHalData->odmpriv, 0x20);
+ } else if (mp_cmd_id == MP_STOP) {
+ if (padapter->registrypriv.mp_mode == 1) {
+ MPT_DeInitAdapter(padapter);
+ rtw_hal_deinit(padapter);
+ padapter->registrypriv.mp_mode = 0;
+ rtw_hal_init(padapter);
+ }
+
+ if (padapter->mppriv.mode != MP_OFF) {
+ mp_stop_test(padapter);
+ padapter->mppriv.mode = MP_OFF;
+ }
+ } else {
+ RTW_INFO(FUNC_ADPT_FMT"invalid id:%d\n", FUNC_ADPT_ARG(padapter), mp_cmd_id);
+ ret = H2C_PARAMETERS_ERROR;
+ rtw_warn_on(1);
+ }
+
+exit:
+ return ret;
+}
+
+u8 rtw_mp_cmd(_adapter *adapter, u8 mp_cmd_id, u8 flags)
+{
+ struct cmd_obj *cmdobj;
+ struct drvextra_cmd_parm *parm;
+ struct cmd_priv *pcmdpriv = &adapter->cmdpriv;
+ struct submit_ctx sctx;
+ u8 res = _SUCCESS;
+
+ parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (!parm) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ parm->ec_id = MP_CMD_WK_CID;
+ parm->type = mp_cmd_id;
+ parm->size = 0;
+ parm->pbuf = NULL;
+
+ if (flags & RTW_CMDF_DIRECTLY) {
+ /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
+ if (rtw_mp_cmd_hdl(adapter, mp_cmd_id) != H2C_SUCCESS)
+ res = _FAIL;
+ rtw_mfree((u8 *)parm, sizeof(*parm));
+ } else {
+ /* need enqueue, prepare cmd_obj and enqueue */
+ cmdobj = (struct cmd_obj *)rtw_zmalloc(sizeof(*cmdobj));
+ if (cmdobj == NULL) {
+ res = _FAIL;
+ rtw_mfree((u8 *)parm, sizeof(*parm));
+ goto exit;
+ }
+
+ init_h2fwcmd_w_parm_no_rsp(cmdobj, parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ if (flags & RTW_CMDF_WAIT_ACK) {
+ cmdobj->sctx = &sctx;
+ rtw_sctx_init(&sctx, 10 * 1000);
+ }
+
+ res = rtw_enqueue_cmd(pcmdpriv, cmdobj);
+
+ if (res == _SUCCESS && (flags & RTW_CMDF_WAIT_ACK)) {
+ rtw_sctx_wait(&sctx, __func__);
+ _enter_critical_mutex(&pcmdpriv->sctx_mutex, NULL);
+ if (sctx.status == RTW_SCTX_SUBMITTED)
+ cmdobj->sctx = NULL;
+ _exit_critical_mutex(&pcmdpriv->sctx_mutex, NULL);
+ if (sctx.status != RTW_SCTX_DONE_SUCCESS)
+ res = _FAIL;
+ }
+ }
+
+exit:
+ return res;
+}
+
+#ifdef CONFIG_RTW_CUSTOMER_STR
+static s32 rtw_customer_str_cmd_hdl(_adapter *adapter, u8 write, const u8 *cstr)
+{
+ int ret = H2C_SUCCESS;
+
+ if (write)
+ ret = rtw_hal_h2c_customer_str_write(adapter, cstr);
+ else
+ ret = rtw_hal_h2c_customer_str_req(adapter);
+
+ return ret == _SUCCESS ? H2C_SUCCESS : H2C_REJECTED;
+}
+
+static u8 rtw_customer_str_cmd(_adapter *adapter, u8 write, const u8 *cstr)
+{
+ struct cmd_obj *cmdobj;
+ struct drvextra_cmd_parm *parm;
+ u8 *str = NULL;
+ struct cmd_priv *pcmdpriv = &adapter->cmdpriv;
+ struct submit_ctx sctx;
+ u8 res = _SUCCESS;
+
+ parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (parm == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ if (write) {
+ str = rtw_zmalloc(RTW_CUSTOMER_STR_LEN);
+ if (str == NULL) {
+ rtw_mfree((u8 *)parm, sizeof(struct drvextra_cmd_parm));
+ res = _FAIL;
+ goto exit;
+ }
+ }
+
+ parm->ec_id = CUSTOMER_STR_WK_CID;
+ parm->type = write;
+ parm->size = write ? RTW_CUSTOMER_STR_LEN : 0;
+ parm->pbuf = write ? str : NULL;
+
+ if (write)
+ memcpy(str, cstr, RTW_CUSTOMER_STR_LEN);
+
+ /* need enqueue, prepare cmd_obj and enqueue */
+ cmdobj = (struct cmd_obj *)rtw_zmalloc(sizeof(*cmdobj));
+ if (cmdobj == NULL) {
+ res = _FAIL;
+ rtw_mfree((u8 *)parm, sizeof(*parm));
+ if (write)
+ rtw_mfree(str, RTW_CUSTOMER_STR_LEN);
+ goto exit;
+ }
+
+ init_h2fwcmd_w_parm_no_rsp(cmdobj, parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ cmdobj->sctx = &sctx;
+ rtw_sctx_init(&sctx, 2 * 1000);
+
+ res = rtw_enqueue_cmd(pcmdpriv, cmdobj);
+
+ if (res == _SUCCESS) {
+ rtw_sctx_wait(&sctx, __func__);
+ _enter_critical_mutex(&pcmdpriv->sctx_mutex, NULL);
+ if (sctx.status == RTW_SCTX_SUBMITTED)
+ cmdobj->sctx = NULL;
+ _exit_critical_mutex(&pcmdpriv->sctx_mutex, NULL);
+ if (sctx.status != RTW_SCTX_DONE_SUCCESS)
+ res = _FAIL;
+ }
+
+exit:
+ return res;
+}
+
+inline u8 rtw_customer_str_req_cmd(_adapter *adapter)
+{
+ return rtw_customer_str_cmd(adapter, 0, NULL);
+}
+
+inline u8 rtw_customer_str_write_cmd(_adapter *adapter, const u8 *cstr)
+{
+ return rtw_customer_str_cmd(adapter, 1, cstr);
+}
+#endif /* CONFIG_RTW_CUSTOMER_STR */
+
+static u8 rtw_c2h_wk_cmd(PADAPTER padapter, u8 *pbuf, u16 length, u8 type)
+{
+ struct cmd_obj *ph2c;
+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
+ u8 *extra_cmd_buf;
+ u8 res = _SUCCESS;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (ph2c == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (pdrvextra_cmd_parm == NULL) {
+ rtw_mfree((u8 *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ extra_cmd_buf = rtw_zmalloc(length);
+ if (extra_cmd_buf == NULL) {
+ rtw_mfree((u8 *)ph2c, sizeof(struct cmd_obj));
+ rtw_mfree((u8 *)pdrvextra_cmd_parm, sizeof(struct drvextra_cmd_parm));
+ res = _FAIL;
+ goto exit;
+ }
+
+ memcpy(extra_cmd_buf, pbuf, length);
+ pdrvextra_cmd_parm->ec_id = C2H_WK_CID;
+ pdrvextra_cmd_parm->type = type;
+ pdrvextra_cmd_parm->size = length;
+ pdrvextra_cmd_parm->pbuf = extra_cmd_buf;
+
+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+
+exit:
+ return res;
+}
+
+#ifdef CONFIG_FW_C2H_REG
+inline u8 rtw_c2h_reg_wk_cmd(_adapter *adapter, u8 *c2h_evt)
+{
+ return rtw_c2h_wk_cmd(adapter, c2h_evt, c2h_evt ? C2H_REG_LEN : 0, C2H_TYPE_REG);
+}
+#endif
+
+#ifdef CONFIG_FW_C2H_PKT
+inline u8 rtw_c2h_packet_wk_cmd(_adapter *adapter, u8 *c2h_evt, u16 length)
+{
+ return rtw_c2h_wk_cmd(adapter, c2h_evt, length, C2H_TYPE_PKT);
+}
+#endif
+
+u8 rtw_run_in_thread_cmd(PADAPTER padapter, void (*func)(void *), void *context)
+{
+ struct cmd_priv *pcmdpriv;
+ struct cmd_obj *ph2c;
+ struct RunInThread_param *parm;
+ s32 res = _SUCCESS;
+
+ pcmdpriv = &padapter->cmdpriv;
+
+ ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (!ph2c) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ parm = (struct RunInThread_param *)rtw_zmalloc(sizeof(struct RunInThread_param));
+ if (!parm) {
+ rtw_mfree((u8 *)ph2c, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ parm->func = func;
+ parm->context = context;
+ init_h2fwcmd_w_parm_no_rsp(ph2c, parm, GEN_CMD_CODE(_RunInThreadCMD));
+
+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
+exit:
+
+
+ return res;
+}
+
+#ifdef CONFIG_FW_C2H_REG
+s32 c2h_evt_hdl(_adapter *adapter, u8 *c2h_evt, c2h_id_filter filter)
+{
+ s32 ret = _FAIL;
+ u8 buf[C2H_REG_LEN] = {0};
+ u8 id, seq, plen;
+ u8 *payload;
+
+ if (!c2h_evt) {
+ /* No c2h event in cmd_obj, read c2h event before handling*/
+ if (rtw_hal_c2h_evt_read(adapter, buf) != _SUCCESS)
+ goto exit;
+ c2h_evt = buf;
+ }
+
+ rtw_hal_c2h_reg_hdr_parse(adapter, c2h_evt, &id, &seq, &plen, &payload);
+
+ if (filter && filter(adapter, id, seq, plen, payload) == false)
+ goto exit;
+
+ ret = rtw_hal_c2h_handler(adapter, id, seq, plen, payload);
+
+exit:
+ return ret;
+}
+#endif /* CONFIG_FW_C2H_REG */
+
+static u8 session_tracker_cmd(_adapter *adapter, u8 cmd, struct sta_info *sta, u8 *local_naddr, u8 *local_port, u8 *remote_naddr, u8 *remote_port)
+{
+ struct cmd_priv *cmdpriv = &adapter->cmdpriv;
+ struct cmd_obj *cmdobj;
+ struct drvextra_cmd_parm *cmd_parm;
+ struct st_cmd_parm *st_parm;
+ u8 res = _SUCCESS;
+
+ cmdobj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
+ if (cmdobj == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+
+ cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
+ if (cmd_parm == NULL) {
+ rtw_mfree((u8 *)cmdobj, sizeof(struct cmd_obj));
+ res = _FAIL;
+ goto exit;
+ }
+
+ st_parm = (struct st_cmd_parm *)rtw_zmalloc(sizeof(struct st_cmd_parm));
+ if (st_parm == NULL) {
+ rtw_mfree((u8 *)cmdobj, sizeof(struct cmd_obj));
+ rtw_mfree((u8 *)cmd_parm, sizeof(struct drvextra_cmd_parm));
+ res = _FAIL;
+ goto exit;
+ }
+
+ st_parm->cmd = cmd;
+ st_parm->sta = sta;
+ if (cmd != ST_CMD_CHK) {
+ memcpy(&st_parm->local_naddr, local_naddr, 4);
+ memcpy(&st_parm->local_port, local_port, 2);
+ memcpy(&st_parm->remote_naddr, remote_naddr, 4);
+ memcpy(&st_parm->remote_port, remote_port, 2);
+ }
+
+ cmd_parm->ec_id = SESSION_TRACKER_WK_CID;
+ cmd_parm->type = 0;
+ cmd_parm->size = sizeof(struct st_cmd_parm);
+ cmd_parm->pbuf = (u8 *)st_parm;
+ init_h2fwcmd_w_parm_no_rsp(cmdobj, cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
+ cmdobj->no_io = 1;
+
+ res = rtw_enqueue_cmd(cmdpriv, cmdobj);
+
+exit:
+ return res;
+}
+
+inline u8 session_tracker_chk_cmd(_adapter *adapter, struct sta_info *sta)
+{
+ return session_tracker_cmd(adapter, ST_CMD_CHK, sta, NULL, NULL, NULL, NULL);
+}
+
+inline u8 session_tracker_add_cmd(_adapter *adapter, struct sta_info *sta, u8 *local_naddr, u8 *local_port, u8 *remote_naddr, u8 *remote_port)
+{
+ return session_tracker_cmd(adapter, ST_CMD_ADD, sta, local_naddr, local_port, remote_naddr, remote_port);
+}
+
+inline u8 session_tracker_del_cmd(_adapter *adapter, struct sta_info *sta, u8 *local_naddr, u8 *local_port, u8 *remote_naddr, u8 *remote_port)
+{
+ return session_tracker_cmd(adapter, ST_CMD_DEL, sta, local_naddr, local_port, remote_naddr, remote_port);
+}
+
+static void session_tracker_chk_for_sta(_adapter *adapter, struct sta_info *sta)
+{
+ struct st_ctl_t *st_ctl = &sta->st_ctl;
+ int i;
+ unsigned long irqL;
+ _list *plist, *phead, *pnext;
+ _list dlist;
+ struct session_tracker *st = NULL;
+ u8 op_wfd_mode = MIRACAST_DISABLED;
+
+ if (DBG_SESSION_TRACKER)
+ RTW_INFO(FUNC_ADPT_FMT" sta:%p\n", FUNC_ADPT_ARG(adapter), sta);
+
+ if (!(sta->state & _FW_LINKED))
+ goto exit;
+
+ for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++) {
+ if (st_ctl->reg[i].s_proto != 0)
+ break;
+ }
+ if (i >= SESSION_TRACKER_REG_ID_NUM)
+ goto chk_sta;
+
+ INIT_LIST_HEAD(&dlist);
+
+ _enter_critical_bh(&st_ctl->tracker_q.lock, &irqL);
+
+ phead = &st_ctl->tracker_q.queue;
+ plist = get_next(phead);
+ pnext = get_next(plist);
+ while (rtw_end_of_queue_search(phead, plist) == false) {
+ st = LIST_CONTAINOR(plist, struct session_tracker, list);
+ plist = pnext;
+ pnext = get_next(pnext);
+
+ if (st->status != ST_STATUS_ESTABLISH
+ && rtw_get_passing_time_ms(st->set_time) > ST_EXPIRE_MS
+ ) {
+ list_del_init(&st->list);
+ list_add_tail(&st->list, &dlist);
+ }
+
+ /* TODO: check OS for status update */
+ if (st->status == ST_STATUS_CHECK)
+ st->status = ST_STATUS_ESTABLISH;
+
+ if (st->status != ST_STATUS_ESTABLISH)
+ continue;
+
+ #ifdef CONFIG_WFD
+ if (ntohs(st->local_port) == adapter->wfd_info.rtsp_ctrlport)
+ op_wfd_mode |= MIRACAST_SINK;
+ if (ntohs(st->local_port) == adapter->wfd_info.tdls_rtsp_ctrlport)
+ op_wfd_mode |= MIRACAST_SINK;
+ if (ntohs(st->remote_port) == adapter->wfd_info.peer_rtsp_ctrlport)
+ op_wfd_mode |= MIRACAST_SOURCE;
+ #endif
+ }
+
+ _exit_critical_bh(&st_ctl->tracker_q.lock, &irqL);
+
+ plist = get_next(&dlist);
+ while (rtw_end_of_queue_search(&dlist, plist) == false) {
+ st = LIST_CONTAINOR(plist, struct session_tracker, list);
+ plist = get_next(plist);
+ rtw_mfree((u8 *)st, sizeof(struct session_tracker));
+ }
+
+chk_sta:
+ if (STA_OP_WFD_MODE(sta) != op_wfd_mode) {
+ STA_SET_OP_WFD_MODE(sta, op_wfd_mode);
+ rtw_sta_media_status_rpt_cmd(adapter, sta, 1);
+ }
+
+exit:
+ return;
+}
+
+static void session_tracker_chk_for_adapter(_adapter *adapter)
+{
+ struct sta_priv *stapriv = &adapter->stapriv;
+ struct sta_info *sta;
+ int i;
+ unsigned long irqL;
+ _list *plist, *phead;
+ u8 op_wfd_mode = MIRACAST_DISABLED;
+
+ _enter_critical_bh(&stapriv->sta_hash_lock, &irqL);
+
+ for (i = 0; i < NUM_STA; i++) {
+ phead = &(stapriv->sta_hash[i]);
+ plist = get_next(phead);
+
+ while ((rtw_end_of_queue_search(phead, plist)) == false) {
+ sta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
+ plist = get_next(plist);
+
+ session_tracker_chk_for_sta(adapter, sta);
+
+ op_wfd_mode |= STA_OP_WFD_MODE(sta);
+ }
+ }
+
+ _exit_critical_bh(&stapriv->sta_hash_lock, &irqL);
+
+#ifdef CONFIG_WFD
+ adapter->wfd_info.op_wfd_mode = MIRACAST_MODE_REVERSE(op_wfd_mode);
+#endif
+}
+
+static void session_tracker_cmd_hdl(_adapter *adapter, struct st_cmd_parm *parm)
+{
+ u8 cmd = parm->cmd;
+ struct sta_info *sta = parm->sta;
+
+ if (cmd == ST_CMD_CHK) {
+ if (sta)
+ session_tracker_chk_for_sta(adapter, sta);
+ else
+ session_tracker_chk_for_adapter(adapter);
+
+ goto exit;
+
+ } else if (cmd == ST_CMD_ADD || cmd == ST_CMD_DEL) {
+ struct st_ctl_t *st_ctl;
+ u32 local_naddr = parm->local_naddr;
+ u16 local_port = parm->local_port;
+ u32 remote_naddr = parm->remote_naddr;
+ u16 remote_port = parm->remote_port;
+ struct session_tracker *st = NULL;
+ unsigned long irqL;
+ _list *plist, *phead;
+ u8 free_st = 0;
+ u8 alloc_st = 0;
+
+ if (DBG_SESSION_TRACKER)
+ RTW_INFO(FUNC_ADPT_FMT" cmd:%u, sta:%p, local:"IP_FMT":"PORT_FMT", remote:"IP_FMT":"PORT_FMT"\n"
+ , FUNC_ADPT_ARG(adapter), cmd, sta
+ , IP_ARG(&local_naddr), PORT_ARG(&local_port)
+ , IP_ARG(&remote_naddr), PORT_ARG(&remote_port)
+ );
+
+ if (!(sta->state & _FW_LINKED))
+ goto exit;
+
+ st_ctl = &sta->st_ctl;
+
+ _enter_critical_bh(&st_ctl->tracker_q.lock, &irqL);
+
+ phead = &st_ctl->tracker_q.queue;
+ plist = get_next(phead);
+ while (rtw_end_of_queue_search(phead, plist) == false) {
+ st = LIST_CONTAINOR(plist, struct session_tracker, list);
+
+ if (st->local_naddr == local_naddr
+ && st->local_port == cpu_to_be16(local_port)
+ && st->remote_naddr == remote_naddr
+ && st->remote_port == cpu_to_be16(remote_port))
+ break;
+
+ plist = get_next(plist);
+ }
+
+ if (rtw_end_of_queue_search(phead, plist) == true)
+ st = NULL;
+
+ switch (cmd) {
+ case ST_CMD_DEL:
+ if (st) {
+ list_del_init(plist);
+ free_st = 1;
+ }
+ goto unlock;
+ case ST_CMD_ADD:
+ if (!st)
+ alloc_st = 1;
+ }
+
+unlock:
+ _exit_critical_bh(&st_ctl->tracker_q.lock, &irqL);
+
+ if (free_st) {
+ rtw_mfree((u8 *)st, sizeof(struct session_tracker));
+ goto exit;
+ }
+
+ if (alloc_st) {
+ st = (struct session_tracker *)rtw_zmalloc(sizeof(struct session_tracker));
+ if (!st)
+ goto exit;
+
+ st->local_naddr = local_naddr;
+ st->local_port = cpu_to_be16(local_port);
+ st->remote_naddr = remote_naddr;
+ st->remote_port = cpu_to_be16(remote_port);
+ st->set_time = jiffies;
+ st->status = ST_STATUS_CHECK;
+
+ _enter_critical_bh(&st_ctl->tracker_q.lock, &irqL);
+ list_add_tail(&st->list, phead);
+ _exit_critical_bh(&st_ctl->tracker_q.lock, &irqL);
+ }
+ }
+
+exit:
+ return;
+}
+
+u8 rtw_drvextra_cmd_hdl(_adapter *padapter, unsigned char *pbuf)
+{
+ int ret = H2C_SUCCESS;
+ struct drvextra_cmd_parm *pdrvextra_cmd;
+
+ if (!pbuf)
+ return H2C_PARAMETERS_ERROR;
+
+ pdrvextra_cmd = (struct drvextra_cmd_parm *)pbuf;
+
+ switch (pdrvextra_cmd->ec_id) {
+ case STA_MSTATUS_RPT_WK_CID:
+ rtw_sta_media_status_rpt_cmd_hdl(padapter, (struct sta_media_status_rpt_cmd_parm *)pdrvextra_cmd->pbuf);
+ break;
+
+ case DYNAMIC_CHK_WK_CID:/*only primary padapter go to this cmd, but execute dynamic_chk_wk_hdl() for two interfaces */
+ rtw_dynamic_chk_wk_hdl(padapter);
+ break;
+ case POWER_SAVING_CTRL_WK_CID:
+ power_saving_wk_hdl(padapter);
+ break;
+#ifdef CONFIG_LPS
+ case LPS_CTRL_WK_CID:
+ lps_ctrl_wk_hdl(padapter, (u8)pdrvextra_cmd->type);
+ break;
+ case DM_IN_LPS_WK_CID:
+ rtw_dm_in_lps_hdl(padapter);
+ break;
+ case LPS_CHANGE_DTIM_CID:
+ rtw_lps_change_dtim_hdl(padapter, (u8)pdrvextra_cmd->type);
+ break;
+#endif
+#if (RATE_ADAPTIVE_SUPPORT == 1)
+ case RTP_TIMER_CFG_WK_CID:
+ rpt_timer_setting_wk_hdl(padapter, pdrvextra_cmd->type);
+ break;
+#endif
+#ifdef CONFIG_ANTENNA_DIVERSITY
+ case ANT_SELECT_WK_CID:
+ antenna_select_wk_hdl(padapter, pdrvextra_cmd->type);
+ break;
+#endif
+#ifdef CONFIG_P2P_PS
+ case P2P_PS_WK_CID:
+ p2p_ps_wk_hdl(padapter, pdrvextra_cmd->type);
+ break;
+#endif
+#ifdef CONFIG_P2P
+ case P2P_PROTO_WK_CID:
+ /* I used the type_size as the type command */
+ ret = p2p_protocol_wk_hdl(padapter, pdrvextra_cmd->type, pdrvextra_cmd->pbuf);
+ break;
+#endif
+#ifdef CONFIG_AP_MODE
+ case CHECK_HIQ_WK_CID:
+ rtw_chk_hi_queue_hdl(padapter);
+ break;
+#endif
+#ifdef CONFIG_INTEL_WIDI
+ case INTEl_WIDI_WK_CID:
+ intel_widi_wk_hdl(padapter, pdrvextra_cmd->type, pdrvextra_cmd->pbuf);
+ break;
+#endif
+ /* add for CONFIG_IEEE80211W, none 11w can use it */
+ case RESET_SECURITYPRIV:
+ reset_securitypriv_hdl(padapter);
+ break;
+ case FREE_ASSOC_RESOURCES:
+ free_assoc_resources_hdl(padapter);
+ break;
+ case C2H_WK_CID:
+ switch (pdrvextra_cmd->type) {
+ #ifdef CONFIG_FW_C2H_REG
+ case C2H_TYPE_REG:
+ c2h_evt_hdl(padapter, pdrvextra_cmd->pbuf, NULL);
+ break;
+ #endif
+ #ifdef CONFIG_FW_C2H_PKT
+ case C2H_TYPE_PKT:
+ rtw_hal_c2h_pkt_hdl(padapter, pdrvextra_cmd->pbuf, pdrvextra_cmd->size);
+ break;
+ #endif
+ default:
+ RTW_ERR("unknown C2H type:%d\n", pdrvextra_cmd->type);
+ rtw_warn_on(1);
+ break;
+ }
+ break;
+#ifdef CONFIG_BEAMFORMING
+ case BEAMFORMING_WK_CID:
+ beamforming_wk_hdl(padapter, pdrvextra_cmd->type, pdrvextra_cmd->pbuf);
+ break;
+#endif
+ case DM_RA_MSK_WK_CID:
+ rtw_dm_ra_mask_hdl(padapter, (struct sta_info *)pdrvextra_cmd->pbuf);
+ break;
+#ifdef CONFIG_BT_COEXIST
+ case BTINFO_WK_CID:
+ rtw_btinfo_hdl(padapter, pdrvextra_cmd->pbuf, pdrvextra_cmd->size);
+ break;
+#endif
+#ifdef CONFIG_DFS_MASTER
+ case DFS_MASTER_WK_CID:
+ rtw_dfs_master_hdl(padapter);
+ break;
+#endif
+ case SESSION_TRACKER_WK_CID:
+ session_tracker_cmd_hdl(padapter, (struct st_cmd_parm *)pdrvextra_cmd->pbuf);
+ break;
+ case EN_HW_UPDATE_TSF_WK_CID:
+ rtw_hal_set_hwreg(padapter, HW_VAR_EN_HW_UPDATE_TSF, NULL);
+ break;
+ case TEST_H2C_CID:
+ rtw_hal_fill_h2c_cmd(padapter, pdrvextra_cmd->pbuf[0], pdrvextra_cmd->size - 1, &pdrvextra_cmd->pbuf[1]);
+ break;
+ case MP_CMD_WK_CID:
+ ret = rtw_mp_cmd_hdl(padapter, pdrvextra_cmd->type);
+ break;
+#ifdef CONFIG_RTW_CUSTOMER_STR
+ case CUSTOMER_STR_WK_CID:
+ ret = rtw_customer_str_cmd_hdl(padapter, pdrvextra_cmd->type, pdrvextra_cmd->pbuf);
+ break;
+#endif
+ default:
+ break;
+ }
+
+ if (pdrvextra_cmd->pbuf && pdrvextra_cmd->size > 0)
+ rtw_mfree(pdrvextra_cmd->pbuf, pdrvextra_cmd->size);
+
+ return ret;
+}
+
+void rtw_survey_cmd_callback(_adapter *padapter, struct cmd_obj *pcmd)
+{
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+
+
+ if (pcmd->res == H2C_DROPPED) {
+ /* TODO: cancel timer and do timeout handler directly... */
+ /* need to make timeout handlerOS independent */
+ mlme_set_scan_to_timer(pmlmepriv, 1);
+ } else if (pcmd->res != H2C_SUCCESS) {
+ mlme_set_scan_to_timer(pmlmepriv, 1);
+ }
+
+ /* free cmd */
+ rtw_free_cmd_obj(pcmd);
+}
+
+void rtw_disassoc_cmd_callback(_adapter *padapter, struct cmd_obj *pcmd)
+{
+ unsigned long irqL;
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+
+
+ if (pcmd->res != H2C_SUCCESS) {
+ _enter_critical_bh(&pmlmepriv->lock, &irqL);
+ set_fwstate(pmlmepriv, _FW_LINKED);
+ _exit_critical_bh(&pmlmepriv->lock, &irqL);
+ goto exit;
+ }
+#ifdef CONFIG_BR_EXT
+ else /* clear bridge database */
+ nat25_db_cleanup(padapter);
+#endif /* CONFIG_BR_EXT */
+
+ /* free cmd */
+ rtw_free_cmd_obj(pcmd);
+
+exit:
+ return;
+}
+
+void rtw_getmacreg_cmdrsp_callback(_adapter *padapter, struct cmd_obj *pcmd)
+{
+ rtw_free_cmd_obj(pcmd);
+}
+
+void rtw_joinbss_cmd_callback(_adapter *padapter, struct cmd_obj *pcmd)
+{
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+
+ if (pcmd->res == H2C_DROPPED) {
+ /* TODO: cancel timer and do timeout handler directly... */
+ /* need to make timeout handlerOS independent */
+ _set_timer(&pmlmepriv->assoc_timer, 1);
+ } else if (pcmd->res != H2C_SUCCESS)
+ _set_timer(&pmlmepriv->assoc_timer, 1);
+
+ rtw_free_cmd_obj(pcmd);
+
+}
+
+void rtw_create_ibss_post_hdl(_adapter *padapter, int status)
+{
+ u8 timer_cancelled;
+ struct sta_info *psta = NULL;
+ struct wlan_network *pwlan = NULL;
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ WLAN_BSSID_EX *pdev_network = &padapter->registrypriv.dev_network;
+ struct wlan_network *mlme_cur_network = &(pmlmepriv->cur_network);
+ unsigned long irqL, irqL2;
+
+ if (status != H2C_SUCCESS)
+ _set_timer(&pmlmepriv->assoc_timer, 1);
+
+ _cancel_timer(&pmlmepriv->assoc_timer, &timer_cancelled);
+
+ _enter_critical_bh(&pmlmepriv->lock, &irqL);
+
+ pwlan = _rtw_alloc_network(pmlmepriv);
+ _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL2);
+ if (!pwlan) {
+ pwlan = rtw_get_oldest_wlan_network(&pmlmepriv->scanned_queue);
+ if (!pwlan) {
+ _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL2);
+ goto createbss_cmd_fail;
+ }
+ pwlan->last_scanned = jiffies;
+ } else {
+ list_add_tail(&(pwlan->list), &pmlmepriv->scanned_queue.queue);
+ }
+ pdev_network->Length = get_WLAN_BSSID_EX_sz(pdev_network);
+ memcpy(&(pwlan->network), pdev_network, pdev_network->Length);
+
+ /* copy pdev_network information to pmlmepriv->cur_network */
+ memcpy(&mlme_cur_network->network, pdev_network, (get_WLAN_BSSID_EX_sz(pdev_network)));
+
+ _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
+ _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL2);
+
+createbss_cmd_fail:
+ _exit_critical_bh(&pmlmepriv->lock, &irqL);
+exit:
+ return;
+}
+
+void rtw_setstaKey_cmdrsp_callback(_adapter *padapter, struct cmd_obj *pcmd)
+{
+ rtw_free_cmd_obj(pcmd);
+}
+
+void rtw_setassocsta_cmdrsp_callback(_adapter *padapter, struct cmd_obj *pcmd)
+{
+ unsigned long irqL;
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ struct set_assocsta_parm *passocsta_parm = (struct set_assocsta_parm *)(pcmd->parmbuf);
+ struct set_assocsta_rsp *passocsta_rsp = (struct set_assocsta_rsp *)(pcmd->rsp);
+ struct sta_info *psta = rtw_get_stainfo(pstapriv, passocsta_parm->addr);
+
+ if (!psta)
+ goto exit;
+
+ psta->aid = psta->mac_id = passocsta_rsp->cam_id;
+
+ _enter_critical_bh(&pmlmepriv->lock, &irqL);
+
+ if (check_fwstate(pmlmepriv, WIFI_MP_STATE) &&
+ check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
+ _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
+
+ set_fwstate(pmlmepriv, _FW_LINKED);
+ _exit_critical_bh(&pmlmepriv->lock, &irqL);
+
+exit:
+ rtw_free_cmd_obj(pcmd);
+}
+
+void rtw_getrttbl_cmd_cmdrsp_callback(_adapter *padapter, struct cmd_obj *pcmd)
+{
+
+ rtw_free_cmd_obj(pcmd);
+#ifdef CONFIG_MP_INCLUDED
+ if (padapter->registrypriv.mp_mode == 1)
+ padapter->mppriv.workparam.bcompleted = true;
+#endif
+}
diff --git a/drivers/staging/rtl8188eu/core/rtw_debug.c b/drivers/staging/rtl8188eu/core/rtw_debug.c
new file mode 100644
index 000000000000..8c458700288c
--- /dev/null
+++ b/drivers/staging/rtl8188eu/core/rtw_debug.c
@@ -0,0 +1,4800 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved. */
+
+#define _RTW_DEBUG_C_
+
+#include <drv_types.h>
+#include <hal_data.h>
+
+#ifdef CONFIG_RTW_DEBUG
+static const char *rtw_log_level_str[] = {
+ "_DRV_NONE_ = 0",
+ "_DRV_ALWAYS_ = 1",
+ "_DRV_ERR_ = 2",
+ "_DRV_WARNING_ = 3",
+ "_DRV_INFO_ = 4",
+ "_DRV_DEBUG_ = 5",
+ "_DRV_MAX_ = 6",
+};
+#endif
+
+#ifdef CONFIG_DEBUG_RTL871X
+ u64 GlobalDebugComponents = 0;
+#endif /* CONFIG_DEBUG_RTL871X */
+
+#include <rtw_version.h>
+
+#ifdef CONFIG_TDLS
+ #define TDLS_DBG_INFO_SPACE_BTWN_ITEM_AND_VALUE 41
+#endif
+
+void dump_drv_version(void *sel)
+{
+ RTW_PRINT_SEL(sel, "%s %s\n", DRV_NAME, DRIVERVERSION);
+}
+
+void dump_drv_cfg(void *sel)
+{
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24))
+ char *kernel_version = utsname()->release;
+
+ RTW_PRINT_SEL(sel, "\nKernel Version: %s\n", kernel_version);
+#endif
+
+ RTW_PRINT_SEL(sel, "Driver Version: %s\n", DRIVERVERSION);
+ RTW_PRINT_SEL(sel, "------------------------------------------------\n");
+#ifdef CONFIG_IOCTL_CFG80211
+ RTW_PRINT_SEL(sel, "CFG80211\n");
+#ifdef RTW_USE_CFG80211_STA_EVENT
+ RTW_PRINT_SEL(sel, "RTW_USE_CFG80211_STA_EVENT\n");
+#endif
+ #ifdef CONFIG_RADIO_WORK
+ RTW_PRINT_SEL(sel, "CONFIG_RADIO_WORK\n");
+ #endif
+#else
+ RTW_PRINT_SEL(sel, "WEXT\n");
+#endif
+
+ RTW_PRINT_SEL(sel, "DBG:%d\n", DBG);
+#ifdef CONFIG_RTW_DEBUG
+ RTW_PRINT_SEL(sel, "CONFIG_RTW_DEBUG\n");
+#endif
+
+#ifdef CONFIG_CONCURRENT_MODE
+ RTW_PRINT_SEL(sel, "CONFIG_CONCURRENT_MODE\n");
+#endif
+
+#ifdef CONFIG_POWER_SAVING
+ RTW_PRINT_SEL(sel, "CONFIG_POWER_SAVING\n");
+#endif
+
+#ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
+ RTW_PRINT_SEL(sel, "LOAD_PHY_PARA_FROM_FILE - REALTEK_CONFIG_PATH=%s\n", REALTEK_CONFIG_PATH);
+ #if defined(CONFIG_MULTIDRV) || defined(REALTEK_CONFIG_PATH_WITH_IC_NAME_FOLDER)
+ RTW_PRINT_SEL(sel, "LOAD_PHY_PARA_FROM_FILE - REALTEK_CONFIG_PATH_WITH_IC_NAME_FOLDER\n");
+ #endif
+
+/* configurations about TX power */
+#ifdef CONFIG_CALIBRATE_TX_POWER_BY_REGULATORY
+ RTW_PRINT_SEL(sel, "CONFIG_CALIBRATE_TX_POWER_BY_REGULATORY\n");
+#endif
+#ifdef CONFIG_CALIBRATE_TX_POWER_TO_MAX
+ RTW_PRINT_SEL(sel, "CONFIG_CALIBRATE_TX_POWER_TO_MAX\n");
+#endif
+#endif
+ RTW_PRINT_SEL(sel, "RTW_DEF_MODULE_REGULATORY_CERT=0x%02x\n", RTW_DEF_MODULE_REGULATORY_CERT);
+
+ RTW_PRINT_SEL(sel, "CONFIG_TXPWR_BY_RATE_EN=%d\n", CONFIG_TXPWR_BY_RATE_EN);
+ RTW_PRINT_SEL(sel, "CONFIG_TXPWR_LIMIT_EN=%d\n", CONFIG_TXPWR_LIMIT_EN);
+
+
+#ifdef CONFIG_DISABLE_ODM
+ RTW_PRINT_SEL(sel, "CONFIG_DISABLE_ODM\n");
+#endif
+
+#ifdef CONFIG_MINIMAL_MEMORY_USAGE
+ RTW_PRINT_SEL(sel, "CONFIG_MINIMAL_MEMORY_USAGE\n");
+#endif
+
+ RTW_PRINT_SEL(sel, "CONFIG_RTW_ADAPTIVITY_EN = %d\n", CONFIG_RTW_ADAPTIVITY_EN);
+#if (CONFIG_RTW_ADAPTIVITY_EN)
+ RTW_PRINT_SEL(sel, "ADAPTIVITY_MODE = %s\n", (CONFIG_RTW_ADAPTIVITY_MODE) ? "carrier_sense" : "normal");
+#endif
+
+#ifdef CONFIG_WOWLAN
+ RTW_PRINT_SEL(sel, "CONFIG_WOWLAN - ");
+
+#ifdef CONFIG_GPIO_WAKEUP
+ RTW_PRINT_SEL(sel, "CONFIG_GPIO_WAKEUP - WAKEUP_GPIO_IDX:%d\n", WAKEUP_GPIO_IDX);
+#endif
+#endif
+
+#ifdef CONFIG_TDLS
+ RTW_PRINT_SEL(sel, "CONFIG_TDLS\n");
+#endif
+
+#ifdef CONFIG_RTW_80211R
+ RTW_PRINT_SEL(sel, "CONFIG_RTW_80211R\n");
+#endif
+
+#ifdef CONFIG_SUPPORT_USB_INT
+ RTW_PRINT_SEL(sel, "CONFIG_SUPPORT_USB_INT\n");
+#endif
+#ifdef CONFIG_USB_INTERRUPT_IN_PIPE
+ RTW_PRINT_SEL(sel, "CONFIG_USB_INTERRUPT_IN_PIPE\n");
+#endif
+#ifdef CONFIG_USB_TX_AGGREGATION
+ RTW_PRINT_SEL(sel, "CONFIG_USB_TX_AGGREGATION\n");
+#endif
+#ifdef CONFIG_USB_RX_AGGREGATION
+ RTW_PRINT_SEL(sel, "CONFIG_USB_RX_AGGREGATION\n");
+#endif
+#ifdef CONFIG_USE_USB_BUFFER_ALLOC_TX
+ RTW_PRINT_SEL(sel, "CONFIG_USE_USB_BUFFER_ALLOC_TX\n");
+#endif
+#ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
+ RTW_PRINT_SEL(sel, "CONFIG_USE_USB_BUFFER_ALLOC_RX\n");
+#endif
+#ifdef CONFIG_PREALLOC_RECV_SKB
+ RTW_PRINT_SEL(sel, "CONFIG_PREALLOC_RECV_SKB\n");
+#endif
+#ifdef CONFIG_FIX_NR_BULKIN_BUFFER
+ RTW_PRINT_SEL(sel, "CONFIG_FIX_NR_BULKIN_BUFFER\n");
+#endif
+ RTW_PRINT_SEL(sel, "MAX_XMITBUF_SZ = %d\n", MAX_XMITBUF_SZ);
+ RTW_PRINT_SEL(sel, "MAX_RECVBUF_SZ = %d\n", MAX_RECVBUF_SZ);
+}
+
+void dump_log_level(void *sel)
+{
+#ifdef CONFIG_RTW_DEBUG
+ int i;
+
+ RTW_PRINT_SEL(sel, "drv_log_level:%d\n", rtw_drv_log_level);
+ for (i = 0; i <= _DRV_MAX_; i++) {
+ if (rtw_log_level_str[i])
+ RTW_PRINT_SEL(sel, "%c %s = %d\n",
+ (rtw_drv_log_level == i) ? '+' : ' ', rtw_log_level_str[i], i);
+ }
+#else
+ RTW_PRINT_SEL(sel, "CONFIG_RTW_DEBUG is disabled\n");
+#endif
+}
+
+void mac_reg_dump(void *sel, _adapter *adapter)
+{
+ int i, j = 1;
+
+ RTW_PRINT_SEL(sel, "======= MAC REG =======\n");
+
+ for (i = 0x0; i < 0x800; i += 4) {
+ if (j % 4 == 1)
+ RTW_PRINT_SEL(sel, "0x%04x", i);
+ _RTW_PRINT_SEL(sel, " 0x%08x ", rtw_read32(adapter, i));
+ if ((j++) % 4 == 0)
+ _RTW_PRINT_SEL(sel, "\n");
+ }
+}
+
+void bb_reg_dump(void *sel, _adapter *adapter)
+{
+ int i, j = 1;
+
+ RTW_PRINT_SEL(sel, "======= BB REG =======\n");
+ for (i = 0x800; i < 0x1000; i += 4) {
+ if (j % 4 == 1)
+ RTW_PRINT_SEL(sel, "0x%04x", i);
+ _RTW_PRINT_SEL(sel, " 0x%08x ", rtw_read32(adapter, i));
+ if ((j++) % 4 == 0)
+ _RTW_PRINT_SEL(sel, "\n");
+ }
+}
+
+void bb_reg_dump_ex(void *sel, _adapter *adapter)
+{
+ int i, j = 1;
+
+ RTW_PRINT_SEL(sel, "======= BB REG =======\n");
+ for (i = 0x800; i < 0x1000; i += 4) {
+ RTW_PRINT_SEL(sel, "0x%04x", i);
+ _RTW_PRINT_SEL(sel, " 0x%08x ", rtw_read32(adapter, i));
+ _RTW_PRINT_SEL(sel, "\n");
+ }
+}
+
+void rf_reg_dump(void *sel, _adapter *adapter)
+{
+ int i, j = 1, path;
+ u32 value;
+ u8 rf_type = 0;
+ u8 path_nums = 0;
+
+ rtw_hal_get_hwreg(adapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
+ if ((RF_1T2R == rf_type) || (RF_1T1R == rf_type))
+ path_nums = 1;
+ else
+ path_nums = 2;
+
+ RTW_PRINT_SEL(sel, "======= RF REG =======\n");
+
+ for (path = 0; path < path_nums; path++) {
+ RTW_PRINT_SEL(sel, "RF_Path(%x)\n", path);
+ for (i = 0; i < 0x100; i++) {
+ value = rtw_hal_read_rfreg(adapter, path, i, 0xffffffff);
+ if (j % 4 == 1)
+ RTW_PRINT_SEL(sel, "0x%02x ", i);
+ _RTW_PRINT_SEL(sel, " 0x%08x ", value);
+ if ((j++) % 4 == 0)
+ _RTW_PRINT_SEL(sel, "\n");
+ }
+ }
+}
+
+static u8 fwdl_test_chksum_fail = 0;
+static u8 fwdl_test_wintint_rdy_fail = 0;
+
+bool rtw_fwdl_test_trigger_chksum_fail(void)
+{
+ if (fwdl_test_chksum_fail) {
+ RTW_PRINT("fwdl test case: trigger chksum_fail\n");
+ fwdl_test_chksum_fail--;
+ return true;
+ }
+ return false;
+}
+
+bool rtw_fwdl_test_trigger_wintint_rdy_fail(void)
+{
+ if (fwdl_test_wintint_rdy_fail) {
+ RTW_PRINT("fwdl test case: trigger wintint_rdy_fail\n");
+ fwdl_test_wintint_rdy_fail--;
+ return true;
+ }
+ return false;
+}
+
+static u32 g_wait_hiq_empty_ms = 0;
+
+u32 rtw_get_wait_hiq_empty_ms(void)
+{
+ return g_wait_hiq_empty_ms;
+}
+
+static u8 del_rx_ampdu_test_no_tx_fail = 0;
+
+bool rtw_del_rx_ampdu_test_trigger_no_tx_fail(void)
+{
+ if (del_rx_ampdu_test_no_tx_fail) {
+ RTW_PRINT("del_rx_ampdu test case: trigger no_tx_fail\n");
+ del_rx_ampdu_test_no_tx_fail--;
+ return true;
+ }
+ return false;
+}
+
+void rtw_sink_rtp_seq_dbg(_adapter *adapter, _pkt *pkt)
+{
+ struct recv_priv *precvpriv = &(adapter->recvpriv);
+ if (precvpriv->sink_udpport > 0) {
+ if (*((__be16 *)((pkt->data) + 0x24)) == cpu_to_be16(precvpriv->sink_udpport)) {
+ precvpriv->pre_rtp_rxseq = precvpriv->cur_rtp_rxseq;
+ precvpriv->cur_rtp_rxseq = be16_to_cpu(*((__be16 *)((pkt->data) + 0x2C)));
+ if (precvpriv->pre_rtp_rxseq + 1 != precvpriv->cur_rtp_rxseq)
+ RTW_INFO("%s : RTP Seq num from %d to %d\n", __func__, precvpriv->pre_rtp_rxseq, precvpriv->cur_rtp_rxseq);
+ }
+ }
+}
+
+void sta_rx_reorder_ctl_dump(void *sel, struct sta_info *sta)
+{
+ struct recv_reorder_ctrl *reorder_ctl;
+ int i;
+
+ for (i = 0; i < 16; i++) {
+ reorder_ctl = &sta->recvreorder_ctrl[i];
+ if (reorder_ctl->ampdu_size != RX_AMPDU_SIZE_INVALID || reorder_ctl->indicate_seq != 0xFFFF) {
+ RTW_PRINT_SEL(sel, "tid=%d, enable=%d, ampdu_size=%u, indicate_seq=%u\n"
+ , i, reorder_ctl->enable, reorder_ctl->ampdu_size, reorder_ctl->indicate_seq
+ );
+ }
+ }
+}
+
+void dump_tx_rate_bmp(void *sel, struct dvobj_priv *dvobj)
+{
+ _adapter *adapter = dvobj_get_primary_adapter(dvobj);
+ struct rf_ctl_t *rfctl = dvobj_to_rfctl(dvobj);
+ u8 bw;
+
+ RTW_PRINT_SEL(sel, "%-6s", "bw");
+ if (hal_chk_proto_cap(adapter, PROTO_CAP_11AC))
+ _RTW_PRINT_SEL(sel, " %-11s", "vht");
+
+ _RTW_PRINT_SEL(sel, " %-11s %-4s %-3s\n", "ht", "ofdm", "cck");
+
+ for (bw = CHANNEL_WIDTH_20; bw <= CHANNEL_WIDTH_160; bw++) {
+ if (!hal_is_bw_support(adapter, bw))
+ continue;
+
+ RTW_PRINT_SEL(sel, "%6s", ch_width_str(bw));
+ if (hal_chk_proto_cap(adapter, PROTO_CAP_11AC)) {
+ _RTW_PRINT_SEL(sel, " %03x %03x %03x"
+ , RATE_BMP_GET_VHT_3SS(rfctl->rate_bmp_vht_by_bw[bw])
+ , RATE_BMP_GET_VHT_2SS(rfctl->rate_bmp_vht_by_bw[bw])
+ , RATE_BMP_GET_VHT_1SS(rfctl->rate_bmp_vht_by_bw[bw])
+ );
+ }
+
+ _RTW_PRINT_SEL(sel, " %02x %02x %02x %02x"
+ , bw <= CHANNEL_WIDTH_40 ? RATE_BMP_GET_HT_4SS(rfctl->rate_bmp_ht_by_bw[bw]) : 0
+ , bw <= CHANNEL_WIDTH_40 ? RATE_BMP_GET_HT_3SS(rfctl->rate_bmp_ht_by_bw[bw]) : 0
+ , bw <= CHANNEL_WIDTH_40 ? RATE_BMP_GET_HT_2SS(rfctl->rate_bmp_ht_by_bw[bw]) : 0
+ , bw <= CHANNEL_WIDTH_40 ? RATE_BMP_GET_HT_1SS(rfctl->rate_bmp_ht_by_bw[bw]) : 0
+ );
+
+ _RTW_PRINT_SEL(sel, " %03x %01x\n"
+ , bw <= CHANNEL_WIDTH_20 ? RATE_BMP_GET_OFDM(rfctl->rate_bmp_cck_ofdm) : 0
+ , bw <= CHANNEL_WIDTH_20 ? RATE_BMP_GET_CCK(rfctl->rate_bmp_cck_ofdm) : 0
+ );
+ }
+}
+
+void dump_adapters_status(void *sel, struct dvobj_priv *dvobj)
+{
+ struct rf_ctl_t *rfctl = dvobj_to_rfctl(dvobj);
+ int i;
+ _adapter *iface;
+ u8 u_ch, u_bw, u_offset;
+
+ dump_mi_status(sel, dvobj);
+
+#ifdef CONFIG_FW_MULTI_PORT_SUPPORT
+ RTW_PRINT_SEL(sel, "default port id:%d\n\n", dvobj->default_port_id);
+#endif /* CONFIG_FW_MULTI_PORT_SUPPORT */
+
+ RTW_PRINT_SEL(sel, "dev status:%s%s\n\n"
+ , dev_is_surprise_removed(dvobj) ? " SR" : ""
+ , dev_is_drv_stopped(dvobj) ? " DS" : ""
+ );
+
+#ifdef CONFIG_P2P
+#define P2P_INFO_TITLE_FMT " %-3s %-4s"
+#define P2P_INFO_TITLE_ARG , "lch", "p2ps"
+#ifdef CONFIG_IOCTL_CFG80211
+#define P2P_INFO_VALUE_FMT " %3u %c%3u"
+#define P2P_INFO_VALUE_ARG , iface->wdinfo.listen_channel, iface->wdev_data.p2p_enabled ? 'e' : ' ', rtw_p2p_state(&iface->wdinfo)
+#else
+#define P2P_INFO_VALUE_FMT " %3u %4u"
+#define P2P_INFO_VALUE_ARG , iface->wdinfo.listen_channel, rtw_p2p_state(&iface->wdinfo)
+#endif
+#define P2P_INFO_DASH "---------"
+#else
+#define P2P_INFO_TITLE_FMT ""
+#define P2P_INFO_TITLE_ARG
+#define P2P_INFO_VALUE_FMT ""
+#define P2P_INFO_VALUE_ARG
+#define P2P_INFO_DASH
+#endif
+
+ RTW_PRINT_SEL(sel, "%-2s %-15s %c %-3s %-3s %-3s %-17s %-4s %-7s"
+ P2P_INFO_TITLE_FMT
+ " %s\n"
+ , "id", "ifname", ' ', "bup", "nup", "ncd", "macaddr", "port", "ch"
+ P2P_INFO_TITLE_ARG
+ , "status");
+
+ RTW_PRINT_SEL(sel, "---------------------------------------------------------------"
+ P2P_INFO_DASH
+ "-------\n");
+
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ iface = dvobj->padapters[i];
+ if (iface) {
+ RTW_PRINT_SEL(sel, "%2d %-15s %c %3u %3u %3u "MAC_FMT" %4hhu %3u,%u,%u"
+ P2P_INFO_VALUE_FMT
+ " "MLME_STATE_FMT"\n"
+ , i, iface->registered ? ADPT_ARG(iface) : NULL
+ , iface->registered ? 'R' : ' '
+ , iface->bup
+ , iface->netif_up
+ , iface->net_closed
+ , MAC_ARG(adapter_mac_addr(iface))
+ , get_hw_port(iface)
+ , iface->mlmeextpriv.cur_channel
+ , iface->mlmeextpriv.cur_bwmode
+ , iface->mlmeextpriv.cur_ch_offset
+ P2P_INFO_VALUE_ARG
+ , MLME_STATE_ARG(iface)
+ );
+ }
+ }
+
+ RTW_PRINT_SEL(sel, "---------------------------------------------------------------"
+ P2P_INFO_DASH
+ "-------\n");
+
+ rtw_mi_get_ch_setting_union(dvobj_get_primary_adapter(dvobj), &u_ch, &u_bw, &u_offset);
+ RTW_PRINT_SEL(sel, "%55s %3u,%u,%u\n"
+ , "union:"
+ , u_ch, u_bw, u_offset
+ );
+
+ RTW_PRINT_SEL(sel, "%55s %3u,%u,%u\n"
+ , "oper:"
+ , dvobj->oper_channel
+ , dvobj->oper_bwmode
+ , dvobj->oper_ch_offset
+ );
+
+#ifdef CONFIG_DFS_MASTER
+ if (rfctl->radar_detect_ch != 0) {
+ u32 non_ocp_ms;
+ u32 cac_ms;
+
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ if (!dvobj->padapters[i])
+ continue;
+ if (check_fwstate(&dvobj->padapters[i]->mlmepriv, WIFI_AP_STATE)
+ && check_fwstate(&dvobj->padapters[i]->mlmepriv, WIFI_ASOC_STATE))
+ break;
+ }
+
+ if (i >= dvobj->iface_nums) {
+ RTW_PRINT_SEL(sel, "DFS master enable without AP mode???");
+ goto end_dfs_master;
+ }
+
+ RTW_PRINT_SEL(sel, "%55s %3u,%u,%u"
+ , "radar_detect:"
+ , rfctl->radar_detect_ch
+ , rfctl->radar_detect_bw
+ , rfctl->radar_detect_offset
+ );
+
+ _RTW_PRINT_SEL(sel, ", domain:%u", rtw_odm_get_dfs_domain(dvobj->padapters[IFACE_ID0]));
+
+ rtw_get_ch_waiting_ms(dvobj->padapters[i]
+ , rfctl->radar_detect_ch
+ , rfctl->radar_detect_bw
+ , rfctl->radar_detect_offset
+ , &non_ocp_ms
+ , &cac_ms
+ );
+
+ if (non_ocp_ms)
+ _RTW_PRINT_SEL(sel, ", non_ocp:%d", non_ocp_ms);
+ if (cac_ms)
+ _RTW_PRINT_SEL(sel, ", cac:%d", cac_ms);
+end_dfs_master:
+ _RTW_PRINT_SEL(sel, "\n");
+ }
+#endif /* CONFIG_DFS_MASTER */
+}
+
+#define SEC_CAM_ENT_ID_TITLE_FMT "%-2s"
+#define SEC_CAM_ENT_ID_TITLE_ARG "id"
+#define SEC_CAM_ENT_ID_VALUE_FMT "%2u"
+#define SEC_CAM_ENT_ID_VALUE_ARG(id) (id)
+
+#define SEC_CAM_ENT_TITLE_FMT "%-6s %-17s %-32s %-3s %-7s %-2s %-2s %-5s"
+#define SEC_CAM_ENT_TITLE_ARG "ctrl", "addr", "key", "kid", "type", "MK", "GK", "valid"
+#define SEC_CAM_ENT_VALUE_FMT "0x%04x "MAC_FMT" "KEY_FMT" %3u %-7s %2u %2u %5u"
+#define SEC_CAM_ENT_VALUE_ARG(ent) \
+ (ent)->ctrl \
+ , MAC_ARG((ent)->mac) \
+ , KEY_ARG((ent)->key) \
+ , ((ent)->ctrl) & 0x03 \
+ , security_type_str((((ent)->ctrl) >> 2) & 0x07) \
+ , (((ent)->ctrl) >> 5) & 0x01 \
+ , (((ent)->ctrl) >> 6) & 0x01 \
+ , (((ent)->ctrl) >> 15) & 0x01
+
+void dump_sec_cam_ent(void *sel, struct sec_cam_ent *ent, int id)
+{
+ if (id >= 0) {
+ RTW_PRINT_SEL(sel, SEC_CAM_ENT_ID_VALUE_FMT " " SEC_CAM_ENT_VALUE_FMT"\n"
+ , SEC_CAM_ENT_ID_VALUE_ARG(id), SEC_CAM_ENT_VALUE_ARG(ent));
+ } else
+ RTW_PRINT_SEL(sel, SEC_CAM_ENT_VALUE_FMT"\n", SEC_CAM_ENT_VALUE_ARG(ent));
+}
+
+void dump_sec_cam_ent_title(void *sel, u8 has_id)
+{
+ if (has_id) {
+ RTW_PRINT_SEL(sel, SEC_CAM_ENT_ID_TITLE_FMT " " SEC_CAM_ENT_TITLE_FMT"\n"
+ , SEC_CAM_ENT_ID_TITLE_ARG, SEC_CAM_ENT_TITLE_ARG);
+ } else
+ RTW_PRINT_SEL(sel, SEC_CAM_ENT_TITLE_FMT"\n", SEC_CAM_ENT_TITLE_ARG);
+}
+
+void dump_sec_cam(void *sel, _adapter *adapter)
+{
+ struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
+ struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
+ struct sec_cam_ent ent;
+ int i;
+
+ RTW_PRINT_SEL(sel, "HW sec cam:\n");
+ dump_sec_cam_ent_title(sel, 1);
+ for (i = 0; i < cam_ctl->num; i++) {
+ rtw_sec_read_cam_ent(adapter, i, (u8 *)(&ent.ctrl), ent.mac, ent.key);
+ dump_sec_cam_ent(sel , &ent, i);
+ }
+}
+
+void dump_sec_cam_cache(void *sel, _adapter *adapter)
+{
+ struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
+ struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
+ int i;
+
+ RTW_PRINT_SEL(sel, "SW sec cam cache:\n");
+ dump_sec_cam_ent_title(sel, 1);
+ for (i = 0; i < cam_ctl->num; i++) {
+ if (dvobj->cam_cache[i].ctrl != 0)
+ dump_sec_cam_ent(sel, &dvobj->cam_cache[i], i);
+ }
+
+}
+
+#ifdef CONFIG_PROC_DEBUG
+ssize_t proc_set_write_reg(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[32];
+ u32 addr, val, len;
+
+ if (count < 3) {
+ RTW_INFO("argument size is less than 3\n");
+ return -EFAULT;
+ }
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%x %x %x", &addr, &val, &len);
+
+ if (num != 3) {
+ RTW_INFO("invalid write_reg parameter!\n");
+ return count;
+ }
+
+ switch (len) {
+ case 1:
+ rtw_write8(padapter, addr, (u8)val);
+ break;
+ case 2:
+ rtw_write16(padapter, addr, (u16)val);
+ break;
+ case 4:
+ rtw_write32(padapter, addr, val);
+ break;
+ default:
+ RTW_INFO("error write length=%d", len);
+ break;
+ }
+
+ }
+
+ return count;
+
+}
+
+static u32 proc_get_read_addr = 0xeeeeeeee;
+static u32 proc_get_read_len = 0x4;
+
+int proc_get_read_reg(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+
+ if (proc_get_read_addr == 0xeeeeeeee) {
+ RTW_PRINT_SEL(m, "address not initialized\n");
+ return 0;
+ }
+
+ switch (proc_get_read_len) {
+ case 1:
+ RTW_PRINT_SEL(m, "rtw_read8(0x%x)=0x%x\n", proc_get_read_addr, rtw_read8(padapter, proc_get_read_addr));
+ break;
+ case 2:
+ RTW_PRINT_SEL(m, "rtw_read16(0x%x)=0x%x\n", proc_get_read_addr, rtw_read16(padapter, proc_get_read_addr));
+ break;
+ case 4:
+ RTW_PRINT_SEL(m, "rtw_read32(0x%x)=0x%x\n", proc_get_read_addr, rtw_read32(padapter, proc_get_read_addr));
+ break;
+ default:
+ RTW_PRINT_SEL(m, "error read length=%d\n", proc_get_read_len);
+ break;
+ }
+
+ return 0;
+}
+
+ssize_t proc_set_read_reg(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ char tmp[16];
+ u32 addr, len;
+
+ if (count < 2) {
+ RTW_INFO("argument size is less than 2\n");
+ return -EFAULT;
+ }
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%x %x", &addr, &len);
+
+ if (num != 2) {
+ RTW_INFO("invalid read_reg parameter!\n");
+ return count;
+ }
+
+ proc_get_read_addr = addr;
+
+ proc_get_read_len = len;
+ }
+
+ return count;
+
+}
+
+int proc_get_rx_stat(struct seq_file *m, void *v)
+{
+ unsigned long irqL;
+ _list *plist, *phead;
+ struct net_device *dev = m->private;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ struct sta_info *psta = NULL;
+ struct stainfo_stats *pstats = NULL;
+ struct sta_priv *pstapriv = &(adapter->stapriv);
+ u32 i, j;
+ u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+ u8 null_addr[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+ _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
+ for (i = 0; i < NUM_STA; i++) {
+ phead = &(pstapriv->sta_hash[i]);
+ plist = get_next(phead);
+ while ((rtw_end_of_queue_search(phead, plist)) == false) {
+ psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
+ plist = get_next(plist);
+ pstats = &psta->sta_stats;
+
+ if (pstats == NULL)
+ continue;
+ if ((memcmp(psta->hwaddr, bc_addr, 6))
+ && (memcmp(psta->hwaddr, null_addr, 6))
+ && (memcmp(psta->hwaddr, adapter_mac_addr(adapter), 6))) {
+ RTW_PRINT_SEL(m, "MAC :\t\t"MAC_FMT "\n", MAC_ARG(psta->hwaddr));
+ RTW_PRINT_SEL(m, "data_rx_cnt :\t%llu\n", pstats->rx_data_pkts - pstats->rx_data_last_pkts);
+ pstats->rx_data_last_pkts = pstats->rx_data_pkts;
+ RTW_PRINT_SEL(m, "duplicate_cnt :\t%u\n", pstats->duplicate_cnt);
+ pstats->duplicate_cnt = 0;
+ RTW_PRINT_SEL(m, "rx_per_rate_cnt :\n");
+
+ for (j = 0; j < 0x60; j++) {
+ RTW_PRINT_SEL(m, "%08u ", pstats->rxratecnt[j]);
+ pstats->rxratecnt[j] = 0;
+ if ((j%8) == 7)
+ RTW_PRINT_SEL(m, "\n");
+ }
+ RTW_PRINT_SEL(m, "\n");
+ }
+ }
+ }
+ _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
+ return 0;
+}
+
+int proc_get_tx_stat(struct seq_file *m, void *v)
+{
+ unsigned long irqL;
+ _list *plist, *phead;
+ struct net_device *dev = m->private;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ struct sta_info *psta = NULL, *sta_rec[NUM_STA];
+ struct stainfo_stats *pstats = NULL;
+ struct sta_priv *pstapriv = &(adapter->stapriv);
+ u32 i, macid_rec_idx = 0;
+ u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+ u8 null_addr[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ struct submit_ctx gotc2h;
+
+ _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
+ for (i = 0; i < NUM_STA; i++) {
+ sta_rec[i] = NULL;
+ phead = &(pstapriv->sta_hash[i]);
+ plist = get_next(phead);
+ while ((rtw_end_of_queue_search(phead, plist)) == false) {
+ psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
+ plist = get_next(plist);
+ if ((memcmp(psta->hwaddr, bc_addr, 6))
+ && (memcmp(psta->hwaddr, null_addr, 6))
+ && (memcmp(psta->hwaddr, adapter_mac_addr(adapter), 6))) {
+ sta_rec[macid_rec_idx++] = psta;
+ }
+ }
+ }
+ _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
+ for (i = 0; i < macid_rec_idx; i++) {
+ pstats = &(sta_rec[i]->sta_stats);
+ if (pstats == NULL)
+ continue;
+ pstapriv->c2h_sta = sta_rec[i];
+ rtw_hal_reqtxrpt(adapter, sta_rec[i]->mac_id);
+ rtw_sctx_init(&gotc2h, 60);
+ pstapriv->gotc2h = &gotc2h;
+ if (rtw_sctx_wait(&gotc2h, __func__)) {
+ RTW_PRINT_SEL(m, "MAC :\t\t"MAC_FMT "\n", MAC_ARG(sta_rec[i]->hwaddr));
+ RTW_PRINT_SEL(m, "data_sent_cnt :\t%u\n", pstats->tx_ok_cnt + pstats->tx_fail_cnt);
+ RTW_PRINT_SEL(m, "success_cnt :\t%u\n", pstats->tx_ok_cnt);
+ RTW_PRINT_SEL(m, "failure_cnt :\t%u\n", pstats->tx_fail_cnt);
+ RTW_PRINT_SEL(m, "retry_cnt :\t%u\n\n", pstats->tx_retry_cnt);
+ } else {
+ RTW_PRINT_SEL(m, "Warming : Query timeout, operation abort!!\n");
+ RTW_PRINT_SEL(m, "\n");
+ break;
+ }
+ }
+ return 0;
+}
+
+int proc_get_fwstate(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+
+ RTW_PRINT_SEL(m, "fwstate=0x%x\n", get_fwstate(pmlmepriv));
+
+ return 0;
+}
+
+int proc_get_sec_info(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct security_priv *sec = &padapter->securitypriv;
+
+ RTW_PRINT_SEL(m, "auth_alg=0x%x, enc_alg=0x%x, auth_type=0x%x, enc_type=0x%x\n",
+ sec->dot11AuthAlgrthm, sec->dot11PrivacyAlgrthm,
+ sec->ndisauthtype, sec->ndisencryptstatus);
+
+ RTW_PRINT_SEL(m, "hw_decrypted=%d\n", sec->hw_decrypted);
+
+#ifdef DBG_SW_SEC_CNT
+ RTW_PRINT_SEL(m, "wep_sw_enc_cnt=%llu, %llu, %llu\n"
+ , sec->wep_sw_enc_cnt_bc , sec->wep_sw_enc_cnt_mc, sec->wep_sw_enc_cnt_uc);
+ RTW_PRINT_SEL(m, "wep_sw_dec_cnt=%llu, %llu, %llu\n"
+ , sec->wep_sw_dec_cnt_bc , sec->wep_sw_dec_cnt_mc, sec->wep_sw_dec_cnt_uc);
+
+ RTW_PRINT_SEL(m, "tkip_sw_enc_cnt=%llu, %llu, %llu\n"
+ , sec->tkip_sw_enc_cnt_bc , sec->tkip_sw_enc_cnt_mc, sec->tkip_sw_enc_cnt_uc);
+ RTW_PRINT_SEL(m, "tkip_sw_dec_cnt=%llu, %llu, %llu\n"
+ , sec->tkip_sw_dec_cnt_bc , sec->tkip_sw_dec_cnt_mc, sec->tkip_sw_dec_cnt_uc);
+
+ RTW_PRINT_SEL(m, "aes_sw_enc_cnt=%llu, %llu, %llu\n"
+ , sec->aes_sw_enc_cnt_bc , sec->aes_sw_enc_cnt_mc, sec->aes_sw_enc_cnt_uc);
+ RTW_PRINT_SEL(m, "aes_sw_dec_cnt=%llu, %llu, %llu\n"
+ , sec->aes_sw_dec_cnt_bc , sec->aes_sw_dec_cnt_mc, sec->aes_sw_dec_cnt_uc);
+#endif /* DBG_SW_SEC_CNT */
+
+ return 0;
+}
+
+int proc_get_mlmext_state(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+
+ RTW_PRINT_SEL(m, "pmlmeinfo->state=0x%x\n", pmlmeinfo->state);
+
+ return 0;
+}
+
+#ifdef CONFIG_LAYER2_ROAMING
+int proc_get_roam_flags(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+
+ RTW_PRINT_SEL(m, "0x%02x\n", rtw_roam_flags(adapter));
+
+ return 0;
+}
+
+ssize_t proc_set_roam_flags(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+
+ char tmp[32];
+ u8 flags;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%hhx", &flags);
+
+ if (num == 1)
+ rtw_assign_roam_flags(adapter, flags);
+ }
+
+ return count;
+
+}
+
+int proc_get_roam_param(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_priv *mlme = &adapter->mlmepriv;
+
+ RTW_PRINT_SEL(m, "%12s %12s %11s %14s\n", "rssi_diff_th", "scanr_exp_ms", "scan_int_ms", "rssi_threshold");
+ RTW_PRINT_SEL(m, "%-12u %-12u %-11u %-14u\n"
+ , mlme->roam_rssi_diff_th
+ , mlme->roam_scanr_exp_ms
+ , mlme->roam_scan_int_ms
+ , mlme->roam_rssi_threshold
+ );
+
+ return 0;
+}
+
+ssize_t proc_set_roam_param(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_priv *mlme = &adapter->mlmepriv;
+
+ char tmp[32];
+ u8 rssi_diff_th;
+ u32 scanr_exp_ms;
+ u32 scan_int_ms;
+ u8 rssi_threshold;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%hhu %u %u %hhu", &rssi_diff_th, &scanr_exp_ms, &scan_int_ms, &rssi_threshold);
+
+ if (num >= 1)
+ mlme->roam_rssi_diff_th = rssi_diff_th;
+ if (num >= 2)
+ mlme->roam_scanr_exp_ms = scanr_exp_ms;
+ if (num >= 3)
+ mlme->roam_scan_int_ms = scan_int_ms;
+ if (num >= 4)
+ mlme->roam_rssi_threshold = rssi_threshold;
+ }
+
+ return count;
+
+}
+
+ssize_t proc_set_roam_tgt_addr(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+
+ char tmp[32];
+ u8 addr[ETH_ALEN];
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", addr, addr + 1, addr + 2, addr + 3, addr + 4, addr + 5);
+ if (num == 6)
+ memcpy(adapter->mlmepriv.roam_tgt_addr, addr, ETH_ALEN);
+
+ RTW_INFO("set roam_tgt_addr to "MAC_FMT"\n", MAC_ARG(adapter->mlmepriv.roam_tgt_addr));
+ }
+
+ return count;
+}
+#endif /* CONFIG_LAYER2_ROAMING */
+
+#ifdef CONFIG_RTW_80211R
+ssize_t proc_set_ft_flags(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+
+ char tmp[32];
+ u8 flags;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+ int num = sscanf(tmp, "%hhx", &flags);
+
+ if (num == 1)
+ adapter->mlmepriv.ftpriv.ft_flags = flags;
+ }
+
+ return count;
+
+}
+
+int proc_get_ft_flags(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+
+ RTW_PRINT_SEL(m, "0x%02x\n", adapter->mlmepriv.ftpriv.ft_flags);
+
+ return 0;
+}
+#endif
+
+int proc_get_qos_option(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+
+ RTW_PRINT_SEL(m, "qos_option=%d\n", pmlmepriv->qospriv.qos_option);
+
+ return 0;
+}
+
+int proc_get_ht_option(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+
+ RTW_PRINT_SEL(m, "ht_option=%d\n", pmlmepriv->htpriv.ht_option);
+ return 0;
+}
+
+int proc_get_rf_info(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+
+ RTW_PRINT_SEL(m, "cur_ch=%d, cur_bw=%d, cur_ch_offet=%d\n",
+ pmlmeext->cur_channel, pmlmeext->cur_bwmode, pmlmeext->cur_ch_offset);
+
+ RTW_PRINT_SEL(m, "oper_ch=%d, oper_bw=%d, oper_ch_offet=%d\n",
+ rtw_get_oper_ch(padapter), rtw_get_oper_bw(padapter), rtw_get_oper_choffset(padapter));
+
+ return 0;
+}
+
+int proc_get_scan_param(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_ext_priv *mlmeext = &adapter->mlmeextpriv;
+ struct ss_res *ss = &mlmeext->sitesurvey_res;
+
+#define SCAN_PARAM_TITLE_FMT "%10s"
+#define SCAN_PARAM_VALUE_FMT "%-10u"
+#define SCAN_PARAM_TITLE_ARG , "scan_ch_ms"
+#define SCAN_PARAM_VALUE_ARG , ss->scan_ch_ms
+#define SCAN_PARAM_TITLE_FMT_HT " %15s %13s"
+#define SCAN_PARAM_VALUE_FMT_HT " %-15u %-13u"
+#define SCAN_PARAM_TITLE_ARG_HT , "rx_ampdu_accept", "rx_ampdu_size"
+#define SCAN_PARAM_VALUE_ARG_HT , ss->rx_ampdu_accept, ss->rx_ampdu_size
+#ifdef CONFIG_SCAN_BACKOP
+#define SCAN_PARAM_TITLE_FMT_BACKOP " %9s %12s"
+#define SCAN_PARAM_VALUE_FMT_BACKOP " %-9u %-12u"
+#define SCAN_PARAM_TITLE_ARG_BACKOP , "backop_ms", "scan_cnt_max"
+#define SCAN_PARAM_VALUE_ARG_BACKOP , ss->backop_ms, ss->scan_cnt_max
+#else
+#define SCAN_PARAM_TITLE_FMT_BACKOP ""
+#define SCAN_PARAM_VALUE_FMT_BACKOP ""
+#define SCAN_PARAM_TITLE_ARG_BACKOP
+#define SCAN_PARAM_VALUE_ARG_BACKOP
+#endif
+
+ RTW_PRINT_SEL(m,
+ SCAN_PARAM_TITLE_FMT
+ SCAN_PARAM_TITLE_FMT_HT
+ SCAN_PARAM_TITLE_FMT_BACKOP
+ "\n"
+ SCAN_PARAM_TITLE_ARG
+ SCAN_PARAM_TITLE_ARG_HT
+ SCAN_PARAM_TITLE_ARG_BACKOP
+ );
+
+ RTW_PRINT_SEL(m,
+ SCAN_PARAM_VALUE_FMT
+ SCAN_PARAM_VALUE_FMT_HT
+ SCAN_PARAM_VALUE_FMT_BACKOP
+ "\n"
+ SCAN_PARAM_VALUE_ARG
+ SCAN_PARAM_VALUE_ARG_HT
+ SCAN_PARAM_VALUE_ARG_BACKOP
+ );
+
+ return 0;
+}
+
+ssize_t proc_set_scan_param(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_ext_priv *mlmeext = &adapter->mlmeextpriv;
+ struct ss_res *ss = &mlmeext->sitesurvey_res;
+
+ char tmp[32] = {0};
+
+ u16 scan_ch_ms;
+#define SCAN_PARAM_INPUT_FMT "%hu"
+#define SCAN_PARAM_INPUT_ARG , &scan_ch_ms
+ u8 rx_ampdu_accept;
+ u8 rx_ampdu_size;
+#define SCAN_PARAM_INPUT_FMT_HT " %hhu %hhu"
+#define SCAN_PARAM_INPUT_ARG_HT , &rx_ampdu_accept, &rx_ampdu_size
+#ifdef CONFIG_SCAN_BACKOP
+ u16 backop_ms;
+ u8 scan_cnt_max;
+#define SCAN_PARAM_INPUT_FMT_BACKOP " %hu %hhu"
+#define SCAN_PARAM_INPUT_ARG_BACKOP , &backop_ms, &scan_cnt_max
+#else
+#define SCAN_PARAM_INPUT_FMT_BACKOP ""
+#define SCAN_PARAM_INPUT_ARG_BACKOP
+#endif
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp,
+ SCAN_PARAM_INPUT_FMT
+ SCAN_PARAM_INPUT_FMT_HT
+ SCAN_PARAM_INPUT_FMT_BACKOP
+ SCAN_PARAM_INPUT_ARG
+ SCAN_PARAM_INPUT_ARG_HT
+ SCAN_PARAM_INPUT_ARG_BACKOP
+ );
+
+ if (num-- > 0)
+ ss->scan_ch_ms = scan_ch_ms;
+ if (num-- > 0)
+ ss->rx_ampdu_accept = rx_ampdu_accept;
+ if (num-- > 0)
+ ss->rx_ampdu_size = rx_ampdu_size;
+#ifdef CONFIG_SCAN_BACKOP
+ if (num-- > 0)
+ ss->backop_ms = backop_ms;
+ if (num-- > 0)
+ ss->scan_cnt_max = scan_cnt_max;
+#endif
+ }
+
+ return count;
+}
+
+int proc_get_scan_abort(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ u32 pass_ms;
+
+ pass_ms = rtw_scan_abort_timeout(adapter, 10000);
+
+ RTW_PRINT_SEL(m, "%u\n", pass_ms);
+
+ return 0;
+}
+
+#ifdef CONFIG_SCAN_BACKOP
+int proc_get_backop_flags_sta(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_ext_priv *mlmeext = &adapter->mlmeextpriv;
+
+ RTW_PRINT_SEL(m, "0x%02x\n", mlmeext_scan_backop_flags_sta(mlmeext));
+
+ return 0;
+}
+
+ssize_t proc_set_backop_flags_sta(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_ext_priv *mlmeext = &adapter->mlmeextpriv;
+
+ char tmp[32];
+ u8 flags;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%hhx", &flags);
+
+ if (num == 1)
+ mlmeext_assign_scan_backop_flags_sta(mlmeext, flags);
+ }
+
+ return count;
+}
+
+int proc_get_backop_flags_ap(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_ext_priv *mlmeext = &adapter->mlmeextpriv;
+
+ RTW_PRINT_SEL(m, "0x%02x\n", mlmeext_scan_backop_flags_ap(mlmeext));
+
+ return 0;
+}
+
+ssize_t proc_set_backop_flags_ap(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_ext_priv *mlmeext = &adapter->mlmeextpriv;
+
+ char tmp[32];
+ u8 flags;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%hhx", &flags);
+
+ if (num == 1)
+ mlmeext_assign_scan_backop_flags_ap(mlmeext, flags);
+ }
+
+ return count;
+}
+
+#endif /* CONFIG_SCAN_BACKOP */
+
+int proc_get_survey_info(struct seq_file *m, void *v)
+{
+ unsigned long irqL;
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ _queue *queue = &(pmlmepriv->scanned_queue);
+ struct wlan_network *pnetwork = NULL;
+ _list *plist, *phead;
+ s32 notify_signal;
+ s16 notify_noise = 0;
+ u16 index = 0, ie_cap = 0;
+ unsigned char *ie_wpa = NULL, *ie_wpa2 = NULL, *ie_wps = NULL;
+ unsigned char *ie_p2p = NULL, *ssid = NULL;
+ char flag_str[64];
+ int ielen = 0;
+ u32 wpsielen = 0;
+
+ _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
+ phead = get_list_head(queue);
+ if (!phead)
+ goto exit;
+ plist = get_next(phead);
+ if (!plist)
+ goto exit;
+
+ RTW_PRINT_SEL(m, "%5s %-17s %3s %-3s %-4s %-4s %5s %32s %32s\n", "index", "bssid", "ch", "RSSI", "SdBm", "Noise", "age", "flag", "ssid");
+ while (1) {
+ if (rtw_end_of_queue_search(phead, plist) == true)
+ break;
+
+ pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
+ if (!pnetwork)
+ break;
+
+ if (check_fwstate(pmlmepriv, _FW_LINKED) == true &&
+ is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network, 0)) {
+ notify_signal = translate_percentage_to_dbm(padapter->recvpriv.signal_strength);/* dbm */
+ } else {
+ notify_signal = translate_percentage_to_dbm(pnetwork->network.PhyInfo.SignalStrength);/* dbm */
+ }
+
+#if defined(CONFIG_SIGNAL_DISPLAY_DBM) && defined(CONFIG_BACKGROUND_NOISE_MONITOR)
+ rtw_hal_get_odm_var(padapter, HAL_ODM_NOISE_MONITOR, &(pnetwork->network.Configuration.DSConfig), &(notify_noise));
+#endif
+
+ ie_wpa = rtw_get_wpa_ie(&pnetwork->network.IEs[12], &ielen, pnetwork->network.IELength - 12);
+ ie_wpa2 = rtw_get_wpa2_ie(&pnetwork->network.IEs[12], &ielen, pnetwork->network.IELength - 12);
+ ie_cap = rtw_get_capability(&pnetwork->network);
+ ie_wps = rtw_get_wps_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &wpsielen);
+ ie_p2p = rtw_get_p2p_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &ielen);
+ ssid = pnetwork->network.Ssid.Ssid;
+ sprintf(flag_str, "%s%s%s%s%s%s%s",
+ (ie_wpa) ? "[WPA]" : "",
+ (ie_wpa2) ? "[WPA2]" : "",
+ (!ie_wpa && !ie_wpa && ie_cap & BIT(4)) ? "[WEP]" : "",
+ (ie_wps) ? "[WPS]" : "",
+ (pnetwork->network.InfrastructureMode == Ndis802_11IBSS) ? "[IBSS]" : "",
+ (ie_cap & BIT(0)) ? "[ESS]" : "",
+ (ie_p2p) ? "[P2P]" : "");
+ RTW_PRINT_SEL(m, "%5d "MAC_FMT" %3d %3d %4d %4d %5d %32s %32s\n",
+ ++index,
+ MAC_ARG(pnetwork->network.MacAddress),
+ pnetwork->network.Configuration.DSConfig,
+ (int)pnetwork->network.Rssi,
+ notify_signal,
+ notify_noise,
+ rtw_get_passing_time_ms((u32)pnetwork->last_scanned),
+ flag_str,
+ pnetwork->network.Ssid.Ssid);
+ plist = get_next(plist);
+ }
+exit:
+ _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
+
+ return 0;
+}
+
+ssize_t proc_set_survey_info(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ unsigned long irqL;
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ bool need_indicate_scan_done = false;
+ u8 _status = false;
+ NDIS_802_11_SSID ssid[RTW_SSID_SCAN_AMOUNT];
+
+ if (count < 1)
+ return -EFAULT;
+
+#ifdef CONFIG_MP_INCLUDED
+ if (rtw_mi_mp_mode_check(padapter)) {
+ RTW_INFO("MP mode block Scan request\n");
+ goto exit;
+ }
+#endif
+ if (rtw_is_scan_deny(padapter)) {
+ RTW_INFO(FUNC_ADPT_FMT ": scan deny\n", FUNC_ADPT_ARG(padapter));
+ goto exit;
+ }
+
+ rtw_ps_deny(padapter, PS_DENY_SCAN);
+ if (_FAIL == rtw_pwr_wakeup(padapter))
+ goto cancel_ps_deny;
+
+ if (!rtw_is_adapter_up(padapter)) {
+ RTW_INFO("scan abort!! adapter cannot use\n");
+ goto cancel_ps_deny;
+ }
+
+ if (rtw_mi_busy_traffic_check(padapter, false)) {
+ RTW_INFO("scan abort!! BusyTraffic == true\n");
+ goto cancel_ps_deny;
+ }
+
+ if (check_fwstate(pmlmepriv, WIFI_AP_STATE) && check_fwstate(pmlmepriv, WIFI_UNDER_WPS)) {
+ RTW_INFO("scan abort!! AP mode process WPS\n");
+ goto cancel_ps_deny;
+ }
+ if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING) == true) {
+ RTW_INFO("scan abort!! fwstate=0x%x\n", pmlmepriv->fw_state);
+ goto cancel_ps_deny;
+ }
+
+#ifdef CONFIG_CONCURRENT_MODE
+ if (rtw_mi_buddy_check_fwstate(padapter,
+ _FW_UNDER_SURVEY | _FW_UNDER_LINKING | WIFI_UNDER_WPS)) {
+ RTW_INFO("scan abort!! buddy_fwstate check failed\n");
+ goto cancel_ps_deny;
+ }
+#endif
+ _status = rtw_set_802_11_bssid_list_scan(padapter, NULL, 0, NULL, 0);
+
+cancel_ps_deny:
+ rtw_ps_deny_cancel(padapter, PS_DENY_SCAN);
+exit:
+ return count;
+}
+
+int proc_get_ap_info(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ struct sta_info *psta;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct wlan_network *cur_network = &(pmlmepriv->cur_network);
+ struct sta_priv *pstapriv = &padapter->stapriv;
+
+ psta = rtw_get_stainfo(pstapriv, cur_network->network.MacAddress);
+ if (psta) {
+ int i;
+ struct recv_reorder_ctrl *preorder_ctrl;
+
+ RTW_PRINT_SEL(m, "SSID=%s\n", cur_network->network.Ssid.Ssid);
+ RTW_PRINT_SEL(m, "sta's macaddr:" MAC_FMT "\n", MAC_ARG(psta->hwaddr));
+ RTW_PRINT_SEL(m, "cur_channel=%d, cur_bwmode=%d, cur_ch_offset=%d\n", pmlmeext->cur_channel, pmlmeext->cur_bwmode, pmlmeext->cur_ch_offset);
+ RTW_PRINT_SEL(m, "wireless_mode=0x%x, rtsen=%d, cts2slef=%d\n", psta->wireless_mode, psta->rtsen, psta->cts2self);
+ RTW_PRINT_SEL(m, "state=0x%x, aid=%d, macid=%d, raid=%d\n", psta->state, psta->aid, psta->mac_id, psta->raid);
+ RTW_PRINT_SEL(m, "qos_en=%d, ht_en=%d, init_rate=%d\n", psta->qos_option, psta->htpriv.ht_option, psta->init_rate);
+ RTW_PRINT_SEL(m, "bwmode=%d, ch_offset=%d, sgi_20m=%d,sgi_40m=%d\n", psta->bw_mode, psta->htpriv.ch_offset, psta->htpriv.sgi_20m, psta->htpriv.sgi_40m);
+ RTW_PRINT_SEL(m, "ampdu_enable = %d\n", psta->htpriv.ampdu_enable);
+ RTW_PRINT_SEL(m, "agg_enable_bitmap=%x, candidate_tid_bitmap=%x\n", psta->htpriv.agg_enable_bitmap, psta->htpriv.candidate_tid_bitmap);
+ RTW_PRINT_SEL(m, "ldpc_cap=0x%x, stbc_cap=0x%x, beamform_cap=0x%x\n", psta->htpriv.ldpc_cap, psta->htpriv.stbc_cap, psta->htpriv.beamform_cap);
+ sta_rx_reorder_ctl_dump(m, psta);
+ } else
+ RTW_PRINT_SEL(m, "can't get sta's macaddr, cur_network's macaddr:" MAC_FMT "\n", MAC_ARG(cur_network->network.MacAddress));
+
+ return 0;
+}
+
+ssize_t proc_reset_trx_info(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct dvobj_priv *psdpriv = padapter->dvobj;
+ struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
+ char cmd[32] = {0};
+ u8 cnt = 0;
+
+ if (count > sizeof(cmd)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(cmd, buffer, count)) {
+ int num = sscanf(cmd, "%hhx", &cnt);
+
+ if (0 == cnt) {
+ pdbgpriv->dbg_rx_ampdu_drop_count = 0;
+ pdbgpriv->dbg_rx_ampdu_forced_indicate_count = 0;
+ pdbgpriv->dbg_rx_ampdu_loss_count = 0;
+ pdbgpriv->dbg_rx_dup_mgt_frame_drop_count = 0;
+ pdbgpriv->dbg_rx_ampdu_window_shift_cnt = 0;
+ pdbgpriv->dbg_rx_conflic_mac_addr_cnt = 0;
+ }
+ }
+
+ return count;
+}
+
+int proc_get_trx_info(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ int i;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
+ struct recv_priv *precvpriv = &padapter->recvpriv;
+ struct dvobj_priv *psdpriv = padapter->dvobj;
+ struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
+ struct hw_xmit *phwxmit;
+
+ dump_os_queue(m, padapter);
+
+ RTW_PRINT_SEL(m, "free_xmitbuf_cnt=%d, free_xmitframe_cnt=%d\n"
+ , pxmitpriv->free_xmitbuf_cnt, pxmitpriv->free_xmitframe_cnt);
+ RTW_PRINT_SEL(m, "free_ext_xmitbuf_cnt=%d, free_xframe_ext_cnt=%d\n"
+ , pxmitpriv->free_xmit_extbuf_cnt, pxmitpriv->free_xframe_ext_cnt);
+ RTW_PRINT_SEL(m, "free_recvframe_cnt=%d\n"
+ , precvpriv->free_recvframe_cnt);
+
+ for (i = 0; i < 4; i++) {
+ phwxmit = pxmitpriv->hwxmits + i;
+ RTW_PRINT_SEL(m, "%d, hwq.accnt=%d\n", i, phwxmit->accnt);
+ }
+
+ RTW_PRINT_SEL(m, "rx_urb_pending_cn=%d\n", ATOMIC_READ(&(precvpriv->rx_pending_cnt)));
+
+ /* Folowing are RX info */
+ /* Counts of packets whose seq_num is less than preorder_ctrl->indicate_seq, Ex delay, retransmission, redundant packets and so on */
+ RTW_PRINT_SEL(m, "Rx: Counts of Packets Whose Seq_Num Less Than Reorder Control Seq_Num: %llu\n", (unsigned long long)pdbgpriv->dbg_rx_ampdu_drop_count);
+ /* How many times the Rx Reorder Timer is triggered. */
+ RTW_PRINT_SEL(m, "Rx: Reorder Time-out Trigger Counts: %llu\n", (unsigned long long)pdbgpriv->dbg_rx_ampdu_forced_indicate_count);
+ /* Total counts of packets loss */
+ RTW_PRINT_SEL(m, "Rx: Packet Loss Counts: %llu\n", (unsigned long long)pdbgpriv->dbg_rx_ampdu_loss_count);
+ RTW_PRINT_SEL(m, "Rx: Duplicate Management Frame Drop Count: %llu\n", (unsigned long long)pdbgpriv->dbg_rx_dup_mgt_frame_drop_count);
+ RTW_PRINT_SEL(m, "Rx: AMPDU BA window shift Count: %llu\n", (unsigned long long)pdbgpriv->dbg_rx_ampdu_window_shift_cnt);
+ /*The same mac addr counts*/
+ RTW_PRINT_SEL(m, "Rx: Conflict MAC Address Frames Count: %llu\n", (unsigned long long)pdbgpriv->dbg_rx_conflic_mac_addr_cnt);
+ return 0;
+}
+
+int proc_get_dis_pwt(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ u8 dis_pwt = 0;
+ rtw_hal_get_def_var(padapter, HAL_DEF_DBG_DIS_PWT, &(dis_pwt));
+ RTW_PRINT_SEL(m, " Tx Power training mode:%s\n", (dis_pwt == true) ? "Disable" : "Enable");
+ return 0;
+}
+ssize_t proc_set_dis_pwt(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[4] = {0};
+ u8 dis_pwt = 0;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%hhx", &dis_pwt);
+ RTW_INFO("Set Tx Power training mode:%s\n", (dis_pwt == true) ? "Disable" : "Enable");
+
+ if (num >= 1)
+ rtw_hal_set_def_var(padapter, HAL_DEF_DBG_DIS_PWT, &(dis_pwt));
+ }
+
+ return count;
+
+}
+
+int proc_get_rate_ctl(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ int i;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ u8 data_rate = 0, sgi = 0, data_fb = 0;
+
+ if (adapter->fix_rate != 0xff) {
+ data_rate = adapter->fix_rate & 0x7F;
+ sgi = adapter->fix_rate >> 7;
+ data_fb = adapter->data_fb ? 1 : 0;
+ RTW_PRINT_SEL(m, "FIXED %s%s%s\n"
+ , HDATA_RATE(data_rate)
+ , data_rate > DESC_RATE54M ? (sgi ? " SGI" : " LGI") : ""
+ , data_fb ? " FB" : ""
+ );
+ RTW_PRINT_SEL(m, "0x%02x %u\n", adapter->fix_rate, adapter->data_fb);
+ } else
+ RTW_PRINT_SEL(m, "RA\n");
+
+ return 0;
+}
+
+ssize_t proc_set_rate_ctl(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[32];
+ u8 fix_rate;
+ u8 data_fb;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%hhx %hhu", &fix_rate, &data_fb);
+
+ if (num >= 1) {
+ u8 fix_rate_ori = adapter->fix_rate;
+
+ adapter->fix_rate = fix_rate;
+ if (adapter->fix_bw != 0xFF && fix_rate_ori != fix_rate)
+ rtw_update_tx_rate_bmp(adapter_to_dvobj(adapter));
+ }
+ if (num >= 2)
+ adapter->data_fb = data_fb ? 1 : 0;
+ }
+
+ return count;
+}
+
+int proc_get_tx_power_offset(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ int i;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+
+ RTW_PRINT_SEL(m, "Tx power offset - %u\n", adapter->power_offset);
+ return 0;
+}
+
+ssize_t proc_set_tx_power_offset(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[32];
+ u8 power_offset = 0;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%hhu", &power_offset);
+
+ if (num >= 1) {
+ if (power_offset > 5)
+ power_offset = 0;
+
+ adapter->power_offset = power_offset;
+ }
+ }
+
+ return count;
+}
+
+int proc_get_bw_ctl(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ u8 data_bw = 0;
+
+ if (adapter->fix_bw != 0xff) {
+ data_bw = adapter->fix_bw;
+ RTW_PRINT_SEL(m, "FIXED %s\n", ch_width_str(data_bw));
+ } else
+ RTW_PRINT_SEL(m, "Auto\n");
+
+ return 0;
+}
+
+ssize_t proc_set_bw_ctl(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[32];
+ u8 fix_bw;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+ int num = sscanf(tmp, "%hhu", &fix_bw);
+
+ if (num >= 1) {
+ u8 fix_bw_ori = adapter->fix_bw;
+
+ adapter->fix_bw = fix_bw;
+
+ if (adapter->fix_rate != 0xFF && fix_bw_ori != fix_bw)
+ rtw_update_tx_rate_bmp(adapter_to_dvobj(adapter));
+ }
+ }
+
+ return count;
+}
+
+#ifdef DBG_RX_COUNTER_DUMP
+int proc_get_rx_cnt_dump(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ int i;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+
+ RTW_PRINT_SEL(m, "BIT0- Dump RX counters of DRV\n");
+ RTW_PRINT_SEL(m, "BIT1- Dump RX counters of MAC\n");
+ RTW_PRINT_SEL(m, "BIT2- Dump RX counters of PHY\n");
+ RTW_PRINT_SEL(m, "BIT3- Dump TRX data frame of DRV\n");
+ RTW_PRINT_SEL(m, "dump_rx_cnt_mode = 0x%02x\n", adapter->dump_rx_cnt_mode);
+
+ return 0;
+}
+ssize_t proc_set_rx_cnt_dump(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[32];
+ u8 dump_rx_cnt_mode;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%hhx", &dump_rx_cnt_mode);
+
+ rtw_dump_phy_rxcnts_preprocess(adapter, dump_rx_cnt_mode);
+ adapter->dump_rx_cnt_mode = dump_rx_cnt_mode;
+
+ }
+
+ return count;
+}
+#endif
+ssize_t proc_set_fwdl_test_case(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[32];
+ int num;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count))
+ num = sscanf(tmp, "%hhu %hhu", &fwdl_test_chksum_fail, &fwdl_test_wintint_rdy_fail);
+
+ return count;
+}
+
+ssize_t proc_set_del_rx_ampdu_test_case(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[32];
+ int num;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count))
+ num = sscanf(tmp, "%hhu", &del_rx_ampdu_test_no_tx_fail);
+
+ return count;
+}
+
+#ifdef CONFIG_DFS_MASTER
+int proc_get_dfs_master_test_case(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
+
+ RTW_PRINT_SEL(m, "%-24s %-19s\n", "radar_detect_trigger_non", "choose_dfs_ch_first");
+ RTW_PRINT_SEL(m, "%24hhu %19hhu\n"
+ , rfctl->dbg_dfs_master_radar_detect_trigger_non
+ , rfctl->dbg_dfs_master_choose_dfs_ch_first
+ );
+
+ return 0;
+}
+
+ssize_t proc_set_dfs_master_test_case(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+ struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
+ char tmp[32];
+ u8 radar_detect_trigger_non;
+ u8 choose_dfs_ch_first;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+ int num = sscanf(tmp, "%hhu %hhu", &radar_detect_trigger_non, &choose_dfs_ch_first);
+
+ if (num >= 1)
+ rfctl->dbg_dfs_master_radar_detect_trigger_non = radar_detect_trigger_non;
+ if (num >= 2)
+ rfctl->dbg_dfs_master_choose_dfs_ch_first = choose_dfs_ch_first;
+ }
+
+ return count;
+}
+#endif /* CONFIG_DFS_MASTER */
+
+ssize_t proc_set_wait_hiq_empty(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[32];
+ int num;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count))
+ num = sscanf(tmp, "%u", &g_wait_hiq_empty_ms);
+
+ return count;
+}
+
+int proc_get_suspend_resume_info(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct dvobj_priv *dvobj = padapter->dvobj;
+ struct debug_priv *pdbgpriv = &dvobj->drv_dbg;
+
+ RTW_PRINT_SEL(m, "dbg_sdio_alloc_irq_cnt=%d\n", pdbgpriv->dbg_sdio_alloc_irq_cnt);
+ RTW_PRINT_SEL(m, "dbg_sdio_free_irq_cnt=%d\n", pdbgpriv->dbg_sdio_free_irq_cnt);
+ RTW_PRINT_SEL(m, "dbg_sdio_alloc_irq_error_cnt=%d\n", pdbgpriv->dbg_sdio_alloc_irq_error_cnt);
+ RTW_PRINT_SEL(m, "dbg_sdio_free_irq_error_cnt=%d\n", pdbgpriv->dbg_sdio_free_irq_error_cnt);
+ RTW_PRINT_SEL(m, "dbg_sdio_init_error_cnt=%d\n", pdbgpriv->dbg_sdio_init_error_cnt);
+ RTW_PRINT_SEL(m, "dbg_sdio_deinit_error_cnt=%d\n", pdbgpriv->dbg_sdio_deinit_error_cnt);
+ RTW_PRINT_SEL(m, "dbg_suspend_error_cnt=%d\n", pdbgpriv->dbg_suspend_error_cnt);
+ RTW_PRINT_SEL(m, "dbg_suspend_cnt=%d\n", pdbgpriv->dbg_suspend_cnt);
+ RTW_PRINT_SEL(m, "dbg_resume_cnt=%d\n", pdbgpriv->dbg_resume_cnt);
+ RTW_PRINT_SEL(m, "dbg_resume_error_cnt=%d\n", pdbgpriv->dbg_resume_error_cnt);
+ RTW_PRINT_SEL(m, "dbg_deinit_fail_cnt=%d\n", pdbgpriv->dbg_deinit_fail_cnt);
+ RTW_PRINT_SEL(m, "dbg_carddisable_cnt=%d\n", pdbgpriv->dbg_carddisable_cnt);
+ RTW_PRINT_SEL(m, "dbg_ps_insuspend_cnt=%d\n", pdbgpriv->dbg_ps_insuspend_cnt);
+ RTW_PRINT_SEL(m, "dbg_dev_unload_inIPS_cnt=%d\n", pdbgpriv->dbg_dev_unload_inIPS_cnt);
+ RTW_PRINT_SEL(m, "dbg_scan_pwr_state_cnt=%d\n", pdbgpriv->dbg_scan_pwr_state_cnt);
+ RTW_PRINT_SEL(m, "dbg_downloadfw_pwr_state_cnt=%d\n", pdbgpriv->dbg_downloadfw_pwr_state_cnt);
+ RTW_PRINT_SEL(m, "dbg_carddisable_error_cnt=%d\n", pdbgpriv->dbg_carddisable_error_cnt);
+ RTW_PRINT_SEL(m, "dbg_fw_read_ps_state_fail_cnt=%d\n", pdbgpriv->dbg_fw_read_ps_state_fail_cnt);
+ RTW_PRINT_SEL(m, "dbg_leave_ips_fail_cnt=%d\n", pdbgpriv->dbg_leave_ips_fail_cnt);
+ RTW_PRINT_SEL(m, "dbg_leave_lps_fail_cnt=%d\n", pdbgpriv->dbg_leave_lps_fail_cnt);
+ RTW_PRINT_SEL(m, "dbg_h2c_leave32k_fail_cnt=%d\n", pdbgpriv->dbg_h2c_leave32k_fail_cnt);
+ RTW_PRINT_SEL(m, "dbg_diswow_dload_fw_fail_cnt=%d\n", pdbgpriv->dbg_diswow_dload_fw_fail_cnt);
+ RTW_PRINT_SEL(m, "dbg_enwow_dload_fw_fail_cnt=%d\n", pdbgpriv->dbg_enwow_dload_fw_fail_cnt);
+ RTW_PRINT_SEL(m, "dbg_ips_drvopen_fail_cnt=%d\n", pdbgpriv->dbg_ips_drvopen_fail_cnt);
+ RTW_PRINT_SEL(m, "dbg_poll_fail_cnt=%d\n", pdbgpriv->dbg_poll_fail_cnt);
+ RTW_PRINT_SEL(m, "dbg_rpwm_toogle_cnt=%d\n", pdbgpriv->dbg_rpwm_toogle_cnt);
+ RTW_PRINT_SEL(m, "dbg_rpwm_timeout_fail_cnt=%d\n", pdbgpriv->dbg_rpwm_timeout_fail_cnt);
+ RTW_PRINT_SEL(m, "dbg_sreset_cnt=%d\n", pdbgpriv->dbg_sreset_cnt);
+
+ return 0;
+}
+
+#ifdef CONFIG_DBG_COUNTER
+
+int proc_get_rx_logs(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct rx_logs *rx_logs = &padapter->rx_logs;
+
+ RTW_PRINT_SEL(m,
+ "intf_rx=%d\n"
+ "intf_rx_err_recvframe=%d\n"
+ "intf_rx_err_skb=%d\n"
+ "intf_rx_report=%d\n"
+ "core_rx=%d\n"
+ "core_rx_pre=%d\n"
+ "core_rx_pre_ver_err=%d\n"
+ "core_rx_pre_mgmt=%d\n"
+ "core_rx_pre_mgmt_err_80211w=%d\n"
+ "core_rx_pre_mgmt_err=%d\n"
+ "core_rx_pre_ctrl=%d\n"
+ "core_rx_pre_ctrl_err=%d\n"
+ "core_rx_pre_data=%d\n"
+ "core_rx_pre_data_wapi_seq_err=%d\n"
+ "core_rx_pre_data_wapi_key_err=%d\n"
+ "core_rx_pre_data_handled=%d\n"
+ "core_rx_pre_data_err=%d\n"
+ "core_rx_pre_data_unknown=%d\n"
+ "core_rx_pre_unknown=%d\n"
+ "core_rx_enqueue=%d\n"
+ "core_rx_dequeue=%d\n"
+ "core_rx_post=%d\n"
+ "core_rx_post_decrypt=%d\n"
+ "core_rx_post_decrypt_wep=%d\n"
+ "core_rx_post_decrypt_tkip=%d\n"
+ "core_rx_post_decrypt_aes=%d\n"
+ "core_rx_post_decrypt_wapi=%d\n"
+ "core_rx_post_decrypt_hw=%d\n"
+ "core_rx_post_decrypt_unknown=%d\n"
+ "core_rx_post_decrypt_err=%d\n"
+ "core_rx_post_defrag_err=%d\n"
+ "core_rx_post_portctrl_err=%d\n"
+ "core_rx_post_indicate=%d\n"
+ "core_rx_post_indicate_in_oder=%d\n"
+ "core_rx_post_indicate_reoder=%d\n"
+ "core_rx_post_indicate_err=%d\n"
+ "os_indicate=%d\n"
+ "os_indicate_ap_mcast=%d\n"
+ "os_indicate_ap_forward=%d\n"
+ "os_indicate_ap_self=%d\n"
+ "os_indicate_err=%d\n"
+ "os_netif_ok=%d\n"
+ "os_netif_err=%d\n",
+ rx_logs->intf_rx,
+ rx_logs->intf_rx_err_recvframe,
+ rx_logs->intf_rx_err_skb,
+ rx_logs->intf_rx_report,
+ rx_logs->core_rx,
+ rx_logs->core_rx_pre,
+ rx_logs->core_rx_pre_ver_err,
+ rx_logs->core_rx_pre_mgmt,
+ rx_logs->core_rx_pre_mgmt_err_80211w,
+ rx_logs->core_rx_pre_mgmt_err,
+ rx_logs->core_rx_pre_ctrl,
+ rx_logs->core_rx_pre_ctrl_err,
+ rx_logs->core_rx_pre_data,
+ rx_logs->core_rx_pre_data_wapi_seq_err,
+ rx_logs->core_rx_pre_data_wapi_key_err,
+ rx_logs->core_rx_pre_data_handled,
+ rx_logs->core_rx_pre_data_err,
+ rx_logs->core_rx_pre_data_unknown,
+ rx_logs->core_rx_pre_unknown,
+ rx_logs->core_rx_enqueue,
+ rx_logs->core_rx_dequeue,
+ rx_logs->core_rx_post,
+ rx_logs->core_rx_post_decrypt,
+ rx_logs->core_rx_post_decrypt_wep,
+ rx_logs->core_rx_post_decrypt_tkip,
+ rx_logs->core_rx_post_decrypt_aes,
+ rx_logs->core_rx_post_decrypt_wapi,
+ rx_logs->core_rx_post_decrypt_hw,
+ rx_logs->core_rx_post_decrypt_unknown,
+ rx_logs->core_rx_post_decrypt_err,
+ rx_logs->core_rx_post_defrag_err,
+ rx_logs->core_rx_post_portctrl_err,
+ rx_logs->core_rx_post_indicate,
+ rx_logs->core_rx_post_indicate_in_oder,
+ rx_logs->core_rx_post_indicate_reoder,
+ rx_logs->core_rx_post_indicate_err,
+ rx_logs->os_indicate,
+ rx_logs->os_indicate_ap_mcast,
+ rx_logs->os_indicate_ap_forward,
+ rx_logs->os_indicate_ap_self,
+ rx_logs->os_indicate_err,
+ rx_logs->os_netif_ok,
+ rx_logs->os_netif_err
+ );
+
+ return 0;
+}
+
+int proc_get_tx_logs(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct tx_logs *tx_logs = &padapter->tx_logs;
+
+ RTW_PRINT_SEL(m,
+ "os_tx=%d\n"
+ "os_tx_err_up=%d\n"
+ "os_tx_err_xmit=%d\n"
+ "os_tx_m2u=%d\n"
+ "os_tx_m2u_ignore_fw_linked=%d\n"
+ "os_tx_m2u_ignore_self=%d\n"
+ "os_tx_m2u_entry=%d\n"
+ "os_tx_m2u_entry_err_xmit=%d\n"
+ "os_tx_m2u_entry_err_skb=%d\n"
+ "os_tx_m2u_stop=%d\n"
+ "core_tx=%d\n"
+ "core_tx_err_pxmitframe=%d\n"
+ "core_tx_err_brtx=%d\n"
+ "core_tx_upd_attrib=%d\n"
+ "core_tx_upd_attrib_adhoc=%d\n"
+ "core_tx_upd_attrib_sta=%d\n"
+ "core_tx_upd_attrib_ap=%d\n"
+ "core_tx_upd_attrib_unknown=%d\n"
+ "core_tx_upd_attrib_dhcp=%d\n"
+ "core_tx_upd_attrib_icmp=%d\n"
+ "core_tx_upd_attrib_active=%d\n"
+ "core_tx_upd_attrib_err_ucast_sta=%d\n"
+ "core_tx_upd_attrib_err_ucast_ap_link=%d\n"
+ "core_tx_upd_attrib_err_sta=%d\n"
+ "core_tx_upd_attrib_err_link=%d\n"
+ "core_tx_upd_attrib_err_sec=%d\n"
+ "core_tx_ap_enqueue_warn_fwstate=%d\n"
+ "core_tx_ap_enqueue_warn_sta=%d\n"
+ "core_tx_ap_enqueue_warn_nosta=%d\n"
+ "core_tx_ap_enqueue_warn_link=%d\n"
+ "core_tx_ap_enqueue_warn_trigger=%d\n"
+ "core_tx_ap_enqueue_mcast=%d\n"
+ "core_tx_ap_enqueue_ucast=%d\n"
+ "core_tx_ap_enqueue=%d\n"
+ "intf_tx=%d\n"
+ "intf_tx_pending_ac=%d\n"
+ "intf_tx_pending_fw_under_survey=%d\n"
+ "intf_tx_pending_fw_under_linking=%d\n"
+ "intf_tx_pending_xmitbuf=%d\n"
+ "intf_tx_enqueue=%d\n"
+ "core_tx_enqueue=%d\n"
+ "core_tx_enqueue_class=%d\n"
+ "core_tx_enqueue_class_err_sta=%d\n"
+ "core_tx_enqueue_class_err_nosta=%d\n"
+ "core_tx_enqueue_class_err_fwlink=%d\n"
+ "intf_tx_direct=%d\n"
+ "intf_tx_direct_err_coalesce=%d\n"
+ "intf_tx_dequeue=%d\n"
+ "intf_tx_dequeue_err_coalesce=%d\n"
+ "intf_tx_dump_xframe=%d\n"
+ "intf_tx_dump_xframe_err_txdesc=%d\n"
+ "intf_tx_dump_xframe_err_port=%d\n",
+ tx_logs->os_tx,
+ tx_logs->os_tx_err_up,
+ tx_logs->os_tx_err_xmit,
+ tx_logs->os_tx_m2u,
+ tx_logs->os_tx_m2u_ignore_fw_linked,
+ tx_logs->os_tx_m2u_ignore_self,
+ tx_logs->os_tx_m2u_entry,
+ tx_logs->os_tx_m2u_entry_err_xmit,
+ tx_logs->os_tx_m2u_entry_err_skb,
+ tx_logs->os_tx_m2u_stop,
+ tx_logs->core_tx,
+ tx_logs->core_tx_err_pxmitframe,
+ tx_logs->core_tx_err_brtx,
+ tx_logs->core_tx_upd_attrib,
+ tx_logs->core_tx_upd_attrib_adhoc,
+ tx_logs->core_tx_upd_attrib_sta,
+ tx_logs->core_tx_upd_attrib_ap,
+ tx_logs->core_tx_upd_attrib_unknown,
+ tx_logs->core_tx_upd_attrib_dhcp,
+ tx_logs->core_tx_upd_attrib_icmp,
+ tx_logs->core_tx_upd_attrib_active,
+ tx_logs->core_tx_upd_attrib_err_ucast_sta,
+ tx_logs->core_tx_upd_attrib_err_ucast_ap_link,
+ tx_logs->core_tx_upd_attrib_err_sta,
+ tx_logs->core_tx_upd_attrib_err_link,
+ tx_logs->core_tx_upd_attrib_err_sec,
+ tx_logs->core_tx_ap_enqueue_warn_fwstate,
+ tx_logs->core_tx_ap_enqueue_warn_sta,
+ tx_logs->core_tx_ap_enqueue_warn_nosta,
+ tx_logs->core_tx_ap_enqueue_warn_link,
+ tx_logs->core_tx_ap_enqueue_warn_trigger,
+ tx_logs->core_tx_ap_enqueue_mcast,
+ tx_logs->core_tx_ap_enqueue_ucast,
+ tx_logs->core_tx_ap_enqueue,
+ tx_logs->intf_tx,
+ tx_logs->intf_tx_pending_ac,
+ tx_logs->intf_tx_pending_fw_under_survey,
+ tx_logs->intf_tx_pending_fw_under_linking,
+ tx_logs->intf_tx_pending_xmitbuf,
+ tx_logs->intf_tx_enqueue,
+ tx_logs->core_tx_enqueue,
+ tx_logs->core_tx_enqueue_class,
+ tx_logs->core_tx_enqueue_class_err_sta,
+ tx_logs->core_tx_enqueue_class_err_nosta,
+ tx_logs->core_tx_enqueue_class_err_fwlink,
+ tx_logs->intf_tx_direct,
+ tx_logs->intf_tx_direct_err_coalesce,
+ tx_logs->intf_tx_dequeue,
+ tx_logs->intf_tx_dequeue_err_coalesce,
+ tx_logs->intf_tx_dump_xframe,
+ tx_logs->intf_tx_dump_xframe_err_txdesc,
+ tx_logs->intf_tx_dump_xframe_err_port
+ );
+
+ return 0;
+}
+
+int proc_get_int_logs(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+
+ RTW_PRINT_SEL(m,
+ "all=%d\n"
+ "err=%d\n"
+ "tbdok=%d\n"
+ "tbder=%d\n"
+ "bcnderr=%d\n"
+ "bcndma=%d\n"
+ "bcndma_e=%d\n"
+ "rx=%d\n"
+ "rx_rdu=%d\n"
+ "rx_fovw=%d\n"
+ "txfovw=%d\n"
+ "mgntok=%d\n"
+ "highdok=%d\n"
+ "bkdok=%d\n"
+ "bedok=%d\n"
+ "vidok=%d\n"
+ "vodok=%d\n",
+ padapter->int_logs.all,
+ padapter->int_logs.err,
+ padapter->int_logs.tbdok,
+ padapter->int_logs.tbder,
+ padapter->int_logs.bcnderr,
+ padapter->int_logs.bcndma,
+ padapter->int_logs.bcndma_e,
+ padapter->int_logs.rx,
+ padapter->int_logs.rx_rdu,
+ padapter->int_logs.rx_fovw,
+ padapter->int_logs.txfovw,
+ padapter->int_logs.mgntok,
+ padapter->int_logs.highdok,
+ padapter->int_logs.bkdok,
+ padapter->int_logs.bedok,
+ padapter->int_logs.vidok,
+ padapter->int_logs.vodok
+ );
+
+ return 0;
+}
+
+#endif /* CONFIG_DBG_COUNTER */
+
+int proc_get_hw_status(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct dvobj_priv *dvobj = padapter->dvobj;
+ struct debug_priv *pdbgpriv = &dvobj->drv_dbg;
+ struct registry_priv *regsty = dvobj_to_regsty(dvobj);
+
+ if (regsty->check_hw_status == 0)
+ RTW_PRINT_SEL(m, "RX FIFO full count: not check in watch dog\n");
+ else if (pdbgpriv->dbg_rx_fifo_last_overflow == 1
+ && pdbgpriv->dbg_rx_fifo_curr_overflow == 1
+ && pdbgpriv->dbg_rx_fifo_diff_overflow == 1
+ )
+ RTW_PRINT_SEL(m, "RX FIFO full count: no implementation\n");
+ else {
+ RTW_PRINT_SEL(m, "RX FIFO full count: last_time=%llu, current_time=%llu, differential=%llu\n"
+ , pdbgpriv->dbg_rx_fifo_last_overflow, pdbgpriv->dbg_rx_fifo_curr_overflow, pdbgpriv->dbg_rx_fifo_diff_overflow);
+ }
+
+ return 0;
+}
+
+ssize_t proc_set_hw_status(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct dvobj_priv *dvobj = padapter->dvobj;
+ struct registry_priv *regsty = dvobj_to_regsty(dvobj);
+ char tmp[32];
+ u32 enable;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%d ", &enable);
+
+ if (regsty && enable <= 1) {
+ regsty->check_hw_status = enable;
+ RTW_INFO("check_hw_status=%d\n", regsty->check_hw_status);
+ }
+ }
+
+ return count;
+}
+
+int proc_get_trx_info_debug(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
+
+ int i;
+
+
+ /*============ tx info ============ */
+ rtw_hal_get_def_var(padapter, HW_DEF_RA_INFO_DUMP, m);
+
+ /*============ rx info ============ */
+ rtw_hal_set_odm_var(padapter, HAL_ODM_RX_INFO_DUMP, m, false);
+
+
+ return 0;
+}
+
+int proc_get_rx_signal(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+
+ RTW_PRINT_SEL(m, "rssi:%d\n", padapter->recvpriv.rssi);
+ /* RTW_PRINT_SEL(m, "rxpwdb:%d\n", padapter->recvpriv.rxpwdb); */
+ RTW_PRINT_SEL(m, "signal_strength:%u\n", padapter->recvpriv.signal_strength);
+ RTW_PRINT_SEL(m, "signal_qual:%u\n", padapter->recvpriv.signal_qual);
+ if (padapter->registrypriv.mp_mode == 1) {
+ if (padapter->mppriv.antenna_rx == ANTENNA_A)
+ RTW_PRINT_SEL(m, "Antenna: A\n");
+ else if (padapter->mppriv.antenna_rx == ANTENNA_B)
+ RTW_PRINT_SEL(m, "Antenna: B\n");
+ else if (padapter->mppriv.antenna_rx == ANTENNA_C)
+ RTW_PRINT_SEL(m, "Antenna: C\n");
+ else if (padapter->mppriv.antenna_rx == ANTENNA_D)
+ RTW_PRINT_SEL(m, "Antenna: D\n");
+ else if (padapter->mppriv.antenna_rx == ANTENNA_AB)
+ RTW_PRINT_SEL(m, "Antenna: AB\n");
+ else if (padapter->mppriv.antenna_rx == ANTENNA_BC)
+ RTW_PRINT_SEL(m, "Antenna: BC\n");
+ else if (padapter->mppriv.antenna_rx == ANTENNA_CD)
+ RTW_PRINT_SEL(m, "Antenna: CD\n");
+ else
+ RTW_PRINT_SEL(m, "Antenna: __\n");
+ return 0;
+ }
+
+ rtw_get_noise(padapter);
+ RTW_PRINT_SEL(m, "noise:%d\n", padapter->recvpriv.noise);
+#ifdef DBG_RX_SIGNAL_DISPLAY_RAW_DATA
+ rtw_odm_get_perpkt_rssi(m, padapter);
+ rtw_get_raw_rssi_info(m, padapter);
+#endif
+ return 0;
+}
+
+ssize_t proc_set_rx_signal(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[32];
+ u32 is_signal_dbg, signal_strength;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%u %u", &is_signal_dbg, &signal_strength);
+
+ is_signal_dbg = is_signal_dbg == 0 ? 0 : 1;
+
+ if (is_signal_dbg && num != 2)
+ return count;
+
+ signal_strength = signal_strength > 100 ? 100 : signal_strength;
+
+ padapter->recvpriv.is_signal_dbg = is_signal_dbg;
+ padapter->recvpriv.signal_strength_dbg = signal_strength;
+
+ if (is_signal_dbg)
+ RTW_INFO("set %s %u\n", "DBG_SIGNAL_STRENGTH", signal_strength);
+ else
+ RTW_INFO("set %s\n", "HW_SIGNAL_STRENGTH");
+
+ }
+
+ return count;
+
+}
+
+int proc_get_ht_enable(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+
+ if (pregpriv)
+ RTW_PRINT_SEL(m, "%d\n", pregpriv->ht_enable);
+
+ return 0;
+}
+
+ssize_t proc_set_ht_enable(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+ char tmp[32];
+ u32 mode;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%d ", &mode);
+
+ if (pregpriv && mode < 2) {
+ pregpriv->ht_enable = mode;
+ RTW_INFO("ht_enable=%d\n", pregpriv->ht_enable);
+ }
+ }
+
+ return count;
+
+}
+
+int proc_get_bw_mode(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+
+ if (pregpriv)
+ RTW_PRINT_SEL(m, "0x%02x\n", pregpriv->bw_mode);
+
+ return 0;
+}
+
+ssize_t proc_set_bw_mode(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+ char tmp[32];
+ u32 mode;
+ u8 bw_2g;
+ u8 bw_5g;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%x ", &mode);
+ bw_5g = mode >> 4;
+ bw_2g = mode & 0x0f;
+
+ if (pregpriv && bw_2g <= 4 && bw_5g <= 4) {
+
+ pregpriv->bw_mode = mode;
+ RTW_INFO("bw_mode=0x%x\n", mode);
+
+ }
+ }
+
+ return count;
+
+}
+
+int proc_get_ampdu_enable(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+
+ if (pregpriv)
+ RTW_PRINT_SEL(m, "%d\n", pregpriv->ampdu_enable);
+
+ return 0;
+}
+
+ssize_t proc_set_ampdu_enable(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+ char tmp[32];
+ u32 mode;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%d ", &mode);
+
+ if (pregpriv && mode < 2) {
+ pregpriv->ampdu_enable = mode;
+ RTW_INFO("ampdu_enable=%d\n", mode);
+ }
+
+ }
+
+ return count;
+
+}
+
+int proc_get_mac_rptbuf(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ u16 i;
+ u16 mac_id;
+ u32 shcut_addr = 0;
+ u32 read_addr = 0;
+ return 0;
+}
+
+int proc_get_rx_ampdu(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+
+ _RTW_PRINT_SEL(m, "accept: ");
+ if (padapter->fix_rx_ampdu_accept == RX_AMPDU_ACCEPT_INVALID)
+ RTW_PRINT_SEL(m, "%u%s\n", rtw_rx_ampdu_is_accept(padapter), "(auto)");
+ else
+ RTW_PRINT_SEL(m, "%u%s\n", padapter->fix_rx_ampdu_accept, "(fixed)");
+
+ _RTW_PRINT_SEL(m, "size: ");
+ if (padapter->fix_rx_ampdu_size == RX_AMPDU_SIZE_INVALID)
+ RTW_PRINT_SEL(m, "%u%s\n", rtw_rx_ampdu_size(padapter), "(auto)");
+ else
+ RTW_PRINT_SEL(m, "%u%s\n", padapter->fix_rx_ampdu_size, "(fixed)");
+
+ RTW_PRINT_SEL(m, "%19s %17s\n", "fix_rx_ampdu_accept", "fix_rx_ampdu_size");
+
+ _RTW_PRINT_SEL(m, "%-19d %-17u\n"
+ , padapter->fix_rx_ampdu_accept
+ , padapter->fix_rx_ampdu_size);
+
+ return 0;
+}
+
+ssize_t proc_set_rx_ampdu(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ char tmp[32];
+ u8 accept;
+ u8 size;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%hhu %hhu", &accept, &size);
+
+ if (num >= 1)
+ rtw_rx_ampdu_set_accept(padapter, accept, RX_AMPDU_DRV_FIXED);
+ if (num >= 2)
+ rtw_rx_ampdu_set_size(padapter, size, RX_AMPDU_DRV_FIXED);
+
+ rtw_rx_ampdu_apply(padapter);
+ }
+
+exit:
+ return count;
+}
+int proc_get_rx_ampdu_factor(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+
+
+ if (padapter)
+ RTW_PRINT_SEL(m, "rx ampdu factor = %x\n", padapter->driver_rx_ampdu_factor);
+
+ return 0;
+}
+
+ssize_t proc_set_rx_ampdu_factor(struct file *file, const char __user *buffer
+ , size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[32];
+ u32 factor;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%d ", &factor);
+
+ if (padapter && (num == 1)) {
+ RTW_INFO("padapter->driver_rx_ampdu_factor = %x\n", factor);
+
+ if (factor > 0x03)
+ padapter->driver_rx_ampdu_factor = 0xFF;
+ else
+ padapter->driver_rx_ampdu_factor = factor;
+ }
+ }
+
+ return count;
+}
+
+int proc_get_rx_ampdu_density(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+
+
+ if (padapter)
+ RTW_PRINT_SEL(m, "rx ampdu densityg = %x\n", padapter->driver_rx_ampdu_spacing);
+
+ return 0;
+}
+
+ssize_t proc_set_rx_ampdu_density(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[32];
+ u32 density;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%d ", &density);
+
+ if (padapter && (num == 1)) {
+ RTW_INFO("padapter->driver_rx_ampdu_spacing = %x\n", density);
+
+ if (density > 0x07)
+ padapter->driver_rx_ampdu_spacing = 0xFF;
+ else
+ padapter->driver_rx_ampdu_spacing = density;
+ }
+ }
+
+ return count;
+}
+
+int proc_get_tx_ampdu_density(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+
+
+ if (padapter)
+ RTW_PRINT_SEL(m, "tx ampdu density = %x\n", padapter->driver_ampdu_spacing);
+
+ return 0;
+}
+
+ssize_t proc_set_tx_ampdu_density(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[32];
+ u32 density;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%d ", &density);
+
+ if (padapter && (num == 1)) {
+ RTW_INFO("padapter->driver_ampdu_spacing = %x\n", density);
+
+ if (density > 0x07)
+ padapter->driver_ampdu_spacing = 0xFF;
+ else
+ padapter->driver_ampdu_spacing = density;
+ }
+ }
+
+ return count;
+}
+
+#ifdef CONFIG_TX_AMSDU
+int proc_get_tx_amsdu(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
+
+ if (padapter)
+ {
+ RTW_PRINT_SEL(m, "tx amsdu = %d\n", padapter->tx_amsdu);
+ RTW_PRINT_SEL(m, "amsdu set timer conut = %u\n", pxmitpriv->amsdu_debug_set_timer);
+ RTW_PRINT_SEL(m, "amsdu time out count = %u\n", pxmitpriv->amsdu_debug_timeout);
+ RTW_PRINT_SEL(m, "amsdu coalesce one count = %u\n", pxmitpriv->amsdu_debug_coalesce_one);
+ RTW_PRINT_SEL(m, "amsdu coalesce two count = %u\n", pxmitpriv->amsdu_debug_coalesce_two);
+ }
+
+ return 0;
+}
+
+ssize_t proc_set_tx_amsdu(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
+ char tmp[32];
+ u32 amsdu;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%d ", &amsdu);
+
+ if (padapter && (num == 1)) {
+ RTW_INFO("padapter->tx_amsdu = %x\n", amsdu);
+
+ if (amsdu > 3)
+ padapter->tx_amsdu = 0;
+ else if(amsdu == 3)
+ {
+ pxmitpriv->amsdu_debug_set_timer = 0;
+ pxmitpriv->amsdu_debug_timeout = 0;
+ pxmitpriv->amsdu_debug_coalesce_one = 0;
+ pxmitpriv->amsdu_debug_coalesce_two = 0;
+ }
+ else
+ padapter->tx_amsdu = amsdu;
+ }
+ }
+
+ return count;
+}
+
+int proc_get_tx_amsdu_rate(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+
+ if (padapter)
+ RTW_PRINT_SEL(m, "tx amsdu rate = %d Mbps\n", padapter->tx_amsdu_rate);
+
+ return 0;
+}
+
+ssize_t proc_set_tx_amsdu_rate(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[32];
+ u32 amsdu_rate;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%d ", &amsdu_rate);
+
+ if (padapter && (num == 1)) {
+ RTW_INFO("padapter->tx_amsdu_rate = %x\n", amsdu_rate);
+ padapter->tx_amsdu_rate = amsdu_rate;
+ }
+ }
+
+ return count;
+}
+#endif /* CONFIG_TX_AMSDU */
+
+int proc_get_en_fwps(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+
+ if (pregpriv)
+ RTW_PRINT_SEL(m, "check_fw_ps = %d , 1:enable get FW PS state , 0: disable get FW PS state\n"
+ , pregpriv->check_fw_ps);
+
+ return 0;
+}
+
+ssize_t proc_set_en_fwps(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ char tmp[32];
+ u32 mode;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%d ", &mode);
+
+ if (pregpriv && mode < 2) {
+ pregpriv->check_fw_ps = mode;
+ RTW_INFO("pregpriv->check_fw_ps=%d\n", pregpriv->check_fw_ps);
+ }
+
+ }
+
+ return count;
+}
+
+/*
+int proc_get_two_path_rssi(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+
+ if(padapter)
+ RTW_PRINT_SEL(m, "%d %d\n",
+ padapter->recvpriv.RxRssi[0], padapter->recvpriv.RxRssi[1]);
+
+ return 0;
+}
+*/
+void rtw_dump_dft_phy_cap(void *sel, _adapter *adapter)
+{
+ struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
+ struct ht_priv *phtpriv = &pmlmepriv->htpriv;
+
+ RTW_PRINT_SEL(sel, "[DFT CAP] HT STBC Tx : %s\n", (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_TX)) ? "V" : "X");
+ RTW_PRINT_SEL(sel, "[DFT CAP] HT STBC Rx : %s\n\n", (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_RX)) ? "V" : "X");
+
+ RTW_PRINT_SEL(sel, "[DFT CAP] HT LDPC Tx : %s\n", (TEST_FLAG(phtpriv->ldpc_cap, LDPC_HT_ENABLE_TX)) ? "V" : "X");
+ RTW_PRINT_SEL(sel, "[DFT CAP] HT LDPC Rx : %s\n\n", (TEST_FLAG(phtpriv->ldpc_cap, LDPC_HT_ENABLE_RX)) ? "V" : "X");
+
+ #ifdef CONFIG_BEAMFORMING
+ RTW_PRINT_SEL(sel, "[DFT CAP] HT Bfer : %s\n", (TEST_FLAG(phtpriv->beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE)) ? "V" : "X");
+ RTW_PRINT_SEL(sel, "[DFT CAP] HT Bfee : %s\n", (TEST_FLAG(phtpriv->beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE)) ? "V" : "X");
+ #endif
+}
+
+void rtw_get_dft_phy_cap(void *sel, _adapter *adapter)
+{
+ RTW_PRINT_SEL(sel, "\n ======== PHY CAP protocol ========\n");
+ rtw_ht_use_default_setting(adapter);
+ rtw_dump_dft_phy_cap(sel, adapter);
+}
+
+void rtw_dump_drv_phy_cap(void *sel, _adapter *adapter)
+{
+ struct registry_priv *pregistry_priv = &adapter->registrypriv;
+
+ RTW_PRINT_SEL(sel, "\n ======== DRV's configuration ========\n");
+ RTW_PRINT_SEL(sel, "[DRV CAP] STBC Capability : 0x%02x\n", pregistry_priv->stbc_cap);
+ RTW_PRINT_SEL(sel, "[DRV CAP] VHT STBC Tx : %s\n", (TEST_FLAG(pregistry_priv->stbc_cap, BIT1)) ? "V" : "X"); /*BIT1: Enable VHT STBC Tx*/
+ RTW_PRINT_SEL(sel, "[DRV CAP] VHT STBC Rx : %s\n", (TEST_FLAG(pregistry_priv->stbc_cap, BIT0)) ? "V" : "X"); /*BIT0: Enable VHT STBC Rx*/
+ RTW_PRINT_SEL(sel, "[DRV CAP] HT STBC Tx : %s\n", (TEST_FLAG(pregistry_priv->stbc_cap, BIT5)) ? "V" : "X"); /*BIT5: Enable HT STBC Tx*/
+ RTW_PRINT_SEL(sel, "[DRV CAP] HT STBC Rx : %s\n\n", (TEST_FLAG(pregistry_priv->stbc_cap, BIT4)) ? "V" : "X"); /*BIT4: Enable HT STBC Rx*/
+
+ RTW_PRINT_SEL(sel, "[DRV CAP] LDPC Capability : 0x%02x\n", pregistry_priv->ldpc_cap);
+ RTW_PRINT_SEL(sel, "[DRV CAP] VHT LDPC Tx : %s\n", (TEST_FLAG(pregistry_priv->ldpc_cap, BIT1)) ? "V" : "X"); /*BIT1: Enable VHT LDPC Tx*/
+ RTW_PRINT_SEL(sel, "[DRV CAP] VHT LDPC Rx : %s\n", (TEST_FLAG(pregistry_priv->ldpc_cap, BIT0)) ? "V" : "X"); /*BIT0: Enable VHT LDPC Rx*/
+ RTW_PRINT_SEL(sel, "[DRV CAP] HT LDPC Tx : %s\n", (TEST_FLAG(pregistry_priv->ldpc_cap, BIT5)) ? "V" : "X"); /*BIT5: Enable HT LDPC Tx*/
+ RTW_PRINT_SEL(sel, "[DRV CAP] HT LDPC Rx : %s\n\n", (TEST_FLAG(pregistry_priv->ldpc_cap, BIT4)) ? "V" : "X"); /*BIT4: Enable HT LDPC Rx*/
+ #ifdef CONFIG_BEAMFORMING
+
+ /*
+ * BIT0: Enable VHT SU Beamformer
+ * BIT1: Enable VHT SU Beamformee
+ * BIT2: Enable VHT MU Beamformer, depend on VHT SU Beamformer
+ * BIT3: Enable VHT MU Beamformee, depend on VHT SU Beamformee
+ * BIT4: Enable HT Beamformer
+ * BIT5: Enable HT Beamformee
+ */
+ RTW_PRINT_SEL(sel, "[DRV CAP] TxBF Capability : 0x%02x\n", pregistry_priv->beamform_cap);
+ RTW_PRINT_SEL(sel, "[DRV CAP] VHT MU Bfer : %s\n", (TEST_FLAG(pregistry_priv->beamform_cap, BIT2)) ? "V" : "X");
+ RTW_PRINT_SEL(sel, "[DRV CAP] VHT MU Bfee : %s\n", (TEST_FLAG(pregistry_priv->beamform_cap, BIT3)) ? "V" : "X");
+ RTW_PRINT_SEL(sel, "[DRV CAP] VHT SU Bfer : %s\n", (TEST_FLAG(pregistry_priv->beamform_cap, BIT0)) ? "V" : "X");
+ RTW_PRINT_SEL(sel, "[DRV CAP] VHT SU Bfee : %s\n", (TEST_FLAG(pregistry_priv->beamform_cap, BIT1)) ? "V" : "X");
+ RTW_PRINT_SEL(sel, "[DRV CAP] HT Bfer : %s\n", (TEST_FLAG(pregistry_priv->beamform_cap, BIT4)) ? "V" : "X");
+ RTW_PRINT_SEL(sel, "[DRV CAP] HT Bfee : %s\n", (TEST_FLAG(pregistry_priv->beamform_cap, BIT5)) ? "V" : "X");
+
+ RTW_PRINT_SEL(sel, "[DRV CAP] Tx Bfer rf_num : %d\n", pregistry_priv->beamformer_rf_num);
+ RTW_PRINT_SEL(sel, "[DRV CAP] Tx Bfee rf_num : %d\n", pregistry_priv->beamformee_rf_num);
+ #endif
+}
+
+int proc_get_stbc_cap(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+
+ if (pregpriv)
+ RTW_PRINT_SEL(m, "0x%02x\n", pregpriv->stbc_cap);
+
+ return 0;
+}
+
+ssize_t proc_set_stbc_cap(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+ char tmp[32];
+ u32 mode;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%d ", &mode);
+
+ if (pregpriv) {
+ pregpriv->stbc_cap = mode;
+ RTW_INFO("stbc_cap = 0x%02x\n", mode);
+ }
+ }
+
+ return count;
+}
+int proc_get_rx_stbc(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+
+ if (pregpriv)
+ RTW_PRINT_SEL(m, "%d\n", pregpriv->rx_stbc);
+
+ return 0;
+}
+
+ssize_t proc_set_rx_stbc(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+ char tmp[32];
+ u32 mode;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%d ", &mode);
+
+ if (pregpriv && (mode == 0 || mode == 1 || mode == 2 || mode == 3)) {
+ pregpriv->rx_stbc = mode;
+ RTW_INFO("rx_stbc=%d\n", mode);
+ }
+ }
+
+ return count;
+
+}
+int proc_get_ldpc_cap(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+
+ if (pregpriv)
+ RTW_PRINT_SEL(m, "0x%02x\n", pregpriv->ldpc_cap);
+
+ return 0;
+}
+
+ssize_t proc_set_ldpc_cap(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+ char tmp[32];
+ u32 mode;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%d ", &mode);
+
+ if (pregpriv) {
+ pregpriv->ldpc_cap = mode;
+ RTW_INFO("ldpc_cap = 0x%02x\n", mode);
+ }
+ }
+
+ return count;
+}
+#ifdef CONFIG_BEAMFORMING
+int proc_get_txbf_cap(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+
+ if (pregpriv)
+ RTW_PRINT_SEL(m, "0x%02x\n", pregpriv->beamform_cap);
+
+ return 0;
+}
+
+ssize_t proc_set_txbf_cap(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct registry_priv *pregpriv = &padapter->registrypriv;
+ char tmp[32];
+ u32 mode;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%d ", &mode);
+
+ if (pregpriv) {
+ pregpriv->beamform_cap = mode;
+ RTW_INFO("beamform_cap = 0x%02x\n", mode);
+ }
+ }
+
+ return count;
+}
+#endif
+
+#ifdef CONFIG_AP_MODE
+
+int proc_get_all_sta_info(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ unsigned long irqL;
+ struct sta_info *psta;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ int i;
+ _list *plist, *phead;
+
+ RTW_PRINT_SEL(m, "sta_dz_bitmap=0x%x, tim_bitmap=0x%x\n", pstapriv->sta_dz_bitmap, pstapriv->tim_bitmap);
+
+ _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
+
+ for (i = 0; i < NUM_STA; i++) {
+ phead = &(pstapriv->sta_hash[i]);
+ plist = get_next(phead);
+
+ while ((rtw_end_of_queue_search(phead, plist)) == false) {
+ psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
+
+ plist = get_next(plist);
+
+ /* if(extra_arg == psta->aid) */
+ {
+ RTW_PRINT_SEL(m, "==============================\n");
+ RTW_PRINT_SEL(m, "sta's macaddr:" MAC_FMT "\n", MAC_ARG(psta->hwaddr));
+ RTW_PRINT_SEL(m, "rtsen=%d, cts2slef=%d\n", psta->rtsen, psta->cts2self);
+ RTW_PRINT_SEL(m, "state=0x%x, aid=%d, macid=%d, raid=%d\n", psta->state, psta->aid, psta->mac_id, psta->raid);
+ RTW_PRINT_SEL(m, "qos_en=%d, ht_en=%d, init_rate=%d\n", psta->qos_option, psta->htpriv.ht_option, psta->init_rate);
+ RTW_PRINT_SEL(m, "bwmode=%d, ch_offset=%d, sgi_20m=%d,sgi_40m=%d\n", psta->bw_mode, psta->htpriv.ch_offset, psta->htpriv.sgi_20m, psta->htpriv.sgi_40m);
+ RTW_PRINT_SEL(m, "ampdu_enable = %d\n", psta->htpriv.ampdu_enable);
+ RTW_PRINT_SEL(m, "tx_amsdu_enable = %d\n", psta->htpriv.tx_amsdu_enable);
+ RTW_PRINT_SEL(m, "agg_enable_bitmap=%x, candidate_tid_bitmap=%x\n", psta->htpriv.agg_enable_bitmap, psta->htpriv.candidate_tid_bitmap);
+ RTW_PRINT_SEL(m, "sleepq_len=%d\n", psta->sleepq_len);
+ RTW_PRINT_SEL(m, "sta_xmitpriv.vo_q_qcnt=%d\n", psta->sta_xmitpriv.vo_q.qcnt);
+ RTW_PRINT_SEL(m, "sta_xmitpriv.vi_q_qcnt=%d\n", psta->sta_xmitpriv.vi_q.qcnt);
+ RTW_PRINT_SEL(m, "sta_xmitpriv.be_q_qcnt=%d\n", psta->sta_xmitpriv.be_q.qcnt);
+ RTW_PRINT_SEL(m, "sta_xmitpriv.bk_q_qcnt=%d\n", psta->sta_xmitpriv.bk_q.qcnt);
+
+ RTW_PRINT_SEL(m, "capability=0x%x\n", psta->capability);
+ RTW_PRINT_SEL(m, "flags=0x%x\n", psta->flags);
+ RTW_PRINT_SEL(m, "wpa_psk=0x%x\n", psta->wpa_psk);
+ RTW_PRINT_SEL(m, "wpa2_group_cipher=0x%x\n", psta->wpa2_group_cipher);
+ RTW_PRINT_SEL(m, "wpa2_pairwise_cipher=0x%x\n", psta->wpa2_pairwise_cipher);
+ RTW_PRINT_SEL(m, "qos_info=0x%x\n", psta->qos_info);
+ RTW_PRINT_SEL(m, "dot118021XPrivacy=0x%x\n", psta->dot118021XPrivacy);
+
+ sta_rx_reorder_ctl_dump(m, psta);
+
+#ifdef CONFIG_TDLS
+ RTW_PRINT_SEL(m, "tdls_sta_state=0x%08x\n", psta->tdls_sta_state);
+ RTW_PRINT_SEL(m, "PeerKey_Lifetime=%d\n", psta->TDLS_PeerKey_Lifetime);
+ RTW_PRINT_SEL(m, "rx_data_pkts=%llu\n", psta->sta_stats.rx_data_pkts);
+ RTW_PRINT_SEL(m, "rx_bytes=%llu\n", psta->sta_stats.rx_bytes);
+ RTW_PRINT_SEL(m, "tx_data_pkts=%llu\n", psta->sta_stats.tx_pkts);
+ RTW_PRINT_SEL(m, "tx_bytes=%llu\n", psta->sta_stats.tx_bytes);
+#endif /* CONFIG_TDLS */
+
+ dump_st_ctl(m, &psta->st_ctl);
+
+ if (STA_OP_WFD_MODE(psta))
+ RTW_PRINT_SEL(m, "op_wfd_mode:0x%02x\n", STA_OP_WFD_MODE(psta));
+
+ RTW_PRINT_SEL(m, "==============================\n");
+ }
+
+ }
+
+ }
+
+ _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
+
+ return 0;
+}
+
+#endif
+
+#ifdef CONFIG_PREALLOC_RX_SKB_BUFFER
+int proc_get_rtkm_info(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct recv_priv *precvpriv = &padapter->recvpriv;
+ struct recv_buf *precvbuf;
+
+ precvbuf = (struct recv_buf *)precvpriv->precv_buf;
+
+ RTW_PRINT_SEL(m, "============[RTKM Info]============\n");
+ RTW_PRINT_SEL(m, "MAX_RTKM_NR_PREALLOC_RECV_SKB: %d\n", rtw_rtkm_get_nr_recv_skb());
+ RTW_PRINT_SEL(m, "MAX_RTKM_RECVBUF_SZ: %d\n", rtw_rtkm_get_buff_size());
+
+ RTW_PRINT_SEL(m, "============[Driver Info]============\n");
+ RTW_PRINT_SEL(m, "NR_PREALLOC_RECV_SKB: %d\n", NR_PREALLOC_RECV_SKB);
+ RTW_PRINT_SEL(m, "MAX_RECVBUF_SZ: %d\n", precvbuf->alloc_sz);
+
+ return 0;
+}
+#endif /* CONFIG_PREALLOC_RX_SKB_BUFFER */
+
+#ifdef CONFIG_FIND_BEST_CHANNEL
+int proc_get_best_channel(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ u32 i, best_channel_24G = 1, best_channel_5G = 36, index_24G = 0, index_5G = 0;
+
+ for (i = 0; pmlmeext->channel_set[i].ChannelNum != 0; i++) {
+ if (pmlmeext->channel_set[i].ChannelNum == 1)
+ index_24G = i;
+ if (pmlmeext->channel_set[i].ChannelNum == 36)
+ index_5G = i;
+ }
+
+ for (i = 0; (i < MAX_CHANNEL_NUM) && (pmlmeext->channel_set[i].ChannelNum != 0) ; i++) {
+ /* 2.4G */
+ if (pmlmeext->channel_set[i].ChannelNum == 6) {
+ if (pmlmeext->channel_set[i].rx_count < pmlmeext->channel_set[index_24G].rx_count) {
+ index_24G = i;
+ best_channel_24G = pmlmeext->channel_set[i].ChannelNum;
+ }
+ }
+
+ /* 5G */
+ if (pmlmeext->channel_set[i].ChannelNum >= 36
+ && pmlmeext->channel_set[i].ChannelNum < 140) {
+ /* Find primary channel */
+ if (((pmlmeext->channel_set[i].ChannelNum - 36) % 8 == 0)
+ && (pmlmeext->channel_set[i].rx_count < pmlmeext->channel_set[index_5G].rx_count)) {
+ index_5G = i;
+ best_channel_5G = pmlmeext->channel_set[i].ChannelNum;
+ }
+ }
+
+ if (pmlmeext->channel_set[i].ChannelNum >= 149
+ && pmlmeext->channel_set[i].ChannelNum < 165) {
+ /* find primary channel */
+ if (((pmlmeext->channel_set[i].ChannelNum - 149) % 8 == 0)
+ && (pmlmeext->channel_set[i].rx_count < pmlmeext->channel_set[index_5G].rx_count)) {
+ index_5G = i;
+ best_channel_5G = pmlmeext->channel_set[i].ChannelNum;
+ }
+ }
+ RTW_PRINT_SEL(m, "The rx cnt of channel %3d = %d\n",
+ pmlmeext->channel_set[i].ChannelNum, pmlmeext->channel_set[i].rx_count);
+ }
+
+ RTW_PRINT_SEL(m, "best_channel_5G = %d\n", best_channel_5G);
+ RTW_PRINT_SEL(m, "best_channel_24G = %d\n", best_channel_24G);
+
+ return 0;
+}
+
+ssize_t proc_set_best_channel(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ char tmp[32];
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+ int i;
+ for (i = 0; pmlmeext->channel_set[i].ChannelNum != 0; i++)
+ pmlmeext->channel_set[i].rx_count = 0;
+
+ RTW_INFO("set %s\n", "Clean Best Channel Count");
+ }
+
+ return count;
+}
+#endif /* CONFIG_FIND_BEST_CHANNEL */
+
+#ifdef CONFIG_BT_COEXIST
+int proc_get_btcoex_dbg(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ PADAPTER padapter;
+ char buf[512] = {0};
+ padapter = (PADAPTER)rtw_netdev_priv(dev);
+
+ rtw_btcoex_GetDBG(padapter, buf, 512);
+
+ _RTW_PRINT_SEL(m, "%s", buf);
+
+ return 0;
+}
+
+ssize_t proc_set_btcoex_dbg(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ PADAPTER padapter;
+ u8 tmp[80] = {0};
+ u32 module[2] = {0};
+ u32 num;
+
+ padapter = (PADAPTER)rtw_netdev_priv(dev);
+
+ /* RTW_INFO("+" FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(padapter)); */
+
+ if (NULL == buffer) {
+ RTW_INFO(FUNC_ADPT_FMT ": input buffer is NULL!\n",
+ FUNC_ADPT_ARG(padapter));
+
+ return -EFAULT;
+ }
+
+ if (count < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is 0!\n",
+ FUNC_ADPT_ARG(padapter));
+
+ return -EFAULT;
+ }
+
+ num = count;
+ if (num > (sizeof(tmp) - 1))
+ num = (sizeof(tmp) - 1);
+
+ if (copy_from_user(tmp, buffer, num)) {
+ RTW_INFO(FUNC_ADPT_FMT ": copy buffer from user space FAIL!\n",
+ FUNC_ADPT_ARG(padapter));
+
+ return -EFAULT;
+ }
+
+ num = sscanf(tmp, "%x %x", module, module + 1);
+ if (1 == num) {
+ if (0 == module[0])
+ memset(module, 0, sizeof(module));
+ else
+ memset(module, 0xFF, sizeof(module));
+ } else if (2 != num) {
+ RTW_INFO(FUNC_ADPT_FMT ": input(\"%s\") format incorrect!\n",
+ FUNC_ADPT_ARG(padapter), tmp);
+
+ if (0 == num)
+ return -EFAULT;
+ }
+
+ RTW_INFO(FUNC_ADPT_FMT ": input 0x%08X 0x%08X\n",
+ FUNC_ADPT_ARG(padapter), module[0], module[1]);
+ rtw_btcoex_SetDBG(padapter, module);
+
+ return count;
+}
+
+int proc_get_btcoex_info(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ PADAPTER padapter;
+ const u32 bufsize = 30 * 100;
+ u8 *pbuf = NULL;
+
+ padapter = (PADAPTER)rtw_netdev_priv(dev);
+
+ pbuf = rtw_zmalloc(bufsize);
+ if (NULL == pbuf)
+ return -ENOMEM;
+
+ rtw_btcoex_DisplayBtCoexInfo(padapter, pbuf, bufsize);
+
+ _RTW_PRINT_SEL(m, "%s\n", pbuf);
+
+ rtw_mfree(pbuf, bufsize);
+
+ return 0;
+}
+#endif /* CONFIG_BT_COEXIST */
+
+#if defined(DBG_CONFIG_ERROR_DETECT)
+int proc_get_sreset(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+
+ return 0;
+}
+
+ssize_t proc_set_sreset(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[32];
+ s32 trigger_point;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ int num = sscanf(tmp, "%d", &trigger_point);
+
+ if (trigger_point == SRESET_TGP_NULL)
+ rtw_hal_sreset_reset(padapter);
+ else
+ sreset_set_trigger_point(padapter, trigger_point);
+ }
+
+ return count;
+
+}
+#endif /* DBG_CONFIG_ERROR_DETECT */
+
+#ifdef CONFIG_WOWLAN
+int proc_get_pattern_info(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
+ struct registry_priv *pregistrypriv = &padapter->registrypriv;
+ u8 pattern_num = 0, val8;
+ char str_1[128];
+ char *p_str;
+ int i = 0 , j = 0, k = 0;
+ int len = 0, max_len = 0, total = 0;
+
+ p_str = str_1;
+ max_len = sizeof(str_1);
+
+ total = pwrpriv->wowlan_pattern_idx;
+
+ rtw_set_default_pattern(padapter);
+
+ /*show pattern*/
+ RTW_PRINT_SEL(m, "\n======[Pattern Info.]======\n");
+ RTW_PRINT_SEL(m, "pattern number: %d\n", total);
+ RTW_PRINT_SEL(m, "support default patterns: %c\n",
+ (pregistrypriv->default_patterns_en) ? 'Y' : 'N');
+
+ for (k = 0; k < total ; k++) {
+ RTW_PRINT_SEL(m, "\npattern idx: %d\n", k);
+ RTW_PRINT_SEL(m, "pattern content:\n");
+
+ p_str = str_1;
+ max_len = sizeof(str_1);
+ for (i = 0 ; i < MAX_WKFM_PATTERN_SIZE / 8 ; i++) {
+ memset(p_str, 0, max_len);
+ len = 0;
+ for (j = 0 ; j < 8 ; j++) {
+ val8 = pwrpriv->patterns[k].content[i * 8 + j];
+ len += snprintf(p_str + len, max_len - len,
+ "%02x ", val8);
+ }
+ RTW_PRINT_SEL(m, "%s\n", p_str);
+ }
+ RTW_PRINT_SEL(m, "\npattern mask:\n");
+ for (i = 0 ; i < MAX_WKFM_SIZE / 8 ; i++) {
+ memset(p_str, 0, max_len);
+ len = 0;
+ for (j = 0 ; j < 8 ; j++) {
+ val8 = pwrpriv->patterns[k].mask[i * 8 + j];
+ len += snprintf(p_str + len, max_len - len,
+ "%02x ", val8);
+ }
+ RTW_PRINT_SEL(m, "%s\n", p_str);
+ }
+
+ RTW_PRINT_SEL(m, "\npriv_pattern_len:\n");
+ RTW_PRINT_SEL(m, "pattern_len: %d\n", pwrpriv->patterns[k].len);
+ RTW_PRINT_SEL(m, "*****************\n");
+ }
+
+ return 0;
+}
+ssize_t proc_set_pattern_info(struct file *file, const char __user *buffer,
+ size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
+ struct wowlan_ioctl_param poidparam;
+ u8 tmp[MAX_WKFM_PATTERN_SIZE] = {0};
+ int ret = 0, num = 0;
+ u8 index = 0;
+
+ poidparam.subcode = 0;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (pwrpriv->wowlan_pattern_idx >= MAX_WKFM_CAM_NUM) {
+ RTW_INFO("WARNING: priv-pattern is full(idx: %d)\n",
+ pwrpriv->wowlan_pattern_idx);
+ RTW_INFO("WARNING: please clean priv-pattern first\n");
+ return -ENOMEM;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+ if (strncmp(tmp, "clean", 5) == 0) {
+ poidparam.subcode = WOWLAN_PATTERN_CLEAN;
+ rtw_hal_set_hwreg(padapter,
+ HW_VAR_WOWLAN, (u8 *)&poidparam);
+ } else {
+ index = pwrpriv->wowlan_pattern_idx;
+ ret = rtw_wowlan_parser_pattern_cmd(tmp,
+ pwrpriv->patterns[index].content,
+ &pwrpriv->patterns[index].len,
+ pwrpriv->patterns[index].mask);
+ if (ret == true)
+ pwrpriv->wowlan_pattern_idx++;
+ }
+ }
+
+ return count;
+}
+
+int proc_get_wakeup_reason(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
+ u8 val = pwrpriv->wowlan_last_wake_reason;
+
+ RTW_PRINT_SEL(m, "last wake reason: %#02x\n", val);
+ return 0;
+}
+#endif /*CONFIG_WOWLAN*/
+
+#ifdef CONFIG_GPIO_WAKEUP
+int proc_get_wowlan_gpio_info(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
+ u8 val = pwrpriv->is_high_active;
+
+ RTW_PRINT_SEL(m, "wakeup_gpio_idx: %d\n", WAKEUP_GPIO_IDX);
+ RTW_PRINT_SEL(m, "high_active: %d\n", val);
+
+ return 0;
+}
+
+ssize_t proc_set_wowlan_gpio_info(struct file *file, const char __user *buffer,
+ size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
+ char tmp[32] = {0};
+ int num = 0;
+ u32 is_high_active = 0;
+ u8 val8 = 0;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+
+ num = sscanf(tmp, "%u", &is_high_active);
+
+ is_high_active = is_high_active == 0 ? 0 : 1;
+
+ pwrpriv->is_high_active = is_high_active;
+
+ rtw_ps_deny(padapter, PS_DENY_IOCTL);
+ LeaveAllPowerSaveModeDirect(padapter);
+ val8 = (pwrpriv->is_high_active == 0) ? 1 : 0;
+ rtw_hal_set_output_gpio(padapter, WAKEUP_GPIO_IDX, val8);
+ rtw_ps_deny_cancel(padapter, PS_DENY_IOCTL);
+
+ RTW_INFO("set %s %d\n", "gpio_high_active",
+ pwrpriv->is_high_active);
+ RTW_INFO("%s: set GPIO_%d %d as default.\n",
+ __func__, WAKEUP_GPIO_IDX, val8);
+ }
+
+ return count;
+}
+#endif /* CONFIG_GPIO_WAKEUP */
+
+#ifdef CONFIG_P2P_WOWLAN
+int proc_get_p2p_wowlan_info(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
+ struct p2p_wowlan_info peerinfo = pwdinfo->p2p_wow_info;
+ if (peerinfo.is_trigger) {
+ RTW_PRINT_SEL(m, "is_trigger: true\n");
+ switch (peerinfo.wowlan_recv_frame_type) {
+ case P2P_WOWLAN_RECV_NEGO_REQ:
+ RTW_PRINT_SEL(m, "Frame Type: Nego Request\n");
+ break;
+ case P2P_WOWLAN_RECV_INVITE_REQ:
+ RTW_PRINT_SEL(m, "Frame Type: Invitation Request\n");
+ break;
+ case P2P_WOWLAN_RECV_PROVISION_REQ:
+ RTW_PRINT_SEL(m, "Frame Type: Provision Request\n");
+ break;
+ default:
+ break;
+ }
+ RTW_PRINT_SEL(m, "Peer Addr: "MAC_FMT"\n", MAC_ARG(peerinfo.wowlan_peer_addr));
+ RTW_PRINT_SEL(m, "Peer WPS Config: %x\n", peerinfo.wowlan_peer_wpsconfig);
+ RTW_PRINT_SEL(m, "Persistent Group: %d\n", peerinfo.wowlan_peer_is_persistent);
+ RTW_PRINT_SEL(m, "Intivation Type: %d\n", peerinfo.wowlan_peer_invitation_type);
+ } else
+ RTW_PRINT_SEL(m, "is_trigger: False\n");
+ return 0;
+}
+#endif /* CONFIG_P2P_WOWLAN */
+
+int proc_get_new_bcn_max(struct seq_file *m, void *v)
+{
+ extern int new_bcn_max;
+
+ RTW_PRINT_SEL(m, "%d", new_bcn_max);
+ return 0;
+}
+
+ssize_t proc_set_new_bcn_max(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ char tmp[32];
+ extern int new_bcn_max;
+
+ if (count < 1)
+ return -EFAULT;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count))
+ sscanf(tmp, "%d ", &new_bcn_max);
+
+ return count;
+}
+
+#ifdef CONFIG_POWER_SAVING
+int proc_get_ps_info(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
+ u8 ips_mode = pwrpriv->ips_mode;
+ u8 lps_mode = pwrpriv->power_mgnt;
+ char *str = "";
+
+ RTW_PRINT_SEL(m, "======Power Saving Info:======\n");
+ RTW_PRINT_SEL(m, "*IPS:\n");
+
+ if (ips_mode == IPS_NORMAL) {
+#ifdef CONFIG_FWLPS_IN_IPS
+ str = "FW_LPS_IN_IPS";
+#else
+ str = "Card Disable";
+#endif
+ } else if (ips_mode == IPS_NONE)
+ str = "NO IPS";
+ else if (ips_mode == IPS_LEVEL_2)
+ str = "IPS_LEVEL_2";
+ else
+ str = "invalid ips_mode";
+
+ RTW_PRINT_SEL(m, " IPS mode: %s\n", str);
+ RTW_PRINT_SEL(m, " IPS enter count:%d, IPS leave count:%d\n",
+ pwrpriv->ips_enter_cnts, pwrpriv->ips_leave_cnts);
+ RTW_PRINT_SEL(m, "------------------------------\n");
+ RTW_PRINT_SEL(m, "*LPS:\n");
+
+ if (lps_mode == PS_MODE_ACTIVE)
+ str = "NO LPS";
+ else if (lps_mode == PS_MODE_MIN)
+ str = "MIN";
+ else if (lps_mode == PS_MODE_MAX)
+ str = "MAX";
+ else if (lps_mode == PS_MODE_DTIM)
+ str = "DTIM";
+ else
+ sprintf(str, "%d", lps_mode);
+
+ RTW_PRINT_SEL(m, " LPS mode: %s\n", str);
+
+ if (pwrpriv->dtim != 0)
+ RTW_PRINT_SEL(m, " DTIM: %d\n", pwrpriv->dtim);
+ RTW_PRINT_SEL(m, " LPS enter count:%d, LPS leave count:%d\n",
+ pwrpriv->lps_enter_cnts, pwrpriv->lps_leave_cnts);
+ RTW_PRINT_SEL(m, "=============================\n");
+ return 0;
+}
+#endif /* CONFIG_POWER_SAVING */
+
+#ifdef CONFIG_TDLS
+static int proc_tdls_display_tdls_function_info(struct seq_file *m)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
+ u8 SpaceBtwnItemAndValue = TDLS_DBG_INFO_SPACE_BTWN_ITEM_AND_VALUE;
+ u8 SpaceBtwnItemAndValueTmp = 0;
+ bool FirstMatchFound = false;
+ int j = 0;
+
+ RTW_PRINT_SEL(m, "============[TDLS Function Info]============\n");
+ RTW_PRINT_SEL(m, "%-*s = %s\n", SpaceBtwnItemAndValue, "TDLS Prohibited", (ptdlsinfo->ap_prohibited == true) ? "true" : "false");
+ RTW_PRINT_SEL(m, "%-*s = %s\n", SpaceBtwnItemAndValue, "TDLS Channel Switch Prohibited", (ptdlsinfo->ch_switch_prohibited == true) ? "true" : "false");
+ RTW_PRINT_SEL(m, "%-*s = %s\n", SpaceBtwnItemAndValue, "TDLS Link Established", (ptdlsinfo->link_established == true) ? "true" : "false");
+ RTW_PRINT_SEL(m, "%-*s = %d/%d\n", SpaceBtwnItemAndValue, "TDLS STA Num (Linked/Allowed)", ptdlsinfo->sta_cnt, MAX_ALLOWED_TDLS_STA_NUM);
+ RTW_PRINT_SEL(m, "%-*s = %s\n", SpaceBtwnItemAndValue, "TDLS Allowed STA Num Reached", (ptdlsinfo->sta_maximum == true) ? "true" : "false");
+
+#ifdef CONFIG_TDLS_CH_SW
+ RTW_PRINT_SEL(m, "%-*s =", SpaceBtwnItemAndValue, "TDLS CH SW State");
+ if (ptdlsinfo->chsw_info.ch_sw_state == TDLS_STATE_NONE)
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_STATE_NONE");
+ else {
+ for (j = 0; j < 32; j++) {
+ if (ptdlsinfo->chsw_info.ch_sw_state & BIT(j)) {
+ if (FirstMatchFound == false) {
+ SpaceBtwnItemAndValueTmp = 1;
+ FirstMatchFound = true;
+ } else
+ SpaceBtwnItemAndValueTmp = SpaceBtwnItemAndValue + 3;
+ switch (BIT(j)) {
+ case TDLS_INITIATOR_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_INITIATOR_STATE");
+ break;
+ case TDLS_RESPONDER_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_RESPONDER_STATE");
+ break;
+ case TDLS_LINKED_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_LINKED_STATE");
+ break;
+ case TDLS_WAIT_PTR_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_WAIT_PTR_STATE");
+ break;
+ case TDLS_ALIVE_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_ALIVE_STATE");
+ break;
+ case TDLS_CH_SWITCH_ON_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_CH_SWITCH_ON_STATE");
+ break;
+ case TDLS_PEER_AT_OFF_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_PEER_AT_OFF_STATE");
+ break;
+ case TDLS_CH_SW_INITIATOR_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_CH_SW_INITIATOR_STATE");
+ break;
+ case TDLS_WAIT_CH_RSP_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValue, " ", "TDLS_WAIT_CH_RSP_STATE");
+ break;
+ default:
+ RTW_PRINT_SEL(m, "%-*sBIT(%d)\n", SpaceBtwnItemAndValueTmp, " ", j);
+ break;
+ }
+ }
+ }
+ }
+
+ RTW_PRINT_SEL(m, "%-*s = %s\n", SpaceBtwnItemAndValue, "TDLS CH SW On", (ATOMIC_READ(&ptdlsinfo->chsw_info.chsw_on) == true) ? "true" : "false");
+ RTW_PRINT_SEL(m, "%-*s = %d\n", SpaceBtwnItemAndValue, "TDLS CH SW Off-Channel Num", ptdlsinfo->chsw_info.off_ch_num);
+ RTW_PRINT_SEL(m, "%-*s = %d\n", SpaceBtwnItemAndValue, "TDLS CH SW Channel Offset", ptdlsinfo->chsw_info.ch_offset);
+ RTW_PRINT_SEL(m, "%-*s = %d\n", SpaceBtwnItemAndValue, "TDLS CH SW Current Time", ptdlsinfo->chsw_info.cur_time);
+ RTW_PRINT_SEL(m, "%-*s = %s\n", SpaceBtwnItemAndValue, "TDLS CH SW Delay Switch Back", (ptdlsinfo->chsw_info.delay_switch_back == true) ? "true" : "false");
+ RTW_PRINT_SEL(m, "%-*s = %d\n", SpaceBtwnItemAndValue, "TDLS CH SW Dump Back", ptdlsinfo->chsw_info.dump_stack);
+#endif
+
+ RTW_PRINT_SEL(m, "%-*s = %s\n", SpaceBtwnItemAndValue, "TDLS Device Discovered", (ptdlsinfo->dev_discovered == true) ? "true" : "false");
+ RTW_PRINT_SEL(m, "%-*s = %s\n", SpaceBtwnItemAndValue, "TDLS Enable", (ptdlsinfo->tdls_enable == true) ? "true" : "false");
+ RTW_PRINT_SEL(m, "%-*s = %s\n", SpaceBtwnItemAndValue, "TDLS Driver Setup", (ptdlsinfo->driver_setup == true) ? "true" : "false");
+
+ return 0;
+}
+
+static int proc_tdls_display_network_info(struct seq_file *m)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct wlan_network *cur_network = &(pmlmepriv->cur_network);
+ int i = 0;
+ u8 SpaceBtwnItemAndValue = TDLS_DBG_INFO_SPACE_BTWN_ITEM_AND_VALUE;
+
+ /* Display the linked AP/GO info */
+ RTW_PRINT_SEL(m, "============[Associated AP/GO Info]============\n");
+
+ if ((pmlmepriv->fw_state & WIFI_STATION_STATE) && (pmlmepriv->fw_state & _FW_LINKED)) {
+ RTW_PRINT_SEL(m, "%-*s = %s\n", SpaceBtwnItemAndValue, "BSSID", cur_network->network.Ssid.Ssid);
+ RTW_PRINT_SEL(m, "%-*s = "MAC_FMT"\n", SpaceBtwnItemAndValue, "Mac Address", MAC_ARG(cur_network->network.MacAddress));
+
+ RTW_PRINT_SEL(m, "%-*s = ", SpaceBtwnItemAndValue, "Wireless Mode");
+ for (i = 0; i < 8; i++) {
+ if (pmlmeext->cur_wireless_mode & BIT(i)) {
+ switch (BIT(i)) {
+ case WIRELESS_11B:
+ RTW_PRINT_SEL(m, "%4s", "11B ");
+ break;
+ case WIRELESS_11G:
+ RTW_PRINT_SEL(m, "%4s", "11G ");
+ break;
+ case WIRELESS_11A:
+ RTW_PRINT_SEL(m, "%4s", "11A ");
+ break;
+ case WIRELESS_11_24N:
+ RTW_PRINT_SEL(m, "%7s", "11_24N ");
+ break;
+ case WIRELESS_11_5N:
+ RTW_PRINT_SEL(m, "%6s", "11_5N ");
+ break;
+ case WIRELESS_AUTO:
+ RTW_PRINT_SEL(m, "%5s", "AUTO ");
+ break;
+ case WIRELESS_11AC:
+ RTW_PRINT_SEL(m, "%5s", "11AC ");
+ break;
+ }
+ }
+ }
+ RTW_PRINT_SEL(m, "\n");
+
+ RTW_PRINT_SEL(m, "%-*s = ", SpaceBtwnItemAndValue, "Privacy");
+ switch (padapter->securitypriv.dot11PrivacyAlgrthm) {
+ case _NO_PRIVACY_:
+ RTW_PRINT_SEL(m, "%s\n", "NO PRIVACY");
+ break;
+ case _WEP40_:
+ RTW_PRINT_SEL(m, "%s\n", "WEP 40");
+ break;
+ case _TKIP_:
+ RTW_PRINT_SEL(m, "%s\n", "TKIP");
+ break;
+ case _TKIP_WTMIC_:
+ RTW_PRINT_SEL(m, "%s\n", "TKIP WTMIC");
+ break;
+ case _AES_:
+ RTW_PRINT_SEL(m, "%s\n", "AES");
+ break;
+ case _WEP104_:
+ RTW_PRINT_SEL(m, "%s\n", "WEP 104");
+ break;
+ case _WEP_WPA_MIXED_:
+ RTW_PRINT_SEL(m, "%s\n", "WEP/WPA Mixed");
+ break;
+ case _SMS4_:
+ RTW_PRINT_SEL(m, "%s\n", "SMS4");
+ break;
+#ifdef CONFIG_IEEE80211W
+ case _BIP_:
+ RTW_PRINT_SEL(m, "%s\n", "BIP");
+ break;
+#endif /* CONFIG_IEEE80211W */
+ }
+
+ RTW_PRINT_SEL(m, "%-*s = %d\n", SpaceBtwnItemAndValue, "Channel", pmlmeext->cur_channel);
+ RTW_PRINT_SEL(m, "%-*s = ", SpaceBtwnItemAndValue, "Channel Offset");
+ switch (pmlmeext->cur_ch_offset) {
+ case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
+ RTW_PRINT_SEL(m, "%s\n", "N/A");
+ break;
+ case HAL_PRIME_CHNL_OFFSET_LOWER:
+ RTW_PRINT_SEL(m, "%s\n", "Lower");
+ break;
+ case HAL_PRIME_CHNL_OFFSET_UPPER:
+ RTW_PRINT_SEL(m, "%s\n", "Upper");
+ break;
+ }
+
+ RTW_PRINT_SEL(m, "%-*s = ", SpaceBtwnItemAndValue, "Bandwidth Mode");
+ switch (pmlmeext->cur_bwmode) {
+ case CHANNEL_WIDTH_20:
+ RTW_PRINT_SEL(m, "%s\n", "20MHz");
+ break;
+ case CHANNEL_WIDTH_40:
+ RTW_PRINT_SEL(m, "%s\n", "40MHz");
+ break;
+ case CHANNEL_WIDTH_80:
+ RTW_PRINT_SEL(m, "%s\n", "80MHz");
+ break;
+ case CHANNEL_WIDTH_160:
+ RTW_PRINT_SEL(m, "%s\n", "160MHz");
+ break;
+ case CHANNEL_WIDTH_80_80:
+ RTW_PRINT_SEL(m, "%s\n", "80MHz + 80MHz");
+ break;
+ }
+ } else
+ RTW_PRINT_SEL(m, "No association with AP/GO exists!\n");
+
+ return 0;
+}
+
+static int proc_tdls_display_tdls_sta_info(struct seq_file *m)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
+ struct sta_info *psta;
+ int i = 0, j = 0;
+ unsigned long irqL;
+ _list *plist, *phead;
+ u8 SpaceBtwnItemAndValue = TDLS_DBG_INFO_SPACE_BTWN_ITEM_AND_VALUE;
+ u8 SpaceBtwnItemAndValueTmp = 0;
+ u8 NumOfTdlsStaToShow = 0;
+ bool FirstMatchFound = false;
+
+ /* Search for TDLS sta info to display */
+ _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
+ for (i = 0; i < NUM_STA; i++) {
+ phead = &(pstapriv->sta_hash[i]);
+ plist = get_next(phead);
+ while ((rtw_end_of_queue_search(phead, plist)) == false) {
+ psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
+ plist = get_next(plist);
+ if (psta->tdls_sta_state != TDLS_STATE_NONE) {
+ /* We got one TDLS sta info to show */
+ RTW_PRINT_SEL(m, "============[TDLS Peer STA Info: STA %d]============\n", ++NumOfTdlsStaToShow);
+ RTW_PRINT_SEL(m, "%-*s = "MAC_FMT"\n", SpaceBtwnItemAndValue, "Mac Address", MAC_ARG(psta->hwaddr));
+ RTW_PRINT_SEL(m, "%-*s =", SpaceBtwnItemAndValue, "TDLS STA State");
+ SpaceBtwnItemAndValueTmp = 0;
+ FirstMatchFound = false;
+ for (j = 0; j < 32; j++) {
+ if (psta->tdls_sta_state & BIT(j)) {
+ if (FirstMatchFound == false) {
+ SpaceBtwnItemAndValueTmp = 1;
+ FirstMatchFound = true;
+ } else
+ SpaceBtwnItemAndValueTmp = SpaceBtwnItemAndValue + 3;
+ switch (BIT(j)) {
+ case TDLS_INITIATOR_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_INITIATOR_STATE");
+ break;
+ case TDLS_RESPONDER_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_RESPONDER_STATE");
+ break;
+ case TDLS_LINKED_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_LINKED_STATE");
+ break;
+ case TDLS_WAIT_PTR_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_WAIT_PTR_STATE");
+ break;
+ case TDLS_ALIVE_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_ALIVE_STATE");
+ break;
+ case TDLS_CH_SWITCH_ON_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_CH_SWITCH_ON_STATE");
+ break;
+ case TDLS_PEER_AT_OFF_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_PEER_AT_OFF_STATE");
+ break;
+ case TDLS_CH_SW_INITIATOR_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValueTmp, " ", "TDLS_CH_SW_INITIATOR_STATE");
+ break;
+ case TDLS_WAIT_CH_RSP_STATE:
+ RTW_PRINT_SEL(m, "%-*s%s\n", SpaceBtwnItemAndValue, " ", "TDLS_WAIT_CH_RSP_STATE");
+ break;
+ default:
+ RTW_PRINT_SEL(m, "%-*sBIT(%d)\n", SpaceBtwnItemAndValueTmp, " ", j);
+ break;
+ }
+ }
+ }
+
+ RTW_PRINT_SEL(m, "%-*s = ", SpaceBtwnItemAndValue, "Wireless Mode");
+ for (j = 0; j < 8; j++) {
+ if (psta->wireless_mode & BIT(j)) {
+ switch (BIT(j)) {
+ case WIRELESS_11B:
+ RTW_PRINT_SEL(m, "%4s", "11B ");
+ break;
+ case WIRELESS_11G:
+ RTW_PRINT_SEL(m, "%4s", "11G ");
+ break;
+ case WIRELESS_11A:
+ RTW_PRINT_SEL(m, "%4s", "11A ");
+ break;
+ case WIRELESS_11_24N:
+ RTW_PRINT_SEL(m, "%7s", "11_24N ");
+ break;
+ case WIRELESS_11_5N:
+ RTW_PRINT_SEL(m, "%6s", "11_5N ");
+ break;
+ case WIRELESS_AUTO:
+ RTW_PRINT_SEL(m, "%5s", "AUTO ");
+ break;
+ case WIRELESS_11AC:
+ RTW_PRINT_SEL(m, "%5s", "11AC ");
+ break;
+ }
+ }
+ }
+ RTW_PRINT_SEL(m, "\n");
+
+ RTW_PRINT_SEL(m, "%-*s = ", SpaceBtwnItemAndValue, "Bandwidth Mode");
+ switch (psta->bw_mode) {
+ case CHANNEL_WIDTH_20:
+ RTW_PRINT_SEL(m, "%s\n", "20MHz");
+ break;
+ case CHANNEL_WIDTH_40:
+ RTW_PRINT_SEL(m, "%s\n", "40MHz");
+ break;
+ case CHANNEL_WIDTH_80:
+ RTW_PRINT_SEL(m, "%s\n", "80MHz");
+ break;
+ case CHANNEL_WIDTH_160:
+ RTW_PRINT_SEL(m, "%s\n", "160MHz");
+ break;
+ case CHANNEL_WIDTH_80_80:
+ RTW_PRINT_SEL(m, "%s\n", "80MHz + 80MHz");
+ break;
+ }
+
+ RTW_PRINT_SEL(m, "%-*s = ", SpaceBtwnItemAndValue, "Privacy");
+ switch (psta->dot118021XPrivacy) {
+ case _NO_PRIVACY_:
+ RTW_PRINT_SEL(m, "%s\n", "NO PRIVACY");
+ break;
+ case _WEP40_:
+ RTW_PRINT_SEL(m, "%s\n", "WEP 40");
+ break;
+ case _TKIP_:
+ RTW_PRINT_SEL(m, "%s\n", "TKIP");
+ break;
+ case _TKIP_WTMIC_:
+ RTW_PRINT_SEL(m, "%s\n", "TKIP WTMIC");
+ break;
+ case _AES_:
+ RTW_PRINT_SEL(m, "%s\n", "AES");
+ break;
+ case _WEP104_:
+ RTW_PRINT_SEL(m, "%s\n", "WEP 104");
+ break;
+ case _WEP_WPA_MIXED_:
+ RTW_PRINT_SEL(m, "%s\n", "WEP/WPA Mixed");
+ break;
+ case _SMS4_:
+ RTW_PRINT_SEL(m, "%s\n", "SMS4");
+ break;
+#ifdef CONFIG_IEEE80211W
+ case _BIP_:
+ RTW_PRINT_SEL(m, "%s\n", "BIP");
+ break;
+#endif /* CONFIG_IEEE80211W */
+ }
+
+ RTW_PRINT_SEL(m, "%-*s = %d sec/%d sec\n", SpaceBtwnItemAndValue, "TPK Lifetime (Current/Expire)", psta->TPK_count, psta->TDLS_PeerKey_Lifetime);
+ RTW_PRINT_SEL(m, "%-*s = %llu\n", SpaceBtwnItemAndValue, "Tx Packets Over Direct Link", psta->sta_stats.tx_pkts);
+ RTW_PRINT_SEL(m, "%-*s = %llu\n", SpaceBtwnItemAndValue, "Rx Packets Over Direct Link", psta->sta_stats.rx_data_pkts);
+ }
+ }
+ }
+ _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
+ if (NumOfTdlsStaToShow == 0) {
+ RTW_PRINT_SEL(m, "============[TDLS Peer STA Info]============\n");
+ RTW_PRINT_SEL(m, "No TDLS direct link exists!\n");
+ }
+
+ return 0;
+}
+
+int proc_get_tdls_info(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct wlan_network *cur_network = &(pmlmepriv->cur_network);
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
+ struct sta_info *psta;
+ int i = 0, j = 0;
+ unsigned long irqL;
+ _list *plist, *phead;
+ u8 SpaceBtwnItemAndValue = 41;
+ u8 SpaceBtwnItemAndValueTmp = 0;
+ u8 NumOfTdlsStaToShow = 0;
+ bool FirstMatchFound = false;
+
+ if (hal_chk_wl_func(padapter, WL_FUNC_TDLS) == false) {
+ RTW_PRINT_SEL(m, "No tdls info can be shown since hal doesn't support tdls\n");
+ return 0;
+ }
+
+ proc_tdls_display_tdls_function_info(m);
+ proc_tdls_display_network_info(m);
+ proc_tdls_display_tdls_sta_info(m);
+
+ return 0;
+}
+#endif
+
+int proc_get_monitor(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+
+ if (WIFI_MONITOR_STATE == get_fwstate(pmlmepriv)) {
+ RTW_PRINT_SEL(m, "Monitor mode : Enable\n");
+
+ RTW_PRINT_SEL(m, "ch=%d, ch_offset=%d, bw=%d\n",
+ rtw_get_oper_ch(padapter), rtw_get_oper_choffset(padapter), rtw_get_oper_bw(padapter));
+ } else
+ RTW_PRINT_SEL(m, "Monitor mode : Disable\n");
+
+ return 0;
+}
+
+ssize_t proc_set_monitor(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ char tmp[32];
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ u8 target_chan, target_offset, target_bw;
+
+ if (count < 3) {
+ RTW_INFO("argument size is less than 3\n");
+ return -EFAULT;
+ }
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+ int num = sscanf(tmp, "%hhu %hhu %hhu", &target_chan, &target_offset, &target_bw);
+
+ if (num != 3) {
+ RTW_INFO("invalid write_reg parameter!\n");
+ return count;
+ }
+
+ padapter->mlmeextpriv.cur_channel = target_chan;
+ set_channel_bwmode(padapter, target_chan, target_offset, target_bw);
+ }
+
+ return count;
+}
+
+#include <hal_data.h>
+int proc_get_efuse_map(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
+ struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
+ PEFUSE_HAL pEfuseHal = &pHalData->EfuseHal;
+ int i, j;
+ u8 ips_mode = IPS_NUM;
+ u16 mapLen;
+
+ EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, false);
+ if (mapLen > EFUSE_MAX_MAP_LEN)
+ mapLen = EFUSE_MAX_MAP_LEN;
+
+ ips_mode = pwrctrlpriv->ips_mode;
+ rtw_pm_set_ips(padapter, IPS_NONE);
+
+ if (pHalData->efuse_file_status == EFUSE_FILE_LOADED) {
+ RTW_PRINT_SEL(m, "File eFuse Map loaded! file path:%s\nDriver eFuse Map From File\n", EFUSE_MAP_PATH);
+ if (pHalData->bautoload_fail_flag)
+ RTW_PRINT_SEL(m, "File Autoload fail!!!\n");
+ } else if (pHalData->efuse_file_status == EFUSE_FILE_FAILED) {
+ RTW_PRINT_SEL(m, "Open File eFuse Map Fail ! file path:%s\nDriver eFuse Map From Default\n", EFUSE_MAP_PATH);
+ if (pHalData->bautoload_fail_flag)
+ RTW_PRINT_SEL(m, "HW Autoload fail!!!\n");
+ } else {
+ RTW_PRINT_SEL(m, "Driver eFuse Map From HW\n");
+ if (pHalData->bautoload_fail_flag)
+ RTW_PRINT_SEL(m, "HW Autoload fail!!!\n");
+ }
+ for (i = 0; i < mapLen; i += 16) {
+ RTW_PRINT_SEL(m, "0x%02x\t", i);
+ for (j = 0; j < 8; j++)
+ RTW_PRINT_SEL(m, "%02X ", pHalData->efuse_eeprom_data[i + j]);
+ RTW_PRINT_SEL(m, "\t");
+ for (; j < 16; j++)
+ RTW_PRINT_SEL(m, "%02X ", pHalData->efuse_eeprom_data[i + j]);
+ RTW_PRINT_SEL(m, "\n");
+ }
+
+ if (rtw_efuse_map_read(padapter, 0, mapLen, pEfuseHal->fakeEfuseInitMap) == _FAIL) {
+ RTW_PRINT_SEL(m, "WARN - Read Realmap Failed\n");
+ return 0;
+ }
+
+ RTW_PRINT_SEL(m, "\n");
+ RTW_PRINT_SEL(m, "HW eFuse Map\n");
+ for (i = 0; i < mapLen; i += 16) {
+ RTW_PRINT_SEL(m, "0x%02x\t", i);
+ for (j = 0; j < 8; j++)
+ RTW_PRINT_SEL(m, "%02X ", pEfuseHal->fakeEfuseInitMap[i + j]);
+ RTW_PRINT_SEL(m, "\t");
+ for (; j < 16; j++)
+ RTW_PRINT_SEL(m, "%02X ", pEfuseHal->fakeEfuseInitMap[i + j]);
+ RTW_PRINT_SEL(m, "\n");
+ }
+
+ rtw_pm_set_ips(padapter, ips_mode);
+
+ return 0;
+}
+
+ssize_t proc_set_efuse_map(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ return count;
+}
+
+#ifdef CONFIG_IEEE80211W
+ssize_t proc_set_tx_sa_query(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
+ struct macid_ctl_t *macid_ctl = dvobj_to_macidctl(dvobj);
+ struct sta_info *psta;
+ _list *plist, *phead;
+ unsigned long irqL;
+ char tmp[16];
+ u8 mac_addr[NUM_STA][ETH_ALEN];
+ u32 key_type;
+ u8 index;
+
+ if (count > 2) {
+ RTW_INFO("argument size is more than 2\n");
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
+
+ int num = sscanf(tmp, "%x", &key_type);
+
+ if (num != 1) {
+ RTW_INFO("invalid read_reg parameter!\n");
+ return count;
+ }
+ RTW_INFO("0: set sa query request , key_type=%d\n", key_type);
+ }
+
+ if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true)
+ && (check_fwstate(pmlmepriv, _FW_LINKED) == true) && padapter->securitypriv.binstallBIPkey == true) {
+ RTW_INFO("STA:"MAC_FMT"\n", MAC_ARG(get_my_bssid(&(pmlmeinfo->network))));
+ /* TX unicast sa_query to AP */
+ issue_action_SA_Query(padapter, get_my_bssid(&(pmlmeinfo->network)), 0, 0, (u8)key_type);
+ } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true && padapter->securitypriv.binstallBIPkey == true) {
+ /* TX unicast sa_query to every client STA */
+ _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
+ for (index = 0; index < NUM_STA; index++) {
+ psta = NULL;
+
+ phead = &(pstapriv->sta_hash[index]);
+ plist = get_next(phead);
+
+ while ((rtw_end_of_queue_search(phead, plist)) == false) {
+ psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
+ plist = get_next(plist);
+ memcpy(&mac_addr[psta->mac_id][0], psta->hwaddr, ETH_ALEN);
+ }
+ }
+ _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
+
+ for (index = 0; index < macid_ctl->num && index < NUM_STA; index++) {
+ if (rtw_macid_is_used(macid_ctl, index) && !rtw_macid_is_bmc(macid_ctl, index)) {
+ if (memcmp(get_my_bssid(&(pmlmeinfo->network)), &mac_addr[index][0], ETH_ALEN)
+ && !IS_MCAST(&mac_addr[index][0])) {
+ issue_action_SA_Query(padapter, &mac_addr[index][0], 0, 0, (u8)key_type);
+ RTW_INFO("STA[%u]:"MAC_FMT"\n", index , MAC_ARG(&mac_addr[index][0]));
+ }
+ }
+ }
+ }
+
+ return count;
+}
+
+int proc_get_tx_sa_query(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+
+ RTW_PRINT_SEL(m, "%s\n", __func__);
+ return 0;
+}
+
+ssize_t proc_set_tx_deauth(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
+ struct macid_ctl_t *macid_ctl = dvobj_to_macidctl(dvobj);
+ struct sta_info *psta;
+ _list *plist, *phead;
+ unsigned long irqL;
+ char tmp[16];
+ u8 mac_addr[NUM_STA][ETH_ALEN];
+ u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+ u32 key_type;
+ u8 index;
+
+
+ if (count > 2) {
+ RTW_INFO("argument size is more than 2\n");
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
+
+ int num = sscanf(tmp, "%x", &key_type);
+
+ if (num != 1) {
+ RTW_INFO("invalid read_reg parameter!\n");
+ return count;
+ }
+ RTW_INFO("key_type=%d\n", key_type);
+ }
+ if (key_type < 0 || key_type > 4)
+ return count;
+
+ if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true)
+ && (check_fwstate(pmlmepriv, _FW_LINKED) == true)) {
+ if (key_type == 3) /* key_type 3 only for AP mode */
+ return count;
+ /* TX unicast deauth to AP */
+ issue_deauth_11w(padapter, get_my_bssid(&(pmlmeinfo->network)), 0, (u8)key_type);
+ } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
+
+ if (key_type == 3)
+ issue_deauth_11w(padapter, bc_addr, 0, IEEE80211W_RIGHT_KEY);
+
+ /* TX unicast deauth to every client STA */
+ _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
+ for (index = 0; index < NUM_STA; index++) {
+ psta = NULL;
+
+ phead = &(pstapriv->sta_hash[index]);
+ plist = get_next(phead);
+
+ while ((rtw_end_of_queue_search(phead, plist)) == false) {
+ psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
+ plist = get_next(plist);
+ memcpy(&mac_addr[psta->mac_id][0], psta->hwaddr, ETH_ALEN);
+ }
+ }
+ _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
+
+ for (index = 0; index < macid_ctl->num && index < NUM_STA; index++) {
+ if (rtw_macid_is_used(macid_ctl, index) && !rtw_macid_is_bmc(macid_ctl, index)) {
+ if (memcmp(get_my_bssid(&(pmlmeinfo->network)), &mac_addr[index][0], ETH_ALEN)) {
+ if (key_type != 3)
+ issue_deauth_11w(padapter, &mac_addr[index][0], 0, (u8)key_type);
+
+ psta = rtw_get_stainfo(pstapriv, &mac_addr[index][0]);
+ if (psta && key_type != IEEE80211W_WRONG_KEY && key_type != IEEE80211W_NO_KEY) {
+ u8 updated = false;
+
+ _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+ if (list_empty(&psta->asoc_list) == false) {
+ list_del_init(&psta->asoc_list);
+ pstapriv->asoc_list_cnt--;
+ updated = ap_free_sta(padapter, psta, false, WLAN_REASON_PREV_AUTH_NOT_VALID, true);
+
+ }
+ _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+
+ associated_clients_update(padapter, updated, STA_INFO_UPDATE_ALL);
+ }
+
+ RTW_INFO("STA[%u]:"MAC_FMT"\n", index , MAC_ARG(&mac_addr[index][0]));
+ }
+ }
+ }
+ }
+
+ return count;
+}
+
+int proc_get_tx_deauth(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+
+ RTW_PRINT_SEL(m, "%s\n", __func__);
+ return 0;
+}
+
+ssize_t proc_set_tx_auth(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+ struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ struct sta_priv *pstapriv = &padapter->stapriv;
+ struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
+ struct macid_ctl_t *macid_ctl = dvobj_to_macidctl(dvobj);
+ struct sta_info *psta;
+ _list *plist, *phead;
+ unsigned long irqL;
+ char tmp[16];
+ u8 mac_addr[NUM_STA][ETH_ALEN];
+ u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+ u32 tx_auth;
+ u8 index;
+
+
+ if (count > 2) {
+ RTW_INFO("argument size is more than 2\n");
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
+
+ int num = sscanf(tmp, "%x", &tx_auth);
+
+ if (num != 1) {
+ RTW_INFO("invalid read_reg parameter!\n");
+ return count;
+ }
+ RTW_INFO("1: setnd auth, 2: send assoc request. tx_auth=%d\n", tx_auth);
+ }
+
+ if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true)
+ && (check_fwstate(pmlmepriv, _FW_LINKED) == true)) {
+ if (tx_auth == 1) {
+ /* TX unicast auth to AP */
+ issue_auth(padapter, NULL, 0);
+ } else if (tx_auth == 2) {
+ /* TX unicast auth to AP */
+ issue_assocreq(padapter);
+ }
+ }
+
+ return count;
+}
+
+int proc_get_tx_auth(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+
+ RTW_PRINT_SEL(m, "%s\n", __func__);
+ return 0;
+}
+#endif /* CONFIG_IEEE80211W */
+
+#ifdef CONFIG_MCC_MODE
+int proc_get_mcc_info(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+
+ dump_adapters_status(m, adapter_to_dvobj(adapter));
+ rtw_hal_dump_mcc_info(m, adapter_to_dvobj(adapter));
+ return 0;
+}
+
+int proc_get_mcc_policy_table(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
+
+ rtw_hal_dump_mcc_policy_table(m);
+ return 0;
+}
+
+ssize_t proc_set_mcc_policy_table(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[255];
+ s32 mcc_policy_table_idx;
+ u32 mcc_duration;
+ u32 mcc_tsf_sync_offset;
+ u32 mcc_start_time_offset;
+ u32 mcc_interval;
+ s32 mcc_guard_offset0;
+ s32 mcc_guard_offset1;
+
+ if (NULL == buffer) {
+ RTW_INFO(FUNC_ADPT_FMT ": input buffer is NULL!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is 0!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count > sizeof(tmp)) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is too large\n", FUNC_ADPT_ARG(padapter));
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+ struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
+ _adapter *iface = NULL;
+ u8 i = 0;
+ int num = sscanf(tmp, "%d %u %u %u %u %d %d"
+ , &mcc_policy_table_idx, &mcc_duration, &mcc_tsf_sync_offset, &mcc_start_time_offset
+ , &mcc_interval, &mcc_guard_offset0, &mcc_guard_offset1);
+
+ if (num < 7) {
+ RTW_INFO(FUNC_ADPT_FMT ": input parameters < 7\n", FUNC_ADPT_ARG(padapter));
+ return -EINVAL;
+ }
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ iface = dvobj->padapters[i];
+ if (!iface)
+ continue;
+ iface->registrypriv.rtw_mcc_policy_table_idx = mcc_policy_table_idx;
+ iface->registrypriv.rtw_mcc_duration = mcc_duration;
+ iface->registrypriv.rtw_mcc_tsf_sync_offset = mcc_tsf_sync_offset;
+ iface->registrypriv.rtw_mcc_start_time_offset = mcc_start_time_offset;
+ iface->registrypriv.rtw_mcc_interval = mcc_interval;
+ iface->registrypriv.rtw_mcc_guard_offset0 = mcc_guard_offset0;
+ iface->registrypriv.rtw_mcc_guard_offset1 = mcc_guard_offset1;
+ }
+
+ rtw_hal_mcc_update_switch_channel_policy_table(padapter);
+ }
+
+ return count;
+}
+
+ssize_t proc_set_mcc_enable(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[255];
+ u32 en_mcc = 0;
+
+ if (NULL == buffer) {
+ RTW_INFO(FUNC_ADPT_FMT ": input buffer is NULL!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is 0!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count > sizeof(tmp)) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is too large\n", FUNC_ADPT_ARG(padapter));
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+ struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
+ _adapter *iface = NULL;
+ u8 i = 0;
+ int num = sscanf(tmp, "%u", &en_mcc);
+
+ if (num < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input parameters < 1\n", FUNC_ADPT_ARG(padapter));
+ return -EINVAL;
+ }
+
+ RTW_INFO("%s: en_mcc = %d\n", __func__, en_mcc);
+
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ iface = dvobj->padapters[i];
+ if (!iface)
+ continue;
+ iface->registrypriv.en_mcc = en_mcc;
+ }
+ }
+
+ return count;
+}
+
+ssize_t proc_set_mcc_single_tx_criteria(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[255];
+ u32 mcc_single_tx_criteria = 0;
+
+ if (NULL == buffer) {
+ RTW_INFO(FUNC_ADPT_FMT ": input buffer is NULL!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is 0!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count > sizeof(tmp)) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is too large\n", FUNC_ADPT_ARG(padapter));
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+ struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
+ _adapter *iface = NULL;
+ u8 i = 0;
+ int num = sscanf(tmp, "%u", &mcc_single_tx_criteria);
+
+ if (num < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input parameters < 1\n", FUNC_ADPT_ARG(padapter));
+ return -EINVAL;
+ }
+
+ RTW_INFO("%s: mcc_single_tx_criteria = %d\n", __func__, mcc_single_tx_criteria);
+
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ iface = dvobj->padapters[i];
+ if (!iface)
+ continue;
+ iface->registrypriv.rtw_mcc_single_tx_cri = mcc_single_tx_criteria;
+ }
+
+
+ }
+
+ return count;
+}
+
+
+ssize_t proc_set_mcc_ap_bw20_target_tp(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[255];
+ u32 mcc_ap_bw20_target_tp = 0;
+
+ if (NULL == buffer) {
+ RTW_INFO(FUNC_ADPT_FMT ": input buffer is NULL!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is 0!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count > sizeof(tmp)) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is too large\n", FUNC_ADPT_ARG(padapter));
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+ int num = sscanf(tmp, "%u", &mcc_ap_bw20_target_tp);
+
+ if (num < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input parameters < 1\n", FUNC_ADPT_ARG(padapter));
+ return -EINVAL;
+ }
+
+ RTW_INFO("%s: mcc_ap_bw20_target_tp = %d\n", __func__, mcc_ap_bw20_target_tp);
+
+ padapter->registrypriv.rtw_mcc_ap_bw20_target_tx_tp = mcc_ap_bw20_target_tp;
+
+
+ }
+
+ return count;
+}
+
+ssize_t proc_set_mcc_ap_bw40_target_tp(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[255];
+ u32 mcc_ap_bw40_target_tp = 0;
+
+ if (NULL == buffer) {
+ RTW_INFO(FUNC_ADPT_FMT ": input buffer is NULL!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is 0!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count > sizeof(tmp)) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is too large\n", FUNC_ADPT_ARG(padapter));
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+ int num = sscanf(tmp, "%u", &mcc_ap_bw40_target_tp);
+
+ if (num < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input parameters < 1\n", FUNC_ADPT_ARG(padapter));
+ return -EINVAL;
+ }
+
+ RTW_INFO("%s: mcc_ap_bw40_target_tp = %d\n", __func__, mcc_ap_bw40_target_tp);
+
+ padapter->registrypriv.rtw_mcc_ap_bw40_target_tx_tp = mcc_ap_bw40_target_tp;
+
+
+ }
+
+ return count;
+}
+
+ssize_t proc_set_mcc_ap_bw80_target_tp(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[255];
+ u32 mcc_ap_bw80_target_tp = 0;
+
+ if (NULL == buffer) {
+ RTW_INFO(FUNC_ADPT_FMT ": input buffer is NULL!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is 0!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count > sizeof(tmp)) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is too large\n", FUNC_ADPT_ARG(padapter));
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+ int num = sscanf(tmp, "%u", &mcc_ap_bw80_target_tp);
+
+ if (num < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input parameters < 1\n", FUNC_ADPT_ARG(padapter));
+ return -EINVAL;
+ }
+
+ RTW_INFO("%s: mcc_ap_bw80_target_tp = %d\n", __func__, mcc_ap_bw80_target_tp);
+
+ padapter->registrypriv.rtw_mcc_ap_bw80_target_tx_tp = mcc_ap_bw80_target_tp;
+
+
+ }
+
+ return count;
+}
+
+ssize_t proc_set_mcc_sta_bw20_target_tp(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[255];
+ u32 mcc_sta_bw20_target_tp = 0;
+
+ if (NULL == buffer) {
+ RTW_INFO(FUNC_ADPT_FMT ": input buffer is NULL!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is 0!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count > sizeof(tmp)) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is too large\n", FUNC_ADPT_ARG(padapter));
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+ int num = sscanf(tmp, "%u", &mcc_sta_bw20_target_tp);
+
+ if (num < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input parameters < 1\n", FUNC_ADPT_ARG(padapter));
+ return -EINVAL;
+ }
+
+ RTW_INFO("%s: mcc_sta_bw20_target_tp = %d\n", __func__, mcc_sta_bw20_target_tp);
+
+ padapter->registrypriv.rtw_mcc_sta_bw20_target_tx_tp = mcc_sta_bw20_target_tp;
+
+
+ }
+
+ return count;
+}
+
+ssize_t proc_set_mcc_sta_bw40_target_tp(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[255];
+ u32 mcc_sta_bw40_target_tp = 0;
+
+ if (NULL == buffer) {
+ RTW_INFO(FUNC_ADPT_FMT ": input buffer is NULL!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is 0!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count > sizeof(tmp)) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is too large\n", FUNC_ADPT_ARG(padapter));
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+ int num = sscanf(tmp, "%u", &mcc_sta_bw40_target_tp);
+
+ if (num < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input parameters < 1\n", FUNC_ADPT_ARG(padapter));
+ return -EINVAL;
+ }
+
+ RTW_INFO("%s: mcc_sta_bw40_target_tp = %d\n", __func__, mcc_sta_bw40_target_tp);
+
+ padapter->registrypriv.rtw_mcc_sta_bw40_target_tx_tp = mcc_sta_bw40_target_tp;
+
+
+ }
+
+ return count;
+}
+
+ssize_t proc_set_mcc_sta_bw80_target_tp(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[255];
+ u32 mcc_sta_bw80_target_tp = 0;
+
+ if (NULL == buffer) {
+ RTW_INFO(FUNC_ADPT_FMT ": input buffer is NULL!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is 0!\n", FUNC_ADPT_ARG(padapter));
+ return -EFAULT;
+ }
+
+ if (count > sizeof(tmp)) {
+ RTW_INFO(FUNC_ADPT_FMT ": input length is too large\n", FUNC_ADPT_ARG(padapter));
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+ int num = sscanf(tmp, "%u", &mcc_sta_bw80_target_tp);
+
+ if (num < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input parameters < 1\n", FUNC_ADPT_ARG(padapter));
+ return -EINVAL;
+ }
+
+ RTW_INFO("%s: mcc_sta_bw80_target_tp = %d\n", __func__, mcc_sta_bw80_target_tp);
+
+ padapter->registrypriv.rtw_mcc_sta_bw80_target_tx_tp = mcc_sta_bw80_target_tp;
+
+
+ }
+
+ return count;
+}
+#endif /* CONFIG_MCC_MODE */
+
+int proc_get_ack_timeout(struct seq_file *m, void *v)
+{
+ struct net_device *dev = m->private;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ u8 ack_timeout_val, ack_timeout_val_cck;
+
+ ack_timeout_val = rtw_read8(padapter, REG_ACKTO);
+
+ RTW_PRINT_SEL(m, "Current ACK Timeout = %d us (0x%x).\n", ack_timeout_val, ack_timeout_val);
+
+ return 0;
+}
+
+ssize_t proc_set_ack_timeout(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
+{
+ struct net_device *dev = data;
+ _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
+ char tmp[32];
+ u32 ack_timeout_ms, ack_timeout_ms_cck;
+
+ if (count > sizeof(tmp)) {
+ rtw_warn_on(1);
+ return -EFAULT;
+ }
+
+ if (buffer && !copy_from_user(tmp, buffer, count)) {
+ int num = sscanf(tmp, "%u %u", &ack_timeout_ms, &ack_timeout_ms_cck);
+
+ if (num < 1) {
+ RTW_INFO(FUNC_ADPT_FMT ": input parameters < 1\n", FUNC_ADPT_ARG(padapter));
+ return -EINVAL;
+ }
+ /* This register sets the Ack time out value after Tx unicast packet. It is in units of us. */
+ rtw_write8(padapter, REG_ACKTO, (u8)ack_timeout_ms);
+
+ RTW_INFO("Set ACK Timeout to %d us.\n", ack_timeout_ms);
+ }
+
+ return count;
+}
+
+#endif /* CONFIG_PROC_DEBUG */
diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c b/drivers/staging/rtl8188eu/core/rtw_efuse.c
new file mode 100644
index 000000000000..46ffa8d668e3
--- /dev/null
+++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
@@ -0,0 +1,1523 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved. */
+
+#define _RTW_EFUSE_C_
+
+#include <drv_types.h>
+#include <hal_data.h>
+
+#include "../hal/efuse_mask.h"
+
+/*------------------------Define local variable------------------------------*/
+u8 fakeEfuseBank = {0};
+u32 fakeEfuseUsedBytes = {0};
+u8 fakeEfuseContent[EFUSE_MAX_HW_SIZE] = {0};
+u8 fakeEfuseInitMap[EFUSE_MAX_MAP_LEN] = {0};
+u8 fakeEfuseModifiedMap[EFUSE_MAX_MAP_LEN] = {0};
+
+u32 BTEfuseUsedBytes = {0};
+u8 BTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE];
+u8 BTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN] = {0};
+u8 BTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN] = {0};
+
+u32 fakeBTEfuseUsedBytes = {0};
+u8 fakeBTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE];
+u8 fakeBTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN] = {0};
+u8 fakeBTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN] = {0};
+
+u8 maskfileBuffer[64];
+/*------------------------Define local variable------------------------------*/
+static bool rtw_file_efuse_IsMasked(PADAPTER pAdapter, u16 Offset)
+{
+ int r = Offset / 16;
+ int c = (Offset % 16) / 2;
+ int result = 0;
+
+ if (pAdapter->registrypriv.boffefusemask)
+ return false;
+
+ if (c < 4) /* Upper double word */
+ result = (maskfileBuffer[r] & (0x10 << c));
+ else
+ result = (maskfileBuffer[r] & (0x01 << (c - 4)));
+
+ return (result > 0) ? 0 : 1;
+}
+
+static bool efuse_IsMasked(PADAPTER pAdapter, u16 Offset)
+{
+ PHAL_DATA_TYPE pHalData = GET_HAL_DATA(pAdapter);
+
+ if (pAdapter->registrypriv.boffefusemask)
+ return false;
+
+ if (IS_HARDWARE_TYPE_8188E(pAdapter))
+ return (IS_MASKED(8188E, _MUSB, Offset)) ? true : false;
+
+ return false;
+}
+
+void rtw_efuse_mask_array(PADAPTER pAdapter, u8 *pArray)
+{
+ PHAL_DATA_TYPE pHalData = GET_HAL_DATA(pAdapter);
+
+ if (IS_HARDWARE_TYPE_8188E(pAdapter))
+ GET_MASK_ARRAY(8188E, _MUSB, pArray);
+}
+
+u16 rtw_get_efuse_mask_arraylen(PADAPTER pAdapter)
+{
+ HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
+
+ if (IS_HARDWARE_TYPE_8188E(pAdapter))
+ return GET_MASK_ARRAY_LEN(8188E, _MUSB);
+ return 0;
+}
+
+u8 rtw_efuse_mask_map_read(PADAPTER padapter, u16 addr, u16 cnts, u8 *data)
+{
+ u8 ret = _SUCCESS;
+ u16 mapLen = 0, i = 0;
+
+ EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, false);
+
+ ret = rtw_efuse_map_read(padapter, addr, cnts , data);
+
+ if (padapter->registrypriv.boffefusemask == 0) {
+
+ for (i = 0; i < cnts; i++) {
+ if (padapter->registrypriv.bFileMaskEfuse == true) {
+ if (rtw_file_efuse_IsMasked(padapter, addr + i)) /*use file efuse mask.*/
+ data[i] = 0xff;
+ } else {
+ /*RTW_INFO(" %s , data[%d] = %x\n", __func__, i, data[i]);*/
+ if (efuse_IsMasked(padapter, addr + i)) {
+ data[i] = 0xff;
+ /*RTW_INFO(" %s ,mask data[%d] = %x\n", __func__, i, data[i]);*/
+ }
+ }
+ }
+
+ }
+ return ret;
+
+}
+
+
+/* ------------------------------------------------------------------------------ */
+#define REG_EFUSE_CTRL 0x0030
+#define EFUSE_CTRL REG_EFUSE_CTRL /* E-Fuse Control. */
+/* ------------------------------------------------------------------------------ */
+
+static void efuse_PreUpdateAction(
+ PADAPTER pAdapter,
+ u32 * BackupRegs)
+{
+}
+
+static void efuse_PostUpdateAction(
+ PADAPTER pAdapter,
+ u32 * BackupRegs)
+{
+}
+
+
+bool
+Efuse_Read1ByteFromFakeContent(
+ PADAPTER pAdapter,
+ u16 Offset,
+ u8 *Value);
+bool
+Efuse_Read1ByteFromFakeContent(
+ PADAPTER pAdapter,
+ u16 Offset,
+ u8 *Value)
+{
+ if (Offset >= EFUSE_MAX_HW_SIZE)
+ return false;
+ /* DbgPrint("Read fake content, offset = %d\n", Offset); */
+ if (fakeEfuseBank == 0)
+ *Value = fakeEfuseContent[Offset];
+ else
+ *Value = fakeBTEfuseContent[fakeEfuseBank - 1][Offset];
+ return true;
+}
+
+bool
+Efuse_Write1ByteToFakeContent(
+ PADAPTER pAdapter,
+ u16 Offset,
+ u8 Value);
+bool
+Efuse_Write1ByteToFakeContent(
+ PADAPTER pAdapter,
+ u16 Offset,
+ u8 Value)
+{
+ if (Offset >= EFUSE_MAX_HW_SIZE)
+ return false;
+ if (fakeEfuseBank == 0)
+ fakeEfuseContent[Offset] = Value;
+ else
+ fakeBTEfuseContent[fakeEfuseBank - 1][Offset] = Value;
+ return true;
+}
+
+/*-----------------------------------------------------------------------------
+ * Function: Efuse_PowerSwitch
+ *
+ * Overview: When we want to enable write operation, we should change to
+ * pwr on state. When we stop write, we should switch to 500k mode
+ * and disable LDO 2.5V.
+ *
+ * Input: NONE
+ *
+ * Output: NONE
+ *
+ * Return: NONE
+ *
+ * Revised History:
+ * When Who Remark
+ * 11/17/2008 MHC Create Version 0.
+ *
+ *---------------------------------------------------------------------------*/
+void
+Efuse_PowerSwitch(
+ PADAPTER pAdapter,
+ u8 bWrite,
+ u8 PwrState)
+{
+ pAdapter->hal_func.EfusePowerSwitch(pAdapter, bWrite, PwrState);
+}
+
+void
+BTEfuse_PowerSwitch(
+ PADAPTER pAdapter,
+ u8 bWrite,
+ u8 PwrState)
+{
+ if (pAdapter->hal_func.BTEfusePowerSwitch)
+ pAdapter->hal_func.BTEfusePowerSwitch(pAdapter, bWrite, PwrState);
+}
+
+/*-----------------------------------------------------------------------------
+ * Function: efuse_GetCurrentSize
+ *
+ * Overview: Get current efuse size!!!
+ *
+ * Input: NONE
+ *
+ * Output: NONE
+ *
+ * Return: NONE
+ *
+ * Revised History:
+ * When Who Remark
+ * 11/16/2008 MHC Create Version 0.
+ *
+ *---------------------------------------------------------------------------*/
+u16
+Efuse_GetCurrentSize(
+ PADAPTER pAdapter,
+ u8 efuseType,
+ bool bPseudoTest)
+{
+ u16 ret = 0;
+
+ ret = pAdapter->hal_func.EfuseGetCurrentSize(pAdapter, efuseType, bPseudoTest);
+
+ return ret;
+}
+
+/*
+ * Description:
+ * Execute E-Fuse read byte operation.
+ * Refered from SD1 Richard.
+ *
+ * Assumption:
+ * 1. Boot from E-Fuse and successfully auto-load.
+ * 2. PASSIVE_LEVEL (USB interface)
+ *
+ * Created by Roger, 2008.10.21.
+ * */
+void
+ReadEFuseByte(
+ PADAPTER Adapter,
+ u16 _offset,
+ u8 *pbuf,
+ bool bPseudoTest)
+{
+ u32 value32;
+ u8 readbyte;
+ u16 retry;
+ /* u32 start=jiffies; */
+
+ if (bPseudoTest) {
+ Efuse_Read1ByteFromFakeContent(Adapter, _offset, pbuf);
+ return;
+ }
+ /* Write Address */
+ rtw_write8(Adapter, EFUSE_CTRL + 1, (_offset & 0xff));
+ readbyte = rtw_read8(Adapter, EFUSE_CTRL + 2);
+ rtw_write8(Adapter, EFUSE_CTRL + 2, ((_offset >> 8) & 0x03) | (readbyte & 0xfc));
+
+ /* Write bit 32 0 */
+ readbyte = rtw_read8(Adapter, EFUSE_CTRL + 3);
+ rtw_write8(Adapter, EFUSE_CTRL + 3, (readbyte & 0x7f));
+
+ /* Check bit 32 read-ready */
+ retry = 0;
+ value32 = rtw_read32(Adapter, EFUSE_CTRL);
+ /* while(!(((value32 >> 24) & 0xff) & 0x80) && (retry<10)) */
+ while (!(((value32 >> 24) & 0xff) & 0x80) && (retry < 10000)) {
+ value32 = rtw_read32(Adapter, EFUSE_CTRL);
+ retry++;
+ }
+
+ /* 20100205 Joseph: Add delay suggested by SD1 Victor. */
+ /* This fix the problem that Efuse read error in high temperature condition. */
+ /* Designer says that there shall be some delay after ready bit is set, or the */
+ /* result will always stay on last data we read. */
+ rtw_udelay_os(50);
+ value32 = rtw_read32(Adapter, EFUSE_CTRL);
+
+ *pbuf = (u8)(value32 & 0xff);
+ /* RTW_INFO("ReadEFuseByte _offset:%08u, in %d ms\n",_offset ,rtw_get_passing_time_ms(start)); */
+
+}
+
+/*
+ * Description:
+ * 1. Execute E-Fuse read byte operation according as map offset and
+ * save to E-Fuse table.
+ * 2. Refered from SD1 Richard.
+ *
+ * Assumption:
+ * 1. Boot from E-Fuse and successfully auto-load.
+ * 2. PASSIVE_LEVEL (USB interface)
+ *
+ * Created by Roger, 2008.10.21.
+ *
+ * 2008/12/12 MH 1. Reorganize code flow and reserve bytes. and add description.
+ * 2. Add efuse utilization collect.
+ * 2008/12/22 MH Read Efuse must check if we write section 1 data again!!! Sec1
+ * write addr must be after sec5.
+ * */
+
+void
+efuse_ReadEFuse(
+ PADAPTER Adapter,
+ u8 efuseType,
+ u16 _offset,
+ u16 _size_byte,
+ u8 *pbuf,
+ bool bPseudoTest
+);
+void
+efuse_ReadEFuse(
+ PADAPTER Adapter,
+ u8 efuseType,
+ u16 _offset,
+ u16 _size_byte,
+ u8 *pbuf,
+ bool bPseudoTest
+)
+{
+ Adapter->hal_func.ReadEFuse(Adapter, efuseType, _offset, _size_byte, pbuf, bPseudoTest);
+}
+
+void
+EFUSE_GetEfuseDefinition(
+ PADAPTER pAdapter,
+ u8 efuseType,
+ u8 type,
+ void *pOut,
+ bool bPseudoTest
+)
+{
+ pAdapter->hal_func.EFUSEGetEfuseDefinition(pAdapter, efuseType, type, pOut, bPseudoTest);
+}
+
+
+/* 11/16/2008 MH Read one byte from real Efuse. */
+u8
+efuse_OneByteRead(
+ PADAPTER pAdapter,
+ u16 addr,
+ u8 *data,
+ bool bPseudoTest)
+{
+ u32 tmpidx = 0;
+ u8 bResult;
+ u8 readbyte;
+ HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
+
+ /* RTW_INFO("===> EFUSE_OneByteRead(), addr = %x\n", addr); */
+ /* RTW_INFO("===> EFUSE_OneByteRead() start, 0x34 = 0x%X\n", rtw_read32(pAdapter, EFUSE_TEST)); */
+
+ if (bPseudoTest) {
+ bResult = Efuse_Read1ByteFromFakeContent(pAdapter, addr, data);
+ return bResult;
+ }
+
+ if ((IS_VENDOR_8188E_I_CUT_SERIES(pAdapter)) ||
+ (IS_CHIP_VENDOR_SMIC(pHalData->version_id))) {
+ /* <20130121, Kordan> For SMIC EFUSE specificatoin. */
+ /* 0x34[11]: SW force PGMEN input of efuse to high. (for the bank selected by 0x34[9:8]) */
+ /* phy_set_mac_reg(pAdapter, 0x34, BIT11, 0); */
+ rtw_write16(pAdapter, 0x34, rtw_read16(pAdapter, 0x34) & (~BIT11));
+ }
+
+ /* -----------------e-fuse reg ctrl --------------------------------- */
+ /* address */
+ rtw_write8(pAdapter, EFUSE_CTRL + 1, (u8)(addr & 0xff));
+ rtw_write8(pAdapter, EFUSE_CTRL + 2, ((u8)((addr >> 8) & 0x03)) |
+ (rtw_read8(pAdapter, EFUSE_CTRL + 2) & 0xFC));
+
+ /* rtw_write8(pAdapter, EFUSE_CTRL+3, 0x72); */ /* read cmd */
+ /* Write bit 32 0 */
+ readbyte = rtw_read8(pAdapter, EFUSE_CTRL + 3);
+ rtw_write8(pAdapter, EFUSE_CTRL + 3, (readbyte & 0x7f));
+
+ while (!(0x80 & rtw_read8(pAdapter, EFUSE_CTRL + 3)) && (tmpidx < 1000)) {
+ rtw_mdelay_os(1);
+ tmpidx++;
+ }
+ if (tmpidx < 100) {
+ *data = rtw_read8(pAdapter, EFUSE_CTRL);
+ bResult = true;
+ } else {
+ *data = 0xff;
+ bResult = false;
+ RTW_INFO("%s: [ERROR] addr=0x%x bResult=%d time out 1s !!!\n", __func__, addr, bResult);
+ RTW_INFO("%s: [ERROR] EFUSE_CTRL =0x%08x !!!\n", __func__, rtw_read32(pAdapter, EFUSE_CTRL));
+ }
+
+ return bResult;
+}
+
+/* 11/16/2008 MH Write one byte to reald Efuse. */
+u8
+efuse_OneByteWrite(
+ PADAPTER pAdapter,
+ u16 addr,
+ u8 data,
+ bool bPseudoTest)
+{
+ u8 tmpidx = 0;
+ u8 bResult = false;
+ u32 efuseValue = 0;
+ HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
+
+ /* RTW_INFO("===> EFUSE_OneByteWrite(), addr = %x data=%x\n", addr, data); */
+ /* RTW_INFO("===> EFUSE_OneByteWrite() start, 0x34 = 0x%X\n", rtw_read32(pAdapter, EFUSE_TEST)); */
+
+ if (bPseudoTest) {
+ bResult = Efuse_Write1ByteToFakeContent(pAdapter, addr, data);
+ return bResult;
+ }
+
+ Efuse_PowerSwitch(pAdapter, true, true);
+
+ /* -----------------e-fuse reg ctrl --------------------------------- */
+ /* address */
+
+
+ efuseValue = rtw_read32(pAdapter, EFUSE_CTRL);
+ efuseValue |= (BIT21 | BIT31);
+ efuseValue &= ~(0x3FFFF);
+ efuseValue |= ((addr << 8 | data) & 0x3FFFF);
+
+ /* <20130227, Kordan> 8192E MP chip A-cut had better not set 0x34[11] until B-Cut. */
+ if ((IS_VENDOR_8188E_I_CUT_SERIES(pAdapter)) ||
+ (IS_CHIP_VENDOR_SMIC(pHalData->version_id))) {
+ /* <20130121, Kordan> For SMIC EFUSE specificatoin. */
+ /* 0x34[11]: SW force PGMEN input of efuse to high. (for the bank selected by 0x34[9:8]) */
+ /* phy_set_mac_reg(pAdapter, 0x34, BIT11, 1); */
+ rtw_write16(pAdapter, 0x34, rtw_read16(pAdapter, 0x34) | (BIT11));
+ rtw_write32(pAdapter, EFUSE_CTRL, 0x90600000 | ((addr << 8 | data)));
+ } else
+ rtw_write32(pAdapter, EFUSE_CTRL, efuseValue);
+
+ rtw_mdelay_os(1);
+
+ while ((0x80 & rtw_read8(pAdapter, EFUSE_CTRL + 3)) && (tmpidx < 100)) {
+ rtw_mdelay_os(1);
+ tmpidx++;
+ }
+
+ if (tmpidx < 100)
+ bResult = true;
+ else {
+ bResult = false;
+ RTW_INFO("%s: [ERROR] addr=0x%x ,efuseValue=0x%x ,bResult=%d time out 1s !!!\n",
+ __func__, addr, efuseValue, bResult);
+ RTW_INFO("%s: [ERROR] EFUSE_CTRL =0x%08x !!!\n", __func__, rtw_read32(pAdapter, EFUSE_CTRL));
+ }
+
+ /* disable Efuse program enable */
+ if ((IS_VENDOR_8188E_I_CUT_SERIES(pAdapter)) ||
+ (IS_CHIP_VENDOR_SMIC(pHalData->version_id)))
+ phy_set_mac_reg(pAdapter, EFUSE_TEST, BIT(11), 0);
+
+ Efuse_PowerSwitch(pAdapter, true, false);
+
+ return bResult;
+}
+
+int
+Efuse_PgPacketRead(PADAPTER pAdapter,
+ u8 offset,
+ u8 *data,
+ bool bPseudoTest)
+{
+ int ret = 0;
+
+ ret = pAdapter->hal_func.Efuse_PgPacketRead(pAdapter, offset, data, bPseudoTest);
+
+ return ret;
+}
+
+int
+Efuse_PgPacketWrite(PADAPTER pAdapter,
+ u8 offset,
+ u8 word_en,
+ u8 *data,
+ bool bPseudoTest)
+{
+ int ret;
+
+ ret = pAdapter->hal_func.Efuse_PgPacketWrite(pAdapter, offset, word_en, data, bPseudoTest);
+
+ return ret;
+}
+
+
+static int
+Efuse_PgPacketWrite_BT(PADAPTER pAdapter,
+ u8 offset,
+ u8 word_en,
+ u8 *data,
+ bool bPseudoTest)
+{
+ int ret;
+
+ ret = pAdapter->hal_func.Efuse_PgPacketWrite_BT(pAdapter, offset, word_en, data, bPseudoTest);
+
+ return ret;
+}
+
+
+u8
+Efuse_WordEnableDataWrite(PADAPTER pAdapter,
+ u16 efuse_addr,
+ u8 word_en,
+ u8 *data,
+ bool bPseudoTest)
+{
+ u8 ret = 0;
+
+ ret = pAdapter->hal_func.Efuse_WordEnableDataWrite(pAdapter, efuse_addr, word_en, data, bPseudoTest);
+
+ return ret;
+}
+
+static u8 efuse_read8(PADAPTER padapter, u16 address, u8 *value)
+{
+ return efuse_OneByteRead(padapter, address, value, false);
+}
+
+static u8 efuse_write8(PADAPTER padapter, u16 address, u8 *value)
+{
+ return efuse_OneByteWrite(padapter, address, *value, false);
+}
+
+/*
+ * read/wirte raw efuse data
+ */
+u8 rtw_efuse_access(PADAPTER padapter, u8 bWrite, u16 start_addr, u16 cnts, u8 *data)
+{
+ int i = 0;
+ u16 real_content_len = 0, max_available_size = 0;
+ u8 res = _FAIL ;
+ u8(*rw8)(PADAPTER, u16, u8 *);
+ u32 backupRegs[4] = {0};
+
+
+ EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_REAL_CONTENT_LEN, (void *)&real_content_len, false);
+ EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_available_size, false);
+
+ if (start_addr > real_content_len)
+ return _FAIL;
+
+ if (bWrite) {
+ if ((start_addr + cnts) > max_available_size)
+ return _FAIL;
+ rw8 = &efuse_write8;
+ } else
+ rw8 = &efuse_read8;
+
+ efuse_PreUpdateAction(padapter, backupRegs);
+
+ Efuse_PowerSwitch(padapter, bWrite, true);
+
+ /* e-fuse one byte read / write */
+ for (i = 0; i < cnts; i++) {
+ if (start_addr >= real_content_len) {
+ res = _FAIL;
+ break;
+ }
+
+ res = rw8(padapter, start_addr++, data++);
+ if (_FAIL == res)
+ break;
+ }
+
+ Efuse_PowerSwitch(padapter, bWrite, false);
+
+ efuse_PostUpdateAction(padapter, backupRegs);
+
+ return res;
+}
+/* ------------------------------------------------------------------------------ */
+u16 efuse_GetMaxSize(PADAPTER padapter)
+{
+ u16 max_size;
+
+ max_size = 0;
+ EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI , TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_size, false);
+ return max_size;
+}
+/* ------------------------------------------------------------------------------ */
+u8 efuse_GetCurrentSize(PADAPTER padapter, u16 *size)
+{
+ Efuse_PowerSwitch(padapter, false, true);
+ *size = Efuse_GetCurrentSize(padapter, EFUSE_WIFI, false);
+ Efuse_PowerSwitch(padapter, false, false);
+
+ return _SUCCESS;
+}
+/* ------------------------------------------------------------------------------ */
+u16 efuse_bt_GetMaxSize(PADAPTER padapter)
+{
+ u16 max_size;
+
+ max_size = 0;
+ EFUSE_GetEfuseDefinition(padapter, EFUSE_BT , TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_size, false);
+ return max_size;
+}
+
+u8 efuse_bt_GetCurrentSize(PADAPTER padapter, u16 *size)
+{
+ Efuse_PowerSwitch(padapter, false, true);
+ *size = Efuse_GetCurrentSize(padapter, EFUSE_BT, false);
+ Efuse_PowerSwitch(padapter, false, false);
+
+ return _SUCCESS;
+}
+
+u8 rtw_efuse_map_read(PADAPTER padapter, u16 addr, u16 cnts, u8 *data)
+{
+ u16 mapLen = 0;
+
+ EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, false);
+
+ if ((addr + cnts) > mapLen)
+ return _FAIL;
+
+ Efuse_PowerSwitch(padapter, false, true);
+
+ efuse_ReadEFuse(padapter, EFUSE_WIFI, addr, cnts, data, false);
+
+ Efuse_PowerSwitch(padapter, false, false);
+
+ return _SUCCESS;
+}
+
+u8 rtw_BT_efuse_map_read(PADAPTER padapter, u16 addr, u16 cnts, u8 *data)
+{
+ u16 mapLen = 0;
+
+ EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, false);
+
+ if ((addr + cnts) > mapLen)
+ return _FAIL;
+
+ Efuse_PowerSwitch(padapter, false, true);
+
+ efuse_ReadEFuse(padapter, EFUSE_BT, addr, cnts, data, false);
+
+ Efuse_PowerSwitch(padapter, false, false);
+
+ return _SUCCESS;
+}
+
+/* ------------------------------------------------------------------------------ */
+u8 rtw_efuse_map_write(PADAPTER padapter, u16 addr, u16 cnts, u8 *data)
+{
+#define RT_ASSERT_RET(expr) \
+ if (!(expr)) { \
+ RTW_INFO("Assertion failed! %s at ......\n", #expr); \
+ RTW_INFO(" ......%s,%s, line=%d\n",__FILE__, __func__, __LINE__); \
+ return _FAIL; \
+ }
+
+ u8 offset, word_en;
+ u8 *map;
+ u8 newdata[PGPKT_DATA_SIZE];
+ s32 i, j, idx, chk_total_byte;
+ u8 ret = _SUCCESS;
+ u16 mapLen = 0, startAddr = 0, efuse_max_available_len = 0;
+ u32 backupRegs[4] = {0};
+ HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
+ PEFUSE_HAL pEfuseHal = &pHalData->EfuseHal;
+
+
+ EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, false);
+ EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, &efuse_max_available_len, false);
+
+ if ((addr + cnts) > mapLen)
+ return _FAIL;
+
+ RT_ASSERT_RET(PGPKT_DATA_SIZE == 8); /* have to be 8 byte alignment */
+ RT_ASSERT_RET((mapLen & 0x7) == 0); /* have to be PGPKT_DATA_SIZE alignment for memcpy */
+
+ map = rtw_zmalloc(mapLen);
+ if (map == NULL)
+ return _FAIL;
+
+ memset(map, 0xFF, mapLen);
+
+ ret = rtw_efuse_map_read(padapter, 0, mapLen, map);
+ if (ret == _FAIL)
+ goto exit;
+
+ if (padapter->registrypriv.boffefusemask == 0) {
+ for (i = 0; i < cnts; i++) {
+ if (padapter->registrypriv.bFileMaskEfuse == true) {
+ if (rtw_file_efuse_IsMasked(padapter, addr + i)) /*use file efuse mask. */
+ data[i] = map[addr + i];
+ } else {
+ if (efuse_IsMasked(padapter, addr + i))
+ data[i] = map[addr + i];
+ }
+ RTW_INFO("%s , data[%d] = %x, map[addr+i]= %x\n", __func__, i, data[i], map[addr + i]);
+ }
+ }
+ /*Efuse_PowerSwitch(padapter, true, true);*/
+
+ chk_total_byte = 0;
+ idx = 0;
+ offset = (addr >> 3);
+
+ while (idx < cnts) {
+ word_en = 0xF;
+ j = (addr + idx) & 0x7;
+ for (i = j; i < PGPKT_DATA_SIZE && idx < cnts; i++, idx++) {
+ if (data[idx] != map[addr + idx])
+ word_en &= ~BIT(i >> 1);
+ }
+
+ if (word_en != 0xF) {
+ chk_total_byte += Efuse_CalculateWordCnts(word_en) * 2;
+
+ if (offset >= EFUSE_MAX_SECTION_BASE) /* Over EFUSE_MAX_SECTION 16 for 2 ByteHeader */
+ chk_total_byte += 2;
+ else
+ chk_total_byte += 1;
+ }
+
+ offset++;
+ }
+
+ RTW_INFO("Total PG bytes Count = %d\n", chk_total_byte);
+ rtw_hal_get_hwreg(padapter, HW_VAR_EFUSE_BYTES, (u8 *)&startAddr);
+
+ if (startAddr == 0) {
+ startAddr = Efuse_GetCurrentSize(padapter, EFUSE_WIFI, false);
+ RTW_INFO("%s: Efuse_GetCurrentSize startAddr=%#X\n", __func__, startAddr);
+ }
+ RTW_DBG("%s: startAddr=%#X\n", __func__, startAddr);
+
+ if ((startAddr + chk_total_byte) >= efuse_max_available_len) {
+ RTW_INFO("%s: startAddr(0x%X) + PG data len %d >= efuse_max_available_len(0x%X)\n",
+ __func__, startAddr, chk_total_byte, efuse_max_available_len);
+ ret = _FAIL;
+ goto exit;
+ }
+
+ efuse_PreUpdateAction(padapter, backupRegs);
+
+ idx = 0;
+ offset = (addr >> 3);
+ while (idx < cnts) {
+ word_en = 0xF;
+ j = (addr + idx) & 0x7;
+ memcpy(newdata, &map[offset << 3], PGPKT_DATA_SIZE);
+ for (i = j; i < PGPKT_DATA_SIZE && idx < cnts; i++, idx++) {
+ if (data[idx] != map[addr + idx]) {
+ word_en &= ~BIT(i >> 1);
+ newdata[i] = data[idx];
+ }
+ }
+
+ if (word_en != 0xF) {
+ ret = Efuse_PgPacketWrite(padapter, offset, word_en, newdata, false);
+ RTW_INFO("offset=%x\n", offset);
+ RTW_INFO("word_en=%x\n", word_en);
+
+ for (i = 0; i < PGPKT_DATA_SIZE; i++)
+ RTW_INFO("data=%x \t", newdata[i]);
+ if (ret == _FAIL)
+ break;
+ }
+
+ offset++;
+ }
+
+ /*Efuse_PowerSwitch(padapter, true, false);*/
+
+ efuse_PostUpdateAction(padapter, backupRegs);
+
+exit:
+
+ rtw_mfree(map, mapLen);
+
+ return ret;
+}
+
+
+u8 rtw_BT_efuse_map_write(PADAPTER padapter, u16 addr, u16 cnts, u8 *data)
+{
+#define RT_ASSERT_RET(expr) \
+ if (!(expr)) { \
+ RTW_INFO("Assertion failed! %s at ......\n", #expr); \
+ RTW_INFO(" ......%s,%s, line=%d\n",__FILE__, __func__, __LINE__); \
+ return _FAIL; \
+ }
+
+ u8 offset, word_en;
+ u8 *map;
+ u8 newdata[PGPKT_DATA_SIZE];
+ s32 i = 0, j = 0, idx;
+ u8 ret = _SUCCESS;
+ u16 mapLen = 0;
+
+ EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, false);
+
+ if ((addr + cnts) > mapLen)
+ return _FAIL;
+
+ RT_ASSERT_RET(PGPKT_DATA_SIZE == 8); /* have to be 8 byte alignment */
+ RT_ASSERT_RET((mapLen & 0x7) == 0); /* have to be PGPKT_DATA_SIZE alignment for memcpy */
+
+ map = rtw_zmalloc(mapLen);
+ if (map == NULL)
+ return _FAIL;
+
+ ret = rtw_BT_efuse_map_read(padapter, 0, mapLen, map);
+ if (ret == _FAIL)
+ goto exit;
+ RTW_INFO("OFFSET\tVALUE(hex)\n");
+ for (i = 0; i < 1024; i += 16) { /* set 512 because the iwpriv's extra size have limit 0x7FF */
+ RTW_INFO("0x%03x\t", i);
+ for (j = 0; j < 8; j++)
+ RTW_INFO("%02X ", map[i + j]);
+ RTW_INFO("\t");
+ for (; j < 16; j++)
+ RTW_INFO("%02X ", map[i + j]);
+ RTW_INFO("\n");
+ }
+ RTW_INFO("\n");
+ Efuse_PowerSwitch(padapter, true, true);
+
+ idx = 0;
+ offset = (addr >> 3);
+ while (idx < cnts) {
+ word_en = 0xF;
+ j = (addr + idx) & 0x7;
+ memcpy(newdata, &map[offset << 3], PGPKT_DATA_SIZE);
+ for (i = j; i < PGPKT_DATA_SIZE && idx < cnts; i++, idx++) {
+ if (data[idx] != map[addr + idx]) {
+ word_en &= ~BIT(i >> 1);
+ newdata[i] = data[idx];
+ }
+ }
+
+ if (word_en != 0xF) {
+ RTW_INFO("offset=%x\n", offset);
+ RTW_INFO("word_en=%x\n", word_en);
+ RTW_INFO("%s: data=", __func__);
+ for (i = 0; i < PGPKT_DATA_SIZE; i++)
+ RTW_INFO("0x%02X ", newdata[i]);
+ RTW_INFO("\n");
+ ret = Efuse_PgPacketWrite_BT(padapter, offset, word_en, newdata, false);
+ if (ret == _FAIL)
+ break;
+ }
+
+ offset++;
+ }
+
+ Efuse_PowerSwitch(padapter, true, false);
+
+exit:
+
+ rtw_mfree(map, mapLen);
+
+ return ret;
+}
+
+/*-----------------------------------------------------------------------------
+ * Function: Efuse_ReadAllMap
+ *
+ * Overview: Read All Efuse content
+ *
+ * Input: NONE
+ *
+ * Output: NONE
+ *
+ * Return: NONE
+ *
+ * Revised History:
+ * When Who Remark
+ * 11/11/2008 MHC Create Version 0.
+ *
+ *---------------------------------------------------------------------------*/
+void
+Efuse_ReadAllMap(
+ PADAPTER pAdapter,
+ u8 efuseType,
+ u8 *Efuse,
+ bool bPseudoTest);
+void
+Efuse_ReadAllMap(
+ PADAPTER pAdapter,
+ u8 efuseType,
+ u8 *Efuse,
+ bool bPseudoTest)
+{
+ u16 mapLen = 0;
+
+ Efuse_PowerSwitch(pAdapter, false, true);
+
+ EFUSE_GetEfuseDefinition(pAdapter, efuseType, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, bPseudoTest);
+
+ efuse_ReadEFuse(pAdapter, efuseType, 0, mapLen, Efuse, bPseudoTest);
+
+ Efuse_PowerSwitch(pAdapter, false, false);
+}
+
+/*-----------------------------------------------------------------------------
+ * Function: efuse_ShadowRead1Byte
+ * efuse_ShadowRead2Byte
+ * efuse_ShadowRead4Byte
+ *
+ * Overview: Read from efuse init map by one/two/four bytes !!!!!
+ *
+ * Input: NONE
+ *
+ * Output: NONE
+ *
+ * Return: NONE
+ *
+ * Revised History:
+ * When Who Remark
+ * 11/12/2008 MHC Create Version 0.
+ *
+ *---------------------------------------------------------------------------*/
+static void
+efuse_ShadowRead1Byte(
+ PADAPTER pAdapter,
+ u16 Offset,
+ u8 *Value)
+{
+ PHAL_DATA_TYPE pHalData = GET_HAL_DATA(pAdapter);
+
+ *Value = pHalData->efuse_eeprom_data[Offset];
+
+} /* EFUSE_ShadowRead1Byte */
+
+/* ---------------Read Two Bytes */
+static void
+efuse_ShadowRead2Byte(
+ PADAPTER pAdapter,
+ u16 Offset,
+ u16 *Value)
+{
+ PHAL_DATA_TYPE pHalData = GET_HAL_DATA(pAdapter);
+
+ *Value = pHalData->efuse_eeprom_data[Offset];
+ *Value |= pHalData->efuse_eeprom_data[Offset + 1] << 8;
+
+} /* EFUSE_ShadowRead2Byte */
+
+/* ---------------Read Four Bytes */
+static void
+efuse_ShadowRead4Byte(
+ PADAPTER pAdapter,
+ u16 Offset,
+ u32 *Value)
+{
+ PHAL_DATA_TYPE pHalData = GET_HAL_DATA(pAdapter);
+
+ *Value = pHalData->efuse_eeprom_data[Offset];
+ *Value |= pHalData->efuse_eeprom_data[Offset + 1] << 8;
+ *Value |= pHalData->efuse_eeprom_data[Offset + 2] << 16;
+ *Value |= pHalData->efuse_eeprom_data[Offset + 3] << 24;
+
+} /* efuse_ShadowRead4Byte */
+
+
+/*-----------------------------------------------------------------------------
+ * Function: efuse_ShadowWrite1Byte
+ * efuse_ShadowWrite2Byte
+ * efuse_ShadowWrite4Byte
+ *
+ * Overview: Write efuse modify map by one/two/four byte.
+ *
+ * Input: NONE
+ *
+ * Output: NONE
+ *
+ * Return: NONE
+ *
+ * Revised History:
+ * When Who Remark
+ * 11/12/2008 MHC Create Version 0.
+ *
+ *---------------------------------------------------------------------------*/
+
+static void
+efuse_ShadowWrite1Byte(
+ PADAPTER pAdapter,
+ u16 Offset,
+ u8 Value)
+{
+ PHAL_DATA_TYPE pHalData = GET_HAL_DATA(pAdapter);
+
+ pHalData->efuse_eeprom_data[Offset] = Value;
+
+} /* efuse_ShadowWrite1Byte */
+
+/* ---------------Write Two Bytes */
+static void
+efuse_ShadowWrite2Byte(
+ PADAPTER pAdapter,
+ u16 Offset,
+ u16 Value)
+{
+
+ PHAL_DATA_TYPE pHalData = GET_HAL_DATA(pAdapter);
+
+
+ pHalData->efuse_eeprom_data[Offset] = Value & 0x00FF;
+ pHalData->efuse_eeprom_data[Offset + 1] = Value >> 8;
+
+} /* efuse_ShadowWrite1Byte */
+
+/* ---------------Write Four Bytes */
+static void
+efuse_ShadowWrite4Byte(
+ PADAPTER pAdapter,
+ u16 Offset,
+ u32 Value)
+{
+ PHAL_DATA_TYPE pHalData = GET_HAL_DATA(pAdapter);
+
+ pHalData->efuse_eeprom_data[Offset] = (u8)(Value & 0x000000FF);
+ pHalData->efuse_eeprom_data[Offset + 1] = (u8)((Value >> 8) & 0x0000FF);
+ pHalData->efuse_eeprom_data[Offset + 2] = (u8)((Value >> 16) & 0x00FF);
+ pHalData->efuse_eeprom_data[Offset + 3] = (u8)((Value >> 24) & 0xFF);
+
+} /* efuse_ShadowWrite1Byte */
+
+
+/*-----------------------------------------------------------------------------
+ * Function: EFUSE_ShadowRead
+ *
+ * Overview: Read from efuse init map !!!!!
+ *
+ * Input: NONE
+ *
+ * Output: NONE
+ *
+ * Return: NONE
+ *
+ * Revised History:
+ * When Who Remark
+ * 11/12/2008 MHC Create Version 0.
+ *
+ *---------------------------------------------------------------------------*/
+void
+EFUSE_ShadowRead(
+ PADAPTER pAdapter,
+ u8 Type,
+ u16 Offset,
+ u32 *Value)
+{
+ if (Type == 1)
+ efuse_ShadowRead1Byte(pAdapter, Offset, (u8 *)Value);
+ else if (Type == 2)
+ efuse_ShadowRead2Byte(pAdapter, Offset, (u16 *)Value);
+ else if (Type == 4)
+ efuse_ShadowRead4Byte(pAdapter, Offset, (u32 *)Value);
+
+} /* EFUSE_ShadowRead */
+
+/*-----------------------------------------------------------------------------
+ * Function: EFUSE_ShadowWrite
+ *
+ * Overview: Write efuse modify map for later update operation to use!!!!!
+ *
+ * Input: NONE
+ *
+ * Output: NONE
+ *
+ * Return: NONE
+ *
+ * Revised History:
+ * When Who Remark
+ * 11/12/2008 MHC Create Version 0.
+ *
+ *---------------------------------------------------------------------------*/
+void
+EFUSE_ShadowWrite(
+ PADAPTER pAdapter,
+ u8 Type,
+ u16 Offset,
+ u32 Value);
+void
+EFUSE_ShadowWrite(
+ PADAPTER pAdapter,
+ u8 Type,
+ u16 Offset,
+ u32 Value)
+{
+#if (MP_DRIVER == 0)
+ return;
+#endif
+ if (pAdapter->registrypriv.mp_mode == 0)
+ return;
+
+
+ if (Type == 1)
+ efuse_ShadowWrite1Byte(pAdapter, Offset, (u8)Value);
+ else if (Type == 2)
+ efuse_ShadowWrite2Byte(pAdapter, Offset, (u16)Value);
+ else if (Type == 4)
+ efuse_ShadowWrite4Byte(pAdapter, Offset, (u32)Value);
+
+} /* EFUSE_ShadowWrite */
+
+void
+Efuse_InitSomeVar(
+ PADAPTER pAdapter
+);
+void
+Efuse_InitSomeVar(
+ PADAPTER pAdapter
+)
+{
+ u8 i;
+
+ memset((void *)&fakeEfuseContent[0], 0xff, EFUSE_MAX_HW_SIZE);
+ memset((void *)&fakeEfuseInitMap[0], 0xff, EFUSE_MAX_MAP_LEN);
+ memset((void *)&fakeEfuseModifiedMap[0], 0xff, EFUSE_MAX_MAP_LEN);
+
+ for (i = 0; i < EFUSE_MAX_BT_BANK; i++)
+ memset((void *)&BTEfuseContent[i][0], 0xff, EFUSE_MAX_HW_SIZE);
+ memset((void *)&BTEfuseInitMap[0], 0xff, EFUSE_BT_MAX_MAP_LEN);
+ memset((void *)&BTEfuseModifiedMap[0], 0xff, EFUSE_BT_MAX_MAP_LEN);
+
+ for (i = 0; i < EFUSE_MAX_BT_BANK; i++)
+ memset((void *)&fakeBTEfuseContent[i][0], 0xff, EFUSE_MAX_HW_SIZE);
+ memset((void *)&fakeBTEfuseInitMap[0], 0xff, EFUSE_BT_MAX_MAP_LEN);
+ memset((void *)&fakeBTEfuseModifiedMap[0], 0xff, EFUSE_BT_MAX_MAP_LEN);
+}
+
+/* 11/16/2008 MH Add description. Get current efuse area enabled word!!. */
+u8
+Efuse_CalculateWordCnts(u8 word_en)
+{
+ u8 word_cnts = 0;
+ if (!(word_en & BIT(0)))
+ word_cnts++; /* 0 : write enable */
+ if (!(word_en & BIT(1)))
+ word_cnts++;
+ if (!(word_en & BIT(2)))
+ word_cnts++;
+ if (!(word_en & BIT(3)))
+ word_cnts++;
+ return word_cnts;
+}
+
+/*-----------------------------------------------------------------------------
+ * Function: efuse_WordEnableDataRead
+ *
+ * Overview: Read allowed word in current efuse section data.
+ *
+ * Input: NONE
+ *
+ * Output: NONE
+ *
+ * Return: NONE
+ *
+ * Revised History:
+ * When Who Remark
+ * 11/16/2008 MHC Create Version 0.
+ * 11/21/2008 MHC Fix Write bug when we only enable late word.
+ *
+ *---------------------------------------------------------------------------*/
+void
+efuse_WordEnableDataRead(u8 word_en,
+ u8 *sourdata,
+ u8 *targetdata)
+{
+ if (!(word_en & BIT(0))) {
+ targetdata[0] = sourdata[0];
+ targetdata[1] = sourdata[1];
+ }
+ if (!(word_en & BIT(1))) {
+ targetdata[2] = sourdata[2];
+ targetdata[3] = sourdata[3];
+ }
+ if (!(word_en & BIT(2))) {
+ targetdata[4] = sourdata[4];
+ targetdata[5] = sourdata[5];
+ }
+ if (!(word_en & BIT(3))) {
+ targetdata[6] = sourdata[6];
+ targetdata[7] = sourdata[7];
+ }
+}
+
+/*-----------------------------------------------------------------------------
+ * Function: EFUSE_ShadowMapUpdate
+ *
+ * Overview: Transfer current EFUSE content to shadow init and modify map.
+ *
+ * Input: NONE
+ *
+ * Output: NONE
+ *
+ * Return: NONE
+ *
+ * Revised History:
+ * When Who Remark
+ * 11/13/2008 MHC Create Version 0.
+ *
+ *---------------------------------------------------------------------------*/
+void EFUSE_ShadowMapUpdate(
+ PADAPTER pAdapter,
+ u8 efuseType,
+ bool bPseudoTest)
+{
+ PHAL_DATA_TYPE pHalData = GET_HAL_DATA(pAdapter);
+ u16 mapLen = 0;
+ EFUSE_GetEfuseDefinition(pAdapter, efuseType, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, bPseudoTest);
+
+ if (pHalData->bautoload_fail_flag == true)
+ memset(pHalData->efuse_eeprom_data, 0xFF, mapLen);
+ else {
+#ifdef CONFIG_ADAPTOR_INFO_CACHING_FILE
+ if (_SUCCESS != retriveAdaptorInfoFile(pAdapter->registrypriv.adaptor_info_caching_file_path, pHalData->efuse_eeprom_data)) {
+#endif
+
+ Efuse_ReadAllMap(pAdapter, efuseType, pHalData->efuse_eeprom_data, bPseudoTest);
+
+#ifdef CONFIG_ADAPTOR_INFO_CACHING_FILE
+ storeAdaptorInfoFile(pAdapter->registrypriv.adaptor_info_caching_file_path, pHalData->efuse_eeprom_data);
+ }
+#endif
+ }
+
+ rtw_dump_cur_efuse(pAdapter);
+} /* EFUSE_ShadowMapUpdate */
+
+const u8 _mac_hidden_max_bw_to_hal_bw_cap[MAC_HIDDEN_MAX_BW_NUM] = {
+ 0,
+ 0,
+ (BW_CAP_160M | BW_CAP_80M | BW_CAP_40M | BW_CAP_20M | BW_CAP_10M | BW_CAP_5M),
+ (BW_CAP_5M),
+ (BW_CAP_10M | BW_CAP_5M),
+ (BW_CAP_20M | BW_CAP_10M | BW_CAP_5M),
+ (BW_CAP_40M | BW_CAP_20M | BW_CAP_10M | BW_CAP_5M),
+ (BW_CAP_80M | BW_CAP_40M | BW_CAP_20M | BW_CAP_10M | BW_CAP_5M),
+};
+
+const u8 _mac_hidden_proto_to_hal_proto_cap[MAC_HIDDEN_PROTOCOL_NUM] = {
+ 0,
+ 0,
+ (PROTO_CAP_11N | PROTO_CAP_11G | PROTO_CAP_11B),
+ (PROTO_CAP_11AC | PROTO_CAP_11N | PROTO_CAP_11G | PROTO_CAP_11B),
+};
+
+u8 mac_hidden_wl_func_to_hal_wl_func(u8 func)
+{
+ u8 wl_func = 0;
+
+ if (func & BIT0)
+ wl_func |= WL_FUNC_MIRACAST;
+ if (func & BIT1)
+ wl_func |= WL_FUNC_P2P;
+ if (func & BIT2)
+ wl_func |= WL_FUNC_TDLS;
+ if (func & BIT3)
+ wl_func |= WL_FUNC_FTM;
+
+ return wl_func;
+}
+
+#ifdef CONFIG_ADAPTOR_INFO_CACHING_FILE
+
+int isAdaptorInfoFileValid(void)
+{
+ return true;
+}
+
+int storeAdaptorInfoFile(char *path, u8 *efuse_data)
+{
+ int ret = _SUCCESS;
+
+ if (path && efuse_data) {
+ ret = rtw_store_to_file(path, efuse_data, EEPROM_MAX_SIZE_512);
+ if (ret == EEPROM_MAX_SIZE)
+ ret = _SUCCESS;
+ else
+ ret = _FAIL;
+ } else {
+ RTW_INFO("%s NULL pointer\n", __func__);
+ ret = _FAIL;
+ }
+ return ret;
+}
+
+int retriveAdaptorInfoFile(char *path, u8 *efuse_data)
+{
+ int ret = _SUCCESS;
+ mm_segment_t oldfs;
+ struct file *fp;
+
+ if (path && efuse_data) {
+
+ ret = rtw_retrieve_from_file(path, efuse_data, EEPROM_MAX_SIZE);
+
+ if (ret == EEPROM_MAX_SIZE)
+ ret = _SUCCESS;
+ else
+ ret = _FAIL;
+ } else {
+ RTW_INFO("%s NULL pointer\n", __func__);
+ ret = _FAIL;
+ }
+ return ret;
+}
+#endif /* CONFIG_ADAPTOR_INFO_CACHING_FILE */
+
+u8 rtw_efuse_file_read(PADAPTER padapter, u8 *filepatch, u8 *buf, u32 len)
+{
+ char *ptmpbuf = NULL, *ptr;
+ u8 val8;
+ u32 count, i, j;
+ int err;
+ u32 bufsize = 4096;
+
+ ptmpbuf = rtw_zmalloc(bufsize);
+ if (ptmpbuf == NULL)
+ return false;
+
+ count = rtw_retrieve_from_file(filepatch, ptmpbuf, bufsize);
+ if (count <= 100) {
+ rtw_mfree(ptmpbuf, bufsize);
+ RTW_ERR("%s, filepatch %s, size=%d, FAIL!!\n", __func__, filepatch, count);
+ return false;
+ }
+
+ i = 0;
+ j = 0;
+ ptr = ptmpbuf;
+ while ((j < len) && (i < count)) {
+ if (ptmpbuf[i] == '\0')
+ break;
+
+ ptr = strpbrk(&ptmpbuf[i], " \t\n\r");
+ if (ptr) {
+ if (ptr == &ptmpbuf[i]) {
+ i++;
+ continue;
+ }
+
+ /* Add string terminating null */
+ *ptr = 0;
+ } else {
+ ptr = &ptmpbuf[count-1];
+ }
+
+ err = sscanf(&ptmpbuf[i], "%hhx", &val8);
+ if (err != 1) {
+ RTW_WARN("Something wrong to parse efuse file, string=%s\n", &ptmpbuf[i]);
+ } else {
+ buf[j] = val8;
+ RTW_DBG("i=%d, j=%d, 0x%02x\n", i, j, buf[j]);
+ j++;
+ }
+
+ i = ptr - ptmpbuf + 1;
+ }
+
+ rtw_mfree(ptmpbuf, bufsize);
+ RTW_INFO("%s, filepatch %s, size=%d, done\n", __func__, filepatch, count);
+ return true;
+}
+
+#ifdef CONFIG_EFUSE_CONFIG_FILE
+u32 rtw_read_efuse_from_file(const char *path, u8 *buf, int map_size)
+{
+ u32 i;
+ u8 c;
+ u8 temp[3];
+ u8 temp_i;
+ u8 end = false;
+ u32 ret = _FAIL;
+
+ u8 *file_data = NULL;
+ u32 file_size, read_size, pos = 0;
+ u8 *map = NULL;
+
+ if (rtw_is_file_readable_with_size(path, &file_size) != true) {
+ RTW_PRINT("%s %s is not readable\n", __func__, path);
+ goto exit;
+ }
+
+ file_data = vmalloc(file_size);
+ if (!file_data) {
+ RTW_ERR("%s vmalloc(%d) fail\n", __func__, file_size);
+ goto exit;
+ }
+
+ read_size = rtw_retrieve_from_file(path, file_data, file_size);
+ if (read_size == 0) {
+ RTW_ERR("%s read from %s fail\n", __func__, path);
+ goto exit;
+ }
+
+ map = vmalloc(map_size);
+ if (!map) {
+ RTW_ERR("%s vmalloc(%d) fail\n", __func__, map_size);
+ goto exit;
+ }
+ memset(map, 0xff, map_size);
+
+ temp[2] = 0; /* end of string '\0' */
+
+ for (i = 0 ; i < map_size ; i++) {
+ temp_i = 0;
+
+ while (1) {
+ if (pos >= read_size) {
+ end = true;
+ break;
+ }
+ c = file_data[pos++];
+
+ /* bypass spece or eol or null before first hex digit */
+ if (temp_i == 0 && (is_eol(c) == true || is_space(c) == true || is_null(c) == true))
+ continue;
+
+ if (IsHexDigit(c) == false) {
+ RTW_ERR("%s invalid 8-bit hex format for offset:0x%03x\n", __func__, i);
+ goto exit;
+ }
+
+ temp[temp_i++] = c;
+
+ if (temp_i == 2) {
+ /* parse value */
+ if (sscanf(temp, "%hhx", &map[i]) != 1) {
+ RTW_ERR("%s sscanf fail for offset:0x%03x\n", __func__, i);
+ goto exit;
+ }
+ break;
+ }
+ }
+
+ if (end == true) {
+ if (temp_i != 0) {
+ RTW_ERR("%s incomplete 8-bit hex format for offset:0x%03x\n", __func__, i);
+ goto exit;
+ }
+ break;
+ }
+ }
+
+ RTW_PRINT("efuse file:%s, 0x%03x byte content read\n", path, i);
+
+ memcpy(buf, map, map_size);
+
+ ret = _SUCCESS;
+
+exit:
+ if (file_data)
+ rtw_vmfree(file_data, file_size);
+ if (map)
+ rtw_vmfree(map, map_size);
+
+ return ret;
+}
+
+u32 rtw_read_macaddr_from_file(const char *path, u8 *buf)
+{
+ u32 i;
+ u8 temp[3];
+ u32 ret = _FAIL;
+
+ u8 file_data[17];
+ u32 read_size, pos = 0;
+ u8 addr[ETH_ALEN];
+
+ if (rtw_is_file_readable(path) != true) {
+ RTW_PRINT("%s %s is not readable\n", __func__, path);
+ goto exit;
+ }
+
+ read_size = rtw_retrieve_from_file(path, file_data, 17);
+ if (read_size != 17) {
+ RTW_ERR("%s read from %s fail\n", __func__, path);
+ goto exit;
+ }
+
+ temp[2] = 0; /* end of string '\0' */
+
+ for (i = 0 ; i < ETH_ALEN ; i++) {
+ if (IsHexDigit(file_data[i * 3]) == false || IsHexDigit(file_data[i * 3 + 1]) == false) {
+ RTW_ERR("%s invalid 8-bit hex format for address offset:%u\n", __func__, i);
+ goto exit;
+ }
+
+ if (i < ETH_ALEN - 1 && file_data[i * 3 + 2] != ':') {
+ RTW_ERR("%s invalid separator after address offset:%u\n", __func__, i);
+ goto exit;
+ }
+
+ temp[0] = file_data[i * 3];
+ temp[1] = file_data[i * 3 + 1];
+ if (sscanf(temp, "%hhx", &addr[i]) != 1) {
+ RTW_ERR("%s sscanf fail for address offset:0x%03x\n", __func__, i);
+ goto exit;
+ }
+ }
+
+ memcpy(buf, addr, ETH_ALEN);
+
+ RTW_PRINT("wifi_mac file: %s\n", path);
+#ifdef CONFIG_RTW_DEBUG
+ RTW_INFO(MAC_FMT"\n", MAC_ARG(buf));
+#endif
+
+ ret = _SUCCESS;
+
+exit:
+ return ret;
+}
+#endif /* CONFIG_EFUSE_CONFIG_FILE */
diff --git a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
new file mode 100644
index 000000000000..33636425c345
--- /dev/null
+++ b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
@@ -0,0 +1,2673 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved. */
+
+#define _IEEE80211_C
+
+#ifdef CONFIG_PLATFORM_INTEL_BYT
+ #include <linux/fs.h>
+#endif
+#include <drv_types.h>
+#include <hal_data.h>
+
+u8 RTW_WPA_OUI_TYPE[] = { 0x00, 0x50, 0xf2, 1 };
+u16 RTW_WPA_VERSION = 1;
+u8 WPA_AUTH_KEY_MGMT_NONE[] = { 0x00, 0x50, 0xf2, 0 };
+u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X[] = { 0x00, 0x50, 0xf2, 1 };
+u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X[] = { 0x00, 0x50, 0xf2, 2 };
+u8 WPA_CIPHER_SUITE_NONE[] = { 0x00, 0x50, 0xf2, 0 };
+u8 WPA_CIPHER_SUITE_WEP40[] = { 0x00, 0x50, 0xf2, 1 };
+u8 WPA_CIPHER_SUITE_TKIP[] = { 0x00, 0x50, 0xf2, 2 };
+u8 WPA_CIPHER_SUITE_WRAP[] = { 0x00, 0x50, 0xf2, 3 };
+u8 WPA_CIPHER_SUITE_CCMP[] = { 0x00, 0x50, 0xf2, 4 };
+u8 WPA_CIPHER_SUITE_WEP104[] = { 0x00, 0x50, 0xf2, 5 };
+
+u16 RSN_VERSION_BSD = 1;
+u8 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X[] = { 0x00, 0x0f, 0xac, 1 };
+u8 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X[] = { 0x00, 0x0f, 0xac, 2 };
+u8 RSN_CIPHER_SUITE_NONE[] = { 0x00, 0x0f, 0xac, 0 };
+u8 RSN_CIPHER_SUITE_WEP40[] = { 0x00, 0x0f, 0xac, 1 };
+u8 RSN_CIPHER_SUITE_TKIP[] = { 0x00, 0x0f, 0xac, 2 };
+u8 RSN_CIPHER_SUITE_WRAP[] = { 0x00, 0x0f, 0xac, 3 };
+u8 RSN_CIPHER_SUITE_CCMP[] = { 0x00, 0x0f, 0xac, 4 };
+u8 RSN_CIPHER_SUITE_WEP104[] = { 0x00, 0x0f, 0xac, 5 };
+/* -----------------------------------------------------------
+ * for adhoc-master to generate ie and provide supported-rate to fw
+ * ----------------------------------------------------------- */
+
+static u8 WIFI_CCKRATES[] = {
+ (IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK),
+ (IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK),
+ (IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK),
+ (IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK)
+};
+
+static u8 WIFI_OFDMRATES[] = {
+ (IEEE80211_OFDM_RATE_6MB),
+ (IEEE80211_OFDM_RATE_9MB),
+ (IEEE80211_OFDM_RATE_12MB),
+ (IEEE80211_OFDM_RATE_18MB),
+ (IEEE80211_OFDM_RATE_24MB),
+ IEEE80211_OFDM_RATE_36MB,
+ IEEE80211_OFDM_RATE_48MB,
+ IEEE80211_OFDM_RATE_54MB
+};
+
+u8 mgn_rates_cck[4] = {MGN_1M, MGN_2M, MGN_5_5M, MGN_11M};
+u8 mgn_rates_ofdm[8] = {MGN_6M, MGN_9M, MGN_12M, MGN_18M, MGN_24M, MGN_36M, MGN_48M, MGN_54M};
+u8 mgn_rates_mcs0_7[8] = {MGN_MCS0, MGN_MCS1, MGN_MCS2, MGN_MCS3, MGN_MCS4, MGN_MCS5, MGN_MCS6, MGN_MCS7};
+u8 mgn_rates_mcs8_15[8] = {MGN_MCS8, MGN_MCS9, MGN_MCS10, MGN_MCS11, MGN_MCS12, MGN_MCS13, MGN_MCS14, MGN_MCS15};
+u8 mgn_rates_mcs16_23[8] = {MGN_MCS16, MGN_MCS17, MGN_MCS18, MGN_MCS19, MGN_MCS20, MGN_MCS21, MGN_MCS22, MGN_MCS23};
+u8 mgn_rates_mcs24_31[8] = {MGN_MCS24, MGN_MCS25, MGN_MCS26, MGN_MCS27, MGN_MCS28, MGN_MCS29, MGN_MCS30, MGN_MCS31};
+u8 mgn_rates_vht1ss[10] = {MGN_VHT1SS_MCS0, MGN_VHT1SS_MCS1, MGN_VHT1SS_MCS2, MGN_VHT1SS_MCS3, MGN_VHT1SS_MCS4
+ , MGN_VHT1SS_MCS5, MGN_VHT1SS_MCS6, MGN_VHT1SS_MCS7, MGN_VHT1SS_MCS8, MGN_VHT1SS_MCS9
+ };
+u8 mgn_rates_vht2ss[10] = {MGN_VHT2SS_MCS0, MGN_VHT2SS_MCS1, MGN_VHT2SS_MCS2, MGN_VHT2SS_MCS3, MGN_VHT2SS_MCS4
+ , MGN_VHT2SS_MCS5, MGN_VHT2SS_MCS6, MGN_VHT2SS_MCS7, MGN_VHT2SS_MCS8, MGN_VHT2SS_MCS9
+ };
+u8 mgn_rates_vht3ss[10] = {MGN_VHT3SS_MCS0, MGN_VHT3SS_MCS1, MGN_VHT3SS_MCS2, MGN_VHT3SS_MCS3, MGN_VHT3SS_MCS4
+ , MGN_VHT3SS_MCS5, MGN_VHT3SS_MCS6, MGN_VHT3SS_MCS7, MGN_VHT3SS_MCS8, MGN_VHT3SS_MCS9
+ };
+u8 mgn_rates_vht4ss[10] = {MGN_VHT4SS_MCS0, MGN_VHT4SS_MCS1, MGN_VHT4SS_MCS2, MGN_VHT4SS_MCS3, MGN_VHT4SS_MCS4
+ , MGN_VHT4SS_MCS5, MGN_VHT4SS_MCS6, MGN_VHT4SS_MCS7, MGN_VHT4SS_MCS8, MGN_VHT4SS_MCS9
+ };
+
+static const char *const _rate_section_str[] = {
+ "CCK",
+ "OFDM",
+ "HT_1SS",
+ "HT_2SS",
+ "HT_3SS",
+ "HT_4SS",
+ "VHT_1SS",
+ "VHT_2SS",
+ "VHT_3SS",
+ "VHT_4SS",
+ "RATE_SECTION_UNKNOWN",
+};
+
+const char *rate_section_str(u8 section)
+{
+ section = (section >= RATE_SECTION_NUM) ? RATE_SECTION_NUM : section;
+ return _rate_section_str[section];
+}
+
+struct rate_section_ent rates_by_sections[RATE_SECTION_NUM] = {
+ {RF_1TX, 4, mgn_rates_cck},
+ {RF_1TX, 8, mgn_rates_ofdm},
+ {RF_1TX, 8, mgn_rates_mcs0_7},
+ {RF_2TX, 8, mgn_rates_mcs8_15},
+ {RF_3TX, 8, mgn_rates_mcs16_23},
+ {RF_4TX, 8, mgn_rates_mcs24_31},
+ {RF_1TX, 10, mgn_rates_vht1ss},
+ {RF_2TX, 10, mgn_rates_vht2ss},
+ {RF_3TX, 10, mgn_rates_vht3ss},
+ {RF_4TX, 10, mgn_rates_vht4ss},
+};
+
+int rtw_get_bit_value_from_ieee_value(u8 val)
+{
+ unsigned char dot11_rate_table[] = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 0}; /* last element must be zero!! */
+
+ int i = 0;
+ while (dot11_rate_table[i] != 0) {
+ if (dot11_rate_table[i] == val)
+ return BIT(i);
+ i++;
+ }
+ return 0;
+}
+
+uint rtw_is_cckrates_included(u8 *rate)
+{
+ u32 i = 0;
+
+ while (rate[i] != 0) {
+ if ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
+ (((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22))
+ return true;
+ i++;
+ }
+
+ return false;
+}
+
+uint rtw_is_cckratesonly_included(u8 *rate)
+{
+ u32 i = 0;
+
+
+ while (rate[i] != 0) {
+ if ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
+ (((rate[i]) & 0x7f) != 11) && (((rate[i]) & 0x7f) != 22))
+ return false;
+
+ i++;
+ }
+
+ return true;
+
+}
+
+int rtw_check_network_type(unsigned char *rate, int ratelen, int channel)
+{
+ if (channel > 14) {
+ if ((rtw_is_cckrates_included(rate)))
+ return WIRELESS_INVALID;
+ else
+ return WIRELESS_11A;
+ } else { /* could be pure B, pure G, or B/G */
+ if ((rtw_is_cckratesonly_included(rate)))
+ return WIRELESS_11B;
+ else if ((rtw_is_cckrates_included(rate)))
+ return WIRELESS_11BG;
+ else
+ return WIRELESS_11G;
+ }
+
+}
+
+u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len, unsigned char *source,
+ unsigned int *frlen)
+{
+ memcpy((void *)pbuf, (void *)source, len);
+ *frlen = *frlen + len;
+ return pbuf + len;
+}
+
+/* rtw_set_ie will update frame length */
+u8 *rtw_set_ie
+(
+ u8 *pbuf,
+ sint index,
+ uint len,
+ u8 *source,
+ uint *frlen /* frame length */
+)
+{
+ *pbuf = (u8)index;
+
+ *(pbuf + 1) = (u8)len;
+
+ if (len > 0)
+ memcpy((void *)(pbuf + 2), (void *)source, len);
+
+ *frlen = *frlen + (len + 2);
+
+ return pbuf + len + 2;
+}
+
+inline u8 *rtw_set_ie_ch_switch(u8 *buf, u32 *buf_len, u8 ch_switch_mode,
+ u8 new_ch, u8 ch_switch_cnt)
+{
+ u8 ie_data[3];
+
+ ie_data[0] = ch_switch_mode;
+ ie_data[1] = new_ch;
+ ie_data[2] = ch_switch_cnt;
+ return rtw_set_ie(buf, WLAN_EID_CHANNEL_SWITCH, 3, ie_data, buf_len);
+}
+
+inline u8 secondary_ch_offset_to_hal_ch_offset(u8 ch_offset)
+{
+ if (ch_offset == SCN)
+ return HAL_PRIME_CHNL_OFFSET_DONT_CARE;
+ else if (ch_offset == SCA)
+ return HAL_PRIME_CHNL_OFFSET_UPPER;
+ else if (ch_offset == SCB)
+ return HAL_PRIME_CHNL_OFFSET_LOWER;
+
+ return HAL_PRIME_CHNL_OFFSET_DONT_CARE;
+}
+
+inline u8 hal_ch_offset_to_secondary_ch_offset(u8 ch_offset)
+{
+ if (ch_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE)
+ return SCN;
+ else if (ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
+ return SCB;
+ else if (ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
+ return SCA;
+
+ return SCN;
+}
+
+inline u8 *rtw_set_ie_secondary_ch_offset(u8 *buf, u32 *buf_len, u8 secondary_ch_offset)
+{
+ return rtw_set_ie(buf, WLAN_EID_SECONDARY_CHANNEL_OFFSET, 1, &secondary_ch_offset, buf_len);
+}
+
+inline u8 *rtw_set_ie_mesh_ch_switch_parm(u8 *buf, u32 *buf_len, u8 ttl,
+ u8 flags, u16 reason, u16 precedence)
+{
+ u8 ie_data[6];
+
+ ie_data[0] = ttl;
+ ie_data[1] = flags;
+ RTW_PUT_LE16((u8 *)&ie_data[2], reason);
+ RTW_PUT_LE16((u8 *)&ie_data[4], precedence);
+
+ return rtw_set_ie(buf, 0x118, 6, ie_data, buf_len);
+}
+
+/*----------------------------------------------------------------------------
+index: the information element id index, limit is the limit for search
+-----------------------------------------------------------------------------*/
+u8 *rtw_get_ie(u8 *pbuf, sint index, sint *len, sint limit)
+{
+ sint tmp, i;
+ u8 *p;
+ if (limit < 1) {
+ return NULL;
+ }
+
+ p = pbuf;
+ i = 0;
+ *len = 0;
+ while (1) {
+ if (*p == index) {
+ *len = *(p + 1);
+ return p;
+ } else {
+ tmp = *(p + 1);
+ p += (tmp + 2);
+ i += (tmp + 2);
+ }
+ if (i >= limit)
+ break;
+ }
+ return NULL;
+}
+
+/**
+ * rtw_get_ie_ex - Search specific IE from a series of IEs
+ * @in_ie: Address of IEs to search
+ * @in_len: Length limit from in_ie
+ * @eid: Element ID to match
+ * @oui: OUI to match
+ * @oui_len: OUI length
+ * @ie: If not NULL and the specific IE is found, the IE will be copied to the buf starting from the specific IE
+ * @ielen: If not NULL and the specific IE is found, will set to the length of the entire IE
+ *
+ * Returns: The address of the specific IE found, or NULL
+ */
+u8 *rtw_get_ie_ex(u8 *in_ie, uint in_len, u8 eid, u8 *oui, u8 oui_len, u8 *ie, uint *ielen)
+{
+ uint cnt;
+ u8 *target_ie = NULL;
+
+
+ if (ielen)
+ *ielen = 0;
+
+ if (!in_ie || in_len <= 0)
+ return target_ie;
+
+ cnt = 0;
+
+ while (cnt < in_len) {
+ if (eid == in_ie[cnt]
+ && (!oui || !memcmp(&in_ie[cnt + 2], oui, oui_len))) {
+ target_ie = &in_ie[cnt];
+
+ if (ie)
+ memcpy(ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
+
+ if (ielen)
+ *ielen = in_ie[cnt + 1] + 2;
+
+ break;
+ } else {
+ cnt += in_ie[cnt + 1] + 2; /* goto next */
+ }
+
+ }
+
+ return target_ie;
+}
+
+/**
+ * rtw_ies_remove_ie - Find matching IEs and remove
+ * @ies: Address of IEs to search
+ * @ies_len: Pointer of length of ies, will update to new length
+ * @offset: The offset to start scarch
+ * @eid: Element ID to match
+ * @oui: OUI to match
+ * @oui_len: OUI length
+ *
+ * Returns: _SUCCESS: ies is updated, _FAIL: not updated
+ */
+int rtw_ies_remove_ie(u8 *ies, uint *ies_len, uint offset, u8 eid, u8 *oui, u8 oui_len)
+{
+ int ret = _FAIL;
+ u8 *target_ie;
+ u32 target_ielen;
+ u8 *start;
+ uint search_len;
+
+ if (!ies || !ies_len || *ies_len <= offset)
+ goto exit;
+
+ start = ies + offset;
+ search_len = *ies_len - offset;
+
+ while (1) {
+ target_ie = rtw_get_ie_ex(start, search_len, eid, oui, oui_len, NULL, &target_ielen);
+ if (target_ie && target_ielen) {
+ u8 *remain_ies = target_ie + target_ielen;
+ uint remain_len = search_len - (remain_ies - start);
+
+ memmove(target_ie, remain_ies, remain_len);
+ *ies_len = *ies_len - target_ielen;
+ ret = _SUCCESS;
+
+ start = target_ie;
+ search_len = remain_len;
+ } else
+ break;
+ }
+exit:
+ return ret;
+}
+
+void rtw_set_supported_rate(u8 *SupportedRates, uint mode)
+{
+
+ memset(SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX);
+
+ switch (mode) {
+ case WIRELESS_11B:
+ memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
+ break;
+
+ case WIRELESS_11G:
+ case WIRELESS_11A:
+ case WIRELESS_11_5N:
+ case WIRELESS_11A_5N: /* Todo: no basic rate for ofdm ? */
+ case WIRELESS_11_5AC:
+ memcpy(SupportedRates, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
+ break;
+
+ case WIRELESS_11BG:
+ case WIRELESS_11G_24N:
+ case WIRELESS_11_24N:
+ case WIRELESS_11BG_24N:
+ memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
+ memcpy(SupportedRates + IEEE80211_CCK_RATE_LEN, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
+ break;
+
+ }
+}
+
+uint rtw_get_rateset_len(u8 *rateset)
+{
+ uint i = 0;
+ while (1) {
+ if ((rateset[i]) == 0)
+ break;
+
+ if (i > 12)
+ break;
+
+ i++;
+ }
+ return i;
+}
+
+int rtw_generate_ie(struct registry_priv *pregistrypriv)
+{
+ u8 wireless_mode;
+ int sz = 0, rateLen;
+ WLAN_BSSID_EX *pdev_network = &pregistrypriv->dev_network;
+ u8 *ie = pdev_network->IEs;
+
+
+ /* timestamp will be inserted by hardware */
+ sz += 8;
+ ie += sz;
+
+ /* beacon interval : 2bytes */
+ *(__le16 *)ie = cpu_to_le16((u16)pdev_network->Configuration.BeaconPeriod); /* BCN_INTERVAL; */
+ sz += 2;
+ ie += 2;
+
+ /* capability info */
+ *(__le16 *)ie = 0;
+
+ *(__le16 *)ie |= cpu_to_le16(cap_IBSS);
+
+ if (pregistrypriv->preamble == PREAMBLE_SHORT)
+ *(__le16 *)ie |= cpu_to_le16(cap_ShortPremble);
+
+ if (pdev_network->Privacy)
+ *(__le16 *)ie |= cpu_to_le16(cap_Privacy);
+
+ sz += 2;
+ ie += 2;
+
+ /* SSID */
+ ie = rtw_set_ie(ie, _SSID_IE_, pdev_network->Ssid.SsidLength, pdev_network->Ssid.Ssid, &sz);
+
+ /* supported rates */
+ if (pregistrypriv->wireless_mode == WIRELESS_11ABGN) {
+ if (pdev_network->Configuration.DSConfig > 14)
+ wireless_mode = WIRELESS_11A_5N;
+ else
+ wireless_mode = WIRELESS_11BG_24N;
+ } else if (pregistrypriv->wireless_mode == WIRELESS_MODE_MAX) { /* WIRELESS_11ABGN | WIRELESS_11AC */
+ if (pdev_network->Configuration.DSConfig > 14)
+ wireless_mode = WIRELESS_11_5AC;
+ else
+ wireless_mode = WIRELESS_11BG_24N;
+ } else
+ wireless_mode = pregistrypriv->wireless_mode;
+
+ rtw_set_supported_rate(pdev_network->SupportedRates, wireless_mode) ;
+
+ rateLen = rtw_get_rateset_len(pdev_network->SupportedRates);
+
+ if (rateLen > 8) {
+ ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, 8, pdev_network->SupportedRates, &sz);
+ /* ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz); */
+ } else
+ ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, rateLen, pdev_network->SupportedRates, &sz);
+
+ /* DS parameter set */
+ ie = rtw_set_ie(ie, _DSSET_IE_, 1, (u8 *)&(pdev_network->Configuration.DSConfig), &sz);
+
+
+ /* IBSS Parameter Set */
+
+ ie = rtw_set_ie(ie, _IBSS_PARA_IE_, 2, (u8 *)&(pdev_network->Configuration.ATIMWindow), &sz);
+
+ if (rateLen > 8)
+ ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz);
+
+ /* HT Cap. */
+ if (((pregistrypriv->wireless_mode & WIRELESS_11_5N) || (pregistrypriv->wireless_mode & WIRELESS_11_24N))
+ && (pregistrypriv->ht_enable)) {
+ /* todo: */
+ }
+
+ return sz;
+}
+
+unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit)
+{
+ int len;
+ u16 val16;
+ __le16 leval16;
+ unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01};
+ u8 *pbuf = pie;
+ int limit_new = limit;
+
+ while (1) {
+ pbuf = rtw_get_ie(pbuf, _WPA_IE_ID_, &len, limit_new);
+ if (pbuf) {
+ /* check if oui matches... */
+ if (memcmp((pbuf + 2), wpa_oui_type, sizeof(wpa_oui_type)))
+ goto check_next_ie;
+ /* check version... */
+ memcpy((u8 *)&leval16, (pbuf + 6), sizeof(val16));
+
+ val16 = le16_to_cpu(leval16);
+ if (val16 != 0x0001)
+ goto check_next_ie;
+
+ *wpa_ie_len = *(pbuf + 1);
+
+ return pbuf;
+
+ } else {
+ *wpa_ie_len = 0;
+ return NULL;
+ }
+
+check_next_ie:
+
+ limit_new = limit - (pbuf - pie) - 2 - len;
+
+ if (limit_new <= 0)
+ break;
+
+ pbuf += (2 + len);
+
+ }
+
+ *wpa_ie_len = 0;
+
+ return NULL;
+
+}
+
+unsigned char *rtw_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit)
+{
+
+ return rtw_get_ie(pie, _WPA2_IE_ID_, rsn_ie_len, limit);
+
+}
+
+int rtw_get_wpa_cipher_suite(u8 *s)
+{
+ if (!memcmp(s, WPA_CIPHER_SUITE_NONE, WPA_SELECTOR_LEN))
+ return WPA_CIPHER_NONE;
+ if (!memcmp(s, WPA_CIPHER_SUITE_WEP40, WPA_SELECTOR_LEN))
+ return WPA_CIPHER_WEP40;
+ if (!memcmp(s, WPA_CIPHER_SUITE_TKIP, WPA_SELECTOR_LEN))
+ return WPA_CIPHER_TKIP;
+ if (!memcmp(s, WPA_CIPHER_SUITE_CCMP, WPA_SELECTOR_LEN))
+ return WPA_CIPHER_CCMP;
+ if (!memcmp(s, WPA_CIPHER_SUITE_WEP104, WPA_SELECTOR_LEN))
+ return WPA_CIPHER_WEP104;
+
+ return 0;
+}
+
+int rtw_get_wpa2_cipher_suite(u8 *s)
+{
+ if (!memcmp(s, RSN_CIPHER_SUITE_NONE, RSN_SELECTOR_LEN))
+ return WPA_CIPHER_NONE;
+ if (!memcmp(s, RSN_CIPHER_SUITE_WEP40, RSN_SELECTOR_LEN))
+ return WPA_CIPHER_WEP40;
+ if (!memcmp(s, RSN_CIPHER_SUITE_TKIP, RSN_SELECTOR_LEN))
+ return WPA_CIPHER_TKIP;
+ if (!memcmp(s, RSN_CIPHER_SUITE_CCMP, RSN_SELECTOR_LEN))
+ return WPA_CIPHER_CCMP;
+ if (!memcmp(s, RSN_CIPHER_SUITE_WEP104, RSN_SELECTOR_LEN))
+ return WPA_CIPHER_WEP104;
+
+ return 0;
+}
+
+
+int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
+{
+ int i, ret = _SUCCESS;
+ int left, count;
+ u8 *pos;
+ u8 SUITE_1X[4] = {0x00, 0x50, 0xf2, 1};
+
+ if (wpa_ie_len <= 0) {
+ /* No WPA IE - fail silently */
+ return _FAIL;
+ }
+
+
+ if ((*wpa_ie != _WPA_IE_ID_) || (*(wpa_ie + 1) != (u8)(wpa_ie_len - 2)) ||
+ (memcmp(wpa_ie + 2, RTW_WPA_OUI_TYPE, WPA_SELECTOR_LEN)))
+ return _FAIL;
+
+ pos = wpa_ie;
+
+ pos += 8;
+ left = wpa_ie_len - 8;
+
+
+ /* group_cipher */
+ if (left >= WPA_SELECTOR_LEN) {
+
+ *group_cipher = rtw_get_wpa_cipher_suite(pos);
+
+ pos += WPA_SELECTOR_LEN;
+ left -= WPA_SELECTOR_LEN;
+
+ } else if (left > 0) {
+
+ return _FAIL;
+ }
+
+
+ /* pairwise_cipher */
+ if (left >= 2) {
+ /* count = le16_to_cpu(*(u16*)pos); */
+ count = RTW_GET_LE16(pos);
+ pos += 2;
+ left -= 2;
+
+ if (count == 0 || left < count * WPA_SELECTOR_LEN) {
+ return _FAIL;
+ }
+
+ for (i = 0; i < count; i++) {
+ *pairwise_cipher |= rtw_get_wpa_cipher_suite(pos);
+
+ pos += WPA_SELECTOR_LEN;
+ left -= WPA_SELECTOR_LEN;
+ }
+
+ } else if (left == 1) {
+ return _FAIL;
+ }
+
+ if (is_8021x) {
+ if (left >= 6) {
+ pos += 2;
+ if (!memcmp(pos, SUITE_1X, 4)) {
+ *is_8021x = 1;
+ }
+ }
+ }
+
+ return ret;
+
+}
+
+int rtw_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
+{
+ int i, ret = _SUCCESS;
+ int left, count;
+ u8 *pos;
+ u8 SUITE_1X[4] = {0x00, 0x0f, 0xac, 0x01};
+
+ if (rsn_ie_len <= 0) {
+ /* No RSN IE - fail silently */
+ return _FAIL;
+ }
+
+
+ if ((*rsn_ie != _WPA2_IE_ID_) || (*(rsn_ie + 1) != (u8)(rsn_ie_len - 2)))
+ return _FAIL;
+
+ pos = rsn_ie;
+ pos += 4;
+ left = rsn_ie_len - 4;
+
+ /* group_cipher */
+ if (left >= RSN_SELECTOR_LEN) {
+
+ *group_cipher = rtw_get_wpa2_cipher_suite(pos);
+
+ pos += RSN_SELECTOR_LEN;
+ left -= RSN_SELECTOR_LEN;
+
+ } else if (left > 0) {
+ return _FAIL;
+ }
+
+ /* pairwise_cipher */
+ if (left >= 2) {
+ /* count = le16_to_cpu(*(u16*)pos); */
+ count = RTW_GET_LE16(pos);
+ pos += 2;
+ left -= 2;
+
+ if (count == 0 || left < count * RSN_SELECTOR_LEN) {
+ return _FAIL;
+ }
+
+ for (i = 0; i < count; i++) {
+ *pairwise_cipher |= rtw_get_wpa2_cipher_suite(pos);
+
+ pos += RSN_SELECTOR_LEN;
+ left -= RSN_SELECTOR_LEN;
+ }
+
+ } else if (left == 1) {
+
+ return _FAIL;
+ }
+
+ if (is_8021x) {
+ if (left >= 6) {
+ pos += 2;
+ if (!memcmp(pos, SUITE_1X, 4)) {
+ *is_8021x = 1;
+ }
+ }
+ }
+
+ return ret;
+
+}
+
+/* #ifdef CONFIG_WAPI_SUPPORT */
+int rtw_get_wapi_ie(u8 *in_ie, uint in_len, u8 *wapi_ie, u16 *wapi_len)
+{
+ int len = 0;
+ u8 authmode, i;
+ uint cnt;
+ u8 wapi_oui1[4] = {0x0, 0x14, 0x72, 0x01};
+ u8 wapi_oui2[4] = {0x0, 0x14, 0x72, 0x02};
+
+
+ if (wapi_len)
+ *wapi_len = 0;
+
+ if (!in_ie || in_len <= 0)
+ return len;
+
+ cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_);
+
+ while (cnt < in_len) {
+ authmode = in_ie[cnt];
+
+ /* if(authmode==_WAPI_IE_) */
+ if (authmode == _WAPI_IE_ && (!memcmp(&in_ie[cnt + 6], wapi_oui1, 4) ||
+ !memcmp(&in_ie[cnt + 6], wapi_oui2, 4))) {
+ if (wapi_ie)
+ memcpy(wapi_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
+
+ if (wapi_len)
+ *wapi_len = in_ie[cnt + 1] + 2;
+
+ cnt += in_ie[cnt + 1] + 2; /* get next */
+ } else {
+ cnt += in_ie[cnt + 1] + 2; /* get next */
+ }
+ }
+
+ if (wapi_len)
+ len = *wapi_len;
+
+
+ return len;
+
+}
+/* #endif */
+
+int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len)
+{
+ u8 authmode, sec_idx, i;
+ u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};
+ uint cnt;
+
+
+ /* Search required WPA or WPA2 IE and copy to sec_ie[ ] */
+
+ cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_);
+
+ sec_idx = 0;
+
+ while (cnt < in_len) {
+ authmode = in_ie[cnt];
+
+ if ((authmode == _WPA_IE_ID_) && (!memcmp(&in_ie[cnt + 2], &wpa_oui[0], 4))) {
+
+ if (wpa_ie)
+ memcpy(wpa_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
+
+ *wpa_len = in_ie[cnt + 1] + 2;
+ cnt += in_ie[cnt + 1] + 2; /* get next */
+ } else {
+ if (authmode == _WPA2_IE_ID_) {
+
+ if (rsn_ie)
+ memcpy(rsn_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
+
+ *rsn_len = in_ie[cnt + 1] + 2;
+ cnt += in_ie[cnt + 1] + 2; /* get next */
+ } else {
+ cnt += in_ie[cnt + 1] + 2; /* get next */
+ }
+ }
+
+ }
+
+
+ return *rsn_len + *wpa_len;
+
+}
+
+u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen)
+{
+ u8 match = false;
+ u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
+
+ if (ie_ptr == NULL)
+ return match;
+
+ eid = ie_ptr[0];
+
+ if ((eid == _WPA_IE_ID_) && (!memcmp(&ie_ptr[2], wps_oui, 4))) {
+ /* RTW_INFO("==> found WPS_IE.....\n"); */
+ *wps_ielen = ie_ptr[1] + 2;
+ match = true;
+ }
+ return match;
+}
+
+u8 *rtw_get_wps_ie_from_scan_queue(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen, u8 frame_type)
+{
+ u8 *wps = NULL;
+
+ RTW_INFO("[%s] frame_type = %d\n", __func__, frame_type);
+ switch (frame_type) {
+ case 1:
+ case 3: {
+ /* Beacon or Probe Response */
+ wps = rtw_get_wps_ie(in_ie + _PROBERSP_IE_OFFSET_, in_len - _PROBERSP_IE_OFFSET_, wps_ie, wps_ielen);
+ break;
+ }
+ case 2: {
+ /* Probe Request */
+ wps = rtw_get_wps_ie(in_ie + _PROBEREQ_IE_OFFSET_ , in_len - _PROBEREQ_IE_OFFSET_ , wps_ie, wps_ielen);
+ break;
+ }
+ }
+ return wps;
+}
+
+/**
+ * rtw_get_wps_ie - Search WPS IE from a series of IEs
+ * @in_ie: Address of IEs to search
+ * @in_len: Length limit from in_ie
+ * @wps_ie: If not NULL and WPS IE is found, WPS IE will be copied to the buf starting from wps_ie
+ * @wps_ielen: If not NULL and WPS IE is found, will set to the length of the entire WPS IE
+ *
+ * Returns: The address of the WPS IE found, or NULL
+ */
+u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen)
+{
+ uint cnt;
+ u8 *wpsie_ptr = NULL;
+ u8 eid, wps_oui[4] = {0x00, 0x50, 0xf2, 0x04};
+
+ if (wps_ielen)
+ *wps_ielen = 0;
+
+ if (!in_ie) {
+ rtw_warn_on(1);
+ return wpsie_ptr;
+ }
+
+ if (in_len <= 0)
+ return wpsie_ptr;
+
+ cnt = 0;
+
+ while (cnt + 1 + 4 < in_len) {
+ eid = in_ie[cnt];
+
+ if (cnt + 1 + 4 >= MAX_IE_SZ) {
+ rtw_warn_on(1);
+ return NULL;
+ }
+
+ if (eid == WLAN_EID_VENDOR_SPECIFIC && !memcmp(&in_ie[cnt + 2], wps_oui, 4)) {
+ wpsie_ptr = in_ie + cnt;
+
+ if (wps_ie)
+ memcpy(wps_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
+
+ if (wps_ielen)
+ *wps_ielen = in_ie[cnt + 1] + 2;
+
+ break;
+ } else
+ cnt += in_ie[cnt + 1] + 2;
+
+ }
+
+ return wpsie_ptr;
+}
+
+/**
+ * rtw_get_wps_attr - Search a specific WPS attribute from a given WPS IE
+ * @wps_ie: Address of WPS IE to search
+ * @wps_ielen: Length limit from wps_ie
+ * @target_attr_id: The attribute ID of WPS attribute to search
+ * @buf_attr: If not NULL and the WPS attribute is found, WPS attribute will be copied to the buf starting from buf_attr
+ * @len_attr: If not NULL and the WPS attribute is found, will set to the length of the entire WPS attribute
+ *
+ * Returns: the address of the specific WPS attribute found, or NULL
+ */
+u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id , u8 *buf_attr, u32 *len_attr)
+{
+ u8 *attr_ptr = NULL;
+ u8 *target_attr_ptr = NULL;
+ u8 wps_oui[4] = {0x00, 0x50, 0xF2, 0x04};
+
+ if (len_attr)
+ *len_attr = 0;
+
+ if ((wps_ie[0] != _VENDOR_SPECIFIC_IE_) ||
+ (memcmp(wps_ie + 2, wps_oui , 4)))
+ return attr_ptr;
+
+ /* 6 = 1(Element ID) + 1(Length) + 4(WPS OUI) */
+ attr_ptr = wps_ie + 6; /* goto first attr */
+
+ while (attr_ptr - wps_ie < wps_ielen) {
+ /* 4 = 2(Attribute ID) + 2(Length) */
+ u16 attr_id = RTW_GET_BE16(attr_ptr);
+ u16 attr_data_len = RTW_GET_BE16(attr_ptr + 2);
+ u16 attr_len = attr_data_len + 4;
+
+ /* RTW_INFO("%s attr_ptr:%p, id:%u, length:%u\n", __func__, attr_ptr, attr_id, attr_data_len); */
+ if (attr_id == target_attr_id) {
+ target_attr_ptr = attr_ptr;
+
+ if (buf_attr)
+ memcpy(buf_attr, attr_ptr, attr_len);
+
+ if (len_attr)
+ *len_attr = attr_len;
+
+ break;
+ } else {
+ attr_ptr += attr_len; /* goto next */
+ }
+
+ }
+
+ return target_attr_ptr;
+}
+
+/**
+ * rtw_get_wps_attr_content - Search a specific WPS attribute content from a given WPS IE
+ * @wps_ie: Address of WPS IE to search
+ * @wps_ielen: Length limit from wps_ie
+ * @target_attr_id: The attribute ID of WPS attribute to search
+ * @buf_content: If not NULL and the WPS attribute is found, WPS attribute content will be copied to the buf starting from buf_content
+ * @len_content: If not NULL and the WPS attribute is found, will set to the length of the WPS attribute content
+ *
+ * Returns: the address of the specific WPS attribute content found, or NULL
+ */
+u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id , u8 *buf_content, uint *len_content)
+{
+ u8 *attr_ptr;
+ u32 attr_len;
+
+ if (len_content)
+ *len_content = 0;
+
+ attr_ptr = rtw_get_wps_attr(wps_ie, wps_ielen, target_attr_id, NULL, &attr_len);
+
+ if (attr_ptr && attr_len) {
+ if (buf_content)
+ memcpy(buf_content, attr_ptr + 4, attr_len - 4);
+
+ if (len_content)
+ *len_content = attr_len - 4;
+
+ return attr_ptr + 4;
+ }
+
+ return NULL;
+}
+
+static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen,
+ struct rtw_ieee802_11_elems *elems,
+ int show_errors)
+{
+ unsigned int oui;
+
+ /* first 3 bytes in vendor specific information element are the IEEE
+ * OUI of the vendor. The following byte is used a vendor specific
+ * sub-type. */
+ if (elen < 4) {
+ if (show_errors) {
+ RTW_INFO("short vendor specific "
+ "information element ignored (len=%lu)\n",
+ (unsigned long) elen);
+ }
+ return -1;
+ }
+
+ oui = RTW_GET_BE24(pos);
+ switch (oui) {
+ case OUI_MICROSOFT:
+ /* Microsoft/Wi-Fi information elements are further typed and
+ * subtyped */
+ switch (pos[3]) {
+ case 1:
+ /* Microsoft OUI (00:50:F2) with OUI Type 1:
+ * real WPA information element */
+ elems->wpa_ie = pos;
+ elems->wpa_ie_len = elen;
+ break;
+ case WME_OUI_TYPE: /* this is a Wi-Fi WME info. element */
+ if (elen < 5) {
+ RTW_DBG("short WME "
+ "information element ignored "
+ "(len=%lu)\n",
+ (unsigned long) elen);
+ return -1;
+ }
+ switch (pos[4]) {
+ case WME_OUI_SUBTYPE_INFORMATION_ELEMENT:
+ case WME_OUI_SUBTYPE_PARAMETER_ELEMENT:
+ elems->wme = pos;
+ elems->wme_len = elen;
+ break;
+ case WME_OUI_SUBTYPE_TSPEC_ELEMENT:
+ elems->wme_tspec = pos;
+ elems->wme_tspec_len = elen;
+ break;
+ default:
+ RTW_DBG("unknown WME "
+ "information element ignored "
+ "(subtype=%d len=%lu)\n",
+ pos[4], (unsigned long) elen);
+ return -1;
+ }
+ break;
+ case 4:
+ /* Wi-Fi Protected Setup (WPS) IE */
+ elems->wps_ie = pos;
+ elems->wps_ie_len = elen;
+ break;
+ default:
+ RTW_DBG("Unknown Microsoft "
+ "information element ignored "
+ "(type=%d len=%lu)\n",
+ pos[3], (unsigned long) elen);
+ return -1;
+ }
+ break;
+
+ case OUI_BROADCOM:
+ switch (pos[3]) {
+ case VENDOR_HT_CAPAB_OUI_TYPE:
+ elems->vendor_ht_cap = pos;
+ elems->vendor_ht_cap_len = elen;
+ break;
+ default:
+ RTW_DBG("Unknown Broadcom "
+ "information element ignored "
+ "(type=%d len=%lu)\n",
+ pos[3], (unsigned long) elen);
+ return -1;
+ }
+ break;
+
+ default:
+ RTW_DBG("unknown vendor specific information "
+ "element ignored (vendor OUI %02x:%02x:%02x "
+ "len=%lu)\n",
+ pos[0], pos[1], pos[2], (unsigned long) elen);
+ return -1;
+ }
+
+ return 0;
+
+}
+
+/**
+ * ieee802_11_parse_elems - Parse information elements in management frames
+ * @start: Pointer to the start of IEs
+ * @len: Length of IE buffer in octets
+ * @elems: Data structure for parsed elements
+ * @show_errors: Whether to show parsing errors in debug log
+ * Returns: Parsing result
+ */
+ParseRes rtw_ieee802_11_parse_elems(u8 *start, uint len,
+ struct rtw_ieee802_11_elems *elems,
+ int show_errors)
+{
+ uint left = len;
+ u8 *pos = start;
+ int unknown = 0;
+
+ memset(elems, 0, sizeof(*elems));
+
+ while (left >= 2) {
+ u8 id, elen;
+
+ id = *pos++;
+ elen = *pos++;
+ left -= 2;
+
+ if (elen > left) {
+ if (show_errors) {
+ RTW_INFO("IEEE 802.11 element "
+ "parse failed (id=%d elen=%d "
+ "left=%lu)\n",
+ id, elen, (unsigned long) left);
+ }
+ return ParseFailed;
+ }
+
+ switch (id) {
+ case WLAN_EID_SSID:
+ elems->ssid = pos;
+ elems->ssid_len = elen;
+ break;
+ case WLAN_EID_SUPP_RATES:
+ elems->supp_rates = pos;
+ elems->supp_rates_len = elen;
+ break;
+ case WLAN_EID_FH_PARAMS:
+ elems->fh_params = pos;
+ elems->fh_params_len = elen;
+ break;
+ case WLAN_EID_DS_PARAMS:
+ elems->ds_params = pos;
+ elems->ds_params_len = elen;
+ break;
+ case WLAN_EID_CF_PARAMS:
+ elems->cf_params = pos;
+ elems->cf_params_len = elen;
+ break;
+ case WLAN_EID_TIM:
+ elems->tim = pos;
+ elems->tim_len = elen;
+ break;
+ case WLAN_EID_IBSS_PARAMS:
+ elems->ibss_params = pos;
+ elems->ibss_params_len = elen;
+ break;
+ case WLAN_EID_CHALLENGE:
+ elems->challenge = pos;
+ elems->challenge_len = elen;
+ break;
+ case WLAN_EID_ERP_INFO:
+ elems->erp_info = pos;
+ elems->erp_info_len = elen;
+ break;
+ case WLAN_EID_EXT_SUPP_RATES:
+ elems->ext_supp_rates = pos;
+ elems->ext_supp_rates_len = elen;
+ break;
+ case WLAN_EID_VENDOR_SPECIFIC:
+ if (rtw_ieee802_11_parse_vendor_specific(pos, elen,
+ elems,
+ show_errors))
+ unknown++;
+ break;
+ case WLAN_EID_RSN:
+ elems->rsn_ie = pos;
+ elems->rsn_ie_len = elen;
+ break;
+ case WLAN_EID_PWR_CAPABILITY:
+ elems->power_cap = pos;
+ elems->power_cap_len = elen;
+ break;
+ case WLAN_EID_SUPPORTED_CHANNELS:
+ elems->supp_channels = pos;
+ elems->supp_channels_len = elen;
+ break;
+ case WLAN_EID_MOBILITY_DOMAIN:
+ elems->mdie = pos;
+ elems->mdie_len = elen;
+ break;
+ case WLAN_EID_FAST_BSS_TRANSITION:
+ elems->ftie = pos;
+ elems->ftie_len = elen;
+ break;
+ case WLAN_EID_TIMEOUT_INTERVAL:
+ elems->timeout_int = pos;
+ elems->timeout_int_len = elen;
+ break;
+ case WLAN_EID_HT_CAP:
+ elems->ht_capabilities = pos;
+ elems->ht_capabilities_len = elen;
+ break;
+ case WLAN_EID_HT_OPERATION:
+ elems->ht_operation = pos;
+ elems->ht_operation_len = elen;
+ break;
+ case WLAN_EID_VHT_CAPABILITY:
+ elems->vht_capabilities = pos;
+ elems->vht_capabilities_len = elen;
+ break;
+ case WLAN_EID_VHT_OPERATION:
+ elems->vht_operation = pos;
+ elems->vht_operation_len = elen;
+ break;
+ case WLAN_EID_VHT_OP_MODE_NOTIFY:
+ elems->vht_op_mode_notify = pos;
+ elems->vht_op_mode_notify_len = elen;
+ break;
+ default:
+ unknown++;
+ if (!show_errors)
+ break;
+ RTW_DBG("IEEE 802.11 element parse "
+ "ignored unknown element (id=%d elen=%d)\n",
+ id, elen);
+ break;
+ }
+
+ left -= elen;
+ pos += elen;
+ }
+
+ if (left)
+ return ParseFailed;
+
+ return unknown ? ParseUnknown : ParseOK;
+
+}
+
+static u8 key_char2num(u8 ch);
+static u8 key_char2num(u8 ch)
+{
+ if ((ch >= '0') && (ch <= '9'))
+ return ch - '0';
+ else if ((ch >= 'a') && (ch <= 'f'))
+ return ch - 'a' + 10;
+ else if ((ch >= 'A') && (ch <= 'F'))
+ return ch - 'A' + 10;
+ else
+ return 0xff;
+}
+
+u8 str_2char2num(u8 hch, u8 lch);
+u8 str_2char2num(u8 hch, u8 lch)
+{
+ return (key_char2num(hch) * 10) + key_char2num(lch);
+}
+
+u8 key_2char2num(u8 hch, u8 lch);
+u8 key_2char2num(u8 hch, u8 lch)
+{
+ return (key_char2num(hch) << 4) | key_char2num(lch);
+}
+
+void macstr2num(u8 *dst, u8 *src);
+void macstr2num(u8 *dst, u8 *src)
+{
+ int jj, kk;
+ for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
+ dst[jj] = key_2char2num(src[kk], src[kk + 1]);
+}
+
+u8 convert_ip_addr(u8 hch, u8 mch, u8 lch)
+{
+ return (key_char2num(hch) * 100) + (key_char2num(mch) * 10) + key_char2num(lch);
+}
+
+#ifdef CONFIG_PLATFORM_INTEL_BYT
+#define MAC_ADDRESS_LEN 12
+
+int rtw_get_mac_addr_intel(unsigned char *buf)
+{
+ int ret = 0;
+ int i;
+ struct file *fp = NULL;
+ mm_segment_t oldfs;
+ unsigned char c_mac[MAC_ADDRESS_LEN];
+ char fname[] = "/config/wifi/mac.txt";
+ int jj, kk;
+
+ RTW_INFO("%s Enter\n", __func__);
+
+ ret = rtw_retrieve_from_file(fname, c_mac, MAC_ADDRESS_LEN);
+ if (ret < MAC_ADDRESS_LEN)
+ return -1;
+
+ for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 2)
+ buf[jj] = key_2char2num(c_mac[kk], c_mac[kk + 1]);
+
+ RTW_INFO("%s: read from file mac address: "MAC_FMT"\n",
+ __func__, MAC_ARG(buf));
+
+ return 0;
+}
+#endif /* CONFIG_PLATFORM_INTEL_BYT */
+
+/*
+ * Description:
+ * rtw_check_invalid_mac_address:
+ * This is only used for checking mac address valid or not.
+ *
+ * Input:
+ * adapter: mac_address pointer.
+ * check_local_bit: check locally bit or not.
+ *
+ * Output:
+ * true: The mac address is invalid.
+ * false: The mac address is valid.
+ *
+ * Auther: Isaac.Li
+ */
+u8 rtw_check_invalid_mac_address(u8 *mac_addr, u8 check_local_bit)
+{
+ u8 null_mac_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
+ u8 multi_mac_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+ u8 res = false;
+
+ if (!memcmp(mac_addr, null_mac_addr, ETH_ALEN)) {
+ res = true;
+ goto func_exit;
+ }
+
+ if (!memcmp(mac_addr, multi_mac_addr, ETH_ALEN)) {
+ res = true;
+ goto func_exit;
+ }
+
+ if (mac_addr[0] & BIT0) {
+ res = true;
+ goto func_exit;
+ }
+
+ if (check_local_bit) {
+ if (mac_addr[0] & BIT1) {
+ res = true;
+ goto func_exit;
+ }
+ }
+
+func_exit:
+ return res;
+}
+
+/**
+ * rtw_macaddr_cfg - Decide the mac address used
+ * @out: buf to store mac address decided
+ * @hw_mac_addr: mac address from efuse/epprom
+ */
+void rtw_macaddr_cfg(u8 *out, const u8 *hw_mac_addr)
+{
+#define DEFAULT_RANDOM_MACADDR 1
+ u8 mac[ETH_ALEN];
+
+ if (out == NULL) {
+ rtw_warn_on(1);
+ return;
+ }
+
+ /* Users specify the mac address */
+ if (rtw_initmac) {
+ int jj, kk;
+
+ for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
+ mac[jj] = key_2char2num(rtw_initmac[kk], rtw_initmac[kk + 1]);
+
+ goto err_chk;
+ }
+
+ /* platform specified */
+#ifdef CONFIG_PLATFORM_INTEL_BYT
+ if (rtw_get_mac_addr_intel(mac) == 0)
+ goto err_chk;
+#endif
+
+ /* Use the mac address stored in the Efuse */
+ if (hw_mac_addr) {
+ memcpy(mac, hw_mac_addr, ETH_ALEN);
+ goto err_chk;
+ }
+
+err_chk:
+ if (rtw_check_invalid_mac_address(mac, true)) {
+#if DEFAULT_RANDOM_MACADDR
+ RTW_ERR("invalid mac addr:"MAC_FMT", assign random MAC\n", MAC_ARG(mac));
+ *((u32 *)(&mac[2])) = rtw_random32();
+ mac[0] = 0x00;
+ mac[1] = 0xe0;
+ mac[2] = 0x4c;
+#else
+ RTW_ERR("invalid mac addr:"MAC_FMT", assign default one\n", MAC_ARG(mac));
+ mac[0] = 0x00;
+ mac[1] = 0xe0;
+ mac[2] = 0x4c;
+ mac[3] = 0x87;
+ mac[4] = 0x00;
+ mac[5] = 0x00;
+#endif
+ }
+
+ memcpy(out, mac, ETH_ALEN);
+ RTW_INFO("%s mac addr:"MAC_FMT"\n", __func__, MAC_ARG(out));
+}
+
+void dump_ht_cap_ie_content(void *sel, u8 *buf, u32 buf_len)
+{
+ if (buf_len != 26) {
+ RTW_PRINT_SEL(sel, "Invalid HT capability IE len:%d != %d\n", buf_len, 26);
+ return;
+ }
+
+ RTW_PRINT_SEL(sel, "HT Capabilities Info:%02x%02x\n", *(buf), *(buf + 1));
+ RTW_PRINT_SEL(sel, "A-MPDU Parameters:"HT_AMPDU_PARA_FMT"\n"
+ , HT_AMPDU_PARA_ARG(HT_CAP_ELE_AMPDU_PARA(buf)));
+ RTW_PRINT_SEL(sel, "Supported MCS Set:"HT_SUP_MCS_SET_FMT"\n"
+ , HT_SUP_MCS_SET_ARG(HT_CAP_ELE_SUP_MCS_SET(buf)));
+}
+
+static void dump_ht_cap_ie(void *sel, u8 *ie, u32 ie_len)
+{
+ u8 *pos = (u8 *)ie;
+ u16 id;
+ u16 len;
+
+ u8 *ht_cap_ie;
+ sint ht_cap_ielen;
+
+ ht_cap_ie = rtw_get_ie(ie, _HT_CAPABILITY_IE_, &ht_cap_ielen, ie_len);
+ if (!ie || ht_cap_ie != ie)
+ return;
+
+ dump_ht_cap_ie_content(sel, ht_cap_ie + 2, ht_cap_ielen);
+}
+
+void dump_ies(void *sel, u8 *buf, u32 buf_len)
+{
+ u8 *pos = (u8 *)buf;
+ u8 id, len;
+
+ while (pos - buf + 1 < buf_len) {
+ id = *pos;
+ len = *(pos + 1);
+
+ RTW_PRINT_SEL(sel, "%s ID:%u, LEN:%u\n", __func__, id, len);
+ dump_ht_cap_ie(sel, pos, len + 2);
+ dump_wps_ie(sel, pos, len + 2);
+#ifdef CONFIG_P2P
+ dump_p2p_ie(sel, pos, len + 2);
+#ifdef CONFIG_WFD
+ dump_wfd_ie(sel, pos, len + 2);
+#endif
+#endif
+
+ pos += (2 + len);
+ }
+}
+
+void dump_wps_ie(void *sel, u8 *ie, u32 ie_len)
+{
+ u8 *pos = (u8 *)ie;
+ u16 id;
+ u16 len;
+
+ u8 *wps_ie;
+ uint wps_ielen;
+
+ wps_ie = rtw_get_wps_ie(ie, ie_len, NULL, &wps_ielen);
+ if (wps_ie != ie || wps_ielen == 0)
+ return;
+
+ pos += 6;
+ while (pos - ie + 4 <= ie_len) {
+ id = RTW_GET_BE16(pos);
+ len = RTW_GET_BE16(pos + 2);
+
+ RTW_PRINT_SEL(sel, "%s ID:0x%04x, LEN:%u%s\n", __func__, id, len
+ , ((pos - ie + 4 + len) <= ie_len) ? "" : "(exceed ie_len)");
+
+ pos += (4 + len);
+ }
+}
+
+/**
+ * rtw_ies_get_chbw - get operation ch, bw, offset from IEs of BSS.
+ * @ies: pointer of the first tlv IE
+ * @ies_len: length of @ies
+ * @ch: pointer of ch, used as output
+ * @bw: pointer of bw, used as output
+ * @offset: pointer of offset, used as output
+ */
+void rtw_ies_get_chbw(u8 *ies, int ies_len, u8 *ch, u8 *bw, u8 *offset)
+{
+ u8 *p;
+ int ie_len;
+
+ *ch = 0;
+ *bw = CHANNEL_WIDTH_20;
+ *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
+
+ p = rtw_get_ie(ies, _DSSET_IE_, &ie_len, ies_len);
+ if (p && ie_len > 0)
+ *ch = *(p + 2);
+
+ {
+ u8 *ht_cap_ie, *ht_op_ie;
+ int ht_cap_ielen, ht_op_ielen;
+
+ ht_cap_ie = rtw_get_ie(ies, EID_HTCapability, &ht_cap_ielen, ies_len);
+ if (ht_cap_ie && ht_cap_ielen) {
+ if (GET_HT_CAP_ELE_CHL_WIDTH(ht_cap_ie + 2))
+ *bw = CHANNEL_WIDTH_40;
+ }
+
+ ht_op_ie = rtw_get_ie(ies, EID_HTInfo, &ht_op_ielen, ies_len);
+ if (ht_op_ie && ht_op_ielen) {
+ if (*ch == 0)
+ *ch = GET_HT_OP_ELE_PRI_CHL(ht_op_ie + 2);
+ else if (*ch != 0 && *ch != GET_HT_OP_ELE_PRI_CHL(ht_op_ie + 2)) {
+ RTW_INFO("%s ch inconsistent, DSSS:%u, HT primary:%u\n"
+ , __func__, *ch, GET_HT_OP_ELE_PRI_CHL(ht_op_ie + 2));
+ }
+
+ if (!GET_HT_OP_ELE_STA_CHL_WIDTH(ht_op_ie + 2))
+ *bw = CHANNEL_WIDTH_20;
+
+ if (*bw == CHANNEL_WIDTH_40) {
+ switch (GET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2)) {
+ case SCA:
+ *offset = HAL_PRIME_CHNL_OFFSET_LOWER;
+ break;
+ case SCB:
+ *offset = HAL_PRIME_CHNL_OFFSET_UPPER;
+ break;
+ }
+ }
+ }
+ }
+}
+
+void rtw_bss_get_chbw(WLAN_BSSID_EX *bss, u8 *ch, u8 *bw, u8 *offset)
+{
+ rtw_ies_get_chbw(bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)
+ , bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)
+ , ch, bw, offset);
+
+ if (*ch == 0)
+ *ch = bss->Configuration.DSConfig;
+ else if (*ch != bss->Configuration.DSConfig) {
+ RTW_INFO("inconsistent ch - ies:%u bss->Configuration.DSConfig:%u\n"
+ , *ch, bss->Configuration.DSConfig);
+ *ch = bss->Configuration.DSConfig;
+ rtw_warn_on(1);
+ }
+}
+
+/**
+ * rtw_is_chbw_grouped - test if the two ch settings can be grouped together
+ * @ch_a: ch of set a
+ * @bw_a: bw of set a
+ * @offset_a: offset of set a
+ * @ch_b: ch of set b
+ * @bw_b: bw of set b
+ * @offset_b: offset of set b
+ */
+bool rtw_is_chbw_grouped(u8 ch_a, u8 bw_a, u8 offset_a
+ , u8 ch_b, u8 bw_b, u8 offset_b)
+{
+ bool is_grouped = false;
+
+ if (ch_a != ch_b) {
+ /* ch is different */
+ goto exit;
+ } else if ((bw_a == CHANNEL_WIDTH_40 || bw_a == CHANNEL_WIDTH_80)
+ && (bw_b == CHANNEL_WIDTH_40 || bw_b == CHANNEL_WIDTH_80)
+ ) {
+ if (offset_a != offset_b)
+ goto exit;
+ }
+
+ is_grouped = true;
+
+exit:
+ return is_grouped;
+}
+
+/**
+ * rtw_sync_chbw - obey g_ch, adjust g_bw, g_offset, bw, offset
+ * @req_ch: pointer of the request ch, may be modified further
+ * @req_bw: pointer of the request bw, may be modified further
+ * @req_offset: pointer of the request offset, may be modified further
+ * @g_ch: pointer of the ongoing group ch
+ * @g_bw: pointer of the ongoing group bw, may be modified further
+ * @g_offset: pointer of the ongoing group offset, may be modified further
+ */
+void rtw_sync_chbw(u8 *req_ch, u8 *req_bw, u8 *req_offset
+ , u8 *g_ch, u8 *g_bw, u8 *g_offset)
+{
+
+ *req_ch = *g_ch;
+
+ if (*req_bw == CHANNEL_WIDTH_80 && *g_ch <= 14) {
+ /*2.4G ch, downgrade to 40Mhz */
+ *req_bw = CHANNEL_WIDTH_40;
+ }
+
+ switch (*req_bw) {
+ case CHANNEL_WIDTH_80:
+ if (*g_bw == CHANNEL_WIDTH_40 || *g_bw == CHANNEL_WIDTH_80)
+ *req_offset = *g_offset;
+ else if (*g_bw == CHANNEL_WIDTH_20)
+ *req_offset = rtw_get_offset_by_ch(*req_ch);
+
+ if (*req_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE) {
+ RTW_ERR("%s req 80MHz BW without offset, down to 20MHz\n", __func__);
+ rtw_warn_on(1);
+ *req_bw = CHANNEL_WIDTH_20;
+ }
+ break;
+ case CHANNEL_WIDTH_40:
+ if (*g_bw == CHANNEL_WIDTH_40 || *g_bw == CHANNEL_WIDTH_80)
+ *req_offset = *g_offset;
+ else if (*g_bw == CHANNEL_WIDTH_20)
+ *req_offset = rtw_get_offset_by_ch(*req_ch);
+
+ if (*req_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE) {
+ RTW_ERR("%s req 40MHz BW without offset, down to 20MHz\n", __func__);
+ rtw_warn_on(1);
+ *req_bw = CHANNEL_WIDTH_20;
+ }
+ break;
+ case CHANNEL_WIDTH_20:
+ *req_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
+ break;
+ default:
+ RTW_ERR("%s req unsupported BW:%u\n", __func__, *req_bw);
+ rtw_warn_on(1);
+ }
+
+ if (*req_bw > *g_bw) {
+ *g_bw = *req_bw;
+ *g_offset = *req_offset;
+ }
+}
+
+/**
+ * rtw_get_p2p_merged_len - Get merged ie length from muitiple p2p ies.
+ * @in_ie: Pointer of the first p2p ie
+ * @in_len: Total len of muiltiple p2p ies
+ * Returns: Length of merged p2p ie length
+ */
+u32 rtw_get_p2p_merged_ies_len(u8 *in_ie, u32 in_len)
+{
+ PNDIS_802_11_VARIABLE_IEs pIE;
+ u8 OUI[4] = { 0x50, 0x6f, 0x9a, 0x09 };
+ int i = 0;
+ int j = 0, len = 0;
+
+ while (i < in_len) {
+ pIE = (PNDIS_802_11_VARIABLE_IEs)(in_ie + i);
+
+ if (pIE->ElementID == _VENDOR_SPECIFIC_IE_ && !memcmp(pIE->data, OUI, 4)) {
+ len += pIE->Length - 4; /* 4 is P2P OUI length, don't count it in this loop */
+ }
+
+ i += (pIE->Length + 2);
+ }
+
+ return len + 4; /* Append P2P OUI length at last. */
+}
+
+/**
+ * rtw_p2p_merge_ies - Merge muitiple p2p ies into one
+ * @in_ie: Pointer of the first p2p ie
+ * @in_len: Total len of muiltiple p2p ies
+ * @merge_ie: Pointer of merged ie
+ * Returns: Length of merged p2p ie
+ */
+int rtw_p2p_merge_ies(u8 *in_ie, u32 in_len, u8 *merge_ie)
+{
+ PNDIS_802_11_VARIABLE_IEs pIE;
+ u8 len = 0;
+ u8 OUI[4] = { 0x50, 0x6f, 0x9a, 0x09 };
+ u8 ELOUI[6] = { 0xDD, 0x00, 0x50, 0x6f, 0x9a, 0x09 }; /* EID;Len;OUI, Len would copy at the end of function */
+ int i = 0;
+
+ if (merge_ie != NULL) {
+ /* Set first P2P OUI */
+ memcpy(merge_ie, ELOUI, 6);
+ merge_ie += 6;
+
+ while (i < in_len) {
+ pIE = (PNDIS_802_11_VARIABLE_IEs)(in_ie + i);
+
+ /* Take out the rest of P2P OUIs */
+ if (pIE->ElementID == _VENDOR_SPECIFIC_IE_ && !memcmp(pIE->data, OUI, 4)) {
+ memcpy(merge_ie, pIE->data + 4, pIE->Length - 4);
+ len += pIE->Length - 4;
+ merge_ie += pIE->Length - 4;
+ }
+
+ i += (pIE->Length + 2);
+ }
+
+ return len + 4; /* 4 is for P2P OUI */
+
+ }
+
+ return 0;
+}
+
+void dump_p2p_ie(void *sel, u8 *ie, u32 ie_len)
+{
+ u8 *pos = (u8 *)ie;
+ u8 id;
+ u16 len;
+
+ u8 *p2p_ie;
+ uint p2p_ielen;
+
+ p2p_ie = rtw_get_p2p_ie(ie, ie_len, NULL, &p2p_ielen);
+ if (p2p_ie != ie || p2p_ielen == 0)
+ return;
+
+ pos += 6;
+ while (pos - ie + 3 <= ie_len) {
+ id = *pos;
+ len = RTW_GET_LE16(pos + 1);
+
+ RTW_PRINT_SEL(sel, "%s ID:%u, LEN:%u%s\n", __func__, id, len
+ , ((pos - ie + 3 + len) <= ie_len) ? "" : "(exceed ie_len)");
+
+ pos += (3 + len);
+ }
+}
+
+/**
+ * rtw_get_p2p_ie - Search P2P IE from a series of IEs
+ * @in_ie: Address of IEs to search
+ * @in_len: Length limit from in_ie
+ * @p2p_ie: If not NULL and P2P IE is found, P2P IE will be copied to the buf starting from p2p_ie
+ * @p2p_ielen: If not NULL and P2P IE is found, will set to the length of the entire P2P IE
+ *
+ * Returns: The address of the P2P IE found, or NULL
+ */
+u8 *rtw_get_p2p_ie(u8 *in_ie, int in_len, u8 *p2p_ie, uint *p2p_ielen)
+{
+ uint cnt;
+ u8 *p2p_ie_ptr = NULL;
+ u8 eid, p2p_oui[4] = {0x50, 0x6F, 0x9A, 0x09};
+
+ if (p2p_ielen)
+ *p2p_ielen = 0;
+
+ if (!in_ie || in_len < 0) {
+ rtw_warn_on(1);
+ return p2p_ie_ptr;
+ }
+
+ if (in_len <= 0)
+ return p2p_ie_ptr;
+
+ cnt = 0;
+
+ while (cnt + 1 + 4 < in_len) {
+ eid = in_ie[cnt];
+
+ if (cnt + 1 + 4 >= MAX_IE_SZ) {
+ rtw_warn_on(1);
+ return NULL;
+ }
+
+ if (eid == WLAN_EID_VENDOR_SPECIFIC && !memcmp(&in_ie[cnt + 2], p2p_oui, 4)) {
+ p2p_ie_ptr = in_ie + cnt;
+
+ if (p2p_ie)
+ memcpy(p2p_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
+
+ if (p2p_ielen)
+ *p2p_ielen = in_ie[cnt + 1] + 2;
+
+ break;
+ } else
+ cnt += in_ie[cnt + 1] + 2;
+
+ }
+
+ return p2p_ie_ptr;
+}
+
+/**
+ * rtw_get_p2p_attr - Search a specific P2P attribute from a given P2P IE
+ * @p2p_ie: Address of P2P IE to search
+ * @p2p_ielen: Length limit from p2p_ie
+ * @target_attr_id: The attribute ID of P2P attribute to search
+ * @buf_attr: If not NULL and the P2P attribute is found, P2P attribute will be copied to the buf starting from buf_attr
+ * @len_attr: If not NULL and the P2P attribute is found, will set to the length of the entire P2P attribute
+ *
+ * Returns: the address of the specific WPS attribute found, or NULL
+ */
+u8 *rtw_get_p2p_attr(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id , u8 *buf_attr, u32 *len_attr)
+{
+ u8 *attr_ptr = NULL;
+ u8 *target_attr_ptr = NULL;
+ u8 p2p_oui[4] = {0x50, 0x6F, 0x9A, 0x09};
+
+ if (len_attr)
+ *len_attr = 0;
+
+ if (!p2p_ie
+ || p2p_ielen <= 6
+ || (p2p_ie[0] != WLAN_EID_VENDOR_SPECIFIC)
+ || (memcmp(p2p_ie + 2, p2p_oui, 4)))
+ return attr_ptr;
+
+ /* 6 = 1(Element ID) + 1(Length) + 3 (OUI) + 1(OUI Type) */
+ attr_ptr = p2p_ie + 6; /* goto first attr */
+
+ while ((attr_ptr - p2p_ie + 3) <= p2p_ielen) {
+ /* 3 = 1(Attribute ID) + 2(Length) */
+ u8 attr_id = *attr_ptr;
+ u16 attr_data_len = RTW_GET_LE16(attr_ptr + 1);
+ u16 attr_len = attr_data_len + 3;
+
+ if (0)
+ RTW_INFO("%s attr_ptr:%p, id:%u, length:%u\n", __func__, attr_ptr, attr_id, attr_data_len);
+
+ if ((attr_ptr - p2p_ie + attr_len) > p2p_ielen)
+ break;
+
+ if (attr_id == target_attr_id) {
+ target_attr_ptr = attr_ptr;
+
+ if (buf_attr)
+ memcpy(buf_attr, attr_ptr, attr_len);
+
+ if (len_attr)
+ *len_attr = attr_len;
+
+ break;
+ } else
+ attr_ptr += attr_len;
+ }
+
+ return target_attr_ptr;
+}
+
+/**
+ * rtw_get_p2p_attr_content - Search a specific P2P attribute content from a given P2P IE
+ * @p2p_ie: Address of P2P IE to search
+ * @p2p_ielen: Length limit from p2p_ie
+ * @target_attr_id: The attribute ID of P2P attribute to search
+ * @buf_content: If not NULL and the P2P attribute is found, P2P attribute content will be copied to the buf starting from buf_content
+ * @len_content: If not NULL and the P2P attribute is found, will set to the length of the P2P attribute content
+ *
+ * Returns: the address of the specific P2P attribute content found, or NULL
+ */
+u8 *rtw_get_p2p_attr_content(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id , u8 *buf_content, uint *len_content)
+{
+ u8 *attr_ptr;
+ u32 attr_len;
+
+ if (len_content)
+ *len_content = 0;
+
+ attr_ptr = rtw_get_p2p_attr(p2p_ie, p2p_ielen, target_attr_id, NULL, &attr_len);
+
+ if (attr_ptr && attr_len) {
+ if (buf_content)
+ memcpy(buf_content, attr_ptr + 3, attr_len - 3);
+
+ if (len_content)
+ *len_content = attr_len - 3;
+
+ return attr_ptr + 3;
+ }
+
+ return NULL;
+}
+
+u32 rtw_set_p2p_attr_content(u8 *pbuf, u8 attr_id, u16 attr_len, u8 *pdata_attr)
+{
+ u32 a_len;
+
+ *pbuf = attr_id;
+
+ /* *(u16*)(pbuf + 1) = cpu_to_le16(attr_len); */
+ RTW_PUT_LE16(pbuf + 1, attr_len);
+
+ if (pdata_attr)
+ memcpy(pbuf + 3, pdata_attr, attr_len);
+
+ a_len = attr_len + 3;
+
+ return a_len;
+}
+
+uint rtw_del_p2p_ie(u8 *ies, uint ies_len_ori, const char *msg)
+{
+#define DBG_DEL_P2P_IE 0
+
+ u8 *target_ie;
+ u32 target_ie_len;
+ uint ies_len = ies_len_ori;
+ int index = 0;
+
+ while (1) {
+ target_ie = rtw_get_p2p_ie(ies, ies_len, NULL, &target_ie_len);
+ if (target_ie && target_ie_len) {
+ u8 *next_ie = target_ie + target_ie_len;
+ uint remain_len = ies_len - (next_ie - ies);
+
+ if (DBG_DEL_P2P_IE && msg) {
+ RTW_INFO("%s %d before\n", __func__, index);
+ dump_ies(RTW_DBGDUMP, ies, ies_len);
+
+ RTW_INFO("ies:%p, ies_len:%u\n", ies, ies_len);
+ RTW_INFO("target_ie:%p, target_ie_len:%u\n", target_ie, target_ie_len);
+ RTW_INFO("next_ie:%p, remain_len:%u\n", next_ie, remain_len);
+ }
+
+ memmove(target_ie, next_ie, remain_len);
+ memset(target_ie + remain_len, 0, target_ie_len);
+ ies_len -= target_ie_len;
+
+ if (DBG_DEL_P2P_IE && msg) {
+ RTW_INFO("%s %d after\n", __func__, index);
+ dump_ies(RTW_DBGDUMP, ies, ies_len);
+ }
+
+ index++;
+ } else
+ break;
+ }
+
+ return ies_len;
+}
+
+uint rtw_del_p2p_attr(u8 *ie, uint ielen_ori, u8 attr_id)
+{
+#define DBG_DEL_P2P_ATTR 0
+
+ u8 *target_attr;
+ u32 target_attr_len;
+ uint ielen = ielen_ori;
+ int index = 0;
+
+ while (1) {
+ target_attr = rtw_get_p2p_attr(ie, ielen, attr_id, NULL, &target_attr_len);
+ if (target_attr && target_attr_len) {
+ u8 *next_attr = target_attr + target_attr_len;
+ uint remain_len = ielen - (next_attr - ie);
+
+ if (DBG_DEL_P2P_ATTR) {
+ RTW_INFO("%s %d before\n", __func__, index);
+ dump_ies(RTW_DBGDUMP, ie, ielen);
+
+ RTW_INFO("ie:%p, ielen:%u\n", ie, ielen);
+ RTW_INFO("target_attr:%p, target_attr_len:%u\n", target_attr, target_attr_len);
+ RTW_INFO("next_attr:%p, remain_len:%u\n", next_attr, remain_len);
+ }
+
+ memmove(target_attr, next_attr, remain_len);
+ memset(target_attr + remain_len, 0, target_attr_len);
+ *(ie + 1) -= target_attr_len;
+ ielen -= target_attr_len;
+
+ if (DBG_DEL_P2P_ATTR) {
+ RTW_INFO("%s %d after\n", __func__, index);
+ dump_ies(RTW_DBGDUMP, ie, ielen);
+ }
+
+ index++;
+ } else
+ break;
+ }
+
+ return ielen;
+}
+
+inline u8 *rtw_bss_ex_get_p2p_ie(WLAN_BSSID_EX *bss_ex, u8 *p2p_ie, uint *p2p_ielen)
+{
+ return rtw_get_p2p_ie(BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex), p2p_ie, p2p_ielen);
+}
+
+void rtw_bss_ex_del_p2p_ie(WLAN_BSSID_EX *bss_ex)
+{
+#define DBG_BSS_EX_DEL_P2P_IE 0
+
+ u8 *ies = BSS_EX_TLV_IES(bss_ex);
+ uint ies_len_ori = BSS_EX_TLV_IES_LEN(bss_ex);
+ uint ies_len;
+
+ ies_len = rtw_del_p2p_ie(ies, ies_len_ori, DBG_BSS_EX_DEL_P2P_IE ? __func__ : NULL);
+ bss_ex->IELength -= ies_len_ori - ies_len;
+}
+
+void rtw_bss_ex_del_p2p_attr(WLAN_BSSID_EX *bss_ex, u8 attr_id)
+{
+#define DBG_BSS_EX_DEL_P2P_ATTR 0
+
+ u8 *ies = BSS_EX_TLV_IES(bss_ex);
+ uint ies_len = BSS_EX_TLV_IES_LEN(bss_ex);
+
+ u8 *ie;
+ uint ie_len, ie_len_ori;
+
+ int index = 0;
+
+ while (1) {
+ ie = rtw_get_p2p_ie(ies, ies_len, NULL, &ie_len_ori);
+ if (ie) {
+ u8 *next_ie_ori = ie + ie_len_ori;
+ uint remain_len = bss_ex->IELength - (next_ie_ori - bss_ex->IEs);
+ u8 has_target_attr = 0;
+
+ if (DBG_BSS_EX_DEL_P2P_ATTR) {
+ if (rtw_get_p2p_attr(ie, ie_len_ori, attr_id, NULL, NULL)) {
+ RTW_INFO("%s %d before\n", __func__, index);
+ dump_ies(RTW_DBGDUMP, BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex));
+
+ RTW_INFO("ies:%p, ies_len:%u\n", ies, ies_len);
+ RTW_INFO("ie:%p, ie_len_ori:%u\n", ie, ie_len_ori);
+ RTW_INFO("next_ie_ori:%p, remain_len:%u\n", next_ie_ori, remain_len);
+ has_target_attr = 1;
+ }
+ }
+
+ ie_len = rtw_del_p2p_attr(ie, ie_len_ori, attr_id);
+ if (ie_len != ie_len_ori) {
+ u8 *next_ie = ie + ie_len;
+
+ memmove(next_ie, next_ie_ori, remain_len);
+ memset(next_ie + remain_len, 0, ie_len_ori - ie_len);
+ bss_ex->IELength -= ie_len_ori - ie_len;
+
+ ies = next_ie;
+ } else
+ ies = next_ie_ori;
+
+ if (DBG_BSS_EX_DEL_P2P_ATTR) {
+ if (has_target_attr) {
+ RTW_INFO("%s %d after\n", __func__, index);
+ dump_ies(RTW_DBGDUMP, BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex));
+ }
+ }
+
+ ies_len = remain_len;
+
+ index++;
+ } else
+ break;
+ }
+}
+
+void dump_wfd_ie(void *sel, u8 *ie, u32 ie_len)
+{
+ u8 *pos = (u8 *)ie;
+ u8 id;
+ u16 len;
+
+ u8 *wfd_ie;
+ uint wfd_ielen;
+
+ wfd_ie = rtw_get_wfd_ie(ie, ie_len, NULL, &wfd_ielen);
+ if (wfd_ie != ie || wfd_ielen == 0)
+ return;
+
+ pos += 6;
+ while (pos - ie + 3 <= ie_len) {
+ id = *pos;
+ len = RTW_GET_BE16(pos + 1);
+
+ RTW_PRINT_SEL(sel, "%s ID:%u, LEN:%u%s\n", __func__, id, len
+ , ((pos - ie + 3 + len) <= ie_len) ? "" : "(exceed ie_len)");
+
+ pos += (3 + len);
+ }
+}
+
+/**
+ * rtw_get_wfd_ie - Search WFD IE from a series of IEs
+ * @in_ie: Address of IEs to search
+ * @in_len: Length limit from in_ie
+ * @wfd_ie: If not NULL and WFD IE is found, WFD IE will be copied to the buf starting from wfd_ie
+ * @wfd_ielen: If not NULL and WFD IE is found, will set to the length of the entire WFD IE
+ *
+ * Returns: The address of the P2P IE found, or NULL
+ */
+u8 *rtw_get_wfd_ie(u8 *in_ie, int in_len, u8 *wfd_ie, uint *wfd_ielen)
+{
+ uint cnt;
+ u8 *wfd_ie_ptr = NULL;
+ u8 eid, wfd_oui[4] = {0x50, 0x6F, 0x9A, 0x0A};
+
+ if (wfd_ielen)
+ *wfd_ielen = 0;
+
+ if (!in_ie || in_len < 0) {
+ rtw_warn_on(1);
+ return wfd_ie_ptr;
+ }
+
+ if (in_len <= 0)
+ return wfd_ie_ptr;
+
+ cnt = 0;
+
+ while (cnt + 1 + 4 < in_len) {
+ eid = in_ie[cnt];
+
+ if (cnt + 1 + 4 >= MAX_IE_SZ) {
+ rtw_warn_on(1);
+ return NULL;
+ }
+
+ if (eid == WLAN_EID_VENDOR_SPECIFIC && !memcmp(&in_ie[cnt + 2], wfd_oui, 4)) {
+ wfd_ie_ptr = in_ie + cnt;
+
+ if (wfd_ie)
+ memcpy(wfd_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
+
+ if (wfd_ielen)
+ *wfd_ielen = in_ie[cnt + 1] + 2;
+
+ break;
+ } else
+ cnt += in_ie[cnt + 1] + 2;
+
+ }
+
+ return wfd_ie_ptr;
+}
+
+/**
+ * rtw_get_wfd_attr - Search a specific WFD attribute from a given WFD IE
+ * @wfd_ie: Address of WFD IE to search
+ * @wfd_ielen: Length limit from wfd_ie
+ * @target_attr_id: The attribute ID of WFD attribute to search
+ * @buf_attr: If not NULL and the WFD attribute is found, WFD attribute will be copied to the buf starting from buf_attr
+ * @len_attr: If not NULL and the WFD attribute is found, will set to the length of the entire WFD attribute
+ *
+ * Returns: the address of the specific WPS attribute found, or NULL
+ */
+u8 *rtw_get_wfd_attr(u8 *wfd_ie, uint wfd_ielen, u8 target_attr_id, u8 *buf_attr, u32 *len_attr)
+{
+ u8 *attr_ptr = NULL;
+ u8 *target_attr_ptr = NULL;
+ u8 wfd_oui[4] = {0x50, 0x6F, 0x9A, 0x0A};
+
+ if (len_attr)
+ *len_attr = 0;
+
+ if (!wfd_ie
+ || wfd_ielen <= 6
+ || (wfd_ie[0] != WLAN_EID_VENDOR_SPECIFIC)
+ || (memcmp(wfd_ie + 2, wfd_oui, 4)))
+ return attr_ptr;
+
+ /* 6 = 1(Element ID) + 1(Length) + 3 (OUI) + 1(OUI Type) */
+ attr_ptr = wfd_ie + 6; /* goto first attr */
+
+ while ((attr_ptr - wfd_ie + 3) <= wfd_ielen) {
+ /* 3 = 1(Attribute ID) + 2(Length) */
+ u8 attr_id = *attr_ptr;
+ u16 attr_data_len = RTW_GET_BE16(attr_ptr + 1);
+ u16 attr_len = attr_data_len + 3;
+
+ if (0)
+ RTW_INFO("%s attr_ptr:%p, id:%u, length:%u\n", __func__, attr_ptr, attr_id, attr_data_len);
+
+ if ((attr_ptr - wfd_ie + attr_len) > wfd_ielen)
+ break;
+
+ if (attr_id == target_attr_id) {
+ target_attr_ptr = attr_ptr;
+
+ if (buf_attr)
+ memcpy(buf_attr, attr_ptr, attr_len);
+
+ if (len_attr)
+ *len_attr = attr_len;
+
+ break;
+ } else
+ attr_ptr += attr_len;
+ }
+
+ return target_attr_ptr;
+}
+
+/**
+ * rtw_get_wfd_attr_content - Search a specific WFD attribute content from a given WFD IE
+ * @wfd_ie: Address of WFD IE to search
+ * @wfd_ielen: Length limit from wfd_ie
+ * @target_attr_id: The attribute ID of WFD attribute to search
+ * @buf_content: If not NULL and the WFD attribute is found, WFD attribute content will be copied to the buf starting from buf_content
+ * @len_content: If not NULL and the WFD attribute is found, will set to the length of the WFD attribute content
+ *
+ * Returns: the address of the specific WFD attribute content found, or NULL
+ */
+u8 *rtw_get_wfd_attr_content(u8 *wfd_ie, uint wfd_ielen, u8 target_attr_id, u8 *buf_content, uint *len_content)
+{
+ u8 *attr_ptr;
+ u32 attr_len;
+
+ if (len_content)
+ *len_content = 0;
+
+ attr_ptr = rtw_get_wfd_attr(wfd_ie, wfd_ielen, target_attr_id, NULL, &attr_len);
+
+ if (attr_ptr && attr_len) {
+ if (buf_content)
+ memcpy(buf_content, attr_ptr + 3, attr_len - 3);
+
+ if (len_content)
+ *len_content = attr_len - 3;
+
+ return attr_ptr + 3;
+ }
+
+ return NULL;
+}
+
+uint rtw_del_wfd_ie(u8 *ies, uint ies_len_ori, const char *msg)
+{
+#define DBG_DEL_WFD_IE 0
+
+ u8 *target_ie;
+ u32 target_ie_len;
+ uint ies_len = ies_len_ori;
+ int index = 0;
+
+ while (1) {
+ target_ie = rtw_get_wfd_ie(ies, ies_len, NULL, &target_ie_len);
+ if (target_ie && target_ie_len) {
+ u8 *next_ie = target_ie + target_ie_len;
+ uint remain_len = ies_len - (next_ie - ies);
+
+ if (DBG_DEL_WFD_IE && msg) {
+ RTW_INFO("%s %d before\n", __func__, index);
+ dump_ies(RTW_DBGDUMP, ies, ies_len);
+
+ RTW_INFO("ies:%p, ies_len:%u\n", ies, ies_len);
+ RTW_INFO("target_ie:%p, target_ie_len:%u\n", target_ie, target_ie_len);
+ RTW_INFO("next_ie:%p, remain_len:%u\n", next_ie, remain_len);
+ }
+
+ memmove(target_ie, next_ie, remain_len);
+ memset(target_ie + remain_len, 0, target_ie_len);
+ ies_len -= target_ie_len;
+
+ if (DBG_DEL_WFD_IE && msg) {
+ RTW_INFO("%s %d after\n", __func__, index);
+ dump_ies(RTW_DBGDUMP, ies, ies_len);
+ }
+
+ index++;
+ } else
+ break;
+ }
+
+ return ies_len;
+}
+
+uint rtw_del_wfd_attr(u8 *ie, uint ielen_ori, u8 attr_id)
+{
+#define DBG_DEL_WFD_ATTR 0
+
+ u8 *target_attr;
+ u32 target_attr_len;
+ uint ielen = ielen_ori;
+ int index = 0;
+
+ while (1) {
+ target_attr = rtw_get_wfd_attr(ie, ielen, attr_id, NULL, &target_attr_len);
+ if (target_attr && target_attr_len) {
+ u8 *next_attr = target_attr + target_attr_len;
+ uint remain_len = ielen - (next_attr - ie);
+
+ if (DBG_DEL_WFD_ATTR) {
+ RTW_INFO("%s %d before\n", __func__, index);
+ dump_ies(RTW_DBGDUMP, ie, ielen);
+
+ RTW_INFO("ie:%p, ielen:%u\n", ie, ielen);
+ RTW_INFO("target_attr:%p, target_attr_len:%u\n", target_attr, target_attr_len);
+ RTW_INFO("next_attr:%p, remain_len:%u\n", next_attr, remain_len);
+ }
+
+ memmove(target_attr, next_attr, remain_len);
+ memset(target_attr + remain_len, 0, target_attr_len);
+ *(ie + 1) -= target_attr_len;
+ ielen -= target_attr_len;
+
+ if (DBG_DEL_WFD_ATTR) {
+ RTW_INFO("%s %d after\n", __func__, index);
+ dump_ies(RTW_DBGDUMP, ie, ielen);
+ }
+
+ index++;
+ } else
+ break;
+ }
+
+ return ielen;
+}
+
+inline u8 *rtw_bss_ex_get_wfd_ie(WLAN_BSSID_EX *bss_ex, u8 *wfd_ie, uint *wfd_ielen)
+{
+ return rtw_get_wfd_ie(BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex), wfd_ie, wfd_ielen);
+}
+
+void rtw_bss_ex_del_wfd_ie(WLAN_BSSID_EX *bss_ex)
+{
+#define DBG_BSS_EX_DEL_WFD_IE 0
+ u8 *ies = BSS_EX_TLV_IES(bss_ex);
+ uint ies_len_ori = BSS_EX_TLV_IES_LEN(bss_ex);
+ uint ies_len;
+
+ ies_len = rtw_del_wfd_ie(ies, ies_len_ori, DBG_BSS_EX_DEL_WFD_IE ? __func__ : NULL);
+ bss_ex->IELength -= ies_len_ori - ies_len;
+}
+
+void rtw_bss_ex_del_wfd_attr(WLAN_BSSID_EX *bss_ex, u8 attr_id)
+{
+#define DBG_BSS_EX_DEL_WFD_ATTR 0
+
+ u8 *ies = BSS_EX_TLV_IES(bss_ex);
+ uint ies_len = BSS_EX_TLV_IES_LEN(bss_ex);
+
+ u8 *ie;
+ uint ie_len, ie_len_ori;
+
+ int index = 0;
+
+ while (1) {
+ ie = rtw_get_wfd_ie(ies, ies_len, NULL, &ie_len_ori);
+ if (ie) {
+ u8 *next_ie_ori = ie + ie_len_ori;
+ uint remain_len = bss_ex->IELength - (next_ie_ori - bss_ex->IEs);
+ u8 has_target_attr = 0;
+
+ if (DBG_BSS_EX_DEL_WFD_ATTR) {
+ if (rtw_get_wfd_attr(ie, ie_len_ori, attr_id, NULL, NULL)) {
+ RTW_INFO("%s %d before\n", __func__, index);
+ dump_ies(RTW_DBGDUMP, BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex));
+
+ RTW_INFO("ies:%p, ies_len:%u\n", ies, ies_len);
+ RTW_INFO("ie:%p, ie_len_ori:%u\n", ie, ie_len_ori);
+ RTW_INFO("next_ie_ori:%p, remain_len:%u\n", next_ie_ori, remain_len);
+ has_target_attr = 1;
+ }
+ }
+
+ ie_len = rtw_del_wfd_attr(ie, ie_len_ori, attr_id);
+ if (ie_len != ie_len_ori) {
+ u8 *next_ie = ie + ie_len;
+
+ memmove(next_ie, next_ie_ori, remain_len);
+ memset(next_ie + remain_len, 0, ie_len_ori - ie_len);
+ bss_ex->IELength -= ie_len_ori - ie_len;
+
+ ies = next_ie;
+ } else
+ ies = next_ie_ori;
+
+ if (DBG_BSS_EX_DEL_WFD_ATTR) {
+ if (has_target_attr) {
+ RTW_INFO("%s %d after\n", __func__, index);
+ dump_ies(RTW_DBGDUMP, BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex));
+ }
+ }
+
+ ies_len = remain_len;
+
+ index++;
+ } else
+ break;
+ }
+}
+
+/* Baron adds to avoid FreeBSD warning */
+int ieee80211_is_empty_essid(const char *essid, int essid_len)
+{
+ /* Single white space is for Linksys APs */
+ if (essid_len == 1 && essid[0] == ' ')
+ return 1;
+
+ /* Otherwise, if the entire essid is 0, we assume it is hidden */
+ while (essid_len) {
+ essid_len--;
+ if (essid[essid_len] != '\0')
+ return 0;
+ }
+
+ return 1;
+}
+
+int ieee80211_get_hdrlen(u16 fc)
+{
+ int hdrlen = 24;
+
+ switch (WLAN_FC_GET_TYPE(fc)) {
+ case RTW_IEEE80211_FTYPE_DATA:
+ if (fc & RTW_IEEE80211_STYPE_QOS_DATA)
+ hdrlen += 2;
+ if ((fc & RTW_IEEE80211_FCTL_FROMDS) && (fc & RTW_IEEE80211_FCTL_TODS))
+ hdrlen += 6; /* Addr4 */
+ break;
+ case RTW_IEEE80211_FTYPE_CTL:
+ switch (WLAN_FC_GET_STYPE(fc)) {
+ case RTW_IEEE80211_STYPE_CTS:
+ case RTW_IEEE80211_STYPE_ACK:
+ hdrlen = 10;
+ break;
+ default:
+ hdrlen = 16;
+ break;
+ }
+ break;
+ }
+
+ return hdrlen;
+}
+
+static int rtw_get_cipher_info(struct wlan_network *pnetwork)
+{
+ u32 wpa_ielen;
+ unsigned char *pbuf;
+ int group_cipher = 0, pairwise_cipher = 0, is8021x = 0;
+ int ret = _FAIL;
+ pbuf = rtw_get_wpa_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
+
+ if (pbuf && (wpa_ielen > 0)) {
+ if (_SUCCESS == rtw_parse_wpa_ie(pbuf, wpa_ielen + 2, &group_cipher, &pairwise_cipher, &is8021x)) {
+
+ pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher;
+ pnetwork->BcnInfo.group_cipher = group_cipher;
+ pnetwork->BcnInfo.is_8021x = is8021x;
+ ret = _SUCCESS;
+ }
+ } else {
+
+ pbuf = rtw_get_wpa2_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
+
+ if (pbuf && (wpa_ielen > 0)) {
+ if (_SUCCESS == rtw_parse_wpa2_ie(pbuf, wpa_ielen + 2, &group_cipher, &pairwise_cipher, &is8021x)) {
+ pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher;
+ pnetwork->BcnInfo.group_cipher = group_cipher;
+ pnetwork->BcnInfo.is_8021x = is8021x;
+ ret = _SUCCESS;
+ }
+ }
+ }
+
+ return ret;
+}
+
+void rtw_get_bcn_info(struct wlan_network *pnetwork)
+{
+ unsigned short cap = 0;
+ __le16 le_cap;
+ u8 bencrypt = 0;
+ /* u8 wpa_ie[255],rsn_ie[255]; */
+ u16 wpa_len = 0, rsn_len = 0;
+ struct HT_info_element *pht_info = NULL;
+ struct rtw_ieee80211_ht_cap *pht_cap = NULL;
+ unsigned int len;
+ unsigned char *p;
+
+ memcpy((u8 *)&le_cap, rtw_get_capability_from_ie(pnetwork->network.IEs), 2);
+ cap = le16_to_cpu(le_cap);
+ if (cap & WLAN_CAPABILITY_PRIVACY) {
+ bencrypt = 1;
+ pnetwork->network.Privacy = 1;
+ } else
+ pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_OPENSYS;
+ rtw_get_sec_ie(pnetwork->network.IEs , pnetwork->network.IELength, NULL, &rsn_len, NULL, &wpa_len);
+
+ if (rsn_len > 0)
+ pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA2;
+ else if (wpa_len > 0)
+ pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA;
+ else {
+ if (bencrypt)
+ pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WEP;
+ }
+ rtw_get_cipher_info(pnetwork);
+
+ /* get bwmode and ch_offset */
+ /* parsing HT_CAP_IE */
+ p = rtw_get_ie(pnetwork->network.IEs + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, pnetwork->network.IELength - _FIXED_IE_LENGTH_);
+ if (p && len > 0) {
+ pht_cap = (struct rtw_ieee80211_ht_cap *)(p + 2);
+ pnetwork->BcnInfo.ht_cap_info = le16_to_cpu(pht_cap->cap_info);
+ } else
+ pnetwork->BcnInfo.ht_cap_info = 0;
+ /* parsing HT_INFO_IE */
+ p = rtw_get_ie(pnetwork->network.IEs + _FIXED_IE_LENGTH_, _HT_ADD_INFO_IE_, &len, pnetwork->network.IELength - _FIXED_IE_LENGTH_);
+ if (p && len > 0) {
+ pht_info = (struct HT_info_element *)(p + 2);
+ pnetwork->BcnInfo.ht_info_infos_0 = pht_info->infos[0];
+ } else
+ pnetwork->BcnInfo.ht_info_infos_0 = 0;
+}
+
+u8 rtw_ht_mcsset_to_nss(u8 *supp_mcs_set)
+{
+ u8 nss = 1;
+
+ if (supp_mcs_set[3])
+ nss = 4;
+ else if (supp_mcs_set[2])
+ nss = 3;
+ else if (supp_mcs_set[1])
+ nss = 2;
+ else if (supp_mcs_set[0])
+ nss = 1;
+ else
+ RTW_INFO("%s,%d, warning! supp_mcs_set is zero\n", __func__, __LINE__);
+ /* RTW_INFO("%s HT: %dSS\n", __func__, nss); */
+ return nss;
+}
+
+u32 rtw_ht_mcs_set_to_bitmap(u8 *mcs_set, u8 nss)
+{
+ u8 i;
+ u32 bitmap = 0;
+
+ for (i = 0; i < nss; i++)
+ bitmap |= mcs_set[i] << (i * 8);
+
+ RTW_INFO("ht_mcs_set=%02x %02x %02x %02x, nss=%u, bitmap=%08x\n"
+ , mcs_set[0], mcs_set[1], mcs_set[2], mcs_set[3], nss, bitmap);
+
+ return bitmap;
+}
+
+/* show MCS rate, unit: 100Kbps */
+u16 rtw_mcs_rate(u8 rf_type, u8 bw_40MHz, u8 short_GI, unsigned char *MCS_rate)
+{
+ u16 max_rate = 0;
+
+ if (MCS_rate[3]) {
+ if (MCS_rate[3] & BIT(7))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 6000 : 5400) : ((short_GI) ? 2889 : 2600);
+ else if (MCS_rate[3] & BIT(6))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 5400 : 4860) : ((short_GI) ? 2600 : 2340);
+ else if (MCS_rate[3] & BIT(5))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 4800 : 4320) : ((short_GI) ? 2311 : 2080);
+ else if (MCS_rate[3] & BIT(4))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 3600 : 3240) : ((short_GI) ? 1733 : 1560);
+ else if (MCS_rate[3] & BIT(3))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 2400 : 2160) : ((short_GI) ? 1156 : 1040);
+ else if (MCS_rate[3] & BIT(2))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 1800 : 1620) : ((short_GI) ? 867 : 780);
+ else if (MCS_rate[3] & BIT(1))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 1200 : 1080) : ((short_GI) ? 578 : 520);
+ else if (MCS_rate[3] & BIT(0))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 600 : 540) : ((short_GI) ? 289 : 260);
+ } else if (MCS_rate[2]) {
+ if (MCS_rate[2] & BIT(7))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 4500 : 4050) : ((short_GI) ? 2167 : 1950);
+ else if (MCS_rate[2] & BIT(6))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 4050 : 3645) : ((short_GI) ? 1950 : 1750);
+ else if (MCS_rate[2] & BIT(5))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 3600 : 3240) : ((short_GI) ? 1733 : 1560);
+ else if (MCS_rate[2] & BIT(4))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 2700 : 2430) : ((short_GI) ? 1300 : 1170);
+ else if (MCS_rate[2] & BIT(3))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 1800 : 1620) : ((short_GI) ? 867 : 780);
+ else if (MCS_rate[2] & BIT(2))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 1350 : 1215) : ((short_GI) ? 650 : 585);
+ else if (MCS_rate[2] & BIT(1))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 900 : 810) : ((short_GI) ? 433 : 390);
+ else if (MCS_rate[2] & BIT(0))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 450 : 405) : ((short_GI) ? 217 : 195);
+ } else if (MCS_rate[1]) {
+ if (MCS_rate[1] & BIT(7))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 3000 : 2700) : ((short_GI) ? 1444 : 1300);
+ else if (MCS_rate[1] & BIT(6))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 2700 : 2430) : ((short_GI) ? 1300 : 1170);
+ else if (MCS_rate[1] & BIT(5))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 2400 : 2160) : ((short_GI) ? 1156 : 1040);
+ else if (MCS_rate[1] & BIT(4))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 1800 : 1620) : ((short_GI) ? 867 : 780);
+ else if (MCS_rate[1] & BIT(3))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 1200 : 1080) : ((short_GI) ? 578 : 520);
+ else if (MCS_rate[1] & BIT(2))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 900 : 810) : ((short_GI) ? 433 : 390);
+ else if (MCS_rate[1] & BIT(1))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 600 : 540) : ((short_GI) ? 289 : 260);
+ else if (MCS_rate[1] & BIT(0))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 300 : 270) : ((short_GI) ? 144 : 130);
+ } else {
+ if (MCS_rate[0] & BIT(7))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 1500 : 1350) : ((short_GI) ? 722 : 650);
+ else if (MCS_rate[0] & BIT(6))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 1350 : 1215) : ((short_GI) ? 650 : 585);
+ else if (MCS_rate[0] & BIT(5))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 1200 : 1080) : ((short_GI) ? 578 : 520);
+ else if (MCS_rate[0] & BIT(4))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 900 : 810) : ((short_GI) ? 433 : 390);
+ else if (MCS_rate[0] & BIT(3))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 600 : 540) : ((short_GI) ? 289 : 260);
+ else if (MCS_rate[0] & BIT(2))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 450 : 405) : ((short_GI) ? 217 : 195);
+ else if (MCS_rate[0] & BIT(1))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 300 : 270) : ((short_GI) ? 144 : 130);
+ else if (MCS_rate[0] & BIT(0))
+ max_rate = (bw_40MHz) ? ((short_GI) ? 150 : 135) : ((short_GI) ? 72 : 65);
+ }
+
+ return max_rate;
+}
+
+int rtw_action_frame_parse(const u8 *frame, u32 frame_len, u8 *category, u8 *action)
+{
+ const u8 *frame_body = frame + sizeof(struct rtw_ieee80211_hdr_3addr);
+ u16 fc;
+ u8 c;
+ u8 a = ACT_PUBLIC_MAX;
+
+ fc = le16_to_cpu(((struct rtw_ieee80211_hdr_3addr *)frame)->frame_ctl);
+
+ if ((fc & (RTW_IEEE80211_FCTL_FTYPE | RTW_IEEE80211_FCTL_STYPE))
+ != (RTW_IEEE80211_FTYPE_MGMT | RTW_IEEE80211_STYPE_ACTION)
+ )
+ return false;
+
+ c = frame_body[0];
+
+ switch (c) {
+ case RTW_WLAN_CATEGORY_P2P: /* vendor-specific */
+ break;
+ default:
+ a = frame_body[1];
+ }
+
+ if (category)
+ *category = c;
+ if (action)
+ *action = a;
+
+ return true;
+}
+
+static const char *_action_public_str[] = {
+ "ACT_PUB_BSSCOEXIST",
+ "ACT_PUB_DSE_ENABLE",
+ "ACT_PUB_DSE_DEENABLE",
+ "ACT_PUB_DSE_REG_LOCATION",
+ "ACT_PUB_EXT_CHL_SWITCH",
+ "ACT_PUB_DSE_MSR_REQ",
+ "ACT_PUB_DSE_MSR_RPRT",
+ "ACT_PUB_MP",
+ "ACT_PUB_DSE_PWR_CONSTRAINT",
+ "ACT_PUB_VENDOR",
+ "ACT_PUB_GAS_INITIAL_REQ",
+ "ACT_PUB_GAS_INITIAL_RSP",
+ "ACT_PUB_GAS_COMEBACK_REQ",
+ "ACT_PUB_GAS_COMEBACK_RSP",
+ "ACT_PUB_TDLS_DISCOVERY_RSP",
+ "ACT_PUB_LOCATION_TRACK",
+ "ACT_PUB_RSVD",
+};
+
+const char *action_public_str(u8 action)
+{
+ action = (action >= ACT_PUBLIC_MAX) ? ACT_PUBLIC_MAX : action;
+ return _action_public_str[action];
+}
+
diff --git a/drivers/staging/rtl8188eu/core/rtw_io.c b/drivers/staging/rtl8188eu/core/rtw_io.c
new file mode 100644
index 000000000000..d6639cec3bb8
--- /dev/null
+++ b/drivers/staging/rtl8188eu/core/rtw_io.c
@@ -0,0 +1,473 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved. */
+
+/*
+
+The purpose of rtw_io.c
+
+a. provides the API
+
+b. provides the protocol engine
+
+c. provides the software interface between caller and the hardware interface
+
+
+Compiler Flag Option:
+
+2. CONFIG_USB_HCI:
+ a. USE_ASYNC_IRP: Both sync/async operations are provided.
+Only sync read/rtw_write_mem operations are provided.
+
+jackson@realtek.com.tw
+
+*/
+
+#define _RTW_IO_C_
+
+#include <drv_types.h>
+#include <hal_data.h>
+
+ #define rtw_le16_to_cpu(val) le16_to_cpu(val)
+ #define rtw_le32_to_cpu(val) le32_to_cpu(val)
+ #define rtw_cpu_to_le16(val) cpu_to_le16(val)
+ #define rtw_cpu_to_le32(val) cpu_to_le32(val)
+
+u8 _rtw_read8(_adapter *adapter, u32 addr)
+{
+ u8 r_val;
+ /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
+ struct io_priv *pio_priv = &adapter->iopriv;
+ struct intf_hdl *pintfhdl = &(pio_priv->intf);
+ u8(*_read8)(struct intf_hdl *pintfhdl, u32 addr);
+ _read8 = pintfhdl->io_ops._read8;
+
+ r_val = _read8(pintfhdl, addr);
+ return r_val;
+}
+
+u16 _rtw_read16(_adapter *adapter, u32 addr)
+{
+ /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
+ struct io_priv *pio_priv = &adapter->iopriv;
+ struct intf_hdl *pintfhdl = &(pio_priv->intf);
+ u16(*_read16)(struct intf_hdl *pintfhdl, u32 addr);
+ _read16 = pintfhdl->io_ops._read16;
+
+ return _read16(pintfhdl, addr);
+}
+
+u32 _rtw_read32(_adapter *adapter, u32 addr)
+{
+ /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
+ struct io_priv *pio_priv = &adapter->iopriv;
+ struct intf_hdl *pintfhdl = &(pio_priv->intf);
+ u32(*_read32)(struct intf_hdl *pintfhdl, u32 addr);
+ _read32 = pintfhdl->io_ops._read32;
+
+ return _read32(pintfhdl, addr);
+}
+
+int _rtw_write8(_adapter *adapter, u32 addr, u8 val)
+{
+ /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
+ struct io_priv *pio_priv = &adapter->iopriv;
+ struct intf_hdl *pintfhdl = &(pio_priv->intf);
+ int (*_write8)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
+ int ret;
+ _write8 = pintfhdl->io_ops._write8;
+
+ ret = _write8(pintfhdl, addr, val);
+
+ return RTW_STATUS_CODE(ret);
+}
+int _rtw_write16(_adapter *adapter, u32 addr, u16 val)
+{
+ /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
+ struct io_priv *pio_priv = &adapter->iopriv;
+ struct intf_hdl *pintfhdl = &(pio_priv->intf);
+ int (*_write16)(struct intf_hdl *pintfhdl, u32 addr, __le16 val);
+ int ret;
+ __le16 outval;
+
+ _write16 = pintfhdl->io_ops._write16;
+
+ outval = rtw_cpu_to_le16(val);
+ ret = _write16(pintfhdl, addr, outval);
+
+ return RTW_STATUS_CODE(ret);
+}
+int _rtw_write32(_adapter *adapter, u32 addr, u32 val)
+{
+ /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
+ struct io_priv *pio_priv = &adapter->iopriv;
+ struct intf_hdl *pintfhdl = &(pio_priv->intf);
+ int (*_write32)(struct intf_hdl *pintfhdl, u32 addr, __le32 val);
+ int ret;
+ __le32 outval;
+
+ _write32 = pintfhdl->io_ops._write32;
+
+ outval = rtw_cpu_to_le32(val);
+ ret = _write32(pintfhdl, addr, outval);
+
+ return RTW_STATUS_CODE(ret);
+}
+
+int _rtw_writeN(_adapter *adapter, u32 addr , u32 length , u8 *pdata)
+{
+ /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
+ struct io_priv *pio_priv = &adapter->iopriv;
+ struct intf_hdl *pintfhdl = (struct intf_hdl *)(&(pio_priv->intf));
+ int (*_writeN)(struct intf_hdl *pintfhdl, u32 addr, u32 length, u8 *pdata);
+ int ret;
+ _writeN = pintfhdl->io_ops._writeN;
+
+ ret = _writeN(pintfhdl, addr, length, pdata);
+
+ return RTW_STATUS_CODE(ret);
+}
+
+int _rtw_write8_async(_adapter *adapter, u32 addr, u8 val)
+{
+ /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
+ struct io_priv *pio_priv = &adapter->iopriv;
+ struct intf_hdl *pintfhdl = &(pio_priv->intf);
+ int (*_write8_async)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
+ int ret;
+ _write8_async = pintfhdl->io_ops._write8_async;
+
+ ret = _write8_async(pintfhdl, addr, val);
+
+ return RTW_STATUS_CODE(ret);
+}
+int _rtw_write16_async(_adapter *adapter, u32 addr, u16 val)
+{
+ /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
+ struct io_priv *pio_priv = &adapter->iopriv;
+ struct intf_hdl *pintfhdl = &(pio_priv->intf);
+ int (*_write16_async)(struct intf_hdl *pintfhdl, u32 addr, __le16 val);
+ int ret;
+ __le16 outval;
+
+ _write16_async = pintfhdl->io_ops._write16_async;
+ outval = rtw_cpu_to_le16(val);
+ ret = _write16_async(pintfhdl, addr, outval);
+
+ return RTW_STATUS_CODE(ret);
+}
+int _rtw_write32_async(_adapter *adapter, u32 addr, u32 val)
+{
+ /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
+ struct io_priv *pio_priv = &adapter->iopriv;
+ struct intf_hdl *pintfhdl = &(pio_priv->intf);
+ int (*_write32_async)(struct intf_hdl *pintfhdl, u32 addr, __le32 val);
+ int ret;
+ __le32 outval;
+
+ _write32_async = pintfhdl->io_ops._write32_async;
+ outval = rtw_cpu_to_le32(val);
+ ret = _write32_async(pintfhdl, addr, outval);
+
+ return RTW_STATUS_CODE(ret);
+}
+
+void _rtw_read_mem(_adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
+{
+ void (*_read_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
+ /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
+ struct io_priv *pio_priv = &adapter->iopriv;
+ struct intf_hdl *pintfhdl = &(pio_priv->intf);
+
+
+ if (RTW_CANNOT_RUN(adapter)) {
+ return;
+ }
+
+ _read_mem = pintfhdl->io_ops._read_mem;
+
+ _read_mem(pintfhdl, addr, cnt, pmem);
+
+
+}
+
+void _rtw_write_mem(_adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
+{
+ void (*_write_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
+ /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
+ struct io_priv *pio_priv = &adapter->iopriv;
+ struct intf_hdl *pintfhdl = &(pio_priv->intf);
+
+
+ _write_mem = pintfhdl->io_ops._write_mem;
+
+ _write_mem(pintfhdl, addr, cnt, pmem);
+
+
+}
+
+void _rtw_read_port(_adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
+{
+ u32(*_read_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
+ /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
+ struct io_priv *pio_priv = &adapter->iopriv;
+ struct intf_hdl *pintfhdl = &(pio_priv->intf);
+
+
+ if (RTW_CANNOT_RUN(adapter)) {
+ return;
+ }
+
+ _read_port = pintfhdl->io_ops._read_port;
+
+ _read_port(pintfhdl, addr, cnt, pmem);
+
+
+}
+
+void _rtw_read_port_cancel(_adapter *adapter)
+{
+ void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
+ struct io_priv *pio_priv = &adapter->iopriv;
+ struct intf_hdl *pintfhdl = &(pio_priv->intf);
+
+ _read_port_cancel = pintfhdl->io_ops._read_port_cancel;
+
+ RTW_DISABLE_FUNC(adapter, DF_RX_BIT);
+
+ if (_read_port_cancel)
+ _read_port_cancel(pintfhdl);
+}
+
+u32 _rtw_write_port(_adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
+{
+ u32(*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
+ /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
+ struct io_priv *pio_priv = &adapter->iopriv;
+ struct intf_hdl *pintfhdl = &(pio_priv->intf);
+ u32 ret = _SUCCESS;
+
+
+ _write_port = pintfhdl->io_ops._write_port;
+
+ ret = _write_port(pintfhdl, addr, cnt, pmem);
+
+
+ return ret;
+}
+
+u32 _rtw_write_port_and_wait(_adapter *adapter, u32 addr, u32 cnt, u8 *pmem, int timeout_ms)
+{
+ int ret = _SUCCESS;
+ struct xmit_buf *pxmitbuf = (struct xmit_buf *)pmem;
+ struct submit_ctx sctx;
+
+ rtw_sctx_init(&sctx, timeout_ms);
+ pxmitbuf->sctx = &sctx;
+
+ ret = _rtw_write_port(adapter, addr, cnt, pmem);
+
+ if (ret == _SUCCESS)
+ ret = rtw_sctx_wait(&sctx, __func__);
+
+ return ret;
+}
+
+void _rtw_write_port_cancel(_adapter *adapter)
+{
+ void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
+ struct io_priv *pio_priv = &adapter->iopriv;
+ struct intf_hdl *pintfhdl = &(pio_priv->intf);
+
+ _write_port_cancel = pintfhdl->io_ops._write_port_cancel;
+
+ RTW_DISABLE_FUNC(adapter, DF_TX_BIT);
+
+ if (_write_port_cancel)
+ _write_port_cancel(pintfhdl);
+}
+int rtw_init_io_priv(_adapter *padapter, void (*set_intf_ops)(_adapter *padapter, struct _io_ops *pops))
+{
+ struct io_priv *piopriv = &padapter->iopriv;
+ struct intf_hdl *pintf = &piopriv->intf;
+
+ if (set_intf_ops == NULL)
+ return _FAIL;
+
+ piopriv->padapter = padapter;
+ pintf->padapter = padapter;
+ pintf->pintf_dev = adapter_to_dvobj(padapter);
+
+ set_intf_ops(padapter, &pintf->io_ops);
+
+ return _SUCCESS;
+}
+
+/*
+* Increase and check if the continual_io_error of this @param dvobjprive is larger than MAX_CONTINUAL_IO_ERR
+* @return true:
+* @return false:
+*/
+int rtw_inc_and_chk_continual_io_error(struct dvobj_priv *dvobj)
+{
+ int ret = false;
+ int value;
+
+ value = ATOMIC_INC_RETURN(&dvobj->continual_io_error);
+ if (value > MAX_CONTINUAL_IO_ERR) {
+ RTW_INFO("[dvobj:%p][ERROR] continual_io_error:%d > %d\n", dvobj, value, MAX_CONTINUAL_IO_ERR);
+ ret = true;
+ } else {
+ /* RTW_INFO("[dvobj:%p] continual_io_error:%d\n", dvobj, value); */
+ }
+ return ret;
+}
+
+/*
+* Set the continual_io_error of this @param dvobjprive to 0
+*/
+void rtw_reset_continual_io_error(struct dvobj_priv *dvobj)
+{
+ ATOMIC_SET(&dvobj->continual_io_error, 0);
+}
+
+#ifdef DBG_IO
+
+u32 read_sniff_ranges[][2] = {
+ /* {0x520, 0x523}, */
+};
+
+u32 write_sniff_ranges[][2] = {
+ /* {0x520, 0x523}, */
+ /* {0x4c, 0x4c}, */
+};
+
+int read_sniff_num = sizeof(read_sniff_ranges) / sizeof(u32) / 2;
+int write_sniff_num = sizeof(write_sniff_ranges) / sizeof(u32) / 2;
+
+bool match_read_sniff_ranges(u32 addr, u16 len)
+{
+ int i;
+ for (i = 0; i < read_sniff_num; i++) {
+ if (addr + len > read_sniff_ranges[i][0] && addr <= read_sniff_ranges[i][1])
+ return true;
+ }
+
+ return false;
+}
+
+bool match_write_sniff_ranges(u32 addr, u16 len)
+{
+ int i;
+ for (i = 0; i < write_sniff_num; i++) {
+ if (addr + len > write_sniff_ranges[i][0] && addr <= write_sniff_ranges[i][1])
+ return true;
+ }
+
+ return false;
+}
+
+struct rf_sniff_ent {
+ u8 path;
+ u16 reg;
+ u32 mask;
+};
+
+struct rf_sniff_ent rf_read_sniff_ranges[] = {
+ /* example for all path addr 0x55 with all RF Reg mask */
+ /* {MAX_RF_PATH, 0x55, bRFRegOffsetMask}, */
+};
+
+struct rf_sniff_ent rf_write_sniff_ranges[] = {
+ /* example for all path addr 0x55 with all RF Reg mask */
+ /* {MAX_RF_PATH, 0x55, bRFRegOffsetMask}, */
+};
+
+int rf_read_sniff_num = sizeof(rf_read_sniff_ranges) / sizeof(struct rf_sniff_ent);
+int rf_write_sniff_num = sizeof(rf_write_sniff_ranges) / sizeof(struct rf_sniff_ent);
+
+bool match_rf_read_sniff_ranges(u8 path, u32 addr, u32 mask)
+{
+ int i;
+
+ for (i = 0; i < rf_read_sniff_num; i++) {
+ if (rf_read_sniff_ranges[i].path == MAX_RF_PATH || rf_read_sniff_ranges[i].path == path)
+ if (addr == rf_read_sniff_ranges[i].reg && (mask & rf_read_sniff_ranges[i].mask))
+ return true;
+ }
+
+ return false;
+}
+
+bool match_rf_write_sniff_ranges(u8 path, u32 addr, u32 mask)
+{
+ int i;
+
+ for (i = 0; i < rf_write_sniff_num; i++) {
+ if (rf_write_sniff_ranges[i].path == MAX_RF_PATH || rf_write_sniff_ranges[i].path == path)
+ if (addr == rf_write_sniff_ranges[i].reg && (mask & rf_write_sniff_ranges[i].mask))
+ return true;
+ }
+
+ return false;
+}
+
+u8 dbg_rtw_read8(_adapter *adapter, u32 addr, const char *caller, const int line)
+{
+ u8 val = _rtw_read8(adapter, addr);
+
+ if (match_read_sniff_ranges(addr, 1))
+ RTW_INFO("DBG_IO %s:%d rtw_read8(0x%04x) return 0x%02x\n", caller, line, addr, val);
+
+ return val;
+}
+
+u16 dbg_rtw_read16(_adapter *adapter, u32 addr, const char *caller, const int line)
+{
+ u16 val = _rtw_read16(adapter, addr);
+
+ if (match_read_sniff_ranges(addr, 2))
+ RTW_INFO("DBG_IO %s:%d rtw_read16(0x%04x) return 0x%04x\n", caller, line, addr, val);
+
+ return val;
+}
+
+u32 dbg_rtw_read32(_adapter *adapter, u32 addr, const char *caller, const int line)
+{
+ u32 val = _rtw_read32(adapter, addr);
+
+ if (match_read_sniff_ranges(addr, 4))
+ RTW_INFO("DBG_IO %s:%d rtw_read32(0x%04x) return 0x%08x\n", caller, line, addr, val);
+
+ return val;
+}
+
+int dbg_rtw_write8(_adapter *adapter, u32 addr, u8 val, const char *caller, const int line)
+{
+ if (match_write_sniff_ranges(addr, 1))
+ RTW_INFO("DBG_IO %s:%d rtw_write8(0x%04x, 0x%02x)\n", caller, line, addr, val);
+
+ return _rtw_write8(adapter, addr, val);
+}
+int dbg_rtw_write16(_adapter *adapter, u32 addr, u16 val, const char *caller, const int line)
+{
+ if (match_write_sniff_ranges(addr, 2))
+ RTW_INFO("DBG_IO %s:%d rtw_write16(0x%04x, 0x%04x)\n", caller, line, addr, val);
+
+ return _rtw_write16(adapter, addr, val);
+}
+int dbg_rtw_write32(_adapter *adapter, u32 addr, u32 val, const char *caller, const int line)
+{
+ if (match_write_sniff_ranges(addr, 4))
+ RTW_INFO("DBG_IO %s:%d rtw_write32(0x%04x, 0x%08x)\n", caller, line, addr, val);
+
+ return _rtw_write32(adapter, addr, val);
+}
+int dbg_rtw_writeN(_adapter *adapter, u32 addr , u32 length , u8 *data, const char *caller, const int line)
+{
+ if (match_write_sniff_ranges(addr, length))
+ RTW_INFO("DBG_IO %s:%d rtw_writeN(0x%04x, %u)\n", caller, line, addr, length);
+
+ return _rtw_writeN(adapter, addr, length, data);
+}
+
+#endif
diff --git a/drivers/staging/rtl8188eu/core/rtw_ioctl_query.c b/drivers/staging/rtl8188eu/core/rtw_ioctl_query.c
new file mode 100644
index 000000000000..c8a8de75e396
--- /dev/null
+++ b/drivers/staging/rtl8188eu/core/rtw_ioctl_query.c
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved. */
+
+#define _RTW_IOCTL_QUERY_C_
+
+
diff --git a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
new file mode 100644
index 000000000000..9170b8cfc19c
--- /dev/null
+++ b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
@@ -0,0 +1,1035 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved. */
+
+#define _RTW_IOCTL_SET_C_
+
+#include <drv_types.h>
+#include <hal_data.h>
+#include <rtw_mlme.h>
+
+#define IS_MAC_ADDRESS_BROADCAST(addr) \
+ (\
+ ((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)
+ || is_broadcast_mac_addr(bssid)
+ || is_multicast_mac_addr(bssid)
+ )
+ ret = false;
+
+ return ret;
+}
+
+u8 rtw_validate_ssid(NDIS_802_11_SSID *ssid)
+{
+ u8 i;
+ u8 ret = true;
+
+ if (ssid->SsidLength > 32) {
+ ret = false;
+ goto exit;
+ }
+
+#ifdef CONFIG_VALIDATE_SSID
+ 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 */
+
+exit:
+
+ return ret;
+}
+
+u8 rtw_do_join(_adapter *padapter);
+u8 rtw_do_join(_adapter *padapter)
+{
+ unsigned long irqL;
+ _list *plist, *phead;
+ u8 *pibss = NULL;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ _queue *queue = &(pmlmepriv->scanned_queue);
+ 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;
+
+ set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
+
+ pmlmepriv->pscanned = plist;
+
+ pmlmepriv->to_join = true;
+
+ if (_rtw_queue_empty(queue) ) {
+ _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
+ _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
+
+ /* 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
+ ) {
+ /* submit site_survey_cmd */
+ ret = rtw_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid, 1, NULL, 0);
+ if (_SUCCESS != ret) {
+ pmlmepriv->to_join = false;
+ }
+ } else {
+ pmlmepriv->to_join = false;
+ ret = _FAIL;
+ }
+
+ goto exit;
+ } else {
+ int select_ret;
+ _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
+ 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);
+ } else {
+ if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ) {
+ /* submit createbss_cmd to change to a ADHOC_MASTER */
+
+ /* pmlmepriv->lock has been acquired by caller... */
+ WLAN_BSSID_EX *pdev_network = &(padapter->registrypriv.dev_network);
+
+ /*pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;*/
+ init_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
+
+ pibss = padapter->registrypriv.dev_network.MacAddress;
+
+ memset(&pdev_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
+ memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(NDIS_802_11_SSID));
+
+ rtw_update_registrypriv_dev_network(padapter);
+
+ rtw_generate_random_ibss(pibss);
+
+ if (rtw_create_ibss_cmd(padapter, 0) != _SUCCESS) {
+ ret = false;
+ goto exit;
+ }
+
+ pmlmepriv->to_join = false;
+
+ } else {
+ /* can't associate ; reset under-linking */
+ _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
+
+ /* 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
+ ) {
+ /* RTW_INFO("rtw_do_join() when no desired bss in scanning queue\n"); */
+ ret = rtw_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid, 1, NULL, 0);
+ if (_SUCCESS != ret) {
+ pmlmepriv->to_join = false;
+ }
+ } else {
+ ret = _FAIL;
+ pmlmepriv->to_join = false;
+ }
+ }
+
+ }
+
+ }
+
+exit:
+
+ return ret;
+}
+
+u8 rtw_set_802_11_bssid(_adapter *padapter, u8 *bssid)
+{
+ unsigned long irqL;
+ u8 status = _SUCCESS;
+
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+
+ 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;
+ }
+
+ _enter_critical_bh(&pmlmepriv->lock, &irqL);
+
+ RTW_INFO("Set BSSID under fw_state=0x%08x\n", get_fwstate(pmlmepriv));
+ if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) )
+ goto handle_tkip_countermeasure;
+ else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) )
+ goto release_mlme_lock;
+
+ if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE) ) {
+
+ if (!memcmp(&pmlmepriv->cur_network.network.MacAddress, bssid, ETH_ALEN) ) {
+ if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == false)
+ goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */
+ } else {
+
+ rtw_disassoc_cmd(padapter, 0, true);
+
+ if (check_fwstate(pmlmepriv, _FW_LINKED) )
+ rtw_indicate_disconnect(padapter, 0, false);
+
+ rtw_free_assoc_resources(padapter, 1);
+
+ if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) )) {
+ _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
+ set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
+ }
+ }
+ }
+
+handle_tkip_countermeasure:
+ if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) {
+ status = _FAIL;
+ goto release_mlme_lock;
+ }
+
+ memset(&pmlmepriv->assoc_ssid, 0, sizeof(NDIS_802_11_SSID));
+ memcpy(&pmlmepriv->assoc_bssid, bssid, ETH_ALEN);
+ pmlmepriv->assoc_by_bssid = true;
+
+ if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) )
+ pmlmepriv->to_join = true;
+ else
+ status = rtw_do_join(padapter);
+
+release_mlme_lock:
+ _exit_critical_bh(&pmlmepriv->lock, &irqL);
+
+exit:
+
+ return status;
+}
+
+u8 rtw_set_802_11_ssid(_adapter *padapter, NDIS_802_11_SSID *ssid)
+{
+ unsigned long irqL;
+ u8 status = _SUCCESS;
+ u32 cur_time = 0;
+
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ struct wlan_network *pnetwork = &pmlmepriv->cur_network;
+
+ RTW_PRINT("set ssid [%s] fw_state=0x%08x\n",
+ ssid->Ssid, get_fwstate(pmlmepriv));
+
+ if (!rtw_is_hw_init_completed(padapter)) {
+ status = _FAIL;
+ goto exit;
+ }
+
+ _enter_critical_bh(&pmlmepriv->lock, &irqL);
+
+ RTW_INFO("Set SSID under fw_state=0x%08x\n", get_fwstate(pmlmepriv));
+ if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) )
+ goto handle_tkip_countermeasure;
+ else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) )
+ goto release_mlme_lock;
+
+ if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE) ) {
+
+ if ((pmlmepriv->assoc_ssid.SsidLength == ssid->SsidLength) &&
+ (!memcmp(&pmlmepriv->assoc_ssid.Ssid, ssid->Ssid, ssid->SsidLength) )) {
+ 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, true);
+
+ if (check_fwstate(pmlmepriv, _FW_LINKED) )
+ rtw_indicate_disconnect(padapter, 0, false);
+
+ rtw_free_assoc_resources(padapter, 1);
+
+ if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ) {
+ _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
+ set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
+ }
+ } else {
+ goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */
+ }
+ }
+#ifdef CONFIG_LPS
+ else
+ rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_JOINBSS, 1);
+#endif
+ } else {
+
+ rtw_disassoc_cmd(padapter, 0, true);
+
+ if (check_fwstate(pmlmepriv, _FW_LINKED) )
+ rtw_indicate_disconnect(padapter, 0, false);
+
+ rtw_free_assoc_resources(padapter, 1);
+
+ if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ) {
+ _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
+ set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
+ }
+ }
+ }
+
+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;
+ }
+
+ memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(NDIS_802_11_SSID));
+ pmlmepriv->assoc_by_bssid = false;
+
+ if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) )
+ pmlmepriv->to_join = true;
+ else
+ status = rtw_do_join(padapter);
+
+release_mlme_lock:
+ _exit_critical_bh(&pmlmepriv->lock, &irqL);
+
+exit:
+
+ return status;
+
+}
+
+u8 rtw_set_802_11_connect(_adapter *padapter, u8 *bssid, NDIS_802_11_SSID *ssid)
+{
+ unsigned long irqL;
+ u8 status = _SUCCESS;
+ u32 cur_time = 0;
+ 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) {
+ 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;
+ }
+
+ if (!rtw_is_hw_init_completed(padapter)) {
+ status = _FAIL;
+ goto exit;
+ }
+
+ _enter_critical_bh(&pmlmepriv->lock, &irqL);
+
+ RTW_PRINT(FUNC_ADPT_FMT" fw_state=0x%08x\n",
+ FUNC_ADPT_ARG(padapter), get_fwstate(pmlmepriv));
+
+ if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) )
+ goto handle_tkip_countermeasure;
+ else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) )
+ 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)
+ memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(NDIS_802_11_SSID));
+ else
+ memset(&pmlmepriv->assoc_ssid, 0, sizeof(NDIS_802_11_SSID));
+
+ if (bssid && bssid_valid) {
+ memcpy(&pmlmepriv->assoc_bssid, bssid, ETH_ALEN);
+ pmlmepriv->assoc_by_bssid = true;
+ } else
+ pmlmepriv->assoc_by_bssid = false;
+
+ if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) )
+ pmlmepriv->to_join = true;
+ else
+ status = rtw_do_join(padapter);
+
+release_mlme_lock:
+ _exit_critical_bh(&pmlmepriv->lock, &irqL);
+
+exit:
+
+ return status;
+}
+
+u8 rtw_set_802_11_infrastructure_mode(_adapter *padapter,
+ NDIS_802_11_NETWORK_INFRASTRUCTURE networktype)
+{
+ unsigned long irqL;
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ struct wlan_network *cur_network = &pmlmepriv->cur_network;
+ NDIS_802_11_NETWORK_INFRASTRUCTURE *pold_state = &(cur_network->network.InfrastructureMode);
+ u8 ap2sta_mode = 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)); */
+
+ if (*pold_state == Ndis802_11APMode) {
+ /* change to other mode from Ndis802_11APMode */
+ cur_network->join_res = -1;
+ ap2sta_mode = true;
+#ifdef CONFIG_NATIVEAP_MLME
+ stop_ap_mode(padapter);
+#endif
+ }
+
+ _enter_critical_bh(&pmlmepriv->lock, &irqL);
+
+ if ((check_fwstate(pmlmepriv, _FW_LINKED) ) || (*pold_state == Ndis802_11IBSS))
+ rtw_disassoc_cmd(padapter, 0, true);
+
+ if ((check_fwstate(pmlmepriv, _FW_LINKED) ) ||
+ (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ))
+ rtw_free_assoc_resources(padapter, 1);
+
+ if ((*pold_state == Ndis802_11Infrastructure) || (*pold_state == Ndis802_11IBSS)) {
+ if (check_fwstate(pmlmepriv, _FW_LINKED) ) {
+ rtw_indicate_disconnect(padapter, 0, false); /*will clr Linked_state; before this function, we must have checked whether issue dis-assoc_cmd or not*/
+ }
+ }
+
+ *pold_state = networktype;
+
+ _clr_fwstate_(pmlmepriv, ~WIFI_NULL_STATE);
+
+ 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
+ start_ap_mode(padapter);
+ /* rtw_indicate_connect(padapter); */
+#endif
+
+ break;
+
+ case Ndis802_11AutoUnknown:
+ case Ndis802_11InfrastructureMax:
+ break;
+ case Ndis802_11Monitor:
+ set_fwstate(pmlmepriv, WIFI_MONITOR_STATE);
+ break;
+ }
+
+ /* SecClearAllKeys(adapter); */
+
+ _exit_critical_bh(&pmlmepriv->lock, &irqL);
+ }
+
+ return true;
+}
+
+u8 rtw_set_802_11_disassociate(_adapter *padapter)
+{
+ unsigned long irqL;
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+
+ _enter_critical_bh(&pmlmepriv->lock, &irqL);
+
+ if (check_fwstate(pmlmepriv, _FW_LINKED) ) {
+
+ rtw_disassoc_cmd(padapter, 0, true);
+ rtw_indicate_disconnect(padapter, 0, false);
+ /* modify for CONFIG_IEEE80211W, none 11w can use it */
+ rtw_free_assoc_resources_cmd(padapter);
+ if (_FAIL == rtw_pwr_wakeup(padapter))
+ RTW_INFO("%s(): rtw_pwr_wakeup fail !!!\n", __func__);
+ }
+
+ _exit_critical_bh(&pmlmepriv->lock, &irqL);
+
+ return true;
+}
+
+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)
+{
+ unsigned long irqL;
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ u8 res = true;
+
+ _enter_critical_bh(&pmlmepriv->lock, &irqL);
+ res = rtw_sitesurvey_cmd(padapter, pssid, ssid_max_num, ch, ch_num);
+ _exit_critical_bh(&pmlmepriv->lock, &irqL);
+
+ return res;
+}
+
+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;
+
+ psecuritypriv->ndisauthtype = authmode;
+
+ if (psecuritypriv->ndisauthtype > 3)
+ psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
+
+#ifdef CONFIG_WAPI_SUPPORT
+ if (psecuritypriv->ndisauthtype == 6)
+ psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
+#endif
+
+ res = rtw_set_auth(padapter, psecuritypriv);
+
+ if (res == _SUCCESS)
+ ret = true;
+ else
+ ret = false;
+
+ return ret;
+}
+
+u8 rtw_set_802_11_add_wep(_adapter *padapter, NDIS_802_11_WEP *wep)
+{
+
+ u8 bdefaultkey;
+ u8 btransmitkey;
+ sint keyid, res;
+ struct security_priv *psecuritypriv = &(padapter->securitypriv);
+ u8 ret = _SUCCESS;
+
+ bdefaultkey = (wep->KeyIndex & 0x40000000) > 0 ? false : true; /* for ??? */
+ btransmitkey = (wep->KeyIndex & 0x80000000) > 0 ? true : false; /* for ??? */
+ keyid = wep->KeyIndex & 0x3fffffff;
+
+ if (keyid >= 4) {
+ ret = false;
+ goto exit;
+ }
+
+ switch (wep->KeyLength) {
+ case 5:
+ psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
+ break;
+ case 13:
+ psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
+ break;
+ default:
+ psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
+ break;
+ }
+
+ memcpy(&(psecuritypriv->dot11DefKey[keyid].skey[0]), &(wep->KeyMaterial), wep->KeyLength);
+
+ psecuritypriv->dot11DefKeylen[keyid] = wep->KeyLength;
+
+ psecuritypriv->dot11PrivacyKeyIndex = keyid;
+
+ res = rtw_set_key(padapter, psecuritypriv, keyid, 1, true);
+
+ if (res == _FAIL)
+ ret = false;
+exit:
+
+ return ret;
+
+}
+
+u8 rtw_set_802_11_remove_wep(_adapter *padapter, u32 keyindex)
+{
+
+ u8 ret = _SUCCESS;
+
+ if (keyindex >= 0x80000000 || padapter == NULL) {
+
+ ret = false;
+ goto exit;
+
+ } else {
+ int res;
+ struct security_priv *psecuritypriv = &(padapter->securitypriv);
+ if (keyindex < 4) {
+
+ memset(&psecuritypriv->dot11DefKey[keyindex], 0, 16);
+
+ res = rtw_set_key(padapter, psecuritypriv, keyindex, 0, true);
+
+ psecuritypriv->dot11DefKeylen[keyindex] = 0;
+
+ if (res == _FAIL)
+ ret = _FAIL;
+
+ } else
+ ret = _FAIL;
+
+ }
+
+exit:
+
+ return ret;
+
+}
+
+u8 rtw_set_802_11_add_key(_adapter *padapter, NDIS_802_11_KEY *key)
+{
+
+ uint encryptionalgo;
+ u8 *pbssid;
+ struct sta_info *stainfo;
+ u8 bgroup = false;
+ u8 bgrouptkey = false;/* can be remove later */
+ u8 ret = _SUCCESS;
+
+ if (((key->KeyIndex & 0x80000000) == 0) && ((key->KeyIndex & 0x40000000) > 0)) {
+
+ /* It is invalid to clear bit 31 and set bit 30. If the miniport driver encounters this combination, */
+ /* it must fail the request and return NDIS_STATUS_INVALID_DATA. */
+ ret = _FAIL;
+ goto exit;
+ }
+
+ if (key->KeyIndex & 0x40000000) {
+ /* Pairwise key */
+
+ pbssid = get_bssid(&padapter->mlmepriv);
+ stainfo = rtw_get_stainfo(&padapter->stapriv, pbssid);
+
+ if ((stainfo != NULL) && (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)) {
+ encryptionalgo = stainfo->dot118021XPrivacy;
+ } else {
+ encryptionalgo = padapter->securitypriv.dot11PrivacyAlgrthm;
+ }
+
+ if (key->KeyIndex & 0x000000FF) {
+ /* The key index is specified in the lower 8 bits by values of zero to 255. */
+ /* The key index should be set to zero for a Pairwise key, and the driver should fail with */
+ /* NDIS_STATUS_INVALID_DATA if the lower 8 bits is not zero */
+ ret = _FAIL;
+ goto exit;
+ }
+
+ /* check BSSID */
+ if (IS_MAC_ADDRESS_BROADCAST(key->BSSID) ) {
+
+ ret = false;
+ goto exit;
+ }
+
+ /* Check key length for TKIP. */
+ /* if(encryptionAlgorithm == RT_ENC_TKIP_ENCRYPTION && key->KeyLength != 32) */
+ if ((encryptionalgo == _TKIP_) && (key->KeyLength != 32)) {
+ ret = _FAIL;
+ goto exit;
+
+ }
+
+ /* Check key length for AES. */
+ if ((encryptionalgo == _AES_) && (key->KeyLength != 16)) {
+ /* For our supplicant, EAPPkt9x.vxd, cannot differentiate TKIP and AES case. */
+ if (key->KeyLength == 32)
+ key->KeyLength = 16;
+ else {
+ ret = _FAIL;
+ goto exit;
+ }
+ }
+
+ /* Check key length for WEP. For NDTEST, 2005.01.27, by rcnjko. -> modify checking condition*/
+ if (((encryptionalgo == _WEP40_) && (key->KeyLength != 5)) || ((encryptionalgo == _WEP104_) && (key->KeyLength != 13))) {
+ ret = _FAIL;
+ goto exit;
+ }
+
+ bgroup = false;
+
+ /* Check the pairwise key. Added by Annie, 2005-07-06. */
+
+ } else {
+ /* Group key - KeyIndex(BIT30==0) */
+
+ /* when add wep key through add key and didn't assigned encryption type before */
+ if ((padapter->securitypriv.ndisauthtype <= 3) && (padapter->securitypriv.dot118021XGrpPrivacy == 0)) {
+
+ switch (key->KeyLength) {
+ case 5:
+ padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
+ break;
+ case 13:
+ padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
+ break;
+ default:
+ padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
+ break;
+ }
+
+ encryptionalgo = padapter->securitypriv.dot11PrivacyAlgrthm;
+
+ } else {
+ encryptionalgo = padapter->securitypriv.dot118021XGrpPrivacy;
+
+ }
+
+ if ((check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE) ) && (IS_MAC_ADDRESS_BROADCAST(key->BSSID) == false)) {
+ ret = _FAIL;
+ goto exit;
+ }
+
+ /* Check key length for TKIP */
+ if ((encryptionalgo == _TKIP_) && (key->KeyLength != 32)) {
+
+ ret = _FAIL;
+ goto exit;
+
+ } else if (encryptionalgo == _AES_ && (key->KeyLength != 16 && key->KeyLength != 32)) {
+
+ /* Check key length for AES */
+ /* For NDTEST, we allow keylen=32 in this case. 2005.01.27, by rcnjko. */
+ ret = _FAIL;
+ goto exit;
+ }
+
+ /* Change the key length for EAPPkt9x.vxd. Added by Annie, 2005-11-03. */
+ if ((encryptionalgo == _AES_) && (key->KeyLength == 32)) {
+ key->KeyLength = 16;
+ }
+
+ if (key->KeyIndex & 0x8000000) /* error ??? 0x8000_0000 */
+ bgrouptkey = true;
+
+ if ((check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE) ) && (check_fwstate(&padapter->mlmepriv, _FW_LINKED) == true))
+ bgrouptkey = true;
+
+ bgroup = true;
+
+ }
+
+ /* If WEP encryption algorithm, just call rtw_set_802_11_add_wep(). */
+ if ((padapter->securitypriv.dot11AuthAlgrthm != dot11AuthAlgrthm_8021X) && (encryptionalgo == _WEP40_ || encryptionalgo == _WEP104_)) {
+ u8 ret;
+ u32 keyindex;
+ u32 len = FIELD_OFFSET(NDIS_802_11_KEY, KeyMaterial) + key->KeyLength;
+ NDIS_802_11_WEP *wep = &padapter->securitypriv.ndiswep;
+
+ wep->Length = len;
+ keyindex = key->KeyIndex & 0x7fffffff;
+ wep->KeyIndex = keyindex ;
+ wep->KeyLength = key->KeyLength;
+
+ memcpy(wep->KeyMaterial, key->KeyMaterial, key->KeyLength);
+ memcpy(&(padapter->securitypriv.dot11DefKey[keyindex].skey[0]), key->KeyMaterial, key->KeyLength);
+
+ padapter->securitypriv.dot11DefKeylen[keyindex] = key->KeyLength;
+ padapter->securitypriv.dot11PrivacyKeyIndex = keyindex;
+
+ ret = rtw_set_802_11_add_wep(padapter, wep);
+
+ goto exit;
+
+ }
+
+ if (key->KeyIndex & 0x20000000) {
+ /* SetRSC */
+ if (bgroup ) {
+ NDIS_802_11_KEY_RSC keysrc = key->KeyRSC & 0x00FFFFFFFFFFFFULL;
+ memcpy(&padapter->securitypriv.dot11Grprxpn, &keysrc, 8);
+ } else {
+ NDIS_802_11_KEY_RSC keysrc = key->KeyRSC & 0x00FFFFFFFFFFFFULL;
+ memcpy(&padapter->securitypriv.dot11Grptxpn, &keysrc, 8);
+ }
+
+ }
+
+ /* Indicate this key idx is used for TX */
+ /* Save the key in KeyMaterial */
+ if (bgroup ) { /* Group transmit key */
+ int res;
+
+ if (bgrouptkey )
+ padapter->securitypriv.dot118021XGrpKeyid = (u8)key->KeyIndex;
+
+ if ((key->KeyIndex & 0x3) == 0) {
+ ret = _FAIL;
+ goto exit;
+ }
+
+ memset(&padapter->securitypriv.dot118021XGrpKey[(u8)((key->KeyIndex) & 0x03)], 0, 16);
+ memset(&padapter->securitypriv.dot118021XGrptxmickey[(u8)((key->KeyIndex) & 0x03)], 0, 16);
+ memset(&padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)], 0, 16);
+
+ if ((key->KeyIndex & 0x10000000)) {
+ memcpy(&padapter->securitypriv.dot118021XGrptxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 16, 8);
+ memcpy(&padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 24, 8);
+
+ } else {
+ memcpy(&padapter->securitypriv.dot118021XGrptxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 24, 8);
+ memcpy(&padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 16, 8);
+
+ }
+
+ /* set group key by index */
+ memcpy(&padapter->securitypriv.dot118021XGrpKey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial, key->KeyLength);
+
+ key->KeyIndex = key->KeyIndex & 0x03;
+
+ padapter->securitypriv.binstallGrpkey = true;
+
+ padapter->securitypriv.bcheck_grpkey = false;
+
+ res = rtw_set_key(padapter, &padapter->securitypriv, key->KeyIndex, 1, true);
+
+ if (res == _FAIL)
+ ret = _FAIL;
+
+ goto exit;
+
+ } else { /* Pairwise Key */
+ u8 res;
+
+ pbssid = get_bssid(&padapter->mlmepriv);
+ stainfo = rtw_get_stainfo(&padapter->stapriv , pbssid);
+
+ if (stainfo != NULL) {
+ memset(&stainfo->dot118021x_UncstKey, 0, 16); /* clear keybuffer */
+
+ memcpy(&stainfo->dot118021x_UncstKey, key->KeyMaterial, 16);
+
+ if (encryptionalgo == _TKIP_) {
+ padapter->securitypriv.busetkipkey = false;
+
+ /* _set_timer(&padapter->securitypriv.tkip_timer, 50); */
+
+ /* if TKIP, save the Receive/Transmit MIC key in KeyMaterial[128-255] */
+ if ((key->KeyIndex & 0x10000000)) {
+ memcpy(&stainfo->dot11tkiptxmickey, key->KeyMaterial + 16, 8);
+ memcpy(&stainfo->dot11tkiprxmickey, key->KeyMaterial + 24, 8);
+
+ } else {
+ memcpy(&stainfo->dot11tkiptxmickey, key->KeyMaterial + 24, 8);
+ memcpy(&stainfo->dot11tkiprxmickey, key->KeyMaterial + 16, 8);
+
+ }
+
+ } else if (encryptionalgo == _AES_) {
+
+ }
+
+ /* Set key to CAM through H2C command */
+
+ res = rtw_setstakey_cmd(padapter, stainfo, UNICAST_KEY, true);
+
+ if (res == false)
+ ret = _FAIL;
+ }
+ }
+
+exit:
+
+ return ret;
+}
+
+u8 rtw_set_802_11_remove_key(_adapter *padapter, NDIS_802_11_REMOVE_KEY *key)
+{
+
+ uint encryptionalgo;
+ u8 *pbssid;
+ struct sta_info *stainfo;
+ u8 bgroup = (key->KeyIndex & 0x4000000) > 0 ? false : true;
+ u8 keyIndex = (u8)key->KeyIndex & 0x03;
+ u8 ret = _SUCCESS;
+
+ if ((key->KeyIndex & 0xbffffffc) > 0) {
+ ret = _FAIL;
+ goto exit;
+ }
+
+ if (bgroup ) {
+ encryptionalgo = padapter->securitypriv.dot118021XGrpPrivacy;
+ /* clear group key by index */
+ /* NdisZeroMemory(Adapter->MgntInfo.SecurityInfo.KeyBuf[keyIndex], MAX_WEP_KEY_LEN); */
+ /* Adapter->MgntInfo.SecurityInfo.KeyLen[keyIndex] = 0; */
+
+ memset(&padapter->securitypriv.dot118021XGrpKey[keyIndex], 0, 16);
+
+ /* ! \todo Send a H2C Command to Firmware for removing this Key in CAM Entry. */
+
+ } else {
+
+ pbssid = get_bssid(&padapter->mlmepriv);
+ stainfo = rtw_get_stainfo(&padapter->stapriv , pbssid);
+ if (stainfo != NULL) {
+ encryptionalgo = stainfo->dot118021XPrivacy;
+
+ /* clear key by BSSID */
+ memset(&stainfo->dot118021x_UncstKey, 0, 16);
+
+ /* ! \todo Send a H2C Command to Firmware for disable this Key in CAM Entry. */
+
+ } else {
+ ret = _FAIL;
+ goto exit;
+ }
+ }
+
+exit:
+
+ return true;
+
+}
+
+/*
+* rtw_get_cur_max_rate -
+* @adapter: pointer to _adapter structure
+*
+* Return 0 or 100Kbps
+*/
+u16 rtw_get_cur_max_rate(_adapter *adapter)
+{
+ int i = 0;
+ u16 rate = 0, max_rate = 0;
+ struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
+ WLAN_BSSID_EX *pcur_bss = &pmlmepriv->cur_network.network;
+ struct sta_info *psta = NULL;
+ u8 short_GI = 0;
+ u8 rf_type = 0;
+
+#ifdef CONFIG_MP_INCLUDED
+ if (adapter->registrypriv.mp_mode == 1) {
+ if (check_fwstate(pmlmepriv, WIFI_MP_STATE) )
+ return 0;
+ }
+#endif
+
+ 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;
+
+ short_GI = query_ra_short_GI(psta, psta->bw_mode);
+
+ if (is_supported_ht(psta->wireless_mode)) {
+ rtw_hal_get_hwreg(adapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
+ max_rate = rtw_mcs_rate(rf_type
+ , (psta->bw_mode == CHANNEL_WIDTH_40) ? 1 : 0
+ , short_GI
+ , psta->htpriv.ht_cap.supp_mcs_set
+ );
+ } else {
+ while ((pcur_bss->SupportedRates[i] != 0) && (pcur_bss->SupportedRates[i] != 0xFF)) {
+ rate = pcur_bss->SupportedRates[i] & 0x7F;
+ if (rate > max_rate)
+ max_rate = rate;
+ i++;
+ }
+
+ max_rate = max_rate * 10 / 2;
+ }
+
+ return max_rate;
+}
+
+/*
+* rtw_set_scan_mode -
+* @adapter: pointer to _adapter structure
+* @scan_mode:
+*
+* Return _SUCCESS or _FAIL
+*/
+int rtw_set_scan_mode(_adapter *adapter, RT_SCAN_TYPE scan_mode)
+{
+ if (scan_mode != SCAN_ACTIVE && scan_mode != SCAN_PASSIVE)
+ return _FAIL;
+
+ adapter->mlmepriv.scan_mode = scan_mode;
+
+ return _SUCCESS;
+}
+
+/*
+* rtw_set_channel_plan -
+* @adapter: pointer to _adapter structure
+* @channel_plan:
+*
+* Return _SUCCESS or _FAIL
+*/
+int rtw_set_channel_plan(_adapter *adapter, u8 channel_plan)
+{
+ struct registry_priv *pregistrypriv = &adapter->registrypriv;
+ struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
+
+ /* handle by cmd_thread to sync with scan operation */
+ return rtw_set_chplan_cmd(adapter, RTW_CMDF_WAIT_ACK, channel_plan, 1);
+}
+
+/*
+* rtw_set_country -
+* @adapter: pointer to _adapter structure
+* @country_code: string of country code
+*
+* Return _SUCCESS or _FAIL
+*/
+int rtw_set_country(_adapter *adapter, const char *country_code)
+{
+#ifdef CONFIG_RTW_IOCTL_SET_COUNTRY
+ return rtw_set_country_cmd(adapter, RTW_CMDF_WAIT_ACK, country_code, 1);
+#else
+ return _FAIL;
+#endif
+}
+
+/*
+* rtw_set_band -
+* @adapter: pointer to _adapter structure
+* @band: band to set
+*
+* Return _SUCCESS or _FAIL
+*/
+int rtw_set_band(_adapter *adapter, u8 band)
+{
+ if (rtw_band_valid(band)) {
+ RTW_INFO(FUNC_ADPT_FMT" band:%d\n", FUNC_ADPT_ARG(adapter), band);
+ adapter->setband = band;
+ return _SUCCESS;
+ }
+
+ RTW_PRINT(FUNC_ADPT_FMT" band:%d fail\n", FUNC_ADPT_ARG(adapter), band);
+ return _FAIL;
+}
diff --git a/drivers/staging/rtl8188eu/core/rtw_iol.c b/drivers/staging/rtl8188eu/core/rtw_iol.c
new file mode 100644
index 000000000000..44ab64cf7a88
--- /dev/null
+++ b/drivers/staging/rtl8188eu/core/rtw_iol.c
@@ -0,0 +1,355 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved. */
+
+
+#include <drv_types.h>
+
+#ifdef CONFIG_IOL
+struct xmit_frame *rtw_IOL_accquire_xmit_frame(ADAPTER *adapter)
+{
+ struct xmit_frame *xmit_frame;
+ struct xmit_buf *xmitbuf;
+ struct pkt_attrib *pattrib;
+ struct xmit_priv *pxmitpriv = &(adapter->xmitpriv);
+
+ xmit_frame = rtw_alloc_xmitframe(pxmitpriv);
+ if (xmit_frame == NULL) {
+ RTW_INFO("%s rtw_alloc_xmitframe return null\n", __func__);
+ goto exit;
+ }
+
+ xmitbuf = rtw_alloc_xmitbuf(pxmitpriv);
+ if (xmitbuf == NULL) {
+ RTW_INFO("%s rtw_alloc_xmitbuf return null\n", __func__);
+ rtw_free_xmitframe(pxmitpriv, xmit_frame);
+ xmit_frame = NULL;
+ goto exit;
+ }
+
+ xmit_frame->frame_tag = MGNT_FRAMETAG;
+ xmit_frame->pxmitbuf = xmitbuf;
+ xmit_frame->buf_addr = xmitbuf->pbuf;
+ xmitbuf->priv_data = xmit_frame;
+
+ pattrib = &xmit_frame->attrib;
+ update_mgntframe_attrib(adapter, pattrib);
+ pattrib->qsel = QSLT_BEACON;/* Beacon */
+ pattrib->subtype = WIFI_BEACON;
+ pattrib->pktlen = pattrib->last_txcmdsz = 0;
+
+exit:
+ return xmit_frame;
+}
+
+int rtw_IOL_append_cmds(struct xmit_frame *xmit_frame, u8 *IOL_cmds, u32 cmd_len)
+{
+ struct pkt_attrib *pattrib = &xmit_frame->attrib;
+ u16 buf_offset;
+ u32 ori_len;
+
+ buf_offset = TXDESC_OFFSET;
+ ori_len = buf_offset + pattrib->pktlen;
+
+ /* check if the io_buf can accommodate new cmds */
+ if (ori_len + cmd_len + 8 > MAX_XMITBUF_SZ) {
+ RTW_INFO("%s %u is large than MAX_XMITBUF_SZ:%u, can't accommodate new cmds\n", __func__
+ , ori_len + cmd_len + 8, MAX_XMITBUF_SZ);
+ return _FAIL;
+ }
+
+ memcpy(xmit_frame->buf_addr + buf_offset + pattrib->pktlen, IOL_cmds, cmd_len);
+ pattrib->pktlen += cmd_len;
+ pattrib->last_txcmdsz += cmd_len;
+
+ /* RTW_INFO("%s ori:%u + cmd_len:%u = %u\n", __func__, ori_len, cmd_len, buf_offset+pattrib->pktlen); */
+
+ return _SUCCESS;
+}
+
+bool rtw_IOL_applied(ADAPTER *adapter)
+{
+ if (1 == adapter->registrypriv.fw_iol)
+ return true;
+
+ if ((2 == adapter->registrypriv.fw_iol) && (IS_FULL_SPEED_USB(adapter)))
+ return true;
+
+ return false;
+}
+
+int rtw_IOL_exec_cmds_sync(ADAPTER *adapter, struct xmit_frame *xmit_frame, u32 max_wating_ms, u32 bndy_cnt)
+{
+ return rtw_hal_iol_cmd(adapter, xmit_frame, max_wating_ms, bndy_cnt);
+}
+
+#ifdef CONFIG_IOL_NEW_GENERATION
+int rtw_IOL_append_LLT_cmd(struct xmit_frame *xmit_frame, u8 page_boundary)
+{
+ return _SUCCESS;
+}
+int _rtw_IOL_append_WB_cmd(struct xmit_frame *xmit_frame, u16 addr, u8 value, u8 mask)
+{
+ struct ioreg_cfg cmd = {8, IOREG_CMD_WB_REG, 0x0, 0x0, 0x0};
+
+ /* RTW_PUT_LE16((u8*)&cmd.address, addr); */
+ /* RTW_PUT_LE32((u8*)&cmd.value, (u32)value); */
+ cmd.address = cpu_to_le16(addr);
+ cmd.data = cpu_to_le32(value);
+
+ if (mask != 0xFF) {
+ cmd.length = 12;
+ /* RTW_PUT_LE32((u8*)&cmd.mask, (u32)mask); */
+ cmd.mask = cpu_to_le32(mask);
+ }
+
+ /* RTW_INFO("%s addr:0x%04x,value:0x%08x,mask:0x%08x\n", __func__, addr,value,mask); */
+
+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, cmd.length);
+
+}
+int _rtw_IOL_append_WW_cmd(struct xmit_frame *xmit_frame, u16 addr, u16 value, u16 mask)
+{
+ struct ioreg_cfg cmd = {8, IOREG_CMD_WW_REG, 0x0, 0x0, 0x0};
+
+ /* RTW_PUT_LE16((u8*)&cmd.address, addr); */
+ /* RTW_PUT_LE32((u8*)&cmd.value, (u32)value); */
+ cmd.address = cpu_to_le16(addr);
+ cmd.data = cpu_to_le32(value);
+
+ if (mask != 0xFFFF) {
+ cmd.length = 12;
+ /* RTW_PUT_LE32((u8*)&cmd.mask, (u32)mask); */
+ cmd.mask = cpu_to_le32(mask);
+ }
+
+ /* RTW_INFO("%s addr:0x%04x,value:0x%08x,mask:0x%08x\n", __func__, addr,value,mask); */
+
+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, cmd.length);
+
+}
+int _rtw_IOL_append_WD_cmd(struct xmit_frame *xmit_frame, u16 addr, u32 value, u32 mask)
+{
+ struct ioreg_cfg cmd = {8, IOREG_CMD_WD_REG, 0x0, 0x0, 0x0};
+
+ /* RTW_PUT_LE16((u8*)&cmd.address, addr); */
+ /* RTW_PUT_LE32((u8*)&cmd.value, (u32)value); */
+ cmd.address = cpu_to_le16(addr);
+ cmd.data = cpu_to_le32(value);
+
+ if (mask != 0xFFFFFFFF) {
+ cmd.length = 12;
+ /* RTW_PUT_LE32((u8*)&cmd.mask, (u32)mask); */
+ cmd.mask = cpu_to_le32(mask);
+ }
+
+ /* RTW_INFO("%s addr:0x%04x,value:0x%08x,mask:0x%08x\n", __FU2NCTION__, addr,value,mask); */
+
+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, cmd.length);
+
+}
+
+int _rtw_IOL_append_WRF_cmd(struct xmit_frame *xmit_frame, u8 rf_path, u16 addr, u32 value, u32 mask)
+{
+ struct ioreg_cfg cmd = {8, IOREG_CMD_W_RF, 0x0, 0x0, 0x0};
+
+ /* RTW_PUT_LE16((u8*)&cmd.address, addr); */
+ /* RTW_PUT_LE32((u8*)&cmd.value, (u32)value); */
+ cmd.address = cpu_to_le16((rf_path << 8) | ((addr) & 0xFF));
+ cmd.data = cpu_to_le32(value);
+
+ if (mask != 0x000FFFFF) {
+ cmd.length = 12;
+ /* RTW_PUT_LE32((u8*)&cmd.mask, (u32)mask); */
+ cmd.mask = cpu_to_le32(mask);
+ }
+
+ /* RTW_INFO("%s rf_path:0x%02x addr:0x%04x,value:0x%08x,mask:0x%08x\n", __FU2NCTION__,rf_path, addr,value,mask); */
+
+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, cmd.length);
+
+}
+
+
+
+int rtw_IOL_append_DELAY_US_cmd(struct xmit_frame *xmit_frame, u16 us)
+{
+ struct ioreg_cfg cmd = {4, IOREG_CMD_DELAY_US, 0x0, 0x0, 0x0};
+ /* RTW_PUT_LE16((u8*)&cmd.address, us); */
+ cmd.address = cpu_to_le16(us);
+
+ /* RTW_INFO("%s %u\n", __func__, us); */
+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 4);
+}
+
+int rtw_IOL_append_DELAY_MS_cmd(struct xmit_frame *xmit_frame, u16 ms)
+{
+ struct ioreg_cfg cmd = {4, IOREG_CMD_DELAY_US, 0x0, 0x0, 0x0};
+
+ /* RTW_PUT_LE16((u8*)&cmd.address, ms); */
+ cmd.address = cpu_to_le16(ms);
+
+ /* RTW_INFO("%s %u\n", __func__, ms); */
+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 4);
+}
+int rtw_IOL_append_END_cmd(struct xmit_frame *xmit_frame)
+{
+ struct ioreg_cfg cmd = {4, IOREG_CMD_END, cpu_to_le16(0xFFFF), cpu_to_le32(0xFF), 0x0};
+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 4);
+
+}
+
+u8 rtw_IOL_cmd_boundary_handle(struct xmit_frame *pxmit_frame)
+{
+ u8 is_cmd_bndy = false;
+ if (((pxmit_frame->attrib.pktlen + 32) % 256) + 8 >= 256) {
+ rtw_IOL_append_END_cmd(pxmit_frame);
+ pxmit_frame->attrib.pktlen = ((((pxmit_frame->attrib.pktlen + 32) / 256) + 1) * 256);
+
+ /* RTW_INFO("==> %s, pktlen(%d)\n",__func__,pxmit_frame->attrib.pktlen); */
+ pxmit_frame->attrib.last_txcmdsz = pxmit_frame->attrib.pktlen;
+ is_cmd_bndy = true;
+ }
+ return is_cmd_bndy;
+}
+
+void rtw_IOL_cmd_buf_dump(ADAPTER *Adapter, int buf_len, u8 *pbuf)
+{
+ int i;
+ int j = 1;
+
+ RTW_INFO("###### %s ######\n", __func__);
+ for (i = 0; i < buf_len; i++) {
+ RTW_INFO("%02x-", *(pbuf + i));
+
+ if (j % 32 == 0)
+ RTW_INFO("\n");
+ j++;
+ }
+ RTW_INFO("\n");
+ RTW_INFO("============= ioreg_cmd len = %d ===============\n", buf_len);
+}
+
+
+#else /* CONFIG_IOL_NEW_GENERATION */
+int rtw_IOL_append_LLT_cmd(struct xmit_frame *xmit_frame, u8 page_boundary)
+{
+ IOL_CMD cmd = {0x0, IOL_CMD_LLT, 0x0, 0x0};
+
+ RTW_PUT_BE32((u8 *)&cmd.value, (u32)page_boundary);
+
+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 8);
+}
+
+int _rtw_IOL_append_WB_cmd(struct xmit_frame *xmit_frame, u16 addr, u8 value)
+{
+ IOL_CMD cmd = {0x0, IOL_CMD_WB_REG, 0x0, 0x0};
+
+ RTW_PUT_BE16((u8 *)&cmd.address, (u16)addr);
+ RTW_PUT_BE32((u8 *)&cmd.value, (u32)value);
+
+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 8);
+}
+
+int _rtw_IOL_append_WW_cmd(struct xmit_frame *xmit_frame, u16 addr, u16 value)
+{
+ IOL_CMD cmd = {0x0, IOL_CMD_WW_REG, 0x0, 0x0};
+
+ RTW_PUT_BE16((u8 *)&cmd.address, (u16)addr);
+ RTW_PUT_BE32((u8 *)&cmd.value, (u32)value);
+
+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 8);
+}
+
+int _rtw_IOL_append_WD_cmd(struct xmit_frame *xmit_frame, u16 addr, u32 value)
+{
+ IOL_CMD cmd = {0x0, IOL_CMD_WD_REG, 0x0, 0x0};
+ u8 *pos = (u8 *)&cmd;
+
+ RTW_PUT_BE16((u8 *)&cmd.address, (u16)addr);
+ RTW_PUT_BE32((u8 *)&cmd.value, (u32)value);
+
+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 8);
+}
+
+#ifdef DBG_IO
+int dbg_rtw_IOL_append_WB_cmd(struct xmit_frame *xmit_frame, u16 addr, u8 value, const char *caller, const int line)
+{
+ if (match_write_sniff_ranges(addr, 1))
+ RTW_INFO("DBG_IO %s:%d IOL_WB(0x%04x, 0x%02x)\n", caller, line, addr, value);
+
+ return _rtw_IOL_append_WB_cmd(xmit_frame, addr, value);
+}
+
+int dbg_rtw_IOL_append_WW_cmd(struct xmit_frame *xmit_frame, u16 addr, u16 value, const char *caller, const int line)
+{
+ if (match_write_sniff_ranges(addr, 2))
+ RTW_INFO("DBG_IO %s:%d IOL_WW(0x%04x, 0x%04x)\n", caller, line, addr, value);
+
+ return _rtw_IOL_append_WW_cmd(xmit_frame, addr, value);
+}
+
+int dbg_rtw_IOL_append_WD_cmd(struct xmit_frame *xmit_frame, u16 addr, u32 value, const char *caller, const int line)
+{
+ if (match_write_sniff_ranges(addr, 4))
+ RTW_INFO("DBG_IO %s:%d IOL_WD(0x%04x, 0x%08x)\n", caller, line, addr, value);
+
+ return _rtw_IOL_append_WD_cmd(xmit_frame, addr, value);
+}
+#endif
+
+int rtw_IOL_append_DELAY_US_cmd(struct xmit_frame *xmit_frame, u16 us)
+{
+ IOL_CMD cmd = {0x0, IOL_CMD_DELAY_US, 0x0, 0x0};
+
+ RTW_PUT_BE32((u8 *)&cmd.value, (u32)us);
+
+ /* RTW_INFO("%s %u\n", __func__, us); */
+
+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 8);
+}
+
+int rtw_IOL_append_DELAY_MS_cmd(struct xmit_frame *xmit_frame, u16 ms)
+{
+ IOL_CMD cmd = {0x0, IOL_CMD_DELAY_MS, 0x0, 0x0};
+
+ RTW_PUT_BE32((u8 *)&cmd.value, (u32)ms);
+
+ /* RTW_INFO("%s %u\n", __func__, ms); */
+
+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 8);
+}
+
+int rtw_IOL_append_END_cmd(struct xmit_frame *xmit_frame)
+{
+ IOL_CMD end_cmd = {0x0, IOL_CMD_END, 0x0, 0x0};
+
+
+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&end_cmd, 8);
+
+}
+
+int rtw_IOL_exec_cmd_array_sync(PADAPTER adapter, u8 *IOL_cmds, u32 cmd_num, u32 max_wating_ms)
+{
+ struct xmit_frame *xmit_frame;
+
+ xmit_frame = rtw_IOL_accquire_xmit_frame(adapter);
+ if (xmit_frame == NULL)
+ return _FAIL;
+
+ if (rtw_IOL_append_cmds(xmit_frame, IOL_cmds, cmd_num << 3) == _FAIL)
+ return _FAIL;
+
+ return rtw_IOL_exec_cmds_sync(adapter, xmit_frame, max_wating_ms, 0);
+}
+
+int rtw_IOL_exec_empty_cmds_sync(ADAPTER *adapter, u32 max_wating_ms)
+{
+ IOL_CMD end_cmd = {0x0, IOL_CMD_END, 0x0, 0x0};
+ return rtw_IOL_exec_cmd_array_sync(adapter, (u8 *)&end_cmd, 1, max_wating_ms);
+}
+#endif /* CONFIG_IOL_NEW_GENERATION */
+
+
+
+
+#endif /* CONFIG_IOL */
diff --git a/drivers/staging/rtl8188eu/core/rtw_led.c b/drivers/staging/rtl8188eu/core/rtw_led.c
new file mode 100644
index 000000000000..6422dc57853a
--- /dev/null
+++ b/drivers/staging/rtl8188eu/core/rtw_led.c
@@ -0,0 +1,1705 @@
+/******************************************************************************
+ *
+ * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
+ *
+ *
+ ******************************************************************************/
+
+#include <drv_types.h>
+#include "rtw_led.h"
+
+/* */
+/* Description: */
+/* Callback function of LED BlinkTimer, */
+/* it just schedules to corresponding BlinkWorkItem/led_blink_hdl */
+/* */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
+void BlinkTimerCallback(struct timer_list *t)
+#else
+void BlinkTimerCallback(void *data)
+#endif
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
+ struct LED_871x *pLed = from_timer(pLed, t, BlinkTimer);
+#else
+ struct LED_871x *pLed = (struct LED_871x *)data;
+#endif
+ struct adapter *padapter = pLed->padapter;
+
+ if ((padapter->bSurpriseRemoved) || (padapter->bDriverStopped))
+ return;
+
+ _set_workitem(&(pLed->BlinkWorkItem));
+}
+
+/* */
+/* Description: */
+/* Callback function of LED BlinkWorkItem. */
+/* We dispatch acture LED blink action according to LedStrategy. */
+/* */
+void BlinkWorkItemCallback(struct work_struct *work)
+{
+ struct LED_871x *pLed = container_of(work, struct LED_871x, BlinkWorkItem);
+ BlinkHandler(pLed);
+}
+
+/* */
+/* Description: */
+/* Reset status of LED_871x object. */
+/* */
+void ResetLedStatus(struct LED_871x *pLed)
+{
+ pLed->CurrLedState = RTW_LED_OFF; /* Current LED state. */
+ pLed->bLedOn = false; /* true if LED is ON, false if LED is OFF. */
+
+ pLed->bLedBlinkInProgress = false; /* true if it is blinking, false o.w.. */
+ pLed->bLedWPSBlinkInProgress = false;
+
+ pLed->BlinkTimes = 0; /* Number of times to toggle led state for blinking. */
+ pLed->BlinkingLedState = LED_UNKNOWN; /* Next state for blinking, either RTW_LED_ON or RTW_LED_OFF are. */
+
+ pLed->bLedNoLinkBlinkInProgress = false;
+ pLed->bLedLinkBlinkInProgress = false;
+ pLed->bLedStartToLinkBlinkInProgress = false;
+ pLed->bLedScanBlinkInProgress = false;
+}
+
+/*Description: */
+/* Initialize an LED_871x object. */
+void InitLed871x(struct adapter *padapter, struct LED_871x *pLed, enum LED_PIN_871x LedPin)
+{
+ pLed->padapter = padapter;
+ pLed->LedPin = LedPin;
+
+ ResetLedStatus(pLed);
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
+ timer_setup(&pLed->BlinkTimer, BlinkTimerCallback, 0);
+#else
+ _init_timer(&(pLed->BlinkTimer), padapter->pnetdev, BlinkTimerCallback, pLed);
+#endif
+ _init_workitem(&(pLed->BlinkWorkItem), BlinkWorkItemCallback, pLed);
+}
+
+/* */
+/* Description: */
+/* DeInitialize an LED_871x object. */
+/* */
+void DeInitLed871x(struct LED_871x *pLed)
+{
+ _cancel_workitem_sync(&(pLed->BlinkWorkItem));
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ ResetLedStatus(pLed);
+}
+
+/* */
+/* Description: */
+/* Implementation of LED blinking behavior. */
+/* It toggle off LED and schedule corresponding timer if necessary. */
+/* */
+
+static void SwLedBlink(struct LED_871x *pLed)
+{
+ struct adapter *padapter = pLed->padapter;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ u8 bStopBlinking = false;
+
+ /* Change LED according to BlinkingLedState specified. */
+ if (pLed->BlinkingLedState == RTW_LED_ON) {
+ SwLedOn(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
+ } else {
+ SwLedOff(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
+ }
+
+ /* Determine if we shall change LED state again. */
+ pLed->BlinkTimes--;
+ switch (pLed->CurrLedState) {
+ case LED_BLINK_NORMAL:
+ if (pLed->BlinkTimes == 0)
+ bStopBlinking = true;
+ break;
+ case LED_BLINK_StartToBlink:
+ if (check_fwstate(pmlmepriv, _FW_LINKED) && check_fwstate(pmlmepriv, WIFI_STATION_STATE))
+ bStopBlinking = true;
+ if (check_fwstate(pmlmepriv, _FW_LINKED) &&
+ (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
+ check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)))
+ bStopBlinking = true;
+ else if (pLed->BlinkTimes == 0)
+ bStopBlinking = true;
+ break;
+ case LED_BLINK_WPS:
+ if (pLed->BlinkTimes == 0)
+ bStopBlinking = true;
+ break;
+ default:
+ bStopBlinking = true;
+ break;
+ }
+
+ if (bStopBlinking) {
+ /* if (padapter->pwrctrlpriv.cpwm >= PS_STATE_S2) */
+ if (0) {
+ SwLedOff(padapter, pLed);
+ } else if ((check_fwstate(pmlmepriv, _FW_LINKED)) && (!pLed->bLedOn)) {
+ SwLedOn(padapter, pLed);
+ } else if ((check_fwstate(pmlmepriv, _FW_LINKED)) && pLed->bLedOn) {
+ SwLedOff(padapter, pLed);
+ }
+ pLed->BlinkTimes = 0;
+ pLed->bLedBlinkInProgress = false;
+ } else {
+ /* Assign LED state to toggle. */
+ if (pLed->BlinkingLedState == RTW_LED_ON)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+
+ /* Schedule a timer to toggle LED state. */
+ switch (pLed->CurrLedState) {
+ case LED_BLINK_NORMAL:
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NORMAL_INTERVAL);
+ break;
+ case LED_BLINK_SLOWLY:
+ case LED_BLINK_StartToBlink:
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SLOWLY_INTERVAL);
+ break;
+ case LED_BLINK_WPS:
+ if (pLed->BlinkingLedState == RTW_LED_ON)
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_LONG_INTERVAL);
+ else
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_LONG_INTERVAL);
+ break;
+ default:
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SLOWLY_INTERVAL);
+ break;
+ }
+ }
+}
+
+static void SwLedBlink1(struct LED_871x *pLed)
+{
+ struct adapter *padapter = pLed->padapter;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ u8 bStopBlinking = false;
+
+ /* Change LED according to BlinkingLedState specified. */
+ if (pLed->BlinkingLedState == RTW_LED_ON) {
+ SwLedOn(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
+ } else {
+ SwLedOff(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
+ }
+
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
+ SwLedOff(padapter, pLed);
+ ResetLedStatus(pLed);
+ return;
+ }
+
+ switch (pLed->CurrLedState) {
+ case LED_BLINK_SLOWLY:
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NO_LINK_INTERVAL_ALPHA);
+ break;
+ case LED_BLINK_NORMAL:
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_LINK_INTERVAL_ALPHA);
+ break;
+ case LED_BLINK_SCAN:
+ pLed->BlinkTimes--;
+ if (pLed->BlinkTimes == 0)
+ bStopBlinking = true;
+ if (bStopBlinking) {
+ if (check_fwstate(pmlmepriv, _FW_LINKED)) {
+ pLed->bLedLinkBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_NORMAL;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_LINK_INTERVAL_ALPHA);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
+ } else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
+ pLed->bLedNoLinkBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_SLOWLY;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NO_LINK_INTERVAL_ALPHA);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
+ }
+ pLed->bLedScanBlinkInProgress = false;
+ } else {
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SCAN_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_BLINK_TXRX:
+ pLed->BlinkTimes--;
+ if (pLed->BlinkTimes == 0)
+ bStopBlinking = true;
+ if (bStopBlinking) {
+ if (check_fwstate(pmlmepriv, _FW_LINKED)) {
+ pLed->bLedLinkBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_NORMAL;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_LINK_INTERVAL_ALPHA);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
+ } else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
+ pLed->bLedNoLinkBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_SLOWLY;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NO_LINK_INTERVAL_ALPHA);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
+ }
+ pLed->BlinkTimes = 0;
+ pLed->bLedBlinkInProgress = false;
+ } else {
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_FASTER_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_BLINK_WPS:
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SCAN_INTERVAL_ALPHA);
+ break;
+ case LED_BLINK_WPS_STOP: /* WPS success */
+ if (pLed->BlinkingLedState == RTW_LED_ON)
+ bStopBlinking = false;
+ else
+ bStopBlinking = true;
+
+ if (bStopBlinking) {
+ pLed->bLedLinkBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_NORMAL;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_LINK_INTERVAL_ALPHA);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
+
+ pLed->bLedWPSBlinkInProgress = false;
+ } else {
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+static void SwLedBlink2(struct LED_871x *pLed)
+{
+ struct adapter *padapter = pLed->padapter;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ u8 bStopBlinking = false;
+
+ /* Change LED according to BlinkingLedState specified. */
+ if (pLed->BlinkingLedState == RTW_LED_ON) {
+ SwLedOn(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
+ } else {
+ SwLedOff(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
+ }
+
+ switch (pLed->CurrLedState) {
+ case LED_BLINK_SCAN:
+ pLed->BlinkTimes--;
+ if (pLed->BlinkTimes == 0)
+ bStopBlinking = true;
+ if (bStopBlinking) {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
+ SwLedOff(padapter, pLed);
+ } else if (check_fwstate(pmlmepriv, _FW_LINKED)) {
+ pLed->CurrLedState = RTW_LED_ON;
+ pLed->BlinkingLedState = RTW_LED_ON;
+ SwLedOn(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("stop scan blink CurrLedState %d\n", pLed->CurrLedState));
+
+ } else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
+ pLed->CurrLedState = RTW_LED_OFF;
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ SwLedOff(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("stop scan blink CurrLedState %d\n", pLed->CurrLedState));
+ }
+ pLed->bLedScanBlinkInProgress = false;
+ } else {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
+ SwLedOff(padapter, pLed);
+ } else {
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SCAN_INTERVAL_ALPHA);
+ }
+ }
+ break;
+ case LED_BLINK_TXRX:
+ pLed->BlinkTimes--;
+ if (pLed->BlinkTimes == 0)
+ bStopBlinking = true;
+ if (bStopBlinking) {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
+ SwLedOff(padapter, pLed);
+ } else if (check_fwstate(pmlmepriv, _FW_LINKED)) {
+ pLed->CurrLedState = RTW_LED_ON;
+ pLed->BlinkingLedState = RTW_LED_ON;
+ SwLedOn(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("stop CurrLedState %d\n", pLed->CurrLedState));
+ } else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
+ pLed->CurrLedState = RTW_LED_OFF;
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ SwLedOff(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("stop CurrLedState %d\n", pLed->CurrLedState));
+ }
+ pLed->bLedBlinkInProgress = false;
+ } else {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
+ SwLedOff(padapter, pLed);
+ } else {
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_FASTER_INTERVAL_ALPHA);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+static void SwLedBlink3(struct LED_871x *pLed)
+{
+ struct adapter *padapter = pLed->padapter;
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+ u8 bStopBlinking = false;
+
+ /* Change LED according to BlinkingLedState specified. */
+ if (pLed->BlinkingLedState == RTW_LED_ON) {
+ SwLedOn(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
+ } else {
+ if (pLed->CurrLedState != LED_BLINK_WPS_STOP)
+ SwLedOff(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
+ }
+
+ switch (pLed->CurrLedState) {
+ case LED_BLINK_SCAN:
+ pLed->BlinkTimes--;
+ if (pLed->BlinkTimes == 0)
+ bStopBlinking = true;
+ if (bStopBlinking) {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
+ SwLedOff(padapter, pLed);
+ } else if (check_fwstate(pmlmepriv, _FW_LINKED)) {
+ pLed->CurrLedState = RTW_LED_ON;
+ pLed->BlinkingLedState = RTW_LED_ON;
+ if (!pLed->bLedOn)
+ SwLedOn(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
+ } else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
+ pLed->CurrLedState = RTW_LED_OFF;
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ if (pLed->bLedOn)
+ SwLedOff(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
+ }
+ pLed->bLedScanBlinkInProgress = false;
+ } else {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
+ SwLedOff(padapter, pLed);
+ } else {
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SCAN_INTERVAL_ALPHA);
+ }
+ }
+ break;
+ case LED_BLINK_TXRX:
+ pLed->BlinkTimes--;
+ if (pLed->BlinkTimes == 0)
+ bStopBlinking = true;
+ if (bStopBlinking) {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
+ SwLedOff(padapter, pLed);
+ } else if (check_fwstate(pmlmepriv, _FW_LINKED)) {
+ pLed->CurrLedState = RTW_LED_ON;
+ pLed->BlinkingLedState = RTW_LED_ON;
+ if (!pLed->bLedOn)
+ SwLedOn(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
+ } else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
+ pLed->CurrLedState = RTW_LED_OFF;
+ pLed->BlinkingLedState = RTW_LED_OFF;
+
+ if (pLed->bLedOn)
+ SwLedOff(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
+ }
+ pLed->bLedBlinkInProgress = false;
+ } else {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
+ SwLedOff(padapter, pLed);
+ } else {
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_FASTER_INTERVAL_ALPHA);
+ }
+ }
+ break;
+ case LED_BLINK_WPS:
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SCAN_INTERVAL_ALPHA);
+ break;
+ case LED_BLINK_WPS_STOP: /* WPS success */
+ if (pLed->BlinkingLedState == RTW_LED_ON) {
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA);
+ bStopBlinking = false;
+ } else {
+ bStopBlinking = true;
+ }
+ if (bStopBlinking) {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
+ SwLedOff(padapter, pLed);
+ } else {
+ pLed->CurrLedState = RTW_LED_ON;
+ pLed->BlinkingLedState = RTW_LED_ON;
+ SwLedOn(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
+ }
+ pLed->bLedWPSBlinkInProgress = false;
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+static void SwLedBlink4(struct LED_871x *pLed)
+{
+ struct adapter *padapter = pLed->padapter;
+ struct led_priv *ledpriv = &(padapter->ledpriv);
+ struct LED_871x *pLed1 = &(ledpriv->SwLed1);
+ u8 bStopBlinking = false;
+
+ /* Change LED according to BlinkingLedState specified. */
+ if (pLed->BlinkingLedState == RTW_LED_ON) {
+ SwLedOn(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
+ } else {
+ SwLedOff(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
+ }
+
+ if (!pLed1->bLedWPSBlinkInProgress && pLed1->BlinkingLedState == LED_UNKNOWN) {
+ pLed1->BlinkingLedState = RTW_LED_OFF;
+ pLed1->CurrLedState = RTW_LED_OFF;
+ SwLedOff(padapter, pLed1);
+ }
+
+ switch (pLed->CurrLedState) {
+ case LED_BLINK_SLOWLY:
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NO_LINK_INTERVAL_ALPHA);
+ break;
+ case LED_BLINK_StartToBlink:
+ if (pLed->bLedOn) {
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SLOWLY_INTERVAL);
+ } else {
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NORMAL_INTERVAL);
+ }
+ break;
+ case LED_BLINK_SCAN:
+ pLed->BlinkTimes--;
+ if (pLed->BlinkTimes == 0)
+ bStopBlinking = false;
+ if (bStopBlinking) {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
+ SwLedOff(padapter, pLed);
+ } else {
+ pLed->bLedNoLinkBlinkInProgress = false;
+ pLed->CurrLedState = LED_BLINK_SLOWLY;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NO_LINK_INTERVAL_ALPHA);
+ }
+ pLed->bLedScanBlinkInProgress = false;
+ } else {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
+ SwLedOff(padapter, pLed);
+ } else {
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SCAN_INTERVAL_ALPHA);
+ }
+ }
+ break;
+ case LED_BLINK_TXRX:
+ pLed->BlinkTimes--;
+ if (pLed->BlinkTimes == 0)
+ bStopBlinking = true;
+ if (bStopBlinking) {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
+ SwLedOff(padapter, pLed);
+ } else {
+ pLed->bLedNoLinkBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_SLOWLY;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NO_LINK_INTERVAL_ALPHA);
+ }
+ pLed->bLedBlinkInProgress = false;
+ } else {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
+ SwLedOff(padapter, pLed);
+ } else {
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_FASTER_INTERVAL_ALPHA);
+ }
+ }
+ break;
+ case LED_BLINK_WPS:
+ if (pLed->bLedOn) {
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SLOWLY_INTERVAL);
+ } else {
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NORMAL_INTERVAL);
+ }
+ break;
+ case LED_BLINK_WPS_STOP: /* WPS authentication fail */
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NORMAL_INTERVAL);
+ break;
+ case LED_BLINK_WPS_STOP_OVERLAP: /* WPS session overlap */
+ pLed->BlinkTimes--;
+ if (pLed->BlinkTimes == 0) {
+ if (pLed->bLedOn)
+ pLed->BlinkTimes = 1;
+ else
+ bStopBlinking = true;
+ }
+
+ if (bStopBlinking) {
+ pLed->BlinkTimes = 10;
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_LINK_INTERVAL_ALPHA);
+ } else {
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NORMAL_INTERVAL);
+ }
+ break;
+ default:
+ break;
+ }
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("SwLedBlink4 CurrLedState %d\n", pLed->CurrLedState));
+}
+
+static void SwLedBlink5(struct LED_871x *pLed)
+{
+ struct adapter *padapter = pLed->padapter;
+ u8 bStopBlinking = false;
+
+ /* Change LED according to BlinkingLedState specified. */
+ if (pLed->BlinkingLedState == RTW_LED_ON) {
+ SwLedOn(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
+ } else {
+ SwLedOff(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
+ }
+
+ switch (pLed->CurrLedState) {
+ case LED_BLINK_SCAN:
+ pLed->BlinkTimes--;
+ if (pLed->BlinkTimes == 0)
+ bStopBlinking = true;
+
+ if (bStopBlinking) {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
+ pLed->CurrLedState = RTW_LED_OFF;
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ if (pLed->bLedOn)
+ SwLedOff(padapter, pLed);
+ } else {
+ pLed->CurrLedState = RTW_LED_ON;
+ pLed->BlinkingLedState = RTW_LED_ON;
+ if (!pLed->bLedOn)
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_FASTER_INTERVAL_ALPHA);
+ }
+
+ pLed->bLedScanBlinkInProgress = false;
+ } else {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
+ SwLedOff(padapter, pLed);
+ } else {
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SCAN_INTERVAL_ALPHA);
+ }
+ }
+ break;
+ case LED_BLINK_TXRX:
+ pLed->BlinkTimes--;
+ if (pLed->BlinkTimes == 0)
+ bStopBlinking = true;
+
+ if (bStopBlinking) {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
+ pLed->CurrLedState = RTW_LED_OFF;
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ if (pLed->bLedOn)
+ SwLedOff(padapter, pLed);
+ } else {
+ pLed->CurrLedState = RTW_LED_ON;
+ pLed->BlinkingLedState = RTW_LED_ON;
+ if (!pLed->bLedOn)
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_FASTER_INTERVAL_ALPHA);
+ }
+
+ pLed->bLedBlinkInProgress = false;
+ } else {
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
+ SwLedOff(padapter, pLed);
+ } else {
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_FASTER_INTERVAL_ALPHA);
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("SwLedBlink5 CurrLedState %d\n", pLed->CurrLedState));
+}
+
+static void SwLedBlink6(struct LED_871x *pLed)
+{
+ struct adapter *padapter = pLed->padapter;
+
+ /* Change LED according to BlinkingLedState specified. */
+ if (pLed->BlinkingLedState == RTW_LED_ON) {
+ SwLedOn(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
+ } else {
+ SwLedOff(padapter, pLed);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
+ }
+
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("<==== blink6\n"));
+}
+
+ /* ALPHA, added by chiyoko, 20090106 */
+static void SwLedControlMode1(struct adapter *padapter, enum LED_CTL_MODE LedAction)
+{
+ struct led_priv *ledpriv = &(padapter->ledpriv);
+ struct LED_871x *pLed = &(ledpriv->SwLed0);
+ struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+
+ switch (LedAction) {
+ case LED_CTL_POWER_ON:
+ case LED_CTL_START_TO_LINK:
+ case LED_CTL_NO_LINK:
+ if (!pLed->bLedNoLinkBlinkInProgress) {
+ if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed))
+ return;
+ if (pLed->bLedLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedLinkBlinkInProgress = false;
+ }
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+
+ pLed->bLedNoLinkBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_SLOWLY;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NO_LINK_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_CTL_LINK:
+ if (!pLed->bLedLinkBlinkInProgress) {
+ if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed))
+ return;
+ if (pLed->bLedNoLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedNoLinkBlinkInProgress = false;
+ }
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ pLed->bLedLinkBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_NORMAL;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_LINK_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_CTL_SITE_SURVEY:
+ if ((pmlmepriv->LinkDetectInfo.bBusyTraffic) && (check_fwstate(pmlmepriv, _FW_LINKED))) {
+ ;
+ } else if (!pLed->bLedScanBlinkInProgress) {
+ if (IS_LED_WPS_BLINKING(pLed))
+ return;
+ if (pLed->bLedNoLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedNoLinkBlinkInProgress = false;
+ }
+ if (pLed->bLedLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedLinkBlinkInProgress = false;
+ }
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ pLed->bLedScanBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_SCAN;
+ pLed->BlinkTimes = 24;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SCAN_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_CTL_TX:
+ case LED_CTL_RX:
+ if (!pLed->bLedBlinkInProgress) {
+ if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed))
+ return;
+ if (pLed->bLedNoLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedNoLinkBlinkInProgress = false;
+ }
+ if (pLed->bLedLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedLinkBlinkInProgress = false;
+ }
+ pLed->bLedBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_TXRX;
+ pLed->BlinkTimes = 2;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_FASTER_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_CTL_START_WPS: /* wait until xinpin finish */
+ case LED_CTL_START_WPS_BOTTON:
+ if (!pLed->bLedWPSBlinkInProgress) {
+ if (pLed->bLedNoLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedNoLinkBlinkInProgress = false;
+ }
+ if (pLed->bLedLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedLinkBlinkInProgress = false;
+ }
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ if (pLed->bLedScanBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedScanBlinkInProgress = false;
+ }
+ pLed->bLedWPSBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_WPS;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SCAN_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_CTL_STOP_WPS:
+ if (pLed->bLedNoLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedNoLinkBlinkInProgress = false;
+ }
+ if (pLed->bLedLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedLinkBlinkInProgress = false;
+ }
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ if (pLed->bLedScanBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedScanBlinkInProgress = false;
+ }
+ if (pLed->bLedWPSBlinkInProgress)
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ else
+ pLed->bLedWPSBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_WPS_STOP;
+ if (pLed->bLedOn) {
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA);
+ } else {
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), 0);
+ }
+ break;
+ case LED_CTL_STOP_WPS_FAIL:
+ if (pLed->bLedWPSBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedWPSBlinkInProgress = false;
+ }
+ pLed->bLedNoLinkBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_SLOWLY;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NO_LINK_INTERVAL_ALPHA);
+ break;
+ case LED_CTL_POWER_OFF:
+ pLed->CurrLedState = RTW_LED_OFF;
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ if (pLed->bLedNoLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedNoLinkBlinkInProgress = false;
+ }
+ if (pLed->bLedLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedLinkBlinkInProgress = false;
+ }
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ if (pLed->bLedWPSBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedWPSBlinkInProgress = false;
+ }
+ if (pLed->bLedScanBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedScanBlinkInProgress = false;
+ }
+ SwLedOff(padapter, pLed);
+ break;
+ default:
+ break;
+ }
+
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Led %d\n", pLed->CurrLedState));
+}
+
+ /* Arcadyan/Sitecom , added by chiyoko, 20090216 */
+static void SwLedControlMode2(struct adapter *padapter, enum LED_CTL_MODE LedAction)
+{
+ struct led_priv *ledpriv = &(padapter->ledpriv);
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ struct LED_871x *pLed = &(ledpriv->SwLed0);
+
+ switch (LedAction) {
+ case LED_CTL_SITE_SURVEY:
+ if (pmlmepriv->LinkDetectInfo.bBusyTraffic) {
+ } else if (!pLed->bLedScanBlinkInProgress) {
+ if (IS_LED_WPS_BLINKING(pLed))
+ return;
+
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ pLed->bLedScanBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_SCAN;
+ pLed->BlinkTimes = 24;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SCAN_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_CTL_TX:
+ case LED_CTL_RX:
+ if ((!pLed->bLedBlinkInProgress) && (check_fwstate(pmlmepriv, _FW_LINKED))) {
+ if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed))
+ return;
+ pLed->bLedBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_TXRX;
+ pLed->BlinkTimes = 2;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_FASTER_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_CTL_LINK:
+ pLed->CurrLedState = RTW_LED_ON;
+ pLed->BlinkingLedState = RTW_LED_ON;
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ if (pLed->bLedScanBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedScanBlinkInProgress = false;
+ }
+ _set_timer(&(pLed->BlinkTimer), 0);
+ break;
+ case LED_CTL_START_WPS: /* wait until xinpin finish */
+ case LED_CTL_START_WPS_BOTTON:
+ if (!pLed->bLedWPSBlinkInProgress) {
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ if (pLed->bLedScanBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedScanBlinkInProgress = false;
+ }
+ pLed->bLedWPSBlinkInProgress = true;
+ pLed->CurrLedState = RTW_LED_ON;
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), 0);
+ }
+ break;
+ case LED_CTL_STOP_WPS:
+ pLed->bLedWPSBlinkInProgress = false;
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
+ SwLedOff(padapter, pLed);
+ } else {
+ pLed->CurrLedState = RTW_LED_ON;
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), 0);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
+ }
+ break;
+ case LED_CTL_STOP_WPS_FAIL:
+ pLed->bLedWPSBlinkInProgress = false;
+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
+ SwLedOff(padapter, pLed);
+ } else {
+ pLed->CurrLedState = RTW_LED_OFF;
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ _set_timer(&(pLed->BlinkTimer), 0);
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
+ }
+ break;
+ case LED_CTL_START_TO_LINK:
+ case LED_CTL_NO_LINK:
+ if (!IS_LED_BLINKING(pLed)) {
+ pLed->CurrLedState = RTW_LED_OFF;
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ _set_timer(&(pLed->BlinkTimer), 0);
+ }
+ break;
+ case LED_CTL_POWER_OFF:
+ pLed->CurrLedState = RTW_LED_OFF;
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ if (pLed->bLedScanBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedScanBlinkInProgress = false;
+ }
+ if (pLed->bLedWPSBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedWPSBlinkInProgress = false;
+ }
+
+ _set_timer(&(pLed->BlinkTimer), 0);
+ break;
+ default:
+ break;
+ }
+
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
+}
+
+ /* COREGA, added by chiyoko, 20090316 */
+ static void SwLedControlMode3(struct adapter *padapter, enum LED_CTL_MODE LedAction)
+{
+ struct led_priv *ledpriv = &(padapter->ledpriv);
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ struct LED_871x *pLed = &(ledpriv->SwLed0);
+
+ switch (LedAction) {
+ case LED_CTL_SITE_SURVEY:
+ if (pmlmepriv->LinkDetectInfo.bBusyTraffic) {
+ } else if (!pLed->bLedScanBlinkInProgress) {
+ if (IS_LED_WPS_BLINKING(pLed))
+ return;
+
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ pLed->bLedScanBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_SCAN;
+ pLed->BlinkTimes = 24;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SCAN_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_CTL_TX:
+ case LED_CTL_RX:
+ if ((!pLed->bLedBlinkInProgress) && (check_fwstate(pmlmepriv, _FW_LINKED))) {
+ if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed))
+ return;
+ pLed->bLedBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_TXRX;
+ pLed->BlinkTimes = 2;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_FASTER_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_CTL_LINK:
+ if (IS_LED_WPS_BLINKING(pLed))
+ return;
+ pLed->CurrLedState = RTW_LED_ON;
+ pLed->BlinkingLedState = RTW_LED_ON;
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ if (pLed->bLedScanBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedScanBlinkInProgress = false;
+ }
+
+ _set_timer(&(pLed->BlinkTimer), 0);
+ break;
+ case LED_CTL_START_WPS: /* wait until xinpin finish */
+ case LED_CTL_START_WPS_BOTTON:
+ if (!pLed->bLedWPSBlinkInProgress) {
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ if (pLed->bLedScanBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedScanBlinkInProgress = false;
+ }
+ pLed->bLedWPSBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_WPS;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SCAN_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_CTL_STOP_WPS:
+ if (pLed->bLedWPSBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedWPSBlinkInProgress = false;
+ } else {
+ pLed->bLedWPSBlinkInProgress = true;
+ }
+
+ pLed->CurrLedState = LED_BLINK_WPS_STOP;
+ if (pLed->bLedOn) {
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA);
+ } else {
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), 0);
+ }
+ break;
+ case LED_CTL_STOP_WPS_FAIL:
+ if (pLed->bLedWPSBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedWPSBlinkInProgress = false;
+ }
+ pLed->CurrLedState = RTW_LED_OFF;
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ _set_timer(&(pLed->BlinkTimer), 0);
+ break;
+ case LED_CTL_START_TO_LINK:
+ case LED_CTL_NO_LINK:
+ if (!IS_LED_BLINKING(pLed)) {
+ pLed->CurrLedState = RTW_LED_OFF;
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ _set_timer(&(pLed->BlinkTimer), 0);
+ }
+ break;
+ case LED_CTL_POWER_OFF:
+ pLed->CurrLedState = RTW_LED_OFF;
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ if (pLed->bLedScanBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedScanBlinkInProgress = false;
+ }
+ if (pLed->bLedWPSBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedWPSBlinkInProgress = false;
+ }
+
+ _set_timer(&(pLed->BlinkTimer), 0);
+ break;
+ default:
+ break;
+ }
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
+ ("CurrLedState %d\n", pLed->CurrLedState));
+}
+
+ /* Edimax-Belkin, added by chiyoko, 20090413 */
+static void SwLedControlMode4(struct adapter *padapter, enum LED_CTL_MODE LedAction)
+{
+ struct led_priv *ledpriv = &(padapter->ledpriv);
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ struct LED_871x *pLed = &(ledpriv->SwLed0);
+ struct LED_871x *pLed1 = &(ledpriv->SwLed1);
+
+ switch (LedAction) {
+ case LED_CTL_START_TO_LINK:
+ if (pLed1->bLedWPSBlinkInProgress) {
+ pLed1->bLedWPSBlinkInProgress = false;
+ _cancel_timer_ex(&(pLed1->BlinkTimer));
+
+ pLed1->BlinkingLedState = RTW_LED_OFF;
+ pLed1->CurrLedState = RTW_LED_OFF;
+
+ if (pLed1->bLedOn)
+ _set_timer(&(pLed->BlinkTimer), 0);
+ }
+
+ if (!pLed->bLedStartToLinkBlinkInProgress) {
+ if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed))
+ return;
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ if (pLed->bLedNoLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedNoLinkBlinkInProgress = false;
+ }
+
+ pLed->bLedStartToLinkBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_StartToBlink;
+ if (pLed->bLedOn) {
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SLOWLY_INTERVAL);
+ } else {
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NORMAL_INTERVAL);
+ }
+ }
+ break;
+ case LED_CTL_LINK:
+ case LED_CTL_NO_LINK:
+ /* LED1 settings */
+ if (LedAction == LED_CTL_LINK) {
+ if (pLed1->bLedWPSBlinkInProgress) {
+ pLed1->bLedWPSBlinkInProgress = false;
+ _cancel_timer_ex(&(pLed1->BlinkTimer));
+
+ pLed1->BlinkingLedState = RTW_LED_OFF;
+ pLed1->CurrLedState = RTW_LED_OFF;
+
+ if (pLed1->bLedOn)
+ _set_timer(&(pLed->BlinkTimer), 0);
+ }
+ }
+
+ if (!pLed->bLedNoLinkBlinkInProgress) {
+ if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed))
+ return;
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+
+ pLed->bLedNoLinkBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_SLOWLY;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NO_LINK_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_CTL_SITE_SURVEY:
+ if ((pmlmepriv->LinkDetectInfo.bBusyTraffic) && (check_fwstate(pmlmepriv, _FW_LINKED))) {
+ } else if (!pLed->bLedScanBlinkInProgress) {
+ if (IS_LED_WPS_BLINKING(pLed))
+ return;
+
+ if (pLed->bLedNoLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedNoLinkBlinkInProgress = false;
+ }
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ pLed->bLedScanBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_SCAN;
+ pLed->BlinkTimes = 24;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SCAN_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_CTL_TX:
+ case LED_CTL_RX:
+ if (!pLed->bLedBlinkInProgress) {
+ if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed))
+ return;
+ if (pLed->bLedNoLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedNoLinkBlinkInProgress = false;
+ }
+ pLed->bLedBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_TXRX;
+ pLed->BlinkTimes = 2;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_FASTER_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_CTL_START_WPS: /* wait until xinpin finish */
+ case LED_CTL_START_WPS_BOTTON:
+ if (pLed1->bLedWPSBlinkInProgress) {
+ pLed1->bLedWPSBlinkInProgress = false;
+ _cancel_timer_ex(&(pLed1->BlinkTimer));
+
+ pLed1->BlinkingLedState = RTW_LED_OFF;
+ pLed1->CurrLedState = RTW_LED_OFF;
+
+ if (pLed1->bLedOn)
+ _set_timer(&(pLed->BlinkTimer), 0);
+ }
+
+ if (!pLed->bLedWPSBlinkInProgress) {
+ if (pLed->bLedNoLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedNoLinkBlinkInProgress = false;
+ }
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ if (pLed->bLedScanBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedScanBlinkInProgress = false;
+ }
+ pLed->bLedWPSBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_WPS;
+ if (pLed->bLedOn) {
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SLOWLY_INTERVAL);
+ } else {
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NORMAL_INTERVAL);
+ }
+ }
+ break;
+ case LED_CTL_STOP_WPS: /* WPS connect success */
+ if (pLed->bLedWPSBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedWPSBlinkInProgress = false;
+ }
+
+ pLed->bLedNoLinkBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_SLOWLY;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NO_LINK_INTERVAL_ALPHA);
+
+ break;
+ case LED_CTL_STOP_WPS_FAIL: /* WPS authentication fail */
+ if (pLed->bLedWPSBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedWPSBlinkInProgress = false;
+ }
+ pLed->bLedNoLinkBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_SLOWLY;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NO_LINK_INTERVAL_ALPHA);
+
+ /* LED1 settings */
+ if (pLed1->bLedWPSBlinkInProgress)
+ _cancel_timer_ex(&(pLed1->BlinkTimer));
+ else
+ pLed1->bLedWPSBlinkInProgress = true;
+ pLed1->CurrLedState = LED_BLINK_WPS_STOP;
+ if (pLed1->bLedOn)
+ pLed1->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed1->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NORMAL_INTERVAL);
+ break;
+ case LED_CTL_STOP_WPS_FAIL_OVERLAP: /* WPS session overlap */
+ if (pLed->bLedWPSBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedWPSBlinkInProgress = false;
+ }
+ pLed->bLedNoLinkBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_SLOWLY;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NO_LINK_INTERVAL_ALPHA);
+
+ /* LED1 settings */
+ if (pLed1->bLedWPSBlinkInProgress)
+ _cancel_timer_ex(&(pLed1->BlinkTimer));
+ else
+ pLed1->bLedWPSBlinkInProgress = true;
+ pLed1->CurrLedState = LED_BLINK_WPS_STOP_OVERLAP;
+ pLed1->BlinkTimes = 10;
+ if (pLed1->bLedOn)
+ pLed1->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed1->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_NORMAL_INTERVAL);
+ break;
+ case LED_CTL_POWER_OFF:
+ pLed->CurrLedState = RTW_LED_OFF;
+ pLed->BlinkingLedState = RTW_LED_OFF;
+
+ if (pLed->bLedNoLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedNoLinkBlinkInProgress = false;
+ }
+ if (pLed->bLedLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedLinkBlinkInProgress = false;
+ }
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ if (pLed->bLedWPSBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedWPSBlinkInProgress = false;
+ }
+ if (pLed->bLedScanBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedScanBlinkInProgress = false;
+ }
+ if (pLed->bLedStartToLinkBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedStartToLinkBlinkInProgress = false;
+ }
+ if (pLed1->bLedWPSBlinkInProgress) {
+ _cancel_timer_ex(&(pLed1->BlinkTimer));
+ pLed1->bLedWPSBlinkInProgress = false;
+ }
+ pLed1->BlinkingLedState = LED_UNKNOWN;
+ SwLedOff(padapter, pLed);
+ SwLedOff(padapter, pLed1);
+ break;
+ default:
+ break;
+ }
+
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Led %d\n", pLed->CurrLedState));
+}
+
+ /* Sercomm-Belkin, added by chiyoko, 20090415 */
+static void
+SwLedControlMode5(
+ struct adapter *padapter,
+ enum LED_CTL_MODE LedAction
+)
+{
+ struct led_priv *ledpriv = &(padapter->ledpriv);
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ struct LED_871x *pLed = &(ledpriv->SwLed0);
+
+ switch (LedAction) {
+ case LED_CTL_POWER_ON:
+ case LED_CTL_NO_LINK:
+ case LED_CTL_LINK: /* solid blue */
+ pLed->CurrLedState = RTW_LED_ON;
+ pLed->BlinkingLedState = RTW_LED_ON;
+
+ _set_timer(&(pLed->BlinkTimer), 0);
+ break;
+ case LED_CTL_SITE_SURVEY:
+ if ((pmlmepriv->LinkDetectInfo.bBusyTraffic) && (check_fwstate(pmlmepriv, _FW_LINKED))) {
+ } else if (!pLed->bLedScanBlinkInProgress) {
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ pLed->bLedScanBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_SCAN;
+ pLed->BlinkTimes = 24;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_SCAN_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_CTL_TX:
+ case LED_CTL_RX:
+ if (!pLed->bLedBlinkInProgress) {
+ if (pLed->CurrLedState == LED_BLINK_SCAN)
+ return;
+ pLed->bLedBlinkInProgress = true;
+ pLed->CurrLedState = LED_BLINK_TXRX;
+ pLed->BlinkTimes = 2;
+ if (pLed->bLedOn)
+ pLed->BlinkingLedState = RTW_LED_OFF;
+ else
+ pLed->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed->BlinkTimer), LED_BLINK_FASTER_INTERVAL_ALPHA);
+ }
+ break;
+ case LED_CTL_POWER_OFF:
+ pLed->CurrLedState = RTW_LED_OFF;
+ pLed->BlinkingLedState = RTW_LED_OFF;
+
+ if (pLed->bLedBlinkInProgress) {
+ _cancel_timer_ex(&(pLed->BlinkTimer));
+ pLed->bLedBlinkInProgress = false;
+ }
+ SwLedOff(padapter, pLed);
+ break;
+ default:
+ break;
+ }
+
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Led %d\n", pLed->CurrLedState));
+}
+
+ /* WNC-Corega, added by chiyoko, 20090902 */
+static void
+SwLedControlMode6(
+ struct adapter *padapter,
+ enum LED_CTL_MODE LedAction
+)
+{
+ struct led_priv *ledpriv = &(padapter->ledpriv);
+ struct LED_871x *pLed0 = &(ledpriv->SwLed0);
+
+ switch (LedAction) {
+ case LED_CTL_POWER_ON:
+ case LED_CTL_LINK:
+ case LED_CTL_NO_LINK:
+ _cancel_timer_ex(&(pLed0->BlinkTimer));
+ pLed0->CurrLedState = RTW_LED_ON;
+ pLed0->BlinkingLedState = RTW_LED_ON;
+ _set_timer(&(pLed0->BlinkTimer), 0);
+ break;
+ case LED_CTL_POWER_OFF:
+ SwLedOff(padapter, pLed0);
+ break;
+ default:
+ break;
+ }
+
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("ledcontrol 6 Led %d\n", pLed0->CurrLedState));
+}
+
+/* */
+/* Description: */
+/* Handler function of LED Blinking. */
+/* We dispatch acture LED blink action according to LedStrategy. */
+/* */
+void BlinkHandler(struct LED_871x *pLed)
+{
+ struct adapter *padapter = pLed->padapter;
+ struct led_priv *ledpriv = &(padapter->ledpriv);
+
+ if ((padapter->bSurpriseRemoved) || (padapter->bDriverStopped))
+ return;
+
+ switch (ledpriv->LedStrategy) {
+ case SW_LED_MODE0:
+ SwLedBlink(pLed);
+ break;
+ case SW_LED_MODE1:
+ SwLedBlink1(pLed);
+ break;
+ case SW_LED_MODE2:
+ SwLedBlink2(pLed);
+ break;
+ case SW_LED_MODE3:
+ SwLedBlink3(pLed);
+ break;
+ case SW_LED_MODE4:
+ SwLedBlink4(pLed);
+ break;
+ case SW_LED_MODE5:
+ SwLedBlink5(pLed);
+ break;
+ case SW_LED_MODE6:
+ SwLedBlink6(pLed);
+ break;
+ default:
+ break;
+ }
+}
+
+void LedControl8188eu(struct adapter *padapter, enum LED_CTL_MODE LedAction)
+{
+ struct led_priv *ledpriv = &(padapter->ledpriv);
+ struct registry_priv *registry_par;
+
+ if ((padapter->bSurpriseRemoved) || (padapter->bDriverStopped) ||
+ (!padapter->hw_init_completed))
+ return;
+
+ if (!ledpriv->bRegUseLed)
+ return;
+
+ registry_par = &padapter->registrypriv;
+ if (!registry_par->led_enable)
+ return;
+
+ if ((padapter->pwrctrlpriv.rf_pwrstate != rf_on &&
+ padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) &&
+ (LedAction == LED_CTL_TX || LedAction == LED_CTL_RX ||
+ LedAction == LED_CTL_SITE_SURVEY ||
+ LedAction == LED_CTL_LINK ||
+ LedAction == LED_CTL_NO_LINK ||
+ LedAction == LED_CTL_POWER_ON))
+ return;
+
+ switch (ledpriv->LedStrategy) {
+ case SW_LED_MODE0:
+ break;
+ case SW_LED_MODE1:
+ SwLedControlMode1(padapter, LedAction);
+ break;
+ case SW_LED_MODE2:
+ SwLedControlMode2(padapter, LedAction);
+ break;
+ case SW_LED_MODE3:
+ SwLedControlMode3(padapter, LedAction);
+ break;
+ case SW_LED_MODE4:
+ SwLedControlMode4(padapter, LedAction);
+ break;
+ case SW_LED_MODE5:
+ SwLedControlMode5(padapter, LedAction);
+ break;
+ case SW_LED_MODE6:
+ SwLedControlMode6(padapter, LedAction);
+ break;
+ default:
+ break;
+ }
+
+ RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
+ ("LedStrategy:%d, LedAction %d\n",
+ ledpriv->LedStrategy, LedAction));
+}
diff --git a/drivers/staging/rtl8188eu/core/rtw_mi.c b/drivers/staging/rtl8188eu/core/rtw_mi.c
new file mode 100644
index 000000000000..327b59aebdb5
--- /dev/null
+++ b/drivers/staging/rtl8188eu/core/rtw_mi.c
@@ -0,0 +1,1198 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved. */
+
+#define _RTW_MI_C_
+
+#include <drv_types.h>
+#include <hal_data.h>
+
+void rtw_mi_update_union_chan_inf(_adapter *adapter, u8 ch, u8 offset , u8 bw)
+{
+ struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
+ struct mi_state *iface_state = &dvobj->iface_state;
+
+ iface_state->union_ch = ch;
+ iface_state->union_bw = bw;
+ iface_state->union_offset = offset;
+}
+
+/* Find union about ch, bw, ch_offset of all linked/linking interfaces */
+static int _rtw_mi_get_ch_setting_union(_adapter *adapter, u8 *ch, u8 *bw, u8 *offset, bool include_self)
+{
+ struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
+ _adapter *iface;
+ struct mlme_ext_priv *mlmeext;
+ int i;
+ u8 ch_ret = 0;
+ u8 bw_ret = CHANNEL_WIDTH_20;
+ u8 offset_ret = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
+ int num = 0;
+
+ if (ch)
+ *ch = 0;
+ if (bw)
+ *bw = CHANNEL_WIDTH_20;
+ if (offset)
+ *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
+
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ iface = dvobj->padapters[i];
+ mlmeext = &iface->mlmeextpriv;
+
+ if (!check_fwstate(&iface->mlmepriv, _FW_LINKED | _FW_UNDER_LINKING))
+ continue;
+
+ if (check_fwstate(&iface->mlmepriv, WIFI_OP_CH_SWITCHING))
+ continue;
+
+ if (include_self == false && adapter == iface)
+ continue;
+
+ if (num == 0) {
+ ch_ret = mlmeext->cur_channel;
+ bw_ret = mlmeext->cur_bwmode;
+ offset_ret = mlmeext->cur_ch_offset;
+ num++;
+ continue;
+ }
+
+ if (ch_ret != mlmeext->cur_channel) {
+ num = 0;
+ break;
+ }
+
+ if (bw_ret < mlmeext->cur_bwmode) {
+ bw_ret = mlmeext->cur_bwmode;
+ offset_ret = mlmeext->cur_ch_offset;
+ } else if (bw_ret == mlmeext->cur_bwmode && offset_ret != mlmeext->cur_ch_offset) {
+ num = 0;
+ break;
+ }
+
+ num++;
+ }
+
+ if (num) {
+ if (ch)
+ *ch = ch_ret;
+ if (bw)
+ *bw = bw_ret;
+ if (offset)
+ *offset = offset_ret;
+ }
+
+ return num;
+}
+
+inline int rtw_mi_get_ch_setting_union(_adapter *adapter, u8 *ch, u8 *bw, u8 *offset)
+{
+ return _rtw_mi_get_ch_setting_union(adapter, ch, bw, offset, 1);
+}
+
+inline int rtw_mi_get_ch_setting_union_no_self(_adapter *adapter, u8 *ch, u8 *bw, u8 *offset)
+{
+ return _rtw_mi_get_ch_setting_union(adapter, ch, bw, offset, 0);
+}
+
+/* For now, not return union_ch/bw/offset */
+static void _rtw_mi_status(_adapter *adapter, struct mi_state *mstate, bool include_self)
+{
+ struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
+ _adapter *iface;
+ int i;
+
+ memset(mstate, 0, sizeof(struct mi_state));
+
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ iface = dvobj->padapters[i];
+
+ if (include_self == false && iface == adapter)
+ continue;
+
+ if (check_fwstate(&iface->mlmepriv, WIFI_STATION_STATE) == true) {
+ MSTATE_STA_NUM(mstate)++;
+ if (check_fwstate(&iface->mlmepriv, _FW_LINKED) == true)
+ MSTATE_STA_LD_NUM(mstate)++;
+
+ if (check_fwstate(&iface->mlmepriv, _FW_UNDER_LINKING) == true)
+ MSTATE_STA_LG_NUM(mstate)++;
+
+ } else if (check_fwstate(&iface->mlmepriv, WIFI_AP_STATE) == true
+ && check_fwstate(&iface->mlmepriv, _FW_LINKED) == true
+ ) {
+ MSTATE_AP_NUM(mstate)++;
+ if (iface->stapriv.asoc_sta_count > 2)
+ MSTATE_AP_LD_NUM(mstate)++;
+
+ } else if (check_fwstate(&iface->mlmepriv, WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE) == true
+ && check_fwstate(&iface->mlmepriv, _FW_LINKED) == true
+ ) {
+ MSTATE_ADHOC_NUM(mstate)++;
+ if (iface->stapriv.asoc_sta_count > 2)
+ MSTATE_ADHOC_LD_NUM(mstate)++;
+ }
+
+ if (check_fwstate(&iface->mlmepriv, WIFI_UNDER_WPS) == true)
+ MSTATE_WPS_NUM(mstate)++;
+
+#ifdef CONFIG_IOCTL_CFG80211
+ if (rtw_cfg80211_get_is_mgmt_tx(iface))
+ MSTATE_MGMT_TX_NUM(mstate)++;
+ #ifdef CONFIG_P2P
+ if (rtw_cfg80211_get_is_roch(iface) == true)
+ MSTATE_ROCH_NUM(mstate)++;
+ #endif
+#endif /* CONFIG_IOCTL_CFG80211 */
+
+ }
+}
+
+inline void rtw_mi_status(_adapter *adapter, struct mi_state *mstate)
+{
+ return _rtw_mi_status(adapter, mstate, 1);
+}
+inline void rtw_mi_status_no_self(_adapter *adapter, struct mi_state *mstate)
+{
+ return _rtw_mi_status(adapter, mstate, 0);
+}
+void dump_mi_status(void *sel, struct dvobj_priv *dvobj)
+{
+ RTW_PRINT_SEL(sel, "== dvobj-iface_state ==\n");
+ RTW_PRINT_SEL(sel, "sta_num:%d\n", DEV_STA_NUM(dvobj));
+ RTW_PRINT_SEL(sel, "linking_sta_num:%d\n", DEV_STA_LG_NUM(dvobj));
+ RTW_PRINT_SEL(sel, "linked_sta_num:%d\n", DEV_STA_LD_NUM(dvobj));
+ RTW_PRINT_SEL(sel, "ap_num:%d\n", DEV_AP_NUM(dvobj));
+ RTW_PRINT_SEL(sel, "linked_ap_num:%d\n", DEV_AP_LD_NUM(dvobj));
+ RTW_PRINT_SEL(sel, "adhoc_num:%d\n", DEV_ADHOC_NUM(dvobj));
+ RTW_PRINT_SEL(sel, "linked_adhoc_num:%d\n", DEV_ADHOC_LD_NUM(dvobj));
+#ifdef CONFIG_P2P
+ RTW_PRINT_SEL(sel, "p2p_device_num:%d\n", rtw_mi_stay_in_p2p_mode(dvobj->padapters[IFACE_ID0]));
+#endif
+#if defined(CONFIG_IOCTL_CFG80211)
+ #if defined(CONFIG_P2P)
+ RTW_PRINT_SEL(sel, "roch_num:%d\n", DEV_ROCH_NUM(dvobj));
+ #endif
+ RTW_PRINT_SEL(sel, "mgmt_tx_num:%d\n", DEV_MGMT_TX_NUM(dvobj));
+#endif
+ RTW_PRINT_SEL(sel, "under_wps_num:%d\n", DEV_WPS_NUM(dvobj));
+ RTW_PRINT_SEL(sel, "union_ch:%d\n", DEV_U_CH(dvobj));
+ RTW_PRINT_SEL(sel, "union_bw:%d\n", DEV_U_BW(dvobj));
+ RTW_PRINT_SEL(sel, "union_offset:%d\n", DEV_U_OFFSET(dvobj));
+ RTW_PRINT_SEL(sel, "================\n\n");
+}
+
+void dump_dvobj_mi_status(void *sel, const char *fun_name, _adapter *adapter)
+{
+ RTW_INFO("\n[ %s ] call %s\n", fun_name, __func__);
+ dump_mi_status(sel, adapter_to_dvobj(adapter));
+}
+
+inline void rtw_mi_update_iface_status(struct mlme_priv *pmlmepriv, sint state)
+{
+ _adapter *adapter = container_of(pmlmepriv, _adapter, mlmepriv);
+ struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
+ struct mi_state *iface_state = &dvobj->iface_state;
+ struct mi_state tmp_mstate;
+ u8 i;
+ u8 u_ch, u_offset, u_bw;
+ _adapter *iface;
+
+ if (state == WIFI_MONITOR_STATE
+ || state == WIFI_SITE_MONITOR
+ || state == 0xFFFFFFFF
+ )
+ return;
+
+ if (0)
+ RTW_INFO("%s => will change or clean state to 0x%08x\n", __func__, state);
+
+ rtw_mi_status(adapter, &tmp_mstate);
+ memcpy(iface_state, &tmp_mstate, sizeof(struct mi_state));
+
+ if (rtw_mi_get_ch_setting_union(adapter, &u_ch, &u_bw, &u_offset))
+ rtw_mi_update_union_chan_inf(adapter , u_ch, u_offset , u_bw);
+ else {
+ if (0) {
+ dump_adapters_status(RTW_DBGDUMP , dvobj);
+ RTW_INFO("%s-[ERROR] cannot get union channel\n", __func__);
+ rtw_warn_on(1);
+ }
+ }
+
+#ifdef DBG_IFACE_STATUS
+ DBG_IFACE_STATUS_DUMP(adapter);
+#endif
+}
+u8 rtw_mi_check_status(_adapter *adapter, u8 type)
+{
+ struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
+ struct mi_state *iface_state = &dvobj->iface_state;
+ u8 ret = false;
+
+#ifdef DBG_IFACE_STATUS
+ DBG_IFACE_STATUS_DUMP(adapter);
+ RTW_INFO("%s-"ADPT_FMT" check type:%d\n", __func__, ADPT_ARG(adapter), type);
+#endif
+
+ switch (type) {
+ case MI_LINKED:
+ if (MSTATE_STA_LD_NUM(iface_state) || MSTATE_AP_NUM(iface_state) || MSTATE_ADHOC_NUM(iface_state)) /*check_fwstate(&iface->mlmepriv, _FW_LINKED)*/
+ ret = true;
+ break;
+ case MI_ASSOC:
+ if (MSTATE_STA_LD_NUM(iface_state) || MSTATE_AP_LD_NUM(iface_state) || MSTATE_ADHOC_LD_NUM(iface_state))
+ ret = true;
+ break;
+ case MI_UNDER_WPS:
+ if (MSTATE_WPS_NUM(iface_state))
+ ret = true;
+ break;
+
+ case MI_AP_MODE:
+ if (MSTATE_AP_NUM(iface_state))
+ ret = true;
+ break;
+ case MI_AP_ASSOC:
+ if (MSTATE_AP_LD_NUM(iface_state))
+ ret = true;
+ break;
+
+ case MI_ADHOC:
+ if (MSTATE_ADHOC_NUM(iface_state))
+ ret = true;
+ break;
+ case MI_ADHOC_ASSOC:
+ if (MSTATE_ADHOC_LD_NUM(iface_state))
+ ret = true;
+ break;
+
+ case MI_STA_NOLINK: /* this is misleading, but not used now */
+ if (MSTATE_STA_NUM(iface_state) && (!(MSTATE_STA_LD_NUM(iface_state) || MSTATE_STA_LG_NUM(iface_state))))
+ ret = true;
+ break;
+ case MI_STA_LINKED:
+ if (MSTATE_STA_LD_NUM(iface_state))
+ ret = true;
+ break;
+ case MI_STA_LINKING:
+ if (MSTATE_STA_LG_NUM(iface_state))
+ ret = true;
+ break;
+
+ default:
+ break;
+ }
+ return ret;
+}
+
+u8 rtw_mi_mp_mode_check(_adapter *padapter)
+{
+#ifdef CONFIG_MP_INCLUDED
+#ifdef CONFIG_CONCURRENT_MODE
+ int i;
+ struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
+ _adapter *iface = NULL;
+
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ iface = dvobj->padapters[i];
+
+ if ((iface) && (iface->registrypriv.mp_mode == 1))
+ return true;
+ }
+#else
+ if (padapter->registrypriv.mp_mode == 1)
+ return true;
+#endif
+#endif /* CONFIG_MP_INCLUDED */
+ return false;
+}
+
+/*
+* return value : 0 is failed or have not interface meet condition
+* return value : !0 is success or interface numbers which meet condition
+* return value of ops_func must be true or false
+*/
+static u8 _rtw_mi_process(_adapter *padapter, bool exclude_self,
+ void *data, u8(*ops_func)(_adapter *padapter, void *data))
+{
+ int i;
+ _adapter *iface;
+ struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
+
+ u8 ret = 0;
+
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ iface = dvobj->padapters[i];
+ if ((iface) && rtw_is_adapter_up(iface)) {
+
+ if ((exclude_self) && (iface == padapter))
+ continue;
+
+ if (ops_func)
+ if (ops_func(iface, data))
+ ret++;
+ }
+ }
+ return ret;
+}
+static u8 _rtw_mi_netif_stop_queue(_adapter *padapter, void *data)
+{
+ bool carrier_off = *(bool *)data;
+ struct net_device *pnetdev = padapter->pnetdev;
+
+ if (carrier_off)
+ netif_carrier_off(pnetdev);
+ rtw_netif_stop_queue(pnetdev);
+ return true;
+}
+u8 rtw_mi_netif_stop_queue(_adapter *padapter, bool carrier_off)
+{
+ bool in_data = carrier_off;
+
+ return _rtw_mi_process(padapter, false, &in_data, _rtw_mi_netif_stop_queue);
+}
+u8 rtw_mi_buddy_netif_stop_queue(_adapter *padapter, bool carrier_off)
+{
+ bool in_data = carrier_off;
+
+ return _rtw_mi_process(padapter, true, &in_data, _rtw_mi_netif_stop_queue);
+}
+
+static u8 _rtw_mi_netif_wake_queue(_adapter *padapter, void *data)
+{
+ struct net_device *pnetdev = padapter->pnetdev;
+
+ if (pnetdev)
+ rtw_netif_wake_queue(pnetdev);
+ return true;
+}
+u8 rtw_mi_netif_wake_queue(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, false, NULL, _rtw_mi_netif_wake_queue);
+}
+u8 rtw_mi_buddy_netif_wake_queue(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, true, NULL, _rtw_mi_netif_wake_queue);
+}
+
+static u8 _rtw_mi_netif_carrier_on(_adapter *padapter, void *data)
+{
+ struct net_device *pnetdev = padapter->pnetdev;
+
+ if (pnetdev)
+ rtw_netif_carrier_on(pnetdev);
+ return true;
+}
+u8 rtw_mi_netif_carrier_on(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, false, NULL, _rtw_mi_netif_carrier_on);
+}
+u8 rtw_mi_buddy_netif_carrier_on(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, true, NULL, _rtw_mi_netif_carrier_on);
+}
+
+static u8 _rtw_mi_scan_abort(_adapter *adapter, void *data)
+{
+ bool bwait = *(bool *)data;
+
+ if (bwait)
+ rtw_scan_abort(adapter);
+ else
+ rtw_scan_abort_no_wait(adapter);
+
+ return true;
+}
+void rtw_mi_scan_abort(_adapter *adapter, bool bwait)
+{
+ bool in_data = bwait;
+
+ _rtw_mi_process(adapter, false, &in_data, _rtw_mi_scan_abort);
+
+}
+void rtw_mi_buddy_scan_abort(_adapter *adapter, bool bwait)
+{
+ bool in_data = bwait;
+
+ _rtw_mi_process(adapter, true, &in_data, _rtw_mi_scan_abort);
+}
+
+static u8 _rtw_mi_start_drv_threads(_adapter *adapter, void *data)
+{
+ rtw_start_drv_threads(adapter);
+ return true;
+}
+void rtw_mi_start_drv_threads(_adapter *adapter)
+{
+ _rtw_mi_process(adapter, false, NULL, _rtw_mi_start_drv_threads);
+}
+void rtw_mi_buddy_start_drv_threads(_adapter *adapter)
+{
+ _rtw_mi_process(adapter, true, NULL, _rtw_mi_start_drv_threads);
+}
+
+static u8 _rtw_mi_stop_drv_threads(_adapter *adapter, void *data)
+{
+ rtw_stop_drv_threads(adapter);
+ return true;
+}
+void rtw_mi_stop_drv_threads(_adapter *adapter)
+{
+ _rtw_mi_process(adapter, false, NULL, _rtw_mi_stop_drv_threads);
+}
+void rtw_mi_buddy_stop_drv_threads(_adapter *adapter)
+{
+ _rtw_mi_process(adapter, true, NULL, _rtw_mi_stop_drv_threads);
+}
+
+static u8 _rtw_mi_cancel_all_timer(_adapter *adapter, void *data)
+{
+ rtw_cancel_all_timer(adapter);
+ return true;
+}
+void rtw_mi_cancel_all_timer(_adapter *adapter)
+{
+ _rtw_mi_process(adapter, false, NULL, _rtw_mi_cancel_all_timer);
+}
+void rtw_mi_buddy_cancel_all_timer(_adapter *adapter)
+{
+ _rtw_mi_process(adapter, true, NULL, _rtw_mi_cancel_all_timer);
+}
+
+static u8 _rtw_mi_reset_drv_sw(_adapter *adapter, void *data)
+{
+ rtw_reset_drv_sw(adapter);
+ return true;
+}
+void rtw_mi_reset_drv_sw(_adapter *adapter)
+{
+ _rtw_mi_process(adapter, false, NULL, _rtw_mi_reset_drv_sw);
+}
+void rtw_mi_buddy_reset_drv_sw(_adapter *adapter)
+{
+ _rtw_mi_process(adapter, true, NULL, _rtw_mi_reset_drv_sw);
+}
+
+static u8 _rtw_mi_intf_start(_adapter *adapter, void *data)
+{
+ rtw_intf_start(adapter);
+ return true;
+}
+void rtw_mi_intf_start(_adapter *adapter)
+{
+ _rtw_mi_process(adapter, false, NULL, _rtw_mi_intf_start);
+}
+void rtw_mi_buddy_intf_start(_adapter *adapter)
+{
+ _rtw_mi_process(adapter, true, NULL, _rtw_mi_intf_start);
+}
+
+static u8 _rtw_mi_intf_stop(_adapter *adapter, void *data)
+{
+ rtw_intf_stop(adapter);
+ return true;
+}
+void rtw_mi_intf_stop(_adapter *adapter)
+{
+ _rtw_mi_process(adapter, false, NULL, _rtw_mi_intf_stop);
+}
+void rtw_mi_buddy_intf_stop(_adapter *adapter)
+{
+ _rtw_mi_process(adapter, true, NULL, _rtw_mi_intf_stop);
+}
+
+static u8 _rtw_mi_suspend_free_assoc_resource(_adapter *padapter, void *data)
+{
+ return rtw_suspend_free_assoc_resource(padapter);
+}
+void rtw_mi_suspend_free_assoc_resource(_adapter *adapter)
+{
+ _rtw_mi_process(adapter, false, NULL, _rtw_mi_suspend_free_assoc_resource);
+}
+void rtw_mi_buddy_suspend_free_assoc_resource(_adapter *adapter)
+{
+ _rtw_mi_process(adapter, true, NULL, _rtw_mi_suspend_free_assoc_resource);
+}
+
+static u8 _rtw_mi_is_scan_deny(_adapter *adapter, void *data)
+{
+ return rtw_is_scan_deny(adapter);
+}
+
+u8 rtw_mi_is_scan_deny(_adapter *adapter)
+{
+ return _rtw_mi_process(adapter, false, NULL, _rtw_mi_is_scan_deny);
+
+}
+u8 rtw_mi_buddy_is_scan_deny(_adapter *adapter)
+{
+ return _rtw_mi_process(adapter, true, NULL, _rtw_mi_is_scan_deny);
+}
+
+#ifdef CONFIG_SET_SCAN_DENY_TIMER
+static u8 _rtw_mi_set_scan_deny(_adapter *adapter, void *data)
+{
+ u32 ms = *(u32 *)data;
+
+ rtw_set_scan_deny(adapter, ms);
+ return true;
+}
+void rtw_mi_set_scan_deny(_adapter *adapter, u32 ms)
+{
+ u32 in_data = ms;
+
+ _rtw_mi_process(adapter, false, &in_data, _rtw_mi_set_scan_deny);
+}
+void rtw_mi_buddy_set_scan_deny(_adapter *adapter, u32 ms)
+{
+ u32 in_data = ms;
+
+ _rtw_mi_process(adapter, true, &in_data, _rtw_mi_set_scan_deny);
+}
+#endif
+
+struct nulldata_param {
+ unsigned char *da;
+ unsigned int power_mode;
+ int try_cnt;
+ int wait_ms;
+};
+
+static u8 _rtw_mi_issue_nulldata(_adapter *padapter, void *data)
+{
+ struct nulldata_param *pnulldata_param = (struct nulldata_param *)data;
+
+ if (is_client_associated_to_ap(padapter) == true) {
+ /* TODO: TDLS peers */
+ issue_nulldata(padapter, pnulldata_param->da, pnulldata_param->power_mode, pnulldata_param->try_cnt, pnulldata_param->wait_ms);
+ return true;
+ }
+ return false;
+}
+
+u8 rtw_mi_issue_nulldata(_adapter *padapter, unsigned char *da, unsigned int power_mode, int try_cnt, int wait_ms)
+{
+ struct nulldata_param nparam;
+
+ nparam.da = da;
+ nparam.power_mode = power_mode;/*0 or 1*/
+ nparam.try_cnt = try_cnt;
+ nparam.wait_ms = wait_ms;
+
+ return _rtw_mi_process(padapter, false, &nparam, _rtw_mi_issue_nulldata);
+}
+u8 rtw_mi_buddy_issue_nulldata(_adapter *padapter, unsigned char *da, unsigned int power_mode, int try_cnt, int wait_ms)
+{
+ struct nulldata_param nparam;
+
+ nparam.da = da;
+ nparam.power_mode = power_mode;
+ nparam.try_cnt = try_cnt;
+ nparam.wait_ms = wait_ms;
+
+ return _rtw_mi_process(padapter, true, &nparam, _rtw_mi_issue_nulldata);
+}
+
+static u8 _rtw_mi_beacon_update(_adapter *padapter, void *data)
+{
+ struct mlme_ext_priv *mlmeext = &padapter->mlmeextpriv;
+
+ if (mlmeext_msr(mlmeext) == WIFI_FW_AP_STATE
+ && check_fwstate(&padapter->mlmepriv, _FW_LINKED) == true) {
+ RTW_INFO(ADPT_FMT"-WIFI_FW_AP_STATE - update_beacon\n", ADPT_ARG(padapter));
+ update_beacon(padapter, 0, NULL, true);
+ }
+ return true;
+}
+
+void rtw_mi_beacon_update(_adapter *padapter)
+{
+ _rtw_mi_process(padapter, false, NULL, _rtw_mi_beacon_update);
+}
+
+void rtw_mi_buddy_beacon_update(_adapter *padapter)
+{
+ _rtw_mi_process(padapter, true, NULL, _rtw_mi_beacon_update);
+}
+
+static u8 _rtw_mi_hal_dump_macaddr(_adapter *padapter, void *data)
+{
+ u8 mac_addr[ETH_ALEN] = {0};
+
+ rtw_hal_get_macaddr_port(padapter, mac_addr);
+ RTW_INFO(ADPT_FMT"MAC Address ="MAC_FMT"\n", ADPT_ARG(padapter), MAC_ARG(mac_addr));
+ return true;
+}
+void rtw_mi_hal_dump_macaddr(_adapter *padapter)
+{
+ _rtw_mi_process(padapter, false, NULL, _rtw_mi_hal_dump_macaddr);
+}
+void rtw_mi_buddy_hal_dump_macaddr(_adapter *padapter)
+{
+ _rtw_mi_process(padapter, true, NULL, _rtw_mi_hal_dump_macaddr);
+}
+
+static u8 _rtw_mi_busy_traffic_check(_adapter *padapter, void *data)
+{
+ u32 passtime;
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ bool check_sc_interval = *(bool *)data;
+
+ if (pmlmepriv->LinkDetectInfo.bBusyTraffic == true) {
+ if (check_sc_interval) {
+ /* Miracast can't do AP scan*/
+ passtime = rtw_get_passing_time_ms(pmlmepriv->lastscantime);
+ pmlmepriv->lastscantime = jiffies;
+ if (passtime > BUSY_TRAFFIC_SCAN_DENY_PERIOD) {
+ RTW_INFO(ADPT_FMT" bBusyTraffic == true\n", ADPT_ARG(padapter));
+ return true;
+ }
+ } else
+ return true;
+ }
+
+ return false;
+}
+
+u8 rtw_mi_busy_traffic_check(_adapter *padapter, bool check_sc_interval)
+{
+ bool in_data = check_sc_interval;
+
+ return _rtw_mi_process(padapter, false, &in_data, _rtw_mi_busy_traffic_check);
+}
+u8 rtw_mi_buddy_busy_traffic_check(_adapter *padapter, bool check_sc_interval)
+{
+ bool in_data = check_sc_interval;
+
+ return _rtw_mi_process(padapter, true, &in_data, _rtw_mi_busy_traffic_check);
+}
+static u8 _rtw_mi_check_mlmeinfo_state(_adapter *padapter, void *data)
+{
+ u32 state = *(u32 *)data;
+ struct mlme_ext_priv *mlmeext = &padapter->mlmeextpriv;
+
+ /*if (mlmeext_msr(mlmeext) == state)*/
+ if (check_mlmeinfo_state(mlmeext, state))
+ return true;
+ else
+ return false;
+}
+
+u8 rtw_mi_check_mlmeinfo_state(_adapter *padapter, u32 state)
+{
+ u32 in_data = state;
+
+ return _rtw_mi_process(padapter, false, &in_data, _rtw_mi_check_mlmeinfo_state);
+}
+
+u8 rtw_mi_buddy_check_mlmeinfo_state(_adapter *padapter, u32 state)
+{
+ u32 in_data = state;
+
+ return _rtw_mi_process(padapter, true, &in_data, _rtw_mi_check_mlmeinfo_state);
+}
+
+/*#define DBG_DUMP_FW_STATE*/
+#ifdef DBG_DUMP_FW_STATE
+static void rtw_dbg_dump_fwstate(_adapter *padapter, sint state)
+{
+ u8 buf[32] = {0};
+
+ if (state & WIFI_FW_NULL_STATE) {
+ memset(buf, 0, 32);
+ sprintf(buf, "WIFI_FW_NULL_STATE");
+ RTW_INFO(FUNC_ADPT_FMT"fwstate-%s\n", FUNC_ADPT_ARG(padapter), buf);
+ }
+
+ if (state & _FW_LINKED) {
+ memset(buf, 0, 32);
+ sprintf(buf, "_FW_LINKED");
+ RTW_INFO(FUNC_ADPT_FMT"fwstate-%s\n", FUNC_ADPT_ARG(padapter), buf);
+ }
+
+ if (state & _FW_UNDER_LINKING) {
+ memset(buf, 0, 32);
+ sprintf(buf, "_FW_UNDER_LINKING");
+ RTW_INFO(FUNC_ADPT_FMT"fwstate-%s\n", FUNC_ADPT_ARG(padapter), buf);
+ }
+
+ if (state & _FW_UNDER_SURVEY) {
+ memset(buf, 0, 32);
+ sprintf(buf, "_FW_UNDER_SURVEY");
+ RTW_INFO(FUNC_ADPT_FMT"fwstate-%s\n", FUNC_ADPT_ARG(padapter), buf);
+ }
+}
+#endif
+
+static u8 _rtw_mi_check_fwstate(_adapter *padapter, void *data)
+{
+ u8 ret = false;
+
+ sint state = *(sint *)data;
+
+ if ((state == WIFI_FW_NULL_STATE) &&
+ (padapter->mlmepriv.fw_state == WIFI_FW_NULL_STATE))
+ ret = true;
+ else if (check_fwstate(&padapter->mlmepriv, state))
+ ret = true;
+#ifdef DBG_DUMP_FW_STATE
+ if (ret)
+ rtw_dbg_dump_fwstate(padapter, state);
+#endif
+ return ret;
+}
+u8 rtw_mi_check_fwstate(_adapter *padapter, sint state)
+{
+ sint in_data = state;
+
+ return _rtw_mi_process(padapter, false, &in_data, _rtw_mi_check_fwstate);
+}
+u8 rtw_mi_buddy_check_fwstate(_adapter *padapter, sint state)
+{
+ sint in_data = state;
+
+ return _rtw_mi_process(padapter, true, &in_data, _rtw_mi_check_fwstate);
+}
+
+static u8 _rtw_mi_traffic_statistics(_adapter *padapter , void *data)
+{
+ struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
+
+ /* Tx */
+ pdvobjpriv->traffic_stat.tx_bytes += padapter->xmitpriv.tx_bytes;
+ pdvobjpriv->traffic_stat.tx_pkts += padapter->xmitpriv.tx_pkts;
+ pdvobjpriv->traffic_stat.tx_drop += padapter->xmitpriv.tx_drop;
+
+ /* Rx */
+ pdvobjpriv->traffic_stat.rx_bytes += padapter->recvpriv.rx_bytes;
+ pdvobjpriv->traffic_stat.rx_pkts += padapter->recvpriv.rx_pkts;
+ pdvobjpriv->traffic_stat.rx_drop += padapter->recvpriv.rx_drop;
+ return true;
+}
+u8 rtw_mi_traffic_statistics(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, false, NULL, _rtw_mi_traffic_statistics);
+}
+
+static u8 _rtw_mi_check_miracast_enabled(_adapter *padapter , void *data)
+{
+ return is_miracast_enabled(padapter);
+}
+u8 rtw_mi_check_miracast_enabled(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, false, NULL, _rtw_mi_check_miracast_enabled);
+}
+
+#ifdef CONFIG_XMIT_THREAD_MODE
+static u8 _rtw_mi_check_pending_xmitbuf(_adapter *padapter , void *data)
+{
+ struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
+
+ return check_pending_xmitbuf(pxmitpriv);
+}
+u8 rtw_mi_check_pending_xmitbuf(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, false, NULL, _rtw_mi_check_pending_xmitbuf);
+}
+u8 rtw_mi_buddy_check_pending_xmitbuf(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, true, NULL, _rtw_mi_check_pending_xmitbuf);
+}
+#endif
+
+static void _rtw_mi_adapter_reset(_adapter *padapter , u8 exclude_self)
+{
+ int i;
+ struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
+
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ if (dvobj->padapters[i]) {
+ if ((exclude_self) && (dvobj->padapters[i] == padapter))
+ continue;
+ dvobj->padapters[i] = NULL;
+ }
+ }
+}
+
+void rtw_mi_adapter_reset(_adapter *padapter)
+{
+ _rtw_mi_adapter_reset(padapter, false);
+}
+
+void rtw_mi_buddy_adapter_reset(_adapter *padapter)
+{
+ _rtw_mi_adapter_reset(padapter, true);
+}
+
+static u8 _rtw_mi_dynamic_check_timer_handler(_adapter *adapter, void *data)
+{
+ rtw_iface_dynamic_check_timer_handler(adapter);
+ return true;
+}
+u8 rtw_mi_dynamic_check_timer_handler(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, false, NULL, _rtw_mi_dynamic_check_timer_handler);
+}
+u8 rtw_mi_buddy_dynamic_check_timer_handler(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, true, NULL, _rtw_mi_dynamic_check_timer_handler);
+}
+
+static u8 _rtw_mi_dev_unload(_adapter *adapter, void *data)
+{
+ rtw_dev_unload(adapter);
+ return true;
+}
+u8 rtw_mi_dev_unload(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, false, NULL, _rtw_mi_dev_unload);
+}
+u8 rtw_mi_buddy_dev_unload(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, true, NULL, _rtw_mi_dev_unload);
+}
+
+static u8 _rtw_mi_dynamic_chk_wk_hdl(_adapter *adapter, void *data)
+{
+ rtw_iface_dynamic_chk_wk_hdl(adapter);
+ return true;
+}
+u8 rtw_mi_dynamic_chk_wk_hdl(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, false, NULL, _rtw_mi_dynamic_chk_wk_hdl);
+}
+u8 rtw_mi_buddy_dynamic_chk_wk_hdl(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, true, NULL, _rtw_mi_dynamic_chk_wk_hdl);
+}
+
+static u8 _rtw_mi_os_xmit_schedule(_adapter *adapter, void *data)
+{
+ rtw_os_xmit_schedule(adapter);
+ return true;
+}
+u8 rtw_mi_os_xmit_schedule(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, false, NULL, _rtw_mi_os_xmit_schedule);
+}
+u8 rtw_mi_buddy_os_xmit_schedule(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, true, NULL, _rtw_mi_os_xmit_schedule);
+}
+
+static u8 _rtw_mi_report_survey_event(_adapter *adapter, void *data)
+{
+ union recv_frame *precv_frame = (union recv_frame *)data;
+
+ report_survey_event(adapter, precv_frame);
+ return true;
+}
+u8 rtw_mi_report_survey_event(_adapter *padapter, union recv_frame *precv_frame)
+{
+ return _rtw_mi_process(padapter, false, precv_frame, _rtw_mi_report_survey_event);
+}
+u8 rtw_mi_buddy_report_survey_event(_adapter *padapter, union recv_frame *precv_frame)
+{
+ return _rtw_mi_process(padapter, true, precv_frame, _rtw_mi_report_survey_event);
+}
+
+static u8 _rtw_mi_sreset_adapter_hdl(_adapter *adapter, void *data)
+{
+ u8 bstart = *(u8 *)data;
+
+ if (bstart)
+ sreset_start_adapter(adapter);
+ else
+ sreset_stop_adapter(adapter);
+ return true;
+}
+u8 rtw_mi_sreset_adapter_hdl(_adapter *padapter, u8 bstart)
+{
+ u8 in_data = bstart;
+
+ return _rtw_mi_process(padapter, false, &in_data, _rtw_mi_sreset_adapter_hdl);
+}
+u8 rtw_mi_buddy_sreset_adapter_hdl(_adapter *padapter, u8 bstart)
+{
+ u8 in_data = bstart;
+
+ return _rtw_mi_process(padapter, true, &in_data, _rtw_mi_sreset_adapter_hdl);
+}
+static u8 _rtw_mi_tx_beacon_hdl(_adapter *adapter, void *data)
+{
+ if (check_fwstate(&adapter->mlmepriv, WIFI_AP_STATE) == true
+ && check_fwstate(&adapter->mlmepriv, WIFI_ASOC_STATE) == true
+ ) {
+ adapter->mlmepriv.update_bcn = true;
+#ifndef CONFIG_INTERRUPT_BASED_TXBCN
+ tx_beacon_hdl(adapter, NULL);
+#endif
+ }
+ return true;
+}
+u8 rtw_mi_tx_beacon_hdl(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, false, NULL, _rtw_mi_tx_beacon_hdl);
+}
+u8 rtw_mi_buddy_tx_beacon_hdl(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, true, NULL, _rtw_mi_sreset_adapter_hdl);
+}
+
+static u8 _rtw_mi_set_tx_beacon_cmd(_adapter *adapter, void *data)
+{
+ struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
+
+ if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
+ if (pmlmepriv->update_bcn == true)
+ set_tx_beacon_cmd(adapter);
+ }
+ return true;
+}
+u8 rtw_mi_set_tx_beacon_cmd(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, false, NULL, _rtw_mi_set_tx_beacon_cmd);
+}
+u8 rtw_mi_buddy_set_tx_beacon_cmd(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, true, NULL, _rtw_mi_set_tx_beacon_cmd);
+}
+
+#ifdef CONFIG_P2P
+static u8 _rtw_mi_p2p_chk_state(_adapter *adapter, void *data)
+{
+ struct wifidirect_info *pwdinfo = &(adapter->wdinfo);
+ enum P2P_STATE state = *(enum P2P_STATE *)data;
+
+ return rtw_p2p_chk_state(pwdinfo, state);
+}
+u8 rtw_mi_p2p_chk_state(_adapter *padapter, enum P2P_STATE p2p_state)
+{
+ u8 in_data = p2p_state;
+
+ return _rtw_mi_process(padapter, false, &in_data, _rtw_mi_p2p_chk_state);
+}
+u8 rtw_mi_buddy_p2p_chk_state(_adapter *padapter, enum P2P_STATE p2p_state)
+{
+ u8 in_data = p2p_state;
+
+ return _rtw_mi_process(padapter, true, &in_data, _rtw_mi_p2p_chk_state);
+}
+static u8 _rtw_mi_stay_in_p2p_mode(_adapter *adapter, void *data)
+{
+ struct wifidirect_info *pwdinfo = &(adapter->wdinfo);
+
+ if (rtw_p2p_role(pwdinfo) != P2P_ROLE_DISABLE)
+ return true;
+ return false;
+}
+u8 rtw_mi_stay_in_p2p_mode(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, false, NULL, _rtw_mi_stay_in_p2p_mode);
+}
+u8 rtw_mi_buddy_stay_in_p2p_mode(_adapter *padapter)
+{
+ return _rtw_mi_process(padapter, true, NULL, _rtw_mi_stay_in_p2p_mode);
+}
+#endif /*CONFIG_P2P*/
+
+_adapter *rtw_get_iface_by_id(_adapter *padapter, u8 iface_id)
+{
+ _adapter *iface = NULL;
+ struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
+
+ if ((padapter == NULL) || (iface_id >= CONFIG_IFACE_NUMBER)) {
+ rtw_warn_on(1);
+ return iface;
+ }
+
+ return dvobj->padapters[iface_id];
+}
+
+_adapter *rtw_get_iface_by_macddr(_adapter *padapter, u8 *mac_addr)
+{
+ int i;
+ _adapter *iface = NULL;
+ u8 bmatch = false;
+ struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
+
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ iface = dvobj->padapters[i];
+ if ((iface) && (!memcmp(mac_addr, adapter_mac_addr(iface), ETH_ALEN))) {
+ bmatch = true;
+ break;
+ }
+ }
+ if (bmatch)
+ return iface;
+ else
+ return NULL;
+}
+
+_adapter *rtw_get_iface_by_hwport(_adapter *padapter, u8 hw_port)
+{
+ int i;
+ _adapter *iface = NULL;
+ u8 bmatch = false;
+ struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
+
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ iface = dvobj->padapters[i];
+ if ((iface) && (hw_port == iface->hw_port)) {
+ bmatch = true;
+ break;
+ }
+ }
+ if (bmatch)
+ return iface;
+ else
+ return NULL;
+}
+
+/*#define CONFIG_SKB_ALLOCATED*/
+#define DBG_SKB_PROCESS
+#ifdef DBG_SKB_PROCESS
+static void rtw_dbg_skb_process(_adapter *padapter, union recv_frame *precvframe, union recv_frame *pcloneframe)
+{
+ _pkt *pkt_copy, *pkt_org;
+
+ pkt_org = precvframe->u.hdr.pkt;
+ pkt_copy = pcloneframe->u.hdr.pkt;
+ /*
+ RTW_INFO("%s ===== ORG SKB =====\n", __func__);
+ RTW_INFO(" SKB head(%p)\n", pkt_org->head);
+ RTW_INFO(" SKB data(%p)\n", pkt_org->data);
+ RTW_INFO(" SKB tail(%p)\n", pkt_org->tail);
+ RTW_INFO(" SKB end(%p)\n", pkt_org->end);
+
+ RTW_INFO(" recv frame head(%p)\n", precvframe->u.hdr.rx_head);
+ RTW_INFO(" recv frame data(%p)\n", precvframe->u.hdr.rx_data);
+ RTW_INFO(" recv frame tail(%p)\n", precvframe->u.hdr.rx_tail);
+ RTW_INFO(" recv frame end(%p)\n", precvframe->u.hdr.rx_end);
+
+ RTW_INFO("%s ===== COPY SKB =====\n", __func__);
+ RTW_INFO(" SKB head(%p)\n", pkt_copy->head);
+ RTW_INFO(" SKB data(%p)\n", pkt_copy->data);
+ RTW_INFO(" SKB tail(%p)\n", pkt_copy->tail);
+ RTW_INFO(" SKB end(%p)\n", pkt_copy->end);
+
+ RTW_INFO(" recv frame head(%p)\n", pcloneframe->u.hdr.rx_head);
+ RTW_INFO(" recv frame data(%p)\n", pcloneframe->u.hdr.rx_data);
+ RTW_INFO(" recv frame tail(%p)\n", pcloneframe->u.hdr.rx_tail);
+ RTW_INFO(" recv frame end(%p)\n", pcloneframe->u.hdr.rx_end);
+ */
+ /*
+ RTW_INFO("%s => recv_frame adapter(%p,%p)\n", __func__, precvframe->u.hdr.adapter, pcloneframe->u.hdr.adapter);
+ RTW_INFO("%s => recv_frame dev(%p,%p)\n", __func__, pkt_org->dev , pkt_copy->dev);
+ RTW_INFO("%s => recv_frame len(%d,%d)\n", __func__, precvframe->u.hdr.len, pcloneframe->u.hdr.len);
+ */
+ if (precvframe->u.hdr.len != pcloneframe->u.hdr.len)
+ RTW_INFO("%s [WARN] recv_frame length(%d:%d) compare failed\n", __func__, precvframe->u.hdr.len, pcloneframe->u.hdr.len);
+
+ if (!memcmp(&precvframe->u.hdr.attrib, &pcloneframe->u.hdr.attrib, sizeof(struct rx_pkt_attrib)) == false)
+ RTW_INFO("%s [WARN] recv_frame attrib compare failed\n", __func__);
+
+ if (!memcmp(precvframe->u.hdr.rx_data, pcloneframe->u.hdr.rx_data, precvframe->u.hdr.len) == false)
+ RTW_INFO("%s [WARN] recv_frame rx_data compare failed\n", __func__);
+
+}
+#endif
+
+static s32 _rtw_mi_buddy_clone_bcmc_packet(_adapter *adapter, union recv_frame *precvframe, u8 *pphy_status, union recv_frame *pcloneframe)
+{
+ s32 ret = _SUCCESS;
+ u8 *pbuf = precvframe->u.hdr.rx_data;
+ struct rx_pkt_attrib *pattrib = NULL;
+ HAL_DATA_TYPE *pHalData = GET_HAL_DATA(adapter);
+
+ if (pcloneframe) {
+ pcloneframe->u.hdr.adapter = adapter;
+
+ INIT_LIST_HEAD(&pcloneframe->u.hdr.list);
+ pcloneframe->u.hdr.precvbuf = NULL; /*can't access the precvbuf for new arch.*/
+ pcloneframe->u.hdr.len = 0;
+
+ memcpy(&pcloneframe->u.hdr.attrib, &precvframe->u.hdr.attrib, sizeof(struct rx_pkt_attrib));
+
+ pattrib = &pcloneframe->u.hdr.attrib;
+#ifdef CONFIG_SKB_ALLOCATED
+ if (rtw_os_alloc_recvframe(adapter, pcloneframe, pbuf, NULL) == _SUCCESS)
+#else
+ if (rtw_os_recvframe_duplicate_skb(adapter, pcloneframe, precvframe->u.hdr.pkt) == _SUCCESS)
+#endif
+ {
+#ifdef CONFIG_SKB_ALLOCATED
+ recvframe_put(pcloneframe, pattrib->pkt_len);
+#endif
+
+#ifdef DBG_SKB_PROCESS
+ rtw_dbg_skb_process(adapter, precvframe, pcloneframe);
+#endif
+
+ if (pattrib->physt && pphy_status)
+ rx_query_phy_status(pcloneframe, pphy_status);
+
+ ret = rtw_recv_entry(pcloneframe);
+ } else {
+ ret = -1;
+ RTW_INFO("%s()-%d: rtw_os_alloc_recvframe() failed!\n", __func__, __LINE__);
+ }
+
+ }
+ return ret;
+}
+
+void rtw_mi_buddy_clone_bcmc_packet(_adapter *padapter, union recv_frame *precvframe, u8 *pphy_status)
+{
+ int i;
+ s32 ret = _SUCCESS;
+ _adapter *iface = NULL;
+ union recv_frame *pcloneframe = NULL;
+ struct recv_priv *precvpriv = &padapter->recvpriv;/*primary_padapter*/
+ _queue *pfree_recv_queue = &precvpriv->free_recv_queue;
+ struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
+
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ iface = dvobj->padapters[i];
+ if (!iface || iface == padapter)
+ continue;
+ if (rtw_is_adapter_up(iface) == false || iface->registered == 0)
+ continue;
+
+ pcloneframe = rtw_alloc_recvframe(pfree_recv_queue);
+ if (pcloneframe) {
+ ret = _rtw_mi_buddy_clone_bcmc_packet(iface, precvframe, pphy_status, pcloneframe);
+ if (_SUCCESS != ret) {
+ if (ret == -1)
+ rtw_free_recvframe(pcloneframe, pfree_recv_queue);
+ /*RTW_INFO(ADPT_FMT"-clone BC/MC frame failed\n", ADPT_ARG(iface));*/
+ }
+ }
+ }
+
+}
+
+void rtw_mi_update_ap_bmc_camid(_adapter *padapter, u8 camid_a, u8 camid_b)
+{
+#ifdef CONFIG_CONCURRENT_MODE
+ struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
+ struct macid_ctl_t *macid_ctl = dvobj_to_macidctl(dvobj);
+
+ int i;
+ _adapter *iface = NULL;
+
+ for (i = 0; i < dvobj->iface_nums; i++) {
+ iface = dvobj->padapters[i];
+ if (!iface)
+ continue;
+
+ if (macid_ctl->iface_bmc[iface->iface_id] != INVALID_SEC_MAC_CAM_ID) {
+ if (macid_ctl->iface_bmc[iface->iface_id] == camid_a)
+ macid_ctl->iface_bmc[iface->iface_id] = camid_b;
+ else if (macid_ctl->iface_bmc[iface->iface_id] == camid_b)
+ macid_ctl->iface_bmc[iface->iface_id] = camid_a;
+ iface->securitypriv.dot118021x_bmc_cam_id = macid_ctl->iface_bmc[iface->iface_id];
+ }
+ }
+#endif
+}
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c b/drivers/staging/rtl8188eu/core/rtw_mlme.c
new file mode 100644
index 000000000000..00eedc7c6aab
--- /dev/null
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
@@ -0,0 +1,4401 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved. */
+
+#define _RTW_MLME_C_
+
+#include <hal_data.h>
+#include <usb_osintf.h>
+
+extern void indicate_wx_scan_complete_event(_adapter *padapter);
+extern u8 rtw_do_join(_adapter *padapter);
+
+
+static sint _rtw_init_mlme_priv(_adapter *padapter)
+{
+ sint i;
+ u8 *pbuf;
+ struct wlan_network *pnetwork;
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ sint res = _SUCCESS;
+
+ /*ht_priv*/
+ pmlmepriv->htpriv.ampdu_enable = false;/*set to disabled*/
+
+ pmlmepriv->nic_hdl = (u8 *)padapter;
+
+ pmlmepriv->pscanned = NULL;
+ /*pmlmepriv->fw_state = WIFI_STATION_STATE; */ /*Must sync with rtw_wdev_alloc()*/
+ /*init_fwstate(pmlmepriv, WIFI_STATION_STATE);*/
+ init_fwstate(pmlmepriv, WIFI_NULL_STATE);/*assigned interface role(STA/AP) must after execute set_opmode*/
+
+ /* wdev->iftype = NL80211_IFTYPE_STATION*/
+ pmlmepriv->cur_network.network.InfrastructureMode = Ndis802_11AutoUnknown;
+ pmlmepriv->scan_mode = SCAN_ACTIVE; /* 1: active, 0: pasive. Maybe someday we should rename this varable to "active_mode" (Jeff) */
+
+ spin_lock_init(&(pmlmepriv->lock));
+ _rtw_init_queue(&(pmlmepriv->free_bss_pool));
+ _rtw_init_queue(&(pmlmepriv->scanned_queue));
+
+ set_scanned_network_val(pmlmepriv, 0);
+
+ memset(&pmlmepriv->assoc_ssid, 0, sizeof(NDIS_802_11_SSID));
+
+ pbuf = rtw_zvmalloc(MAX_BSS_CNT * (sizeof(struct wlan_network)));
+
+ if (pbuf == NULL) {
+ res = _FAIL;
+ goto exit;
+ }
+ pmlmepriv->free_bss_buf = pbuf;
+
+ pnetwork = (struct wlan_network *)pbuf;
+
+ for (i = 0; i < MAX_BSS_CNT; i++) {
+ INIT_LIST_HEAD(&(pnetwork->list));
+
+ list_add_tail(&(pnetwork->list), &(pmlmepriv->free_bss_pool.queue));
+
+ pnetwork++;
+ }
+
+ /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
+
+ rtw_clear_scan_deny(padapter);
+#ifdef CONFIG_ARP_KEEP_ALIVE
+ pmlmepriv->bGetGateway = 0;
+ pmlmepriv->GetGatewayTryCnt = 0;
+#endif
+
+#ifdef CONFIG_LAYER2_ROAMING
+#define RTW_ROAM_SCAN_RESULT_EXP_MS (5*1000)
+#define RTW_ROAM_RSSI_DIFF_TH 10
+#define RTW_ROAM_SCAN_INTERVAL_MS (10*1000)
+#define RTW_ROAM_RSSI_THRESHOLD 70
+
+ pmlmepriv->roam_flags = 0
+ | RTW_ROAM_ON_EXPIRED
+#ifdef CONFIG_LAYER2_ROAMING_RESUME
+ | RTW_ROAM_ON_RESUME
+#endif
+#ifdef CONFIG_LAYER2_ROAMING_ACTIVE
+ | RTW_ROAM_ACTIVE
+#endif
+ ;
+
+ pmlmepriv->roam_scanr_exp_ms = RTW_ROAM_SCAN_RESULT_EXP_MS;
+ pmlmepriv->roam_rssi_diff_th = RTW_ROAM_RSSI_DIFF_TH;
+ pmlmepriv->roam_scan_int_ms = RTW_ROAM_SCAN_INTERVAL_MS;
+ pmlmepriv->roam_rssi_threshold = RTW_ROAM_RSSI_THRESHOLD;
+#endif /* CONFIG_LAYER2_ROAMING */
+
+#ifdef CONFIG_RTW_80211R
+ memset(&pmlmepriv->ftpriv, 0, sizeof(ft_priv));
+ pmlmepriv->ftpriv.ft_flags = 0
+ | RTW_FT_STA_SUPPORTED
+ | RTW_FT_STA_OVER_DS_SUPPORTED
+ ;
+#endif
+ rtw_init_mlme_timer(padapter);
+
+exit:
+
+
+ return res;
+}
+
+static void rtw_mfree_mlme_priv_lock(struct mlme_priv *pmlmepriv)
+{
+}
+
+static void rtw_free_mlme_ie_data(u8 **ppie, u32 *plen)
+{
+ if (*ppie) {
+ rtw_mfree(*ppie, *plen);
+ *plen = 0;
+ *ppie = NULL;
+ }
+}
+
+void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv)
+{
+#if defined(CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
+ rtw_buf_free(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len);
+ rtw_buf_free(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len);
+ rtw_free_mlme_ie_data(&pmlmepriv->wps_beacon_ie, &pmlmepriv->wps_beacon_ie_len);
+ rtw_free_mlme_ie_data(&pmlmepriv->wps_probe_req_ie, &pmlmepriv->wps_probe_req_ie_len);
+ rtw_free_mlme_ie_data(&pmlmepriv->wps_probe_resp_ie, &pmlmepriv->wps_probe_resp_ie_len);
+ rtw_free_mlme_ie_data(&pmlmepriv->wps_assoc_resp_ie, &pmlmepriv->wps_assoc_resp_ie_len);
+
+ rtw_free_mlme_ie_data(&pmlmepriv->p2p_beacon_ie, &pmlmepriv->p2p_beacon_ie_len);
+ rtw_free_mlme_ie_data(&pmlmepriv->p2p_probe_req_ie, &pmlmepriv->p2p_probe_req_ie_len);
+ rtw_free_mlme_ie_data(&pmlmepriv->p2p_probe_resp_ie, &pmlmepriv->p2p_probe_resp_ie_len);
+ rtw_free_mlme_ie_data(&pmlmepriv->p2p_go_probe_resp_ie, &pmlmepriv->p2p_go_probe_resp_ie_len);
+ rtw_free_mlme_ie_data(&pmlmepriv->p2p_assoc_req_ie, &pmlmepriv->p2p_assoc_req_ie_len);
+ rtw_free_mlme_ie_data(&pmlmepriv->p2p_assoc_resp_ie, &pmlmepriv->p2p_assoc_resp_ie_len);
+#endif
+
+#if defined(CONFIG_WFD) && defined(CONFIG_IOCTL_CFG80211)
+ rtw_free_mlme_ie_data(&pmlmepriv->wfd_beacon_ie, &pmlmepriv->wfd_beacon_ie_len);
+ rtw_free_mlme_ie_data(&pmlmepriv->wfd_probe_req_ie, &pmlmepriv->wfd_probe_req_ie_len);
+ rtw_free_mlme_ie_data(&pmlmepriv->wfd_probe_resp_ie, &pmlmepriv->wfd_probe_resp_ie_len);
+ rtw_free_mlme_ie_data(&pmlmepriv->wfd_go_probe_resp_ie, &pmlmepriv->wfd_go_probe_resp_ie_len);
+ rtw_free_mlme_ie_data(&pmlmepriv->wfd_assoc_req_ie, &pmlmepriv->wfd_assoc_req_ie_len);
+ rtw_free_mlme_ie_data(&pmlmepriv->wfd_assoc_resp_ie, &pmlmepriv->wfd_assoc_resp_ie_len);
+#endif
+
+#ifdef CONFIG_RTW_80211R
+ rtw_free_mlme_ie_data(&pmlmepriv->auth_rsp, &pmlmepriv->auth_rsp_len);
+#endif
+}
+
+#if defined(CONFIG_WFD) && defined(CONFIG_IOCTL_CFG80211)
+int rtw_mlme_update_wfd_ie_data(struct mlme_priv *mlme, u8 type, u8 *ie, u32 ie_len)
+{
+ _adapter *adapter = mlme_to_adapter(mlme);
+ struct wifi_display_info *wfd_info = &adapter->wfd_info;
+ u8 clear = 0;
+ u8 **t_ie = NULL;
+ u32 *t_ie_len = NULL;
+ int ret = _FAIL;
+
+ if (!hal_chk_wl_func(adapter, WL_FUNC_MIRACAST))
+ goto success;
+
+ if (wfd_info->wfd_enable)
+ goto success; /* WFD IE is build by self */
+
+ if (!ie && !ie_len)
+ clear = 1;
+ else if (!ie || !ie_len) {
+ RTW_PRINT(FUNC_ADPT_FMT" type:%u, ie:%p, ie_len:%u"
+ , FUNC_ADPT_ARG(adapter), type, ie, ie_len);
+ rtw_warn_on(1);
+ goto exit;
+ }
+
+ switch (type) {
+ case MLME_BEACON_IE:
+ t_ie = &mlme->wfd_beacon_ie;
+ t_ie_len = &mlme->wfd_beacon_ie_len;
+ break;
+ case MLME_PROBE_REQ_IE:
+ t_ie = &mlme->wfd_probe_req_ie;
+ t_ie_len = &mlme->wfd_probe_req_ie_len;
+ break;
+ case MLME_PROBE_RESP_IE:
+ t_ie = &mlme->wfd_probe_resp_ie;
+ t_ie_len = &mlme->wfd_probe_resp_ie_len;
+ break;
+ case MLME_GO_PROBE_RESP_IE:
+ t_ie = &mlme->wfd_go_probe_resp_ie;
+ t_ie_len = &mlme->wfd_go_probe_resp_ie_len;
+ break;
+ case MLME_ASSOC_REQ_IE:
+ t_ie = &mlme->wfd_assoc_req_ie;
+ t_ie_len = &mlme->wfd_assoc_req_ie_len;
+ break;
+ case MLME_ASSOC_RESP_IE:
+ t_ie = &mlme->wfd_assoc_resp_ie;
+ t_ie_len = &mlme->wfd_assoc_resp_ie_len;
+ break;
+ default:
+ RTW_PRINT(FUNC_ADPT_FMT" unsupported type:%u"
+ , FUNC_ADPT_ARG(adapter), type);
+ rtw_warn_on(1);
+ goto exit;
+ }
+
+ if (*t_ie) {
+ u32 free_len = *t_ie_len;
+ *t_ie_len = 0;
+ rtw_mfree(*t_ie, free_len);
+ *t_ie = NULL;
+ }
+
+ if (!clear) {
+ *t_ie = rtw_malloc(ie_len);
+ if (*t_ie == NULL) {
+ RTW_ERR(FUNC_ADPT_FMT" type:%u, rtw_malloc() fail\n"
+ , FUNC_ADPT_ARG(adapter), type);
+ goto exit;
+ }
+ memcpy(*t_ie, ie, ie_len);
+ *t_ie_len = ie_len;
+ }
+
+ if (*t_ie && *t_ie_len) {
+ u8 *attr_content;
+ u32 attr_contentlen = 0;
+
+ attr_content = rtw_get_wfd_attr_content(*t_ie, *t_ie_len, WFD_ATTR_DEVICE_INFO, NULL, &attr_contentlen);
+ if (attr_content && attr_contentlen) {
+ if (RTW_GET_BE16(attr_content + 2) != wfd_info->rtsp_ctrlport) {
+ wfd_info->rtsp_ctrlport = RTW_GET_BE16(attr_content + 2);
+ RTW_INFO(FUNC_ADPT_FMT" type:%u, RTSP CTRL port = %u\n"
+ , FUNC_ADPT_ARG(adapter), type, wfd_info->rtsp_ctrlport);
+ }
+ }
+ }
+
+success:
+ ret = _SUCCESS;
+
+exit:
+ return ret;
+}
+#endif /* defined(CONFIG_WFD) && defined(CONFIG_IOCTL_CFG80211) */
+
+static void _rtw_free_mlme_priv(struct mlme_priv *pmlmepriv)
+{
+ if (NULL == pmlmepriv) {
+ rtw_warn_on(1);
+ goto exit;
+ }
+ rtw_free_mlme_priv_ie_data(pmlmepriv);
+
+ if (pmlmepriv) {
+ rtw_mfree_mlme_priv_lock(pmlmepriv);
+
+ if (pmlmepriv->free_bss_buf)
+ rtw_vmfree(pmlmepriv->free_bss_buf, MAX_BSS_CNT * sizeof(struct wlan_network));
+ }
+exit:
+ return;
+}
+
+static sint _rtw_enqueue_network(_queue *queue, struct wlan_network *pnetwork)
+{
+ unsigned long irqL;
+
+
+ if (pnetwork == NULL)
+ goto exit;
+
+ _enter_critical_bh(&queue->lock, &irqL);
+
+ list_add_tail(&pnetwork->list, &queue->queue);
+
+ _exit_critical_bh(&queue->lock, &irqL);
+
+exit:
+
+
+ return _SUCCESS;
+}
+
+/*
+struct wlan_network *_rtw_dequeue_network(_queue *queue)
+{
+ unsigned long irqL;
+
+ struct wlan_network *pnetwork;
+
+
+ _enter_critical_bh(&queue->lock, &irqL);
+
+ if (_rtw_queue_empty(queue))
+
+ pnetwork = NULL;
+
+ else
+ {
+ pnetwork = LIST_CONTAINOR(get_next(&queue->queue), struct wlan_network, list);
+
+ list_del_init(&(pnetwork->list));
+ }
+
+ _exit_critical_bh(&queue->lock, &irqL);
+
+
+ return pnetwork;
+}
+*/
+
+struct wlan_network *_rtw_alloc_network(struct mlme_priv *pmlmepriv) /* (_queue *free_queue) */
+{
+ unsigned long irqL;
+ struct wlan_network *pnetwork;
+ _queue *free_queue = &pmlmepriv->free_bss_pool;
+ _list *plist = NULL;
+
+
+ _enter_critical_bh(&free_queue->lock, &irqL);
+
+ if (_rtw_queue_empty(free_queue)) {
+ pnetwork = NULL;
+ goto exit;
+ }
+ plist = get_next(&(free_queue->queue));
+
+ pnetwork = LIST_CONTAINOR(plist , struct wlan_network, list);
+
+ list_del_init(&pnetwork->list);
+
+ pnetwork->network_type = 0;
+ pnetwork->fixed = false;
+ pnetwork->last_scanned = jiffies;
+ pnetwork->aid = 0;
+ pnetwork->join_res = 0;
+
+ pmlmepriv->num_of_scanned++;
+
+exit:
+ _exit_critical_bh(&free_queue->lock, &irqL);
+
+
+ return pnetwork;
+}
+
+void _rtw_free_network(struct mlme_priv *pmlmepriv , struct wlan_network *pnetwork, u8 isfreeall)
+{
+ u32 delta_time;
+ u32 lifetime = SCANQUEUE_LIFETIME;
+ unsigned long irqL;
+ _queue *free_queue = &(pmlmepriv->free_bss_pool);
+
+
+ if (pnetwork == NULL)
+ goto exit;
+
+ if (pnetwork->fixed)
+ goto exit;
+
+ if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) ||
+ (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)))
+ lifetime = 1;
+
+ if (!isfreeall) {
+ delta_time = (u32) rtw_get_passing_time_ms(pnetwork->last_scanned);
+ if (delta_time < lifetime) /* unit:msec */
+ goto exit;
+ }
+
+ _enter_critical_bh(&free_queue->lock, &irqL);
+
+ list_del_init(&(pnetwork->list));
+
+ list_add_tail(&(pnetwork->list), &(free_queue->queue));
+
+ pmlmepriv->num_of_scanned--;
+
+
+ /* RTW_INFO("_rtw_free_network:SSID=%s\n", pnetwork->network.Ssid.Ssid); */
+
+ _exit_critical_bh(&free_queue->lock, &irqL);
+
+exit:
+ return;
+}
+
+void _rtw_free_network_nolock(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork)
+{
+
+ _queue *free_queue = &(pmlmepriv->free_bss_pool);
+
+
+ if (pnetwork == NULL)
+ goto exit;
+
+ if (pnetwork->fixed)
+ goto exit;
+
+ /* _enter_critical(&free_queue->lock, &irqL); */
+
+ list_del_init(&(pnetwork->list));
+
+ list_add_tail(&(pnetwork->list), get_list_head(free_queue));
+
+ pmlmepriv->num_of_scanned--;
+
+ /* _exit_critical(&free_queue->lock, &irqL); */
+
+exit:
+ return;
+}
+
+
+/*
+ return the wlan_network with the matching addr
+
+ Shall be calle under atomic context... to avoid possible racing condition...
+*/
+struct wlan_network *_rtw_find_network(_queue *scanned_queue, u8 *addr)
+{
+
+ /* unsigned long irqL; */
+ _list *phead, *plist;
+ struct wlan_network *pnetwork = NULL;
+ u8 zero_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
+
+
+ if (!memcmp(zero_addr, addr, ETH_ALEN)) {
+ pnetwork = NULL;
+ goto exit;
+ }
+
+ /* _enter_critical_bh(&scanned_queue->lock, &irqL); */
+
+ phead = get_list_head(scanned_queue);
+ plist = get_next(phead);
+
+ while (plist != phead) {
+ pnetwork = LIST_CONTAINOR(plist, struct wlan_network , list);
+
+ if (!memcmp(addr, pnetwork->network.MacAddress, ETH_ALEN))
+ break;
+
+ plist = get_next(plist);
+ }
+
+ if (plist == phead)
+ pnetwork = NULL;
+
+ /* _exit_critical_bh(&scanned_queue->lock, &irqL); */
+
+exit:
+
+
+ return pnetwork;
+
+}
+
+
+void _rtw_free_network_queue(_adapter *padapter, u8 isfreeall)
+{
+ unsigned long irqL;
+ _list *phead, *plist;
+ struct wlan_network *pnetwork;
+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+ _queue *scanned_queue = &pmlmepriv->scanned_queue;
+
+
+
+ _enter_critical_bh(&scanned_queue->lock, &irqL);
+
+ phead = get_list_head(scanned_queue);
+ plist = get_next(phead);
+
+ while (rtw_end_of_queue_search(phead, plist) == false) {
+
+ pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
+
+ plist = get_next(plist);
+
+ _rtw_free_network(pmlmepriv, pnetwork, isfreeall);
+
+ }
+
+ _exit_critical_bh(&scanned_queue->lock, &irqL);
+
+
+}
+
+
+
+
+sint rtw_if_up(_adapter *padapter)
+{
+
+ sint res;
+
+ if (RTW_CANNOT_RUN(padapter) ||
+ (check_fwstate(&padapter->mlmepriv, _FW_LINKED) == false)) {
+ res = false;
+ } else
+ res = true;
+
+ return res;
+}
+
+
+void rtw_generate_random_ibss(u8 *pibss)
+{
+ *((u32 *)(&pibss[2])) = rtw_random32();
+ pibss[0] = 0x02; /* in ad-hoc mode local bit must set to 1 */
+ pibss[1] = 0x11;
+ pibss[2] = 0x87;
+}
+
+u8 *rtw_get_capability_from_ie(u8 *ie)
+{
+ return ie + 8 + 2;
+}
+
+
+u16 rtw_get_capability(WLAN_BSSID_EX *bss)
+{
+ __le16 val;
+
+ memcpy((u8 *)&val, rtw_get_capability_from_ie(bss->IEs), 2);
+ return le16_to_cpu(val);
+}
+
+u8 *rtw_get_timestampe_from_ie(u8 *ie)
+{
+ return ie + 0;
+}
+
+u8 *rtw_get_beacon_interval_from_ie(u8 *ie)
+{
+ return ie + 8;
+}
+
+
+int rtw_init_mlme_priv(_adapter *padapter) /* (struct mlme_priv *pmlmepriv) */
+{
+ int res;
+ res = _rtw_init_mlme_priv(padapter);/* (pmlmepriv); */
+ return res;
+}
+
+void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv)
+{
+ _rtw_free_mlme_priv(pmlmepriv);
+}
+
+int rtw_enqueue_network(_queue *queue, struct wlan_network *pnetwork);
+int rtw_enqueue_network(_queue *queue, struct wlan_network *pnetwork)
+{
+ int res;
+ res = _rtw_enqueue_network(queue, pnetwork);
+ return res;
+}
+
+/*
+static struct wlan_network *rtw_dequeue_network(_queue *queue)
+{
+ struct wlan_network *pnetwork;
+ pnetwork = _rtw_dequeue_network(queue);
+ return pnetwork;
+}
+*/
+
+struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv);
+struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv) /* (_queue *free_queue) */
+{
+ struct wlan_network *pnetwork;
+ pnetwork = _rtw_alloc_network(pmlmepriv);
+ return pnetwork;
+}
+
+void rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 is_freeall);
+void rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 is_freeall)/* (struct wlan_network *pnetwork, _queue *free_queue) */
+{
+ _rtw_free_network(pmlmepriv, pnetwork, is_freeall);
+}
+
+void rtw_free_network_nolock(_adapter *padapter, struct wlan_network *pnetwork);
+void rtw_free_network_nolock(_adapter *padapter, struct wlan_network *pnetwork)
+{
+ _rtw_free_network_nolock(&(padapter->mlmepriv), pnetwork);
+#ifdef CONFIG_IOCTL_CFG80211
+ rtw_cfg80211_unlink_bss(padapter, pnetwork);
+#endif /* CONFIG_IOCTL_CFG80211 */
+}
+
+
+void rtw_free_network_queue(_adapter *dev, u8 isfreeall)
+{
+ _rtw_free_network_queue(dev, isfreeall);
+}
+
+/*
+ return the wlan_network with the matching addr
+
+ Shall be calle under atomic context... to avoid possible racing condition...
+*/
+struct wlan_network *rtw_find_network(_queue *scanned_queue, u8 *addr)
+{
+ struct wlan_network *pnetwork = _rtw_find_network(scanned_queue, addr);
+
+ return pnetwork;
+}
+
+int rtw_is_same_ibss(_adapter *adapter, struct wlan_network *pnetwork)
+{
+ int ret = true;
+ struct security_priv *psecuritypriv = &adapter->securitypriv;
+
+ if ((psecuritypriv->dot11PrivacyAlgrthm != _NO_PRIVACY_) &&
+ (pnetwork->network.Privacy == 0))
+ ret = false;
+ else if ((psecuritypriv->dot11PrivacyAlgrthm == _NO_PRIVACY_) &&
+ (pnetwork->network.Privacy == 1))
+ ret = false;
+ else
+ ret = true;
+
+ return ret;
+
+}
+
+inline int is_same_ess(WLAN_BSSID_EX *a, WLAN_BSSID_EX *b)
+{
+ return (a->Ssid.SsidLength == b->Ssid.SsidLength)
+ && !memcmp(a->Ssid.Ssid, b->Ssid.Ssid, a->Ssid.SsidLength);
+}
+
+int is_same_network(WLAN_BSSID_EX *src, WLAN_BSSID_EX *dst, u8 feature)
+{
+ u16 s_cap, d_cap;
+ __le16 le_tmp;
+
+ if (rtw_bug_check(dst, src, &s_cap, &d_cap) == false)
+ return false;
+
+ memcpy((u8 *)&le_tmp, rtw_get_capability_from_ie(src->IEs), 2);
+ s_cap = le16_to_cpu(le_tmp);
+ memcpy((u8 *)&le_tmp, rtw_get_capability_from_ie(dst->IEs), 2);
+ d_cap = le16_to_cpu(le_tmp);
+
+#ifdef CONFIG_P2P
+ if ((feature == 1) && /* 1: P2P supported */
+ (!memcmp(src->MacAddress, dst->MacAddress, ETH_ALEN))
+ )
+ return true;
+#endif
+
+ return ((src->Ssid.SsidLength == dst->Ssid.SsidLength) &&
+ /* (src->Configuration.DSConfig == dst->Configuration.DSConfig) && */
+ ((!memcmp(src->MacAddress, dst->MacAddress, ETH_ALEN))) &&
+ ((!memcmp(src->Ssid.Ssid, dst->Ssid.Ssid, src->Ssid.SsidLength))) &&
+ ((s_cap & WLAN_CAPABILITY_IBSS) ==
+ (d_cap & WLAN_CAPABILITY_IBSS)) &&
+ ((s_cap & WLAN_CAPABILITY_BSS) ==
+ (d_cap & WLAN_CAPABILITY_BSS)));
+}
+
+struct wlan_network *_rtw_find_same_network(_queue *scanned_queue, struct wlan_network *network)
+{
+ _list *phead, *plist;
+ struct wlan_network *found = NULL;
+
+ phead = get_list_head(scanned_queue);
+ plist = get_next(phead);
+
+ while (plist != phead) {
+ found = LIST_CONTAINOR(plist, struct wlan_network , list);
+
+ if (is_same_network(&network->network, &found->network, 0))
+ break;
+
+ plist = get_next(plist);
+ }
+
+ if (plist == phead)
+ found = NULL;
+exit:
+ return found;
+}
+
+struct wlan_network *rtw_find_same_network(_queue *scanned_queue, struct wlan_network *network)
+{
+ unsigned long irqL;
+ struct wlan_network *found = NULL;
+
+ if (scanned_queue == NULL || network == NULL)
+ goto exit;
+
+ _enter_critical_bh(&scanned_queue->lock, &irqL);
+ found = _rtw_find_same_network(scanned_queue, network);
+ _exit_critical_bh(&scanned_queue->lock, &irqL);
+
+exit:
+ return found;
+}
+
+struct wlan_network *rtw_get_oldest_wlan_network(_queue *scanned_queue)
+{
+ _list *plist, *phead;
+
+
+ struct wlan_network *pwlan = NULL;
+ struct wlan_network *oldest = NULL;
+ phead = get_list_head(scanned_queue);
+
+ plist = get_next(phead);
+
+ while (1) {
+
+ if (rtw_end_of_queue_search(phead, plist))
+ break;
+
+ pwlan = LIST_CONTAINOR(plist, struct wlan_network, list);
+
+ if (pwlan->fixed != true) {
+ if (oldest == NULL || time_after(oldest->last_scanned, pwlan->last_scanned))
+ oldest = pwlan;
+ }
+
+ plist = get_next(plist);
+ }
+ return oldest;
+
+}
+
+void update_network(WLAN_BSSID_EX *dst, WLAN_BSSID_EX *src,
+ _adapter *padapter, bool update_ie)
+{
+ u8 ss_ori = dst->PhyInfo.SignalStrength;
+ u8 sq_ori = dst->PhyInfo.SignalQuality;
+ long rssi_ori = dst->Rssi;
+
+ u8 ss_smp = src->PhyInfo.SignalStrength;
+ u8 sq_smp = src->PhyInfo.SignalQuality;
+ long rssi_smp = src->Rssi;
+
+ u8 ss_final;
+ u8 sq_final;
+ long rssi_final;
+
+
+#ifdef CONFIG_ANTENNA_DIVERSITY
+ rtw_hal_antdiv_rssi_compared(padapter, dst, src); /* this will update src.Rssi, need consider again */
+#endif
+
+#if defined(DBG_RX_SIGNAL_DISPLAY_SSID_MONITORED) && 1
+ if (strcmp(dst->Ssid.Ssid, DBG_RX_SIGNAL_DISPLAY_SSID_MONITORED) == 0) {
+ RTW_INFO(FUNC_ADPT_FMT" %s("MAC_FMT", ch%u) ss_ori:%3u, sq_ori:%3u, rssi_ori:%3ld, ss_smp:%3u, sq_smp:%3u, rssi_smp:%3ld\n"
+ , FUNC_ADPT_ARG(padapter)
+ , src->Ssid.Ssid, MAC_ARG(src->MacAddress), src->Configuration.DSConfig
+ , ss_ori, sq_ori, rssi_ori
+ , ss_smp, sq_smp, rssi_smp
+ );
+ }
+#endif
+
+ /* The rule below is 1/5 for sample value, 4/5 for history value */
+ if (check_fwstate(&padapter->mlmepriv, _FW_LINKED) && is_same_network(&(padapter->mlmepriv.cur_network.network), src, 0)) {
+ /* Take the recvpriv's value for the connected AP*/
+ ss_final = padapter->recvpriv.signal_strength;
+ sq_final = padapter->recvpriv.signal_qual;
+ /* the rssi value here is undecorated, and will be used for antenna diversity */
+ if (sq_smp != 101) /* from the right channel */
+ rssi_final = (src->Rssi + dst->Rssi * 4) / 5;
+ else
+ rssi_final = rssi_ori;
+ } else {
+ if (sq_smp != 101) { /* from the right channel */
+ ss_final = ((u32)(src->PhyInfo.SignalStrength) + (u32)(dst->PhyInfo.SignalStrength) * 4) / 5;
+ sq_final = ((u32)(src->PhyInfo.SignalQuality) + (u32)(dst->PhyInfo.SignalQuality) * 4) / 5;
+ rssi_final = (src->Rssi + dst->Rssi * 4) / 5;
+ } else {
+ /* bss info not receving from the right channel, use the original RX signal infos */
+ ss_final = dst->PhyInfo.SignalStrength;
+ sq_final = dst->PhyInfo.SignalQuality;
+ rssi_final = dst->Rssi;
+ }
+
+ }
+
+ if (update_ie) {
+ dst->Reserved[0] = src->Reserved[0];
+ dst->Reserved[1] = src->Reserved[1];
+ memcpy((u8 *)dst, (u8 *)src, get_WLAN_BSSID_EX_sz(src));
+ }
+
+ dst->PhyInfo.SignalStrength = ss_final;
+ dst->PhyInfo.SignalQuality = sq_final;
+ dst->Rssi = rssi_final;
+
+#if defined(DBG_RX_SIGNAL_DISPLAY_SSID_MONITORED) && 1
+ if (strcmp(dst->Ssid.Ssid, DBG_RX_SIGNAL_DISPLAY_SSID_MONITORED) == 0) {
+ RTW_INFO(FUNC_ADPT_FMT" %s("MAC_FMT"), SignalStrength:%u, SignalQuality:%u, RawRSSI:%ld\n"
+ , FUNC_ADPT_ARG(padapter)
+ , dst->Ssid.Ssid, MAC_ARG(dst->MacAddress), dst->PhyInfo.SignalStrength, dst->PhyInfo.SignalQuality, dst->Rssi);
+ }
+#endif
+}
+
+static void update_current_network(_adapter *adapter, WLAN_BSSID_EX *pnetwork)
+{
+ struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
+
+
+ rtw_bug_check(&(pmlmepriv->cur_network.network),
+ &(pmlmepriv->cur_network.network),
+ &(pmlmepriv->cur_network.network),
+ &(pmlmepriv->cur_network.network));
+
+ if ((check_fwstate(pmlmepriv, _FW_LINKED)) && (is_same_network(&(pmlmepriv->cur_network.network), pnetwork, 0))) {
+ update_network(&(pmlmepriv->cur_network.network), pnetwork, adapter, true);
+ rtw_update_protection(adapter, (pmlmepriv->cur_network.network.IEs) + sizeof(NDIS_802_11_FIXED_IEs),
+ pmlmepriv->cur_network.network.IELength);
+ }
+
+
+}
+
+
+/*
+
+Caller must hold pmlmepriv->lock first.
+
+
+*/
+void rtw_update_scanned_network(_adapter *adapter, WLAN_BSSID_EX *target)
+{
+ unsigned long irqL;
+ _list *plist, *phead;
+ u32 bssid_ex_sz;
+ struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
+ struct mlme_ext_priv *pmlmeext = &(adapter->mlmeextpriv);
+#ifdef CONFIG_P2P
+ struct wifidirect_info *pwdinfo = &(adapter->wdinfo);
+#endif /* CONFIG_P2P */
+ _queue *queue = &(pmlmepriv->scanned_queue);
+ struct wlan_network *pnetwork = NULL;
+ struct wlan_network *oldest = NULL;
+ int target_find = 0;
+ u8 feature = 0;
+
+
+ _enter_critical_bh(&queue->lock, &irqL);
+ phead = get_list_head(queue);
+ plist = get_next(phead);
+
+#ifdef CONFIG_P2P
+ if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
+ feature = 1; /* p2p enable */
+#endif
+
+ while (1) {
+ if (rtw_end_of_queue_search(phead, plist))
+ break;
+
+ pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
+
+ rtw_bug_check(pnetwork, pnetwork, pnetwork, pnetwork);
+
+#ifdef CONFIG_P2P
+ if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) &&
+ (!memcmp(pnetwork->network.MacAddress, target->MacAddress, ETH_ALEN))) {
+ target_find = 1;
+ break;
+ }
+#endif
+
+ if (is_same_network(&(pnetwork->network), target, feature)) {
+ target_find = 1;
+ break;
+ }
+
+ if (rtw_roam_flags(adapter)) {
+ /* TODO: don't select netowrk in the same ess as oldest if it's new enough*/
+ }
+
+ if (oldest == NULL || time_after(oldest->last_scanned, pnetwork->last_scanned))
+ oldest = pnetwork;
+
+ plist = get_next(plist);
+
+ }
+
+
+ /* If we didn't find a match, then get a new network slot to initialize
+ * with this beacon's information */
+ /* if (rtw_end_of_queue_search(phead,plist)== true) { */
+ if (!target_find) {
+ if (_rtw_queue_empty(&(pmlmepriv->free_bss_pool))) {
+ /* If there are no more slots, expire the oldest */
+ /* list_del_init(&oldest->list); */
+ pnetwork = oldest;
+ if (pnetwork == NULL) {
+ goto exit;
+ }
+#ifdef CONFIG_ANTENNA_DIVERSITY
+ rtw_hal_get_odm_var(adapter, HAL_ODM_ANTDIV_SELECT, &(target->PhyInfo.Optimum_antenna), NULL);
+#endif
+ memcpy(&(pnetwork->network), target, get_WLAN_BSSID_EX_sz(target));
+ /* pnetwork->last_scanned = jiffies; */
+ /* variable initialize */
+ pnetwork->fixed = false;
+ pnetwork->last_scanned = jiffies;
+
+ pnetwork->network_type = 0;
+ pnetwork->aid = 0;
+ pnetwork->join_res = 0;
+
+ /* bss info not receving from the right channel */
+ if (pnetwork->network.PhyInfo.SignalQuality == 101)
+ pnetwork->network.PhyInfo.SignalQuality = 0;
+ } else {
+ /* Otherwise just pull from the free list */
+
+ pnetwork = rtw_alloc_network(pmlmepriv); /* will update scan_time */
+
+ if (pnetwork == NULL) {
+ goto exit;
+ }
+
+ bssid_ex_sz = get_WLAN_BSSID_EX_sz(target);
+ target->Length = bssid_ex_sz;
+#ifdef CONFIG_ANTENNA_DIVERSITY
+ rtw_hal_get_odm_var(adapter, HAL_ODM_ANTDIV_SELECT, &(target->PhyInfo.Optimum_antenna), NULL);
+#endif
+ memcpy(&(pnetwork->network), target, bssid_ex_sz);
+
+ pnetwork->last_scanned = jiffies;
+
+ /* bss info not receving from the right channel */
+ if (pnetwork->network.PhyInfo.SignalQuality == 101)
+ pnetwork->network.PhyInfo.SignalQuality = 0;
+
+ list_add_tail(&(pnetwork->list), &(queue->queue));
+
+ }
+ } else {
+ /* we have an entry and we are going to update it. But this entry may
+ * be already expired. In this case we do the same as we found a new
+ * net and call the new_net handler
+ */
+ bool update_ie = true;
+
+ pnetwork->last_scanned = jiffies;
+
+ /* target.Reserved[0]==1, means that scaned network is a bcn frame. */
+ if ((pnetwork->network.IELength > target->IELength) && (target->Reserved[0] == 1))
+ update_ie = false;
+
+ /* probe resp(3) > beacon(1) > probe req(2) */
+ if ((target->Reserved[0] != 2) &&
+ (target->Reserved[0] >= pnetwork->network.Reserved[0])
+ )
+ update_ie = true;
+ else
+ update_ie = false;
+
+ update_network(&(pnetwork->network), target, adapter, update_ie);
+ }
+
+exit:
+ _exit_critical_bh(&queue->lock, &irqL);
+
+}
+
+void rtw_add_network(_adapter *adapter, WLAN_BSSID_EX *pnetwork);
+void rtw_add_network(_adapter *adapter, WLAN_BSSID_EX *pnetwork)
+{
+ unsigned long irqL;
+ struct mlme_priv *pmlmepriv = &(((_adapter *)adapter)->mlmepriv);
+ /* _queue *queue = &(pmlmepriv->scanned_queue); */
+
+
+ /* _enter_critical_bh(&queue->lock, &irqL); */
+
+#if defined(CONFIG_P2P) && defined(CONFIG_P2P_REMOVE_GROUP_INFO)
+ if (adapter->registrypriv.wifi_spec == 0)
+ rtw_bss_ex_del_p2p_attr(pnetwork, P2P_ATTR_GROUP_INFO);
+#endif
+
+ if (!hal_chk_wl_func(adapter, WL_FUNC_MIRACAST))
+ rtw_bss_ex_del_wfd_ie(pnetwork);
+
+ update_current_network(adapter, pnetwork);
+
+ rtw_update_scanned_network(adapter, pnetwork);
+
+ /* _exit_critical_bh(&queue->lock, &irqL); */
+
+}
+
+/* select the desired network based on the capability of the (i)bss.
+ * check items: (1) security
+ * (2) network_type
+ * (3) WMM
+ * (4) HT
+ * (5) others */
+int rtw_is_desired_network(_adapter *adapter, struct wlan_network *pnetwork);
+int rtw_is_desired_network(_adapter *adapter, struct wlan_network *pnetwork)
+{
+ struct security_priv *psecuritypriv = &adapter->securitypriv;
+ struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
+ u32 desired_encmode;
+ u32 privacy;
+
+ /* u8 wps_ie[512]; */
+ uint wps_ielen;
+
+ int bselected = true;
+
+ desired_encmode = psecuritypriv->ndisencryptstatus;
+ privacy = pnetwork->network.Privacy;
+
+ if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS)) {
+ if (rtw_get_wps_ie(pnetwork->network.IEs + _FIXED_IE_LENGTH_, pnetwork->network.IELength - _FIXED_IE_LENGTH_, NULL, &wps_ielen) != NULL)
+ return true;
+ else
+ return false;
+ }
+ if (adapter->registrypriv.wifi_spec == 1) { /* for correct flow of 8021X to do.... */
+ u8 *p = NULL;
+ uint ie_len = 0;
+
+ if ((desired_encmode == Ndis802_11EncryptionDisabled) && (privacy != 0))
+ bselected = false;
+
+ if (psecuritypriv->ndisauthtype == Ndis802_11AuthModeWPA2PSK) {
+ p = rtw_get_ie(pnetwork->network.IEs + _BEACON_IE_OFFSET_, _RSN_IE_2_, &ie_len, (pnetwork->network.IELength - _BEACON_IE_OFFSET_));
+ if (p && ie_len > 0)
+ bselected = true;
+ else
+ bselected = false;
+ }
+ }
+
+
+ if ((desired_encmode != Ndis802_11EncryptionDisabled) && (privacy == 0)) {
+ RTW_INFO("desired_encmode: %d, privacy: %d\n", desired_encmode, privacy);
+ bselected = false;
+ }
+
+ if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) {
+ if (pnetwork->network.InfrastructureMode != pmlmepriv->cur_network.network.InfrastructureMode)
+ bselected = false;
+ }
+
+
+ return bselected;
+}
+
+/* TODO: Perry : For Power Management */
+void rtw_atimdone_event_callback(_adapter *adapter , u8 *pbuf)
+{
+
+ return;
+}
+
+
+void rtw_survey_event_callback(_adapter *adapter, u8 *pbuf)
+{
+ unsigned long irqL;
+ u32 len;
+ WLAN_BSSID_EX *pnetwork;
+ struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
+
+
+ pnetwork = (WLAN_BSSID_EX *)pbuf;
+
+ len = get_WLAN_BSSID_EX_sz(pnetwork);
+ if (len > (sizeof(WLAN_BSSID_EX))) {
+ return;
+ }
+
+
+ _enter_critical_bh(&pmlmepriv->lock, &irqL);
+
+ /* update IBSS_network 's timestamp */
+ if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))) {
+ if (!memcmp(&(pmlmepriv->cur_network.network.MacAddress), pnetwork->MacAddress, ETH_ALEN)) {
+ struct wlan_network *ibss_wlan = NULL;
+ unsigned long irqL;
+
+ memcpy(pmlmepriv->cur_network.network.IEs, pnetwork->IEs, 8);
+ _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
+ ibss_wlan = rtw_find_network(&pmlmepriv->scanned_queue, pnetwork->MacAddress);
+ if (ibss_wlan) {
+ memcpy(ibss_wlan->network.IEs , pnetwork->IEs, 8);
+ _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
+ goto exit;
+ }
+ _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
+ }
+ }
+
+ /* lock pmlmepriv->lock when you accessing network_q */
+ if ((check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) == false) {
+ if (pnetwork->Ssid.Ssid[0] == 0)
+ pnetwork->Ssid.SsidLength = 0;
+ rtw_add_network(adapter, pnetwork);
+ }
+
+exit:
+
+ _exit_critical_bh(&pmlmepriv->lock, &irqL);
+
+
+ return;
+}
+
+void rtw_surveydone_event_callback(_adapter *adapter, u8 *pbuf)
+{
+ unsigned long irqL;
+ u8 timer_cancelled;
+ struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
+#ifdef CONFIG_RTW_80211R
+ struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
+#endif
+
+#ifdef CONFIG_MLME_EXT
+ mlmeext_surveydone_event_callback(adapter);
+#endif
+
+
+ _enter_critical_bh(&pmlmepriv->lock, &irqL);
+ if (pmlmepriv->wps_probe_req_ie) {
+ u32 free_len = pmlmepriv->wps_probe_req_ie_len;
+ pmlmepriv->wps_probe_req_ie_len = 0;
+ rtw_mfree(pmlmepriv->wps_probe_req_ie, free_len);
+ pmlmepriv->wps_probe_req_ie = NULL;
+ }
+
+
+ if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == false) {
+ RTW_INFO(FUNC_ADPT_FMT" fw_state:0x%x\n", FUNC_ADPT_ARG(adapter), get_fwstate(pmlmepriv));
+ /* rtw_warn_on(1); */
+ }
+
+ _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY);
+ _exit_critical_bh(&pmlmepriv->lock, &irqL);
+
+ _cancel_timer(&pmlmepriv->scan_to_timer, &timer_cancelled);
+
+ _enter_critical_bh(&pmlmepriv->lock, &irqL);
+
+#ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
+ rtw_set_signal_stat_timer(&adapter->recvpriv);
+#endif
+
+ if (pmlmepriv->to_join) {
+ if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE))) {
+ if (check_fwstate(pmlmepriv, _FW_LINKED) == false) {
+ set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
+
+ if (rtw_select_and_join_from_scanned_queue(pmlmepriv) == _SUCCESS)
+ _set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT);
+ else {
+ WLAN_BSSID_EX *pdev_network = &(adapter->registrypriv.dev_network);
+ u8 *pibss = adapter->registrypriv.dev_network.MacAddress;
+
+ /* pmlmepriv->fw_state ^= _FW_UNDER_SURVEY; */ /* because don't set assoc_timer */
+ _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY);
+
+
+ memset(&pdev_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
+ memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(NDIS_802_11_SSID));
+
+ rtw_update_registrypriv_dev_network(adapter);
+ rtw_generate_random_ibss(pibss);
+
+ /*pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;*/
+ init_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
+
+ if (rtw_create_ibss_cmd(adapter, 0) != _SUCCESS)
+ RTW_ERR("rtw_create_ibss_cmd FAIL\n");
+
+ pmlmepriv->to_join = false;
+ }
+ }
+ } else {
+ int s_ret;
+ set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
+ pmlmepriv->to_join = false;
+ s_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv);
+ if (_SUCCESS == s_ret)
+ _set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT);
+ else if (s_ret == 2) { /* there is no need to wait for join */
+ _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
+ rtw_indicate_connect(adapter);
+ } else {
+ RTW_INFO("try_to_join, but select scanning queue fail, to_roam:%d\n", rtw_to_roam(adapter));
+
+ if (rtw_to_roam(adapter) != 0) {
+ if (rtw_dec_to_roam(adapter) == 0
+ || _SUCCESS != rtw_sitesurvey_cmd(adapter, &pmlmepriv->assoc_ssid, 1, NULL, 0)
+ ) {
+ rtw_set_to_roam(adapter, 0);
+#ifdef CONFIG_INTEL_WIDI
+ if (adapter->mlmepriv.widi_state == INTEL_WIDI_STATE_ROAMING) {
+ memset(pmlmepriv->sa_ext, 0x00, L2SDTA_SERVICE_VE_LEN);
+ intel_widi_wk_cmd(adapter, INTEL_WIDI_LISTEN_WK, NULL, 0);
+ RTW_INFO("change to widi listen\n");
+ }
+#endif /* CONFIG_INTEL_WIDI */
+ rtw_free_assoc_resources(adapter, 1);
+ rtw_indicate_disconnect(adapter, 0, false);
+ } else
+ pmlmepriv->to_join = true;
+ } else
+ rtw_indicate_disconnect(adapter, 0, false);
+ _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
+ }
+ }
+ } else {
+ if (rtw_chk_roam_flags(adapter, RTW_ROAM_ACTIVE)) {
+ if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)
+ && check_fwstate(pmlmepriv, _FW_LINKED)) {
+ if (rtw_select_roaming_candidate(pmlmepriv) == _SUCCESS) {
+#ifdef CONFIG_RTW_80211R
+ if (rtw_chk_ft_flags(adapter, RTW_FT_OVER_DS_SUPPORTED)) {
+ start_clnt_ft_action(adapter, (u8 *)pmlmepriv->roam_network->network.MacAddress);
+ } else {
+ /*wait a little time to retrieve packets buffered in the current ap while scan*/
+ _set_timer(&pmlmeext->ft_roam_timer, 30);
+ }
+#else
+ receive_disconnect(adapter, pmlmepriv->cur_network.network.MacAddress
+ , WLAN_REASON_ACTIVE_ROAM, false);
+#endif
+ }
+ }
+ }
+ }
+
+ /* RTW_INFO("scan complete in %dms\n",rtw_get_passing_time_ms(pmlmepriv->scan_start_time)); */
+
+ _exit_critical_bh(&pmlmepriv->lock, &irqL);
+
+#ifdef CONFIG_P2P_PS
+ if (check_fwstate(pmlmepriv, _FW_LINKED))
+ p2p_ps_wk_cmd(adapter, P2P_PS_SCAN_DONE, 0);
+#endif /* CONFIG_P2P_PS */
+
+ rtw_mi_os_xmit_schedule(adapter);
+
+#ifdef CONFIG_DRVEXT_MODULE_WSC
+ drvext_surveydone_callback(&adapter->drvextpriv);
+#endif
+
+#ifdef DBG_CONFIG_ERROR_DETECT
+ {
+ struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
+ if (pmlmeext->sitesurvey_res.bss_cnt == 0) {
+ /* rtw_hal_sreset_reset(adapter); */
+ }
+ }
+#endif
+
+#ifdef CONFIG_IOCTL_CFG80211
+ rtw_cfg80211_surveydone_event_callback(adapter);
+#endif /* CONFIG_IOCTL_CFG80211 */
+
+ rtw_indicate_scan_done(adapter, false);
+
+#if defined(CONFIG_CONCURRENT_MODE) && defined(CONFIG_IOCTL_CFG80211)
+ rtw_cfg80211_indicate_scan_done_for_buddy(adapter, false);
+#endif
+
+}
+
+void rtw_dummy_event_callback(_adapter *adapter , u8 *pbuf)
+{
+
+}
+
+void rtw_fwdbg_event_callback(_adapter *adapter , u8 *pbuf)
+{
+
+}
+
+static void free_scanqueue(struct mlme_priv *pmlmepriv)
+{
+ unsigned long irqL, irqL0;
+ _queue *free_queue = &pmlmepriv->free_bss_pool;
+ _queue *scan_queue = &pmlmepriv->scanned_queue;
+ _list *plist, *phead, *ptemp;
+
+
+ _enter_critical_bh(&scan_queue->lock, &irqL0);
+ _enter_critical_bh(&free_queue->lock, &irqL);
+
+ phead = get_list_head(scan_queue);
+ plist = get_next(phead);
+
+ while (plist != phead) {
+ ptemp = get_next(plist);
+ list_del_init(plist);
+ list_add_tail(plist, &free_queue->queue);
+ plist = ptemp;
+ pmlmepriv->num_of_scanned--;
+ }
+
+ _exit_critical_bh(&free_queue->lock, &irqL);
+ _exit_critical_bh(&scan_queue->lock, &irqL0);
+
+}
+
+static void rtw_reset_rx_info(struct debug_priv *pdbgpriv)
+{
+ pdbgpriv->dbg_rx_ampdu_drop_count = 0;
+ pdbgpriv->dbg_rx_ampdu_forced_indicate_count = 0;
+ pdbgpriv->dbg_rx_ampdu_loss_count = 0;
+ pdbgpriv->dbg_rx_dup_mgt_frame_drop_count = 0;
+ pdbgpriv->dbg_rx_ampdu_window_shift_cnt = 0;
+}
+
+/*
+*rtw_free_assoc_resources: the caller has to lock pmlmepriv->lock
+*/
+void rtw_free_assoc_resources(_adapter *adapter, int lock_scanned_queue)
+{
+ unsigned long irqL;
+ struct wlan_network *pwlan = NULL;
+ struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
+ struct sta_priv *pstapriv = &adapter->stapriv;
+ struct wlan_network *tgt_network = &pmlmepriv->cur_network;
+ struct dvobj_priv *psdpriv = adapter->dvobj;
+ struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
+
+
+#ifdef CONFIG_TDLS
+ struct tdls_info *ptdlsinfo = &adapter->tdlsinfo;
+#endif /* CONFIG_TDLS */
+
+
+ RTW_INFO("%s-"ADPT_FMT" tgt_network MacAddress=" MAC_FMT"ssid=%s\n",
+ __func__, ADPT_ARG(adapter), MAC_ARG(tgt_network->network.MacAddress), tgt_network->network.Ssid.Ssid);
+
+ if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
+ struct sta_info *psta;
+
+ psta = rtw_get_stainfo(&adapter->stapriv, tgt_network->network.MacAddress);
+
+#ifdef CONFIG_TDLS
+ if (ptdlsinfo->link_established) {
+ rtw_tdls_cmd(adapter, NULL, TDLS_RS_RCR);
+ rtw_reset_tdls_info(adapter);
+ rtw_free_all_stainfo(adapter);
+ /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
+ } else
+#endif /* CONFIG_TDLS */
+ {
+ /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
+ rtw_free_stainfo(adapter, psta);
+ }
+
+ /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
+
+ }
+
+ if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE)) {
+ struct sta_info *psta;
+
+ rtw_free_all_stainfo(adapter);
+
+ psta = rtw_get_bcmc_stainfo(adapter);
+ /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
+ rtw_free_stainfo(adapter, psta);
+ /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
+
+ rtw_init_bcmc_stainfo(adapter);
+ }
+
+ if (lock_scanned_queue)
+ _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
+
+ pwlan = _rtw_find_same_network(&pmlmepriv->scanned_queue, tgt_network);
+ if ((pwlan) && (!check_fwstate(pmlmepriv, WIFI_UNDER_WPS))) {
+ pwlan->fixed = false;
+
+ RTW_INFO("free disconnecting network of scanned_queue\n");
+ rtw_free_network_nolock(adapter, pwlan);
+#ifdef CONFIG_P2P
+ if (!rtw_p2p_chk_state(&adapter->wdinfo, P2P_STATE_NONE)) {
+ rtw_mi_set_scan_deny(adapter, 2000);
+ /* rtw_clear_scan_deny(adapter); */
+ }
+#endif /* CONFIG_P2P */
+ } else {
+ if (pwlan == NU