1 /******************************************************************************
3 * Copyright(c) 2013 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
20 #define __HAL_BTCOEX_C__
22 #ifdef CONFIG_BT_COEXIST
25 #include <hal_btcoex.h>
26 #include <Mp_Precomp.h>
28 //====================================
30 //====================================
31 const char *const BtProfileString[] =
40 const char *const BtSpecString[] =
51 const char *const BtLinkRoleString[] =
57 const char *const h2cStaString[] =
65 const char *const ioStaString[] =
80 const char *const GLBtcWifiBwString[]={
88 const char *const GLBtcWifiFreqString[]={
93 #define HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS 8000
95 BTC_COEXIST GLBtCoexist;
96 u8 GLBtcWiFiInScanState;
97 u8 GLBtcWiFiInIQKState;
100 u8 GLBtcBtCoexAliveRegistered;
102 u32 GLBtcDbgType[BTC_MSG_MAX];
103 u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE];
105 typedef struct _btcoexdbginfo
108 u32 size; // buffer total size
109 u32 len; // now used length
110 } BTCDBGINFO, *PBTCDBGINFO;
112 BTCDBGINFO GLBtcDbgInfo;
114 #define BT_Operation(Adapter) _FALSE
116 static void DBG_BT_INFO_INIT(PBTCDBGINFO pinfo, u8 *pbuf, u32 size)
118 if (NULL == pinfo) return;
120 _rtw_memset(pinfo, 0, sizeof(BTCDBGINFO));
128 void DBG_BT_INFO(u8 *dbgmsg)
135 pinfo = &GLBtcDbgInfo;
137 if (NULL == pinfo->info)
140 msglen = strlen(dbgmsg);
141 if (pinfo->len + msglen > pinfo->size)
144 pbuf = pinfo->info + pinfo->len;
145 _rtw_memcpy(pbuf, dbgmsg, msglen);
146 pinfo->len += msglen;
149 //====================================
150 // Debug related function
151 //====================================
152 static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)
154 if (!pBtCoexist->bBinded ||
155 NULL == pBtCoexist->Adapter)
162 static void halbtcoutsrc_DbgInit(void)
166 for (i=0; i<BTC_MSG_MAX; i++)
169 GLBtcDbgType[BTC_MSG_INTERFACE] = \
174 GLBtcDbgType[BTC_MSG_ALGORITHM] = \
175 // ALGO_BT_RSSI_STATE |
176 // ALGO_WIFI_RSSI_STATE |
180 // ALGO_TRACE_FW_DETAIL |
181 // ALGO_TRACE_FW_EXEC |
183 // ALGO_TRACE_SW_DETAIL |
184 // ALGO_TRACE_SW_EXEC |
188 static u8 halbtcoutsrc_IsCsrBtCoex(PBTC_COEXIST pBtCoexist)
190 if (pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC4
191 || pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC8
198 static u8 halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist)
200 if (pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC4
201 || pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC8
205 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
213 static void halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)
218 padapter = pBtCoexist->Adapter;
220 pBtCoexist->btInfo.bBtCtrlLps = _TRUE;
221 pBtCoexist->btInfo.bBtLpsOn = _FALSE;
223 rtw_btcoex_LPS_Leave(padapter);
226 void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)
231 padapter = pBtCoexist->Adapter;
233 pBtCoexist->btInfo.bBtCtrlLps = _TRUE;
234 pBtCoexist->btInfo.bBtLpsOn = _TRUE;
236 rtw_btcoex_LPS_Enter(padapter);
239 void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)
244 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Normal LPS behavior!!!\n"));
246 padapter = pBtCoexist->Adapter;
248 if (pBtCoexist->btInfo.bBtCtrlLps)
250 pBtCoexist->btInfo.bBtLpsOn = _FALSE;
251 rtw_btcoex_LPS_Leave(padapter);
252 pBtCoexist->btInfo.bBtCtrlLps = _FALSE;
254 // recover the LPS state to the original
256 padapter->HalFunc.UpdateLPSStatusHandler(
258 pPSC->RegLeisurePsMode,
259 pPSC->RegPowerSaveMode);
266 * 1. this function will request pwrctrl->lock
268 void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
270 #ifdef CONFIG_LPS_LCLK
272 PHAL_DATA_TYPE pHalData;
273 struct pwrctrl_priv *pwrctrl;
277 u32 timeout; // unit: ms
280 padapter = pBtCoexist->Adapter;
281 pHalData = GET_HAL_DATA(padapter);
282 pwrctrl = adapter_to_pwrctl(padapter);
284 #ifdef LPS_RPWM_WAIT_MS
285 timeout = LPS_RPWM_WAIT_MS;
286 #else // !LPS_RPWM_WAIT_MS
288 #endif // !LPS_RPWM_WAIT_MS
290 if (GLBtcBtCoexAliveRegistered == _TRUE)
293 stime = rtw_get_current_time();
295 ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
296 if (_SUCCESS == ready)
299 utime = rtw_get_passing_time_ms(stime);
306 GLBtcBtCoexAliveRegistered = _TRUE;
307 #endif // CONFIG_LPS_LCLK
312 * 1. this function will request pwrctrl->lock
314 void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)
316 #ifdef CONFIG_LPS_LCLK
319 if (GLBtcBtCoexAliveRegistered == _FALSE)
322 padapter = pBtCoexist->Adapter;
323 rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
325 GLBtcBtCoexAliveRegistered = _FALSE;
326 #endif // CONFIG_LPS_LCLK
329 void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable)
331 pBtCoexist->btInfo.bBtDisableLowPwr = bLowPwrDisable;
333 halbtcoutsrc_LeaveLowPower(pBtCoexist); // leave 32k low power.
335 halbtcoutsrc_NormalLowPower(pBtCoexist); // original 32k low power behavior.
338 void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)
341 BOOLEAN bNeedToAct = _FALSE;
342 static u32 preTime = 0;
345 padapter = pBtCoexist->Adapter;
347 //=====================================
348 // To void continuous deleteBA=>addBA=>deleteBA=>addBA
349 // This function is not allowed to continuous called.
350 // It can only be called after 8 seconds.
351 //=====================================
353 curTime = rtw_systime_to_ms(rtw_get_current_time());
354 if((curTime - preTime) < HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS) // over 8 seconds you can execute this function again.
363 if (pBtCoexist->btInfo.bRejectAggPkt)
365 rtw_btcoex_RejectApAggregatedPacket(padapter, _TRUE);
366 pBtCoexist->btInfo.bPreRejectAggPkt = pBtCoexist->btInfo.bRejectAggPkt;
370 if(pBtCoexist->btInfo.bPreRejectAggPkt)
373 pBtCoexist->btInfo.bPreRejectAggPkt = pBtCoexist->btInfo.bRejectAggPkt;
376 if (pBtCoexist->btInfo.bPreBtCtrlAggBufSize !=
377 pBtCoexist->btInfo.bBtCtrlAggBufSize)
380 pBtCoexist->btInfo.bPreBtCtrlAggBufSize = pBtCoexist->btInfo.bBtCtrlAggBufSize;
383 if (pBtCoexist->btInfo.bBtCtrlAggBufSize)
385 if (pBtCoexist->btInfo.preAggBufSize !=
386 pBtCoexist->btInfo.aggBufSize)
390 pBtCoexist->btInfo.preAggBufSize = pBtCoexist->btInfo.aggBufSize;
395 rtw_btcoex_RejectApAggregatedPacket(padapter, _TRUE);
396 rtw_btcoex_RejectApAggregatedPacket(padapter, _FALSE);
401 u8 halbtcoutsrc_IsWifiBusy(PADAPTER padapter)
403 struct mlme_priv *pmlmepriv;
406 pmlmepriv = &padapter->mlmepriv;
408 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
410 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
412 if (_TRUE == pmlmepriv->LinkDetectInfo.bBusyTraffic)
416 #if defined(CONFIG_CONCURRENT_MODE) || defined(CONFIG_DUALMAC_CONCURRENT)
417 pmlmepriv = &padapter->pbuddy_adapter->mlmepriv;
419 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
421 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
423 if (_TRUE == pmlmepriv->LinkDetectInfo.bBusyTraffic)
431 static u32 _halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter)
433 struct mlme_priv *pmlmepriv;
435 u32 portConnectedStatus;
438 pmlmepriv = &padapter->mlmepriv;
440 portConnectedStatus = 0;
443 if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE))
447 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
449 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
452 portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
454 portConnectedStatus |= WIFI_AP_CONNECTED;
459 portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
461 portConnectedStatus |= WIFI_STA_CONNECTED;
465 return portConnectedStatus;
468 u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)
470 //=================================
472 // [31:16]=> connected port number
473 // [15:0]=> port connected bit define
474 //================================
478 u32 portConnectedStatus, numOfConnectedPort;
481 padapter = pBtCoexist->Adapter;
483 portConnectedStatus = 0;
484 numOfConnectedPort = 0;
486 retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter);
489 portConnectedStatus |= retVal;
490 numOfConnectedPort++;
493 #ifdef CONFIG_CONCURRENT_MODE
494 if (padapter->pbuddy_adapter)
496 retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter->pbuddy_adapter);
499 portConnectedStatus |= retVal;
500 numOfConnectedPort++;
503 #endif // CONFIG_CONCURRENT_MODE
505 retVal = (numOfConnectedPort << 16) | portConnectedStatus;
510 u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)
512 u16 btRealFwVer = 0x0;
517 if (!pBtCoexist->btInfo.btRealFwVer && cnt<=5)
519 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist))
520 { // mailbox exists, through mailbox
521 if (NDBG_GetBtFwVersion(pBtCoexist->Adapter, &btRealFwVer, &btFwVer))
523 pBtCoexist->btInfo.btRealFwVer = btRealFwVer;
524 pBtCoexist->btInfo.btFwVer = btFwVer;
528 pBtCoexist->btInfo.btRealFwVer = 0x0;
529 pBtCoexist->btInfo.btFwVer = 0x0;
532 else // no mailbox, query bt patch version through stack.
536 buf[0] = 0x0; // OP_Code
537 buf[1] = 0x0; // OP_Code_Length
538 BT_SendEventExtBtCoexControl(pBtCoexist->Adapter, _FALSE, dataLen, &buf[0]);
543 return pBtCoexist->btInfo.btRealFwVer;
546 s32 halbtcoutsrc_GetWifiRssi(PADAPTER padapter)
548 PHAL_DATA_TYPE pHalData;
549 s32 UndecoratedSmoothedPWDB = 0;
552 pHalData = GET_HAL_DATA(padapter);
554 UndecoratedSmoothedPWDB = pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
556 return UndecoratedSmoothedPWDB;
559 static u8 halbtcoutsrc_GetWifiScanAPNum(PADAPTER padapter)
561 struct mlme_priv *pmlmepriv;
562 struct mlme_ext_priv *pmlmeext;
563 static u8 scan_AP_num = 0;
566 pmlmepriv = &padapter->mlmepriv;
567 pmlmeext = &padapter->mlmeextpriv;
569 if (GLBtcWiFiInScanState == _FALSE) {
570 if (pmlmepriv->num_of_scanned > 0xFF)
573 scan_AP_num = (u8)pmlmepriv->num_of_scanned;
579 u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
581 PBTC_COEXIST pBtCoexist;
583 PHAL_DATA_TYPE pHalData;
584 struct mlme_ext_priv *mlmeext;
585 u8 bSoftApExist, bVwifiExist;
593 pBtCoexist = (PBTC_COEXIST)pBtcContext;
594 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
597 padapter = pBtCoexist->Adapter;
598 pHalData = GET_HAL_DATA(padapter);
599 mlmeext = &padapter->mlmeextpriv;
600 bSoftApExist = _FALSE;
601 bVwifiExist = _FALSE;
603 pS4Tmp = (s32*)pOutBuf;
604 pU4Tmp = (u32*)pOutBuf;
605 pU1Tmp = (u8*)pOutBuf;
610 case BTC_GET_BL_HS_OPERATION:
615 case BTC_GET_BL_HS_CONNECTING:
620 case BTC_GET_BL_WIFI_CONNECTED:
621 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE);
622 #ifdef CONFIG_CONCURRENT_MODE
623 if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
625 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_ASOC_STATE);
627 #endif // CONFIG_CONCURRENT_MODE
630 case BTC_GET_BL_WIFI_BUSY:
631 *pu8 = halbtcoutsrc_IsWifiBusy(padapter);
634 case BTC_GET_BL_WIFI_SCAN:
636 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_SITE_MONITOR);
637 #ifdef CONFIG_CONCURRENT_MODE
638 if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
640 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_SITE_MONITOR);
642 #endif // CONFIG_CONCURRENT_MODE
644 /* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag
645 WIFI_SITE_MONITOR in fwstate may not be cleared in time */
646 *pu8 = GLBtcWiFiInScanState;
650 case BTC_GET_BL_WIFI_LINK:
651 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
652 #ifdef CONFIG_CONCURRENT_MODE
653 if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
655 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_UNDER_LINKING);
657 #endif // CONFIG_CONCURRENT_MODE
660 case BTC_GET_BL_WIFI_ROAM:
661 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
662 #ifdef CONFIG_CONCURRENT_MODE
663 if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
665 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_UNDER_LINKING);
667 #endif // CONFIG_CONCURRENT_MODE
670 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
674 case BTC_GET_BL_WIFI_UNDER_5G:
675 *pu8 = (pHalData->CurrentBandType == 1)? _TRUE : _FALSE;
678 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
679 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE);
680 #ifdef CONFIG_CONCURRENT_MODE
681 if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
683 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_AP_STATE);
685 #endif // CONFIG_CONCURRENT_MODE
688 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
689 *pu8 = padapter->securitypriv.dot11PrivacyAlgrthm == 0? _FALSE: _TRUE;
692 case BTC_GET_BL_WIFI_UNDER_B_MODE:
693 if (mlmeext->cur_wireless_mode == WIRELESS_11B)
699 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
700 if (padapter->registrypriv.mp_mode == 0)
710 case BTC_GET_BL_EXT_SWITCH:
713 case BTC_GET_BL_IS_ASUS_8723B:
714 /* Always return FALSE in linux driver since this case is added only for windows driver */
718 case BTC_GET_S4_WIFI_RSSI:
719 *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
722 case BTC_GET_S4_HS_RSSI:
727 case BTC_GET_U4_WIFI_BW:
728 if (IsLegacyOnly(mlmeext->cur_wireless_mode))
729 *pU4Tmp = BTC_WIFI_BW_LEGACY;
730 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
731 *pU4Tmp = BTC_WIFI_BW_HT20;
732 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_40)
733 *pU4Tmp = BTC_WIFI_BW_HT40;
735 *pU4Tmp = BTC_WIFI_BW_HT40; /* todo */
738 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
740 PRT_LINK_DETECT_T plinkinfo;
741 plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
743 if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
744 *pU4Tmp = BTC_WIFI_TRAFFIC_TX;
746 *pU4Tmp = BTC_WIFI_TRAFFIC_RX;
750 case BTC_GET_U4_WIFI_FW_VER:
751 *pU4Tmp = pHalData->FirmwareVersion << 16;
752 *pU4Tmp |= pHalData->FirmwareSubVersion;
755 case BTC_GET_U4_WIFI_LINK_STATUS:
756 *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
759 case BTC_GET_U4_BT_PATCH_VER:
760 *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
763 case BTC_GET_U1_WIFI_DOT11_CHNL:
764 *pU1Tmp = padapter->mlmeextpriv.cur_channel;
767 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
768 *pU1Tmp = pHalData->CurrentChannel;
771 case BTC_GET_U1_WIFI_HS_CHNL:
776 case BTC_GET_U1_MAC_PHY_MODE:
778 // *pU1Tmp = BTC_DMSP;
779 // *pU1Tmp = BTC_DMDP;
780 // *pU1Tmp = BTC_MP_UNKNOWN;
783 case BTC_GET_U1_AP_NUM:
784 *pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter);
786 case BTC_GET_U1_ANT_TYPE:
787 *pU1Tmp = (u1Byte)BTC_ANT_TYPE_0;
790 //=======1Ant===========
791 case BTC_GET_U1_LPS_MODE:
792 *pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode;
803 u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
805 PBTC_COEXIST pBtCoexist;
807 PHAL_DATA_TYPE pHalData;
814 pBtCoexist = (PBTC_COEXIST)pBtcContext;
815 padapter = pBtCoexist->Adapter;
816 pHalData = GET_HAL_DATA(padapter);
818 pU1Tmp = (u8*)pInBuf;
819 pU4Tmp = (u32*)pInBuf;
822 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
827 // set some u8 type variables.
828 case BTC_SET_BL_BT_DISABLE:
829 pBtCoexist->btInfo.bBtDisabled = *pu8;
832 case BTC_SET_BL_BT_TRAFFIC_BUSY:
833 pBtCoexist->btInfo.bBtBusy = *pu8;
836 case BTC_SET_BL_BT_LIMITED_DIG:
837 pBtCoexist->btInfo.bLimitedDig = *pu8;
840 case BTC_SET_BL_FORCE_TO_ROAM:
841 pBtCoexist->btInfo.bForceToRoam = *pu8;
844 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
845 pBtCoexist->btInfo.bRejectAggPkt = *pu8;
848 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
849 pBtCoexist->btInfo.bBtCtrlAggBufSize = *pu8;
852 case BTC_SET_BL_INC_SCAN_DEV_NUM:
853 pBtCoexist->btInfo.bIncreaseScanDevNum = *pu8;
856 case BTC_SET_BL_BT_TX_RX_MASK:
857 pBtCoexist->btInfo.bBtTxRxMask = *pu8;
860 case BTC_SET_BL_MIRACAST_PLUS_BT:
861 pBtCoexist->btInfo.bMiracastPlusBt = *pu8;
864 // set some u8 type variables.
865 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
866 pBtCoexist->btInfo.rssiAdjustForAgcTableOn = *pU1Tmp;
869 case BTC_SET_U1_AGG_BUF_SIZE:
870 pBtCoexist->btInfo.aggBufSize = *pU1Tmp;
873 // the following are some action which will be triggered
874 case BTC_SET_ACT_GET_BT_RSSI:
876 BT_SendGetBtRssiEvent(padapter);
882 case BTC_SET_ACT_AGGREGATE_CTRL:
883 halbtcoutsrc_AggregationCheck(pBtCoexist);
886 //=======1Ant===========
887 // set some u8 type variables.
888 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
889 pBtCoexist->btInfo.rssiAdjustFor1AntCoexType = *pU1Tmp;
892 case BTC_SET_U1_LPS_VAL:
893 pBtCoexist->btInfo.lpsVal = *pU1Tmp;
896 case BTC_SET_U1_RPWM_VAL:
897 pBtCoexist->btInfo.rpwmVal = *pU1Tmp;
900 // the following are some action which will be triggered
901 case BTC_SET_ACT_LEAVE_LPS:
902 halbtcoutsrc_LeaveLps(pBtCoexist);
905 case BTC_SET_ACT_ENTER_LPS:
906 halbtcoutsrc_EnterLps(pBtCoexist);
909 case BTC_SET_ACT_NORMAL_LPS:
910 halbtcoutsrc_NormalLps(pBtCoexist);
913 case BTC_SET_ACT_DISABLE_LOW_POWER:
914 halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
917 case BTC_SET_ACT_UPDATE_RAMASK:
918 pBtCoexist->btInfo.raMask = *pU4Tmp;
920 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == _TRUE)
922 struct sta_info *psta;
923 PWLAN_BSSID_EX cur_network;
925 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
926 psta = rtw_get_stainfo(&padapter->stapriv, cur_network->MacAddress);
927 rtw_hal_update_ra_mask(psta, 0);
931 case BTC_SET_ACT_SEND_MIMO_PS:
933 u8 newMimoPsMode = 3;
934 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
935 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
937 // *pU1Tmp = 0 use SM_PS static type
938 // *pU1Tmp = 1 disable SM_PS
940 newMimoPsMode = WLAN_HT_CAP_SM_PS_STATIC;
942 newMimoPsMode = WLAN_HT_CAP_SM_PS_DISABLED;
944 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == _TRUE)
946 //issue_action_SM_PS(padapter, get_my_bssid(&(pmlmeinfo->network)), newMimoPsMode);
947 issue_action_SM_PS_wait_ack(padapter, get_my_bssid(&(pmlmeinfo->network)), newMimoPsMode, 3, 1);
952 case BTC_SET_ACT_CTRL_BT_INFO:
955 u8 dataLen = *pU1Tmp;
959 _rtw_memcpy(tmpBuf, pU1Tmp+1, dataLen);
961 // BT_SendEventExtBtInfoControl(padapter, dataLen, &tmpBuf[0]);
968 case BTC_SET_ACT_CTRL_BT_COEX:
971 u8 dataLen = *pU1Tmp;
975 _rtw_memcpy(tmpBuf, pU1Tmp+1, dataLen);
977 // BT_SendEventExtBtCoexControl(padapter, _FALSE, dataLen, &tmpBuf[0]);
983 case BTC_SET_ACT_CTRL_8723B_ANT:
986 u1Byte dataLen=*pU1Tmp;
990 PlatformMoveMemory(&tmpBuf[0], pU1Tmp+1, dataLen);
992 BT_Set8723bAnt(Adapter, dataLen, &tmpBuf[0]);
998 //=====================
1007 u8 halbtcoutsrc_UnderIps(PBTC_COEXIST pBtCoexist)
1010 struct pwrctrl_priv *pwrpriv;
1013 padapter = pBtCoexist->Adapter;
1014 pwrpriv = &padapter->dvobj->pwrctl_priv;
1015 bMacPwrCtrlOn = _FALSE;
1017 if ((_TRUE == pwrpriv->bips_processing)
1018 && (IPS_NONE != pwrpriv->ips_mode_req)
1024 if (rf_off == pwrpriv->rf_pwrstate)
1029 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
1030 if (_FALSE == bMacPwrCtrlOn)
1038 u8 halbtcoutsrc_UnderLps(PBTC_COEXIST pBtCoexist)
1040 return GLBtcWiFiInLPS;
1043 u8 halbtcoutsrc_Under32K(PBTC_COEXIST pBtCoexist)
1045 /* todo: the method to check whether wifi is under 32K or not */
1049 void halbtcoutsrc_DisplayCoexStatistics(PBTC_COEXIST pBtCoexist)
1052 PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1053 PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1054 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
1055 u8 *cliBuf = pBtCoexist->cliBuf;
1058 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Statistics]============");
1061 #if (H2C_USE_IO_THREAD != 1)
1062 for(i=0; i<H2C_STATUS_MAX; i++)
1064 if (pHalData->h2cStatistics[i])
1066 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
1067 h2cStaString[i], pHalData->h2cStatistics[i]);
1072 for(i=0; i<IO_STATUS_MAX; i++)
1074 if(Adapter->ioComStr.ioH2cStatistics[i])
1076 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
1077 ioStaString[i], Adapter->ioComStr.ioH2cStatistics[i]);
1083 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
1084 pHalData->LastHMEBoxNum);
1086 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "LastOkH2c/FirstFailH2c(fwNotRead)", \
1087 pHalData->lastSuccessH2cEid, pHalData->firstFailedH2cEid);
1090 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "c2hIsr/c2hIntr/clr1AF/noRdy/noBuf", \
1091 pHalData->InterruptLog.nIMR_C2HCMD, DBG_Var.c2hInterruptCnt, DBG_Var.c2hClrReadC2hCnt,
1092 DBG_Var.c2hNotReadyCnt, DBG_Var.c2hBufAlloFailCnt);
1095 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "c2hPacket", \
1096 DBG_Var.c2hPacketCnt);
1099 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Periodical/ DbgCtrl", \
1100 pBtCoexist->statistics.cntPeriodical, pBtCoexist->statistics.cntDbgCtrl);
1102 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "PowerOn/InitHw/InitCoexDm/RfStatus", \
1103 pBtCoexist->statistics.cntPowerOn, pBtCoexist->statistics.cntInitHwConfig, pBtCoexist->statistics.cntInitCoexDm,
1104 pBtCoexist->statistics.cntRfStatusNotify);
1106 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "Ips/Lps/Scan/Connect/Mstatus", \
1107 pBtCoexist->statistics.cntIpsNotify, pBtCoexist->statistics.cntLpsNotify,
1108 pBtCoexist->statistics.cntScanNotify, pBtCoexist->statistics.cntConnectNotify,
1109 pBtCoexist->statistics.cntMediaStatusNotify);
1111 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Special pkt/Bt info", \
1112 pBtCoexist->statistics.cntSpecialPacketNotify, pBtCoexist->statistics.cntBtInfoNotify);
1117 void halbtcoutsrc_DisplayBtLinkInfo(PBTC_COEXIST pBtCoexist)
1120 PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1121 PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1122 u8 *cliBuf = pBtCoexist->cliBuf;
1126 if (pBtCoexist->stackInfo.bProfileNotified)
1128 for (i=0; i<pBtMgnt->ExtConfig.NumberOfACL; i++)
1130 if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1)
1132 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role", \
1133 BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
1134 BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec],
1135 BtLinkRoleString[pBtMgnt->ExtConfig.aclLink[i].linkRole]);
1136 CL_PRINTF(cliBuf); }
1139 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
1140 BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
1141 BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec]);
1149 void halbtcoutsrc_DisplayWifiStatus(PBTC_COEXIST pBtCoexist)
1151 PADAPTER padapter = pBtCoexist->Adapter;
1152 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1153 u8* cliBuf=pBtCoexist->cliBuf;
1154 s32 wifiRssi=0, btHsRssi=0;
1155 BOOLEAN bScan=_FALSE, bLink=_FALSE, bRoam=_FALSE, bWifiBusy=_FALSE, bWifiUnderBMode=_FALSE;
1156 u32 wifiBw=BTC_WIFI_BW_HT20, wifiTrafficDir=BTC_WIFI_TRAFFIC_TX, wifiFreq=BTC_FREQ_2_4G;
1157 u32 wifiLinkStatus=0x0;
1158 BOOLEAN bBtHsOn=_FALSE, bLowPower=_FALSE;
1159 u8 wifiChnl=0, wifiHsChnl=0, nScanAPNum = 0, FwPSState;
1161 wifiLinkStatus = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
1162 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "STA/vWifi/HS/p2pGo/p2pGc", \
1163 ((wifiLinkStatus&WIFI_STA_CONNECTED)? 1:0), ((wifiLinkStatus&WIFI_AP_CONNECTED)? 1:0),
1164 ((wifiLinkStatus&WIFI_HS_CONNECTED)? 1:0), ((wifiLinkStatus&WIFI_P2P_GO_CONNECTED)? 1:0),
1165 ((wifiLinkStatus&WIFI_P2P_GC_CONNECTED)? 1:0) );
1168 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
1169 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifiChnl);
1170 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifiHsChnl); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d(%d)", "Dot11 channel / HsChnl(High Speed)", \
1171 wifiChnl, wifiHsChnl, bBtHsOn);
1174 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
1175 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_HS_RSSI, &btHsRssi);
1176 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Wifi rssi/ HS rssi", \
1177 wifiRssi-100, btHsRssi-100);
1181 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
1182 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
1183 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
1184 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "Wifi bLink/ bRoam/ bScan", \
1185 bLink, bRoam, bScan);
1188 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifiFreq);
1189 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1190 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1191 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
1192 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
1193 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &nScanAPNum);
1194 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s/ AP=%d ", "Wifi freq/ bw/ traffic", \
1195 GLBtcWifiFreqString[wifiFreq], ((bWifiUnderBMode)? "11b": GLBtcWifiBwString[wifiBw]),
1196 ((!bWifiBusy)? "idle": ((BTC_WIFI_TRAFFIC_TX==wifiTrafficDir)? "uplink":"downlink")),
1201 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s%s%s", "Power Status", \
1202 ((halbtcoutsrc_UnderIps(pBtCoexist) == _TRUE)? "IPS ON":"IPS OFF"),
1203 ((halbtcoutsrc_UnderLps(pBtCoexist) == _TRUE)? ", LPS ON":", LPS OFF"),
1204 ((halbtcoutsrc_Under32K(pBtCoexist) == _TRUE)? ", 32k":""));
1207 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)", "Power mode cmd(lps/rpwm)", \
1208 pBtCoexist->pwrModeVal[0], pBtCoexist->pwrModeVal[1],
1209 pBtCoexist->pwrModeVal[2], pBtCoexist->pwrModeVal[3],
1210 pBtCoexist->pwrModeVal[4], pBtCoexist->pwrModeVal[5],
1211 pBtCoexist->btInfo.lpsVal,
1212 pBtCoexist->btInfo.rpwmVal);
1216 void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType)
1218 PBTC_COEXIST pBtCoexist;
1221 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1224 case BTC_DBG_DISP_COEX_STATISTICS:
1225 halbtcoutsrc_DisplayCoexStatistics(pBtCoexist);
1227 case BTC_DBG_DISP_BT_LINK_INFO:
1228 halbtcoutsrc_DisplayBtLinkInfo(pBtCoexist);
1230 case BTC_DBG_DISP_WIFI_STATUS:
1231 halbtcoutsrc_DisplayWifiStatus(pBtCoexist);
1238 //====================================
1239 // IO related function
1240 //====================================
1241 u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
1243 PBTC_COEXIST pBtCoexist;
1247 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1248 padapter = pBtCoexist->Adapter;
1250 return rtw_read8(padapter, RegAddr);
1253 u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
1255 PBTC_COEXIST pBtCoexist;
1259 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1260 padapter = pBtCoexist->Adapter;
1262 return rtw_read16(padapter, RegAddr);
1265 u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
1267 PBTC_COEXIST pBtCoexist;
1271 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1272 padapter = pBtCoexist->Adapter;
1274 return rtw_read32(padapter, RegAddr);
1277 void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1279 PBTC_COEXIST pBtCoexist;
1283 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1284 padapter = pBtCoexist->Adapter;
1286 rtw_write8(padapter, RegAddr, Data);
1289 void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
1291 PBTC_COEXIST pBtCoexist;
1293 u8 originalValue, bitShift;
1297 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1298 padapter = pBtCoexist->Adapter;
1304 originalValue = rtw_read8(padapter, regAddr);
1306 for (i=0; i<=7; i++)
1308 if ((bitMask>>i)&0x1)
1313 data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
1316 rtw_write8(padapter, regAddr, data1b);
1319 void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
1321 PBTC_COEXIST pBtCoexist;
1325 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1326 padapter = pBtCoexist->Adapter;
1328 rtw_write16(padapter, RegAddr, Data);
1331 void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
1333 PBTC_COEXIST pBtCoexist;
1337 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1338 padapter = pBtCoexist->Adapter;
1340 rtw_write32(padapter, RegAddr, Data);
1343 void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1345 PBTC_COEXIST pBtCoexist=(PBTC_COEXIST)pBtcContext;
1346 PADAPTER Adapter=pBtCoexist->Adapter;
1348 if(BTC_INTF_SDIO == pBtCoexist->chipInterface)
1350 rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
1354 rtw_write8(Adapter, RegAddr, Data);
1358 void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
1360 PBTC_COEXIST pBtCoexist;
1364 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1365 padapter = pBtCoexist->Adapter;
1367 PHY_SetBBReg(padapter, RegAddr, BitMask, Data);
1371 u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
1373 PBTC_COEXIST pBtCoexist;
1377 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1378 padapter = pBtCoexist->Adapter;
1380 return PHY_QueryBBReg(padapter, RegAddr, BitMask);
1383 void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
1385 PBTC_COEXIST pBtCoexist;
1389 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1390 padapter = pBtCoexist->Adapter;
1392 PHY_SetRFReg(padapter, eRFPath, RegAddr, BitMask, Data);
1395 u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask)
1397 PBTC_COEXIST pBtCoexist;
1401 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1402 padapter = pBtCoexist->Adapter;
1404 return PHY_QueryRFReg(padapter, eRFPath, RegAddr, BitMask);
1407 void halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
1409 PBTC_COEXIST pBtCoexist;
1411 u8 CmdBuffer1[4] = {0};
1412 u8 CmdBuffer2[4] = {0};
1413 u8* AddrToSet = (u8*)&RegAddr;
1414 u8* ValueToSet = (u8*)&Data;
1418 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1419 padapter = pBtCoexist->Adapter;
1421 if (IS_HARDWARE_TYPE_8723B(padapter))
1423 CmdBuffer1[0] |= (OperVer & 0x0f); /* Set OperVer */
1424 CmdBuffer1[0] |= ((ReqNum << 4) & 0xf0); /* Set ReqNum */
1425 CmdBuffer1[1] = 0x0d; /* Set OpCode to BT_LO_OP_WRITE_REG_VALUE */
1426 CmdBuffer1[2] = ValueToSet[0]; /* Set WriteRegValue */
1427 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer1[0]));
1432 CmdBuffer2[0] |= (OperVer & 0x0f); /* Set OperVer */
1433 CmdBuffer2[0] |= ((ReqNum << 4) & 0xf0); /* Set ReqNum */
1434 CmdBuffer2[1] = 0x0c; /* Set OpCode of BT_LO_OP_WRITE_REG_ADDR */
1435 CmdBuffer2[3] = AddrToSet[0]; /* Set WriteRegAddr */
1436 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer2[0]));
1440 u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)
1442 /* To be implemented. Always return 0 temporarily */
1446 void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
1448 PBTC_COEXIST pBtCoexist;
1452 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1453 padapter = pBtCoexist->Adapter;
1455 rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
1458 //====================================
1459 // Extern functions called by other module
1460 //====================================
1461 u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
1463 PBTC_COEXIST pBtCoexist=&GLBtCoexist;
1464 u1Byte antNum=2, chipType;
1466 if(pBtCoexist->bBinded)
1469 pBtCoexist->bBinded = _TRUE;
1471 pBtCoexist->statistics.cntBind++;
1473 pBtCoexist->Adapter = padapter;
1475 pBtCoexist->stackInfo.bProfileNotified = _FALSE;
1477 pBtCoexist->btInfo.bBtCtrlAggBufSize = _FALSE;
1478 pBtCoexist->btInfo.aggBufSize = 5;
1480 pBtCoexist->btInfo.bIncreaseScanDevNum = _FALSE;
1481 pBtCoexist->btInfo.bMiracastPlusBt = _FALSE;
1484 chipType = HALBT_GetBtChipType(Adapter);
1485 EXhalbtcoutsrc_SetChipType(chipType);
1486 antNum = HALBT_GetPgAntNum(Adapter);
1487 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
1489 // set default antenna position to main port
1490 pBtCoexist->boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
1495 u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter)
1497 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
1499 //pBtCoexist->statistics.cntBind++;
1501 halbtcoutsrc_DbgInit();
1503 #ifdef CONFIG_PCI_HCI
1504 pBtCoexist->chipInterface = BTC_INTF_PCI;
1505 #elif defined(CONFIG_USB_HCI)
1506 pBtCoexist->chipInterface = BTC_INTF_USB;
1507 #elif defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
1508 pBtCoexist->chipInterface = BTC_INTF_SDIO;
1510 pBtCoexist->chipInterface = BTC_INTF_UNKNOWN;
1513 EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
1515 pBtCoexist->fBtcRead1Byte = halbtcoutsrc_Read1Byte;
1516 pBtCoexist->fBtcWrite1Byte = halbtcoutsrc_Write1Byte;
1517 pBtCoexist->fBtcWrite1ByteBitMask = halbtcoutsrc_BitMaskWrite1Byte;
1518 pBtCoexist->fBtcRead2Byte = halbtcoutsrc_Read2Byte;
1519 pBtCoexist->fBtcWrite2Byte = halbtcoutsrc_Write2Byte;
1520 pBtCoexist->fBtcRead4Byte = halbtcoutsrc_Read4Byte;
1521 pBtCoexist->fBtcWrite4Byte = halbtcoutsrc_Write4Byte;
1522 pBtCoexist->fBtcWriteLocalReg1Byte = halbtcoutsrc_WriteLocalReg1Byte;
1524 pBtCoexist->fBtcSetBbReg = halbtcoutsrc_SetBbReg;
1525 pBtCoexist->fBtcGetBbReg = halbtcoutsrc_GetBbReg;
1527 pBtCoexist->fBtcSetRfReg = halbtcoutsrc_SetRfReg;
1528 pBtCoexist->fBtcGetRfReg = halbtcoutsrc_GetRfReg;
1530 pBtCoexist->fBtcFillH2c = halbtcoutsrc_FillH2cCmd;
1531 pBtCoexist->fBtcDispDbgMsg = halbtcoutsrc_DisplayDbgMsg;
1533 pBtCoexist->fBtcGet = halbtcoutsrc_Get;
1534 pBtCoexist->fBtcSet = halbtcoutsrc_Set;
1535 pBtCoexist->fBtcGetBtReg = halbtcoutsrc_GetBtReg;
1536 pBtCoexist->fBtcSetBtReg = halbtcoutsrc_SetBtReg;
1538 pBtCoexist->cliBuf = &GLBtcDbgBuf[0];
1540 pBtCoexist->boardInfo.singleAntPath = 0;
1542 GLBtcWiFiInScanState = _FALSE;
1544 GLBtcWiFiInIQKState = _FALSE;
1546 GLBtcWiFiInIPS = _FALSE;
1548 GLBtcWiFiInLPS = _FALSE;
1550 GLBtcBtCoexAliveRegistered = _FALSE;
1555 void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)
1557 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1560 /* Power on setting function is only added in 8723B currently */
1561 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1563 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1564 EXhalbtc8723b2ant_PowerOnSetting(pBtCoexist);
1565 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1566 EXhalbtc8723b1ant_PowerOnSetting(pBtCoexist);
1570 void EXhalbtcoutsrc_PreLoadFirmware(PBTC_COEXIST pBtCoexist)
1572 if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1575 pBtCoexist->statistics.cntPreLoadFirmware++;
1577 if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1579 if(pBtCoexist->boardInfo.btdmAntNum == 2)
1580 EXhalbtc8723b2ant_PreLoadFirmware(pBtCoexist);
1581 else if(pBtCoexist->boardInfo.btdmAntNum == 1)
1582 EXhalbtc8723b1ant_PreLoadFirmware(pBtCoexist);
1586 void EXhalbtcoutsrc_InitHwConfig(PBTC_COEXIST pBtCoexist, u8 bWifiOnly)
1588 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1591 pBtCoexist->statistics.cntInitHwConfig++;
1593 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1595 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1596 EXhalbtc8821aCsr2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1597 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1598 EXhalbtc8821a2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1599 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1600 EXhalbtc8821a1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1602 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1604 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1605 EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1606 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1607 EXhalbtc8723b1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1609 else if (IS_HARDWARE_TYPE_8723A(pBtCoexist->Adapter))
1611 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1612 EXhalbtc8723a2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1614 else if (IS_HARDWARE_TYPE_8192C(pBtCoexist->Adapter))
1616 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1617 EXhalbtc8188c2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1619 else if (IS_HARDWARE_TYPE_8192D(pBtCoexist->Adapter))
1621 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1622 EXhalbtc8192d2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1624 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1626 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1627 EXhalbtc8192e2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1628 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1629 EXhalbtc8192e1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1631 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1633 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1634 EXhalbtc8812a2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1635 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1636 EXhalbtc8812a1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1640 void EXhalbtcoutsrc_InitCoexDm(PBTC_COEXIST pBtCoexist)
1642 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1645 pBtCoexist->statistics.cntInitCoexDm++;
1647 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1649 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1650 EXhalbtc8821aCsr2ant_InitCoexDm(pBtCoexist);
1651 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1652 EXhalbtc8821a2ant_InitCoexDm(pBtCoexist);
1653 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1654 EXhalbtc8821a1ant_InitCoexDm(pBtCoexist);
1656 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1658 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1659 EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
1660 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1661 EXhalbtc8723b1ant_InitCoexDm(pBtCoexist);
1663 else if (IS_HARDWARE_TYPE_8723A(pBtCoexist->Adapter))
1665 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1666 EXhalbtc8723a2ant_InitCoexDm(pBtCoexist);
1668 else if (IS_HARDWARE_TYPE_8192C(pBtCoexist->Adapter))
1670 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1671 EXhalbtc8188c2ant_InitCoexDm(pBtCoexist);
1673 else if (IS_HARDWARE_TYPE_8192D(pBtCoexist->Adapter))
1675 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1676 EXhalbtc8192d2ant_InitCoexDm(pBtCoexist);
1678 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1680 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1681 EXhalbtc8192e2ant_InitCoexDm(pBtCoexist);
1682 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1683 EXhalbtc8192e1ant_InitCoexDm(pBtCoexist);
1685 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1687 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1688 EXhalbtc8812a2ant_InitCoexDm(pBtCoexist);
1689 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1690 EXhalbtc8812a1ant_InitCoexDm(pBtCoexist);
1693 pBtCoexist->bInitilized = _TRUE;
1696 void EXhalbtcoutsrc_IpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
1700 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1703 pBtCoexist->statistics.cntIpsNotify++;
1704 if (pBtCoexist->bManualControl)
1707 if (IPS_NONE == type)
1709 ipsType = BTC_IPS_LEAVE;
1710 GLBtcWiFiInIPS = _FALSE;
1714 ipsType = BTC_IPS_ENTER;
1715 GLBtcWiFiInIPS = _TRUE;
1718 // All notify is called in cmd thread, don't need to leave low power again
1719 // halbtcoutsrc_LeaveLowPower(pBtCoexist);
1721 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1723 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1724 EXhalbtc8821aCsr2ant_IpsNotify(pBtCoexist, ipsType);
1725 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1726 EXhalbtc8821a2ant_IpsNotify(pBtCoexist, ipsType);
1727 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1728 EXhalbtc8821a1ant_IpsNotify(pBtCoexist, ipsType);
1730 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1732 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1733 EXhalbtc8723b2ant_IpsNotify(pBtCoexist, ipsType);
1734 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1735 EXhalbtc8723b1ant_IpsNotify(pBtCoexist, ipsType);
1737 else if (IS_HARDWARE_TYPE_8723A(pBtCoexist->Adapter))
1739 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1740 EXhalbtc8723a2ant_IpsNotify(pBtCoexist, ipsType);
1742 else if (IS_HARDWARE_TYPE_8192C(pBtCoexist->Adapter))
1744 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1745 EXhalbtc8188c2ant_IpsNotify(pBtCoexist, ipsType);
1747 else if (IS_HARDWARE_TYPE_8192D(pBtCoexist->Adapter))
1749 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1750 EXhalbtc8192d2ant_IpsNotify(pBtCoexist, ipsType);
1752 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1754 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1755 EXhalbtc8192e2ant_IpsNotify(pBtCoexist, ipsType);
1756 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1757 EXhalbtc8192e1ant_IpsNotify(pBtCoexist, ipsType);
1759 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1761 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1762 EXhalbtc8812a2ant_IpsNotify(pBtCoexist, ipsType);
1763 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1764 EXhalbtc8812a1ant_IpsNotify(pBtCoexist, ipsType);
1767 // halbtcoutsrc_NormalLowPower(pBtCoexist);
1770 void EXhalbtcoutsrc_LpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
1775 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1778 pBtCoexist->statistics.cntLpsNotify++;
1779 if (pBtCoexist->bManualControl)
1782 if (PS_MODE_ACTIVE == type)
1784 lpsType = BTC_LPS_DISABLE;
1785 GLBtcWiFiInLPS = _FALSE;
1789 lpsType = BTC_LPS_ENABLE;
1790 GLBtcWiFiInLPS = _TRUE;
1793 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1795 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1796 EXhalbtc8821aCsr2ant_LpsNotify(pBtCoexist, lpsType);
1797 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1798 EXhalbtc8821a2ant_LpsNotify(pBtCoexist, lpsType);
1799 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1800 EXhalbtc8821a1ant_LpsNotify(pBtCoexist, lpsType);
1802 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1804 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1805 EXhalbtc8723b2ant_LpsNotify(pBtCoexist, lpsType);
1806 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1807 EXhalbtc8723b1ant_LpsNotify(pBtCoexist, lpsType);
1809 else if (IS_HARDWARE_TYPE_8723A(pBtCoexist->Adapter))
1811 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1812 EXhalbtc8723a2ant_LpsNotify(pBtCoexist, lpsType);
1814 else if (IS_HARDWARE_TYPE_8192C(pBtCoexist->Adapter))
1816 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1817 EXhalbtc8188c2ant_LpsNotify(pBtCoexist, lpsType);
1819 else if (IS_HARDWARE_TYPE_8192D(pBtCoexist->Adapter))
1821 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1822 EXhalbtc8192d2ant_LpsNotify(pBtCoexist, lpsType);
1824 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1826 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1827 EXhalbtc8192e2ant_LpsNotify(pBtCoexist, lpsType);
1828 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1829 EXhalbtc8192e1ant_LpsNotify(pBtCoexist, lpsType);
1831 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1833 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1834 EXhalbtc8812a2ant_LpsNotify(pBtCoexist, lpsType);
1835 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1836 EXhalbtc8812a1ant_LpsNotify(pBtCoexist, lpsType);
1840 void EXhalbtcoutsrc_ScanNotify(PBTC_COEXIST pBtCoexist, u8 type)
1844 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1846 pBtCoexist->statistics.cntScanNotify++;
1847 if (pBtCoexist->bManualControl)
1852 scanType = BTC_SCAN_START;
1853 GLBtcWiFiInScanState = _TRUE;
1857 scanType = BTC_SCAN_FINISH;
1858 GLBtcWiFiInScanState = _FALSE;
1861 // All notify is called in cmd thread, don't need to leave low power again
1862 // halbtcoutsrc_LeaveLowPower(pBtCoexist);
1864 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1866 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1867 EXhalbtc8821aCsr2ant_ScanNotify(pBtCoexist, scanType);
1868 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1869 EXhalbtc8821a2ant_ScanNotify(pBtCoexist, scanType);
1870 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1871 EXhalbtc8821a1ant_ScanNotify(pBtCoexist, scanType);
1873 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1875 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1876 EXhalbtc8723b2ant_ScanNotify(pBtCoexist, scanType);
1877 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1878 EXhalbtc8723b1ant_ScanNotify(pBtCoexist, scanType);
1880 else if (IS_HARDWARE_TYPE_8723A(pBtCoexist->Adapter))
1882 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1883 EXhalbtc8723a2ant_ScanNotify(pBtCoexist, scanType);
1885 else if (IS_HARDWARE_TYPE_8192C(pBtCoexist->Adapter))
1887 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1888 EXhalbtc8188c2ant_ScanNotify(pBtCoexist, scanType);
1890 else if (IS_HARDWARE_TYPE_8192D(pBtCoexist->Adapter))
1892 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1893 EXhalbtc8192d2ant_ScanNotify(pBtCoexist, scanType);
1895 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1897 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1898 EXhalbtc8192e2ant_ScanNotify(pBtCoexist, scanType);
1899 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1900 EXhalbtc8192e1ant_ScanNotify(pBtCoexist, scanType);
1902 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1904 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1905 EXhalbtc8812a2ant_ScanNotify(pBtCoexist, scanType);
1906 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1907 EXhalbtc8812a1ant_ScanNotify(pBtCoexist, scanType);
1910 // halbtcoutsrc_NormalLowPower(pBtCoexist);
1913 void EXhalbtcoutsrc_ConnectNotify(PBTC_COEXIST pBtCoexist, u8 action)
1917 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1919 pBtCoexist->statistics.cntConnectNotify++;
1920 if (pBtCoexist->bManualControl)
1924 assoType = BTC_ASSOCIATE_START;
1926 assoType = BTC_ASSOCIATE_FINISH;
1928 // All notify is called in cmd thread, don't need to leave low power again
1929 // halbtcoutsrc_LeaveLowPower(pBtCoexist);
1931 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1933 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1934 EXhalbtc8821aCsr2ant_ConnectNotify(pBtCoexist, assoType);
1935 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1936 EXhalbtc8821a2ant_ConnectNotify(pBtCoexist, assoType);
1937 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1938 EXhalbtc8821a1ant_ConnectNotify(pBtCoexist, assoType);
1940 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1942 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1943 EXhalbtc8723b2ant_ConnectNotify(pBtCoexist, assoType);
1944 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1945 EXhalbtc8723b1ant_ConnectNotify(pBtCoexist, assoType);
1947 else if (IS_HARDWARE_TYPE_8723A(pBtCoexist->Adapter))
1949 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1950 EXhalbtc8723a2ant_ConnectNotify(pBtCoexist, assoType);
1952 else if (IS_HARDWARE_TYPE_8192C(pBtCoexist->Adapter))
1954 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1955 EXhalbtc8188c2ant_ConnectNotify(pBtCoexist, assoType);
1957 else if (IS_HARDWARE_TYPE_8192D(pBtCoexist->Adapter))
1959 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1960 EXhalbtc8192d2ant_ConnectNotify(pBtCoexist, assoType);
1962 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1964 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1965 EXhalbtc8192e2ant_ConnectNotify(pBtCoexist, assoType);
1966 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1967 EXhalbtc8192e1ant_ConnectNotify(pBtCoexist, assoType);
1969 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1971 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1972 EXhalbtc8812a2ant_ConnectNotify(pBtCoexist, assoType);
1973 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1974 EXhalbtc8812a1ant_ConnectNotify(pBtCoexist, assoType);
1977 // halbtcoutsrc_NormalLowPower(pBtCoexist);
1980 void EXhalbtcoutsrc_MediaStatusNotify(PBTC_COEXIST pBtCoexist, RT_MEDIA_STATUS mediaStatus)
1984 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1987 pBtCoexist->statistics.cntMediaStatusNotify++;
1988 if (pBtCoexist->bManualControl)
1991 if (RT_MEDIA_CONNECT == mediaStatus)
1992 mStatus = BTC_MEDIA_CONNECT;
1994 mStatus = BTC_MEDIA_DISCONNECT;
1996 // All notify is called in cmd thread, don't need to leave low power again
1997 // halbtcoutsrc_LeaveLowPower(pBtCoexist);
1999 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2001 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2002 EXhalbtc8821aCsr2ant_MediaStatusNotify(pBtCoexist, mStatus);
2003 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2004 EXhalbtc8821a2ant_MediaStatusNotify(pBtCoexist, mStatus);
2005 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2006 EXhalbtc8821a1ant_MediaStatusNotify(pBtCoexist, mStatus);
2008 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2010 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2011 EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, mStatus);
2012 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2013 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, mStatus);
2015 else if (IS_HARDWARE_TYPE_8723A(pBtCoexist->Adapter))
2017 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2018 EXhalbtc8723a2ant_MediaStatusNotify(pBtCoexist, mStatus);
2020 else if (IS_HARDWARE_TYPE_8192C(pBtCoexist->Adapter))
2022 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2023 EXhalbtc8188c2ant_MediaStatusNotify(pBtCoexist, mStatus);
2025 else if (IS_HARDWARE_TYPE_8192D(pBtCoexist->Adapter))
2027 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2028 EXhalbtc8192d2ant_MediaStatusNotify(pBtCoexist, mStatus);
2030 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2032 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2033 EXhalbtc8192e2ant_MediaStatusNotify(pBtCoexist, mStatus);
2034 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2035 EXhalbtc8192e1ant_MediaStatusNotify(pBtCoexist, mStatus);
2037 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2039 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2040 EXhalbtc8812a2ant_MediaStatusNotify(pBtCoexist, mStatus);
2041 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2042 EXhalbtc8812a1ant_MediaStatusNotify(pBtCoexist, mStatus);
2045 // halbtcoutsrc_NormalLowPower(pBtCoexist);
2048 void EXhalbtcoutsrc_SpecialPacketNotify(PBTC_COEXIST pBtCoexist, u8 pktType)
2052 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2054 pBtCoexist->statistics.cntSpecialPacketNotify++;
2055 if (pBtCoexist->bManualControl)
2058 if (PACKET_DHCP == pktType)
2059 packetType = BTC_PACKET_DHCP;
2060 else if (PACKET_EAPOL == pktType)
2061 packetType = BTC_PACKET_EAPOL;
2062 else if (PACKET_ARP == pktType)
2063 packetType = BTC_PACKET_ARP;
2066 packetType = BTC_PACKET_UNKNOWN;
2070 // All notify is called in cmd thread, don't need to leave low power again
2071 // halbtcoutsrc_LeaveLowPower(pBtCoexist);
2073 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2075 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2076 EXhalbtc8821aCsr2ant_SpecialPacketNotify(pBtCoexist, packetType);
2077 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2078 EXhalbtc8821a2ant_SpecialPacketNotify(pBtCoexist, packetType);
2079 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2080 EXhalbtc8821a1ant_SpecialPacketNotify(pBtCoexist, packetType);
2082 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2084 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2085 EXhalbtc8723b2ant_SpecialPacketNotify(pBtCoexist, packetType);
2086 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2087 EXhalbtc8723b1ant_SpecialPacketNotify(pBtCoexist, packetType);
2089 else if (IS_HARDWARE_TYPE_8723A(pBtCoexist->Adapter))
2091 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2092 EXhalbtc8723a2ant_SpecialPacketNotify(pBtCoexist, packetType);
2094 else if (IS_HARDWARE_TYPE_8192C(pBtCoexist->Adapter))
2096 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2097 EXhalbtc8188c2ant_SpecialPacketNotify(pBtCoexist, packetType);
2099 else if (IS_HARDWARE_TYPE_8192D(pBtCoexist->Adapter))
2101 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2102 EXhalbtc8192d2ant_SpecialPacketNotify(pBtCoexist, packetType);
2104 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2106 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2107 EXhalbtc8192e2ant_SpecialPacketNotify(pBtCoexist, packetType);
2108 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2109 EXhalbtc8192e1ant_SpecialPacketNotify(pBtCoexist, packetType);
2111 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2113 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2114 EXhalbtc8812a2ant_SpecialPacketNotify(pBtCoexist, packetType);
2115 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2116 EXhalbtc8812a1ant_SpecialPacketNotify(pBtCoexist, packetType);
2119 // halbtcoutsrc_NormalLowPower(pBtCoexist);
2122 void EXhalbtcoutsrc_BtInfoNotify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)
2124 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2127 pBtCoexist->statistics.cntBtInfoNotify++;
2129 // All notify is called in cmd thread, don't need to leave low power again
2130 // halbtcoutsrc_LeaveLowPower(pBtCoexist);
2132 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2134 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2135 EXhalbtc8821aCsr2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2136 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2137 EXhalbtc8821a2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2138 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2139 EXhalbtc8821a1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2141 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2143 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2144 EXhalbtc8723b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2145 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2146 EXhalbtc8723b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2148 else if (IS_HARDWARE_TYPE_8723A(pBtCoexist->Adapter))
2150 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2151 EXhalbtc8723a2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2153 else if (IS_HARDWARE_TYPE_8192C(pBtCoexist->Adapter))
2155 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2156 EXhalbtc8188c2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2158 else if (IS_HARDWARE_TYPE_8192D(pBtCoexist->Adapter))
2160 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2161 EXhalbtc8192d2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2163 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2165 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2166 EXhalbtc8192e2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2167 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2168 EXhalbtc8192e1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2170 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2172 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2173 EXhalbtc8812a2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2174 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2175 EXhalbtc8812a1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2178 // halbtcoutsrc_NormalLowPower(pBtCoexist);
2182 EXhalbtcoutsrc_RfStatusNotify(
2183 IN PBTC_COEXIST pBtCoexist,
2187 if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2189 pBtCoexist->statistics.cntRfStatusNotify++;
2191 if(IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2194 else if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2196 if(pBtCoexist->boardInfo.btdmAntNum == 1)
2197 EXhalbtc8723b1ant_RfStatusNotify(pBtCoexist, type);
2199 else if(IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2202 else if(IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2207 void EXhalbtcoutsrc_StackOperationNotify(PBTC_COEXIST pBtCoexist, u8 type)
2212 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2214 pBtCoexist->statistics.cntStackOperationNotify++;
2215 if (pBtCoexist->bManualControl)
2218 if ((HCI_BT_OP_INQUIRY_START == type) ||
2219 (HCI_BT_OP_PAGING_START == type) ||
2220 (HCI_BT_OP_PAIRING_START == type))
2222 stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_START;
2224 else if ((HCI_BT_OP_INQUIRY_FINISH == type) ||
2225 (HCI_BT_OP_PAGING_SUCCESS == type) ||
2226 (HCI_BT_OP_PAGING_UNSUCCESS == type) ||
2227 (HCI_BT_OP_PAIRING_FINISH == type) )
2229 stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;
2233 stackOpType = BTC_STACK_OP_NONE;
2236 if (IS_HARDWARE_TYPE_8723A(pBtCoexist->Adapter))
2238 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2239 EXhalbtc8723a2ant_StackOperationNotify(pBtCoexist, stackOpType);
2244 void EXhalbtcoutsrc_HaltNotify(PBTC_COEXIST pBtCoexist)
2246 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2249 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2251 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2252 EXhalbtc8821aCsr2ant_HaltNotify(pBtCoexist);
2253 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2254 EXhalbtc8821a2ant_HaltNotify(pBtCoexist);
2255 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2256 EXhalbtc8821a1ant_HaltNotify(pBtCoexist);
2258 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2260 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2261 EXhalbtc8723b2ant_HaltNotify(pBtCoexist);
2262 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2263 EXhalbtc8723b1ant_HaltNotify(pBtCoexist);
2265 else if (IS_HARDWARE_TYPE_8723A(pBtCoexist->Adapter))
2267 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2268 EXhalbtc8723a2ant_HaltNotify(pBtCoexist);
2269 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2270 EXhalbtc8723a1ant_HaltNotify(pBtCoexist);
2272 else if (IS_HARDWARE_TYPE_8192C(pBtCoexist->Adapter))
2274 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2275 EXhalbtc8188c2ant_HaltNotify(pBtCoexist);
2277 else if (IS_HARDWARE_TYPE_8192D(pBtCoexist->Adapter))
2279 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2280 EXhalbtc8192d2ant_HaltNotify(pBtCoexist);
2282 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2284 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2285 EXhalbtc8192e2ant_HaltNotify(pBtCoexist);
2286 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2287 EXhalbtc8192e1ant_HaltNotify(pBtCoexist);
2289 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2291 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2292 EXhalbtc8812a2ant_HaltNotify(pBtCoexist);
2293 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2294 EXhalbtc8812a1ant_HaltNotify(pBtCoexist);
2297 pBtCoexist->bBinded = FALSE;
2300 void EXhalbtcoutsrc_SwitchBtTRxMask(PBTC_COEXIST pBtCoexist)
2302 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2304 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2306 halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x01); //BT goto standby while GNT_BT 1-->0
2308 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2310 halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x15); //BT goto standby while GNT_BT 1-->0
2315 void EXhalbtcoutsrc_PnpNotify(PBTC_COEXIST pBtCoexist, u8 pnpState)
2317 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2321 // currently only 1ant we have to do the notification,
2322 // once pnp is notified to sleep state, we have to leave LPS that we can sleep normally.
2325 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2327 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2328 EXhalbtc8723b1ant_PnpNotify(pBtCoexist,pnpState);
2329 else if(pBtCoexist->boardInfo.btdmAntNum == 2)
2330 EXhalbtc8723b2ant_PnpNotify(pBtCoexist,pnpState);
2332 else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2334 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2335 EXhalbtc8821aCsr2ant_PnpNotify(pBtCoexist, pnpState);
2336 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2337 EXhalbtc8821a1ant_PnpNotify(pBtCoexist,pnpState);
2338 else if(pBtCoexist->boardInfo.btdmAntNum == 2)
2339 EXhalbtc8821a2ant_PnpNotify(pBtCoexist,pnpState);
2341 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2343 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2344 EXhalbtc8192e1ant_PnpNotify(pBtCoexist, pnpState);
2346 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2348 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2349 EXhalbtc8812a1ant_PnpNotify(pBtCoexist, pnpState);
2353 void EXhalbtcoutsrc_CoexDmSwitch(PBTC_COEXIST pBtCoexist)
2355 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2357 pBtCoexist->statistics.cntCoexDmSwitch++;
2359 halbtcoutsrc_LeaveLowPower(pBtCoexist);
2361 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2363 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2365 pBtCoexist->bStopCoexDm = TRUE;
2366 EXhalbtc8723b1ant_CoexDmReset(pBtCoexist);
2367 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2);
2368 EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, FALSE);
2369 EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
2370 pBtCoexist->bStopCoexDm = FALSE;
2374 halbtcoutsrc_NormalLowPower(pBtCoexist);
2377 void EXhalbtcoutsrc_Periodical(PBTC_COEXIST pBtCoexist)
2379 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2381 pBtCoexist->statistics.cntPeriodical++;
2383 // Periodical should be called in cmd thread,
2384 // don't need to leave low power again
2385 // halbtcoutsrc_LeaveLowPower(pBtCoexist);
2387 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2389 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2390 EXhalbtc8821aCsr2ant_Periodical(pBtCoexist);
2391 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2392 EXhalbtc8821a2ant_Periodical(pBtCoexist);
2393 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2395 if (!halbtcoutsrc_UnderIps(pBtCoexist))
2397 EXhalbtc8821a1ant_Periodical(pBtCoexist);
2401 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2403 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2404 EXhalbtc8723b2ant_Periodical(pBtCoexist);
2405 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2406 EXhalbtc8723b1ant_Periodical(pBtCoexist);
2408 else if (IS_HARDWARE_TYPE_8723A(pBtCoexist->Adapter))
2410 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2411 EXhalbtc8723a2ant_Periodical(pBtCoexist);
2412 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2414 if (!halbtcoutsrc_UnderIps(pBtCoexist))
2415 EXhalbtc8723a1ant_Periodical(pBtCoexist);
2418 else if (IS_HARDWARE_TYPE_8192C(pBtCoexist->Adapter))
2420 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2421 EXhalbtc8188c2ant_Periodical(pBtCoexist);
2423 else if (IS_HARDWARE_TYPE_8192D(pBtCoexist->Adapter))
2425 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2426 EXhalbtc8192d2ant_Periodical(pBtCoexist);
2428 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2430 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2431 EXhalbtc8192e2ant_Periodical(pBtCoexist);
2432 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2433 EXhalbtc8192e1ant_Periodical(pBtCoexist);
2435 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2437 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2438 EXhalbtc8812a2ant_Periodical(pBtCoexist);
2439 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2440 EXhalbtc8812a1ant_Periodical(pBtCoexist);
2443 // halbtcoutsrc_NormalLowPower(pBtCoexist);
2446 void EXhalbtcoutsrc_DbgControl(PBTC_COEXIST pBtCoexist, u8 opCode, u8 opLen, u8 *pData)
2448 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2451 pBtCoexist->statistics.cntDbgCtrl++;
2453 // This function doesn't be called yet,
2454 // default no need to leave low power to avoid deadlock
2455 // halbtcoutsrc_LeaveLowPower(pBtCoexist);
2457 if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2459 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2460 EXhalbtc8192e1ant_DbgControl(pBtCoexist, opCode, opLen, pData);
2462 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2464 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2465 EXhalbtc8812a2ant_DbgControl(pBtCoexist, opCode, opLen, pData);
2466 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2467 EXhalbtc8812a1ant_DbgControl(pBtCoexist, opCode, opLen, pData);
2470 // halbtcoutsrc_NormalLowPower(pBtCoexist);
2475 EXhalbtcoutsrc_AntennaDetection(
2476 IN PBTC_COEXIST pBtCoexist,
2483 if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2486 /* Need to refine the following power save operations to enable this function in the future */
2488 IPSDisable(pBtCoexist->Adapter, FALSE, 0);
2489 LeisurePSLeave(pBtCoexist->Adapter, LPS_DISABLE_BT_COEX);
2492 if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2494 if(pBtCoexist->boardInfo.btdmAntNum == 1)
2495 EXhalbtc8723b1ant_AntennaDetection(pBtCoexist, centFreq, offset, span, seconds);
2498 //IPSReturn(pBtCoexist->Adapter, 0xff);
2502 void EXhalbtcoutsrc_StackUpdateProfileInfo(void)
2505 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2506 PADAPTER padapter = (PADAPTER)GLBtCoexist.padapter;
2507 PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
2510 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2513 pBtCoexist->stackInfo.bProfileNotified = _TRUE;
2515 pBtCoexist->stackInfo.numOfLink =
2516 pBtMgnt->ExtConfig.NumberOfACL+pBtMgnt->ExtConfig.NumberOfSCO;
2519 pBtCoexist->stackInfo.bBtLinkExist = _FALSE;
2520 pBtCoexist->stackInfo.bScoExist = _FALSE;
2521 pBtCoexist->stackInfo.bAclExist = _FALSE;
2522 pBtCoexist->stackInfo.bA2dpExist = _FALSE;
2523 pBtCoexist->stackInfo.bHidExist = _FALSE;
2524 pBtCoexist->stackInfo.numOfHid = 0;
2525 pBtCoexist->stackInfo.bPanExist = _FALSE;
2527 if (!pBtMgnt->ExtConfig.NumberOfACL)
2528 pBtCoexist->stackInfo.minBtRssi = 0;
2530 if (pBtCoexist->stackInfo.numOfLink)
2532 pBtCoexist->stackInfo.bBtLinkExist = _TRUE;
2533 if (pBtMgnt->ExtConfig.NumberOfSCO)
2534 pBtCoexist->stackInfo.bScoExist = _TRUE;
2535 if (pBtMgnt->ExtConfig.NumberOfACL)
2536 pBtCoexist->stackInfo.bAclExist = _TRUE;
2539 for (i=0; i<pBtMgnt->ExtConfig.NumberOfACL; i++)
2541 if (BT_PROFILE_A2DP == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
2543 pBtCoexist->stackInfo.bA2dpExist = _TRUE;
2545 else if (BT_PROFILE_PAN == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
2547 pBtCoexist->stackInfo.bPanExist = _TRUE;
2549 else if (BT_PROFILE_HID == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
2551 pBtCoexist->stackInfo.bHidExist = _TRUE;
2552 pBtCoexist->stackInfo.numOfHid++;
2556 pBtCoexist->stackInfo.bUnknownAclExist = _TRUE;
2562 void EXhalbtcoutsrc_UpdateMinBtRssi(s8 btRssi)
2564 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2566 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2569 pBtCoexist->stackInfo.minBtRssi = btRssi;
2572 void EXhalbtcoutsrc_SetHciVersion(u16 hciVersion)
2574 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2576 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2579 pBtCoexist->stackInfo.hciVersion = hciVersion;
2582 void EXhalbtcoutsrc_SetBtPatchVersion(u16 btHciVersion, u16 btPatchVersion)
2584 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2586 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2589 pBtCoexist->btInfo.btRealFwVer = btPatchVersion;
2590 pBtCoexist->btInfo.btHciVer = btHciVersion;
2594 void EXhalbtcoutsrc_SetBtExist(u8 bBtExist)
2596 GLBtCoexist.boardInfo.bBtExist = bBtExist;
2599 void EXhalbtcoutsrc_SetChipType(u8 chipType)
2608 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_UNDEF;
2611 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_CSR_BC4;
2614 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_CSR_BC8;
2617 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723A;
2620 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8821;
2623 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723B;
2628 void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
2630 if (BT_COEX_ANT_TYPE_PG == type)
2632 GLBtCoexist.boardInfo.pgAntNum = antNum;
2633 GLBtCoexist.boardInfo.btdmAntNum = antNum;
2635 //The antenna position: Main (default) or Aux for pgAntNum=2 && btdmAntNum =1
2636 //The antenna position should be determined by auto-detect mechanism
2637 // The following is assumed to main, and those must be modified if y auto-detect mechanism is ready
2638 if ((GLBtCoexist.boardInfo.pgAntNum == 2) && (GLBtCoexist.boardInfo.btdmAntNum == 1) )
2639 GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2641 GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2644 else if (BT_COEX_ANT_TYPE_ANTDIV == type)
2646 GLBtCoexist.boardInfo.btdmAntNum = antNum;
2647 //GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2649 else if (BT_COEX_ANT_TYPE_DETECTED == type)
2651 GLBtCoexist.boardInfo.btdmAntNum = antNum;
2652 //GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2657 // Currently used by 8723b only, S0 or S1
2659 void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
2661 GLBtCoexist.boardInfo.singleAntPath = singleAntPath;
2664 void EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)
2666 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2669 halbtcoutsrc_LeaveLowPower(pBtCoexist);
2671 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2673 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2674 EXhalbtc8821aCsr2ant_DisplayCoexInfo(pBtCoexist);
2675 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2676 EXhalbtc8821a2ant_DisplayCoexInfo(pBtCoexist);
2677 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2678 EXhalbtc8821a1ant_DisplayCoexInfo(pBtCoexist);
2680 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2682 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2683 EXhalbtc8723b2ant_DisplayCoexInfo(pBtCoexist);
2684 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2685 EXhalbtc8723b1ant_DisplayCoexInfo(pBtCoexist);
2687 else if (IS_HARDWARE_TYPE_8723A(pBtCoexist->Adapter))
2689 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2690 EXhalbtc8723a2ant_DisplayCoexInfo(pBtCoexist);
2691 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2692 EXhalbtc8723a1ant_DisplayCoexInfo(pBtCoexist);
2694 else if (IS_HARDWARE_TYPE_8192C(pBtCoexist->Adapter))
2696 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2697 EXhalbtc8188c2ant_DisplayCoexInfo(pBtCoexist);
2699 else if (IS_HARDWARE_TYPE_8192D(pBtCoexist->Adapter))
2701 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2702 EXhalbtc8192d2ant_DisplayCoexInfo(pBtCoexist);
2704 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2706 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2707 EXhalbtc8192e2ant_DisplayCoexInfo(pBtCoexist);
2708 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2709 EXhalbtc8192e1ant_DisplayCoexInfo(pBtCoexist);
2711 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2713 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2714 EXhalbtc8812a2ant_DisplayCoexInfo(pBtCoexist);
2715 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2716 EXhalbtc8812a1ant_DisplayCoexInfo(pBtCoexist);
2719 halbtcoutsrc_NormalLowPower(pBtCoexist);
2723 EXhalbtcoutsrc_DisplayAntIsolation(
2724 IN PBTC_COEXIST pBtCoexist
2727 if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2730 halbtcoutsrc_LeaveLowPower(pBtCoexist);
2732 if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2734 if(pBtCoexist->boardInfo.btdmAntNum == 1)
2735 EXhalbtc8723b1ant_DisplayAntIsolation(pBtCoexist);
2738 halbtcoutsrc_NormalLowPower(pBtCoexist);
2741 static void halbt_InitHwConfig92C(PADAPTER padapter)
2743 PHAL_DATA_TYPE pHalData;
2747 pHalData = GET_HAL_DATA(padapter);
2748 if( (pHalData->bt_coexist.btChipType == BT_CSR_BC4) ||
2749 (pHalData->bt_coexist.btChipType == BT_CSR_BC8))
2751 if (pHalData->rf_type == RF_1T1R)
2754 u1Tmp = rtw_read8(padapter, rOFDM0_TRxPathEnable);
2756 rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
2757 RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
2759 u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
2761 rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
2762 RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
2767 static void halbt_InitHwConfig92D(PADAPTER padapter)
2769 PHAL_DATA_TYPE pHalData;
2772 pHalData = GET_HAL_DATA(padapter);
2773 if ((pHalData->bt_coexist.btChipType == BT_CSR_BC4) ||
2774 (pHalData->bt_coexist.btChipType == BT_CSR_BC8))
2776 if (pHalData->rf_type == RF_1T1R)
2779 u1Tmp = rtw_read8(padapter, rOFDM0_TRxPathEnable);
2781 rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
2782 RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
2784 u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
2786 rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
2787 RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
2794 * Run BT-Coexist mechansim or not
2797 void hal_btcoex_SetBTCoexist(PADAPTER padapter, u8 bBtExist)
2799 PHAL_DATA_TYPE pHalData;
2802 pHalData = GET_HAL_DATA(padapter);
2803 pHalData->bt_coexist.bBtExist = bBtExist;
2805 //EXhalbtcoutsrc_SetBtExist(bBtExist);
2810 * Check is co-exist mechanism enabled or not
2813 * _TRUE Enable BT co-exist mechanism
2814 * _FALSE Disable BT co-exist mechanism
2816 u8 hal_btcoex_IsBtExist(PADAPTER padapter)
2818 PHAL_DATA_TYPE pHalData;
2821 pHalData = GET_HAL_DATA(padapter);
2822 return pHalData->bt_coexist.bBtExist;
2825 u8 hal_btcoex_IsBtDisabled(PADAPTER padapter)
2827 if (!hal_btcoex_IsBtExist(padapter))
2830 if (GLBtCoexist.btInfo.bBtDisabled)
2836 void hal_btcoex_SetChipType(PADAPTER padapter, u8 chipType)
2838 PHAL_DATA_TYPE pHalData;
2841 pHalData = GET_HAL_DATA(padapter);
2842 pHalData->bt_coexist.btChipType = chipType;
2844 EXhalbtcoutsrc_SetChipType(chipType);
2847 u8 hal_btcoex_GetChipType(PADAPTER padapter)
2849 PHAL_DATA_TYPE pHalData;
2852 pHalData = GET_HAL_DATA(padapter);
2853 return pHalData->bt_coexist.btChipType;
2856 void hal_btcoex_SetPgAntNum(PADAPTER padapter, u8 antNum)
2858 PHAL_DATA_TYPE pHalData;
2861 pHalData = GET_HAL_DATA(padapter);
2863 pHalData->bt_coexist.btTotalAntNum = antNum;
2864 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
2867 u8 hal_btcoex_GetPgAntNum(PADAPTER padapter)
2869 PHAL_DATA_TYPE pHalData;
2872 pHalData = GET_HAL_DATA(padapter);
2874 return pHalData->bt_coexist.btTotalAntNum;
2877 void hal_btcoex_SetSingleAntPath(PADAPTER padapter, u8 singleAntPath)
2879 EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
2882 u8 hal_btcoex_Initialize(PADAPTER padapter)
2888 _rtw_memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
2889 ret1 = EXhalbtcoutsrc_InitlizeVariables((void*)padapter);
2890 ret2 = (ret1==_TRUE) ? _TRUE : _FALSE;
2895 void hal_btcoex_PowerOnSetting(PADAPTER padapter)
2897 EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
2900 void hal_btcoex_PreLoadFirmware(PADAPTER padapter)
2902 EXhalbtcoutsrc_PreLoadFirmware(&GLBtCoexist);
2905 void hal_btcoex_InitHwConfig(PADAPTER padapter, u8 bWifiOnly)
2907 if (!hal_btcoex_IsBtExist(padapter))
2910 if (IS_HARDWARE_TYPE_8192C(padapter))
2912 halbt_InitHwConfig92C(padapter);
2914 else if(IS_HARDWARE_TYPE_8192D(padapter))
2916 halbt_InitHwConfig92D(padapter);
2919 EXhalbtcoutsrc_InitHwConfig(&GLBtCoexist, bWifiOnly);
2920 EXhalbtcoutsrc_InitCoexDm(&GLBtCoexist);
2923 void hal_btcoex_IpsNotify(PADAPTER padapter, u8 type)
2925 EXhalbtcoutsrc_IpsNotify(&GLBtCoexist, type);
2928 void hal_btcoex_LpsNotify(PADAPTER padapter, u8 type)
2930 EXhalbtcoutsrc_LpsNotify(&GLBtCoexist, type);
2933 void hal_btcoex_ScanNotify(PADAPTER padapter, u8 type)
2935 EXhalbtcoutsrc_ScanNotify(&GLBtCoexist, type);
2938 void hal_btcoex_ConnectNotify(PADAPTER padapter, u8 action)
2940 EXhalbtcoutsrc_ConnectNotify(&GLBtCoexist, action);
2943 void hal_btcoex_MediaStatusNotify(PADAPTER padapter, u8 mediaStatus)
2945 EXhalbtcoutsrc_MediaStatusNotify(&GLBtCoexist, mediaStatus);
2948 void hal_btcoex_SpecialPacketNotify(PADAPTER padapter, u8 pktType)
2950 EXhalbtcoutsrc_SpecialPacketNotify(&GLBtCoexist, pktType);
2953 void hal_btcoex_IQKNotify(PADAPTER padapter, u8 state)
2955 GLBtcWiFiInIQKState = state;
2958 void hal_btcoex_BtInfoNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
2960 if (GLBtcWiFiInIQKState == _TRUE)
2963 EXhalbtcoutsrc_BtInfoNotify(&GLBtCoexist, tmpBuf, length);
2966 void hal_btcoex_SuspendNotify(PADAPTER padapter, u8 state)
2969 state = BTC_WIFI_PNP_SLEEP;
2971 state = BTC_WIFI_PNP_WAKE_UP;
2973 EXhalbtcoutsrc_PnpNotify(&GLBtCoexist, state);
2976 void hal_btcoex_HaltNotify(PADAPTER padapter)
2978 EXhalbtcoutsrc_HaltNotify(&GLBtCoexist);
2981 void hal_btcoex_SwitchBtTRxMask(PADAPTER padapter)
2983 EXhalbtcoutsrc_SwitchBtTRxMask(&GLBtCoexist);
2986 void hal_btcoex_Hanlder(PADAPTER padapter)
2988 EXhalbtcoutsrc_Periodical(&GLBtCoexist);
2991 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(PADAPTER padapter)
2993 return (s32)GLBtCoexist.btInfo.bBtCtrlAggBufSize;
2996 u32 hal_btcoex_GetAMPDUSize(PADAPTER padapter)
2998 return (u32)GLBtCoexist.btInfo.aggBufSize;
3001 void hal_btcoex_SetManualControl(PADAPTER padapter, u8 bmanual)
3003 GLBtCoexist.bManualControl = bmanual;
3006 u8 hal_btcoex_1Ant(PADAPTER padapter)
3008 if (hal_btcoex_IsBtExist(padapter) == _FALSE)
3011 if (GLBtCoexist.boardInfo.btdmAntNum == 1)
3017 u8 hal_btcoex_IsBtControlLps(PADAPTER padapter)
3019 if (hal_btcoex_IsBtExist(padapter) == _FALSE)
3022 if (GLBtCoexist.btInfo.bBtDisabled)
3025 if (GLBtCoexist.btInfo.bBtCtrlLps)
3031 u8 hal_btcoex_IsLpsOn(PADAPTER padapter)
3033 if (hal_btcoex_IsBtExist(padapter) == _FALSE)
3036 if (GLBtCoexist.btInfo.bBtDisabled)
3039 if (GLBtCoexist.btInfo.bBtLpsOn)
3045 u8 hal_btcoex_RpwmVal(PADAPTER padapter)
3047 return GLBtCoexist.btInfo.rpwmVal;
3050 u8 hal_btcoex_LpsVal(PADAPTER padapter)
3052 return GLBtCoexist.btInfo.lpsVal;
3055 u32 hal_btcoex_GetRaMask(PADAPTER padapter)
3057 if (!hal_btcoex_IsBtExist(padapter))
3060 if (GLBtCoexist.btInfo.bBtDisabled)
3063 // Modify by YiWei , suggest by Cosa and Jenyu
3064 // Remove the limit antenna number , because 2 antenna case (ex: 8192eu)also want to get BT coex report rate mask.
3065 //if (GLBtCoexist.boardInfo.btdmAntNum != 1)
3068 return GLBtCoexist.btInfo.raMask;
3071 void hal_btcoex_RecordPwrMode(PADAPTER padapter, u8 *pCmdBuf, u8 cmdLen)
3073 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write pwrModeCmd=0x%04x%08x\n",
3074 pCmdBuf[0]<<8|pCmdBuf[1],
3075 pCmdBuf[2]<<24|pCmdBuf[3]<<16|pCmdBuf[4]<<8|pCmdBuf[5]));
3077 _rtw_memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);
3080 void hal_btcoex_DisplayBtCoexInfo(PADAPTER padapter, u8 *pbuf, u32 bufsize)
3085 pinfo = &GLBtcDbgInfo;
3086 DBG_BT_INFO_INIT(pinfo, pbuf, bufsize);
3087 EXhalbtcoutsrc_DisplayBtCoexInfo(&GLBtCoexist);
3088 DBG_BT_INFO_INIT(pinfo, NULL, 0);
3091 void hal_btcoex_SetDBG(PADAPTER padapter, u32 *pDbgModule)
3096 if (NULL == pDbgModule)
3099 for (i=0; i<BTC_MSG_MAX; i++)
3100 GLBtcDbgType[i] = pDbgModule[i];
3103 u32 hal_btcoex_GetDBG(PADAPTER padapter, u8 *pStrBuf, u32 bufSize)
3110 if ((NULL == pStrBuf) || (0 == bufSize))
3116 // DBG_871X(FUNC_ADPT_FMT ": bufsize=%d\n", FUNC_ADPT_ARG(padapter), bufSize);
3118 count = rtw_sprintf(pstr, leftSize, "#define DBG\t%d\n", DBG);
3119 if ((count < 0) || (count >= leftSize))
3124 count = rtw_sprintf(pstr, leftSize, "BTCOEX Debug Setting:\n");
3125 if ((count < 0) || (count >= leftSize))
3130 count = rtw_sprintf(pstr, leftSize,
3131 "INTERFACE / ALGORITHM: 0x%08X / 0x%08X\n\n",
3132 GLBtcDbgType[BTC_MSG_INTERFACE],
3133 GLBtcDbgType[BTC_MSG_ALGORITHM]);
3134 if ((count < 0) || (count >= leftSize))
3139 count = rtw_sprintf(pstr, leftSize, "INTERFACE Debug Setting Definition:\n");
3140 if ((count < 0) || (count >= leftSize))
3144 count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for INTF_INIT\n",
3145 GLBtcDbgType[BTC_MSG_INTERFACE]&INTF_INIT?1:0);
3146 if ((count < 0) || (count >= leftSize))
3150 count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for INTF_NOTIFY\n\n",
3151 GLBtcDbgType[BTC_MSG_INTERFACE]&INTF_NOTIFY?1:0);
3152 if ((count < 0) || (count >= leftSize))
3157 count = rtw_sprintf(pstr, leftSize, "ALGORITHM Debug Setting Definition:\n");
3158 if ((count < 0) || (count >= leftSize))
3162 count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for BT_RSSI_STATE\n",
3163 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_BT_RSSI_STATE?1:0);
3164 if ((count < 0) || (count >= leftSize))
3168 count = rtw_sprintf(pstr, leftSize, "\tbit[1]=%d for WIFI_RSSI_STATE\n",
3169 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_WIFI_RSSI_STATE?1:0);
3170 if ((count < 0) || (count >= leftSize))
3174 count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for BT_MONITOR\n",
3175 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_BT_MONITOR?1:0);
3176 if ((count < 0) || (count >= leftSize))
3180 count = rtw_sprintf(pstr, leftSize, "\tbit[3]=%d for TRACE\n",
3181 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE?1:0);
3182 if ((count < 0) || (count >= leftSize))
3186 count = rtw_sprintf(pstr, leftSize, "\tbit[4]=%d for TRACE_FW\n",
3187 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW?1:0);
3188 if ((count < 0) || (count >= leftSize))
3192 count = rtw_sprintf(pstr, leftSize, "\tbit[5]=%d for TRACE_FW_DETAIL\n",
3193 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW_DETAIL?1:0);
3194 if ((count < 0) || (count >= leftSize))
3198 count = rtw_sprintf(pstr, leftSize, "\tbit[6]=%d for TRACE_FW_EXEC\n",
3199 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW_EXEC?1:0);
3200 if ((count < 0) || (count >= leftSize))
3204 count = rtw_sprintf(pstr, leftSize, "\tbit[7]=%d for TRACE_SW\n",
3205 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW?1:0);
3206 if ((count < 0) || (count >= leftSize))
3210 count = rtw_sprintf(pstr, leftSize, "\tbit[8]=%d for TRACE_SW_DETAIL\n",
3211 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW_DETAIL?1:0);
3212 if ((count < 0) || (count >= leftSize))
3216 count = rtw_sprintf(pstr, leftSize, "\tbit[9]=%d for TRACE_SW_EXEC\n",
3217 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW_EXEC?1:0);
3218 if ((count < 0) || (count >= leftSize))
3224 count = pstr - pStrBuf;
3225 // DBG_871X(FUNC_ADPT_FMT ": usedsize=%d\n", FUNC_ADPT_ARG(padapter), count);
3230 u8 hal_btcoex_IncreaseScanDeviceNum(PADAPTER padapter)
3232 if (!hal_btcoex_IsBtExist(padapter))
3235 if (GLBtCoexist.btInfo.bIncreaseScanDevNum)
3241 u8 hal_btcoex_IsBtLinkExist(PADAPTER padapter)
3243 if (GLBtCoexist.btLinkInfo.bBtLinkExist)
3251 * Setting BT coex antenna isolation type .
3252 * coex mechanisn/ spital stream/ best throughput
3253 * anttype = 0 , PSTDMA / 2SS / 0.5T , bad isolation (<20dB) for 2,3 antenna
3254 * anttype = 1 , PSTDMA / 1SS / 0.5T , normal isolaiton (>20dB) for 2 antenna
3255 * anttype = 2 , TDMA / 2SS / T , normal isolaiton (>20dB) for 3 antenna
3256 * anttype = 3 , no TDMA / 1SS / 0.5T , good isolation (>40dB) for 2 antenna
3257 * anttype = 4 , no TDMA / 2SS / T , good isolation (>40dB) for 3 antenna
3258 * wifi only throughput ~ T
3259 * wifi/BT share one antenna with SPDT
3261 void hal_btcoex_SetAntIsolationType(PADAPTER padapter, u8 anttype)
3263 PHAL_DATA_TYPE pHalData;
3265 //DBG_871X("####%s , anttype = %d , %d \n", __FUNCTION__,anttype,__LINE__);
3266 pHalData = GET_HAL_DATA(padapter);
3269 pHalData->bt_coexist.btAntisolation= anttype;
3273 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
3275 hal_btcoex_ParseAntIsolationConfigFile(
3280 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
3282 char *szLine, *ptmp;
3283 int rtStatus = _SUCCESS;
3284 char param_value_string[10];
3288 u8 ant_num=3, ant_distance=50;
3290 typedef struct ant_isolation
3292 char *param_name; // antenna isolation config parameter name
3293 u8 *value; // antenna isolation config parameter value
3296 ANT_ISOLATION ant_isolation_param[]= {
3297 {"ANT_NUMBER",&ant_num},
3298 {"ANT_DISTANCE",&ant_distance},
3304 //DBG_871X("===>Hal_ParseAntIsolationConfigFile()\n" );
3307 for (szLine = GetLineFromBuffer(ptmp); szLine != NULL; szLine = GetLineFromBuffer(ptmp))
3310 if ( IsCommentString( szLine ) ) {
3314 //DBG_871X("%s : szLine = %s , strlen(szLine) = %d \n", __FUNCTION__,szLine,strlen(szLine));
3315 for ( j=0 ;ant_isolation_param[j].param_name != NULL ; j++ )
3317 if ( strstr(szLine,ant_isolation_param[j].param_name)!= NULL )
3320 while ( i < strlen(szLine) )
3322 if (szLine[i] != '"')
3326 // skip only has one "
3327 if( strpbrk(szLine, "\"") == strrchr(szLine, '"'))
3329 DBG_871X("Fail to parse parameters , format error!\n");
3332 _rtw_memset( ( PVOID ) param_value_string, 0, 10 );
3333 if ( ! ParseQualifiedString( szLine, &i, param_value_string, '"' , '"' ) ) {
3334 DBG_871X("Fail to parse parameters \n");
3339 GetU1ByteIntegerFromStringInDecimal( param_value_string, ant_isolation_param[j].value );
3348 // YiWei 20140716 , for BT coex antenna isolation control
3349 if ( ant_num==3 && ant_distance>=50)
3351 pHalData->EEPROMBluetoothCoexist = 0;
3354 else if ( ant_num==2 && ant_distance>=50 )
3358 else if ( ant_num==3 && ant_distance>=15 && ant_distance<50 )
3362 else if ( ant_num==2 && ant_distance>=15 && ant_distance<50 )
3366 else if ( (ant_num==2 && ant_distance<15) || (ant_num==3 && ant_distance<15))
3372 pHalData->EEPROMBluetoothCoexist = 1;
3376 hal_btcoex_SetAntIsolationType(Adapter, anttype);
3378 DBG_871X("%s : ant_num = %d \n", __FUNCTION__,ant_num);
3379 DBG_871X("%s : ant_distance = %d \n", __FUNCTION__,ant_distance);
3380 //DBG_871X("<===Hal_ParseAntIsolationConfigFile()\n");
3386 hal_btcoex_AntIsolationConfig_ParaFile(
3387 IN PADAPTER Adapter,
3391 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
3392 int rlen = 0, rtStatus = _FAIL;
3393 //char file_path[1024];
3395 //if(!(Adapter->registrypriv.load_phy_file & LOAD_RF_TXPWR_LMT_PARA_FILE))
3398 _rtw_memset(pHalData->para_file_buf, 0, MAX_PARA_FILE_BUF_LEN);
3401 rtw_merge_string(file_path, PATH_LENGTH_MAX, rtw_phy_file_path, pFileName);
3403 if (rtw_is_file_readable(file_path) == _TRUE)
3405 rlen = rtw_retrive_from_file(file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
3408 rtStatus = _SUCCESS;
3413 if(rtStatus == _SUCCESS)
3415 //DBG_871X("%s(): read %s ok\n", __FUNCTION__, pFileName);
3416 rtStatus = hal_btcoex_ParseAntIsolationConfigFile( Adapter, pHalData->para_file_buf );
3420 DBG_871X("%s(): No File %s, Load from *** Array!\n", __FUNCTION__, pFileName);
3425 #endif // CONFIG_LOAD_PHY_PARA_FROM_FILE
3426 #endif // CONFIG_BT_COEXIST